增加房间认证代码

This commit is contained in:
zhl 2020-12-08 11:34:05 +08:00
parent 3288cb74a0
commit 1a3117a2ad
2 changed files with 27 additions and 4 deletions

View File

@ -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() {

View File

@ -35,6 +35,7 @@ export class Player extends Schema {
* 1: 已准备好
* 2: 死亡
* 3: 已换完牌
* 4: 玩家已选择英雄
* 9: 掉线
*/
@type("number")