Skip to content

Commit

Permalink
Add FFA_NOT_RANKED to list of checks that are overridden in coop
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Jan 4, 2025
1 parent d015722 commit 99fb962
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
7 changes: 4 additions & 3 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,6 @@ async def validate_game_settings(self):
if self.is_multi_team:
await self.mark_invalid(ValidityState.MULTI_TEAM)
return
if self.is_ffa:
await self.mark_invalid(ValidityState.FFA_NOT_RANKED)
return
valid_options = {
"AIReplacement": (FA.DISABLED, ValidityState.HAS_AI_PLAYERS),
"FogOfWar": ("explored", ValidityState.NO_FOG_OF_WAR),
Expand All @@ -683,6 +680,10 @@ async def validate_game_mode_settings(self):
"""
A subset of checks that need to be overridden in coop games.
"""
if self.is_ffa:
await self.mark_invalid(ValidityState.FFA_NOT_RANKED)
return

if len(self.players) < 2:
await self.mark_invalid(ValidityState.SINGLE_PLAYER)
return
Expand Down
93 changes: 92 additions & 1 deletion tests/integration_tests/test_coop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.utils import fast_forward

from .conftest import connect_and_sign_in, read_until, read_until_command
from .test_game import host_game, send_player_options
from .test_game import host_game, join_game, send_player_options


@fast_forward(100)
Expand Down Expand Up @@ -152,3 +152,94 @@ async def test_single_player_game_early_report_rejected(lobby_server, database):
)
row = result.fetchone()
assert row is None


@fast_forward(100)
async def test_three_player_game_recorded(lobby_server, database):
test_id, _, proto1 = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
await read_until_command(proto1, "game_info")
test2_id, _, proto2 = await connect_and_sign_in(
("test2", "test2"), lobby_server
)
await read_until_command(proto2, "game_info")
test3_id, _, proto3 = await connect_and_sign_in(
("test3", "test3"), lobby_server
)
await read_until_command(proto3, "game_info")

# Set up the game
game_id = await host_game(proto1, mod="coop", mapname="scmp_coop_123.v0002")
await join_game(proto2, game_id)
await join_game(proto3, game_id)
# Set player options
await send_player_options(
proto1,
[test_id, "Army", 1],
[test_id, "Team", 1],
[test_id, "StartSpot", 1],
[test_id, "Faction", 1],
[test_id, "Color", 1],
[test2_id, "Army", 2],
[test2_id, "Team", 1],
[test2_id, "StartSpot", 2],
[test2_id, "Faction", 1],
[test2_id, "Color", 2],
[test3_id, "Army", 3],
[test3_id, "Team", 1],
[test3_id, "StartSpot", 3],
[test3_id, "Faction", 1],
[test3_id, "Color", 3],
)

# Launch game
await proto1.send_message({
"target": "game",
"command": "GameState",
"args": ["Launching"]
})

for proto in (proto1, proto2, proto3):
await read_until(
proto,
lambda cmd: cmd["command"] == "game_info" and cmd["launched_at"]
)

# End the game

for proto in (proto1, proto2, proto3):
await proto.send_message({
"target": "game",
"command": "GameEnded",
"args": []
})

for proto in (proto1, proto2, proto3):
await proto.send_message({
"target": "game",
"command": "OperationComplete",
"args": [1, 0, "00:11:50"]
})

# Now disconnect
for proto in (proto1, proto2, proto3):
await proto.send_message({
"target": "game",
"command": "GameState",
"args": ["Ended"]
})

await read_until_command(proto1, "game_info", uid=game_id, state="closed")

async with database.acquire() as conn:
result = await conn.execute(
select(coop_leaderboard).where(
coop_leaderboard.c.gameuid == game_id
)
)
row = result.fetchone()
assert row is not None
assert row.secondary == 0
assert row.time == datetime.time(0, 11, 50)
assert row.player_count == 3

0 comments on commit 99fb962

Please sign in to comment.