get client方法可传string或者player对象

This commit is contained in:
zhl 2020-12-09 14:12:37 +08:00
parent 393afe0bfa
commit dbeeec1d00
2 changed files with 10 additions and 4 deletions

5
src/global.d.ts vendored
View File

@ -7,6 +7,7 @@ import {PartResultMsg} from "./message/PartResult";
import {RemovePetMsg} from "./message/RemovePetMsg";
import {Dispatcher} from "@colyseus/command";
import {Delayed} from "@gamestdio/timer/lib/Delayed";
import {Player} from "./rooms/schema/Player";
export {};
@ -30,9 +31,9 @@ declare module "colyseus" {
mainClock: Delayed;
/**
* sessionId获取client
* @param sessionId
* @param player id或者玩家的对象
*/
getClient(sessionId: string): Client;
getClient(player: string | Player): Client;
// >>>>>>>>> Begin of extend send message <<<<<<<<<<<<<
/**
* 广

View File

@ -14,6 +14,7 @@ import {debugRoom, error, msgLog} from "../common/Debug";
import {Delayed} from "@gamestdio/timer/lib/Delayed";
import {IncomingMessage} from "http";
import {PlayerStateConst} from "../constants/PlayerStateConst";
import {Player} from "./schema/Player";
export class GeneralRoom extends Room {
@ -105,8 +106,12 @@ export class GeneralRoom extends Room {
this.dispatcher.stop();
}
getClient(sessionId: string) {
return this.clients.find(client => client.sessionId == sessionId );
getClient(player: string | Player) {
if (typeof player == 'string') {
return this.clients.find(client => client.sessionId == player );
} else {
return this.clients.find(client => client.sessionId == player.id );
}
}
/**