now sending message when user leaves the game

This commit is contained in:
jhalitaksoy 2021-07-04 01:05:36 +03:00
parent 5a08e30df1
commit d67904fe34
3 changed files with 6 additions and 6 deletions

View File

@ -5,3 +5,4 @@ export const channel_on_game_update = "on_game_update"
export const channel_leave_game = "leave_game" export const channel_leave_game = "leave_game"
export const channel_on_game_end = "on_game_end" export const channel_on_game_end = "on_game_end"
export const channel_on_game_crashed = "on_game_crashed" export const channel_on_game_crashed = "on_game_crashed"
export const channel_on_game_user_leave = "on_game_user_leave"

View File

@ -5,7 +5,7 @@ import { RTMTWS } from "./rtmt/rtmt_websocket";
import cors from "cors" import cors from "cors"
import { generateKey } from "./key_factory"; import { generateKey } from "./key_factory";
import { MatchMaker } from "./matcmaker"; 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 { Bytes } from "./rtmt/rtmt";
import { createGame, Game, GameMove } from "./mancala"; import { createGame, Game, GameMove } from "./mancala";
@ -87,9 +87,9 @@ rtmt.listenMessage(channel_leave_game, (userKey: string, message: Bytes) => {
const game = gameStore.get(userKey) const game = gameStore.get(userKey)
if (game) { if (game) {
deleteGame(game) deleteGame(game)
const data = encodeText(JSON.stringify(game)) const data = encodeText(userKey)
rtmt.sendMessage(game.player1, channel_on_game_update, data) rtmt.sendMessage(game.player1, channel_on_game_user_leave, data)
rtmt.sendMessage(game.player2, channel_on_game_update, data) rtmt.sendMessage(game.player2, channel_on_game_user_leave, data)
} }
}) })

View File

@ -14,7 +14,6 @@ export class Game {
} }
public moveByIndex(holeIndex: number, player: "player1" | "player2") { public moveByIndex(holeIndex: number, player: "player1" | "player2") {
throw new Error("afdad")
let hole = this.board.player1Holes[holeIndex] let hole = this.board.player1Holes[holeIndex]
if (player == "player2") { if (player == "player2") {