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:
30
game_flow.py
30
game_flow.py
@@ -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": {}}))
|
||||
|
||||
Reference in New Issue
Block a user