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

Only tell authenticated clients about matchmaker info #466

Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def report_dirties():
player_service.clear_dirty()

if len(dirty_queues) > 0:
ctx.broadcast_raw(encode_queues(dirty_queues))
ctx.broadcast_raw(encode_queues(dirty_queues), lambda lobby_conn: lobby_conn.authenticated)

if len(dirty_players) > 0:
ctx.broadcast_raw(encode_players(dirty_players), lambda lobby_conn: lobby_conn.authenticated)
Expand Down
4 changes: 2 additions & 2 deletions server/matchmaker/matchmaker_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def queue_pop_timer(self) -> None:

self.game_service.mark_dirty(self)

def time_until_next_pop(self) -> int:
def time_until_next_pop(self) -> float:
""" Calculate how long we should wait for the next queue to pop based
on a moving average of the amount of people in the queue.

Expand All @@ -93,7 +93,7 @@ def time_until_next_pop(self) -> int:
x = mean(self.last_queue_amounts)
self._logger.debug("Moving average of %s queue size: %f", self.queue_name, x)
# Essentially y = max_time / (x+1) with a scale factor
return int(config.QUEUE_POP_TIME_MAX / (x / config.QUEUE_POP_TIME_SCALE_FACTOR + 1))
return config.QUEUE_POP_TIME_MAX / (x / config.QUEUE_POP_TIME_SCALE_FACTOR + 1)

async def search(self, search: Search) -> None:
"""
Expand Down
4 changes: 1 addition & 3 deletions tests/integration_tests/test_matchmaker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import asyncio

from server import config

from .conftest import connect_and_sign_in, read_until_command

# Need to save the old sleep here otherwise the mocker recursively patches it
Expand Down Expand Up @@ -62,7 +60,7 @@ async def test_game_matchmaking(loop, lobby_server, mocker):

async def test_matchmaker_info_message(lobby_server, mocker):
mocker.patch('server.matchmaker.matchmaker_queue.time', return_value=1_562_000_000)
mocker.patch('server.matchmaker.matchmaker_queue.config.QUEUE_POP_TIME_MAX', return_value=1)
mocker.patch('server.matchmaker.matchmaker_queue.config.QUEUE_POP_TIME_MAX', 1)
Rackover marked this conversation as resolved.
Show resolved Hide resolved

_, _, proto = await connect_and_sign_in(
('ladder1', 'ladder1'),
Expand Down
25 changes: 25 additions & 0 deletions tests/integration_tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

import pytest
from server import VisibilityState

Expand Down Expand Up @@ -104,6 +106,29 @@ async def test_player_info_broadcast(loop, lobby_server):
p2.close()


@pytest.mark.slow
async def test_info_broadcast_authenticated(loop, lobby_server):
proto1 = await connect_client(lobby_server)
proto2 = await connect_client(lobby_server)
proto3 = await connect_client(lobby_server)

await perform_login(proto1, ('test', 'test_password'))
await perform_login(proto2, ('Rhiza', 'puff_the_magic_dragon'))
Askaholic marked this conversation as resolved.
Show resolved Hide resolved
proto1.send_message({
"command": "game_matchmaking",
"state": "start",
"mod": "ladder1v1",
"faction": "uef"
})
await proto1.drain()
# Will timeout if the message is never received
await read_until_command(proto2, "matchmaker_info")
with pytest.raises(asyncio.TimeoutError):
await asyncio.wait_for(proto3.read_message(), 0.2)
# Unauthenticated connections should not receive the message
assert False


@pytest.mark.slow
async def test_public_host(loop, lobby_server, player_service):
# TODO: This test can't fail, why is it here?
Expand Down