import { CardConfig } from '../Config/CardConfig'; import { CardClientWebSocket } from '../Net/CardClientWebSocket'; import { CardRoomManager } from './Room/CardRoomManager'; import { CardRobotManager } from './Robot/CardRobotManager'; import { SeatManager } from './Table/SeatManager'; import { TableManager } from './Table/TableManager'; import { GMWebServer } from './GMWebServer'; import { ISocketServer } from 'cgserver'; import { IClientWebSocket } from 'cgserver'; export class CardServer extends ISocketServer { protected _tableMgr:TableManager=null get tableMgr() { return this._tableMgr } protected _seatMgr:SeatManager=null get seatMgr() { if(!this._seatMgr) { this._seatMgr = new SeatManager() } return this._seatMgr } protected _robotMgr:CardRobotManager=null get robotMgr() { return this._robotMgr } protected _room_mgr:CardRoomManager=null get roomMgr() { return this._room_mgr } protected _cfg:CardConfig=null //方便提示 get cfg() { return this._cfg } protected _gmserver:GMWebServer=null protected _userid_to_socketid=new Map() constructor(table_cls,servername,cfg:CardConfig) { super(servername) this._cfg=cfg this.listenPort=this._cfg.port this._tableMgr = new TableManager(table_cls,this) } onListenning() { super.onListenning() if(!this._gmserver&&this.cfg.gmcfg) { this._gmserver=new GMWebServer(this) this._gmserver.start() } } addUserId(user_id:number,socket_id:number) { this._userid_to_socketid[user_id] = socket_id } removeUserId(user_id:number) { this._userid_to_socketid[user_id] = null delete this._userid_to_socketid[user_id] } getWebSocketByUserId(user_id:number):CardClientWebSocket { let si = this._userid_to_socketid[user_id] if(!si) { return } return this._ws_clients[si] as CardClientWebSocket } broadCast(msg:any) { for(var key in this._ws_clients) { let ws = this._ws_clients[key] as CardClientWebSocket ws.send(msg) } } //方便提示 getAnyWebSocket() { for(var key in this._ws_clients) { return this._ws_clients[key] as CardClientWebSocket } return null } }