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

Issue/#1035 Remove FFA validity check for coop games #1037

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions server/gameconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ async def handle_operation_complete(
return

if not isinstance(self.game, CoopGame):
self._logger.warning(
"OperationComplete called for non-coop game: %s", self.game.id
)
self._logger.warning("OperationComplete called for non-coop game")
return

if self.game.validity != ValidityState.COOP_NOT_RANKED:
Expand All @@ -338,6 +336,13 @@ async def handle_operation_complete(
# message but we only need to perform this insert once
async with self.game.leaderboard_lock:
if not self.game.leaderboard_saved:
self._logger.debug(
"Updating coop leaderboard: mission: %s, secondary: %s, "
"time %s",
mission,
secondary,
delta,
)
await conn.execute(
coop_leaderboard.insert().values(
mission=mission,
Expand Down
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 @@ -95,3 +95,94 @@ async def test_single_player_game_recorded(lobby_server, database):
assert row.secondary == 0
assert row.time == datetime.time(0, 11, 50)
assert row.player_count == 1


@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
Loading