refactor(matchmaking): migrate Python simulator to native Nakama matchmaker

### 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`.
This commit is contained in:
2025-11-26 16:35:19 +05:30
parent ea1a70b212
commit bd376123b3
2 changed files with 41 additions and 31 deletions

View File

@@ -118,17 +118,27 @@ class PlayerWebSocketHandler(WebSocketHandler):
print(f"[{self.label}] UNKNOWN OPCODE {op}: {payload}")
# ---------- Match Helpers ----------
def rpc_find_match(self) -> str:
"""Call rpc_find_match and return Nakama match_id."""
r = requests.post(
f"{HOST}/v2/rpc/rpc_find_match",
headers={"Authorization": f"Bearer {self.token}"},
)
r.raise_for_status()
async def join_matchmaking(self, mode: str = "classic"):
"""Queue into Nakama matchmaker."""
await self.ws.send(json.dumps({
"matchmaker_add": {
"min_count": 2,
"max_count": 2,
"string_properties": {
"mode": mode
}
}
}))
print(f"[{self.label}] Searching match for mode={mode}...")
# RPC returns {"payload": "<json string>"}
payload = json.loads(r.json()["payload"])
return payload["match_id"]
async def leave_matchmaking(self, ticket: str):
"""Remove player from Nakama matchmaking queue."""
await self.ws.send(json.dumps({
"matchmaker_remove": {
"ticket": ticket
}
}))
print(f"[{self.label}] Left matchmaking queue")
async def create_match(self) -> str:
await self.ws.send(json.dumps({"match_create": {}}))