Allow pre-ready heartbeat pings and include local doc updates

This commit is contained in:
Jage9
2026-02-28 21:20:59 -05:00
parent aa5bcd12cc
commit a57e48a265
5 changed files with 37 additions and 12 deletions

View File

@@ -2094,6 +2094,13 @@ class SignalingServer:
await self._activate_authenticated_client(client)
return
if isinstance(packet, PingPacket):
await self._send(
client.websocket,
PongPacket(type="pong", clientSentAt=packet.clientSentAt),
)
return
if not client.world_ready:
PACKET_LOGGER.info("ignoring pre-ready packet id=%s type=%s", client.id, packet.type)
return
@@ -2332,13 +2339,6 @@ class SignalingServer:
)
return
if isinstance(packet, PingPacket):
await self._send(
client.websocket,
PongPacket(type="pong", clientSentAt=packet.clientSentAt),
)
return
if isinstance(packet, ItemAddPacket):
if not self._client_has_permission(client, "item.create"):
await self._send_item_result(client, False, "add", "Not authorized to create items.")

View File

@@ -314,6 +314,34 @@ async def test_auth_login_defers_activation_until_welcome_ready(monkeypatch: pyt
assert any("has logged in" in getattr(packet, "message", "") for packet in broadcast_payloads)
@pytest.mark.asyncio
async def test_ping_works_before_welcome_ready(monkeypatch: pytest.MonkeyPatch) -> None:
server = SignalingServer("127.0.0.1", 8765, None, None)
username = f"ping_{uuid.uuid4().hex[:8]}"
server.auth_service.register(username, "password99")
ws = _fake_ws()
client = ClientConnection(websocket=ws, id="u1", nickname="tester")
send_payloads: list[object] = []
async def fake_send(websocket: ServerConnection, packet: object) -> None:
send_payloads.append(packet)
monkeypatch.setattr(server, "_send", fake_send)
await server._handle_message(
client,
json.dumps({"type": "auth_login", "username": username, "password": "password99"}),
)
assert client.world_ready is False
await server._handle_message(client, json.dumps({"type": "ping", "clientSentAt": -1}))
pong_packets = [packet for packet in send_payloads if getattr(packet, "type", "") == "pong"]
assert pong_packets
assert pong_packets[-1].clientSentAt == -1
@pytest.mark.asyncio
async def test_auth_resume_failure_message_is_generic(monkeypatch: pytest.MonkeyPatch) -> None:
server = SignalingServer("127.0.0.1", 8765, None, None)