### Summary Replaced legacy RPC-based matchmaking flow with proper WebSocket-driven matchmaker integration. Player simulation now queues via `matchmaker_add`, auto-joins matches on `matchmaker_matched`, and no longer depends on `rpc_find_match`.
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import asyncio
|
|
from game_flow import PlayerWebSocketHandler
|
|
|
|
|
|
async def simulate_matchmaking(num_players: int = 6, mode: str = "classic"):
|
|
print(f"\n🎮 Spawning {num_players} players...\n")
|
|
|
|
# 1) Login + WebSocket connect
|
|
players = await asyncio.gather(*[
|
|
PlayerWebSocketHandler.setup_player(f"player_{i}")
|
|
for i in range(num_players)
|
|
])
|
|
|
|
print("\n✅ All players authenticated + connected\n")
|
|
|
|
# 2) Start listeners BEFORE matchmaking
|
|
for p in players:
|
|
p.start_listener()
|
|
|
|
print("\n👂 WebSocket listeners active\n")
|
|
|
|
await asyncio.sleep(0.3)
|
|
|
|
# 3) Queue all players in matchmaking
|
|
print(f"\n🎯 Queuing players for mode={mode}...\n")
|
|
|
|
await asyncio.gather(*[
|
|
p.join_matchmaking(mode)
|
|
for p in players
|
|
])
|
|
|
|
print("\n✅ All players queued — waiting for matches...\n")
|
|
|
|
# 4) Allow enough time for Nakama matchmaker to group players
|
|
await asyncio.sleep(12)
|
|
|
|
# 5) Cleanup
|
|
print("\n🧹 Closing player connections...\n")
|
|
await asyncio.gather(*[p.close() for p in players])
|
|
|
|
print("\n🏁 Matchmaking simulation complete\n")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(simulate_matchmaking(6))
|