Revert "Core: update websockets (#4732)" (#4753)

This reverts commit 42eaeb92f0.
This commit is contained in:
NewSoupVi
2025-03-19 01:39:18 +01:00
committed by GitHub
parent 63cbc00a40
commit b7fc96100c
4 changed files with 9 additions and 9 deletions

View File

@@ -324,7 +324,7 @@ class Context:
# General networking
async def send_msgs(self, endpoint: Endpoint, msgs: typing.Iterable[dict]) -> bool:
if not endpoint.socket or endpoint.socket.state != websockets.protocol.State.OPEN:
if not endpoint.socket or not endpoint.socket.open:
return False
msg = self.dumper(msgs)
try:
@@ -339,7 +339,7 @@ class Context:
return True
async def send_encoded_msgs(self, endpoint: Endpoint, msg: str) -> bool:
if not endpoint.socket or endpoint.socket.state != websockets.protocol.State.OPEN:
if not endpoint.socket or not endpoint.socket.open:
return False
try:
await endpoint.socket.send(msg)
@@ -355,7 +355,7 @@ class Context:
async def broadcast_send_encoded_msgs(self, endpoints: typing.Iterable[Endpoint], msg: str) -> bool:
sockets = []
for endpoint in endpoints:
if endpoint.socket and endpoint.socket.state == websockets.protocol.State.OPEN:
if endpoint.socket and endpoint.socket.open:
sockets.append(endpoint.socket)
try:
websockets.broadcast(sockets, msg)
@@ -924,7 +924,7 @@ async def on_client_joined(ctx: Context, client: Client):
"If your client supports it, "
"you may have additional local commands you can list with /help.",
{"type": "Tutorial"})
if not any(isinstance(extension, PerMessageDeflate) for extension in client.socket.protocol.extensions):
if not any(isinstance(extension, PerMessageDeflate) for extension in client.socket.extensions):
ctx.notify_client(client, "Warning: your client does not support compressed websocket connections! "
"It may stop working in the future. If you are a player, please report this to the "
"client's developer.")
@@ -2107,7 +2107,7 @@ class ServerCommandProcessor(CommonCommandProcessor):
def _cmd_exit(self) -> bool:
"""Shutdown the server"""
try:
self.ctx.server.server.close()
self.ctx.server.ws_server.close()
finally:
self.ctx.exit_event.set()
return True
@@ -2477,7 +2477,7 @@ async def auto_shutdown(ctx, to_cancel=None):
await asyncio.wait_for(ctx.exit_event.wait(), ctx.auto_shutdown)
def inactivity_shutdown():
ctx.server.server.close()
ctx.server.ws_server.close()
ctx.exit_event.set()
if to_cancel:
for task in to_cancel: