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

v2 - Remove Deprecations #816

Merged
merged 9 commits into from
Jan 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN python3 -m pip install -e .
# Main entrypoint and the default command that will be run
CMD ["/usr/local/bin/python3", "server.py"]

# lobby server runs on 8001/tcp (QDataStream) and 8002/tcp (JSON)
EXPOSE 8001 8002
# lobby server runs on 8002/tcp (JSON)
EXPOSE 8002

RUN python3 -V
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,8 @@ You can find an example configuration file under
The protocol is mainly JSON-encoded maps, containing at minimum a `command` key,
representing the command to dispatch.

The wire format uses [QDataStream](http://doc.qt.io/qt-5/qdatastream.html) (UTF-16, BigEndian).

For the lobbyconnection, each message is of the form:

ACTION: QString

With most carrying a footer containing:

LOGIN: QString
SESSION: QString

## Incoming Packages

##### Mod Vault

* `{command: modvault, type: start}`: show the last 100 mods
* `{command: modvault, type: like, uid: <uid>}`: check if user liked the mod, otherwise increase the like counter
* `{command: modvault, type: download, uid: <uid>}`: notify server about a download (for download counter), does not start the download

##### Social
* `{command: social_add, friend|foe: <player_id>}`: Add a friend or foe
* `{command: social_remove, friend|foe: <player_id>}`: Remove a friend or foe
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Manager():
def __init__(self):
self.clients = []

async def add_client(self, host="test.faforever.com", port=8001):
async def add_client(self, host="test.faforever.com", port=8002):
client = FAFClient()
await client.connect(host, port)
self.clients.append(client)
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/fafclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
from hashlib import sha256

from server.protocol import QDataStreamProtocol
from server.protocol import SimpleJsonProtocol
from tests.integration_tests.conftest import read_until, read_until_command


Expand All @@ -29,7 +29,7 @@ async def close(self):
await self.proto.close()

async def connect(self, host, port):
self.proto = QDataStreamProtocol(
self.proto = SimpleJsonProtocol(
*(await asyncio.open_connection(host, port))
)

Expand Down Expand Up @@ -91,8 +91,8 @@ async def login(self, username, password):
"unique_id": unique_id
})
msg = await self.read_until_command("welcome")
self.player_id = msg["id"]
self.player_name = msg["login"]
self.player_id = msg["me"]["id"]
self.player_name = msg["me"]["login"]
return msg

def get_unique_id(self, session):
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ async def test_user_existence(client_factory, username):
"""Verify that these users exist on the test server"""
client, welcome_message = await client_factory.login(username, "foo")

assert welcome_message["login"] == welcome_message["me"]["login"] == username
assert welcome_message["id"] == welcome_message["me"]["id"]
assert welcome_message["me"]["login"] == username
assert client.is_connected()
4 changes: 1 addition & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from server.ice_servers.nts import TwilioNTS
from server.player_service import PlayerService
from server.profiler import Profiler
from server.protocol import SimpleJsonProtocol


async def main():
Expand Down Expand Up @@ -109,8 +108,7 @@ async def restart_control_server():
)
config.register_callback("CONTROL_SERVER_PORT", restart_control_server)

await instance.listen(("", 8001))
await instance.listen(("", 8002), SimpleJsonProtocol)
await instance.listen(("", 8002))

server.metrics.info.info({
"version": version,
Expand Down
4 changes: 2 additions & 2 deletions server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
from .oauth_service import OAuthService
from .party_service import PartyService
from .player_service import PlayerService
from .protocol import Protocol, QDataStreamProtocol
from .protocol import Protocol, SimpleJsonProtocol
from .rating_service.rating_service import RatingService
from .servercontext import ServerContext
from .stats.game_stats_service import GameStatsService
Expand Down Expand Up @@ -245,7 +245,7 @@ async def initialize(service):
async def listen(
self,
address: tuple[str, int],
protocol_class: type[Protocol] = QDataStreamProtocol
protocol_class: type[Protocol] = SimpleJsonProtocol
) -> ServerContext:
"""
Start listening on a new address.
Expand Down
2 changes: 0 additions & 2 deletions server/games/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
7 changes: 0 additions & 7 deletions server/games/typedefs.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -218,7 +212,6 @@ class FA(object):
"GameConnectionState",
"GameState",
"GameType",
"InitMode",
"TeamRatingSummary",
"ValidityState",
"Victory",
Expand Down
41 changes: 14 additions & 27 deletions server/ladder_service.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -470,36 +469,24 @@ def game_options(player: Player) -> GameLaunchOptions:
map_position=game.get_player_option(player.id, "StartSpot")
)

# Tell the host to launch
await host.lobby_connection.launch_game(
game, is_host=True, options=game_options(host)
)
try:
await game.wait_hosted(60)
finally:
# TODO: Once the client supports `match_cancelled`, don't
# send `launch_game` to the client if the host timed out. Until
# then, failing to send `launch_game` will cause the client to
# think it is searching for ladder, even though the server has
# already removed it from the queue.

await asyncio.gather(*[
guest.lobby_connection.launch_game(
game, is_host=False, options=game_options(guest)
)
for guest in all_guests
if guest.lobby_connection is not None
])
await game.wait_launched(60 + 10 * len(all_guests))
self._logger.debug("Ladder game launched successfully %s", game)
except Exception as e:
if isinstance(e, asyncio.TimeoutError):
self._logger.info(
"Ladder game failed to start! %s setup timed out",
game
await game.wait_hosted(60)

# Tell the guests to launch
await asyncio.gather(*[
guest.lobby_connection.launch_game(
game, is_host=False, options=game_options(guest)
)
else:
self._logger.exception("Ladder game failed to start %s", game)
for guest in all_guests
if guest.lobby_connection is not None
])
await game.wait_launched(60 + 10 * len(all_guests))

self._logger.debug("Ladder game launched successfully %s", game)
except Exception:
if game:
await game.on_game_end()

Expand Down