From 1a3117a2ad698d65e5c8db6cd583f606dec7e414 Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 8 Dec 2020 11:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=BF=E9=97=B4=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 30 ++++++++++++++++++++++++++---- src/rooms/schema/Player.ts | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index f9b6d98..edbbfb5 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -13,6 +13,9 @@ import {GiveUpCommand} from "./commands/GiveUpCommand"; import {BattleHandler} from "./logic/Handler/BattleHandler"; import {debugRoom} from "../common/Debug"; import {Delayed} from "@gamestdio/timer/lib/Delayed"; +import {IncomingMessage} from "http"; +import {BaseConst} from "../constants/BaseConst"; +import {PlayerStateConst} from "../constants/PlayerStateConst"; export class GeneralRoom extends Room { @@ -22,7 +25,13 @@ export class GeneralRoom extends Room { battleMan = new BattleHandler(); // 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家 mainClock: Delayed; - + async onAuth (client:Client, options: any, request: IncomingMessage) { + console.log(options); + // TODO: 验证用户信息 + // client.auth.accountId = options.accountId; + // client.auth.sessionId = options.sessionId; + return true; + } onCreate (options: any) { let cs = new CardGameState(); this.setState(cs); @@ -72,13 +81,26 @@ export class GeneralRoom extends Room { } onJoin (client: Client, options: any) { - this.dispatcher.dispatch(new OnJoinCommand(), { + let data = { client: client - }); + }; + this.dispatcher.dispatch(new OnJoinCommand(), data); this.clientMap.set(client.sessionId, client); } + //TODO: 掉线逻辑 + async onLeave (client: Client, consented: boolean) { + this.state.players.get(client.sessionId).state = PlayerStateConst.PLAYER_OFFLINE; - onLeave (client: Client, consented: boolean) { + 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); + } } onDispose() { diff --git a/src/rooms/schema/Player.ts b/src/rooms/schema/Player.ts index 338c3e1..9097fe4 100644 --- a/src/rooms/schema/Player.ts +++ b/src/rooms/schema/Player.ts @@ -35,6 +35,7 @@ export class Player extends Schema { * 1: 已准备好 * 2: 死亡 * 3: 已换完牌 + * 4: 玩家已选择英雄 * 9: 掉线 */ @type("number")