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/#858 validity in game info #900

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
8 changes: 3 additions & 5 deletions server/gameconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ async def handle_operation_complete(
self._logger.warning("OperationComplete called for non-coop game")
return

if self.game.validity != ValidityState.COOP_NOT_RANKED:
validity = self.game.get_validity()
if validity is not ValidityState.COOP_NOT_RANKED:
self._logger.info("Game was not valid: %s", validity)
return

secondary, delta = secondary, str(delta)
Expand Down Expand Up @@ -461,10 +463,6 @@ async def handle_game_state(self, state: str):
return

elif state == "Lobby":
# TODO: Do we still need to schedule with `ensure_future`?
#
# We do not yield from the task, since we
# need to keep processing other commands while it runs
await self._handle_lobby_state()

elif state == "Launching":
Expand Down
27 changes: 12 additions & 15 deletions server/games/coop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio

from server.games.validator import COMMON_RULES, GameOptionRule, Validator

from .game import Game
from .typedefs import FA, GameType, InitMode, ValidityState, Victory

Expand All @@ -8,12 +10,21 @@ class CoopGame(Game):
"""Class for coop game"""
init_mode = InitMode.NORMAL_LOBBY
game_type = GameType.COOP
default_validity = ValidityState.COOP_NOT_RANKED
validator = Validator([
*COMMON_RULES,
GameOptionRule("Victory", Victory.SANDBOX, ValidityState.WRONG_VICTORY_CONDITION),
GameOptionRule("TeamSpawn", "fixed", ValidityState.SPAWN_NOT_FIXED),
GameOptionRule("RevealedCivilians", FA.DISABLED, ValidityState.CIVILIANS_REVEALED),
GameOptionRule("Difficulty", 3, ValidityState.WRONG_DIFFICULTY),
GameOptionRule("Expansion", FA.ENABLED, ValidityState.EXPANSION_DISABLED),
])

def __init__(self, *args, **kwargs):
kwargs["game_mode"] = "coop"
super().__init__(*args, **kwargs)

self.validity = ValidityState.COOP_NOT_RANKED
self.is_coop = True
self.game_options.update({
"Victory": Victory.SANDBOX,
"TeamSpawn": "fixed",
Expand All @@ -24,20 +35,6 @@ def __init__(self, *args, **kwargs):
self.leaderboard_lock = asyncio.Lock()
self.leaderboard_saved = False

async def validate_game_mode_settings(self):
"""
Checks which only apply to the coop mode
"""

valid_options = {
"Victory": (Victory.SANDBOX, ValidityState.WRONG_VICTORY_CONDITION),
"TeamSpawn": ("fixed", ValidityState.SPAWN_NOT_FIXED),
"RevealedCivilians": (FA.DISABLED, ValidityState.CIVILIANS_REVEALED),
"Difficulty": (3, ValidityState.WRONG_DIFFICULTY),
"Expansion": (FA.ENABLED, ValidityState.EXPANSION_DISABLED),
}
await self._validate_game_options(valid_options)

async def process_game_results(self):
"""
When a coop game ends, we don't expect there to be any game results.
Expand Down
25 changes: 18 additions & 7 deletions server/games/custom_game.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import time
from typing import Optional

from server.decorators import with_logger
from server.games.validator import COMMON_RULES, NON_COOP_RULES, Validator
from server.rating import RatingType

from .game import Game
from .typedefs import GameType, InitMode, ValidityState


def minimum_length_rule(game: Game) -> Optional[ValidityState]:
if game.launched_at is None:
return

limit = len(game.players) * 60
if not game.enforce_rating and time.time() - game.launched_at < limit:
return ValidityState.TOO_SHORT


@with_logger
class CustomGame(Game):
init_mode = InitMode.NORMAL_LOBBY
game_type = GameType.CUSTOM
validator = Validator([
*COMMON_RULES,
*NON_COOP_RULES,
minimum_length_rule
])

def __init__(self, id, *args, **kwargs):
def __init__(self, *args, **kwargs):
new_kwargs = {
"rating_type": RatingType.GLOBAL,
"setup_timeout": 30
}
new_kwargs.update(kwargs)
super().__init__(id, *args, **new_kwargs)

async def _run_pre_rate_validity_checks(self):
limit = len(self.players) * 60
if not self.enforce_rating and time.time() - self.launched_at < limit:
await self.mark_invalid(ValidityState.TOO_SHORT)
super().__init__(*args, **new_kwargs)
Loading
Loading