44from tests .utils import fast_forward
55
66from .conftest import connect_and_sign_in , read_until_command
7- from .test_game import open_fa , queue_players_for_matchmaking , start_search
7+ from .test_game import (
8+ client_response ,
9+ open_fa ,
10+ queue_players_for_matchmaking ,
11+ send_player_options ,
12+ start_search
13+ )
814from .test_parties import accept_party_invite , invite_to_party
15+ from .test_teammatchmaker import \
16+ queue_players_for_matchmaking as queue_players_for_matchmaking_2v2
917
1018
1119@fast_forward (360 )
@@ -18,8 +26,7 @@ async def test_violation_for_guest_timeout(mocker, lobby_server):
1826
1927 # The player that queued last will be the host
2028 async def launch_game_and_timeout_guest ():
21- await read_until_command (host , "game_launch" )
22- await open_fa (host )
29+ await client_response (host , timeout = 60 )
2330 await read_until_command (host , "game_info" )
2431
2532 await read_until_command (guest , "game_launch" )
@@ -110,6 +117,64 @@ async def launch_game_and_timeout_guest():
110117 }
111118
112119
120+ @fast_forward (360 )
121+ async def test_violation_for_guest_connected_to_host (mocker , lobby_server ):
122+ mock_now = mocker .patch (
123+ "server.ladder_service.violation_service.datetime_now" ,
124+ return_value = datetime (2022 , 2 , 5 , tzinfo = timezone .utc )
125+ )
126+ protos , ids = await queue_players_for_matchmaking_2v2 (lobby_server )
127+ host , guest1 , guest2 , guest3 = protos
128+ host_id , guest1_id , guest2_id , guest3_id = ids
129+
130+ # Connect all players to the host
131+ await asyncio .gather (* [
132+ client_response (proto , timeout = 60 )
133+ for proto in protos
134+ ])
135+ await send_player_options (
136+ host ,
137+ [host_id , "Color" , 1 ],
138+ [guest1_id , "Color" , 2 ],
139+ [guest2_id , "Color" , 3 ],
140+ [guest3_id , "Color" , 4 ],
141+ )
142+
143+ # Set up connection matrix
144+ # Guest3 only connects to the host
145+ for id in (guest1_id , guest2_id , guest3_id ):
146+ await host .send_message ({
147+ "target" : "game" ,
148+ "command" : "EstablishedPeer" ,
149+ "args" : [id ],
150+ })
151+ for id in (host_id , guest2_id ):
152+ await guest1 .send_message ({
153+ "target" : "game" ,
154+ "command" : "EstablishedPeer" ,
155+ "args" : [id ],
156+ })
157+ for id in (host_id , guest1_id ):
158+ await guest2 .send_message ({
159+ "target" : "game" ,
160+ "command" : "EstablishedPeer" ,
161+ "args" : [id ],
162+ })
163+ await guest3 .send_message ({
164+ "target" : "game" ,
165+ "command" : "EstablishedPeer" ,
166+ "args" : [guest3_id ],
167+ })
168+
169+ await read_until_command (host , "match_cancelled" , timeout = 120 )
170+ msg = await read_until_command (guest3 , "search_violation" , timeout = 10 )
171+ assert msg == {
172+ "command" : "search_violation" ,
173+ "count" : 1 ,
174+ "time" : "2022-02-05T00:00:00+00:00" ,
175+ }
176+
177+
113178@fast_forward (360 )
114179async def test_violation_persisted_across_logins (mocker , lobby_server ):
115180 mocker .patch (
0 commit comments