diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index e9e96c9..2df028b 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -100,22 +100,22 @@ export class GeneralRoom extends Room { } //TODO: 掉线逻辑 async onLeave (client: Client, consented: boolean) { - // this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE; - // - // try { - // if (consented) { - // throw new Error("consented leave"); - // } - // await this.allowReconnection(client, 60); - // this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL; - // - // } catch (e) { - // this.state.players.delete(client.sessionId); - // } - //TODO: 检查重新开始后, gameState if (this.state.gameState === GameStateConst.STATE_GAME_OVER) { - this.state.players.delete(client.id); - this.bUserLeft(client.id); + this.state.players.delete(client.sessionId); + this.bUserLeft(client.sessionId); + } else { + this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE; + try { + if (consented) { + throw new Error("consented leave"); + } + await this.allowReconnection(client, 60); + this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_NORMAL; + + } catch (e) { + debugRoom(`player realy level :${client.sessionId}`); + this.state.players.delete(client.sessionId); + } } } @@ -209,8 +209,8 @@ export class GeneralRoom extends Room { } } - addRobot() { - const sessionId = generateId(); + addRobot(playerId?: string) { + const sessionId = playerId || generateId(); let client = new RobotClient(sessionId, this.state, this.clock, this['onMessageHandlers']); if (this.reservedSeatTimeouts[sessionId]) { clearTimeout(this.reservedSeatTimeouts[sessionId]); diff --git a/src/rooms/commands/GMCommand.ts b/src/rooms/commands/GMCommand.ts index 2e03700..37834e7 100644 --- a/src/rooms/commands/GMCommand.ts +++ b/src/rooms/commands/GMCommand.ts @@ -2,6 +2,7 @@ import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import {debugRoom, error} from "../../common/Debug"; +import {GameResultCommand} from "./GameResultCommand"; export class GMCommand extends Command { @@ -28,6 +29,9 @@ export class GMCommand extends Command { this.room.bGameResult(resultData); this.state.updateGameState(GameStateConst.STATE_GAME_OVER); - this.resetAllState(); //启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private let self = this; let resultTimeOver = async function () { @@ -96,6 +95,7 @@ export class GameResultCommand extends Command { } let time = singleton(GameEnv).gameResultTime * 1000; this.room.beginSchedule(time, resultTimeOver, 'restart_schedule'); + this.resetAllState(); } /**