Repository navigation
Conversation
…semver3 Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
- Moved `BaseCloudServer` (Formerly `_SaCloudServer`) to sa.eventhandlers._base Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
|
Tell me if you require help in applying these changes |
(cherry picked from commit 8d30697) Signed-off-by: GitHub <noreply@github.com>
9a6846e to
2950297
Compare
### sa.eventhandlers._base - changed list comp to generator comp in set_project_vars() and set_var() - reimplemented attribute type hints into BaseCloudServer. since type hints are inhierted, there is no need to restate them in child classes of BaseCloudServer. ### sa.eventhandlers.cloud_server - added type hitns to __init__ of BaseCloudServer child classes - added type hints to init_cloud_server and init_ssl_cloud_server - revert changing warnings.warn to print in 9863d50 Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: TheCommCraft <79996518+TheCommCraft@users.noreply.github.com> Signed-off-by: Boss_1s <95505913+Boss-1s@users.noreply.github.com>
Signed-off-by: GitHub <noreply@github.com>
|
I think that the custom cloud solution you added might cause extreme lag, it would be better to just not add a cloud at first (or you could create a cloud that just translates method calls of the cloud into those of the server) |
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: GitHub <noreply@github.com>
This comment was marked as resolved.
This comment was marked as resolved.
|
The only thing left is the set var prefix option, then we should be done here |
|
Do you want to complete this PR or should I continue? |
|
jtlyk I am unable to resolve the conflicts; they are too complex |
Signed-off-by: TheCommCraft <79996518+TheCommCraft@users.noreply.github.com>
There was a problem hiding this comment.
It is difficult for me to provide a useful review because I haven't interacted the codebase that much recently, but I have tried to provide a few comments. I do not see anything obviously wrong, however my judgement is limited
Some additional notes:
- We are using a lot of
Anyand then converting tostr. Maybe it is not possible now but it would probably be better to do that conversion earlier, so we do not getAnypropagating everywhere. Unless if it would be a breaking change to a user-facing API - We are using
SimpleWebSocketServera lot although we really should change that (#734) - In truth, AI code review could probably be useful here
| certfile: str|None = None, | ||
| keyfile: str|None = None, | ||
| ssl_version: int = ssl.PROTOCOL_TLSv1_2, | ||
| ssl_context: ssl.SSLContext|None = None, |
There was a problem hiding this comment.
These attrs should be specific to SSL servers right?
There was a problem hiding this comment.
Ie don't put them in the base class
|
|
||
|
|
||
| class BaseCloud(AnyCloud[Union[str, int]]): | ||
| class BaseCloud(AnyCloud[Union[str, int, float]]): |
There was a problem hiding this comment.
small thing, but str | int | float is more concise
There was a problem hiding this comment.
This would apply in a lot of cases in the codebase, e.g. every use of Optional, so this is more of a separate style issue
|
|
||
| Args: | ||
| variable (str): The name of the cloud variable that should be set (provided without the cloud emoji) | ||
| value (Any): The value the cloud variable should be set to |
There was a problem hiding this comment.
Any is the wrong type here. should be str | int | float
| "IP address or domain name of the host to bind the server to." | ||
| port: int | ||
| "Port to bind the server to." | ||
| tw_clients: dict[tuple[str, int], dict[str, Any]] |
There was a problem hiding this comment.
Would a TypedDict be possible here instead of using Any?
There was a problem hiding this comment.
It would be better, but we could also just use a class.
| "Port to bind the server to." | ||
| tw_clients: dict[tuple[str, int], dict[str, Any]] | ||
| "Dictionary containing information on connected clients." | ||
| tw_variables: dict[str, dict[str, Any]] |
There was a problem hiding this comment.
Would a TypedDict be possible here instead of using Any?
There was a problem hiding this comment.
It would be better to use str | int | float
| ) | ||
| for varname in data | ||
| ] | ||
| json_string = "\n".join(json.dumps(packet) for packet in packets) |
There was a problem hiding this comment.
This isn't really a json string, but rather a number of lines of json (JSONL). Is this expected and is the scratchattach client also able to handle this?
There was a problem hiding this comment.
It is the intended way to transmit multiple packets in scratch cloud variable websockets
| intelligent_waits: bool = True, | ||
| max_retries: int = 2, |
There was a problem hiding this comment.
these arguments are unused. if this is intentional, they should also be removed from the docstring
| if self.disconnected.is_set(): | ||
| return |
There was a problem hiding this comment.
Would it be more appropriate to raise an error if you are trying to set variables if you are disconnected?
Also, it is noteworthy that self.disconnected.is_set() is being used for the set_var methods but not for the get_var methods. Is this intentional? Perhaps it is useful to still be able to see the variables after you are disconnected?
There was a problem hiding this comment.
that was the thought behind it
| while (progress < amount if amount >= 0 else progress == 0) and ( | ||
| time.time() < end_time if end_time is not None else True | ||
| ): |
There was a problem hiding this comment.
this is a pretty confusing condition
Resolves nothing
Changes
Implemented SSL secure ws server (fix cloud server #658) from semver2 into semver 3
New class
_SaWebSockectServerBaseWebSocketServerinsa.eventhandlers._baseto keep things pythonic and organizedYou can now link a cloud
refactoring everything related cause why not
Tasks
Tests
First, start up an insecure server to ensure it works:
While the above script is running, run
websocat ws://127.0.0.1:8080to interact with the websocket.Once you have determined that this works, replace the above script with the one below:
Then, generate an OpenSSL certificate:
Finally, run the server script, and interact with the WebSocket with
websocat -k wss://127.0.0.1:8080Notes
might wanna have #722 fixed before merging this, idk