diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-03-19 19:14:09 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-03-19 19:14:09 +0100 |
commit | 2f22a0f87dcf8c00ffedc57a69838e13519abefc (patch) | |
tree | ea5796ac9c10c07c0522f5c12a0716b788a73db4 /api | |
parent | 38f22113d3d97f99125ebdafba4aedafc5780987 (diff) |
prefix room name with id type + use socket context in pages/game
Diffstat (limited to 'api')
-rw-r--r-- | api/events.py | 2 | ||||
-rw-r--r-- | api/game/random.py | 2 | ||||
-rw-r--r-- | api/game/socket.py | 11 |
3 files changed, 8 insertions, 7 deletions
diff --git a/api/events.py b/api/events.py index b7b8ab4..8974666 100644 --- a/api/events.py +++ b/api/events.py @@ -24,5 +24,5 @@ def connect(): user_id = token_login(token) if not user_id: return - join_room(user_id) + join_room("user-" + user_id) diff --git a/api/game/random.py b/api/game/random.py index 8d730ad..54ab2a8 100644 --- a/api/game/random.py +++ b/api/game/random.py @@ -41,7 +41,7 @@ def index(): players = cursor.execute("select player_1_id, player_2_id from games where game_id = ?", [game_id]).fetchone() games[game_id] = game(game_id, io, players[0], players[1]) - io.emit("gameStart", room=game_id) + io.emit("gameStart", room=games[game_id].room) player_1 = False game_started = True diff --git a/api/game/socket.py b/api/game/socket.py index 6f1112a..60fea00 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -12,6 +12,7 @@ games = {} class game: def __init__(self, game_id, io, player_1_id, player_2_id): self.game_id = game_id + self.room = "game-" + game_id self.board = bord(7, 6) self.io = io self.player_1_id = player_1_id @@ -23,7 +24,7 @@ class game: if user_id != move: return self.board.drop_fisje(column) - io.emit("fieldUpdate", { "field": self.board.board }, room=self.game_id) + io.emit("fieldUpdate", { "field": self.board.board }, room=self.room) now = int( time.time() * 1000 ) cursor.execute("update games set last_activity = ?, moves = moves || ? || ',' where game_id = ?", [now, column, self.game_id]) @@ -37,15 +38,15 @@ class game: io.emit("finish", { "winPositions": self.board.win_positions, "boardFull": self.board.board_full - }, room=self.game_id) + }, room=self.room) self.close("finished", outcome) return - io.emit("turnUpdate", { "player1": self.board.player_1 }, room=self.game_id) + io.emit("turnUpdate", { "player1": self.board.player_1 }, room=self.room) def resign(self): self.board.kill_voerbak() - io.emit("resign", room=self.game_id) + io.emit("resign", room=self.room) self.close("resign", "d") def close(self, new_status, outcome): @@ -98,5 +99,5 @@ def register_game_listener(data): game_id = data.get("game_id") if not game_id: return - join_room(game_id) + join_room("game-" + game_id) |