static int _m_CreateUser(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); BattleServer.User.BSUserMgr __cl_gen_to_be_invoked = (BattleServer.User.BSUserMgr)translator.FastGetCSObj(L, 1); { Protos.CS2BS_PlayerInfo playerInfo = (Protos.CS2BS_PlayerInfo)translator.GetObject(L, 2, typeof(Protos.CS2BS_PlayerInfo)); BattleServer.Battle.Battle battle = (BattleServer.Battle.Battle)translator.GetObject(L, 3, typeof(BattleServer.Battle.Battle)); BattleServer.User.BSUser __cl_gen_ret = __cl_gen_to_be_invoked.CreateUser(playerInfo, battle); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
/// <summary> /// 创建玩家 /// 在创建战场时调用 /// </summary> public BSUser CreateUser(Protos.CS2BS_PlayerInfo playerInfo, Battle.Battle battle) { BSUser user = new BSUser(playerInfo, battle); this._gcNIDToUser.Add(user.gcNID, user); Logger.Log($"create user:{user.gcNID}"); return(user); }
public ErrorCode OnGc2BsAskLogin(NetSessionBase session, Google.Protobuf.IMessage message) { Protos.GC2BS_AskLogin login = (Protos.GC2BS_AskLogin)message; Protos.BS2GC_LoginRet loginRet = ProtoCreator.R_GC2BS_AskLogin(login.Opts.Pid); //验证并登陆 BSUser user = BS.instance.userMgr.Online(login.SessionID, session.id); if (user != null) { ClientSession gcSession = ( ClientSession )session; //设置该Session为受信任的连接 gcSession.accredited = true; //把战场的初始状态下发到GC loginRet.PlayerID = user.gcNID; loginRet.RndSeed = user.battle.rndSeed; loginRet.FrameRate = user.battle.frameRate; loginRet.KeyframeStep = user.battle.keyframeStep; loginRet.SnapshotStep = user.battle.snapshotStep; loginRet.BattleTime = user.battle.battleTime; loginRet.MapID = user.battle.mapID; loginRet.CurFrame = user.battle.frame; int c1 = user.battle.battleEntry.users.Length; for (int i = 0; i < c1; i++) { var team = user.battle.battleEntry.users[i]; int c2 = team.Length; var teamInfo = new Protos.CS2BS_TeamInfo(); loginRet.TeamInfos.Add(teamInfo); for (int j = 0; j < c2; j++) { BSUser player = team[j]; Protos.CS2BS_PlayerInfo playerInfo = new Protos.CS2BS_PlayerInfo { GcNID = player.gcNID, ActorID = player.actorID, Nickname = player.nickname, Avatar = player.avatar, Gender = player.gender, Rank = player.rank, Exp = player.exp }; teamInfo.PlayerInfos.Add(playerInfo); } } loginRet.Result = Protos.Global.Types.ECommon.Success; session.Send(loginRet); } else { loginRet.Result = Protos.Global.Types.ECommon.Failed; session.Send(loginRet); session.Close(true, "client login failed"); } return(ErrorCode.Success); }
public BSUser(Protos.CS2BS_PlayerInfo playerInfo, Battle.Battle battle) { this.gcNID = playerInfo.GcNID; this.actorID = playerInfo.ActorID; this.nickname = playerInfo.Nickname; this.avatar = playerInfo.Avatar; this.gender = ( byte )playerInfo.Gender; this.money = playerInfo.Money; this.diamoned = playerInfo.Diamoned; this.rank = playerInfo.Rank; this.exp = playerInfo.Exp; this.battle = battle; }
public void BeginBattle(BattleUser[] users, BattleUser[][] tUsers) { BSInfo appropriateBSInfo = CS.instance.appropriateBSInfo; //没有找到合适的bs,通知客户端匹配失败 if (appropriateBSInfo == null) { this.NotifyGCEnterBattleFailed(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; int c1 = tUsers.Length; for (int i = 0; i < c1; i++) { Protos.CS2BS_TeamInfo ti = new Protos.CS2BS_TeamInfo(); battleInfo.TeamInfos.Add(ti); BattleUser[] roomUsers = tUsers[i]; int c2 = roomUsers.Length; for (int j = 0; j < c2; j++) { BattleUser roomUser = roomUsers[j]; CSUser user = CS.instance.userMgr.GetUser(roomUser.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, users, tUsers, appropriateBSInfo.ip, appropriateBSInfo.port, appropriateBSInfo.sessionID, appropriateBSInfo.lid)); }
/// <summary> /// 创建战场 /// </summary> internal void CreateBattle(Protos.CS2BS_BattleInfo battleInfo, Action <uint, bool> callback) { //创建战场 Battle battle = POOL.Pop(); //创建战场描述 BattleEntry battleEntry; battleEntry.rndSeed = this._random.Next(); battleEntry.mapID = battleInfo.MapID; int c1 = battleInfo.TeamInfos.Count; battleEntry.users = new BSUser[c1][]; for (int i = 0; i < c1; i++) { Protos.CS2BS_TeamInfo teamInfo = battleInfo.TeamInfos[i]; int c2 = teamInfo.PlayerInfos.Count; battleEntry.users[i] = new BSUser[c2]; for (int j = 0; j < c2; j++) { Protos.CS2BS_PlayerInfo playerInfo = teamInfo.PlayerInfos[j]; //检查玩家是否在别的战场 if (BS.instance.userMgr.HasUser(playerInfo.GcNID)) { callback(0, false); return; } //创建玩家 battleEntry.users[i][j] = BS.instance.userMgr.CreateUser(playerInfo, battle); } } //初始化战场 battle.Init(battleEntry); //回调函数,通知GC创建战场成功 callback(battle.id, true); //把战场加入工作列表 this._workingBattles.Add(battle); //战场开始 battle.Start(); Logger.Log($"battle:{battle.id} created"); }
static int __CreateInstance(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); if (LuaAPI.lua_gettop(L) == 3 && translator.Assignable <Protos.CS2BS_PlayerInfo>(L, 2) && translator.Assignable <BattleServer.Battle.Battle>(L, 3)) { Protos.CS2BS_PlayerInfo playerInfo = (Protos.CS2BS_PlayerInfo)translator.GetObject(L, 2, typeof(Protos.CS2BS_PlayerInfo)); BattleServer.Battle.Battle battle = (BattleServer.Battle.Battle)translator.GetObject(L, 3, typeof(BattleServer.Battle.Battle)); BattleServer.User.BSUser __cl_gen_ret = new BattleServer.User.BSUser(playerInfo, battle); translator.Push(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to BattleServer.User.BSUser constructor!")); }