Skip to content

Commit

Permalink
Only use offline state
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Dec 27, 2023
1 parent 289e273 commit 1aade7b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
19 changes: 12 additions & 7 deletions server/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

@unique
class PlayerState(Enum):
IDLE = "idle"
PLAYING = "playing"
HOSTING = "hosting"
JOINING = "joining"
SEARCHING_LADDER = "searching"
STARTING_AUTOMATCH = "matching"
IDLE = 1
PLAYING = 2
HOSTING = 3
JOINING = 4
SEARCHING_LADDER = 5
STARTING_AUTOMATCH = 6


class Player:
Expand Down Expand Up @@ -142,7 +142,12 @@ def to_dict(self) -> dict:
"avatar": self.avatar,
"country": self.country,
"clan": self.clan,
"state": self.state.value if self.lobby_connection else "offline",
# NOTE: We are only sending an 'offline' state for now to signal to
# the client when a player disconnects. However, this could be
# expanded in the future to expose more of the internal state
# tracking to the client to make the UI for showing players in game
# more correct.
"state": None if self.lobby_connection else "offline",
"ratings": {
rating_type: {
"rating": self.ratings[rating_type],
Expand Down
4 changes: 0 additions & 4 deletions tests/integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async def test_server_valid_login(lobby_server):
"login": "Rhiza",
"clan": "123",
"country": "",
"state": "idle",
"ratings": {
"global": {
"rating": [1650.0, 62.52],
Expand Down Expand Up @@ -108,7 +107,6 @@ async def test_server_valid_login_admin(lobby_server):
"login": "test",
"clan": "678",
"country": "",
"state": "idle",
"ratings": {
"global": {
"rating": [2000.0, 125.0],
Expand Down Expand Up @@ -153,7 +151,6 @@ async def test_server_valid_login_moderator(lobby_server):
"id": 20,
"login": "moderator",
"country": "",
"state": "idle",
"ratings": {
"global": {
"rating": [1500, 500],
Expand Down Expand Up @@ -252,7 +249,6 @@ async def test_server_valid_login_with_token(lobby_server, jwk_priv_key, jwk_kid
"login": "Rhiza",
"clan": "123",
"country": "",
"state": "idle",
"ratings": {
"global": {
"rating": [1650.0, 62.52],
Expand Down
20 changes: 13 additions & 7 deletions tests/integration_tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,23 @@ async def test_player_info_broadcast(lobby_server):
await perform_login(p2, ("Rhiza", "puff_the_magic_dragon"))

await read_until(
p2, lambda m: m["command"] == "player_info"
and any(map(lambda d: d["login"] == "test", m["players"]))
p2,
lambda m: (
m["command"] == "player_info"
and any(map(lambda d: d["login"] == "test", m["players"]))
)
)

await p1.close()
await read_until(
p2, lambda m: m["command"] == "player_info"
and any(map(
lambda d: d["login"] == "test" and d["state"] == "offline",
m["players"]
))
p2,
lambda m: (
m["command"] == "player_info"
and any(map(
lambda d: d["login"] == "test" and d.get("state") == "offline",
m["players"]
))
)
)


Expand Down
2 changes: 0 additions & 2 deletions tests/integration_tests/test_teammatchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ async def test_ratings_initialized_based_on_global(lobby_server):
"login": "test",
"clan": "678",
"country": "",
"state": "idle",
"ratings": {
"global": {
"rating": [2000.0, 125.0],
Expand Down Expand Up @@ -621,7 +620,6 @@ async def test_ratings_initialized_based_on_global(lobby_server):
"login": "test",
"clan": "678",
"country": "",
"state": "searching",
"ratings": {
"global": {
"rating": [2000.0, 125.0],
Expand Down
9 changes: 4 additions & 5 deletions tests/unit_tests/test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from trueskill import Rating

from server.factions import Faction
from server.players import Player, PlayerState
from server.players import Player
from server.protocol import DisconnectedError
from server.rating import Leaderboard, RatingType

Expand Down Expand Up @@ -111,11 +111,10 @@ def test_serialize():
def test_serialize_state():
conn = mock.Mock()
p = Player(lobby_connection=conn)
assert p.to_dict()["state"] == "idle"
assert "state" not in p.to_dict()

for state in PlayerState:
p.state = state
assert p.to_dict()["state"] == state.value
del p.lobby_connection
assert p.to_dict()["state"] == "offline"


async def test_send_message():
Expand Down

0 comments on commit 1aade7b

Please sign in to comment.