private void BeginBattle(MatchState state) { BSInfo appropriateBSInfo = CS.instance.appropriateBSInfo; //没有找到合适的bs,通知客户端匹配失败 if (appropriateBSInfo == null) { this.NotifyGCEnterBattleFailed(state.users, Protos.CS2GC_EnterBattle.Types.Result.BsnotFound); return; } //todo 现在先随机一张地图 Random rnd = new Random(); int mapCount = Defs.GetMapCount(); int mapID = rnd.Next(0, mapCount); Protos.CS2BS_BattleInfo battleInfo = ProtoCreator.Q_CS2BS_BattleInfo(); battleInfo.MapID = mapID; battleInfo.ConnTimeout = ( int )Consts.WAITING_ROOM_TIME_OUT; for (int i = 0; i < state.numTeam; i++) { Protos.CS2BS_TeamInfo ti = new Protos.CS2BS_TeamInfo(); battleInfo.TeamInfos.Add(ti); MatchUser[] matchUsers = state.tUsers[i]; for (int j = 0; j < state.numUserPerTeam; j++) { MatchUser matchUser = matchUsers[j]; CSUser user = CS.instance.userMgr.GetUser(matchUser.id); Protos.CS2BS_PlayerInfo pi = new Protos.CS2BS_PlayerInfo { GcNID = user.ukey | ( ulong )appropriateBSInfo.lid << 32, ActorID = user.actorID, Avatar = user.avatar, Nickname = user.nickname, Gender = user.gender, Money = user.money, Diamoned = user.diamoned, Rank = user.rank, Exp = user.exp }; ti.PlayerInfos.Add(pi); } } CS.instance.netSessionMgr.Send(appropriateBSInfo.sessionID, battleInfo, RPCEntry.Pop(this.OnBattleInfoRet, state, appropriateBSInfo.ip, appropriateBSInfo.port, appropriateBSInfo.sessionID, appropriateBSInfo.lid)); }
private ErrorCode BStateReportHandler(NetSessionBase session, Protos.BSInfo BSInfoRecv) { session.logicID = BSInfoRecv.Id; bool hasRecord = CS.instance.lIDToBSInfos.TryGetValue(session.logicID, out BSInfo gsInfo); if (!hasRecord) { gsInfo = new BSInfo(); CS.instance.lIDToBSInfos[session.logicID] = gsInfo; } //更新BS信息 gsInfo.lid = session.logicID; gsInfo.sessionID = session.id; gsInfo.ip = BSInfoRecv.Ip; gsInfo.port = BSInfoRecv.Port; gsInfo.state = (BSInfo.State)BSInfoRecv.State; //Logger.Log( $"report from BS:{gsInfo}" ); return(ErrorCode.Success); }