Skip to content

Commit

Permalink
Don't kick player on double login (FAForever#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic authored Nov 3, 2024
1 parent 645d001 commit ede2a07
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
36 changes: 20 additions & 16 deletions server/lobbyconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,26 @@ async def on_player_login(
if not conforms_policy:
return

old_player = self.player_service.get_player(player_id)
if old_player:
self._logger.debug(
"player %s already signed in: %s",
player_id, old_player
)
if old_player.lobby_connection is self:
await self.send_warning(
"You are already signed in from this location!"
)
return
elif old_player.lobby_connection is not None:
with contextlib.suppress(DisconnectedError):
old_player.lobby_connection.write_warning(
"You have been signed out because you signed in "
"elsewhere.",
fatal=True,
style="kick"
)

self._logger.info(
"Login from: %s(id=%s), using method '%s' for session %s",
username,
Expand Down Expand Up @@ -675,22 +695,6 @@ async def on_player_login(
lobby_connection=self,
leaderboards=self.rating_service.leaderboards
)

old_player = self.player_service.get_player(self.player.id)
if old_player:
self._logger.debug(
"player %s already signed in: %s",
self.player.id, old_player
)
if old_player.lobby_connection is not None:
with contextlib.suppress(DisconnectedError):
old_player.lobby_connection.write_warning(
"You have been signed out because you signed in "
"elsewhere.",
fatal=True,
style="kick"
)

await self.player_service.fetch_player_data(self.player)

self.player_service[self.player.id] = self.player
Expand Down
27 changes: 22 additions & 5 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jwt
import pytest

from tests.utils import fast_forward

from .conftest import (
connect_and_sign_in,
connect_client,
Expand Down Expand Up @@ -244,26 +246,41 @@ async def test_policy_server_contacted(lobby_server, policy_server, player_servi
policy_server.verify.assert_called_once()


@fast_forward(15)
async def test_server_login_double(lobby_server):
proto = await connect_client(lobby_server)
await perform_login(proto, ("test", "test_password"))
msg = await proto.read_message()
msg["command"] == "welcome"
await read_until_command(proto, "game_info", timeout=5)

# Sign in again with a new protocol object
proto2 = await connect_client(lobby_server)
await perform_login(proto2, ("test", "test_password"))
msg = await proto2.read_message()
msg["command"] == "welcome"
await read_until_command(proto2, "welcome", timeout=5)

msg = await read_until_command(proto, "notice")
msg = await read_until_command(proto, "notice", timeout=10)
assert msg == {
"command": "notice",
"style": "kick",
"text": "You have been signed out because you signed in elsewhere."
}


@fast_forward(20)
async def test_server_login_double_message(lobby_server):
proto = await connect_client(lobby_server)
await perform_login(proto, ("test", "test_password"))
await read_until_command(proto, "game_info", timeout=5)

# Sign in again with the same connection
await perform_login(proto, ("test", "test_password"))
msg = await read_until_command(proto, "notice", timeout=10)
assert msg == {
"command": "notice",
"style": "info",
"text": "You are already signed in from this location!"
}


async def test_server_login_token_valid(lobby_server, jwk_priv_key, jwk_kid, fixed_time):
proto = await connect_client(lobby_server)
await proto.send_message({
Expand Down

0 comments on commit ede2a07

Please sign in to comment.