From d67904fe34186ac3f4a5ea5082b97e290a0f755b Mon Sep 17 00:00:00 2001 From: jhalitaksoy Date: Sun, 4 Jul 2021 01:05:36 +0300 Subject: [PATCH] now sending message when user leaves the game --- src/channel_names.ts | 3 ++- src/index.ts | 8 ++++---- src/mancala.ts | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/channel_names.ts b/src/channel_names.ts index 75baf27..e31f373 100644 --- a/src/channel_names.ts +++ b/src/channel_names.ts @@ -4,4 +4,5 @@ export const channel_game_move = "game_move" export const channel_on_game_update = "on_game_update" export const channel_leave_game = "leave_game" export const channel_on_game_end = "on_game_end" -export const channel_on_game_crashed = "on_game_crashed" \ No newline at end of file +export const channel_on_game_crashed = "on_game_crashed" +export const channel_on_game_user_leave = "on_game_user_leave" \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 408a33d..913659b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { RTMTWS } from "./rtmt/rtmt_websocket"; import cors from "cors" import { generateKey } from "./key_factory"; import { MatchMaker } from "./matcmaker"; -import { channel_game_move, channel_leave_game, channel_new_game, channel_on_game_crashed, channel_on_game_start, channel_on_game_update } from "./channel_names"; +import { channel_game_move, channel_leave_game, channel_new_game, channel_on_game_crashed, channel_on_game_start, channel_on_game_update, channel_on_game_user_leave } from "./channel_names"; import { Bytes } from "./rtmt/rtmt"; import { createGame, Game, GameMove } from "./mancala"; @@ -87,9 +87,9 @@ rtmt.listenMessage(channel_leave_game, (userKey: string, message: Bytes) => { const game = gameStore.get(userKey) if (game) { deleteGame(game) - const data = encodeText(JSON.stringify(game)) - rtmt.sendMessage(game.player1, channel_on_game_update, data) - rtmt.sendMessage(game.player2, channel_on_game_update, data) + const data = encodeText(userKey) + rtmt.sendMessage(game.player1, channel_on_game_user_leave, data) + rtmt.sendMessage(game.player2, channel_on_game_user_leave, data) } }) diff --git a/src/mancala.ts b/src/mancala.ts index 5fd5e50..5eee132 100644 --- a/src/mancala.ts +++ b/src/mancala.ts @@ -14,7 +14,6 @@ export class Game { } public moveByIndex(holeIndex: number, player: "player1" | "player2") { - throw new Error("afdad") let hole = this.board.player1Holes[holeIndex] if (player == "player2") {