basic matchmaking flow
This commit is contained in:
46
match_making_flow.py
Normal file
46
match_making_flow.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import asyncio
|
||||
from game_flow import PlayerWebSocketHandler
|
||||
|
||||
|
||||
async def simulate_matchmaking(num_players: int = 6):
|
||||
print(f"\n🎮 Spawning {num_players} players...\n")
|
||||
|
||||
# 1) Login + WebSocket connect (NO listener yet!)
|
||||
players = await asyncio.gather(*[
|
||||
PlayerWebSocketHandler.setup_player(f"player_{i}")
|
||||
for i in range(num_players)
|
||||
])
|
||||
|
||||
print("\n✅ All players authenticated + connected\n")
|
||||
|
||||
# 2) First player requests match via RPC
|
||||
p1 = players[0]
|
||||
match_id = p1.rpc_find_match()
|
||||
print(f"\n🎯 Match allocated: {match_id}\n")
|
||||
|
||||
# 3) Everyone joins the same match
|
||||
await asyncio.gather(*[
|
||||
p.join_match(match_id) for p in players
|
||||
])
|
||||
|
||||
print("\n✅ All players joined match\n")
|
||||
|
||||
# 4) NOW start websocket listeners (prevents recv race)
|
||||
for p in players:
|
||||
p.start_listener()
|
||||
|
||||
print("\n👂 Listening for match state + updates...\n")
|
||||
|
||||
# 5) Keep test running long enough to observe messages
|
||||
await asyncio.sleep(10)
|
||||
|
||||
# 6) Cleanup
|
||||
await asyncio.gather(*[
|
||||
p.close() for p in players
|
||||
])
|
||||
|
||||
print("\n🏁 Simulation complete\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(simulate_matchmaking(6))
|
||||
Reference in New Issue
Block a user