From f4553a5009c6efb81ae08f93eb41795173a3c3cc Mon Sep 17 00:00:00 2001 From: Askaholic Date: Sat, 20 Nov 2021 14:43:25 -0900 Subject: [PATCH] Remove InitMode --- server/games/__init__.py | 2 -- server/games/coop.py | 3 +-- server/games/custom_game.py | 3 +-- server/games/game.py | 2 -- server/games/ladder_game.py | 4 +--- server/games/typedefs.py | 7 ------- server/ladder_service.py | 3 +-- server/lobbyconnection.py | 6 ++---- tests/conftest.py | 4 ++-- tests/integration_tests/test_matchmaker.py | 1 - tests/integration_tests/test_teammatchmaker.py | 8 ++++---- tests/unit_tests/test_lobbyconnection.py | 10 ++++------ 12 files changed, 16 insertions(+), 37 deletions(-) diff --git a/server/games/__init__.py b/server/games/__init__.py index 87c7603f5..5c7dd1044 100644 --- a/server/games/__init__.py +++ b/server/games/__init__.py @@ -13,7 +13,6 @@ GameConnectionState, GameState, GameType, - InitMode, ValidityState, Victory, VisibilityState @@ -39,7 +38,6 @@ class FeaturedMod(NamedTuple): "GameError", "GameState", "GameType", - "InitMode", "LadderGame", "ValidityState", "Victory", diff --git a/server/games/coop.py b/server/games/coop.py index e556de87a..67fe880ab 100644 --- a/server/games/coop.py +++ b/server/games/coop.py @@ -1,10 +1,9 @@ from .game import Game -from .typedefs import FA, GameType, InitMode, ValidityState, Victory +from .typedefs import FA, GameType, ValidityState, Victory class CoopGame(Game): """Class for coop game""" - init_mode = InitMode.NORMAL_LOBBY game_type = GameType.COOP def __init__(self, *args, **kwargs): diff --git a/server/games/custom_game.py b/server/games/custom_game.py index c71523bc4..efa1b1ecd 100644 --- a/server/games/custom_game.py +++ b/server/games/custom_game.py @@ -4,12 +4,11 @@ from server.rating import RatingType from .game import Game -from .typedefs import GameType, InitMode, ValidityState +from .typedefs import GameType, ValidityState @with_logger class CustomGame(Game): - init_mode = InitMode.NORMAL_LOBBY game_type = GameType.CUSTOM def __init__(self, id_, *args, **kwargs): diff --git a/server/games/game.py b/server/games/game.py index 95f991163..4ac5d780f 100644 --- a/server/games/game.py +++ b/server/games/game.py @@ -36,7 +36,6 @@ GameConnectionState, GameState, GameType, - InitMode, ValidityState, Victory, VisibilityState @@ -51,7 +50,6 @@ class Game(): """ Object that lasts for the lifetime of a game on FAF. """ - init_mode = InitMode.NORMAL_LOBBY game_type = GameType.CUSTOM def __init__( diff --git a/server/games/ladder_game.py b/server/games/ladder_game.py index 03395b358..cb1c56781 100644 --- a/server/games/ladder_game.py +++ b/server/games/ladder_game.py @@ -7,15 +7,13 @@ from .game import Game from .game_results import ArmyOutcome, GameOutcome -from .typedefs import FeaturedModType, GameType, InitMode +from .typedefs import FeaturedModType, GameType logger = logging.getLogger(__name__) class LadderGame(Game): """Class for 1v1 ladder games""" - - init_mode = InitMode.AUTO_LOBBY game_type = GameType.MATCHMAKER def __init__(self, id_, *args, **kwargs): diff --git a/server/games/typedefs.py b/server/games/typedefs.py index b1fc6243f..ae6ea4b19 100644 --- a/server/games/typedefs.py +++ b/server/games/typedefs.py @@ -22,12 +22,6 @@ class GameConnectionState(Enum): ENDED = 3 -@unique -class InitMode(Enum): - NORMAL_LOBBY = 0 - AUTO_LOBBY = 1 - - @unique class GameType(Enum): COOP = "coop" @@ -218,7 +212,6 @@ class FA(object): "GameConnectionState", "GameState", "GameType", - "InitMode", "TeamRatingSummary", "ValidityState", "Victory", diff --git a/server/ladder_service.py b/server/ladder_service.py index c7d439670..a9657e8b9 100644 --- a/server/ladder_service.py +++ b/server/ladder_service.py @@ -32,7 +32,7 @@ ) from .decorators import with_logger from .game_service import GameService -from .games import InitMode, LadderGame +from .games import LadderGame from .matchmaker import MapPool, MatchmakerQueue, OnMatchedCallback, Search from .players import Player, PlayerState from .types import GameLaunchOptions, Map, NeroxisGeneratedMap @@ -418,7 +418,6 @@ async def start_game( rating_type=queue.rating_type, max_players=len(all_players) ) - game.init_mode = InitMode.AUTO_LOBBY game.map_file_path = map_path game.set_name_unchecked(game_name(team1, team2)) diff --git a/server/lobbyconnection.py b/server/lobbyconnection.py index a9d0a53e8..8c494d1fa 100644 --- a/server/lobbyconnection.py +++ b/server/lobbyconnection.py @@ -40,7 +40,7 @@ FeaturedModType, GameConnectionState, GameState, - InitMode, + GameType, VisibilityState ) from .geoip_service import GeoIpService @@ -885,7 +885,7 @@ async def command_game_join(self, message): }) return - if game.init_mode != InitMode.NORMAL_LOBBY: + if game.game_type not in (GameType.CUSTOM, GameType.COOP): raise ClientError("The game cannot be joined in this way.") if game.password != password: @@ -1024,8 +1024,6 @@ async def launch_game( # options are. Currently, options for ladder are hardcoded into the # client. "name": game.name, - # DEPRICATED: init_mode can be inferred from game_type - "init_mode": game.init_mode.value, "game_type": game.game_type.value, "rating_type": game.rating_type, **options._asdict() diff --git a/tests/conftest.py b/tests/conftest.py index 804ff4396..107994932 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,7 +25,7 @@ CoopGame, FeaturedModType, Game, - InitMode, + GameType, ValidityState ) from server.geoip_service import GeoIpService @@ -259,7 +259,7 @@ def make_game(database, uid, players, game_type=Game): players.joining.getGame = mock.AsyncMock(return_value=game) players.peer.getGame = mock.AsyncMock(return_value=game) game.host = players.hosting - game.init_mode = InitMode.NORMAL_LOBBY + game.game_type = GameType.CUSTOM game.name = "Some game name" game.id = uid return game diff --git a/tests/integration_tests/test_matchmaker.py b/tests/integration_tests/test_matchmaker.py index 0c28117f3..1f441e5e4 100644 --- a/tests/integration_tests/test_matchmaker.py +++ b/tests/integration_tests/test_matchmaker.py @@ -49,7 +49,6 @@ async def test_game_launch_message(lobby_server): "uid": 41956, "mod": "ladder1v1", "name": "ladder1 Vs ladder2", - "init_mode": 1, "game_type": "matchmaker", "rating_type": "ladder_1v1", "team": 2, diff --git a/tests/integration_tests/test_teammatchmaker.py b/tests/integration_tests/test_teammatchmaker.py index 4644a2649..4cb406d46 100644 --- a/tests/integration_tests/test_teammatchmaker.py +++ b/tests/integration_tests/test_teammatchmaker.py @@ -103,7 +103,7 @@ async def test_game_matchmaking(lobby_server): uid = set(msg["uid"] for msg in msgs) assert len(uid) == 1 for msg in msgs: - assert msg["init_mode"] == 1 + assert msg["game_type"] == "matchmaker" assert "None" not in msg["name"] assert msg["mod"] == "faf" assert msg["expected_players"] == 4 @@ -157,7 +157,7 @@ async def test_game_matchmaking_multiqueue(lobby_server): uid = set(msg["uid"] for msg in msgs) assert len(uid) == 1 for msg in msgs: - assert msg["init_mode"] == 1 + assert msg["game_type"] == "matchmaker" assert "None" not in msg["name"] assert msg["mod"] == "faf" assert msg["expected_players"] == 4 @@ -237,7 +237,7 @@ async def test_game_matchmaking_with_parties(lobby_server): uid = set(msg["uid"] for msg in msgs) assert len(uid) == 1 for i, msg in enumerate(msgs): - assert msg["init_mode"] == 1 + assert msg["game_type"] == "matchmaker" assert "None" not in msg["name"] assert msg["mod"] == "faf" assert msg["expected_players"] == 4 @@ -305,7 +305,7 @@ async def test_newbie_matchmaking_with_parties(lobby_server): uid = set(msg["uid"] for msg in msgs) assert len(uid) == 1 for msg in msgs: - assert msg["init_mode"] == 1 + assert msg["game_type"] == "matchmaker" assert "None" not in msg["name"] assert msg["mod"] == "faf" assert msg["expected_players"] == 4 diff --git a/tests/unit_tests/test_lobbyconnection.py b/tests/unit_tests/test_lobbyconnection.py index 9492a5831..ac4d06221 100644 --- a/tests/unit_tests/test_lobbyconnection.py +++ b/tests/unit_tests/test_lobbyconnection.py @@ -11,7 +11,7 @@ from server.exceptions import BanError, ClientError from server.game_service import GameService from server.gameconnection import GameConnection -from server.games import CustomGame, Game, GameState, InitMode, VisibilityState +from server.games import CustomGame, Game, GameState, GameType, VisibilityState from server.geoip_service import GeoIpService from server.ice_servers.nts import TwilioNTS from server.ladder_service import LadderService @@ -315,7 +315,6 @@ async def test_command_game_join_calls_join_game( "uid": 42, "mod": "faf", "name": "Test Game Name", - "init_mode": InitMode.NORMAL_LOBBY.value, "game_type": "custom", "rating_type": "global", } @@ -355,7 +354,6 @@ async def test_command_game_join_uid_as_str( "mod": "faf", "uid": 42, "name": "Test Game Name", - "init_mode": InitMode.NORMAL_LOBBY.value, "game_type": "custom", "rating_type": "global", } @@ -374,7 +372,7 @@ async def test_command_game_join_without_password( lobbyconnection.game_service = game_service game = mock.create_autospec(Game) game.state = GameState.LOBBY - game.init_mode = InitMode.NORMAL_LOBBY + game.game_type = GameType.CUSTOM game.password = "password" game.game_mode = "faf" game.id = 42 @@ -419,7 +417,7 @@ async def test_command_game_join_game_not_found( }) -async def test_command_game_join_game_bad_init_mode( +async def test_command_game_join_matchmaker_game( lobbyconnection, game_service, test_game_info, @@ -429,7 +427,7 @@ async def test_command_game_join_game_bad_init_mode( lobbyconnection.game_service = game_service game = mock.create_autospec(Game) game.state = GameState.LOBBY - game.init_mode = InitMode.AUTO_LOBBY + game.game_type = GameType.MATCHMAKER game.id = 42 game.host = players.hosting game_service._games[42] = game