private Dictionary <Socket, string> _socketDic = new Dictionary <Socket, string>(); //key : socket, value : account public void AddNewConnectionInfo(string account, Socket socket) { if (!_accountsInfoDic.ContainsKey(account)) { _accountsInfoDic[account] = new AccountConnectionInfo { PhaseState = AccountPhaseState.LOBBY, OrigSocket = socket }; _socketDic[socket] = account; } }
public AccountConnectionInfo GetAccountConnectionInfo(string account) { AccountConnectionInfo result = null; if (_accountsInfoDic.ContainsKey(account)) { result = _accountsInfoDic[account]; } return(result); }
private Socket GetPlayerSocket(string account) { Socket result = null; AccountConnectionInfo info = Singleton <AccountConnectionManager> .Instance.GetAccountConnectionInfo(account); if (info != null) { result = info.OrigSocket; } return(result); }
public void EnterNewPlayer(string account) { Console.WriteLine("玩家" + account + "进入" + _roomId + "房间!"); _playerInfoDic.Add(account, new PlayerInfoInRoom()); //TODO TESTAREA // _accountList.Add("robot1"); // _accountList.Add("robot2"); //TODO END NEED DELETE //更新账号连接信息,调整为进入房间状态 Singleton <AccountConnectionManager> .Instance.OnEnterRoom(account, _roomId); //通知客户端进入游戏房间,非新玩家的广播进入新玩家消息,新玩家发送房间玩家列表信息 foreach (var p in _playerInfoDic) { AccountConnectionInfo connectionInfo = Singleton <AccountConnectionManager> .Instance.GetAccountConnectionInfo(p.Key); if (connectionInfo == null) { continue; } Socket socket = connectionInfo.OrigSocket; //除进房间的新玩家外,其余玩家收到新玩家进入房间的消息 if (p.Key != account) { AckNewPlayerEnterRoom msg = new AckNewPlayerEnterRoom(); msg.PlayerInfo = new PlayerInfo(); msg.PlayerInfo.Seat = _playerInfoDic.Count - 1; msg.PlayerInfo.AccountName = account; msg.PlayerInfo.CoinNum = 9999; Singleton <NetworkManager> .Instance.SendMsg(socket, MessageDefine.G2C_NEW_PLAYER_ENTER_ROOM, msg); } //新进房间的玩家收到房间玩家列表信息 else { AckEnterRoomResult msg = new AckEnterRoomResult(); int seat = 0; foreach (var kv in _playerInfoDic) { PlayerInfo pInfo = new PlayerInfo(); pInfo.Seat = seat; pInfo.AccountName = kv.Key; pInfo.CoinNum = 9999; msg.PlayerInfos.Add(pInfo); seat++; } Singleton <NetworkManager> .Instance.SendMsg(socket, MessageDefine.G2C_ENTER_ROOM, msg); } } }