Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform client time sync on login #1004

Merged
merged 17 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ async def on_player_login(
await self.send({
"command": "welcome",
"me": self.player.to_dict(),
"current_time": datetime.utcnow().timestamp(),
baterflyrity marked this conversation as resolved.
Show resolved Hide resolved

# For backwards compatibility for old clients. For now.
"id": self.player.id,
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from time import time

import jwt
Expand All @@ -10,6 +11,8 @@
read_until_command
)

TIMEOUT = 10


async def test_server_login_invalid(lobby_server):
proto = await connect_client(lobby_server)
Expand Down Expand Up @@ -118,9 +121,12 @@ async def test_server_login_valid(lobby_server):
assert msg == {
"command": "welcome",
"me": me,
"current_time": msg.get("current_time", None),
baterflyrity marked this conversation as resolved.
Show resolved Hide resolved
"id": 3,
"login": "Rhiza"
}
assert isinstance(msg.get("current_time", None), float)
assert abs(msg.get("current_time", -1) - datetime.utcnow().timestamp()) <= TIMEOUT
baterflyrity marked this conversation as resolved.
Show resolved Hide resolved
msg = await proto.read_message()
assert msg == {
"command": "player_info",
Expand Down Expand Up @@ -163,9 +169,12 @@ async def test_server_login_valid_admin(lobby_server):
assert msg == {
"command": "welcome",
"me": me,
"current_time": msg.get("current_time", None),
"id": 1,
"login": "test"
}
assert isinstance(msg.get("current_time", None), float)
assert abs(msg.get("current_time", -1) - datetime.utcnow().timestamp()) <= TIMEOUT
msg = await proto.read_message()
assert msg == {
"command": "player_info",
Expand Down Expand Up @@ -207,9 +216,12 @@ async def test_server_login_valid_moderator(lobby_server):
assert msg == {
"command": "welcome",
"me": me,
"current_time": msg.get("current_time", None),
"id": 20,
"login": "moderator"
}
assert isinstance(msg.get("current_time", None), float)
assert abs(msg.get("current_time", -1) - datetime.utcnow().timestamp()) <= TIMEOUT
msg = await proto.read_message()
assert msg == {
"command": "player_info",
Expand Down Expand Up @@ -305,9 +317,12 @@ async def test_server_login_token_valid(lobby_server, jwk_priv_key, jwk_kid):
assert msg == {
"command": "welcome",
"me": me,
"current_time": msg.get("current_time", None),
"id": 3,
"login": "Rhiza"
}
assert isinstance(msg.get("current_time", None), float)
assert abs(msg.get("current_time", -1) - datetime.utcnow().timestamp()) <= TIMEOUT
msg = await proto.read_message()
assert msg == {
"command": "player_info",
Expand Down
Loading