Skip to content

Commit

Permalink
Remove InitMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Dec 19, 2021
1 parent f7f6074 commit 32f2e5b
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 36 deletions.
2 changes: 0 additions & 2 deletions server/games/__init__.py
Expand Up @@ -13,7 +13,6 @@
GameConnectionState,
GameState,
GameType,
InitMode,
ValidityState,
Victory,
VisibilityState
Expand All @@ -39,7 +38,6 @@ class FeaturedMod(NamedTuple):
"GameError",
"GameState",
"GameType",
"InitMode",
"LadderGame",
"ValidityState",
"Victory",
Expand Down
3 changes: 1 addition & 2 deletions 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):
Expand Down
3 changes: 1 addition & 2 deletions server/games/custom_game.py
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions server/games/game.py
Expand Up @@ -36,7 +36,6 @@
GameConnectionState,
GameState,
GameType,
InitMode,
ValidityState,
Victory,
VisibilityState
Expand All @@ -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__(
Expand Down
4 changes: 1 addition & 3 deletions server/games/ladder_game.py
Expand Up @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions server/games/typedefs.py
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions server/ladder_service.py
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
6 changes: 2 additions & 4 deletions server/lobbyconnection.py
Expand Up @@ -40,7 +40,7 @@
FeaturedModType,
GameConnectionState,
GameState,
InitMode,
GameType,
VisibilityState
)
from .geoip_service import GeoIpService
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Expand Up @@ -25,7 +25,7 @@
CoopGame,
FeaturedModType,
Game,
InitMode,
GameType,
ValidityState
)
from server.geoip_service import GeoIpService
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/test_matchmaker.py
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_tests/test_teammatchmaker.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions tests/unit_tests/test_lobbyconnection.py
Expand Up @@ -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
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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",
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 32f2e5b

Please sign in to comment.