internal static Msg_LR_RoomUserInfo BuildRoomUserInfo(UserInfo info, float x, float y) { //todo:加锁 Msg_LR_RoomUserInfo ruiBuilder = new Msg_LR_RoomUserInfo(); ruiBuilder.Guid = info.Guid; ruiBuilder.Nick = info.Nickname; ruiBuilder.Key = info.Key; ruiBuilder.Hero = info.HeroId; ruiBuilder.Camp = info.CampId; ruiBuilder.IsMachine = false; ruiBuilder.Level = info.Level; ruiBuilder.SummonerSkillId = info.SummonerSkillId; /// int memberCount = info.MemberInfos.Count; if (memberCount > 0) { Msg_LR_RoomUserInfo.MemberInfo[] memberList = new Msg_LR_RoomUserInfo.MemberInfo[memberCount]; for (int i = 0; i < memberCount; ++i) { memberList[i] = new Msg_LR_RoomUserInfo.MemberInfo(); memberList[i].Hero = info.MemberInfos[i].HeroId; memberList[i].Level = info.MemberInfos[i].Level; } } if (x > 0 && y > 0) { ruiBuilder.EnterX = x; ruiBuilder.EnterY = y; } return ruiBuilder; }
private bool CheckBagCapacity(UserInfo user, MailInfo info) { bool result = true; if (null == user || null == user.ItemBag || null == info || null == info.m_Items) { return result; } int ct = info.m_Items.Count; int free = user.ItemBag.GetFreeCount(); if (ct > free) { result = false; } NodeMessage opMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_LackOfSpace, user.Guid); Msg_LC_LackOfSpace protoData = new Msg_LC_LackOfSpace(); protoData.m_Succeed = result; protoData.m_ReceiveNum = ct; protoData.m_FreeNum = free; protoData.m_MailGuid = info.m_MailGuid; opMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(user.NodeName, opMsg); return result; }
//-------------------------------------------------------------------------------------------------------------------------- //这些方法是一些工具方法,后面需要重新考虑并发相关的处理。 //-------------------------------------------------------------------------------------------------------------------------- private UserInfo NewUserInfo() { UserInfo info = null; if (m_UnusedUserInfos.IsEmpty) { info = new UserInfo(); } else { if (!m_UnusedUserInfos.TryDequeue(out info)) { info = new UserInfo(); } else { info.IsRecycled = false; } } return info; }
private void InitUserinfo(UserInfo ui) { ui.ResetMoney(); ui.ResetGold(); ui.SceneId = 1010; ui.Level = 1; ui.CreateTime = DateTime.Now; ui.SceneId = 200; ui.SummonerSkillId = 22; //加4个队员 for (int id = 2; id <= 5; ++id) { MemberInfo member = new MemberInfo(); member.MemberGuid = UserServer.Instance.GlobalProcessThread.GenerateMemberGuid(); member.HeroId = id; member.Level = 1; ui.MemberInfos.Add(member); } }
private void FreeUserThread(UserInfo userInfo) { int ix = userInfo.UserThreadIndex; if (ix >= 0 && ix < m_UserThreadUserCounts.Length) { Interlocked.Decrement(ref m_UserThreadUserCounts[ix]); } }
private GameFrameworkMessage.RoleEnterResult CreateRoleEnterResultMsg(UserInfo ui) { GameFrameworkMessage.RoleEnterResult replyMsg = new GameFrameworkMessage.RoleEnterResult(); // replyMsg.Nickname = ui.Nickname; replyMsg.HeroId = ui.HeroId; replyMsg.Level = ui.Level; replyMsg.Money = ui.Money; replyMsg.Gold = ui.Gold; replyMsg.Level = ui.Level; replyMsg.SceneId = ui.SceneId; replyMsg.SummonerSkillId = ui.SummonerSkillId; replyMsg.WorldId = UserServerConfig.WorldId; for (int i = 0; i < ui.MemberInfos.Count; ++i) { MemberInfoForMessage mi = new MemberInfoForMessage(); mi.Hero = ui.MemberInfos[i].HeroId; mi.Level = ui.MemberInfos[i].Level; } return replyMsg; }
private void AllocUserThread(UserInfo userInfo) { //分配到当前人数最少的线程, 均匀分布 int minIndex = 0; int minUserCount = m_UserThreadUserCounts[minIndex]; for (int ix = 1; ix < m_UserThreadUserCounts.Length; ++ix) { if (minUserCount > m_UserThreadUserCounts[ix]) { minUserCount = m_UserThreadUserCounts[ix]; minIndex = ix; } } for (int ct = 0; ct < 256; ++ct) { minUserCount = m_UserThreadUserCounts[minIndex]; int expectCount = minUserCount + 1; if (Interlocked.CompareExchange(ref m_UserThreadUserCounts[minIndex], expectCount, minUserCount) == minUserCount) { userInfo.UserThreadIndex = minIndex; return; } } }
internal UserThread GetUserThread(UserInfo user) { UserThread thread; int ix = user.UserThreadIndex; if (ix >= 0 && ix < m_UserThreads.Length) { thread = m_UserThreads[ix]; } else { thread = m_UserThreads[0]; } return thread; }
internal void DoUserRelogin(UserInfo user) { user.IsDisconnected = false; if (user.CurrentState != UserState.Room) { user.CurrentState = UserState.Online; } else { Msg_LB_UserRelogin builder = new Msg_LB_UserRelogin(); builder.Guid = user.Guid; UserServer.Instance.BigworldChannel.Send(builder); } m_Thread.QueueAction(this.ActivateUserGuid, user.Guid); }
internal void DoUserLogin(UserInfo user) { user.SceneId = 0; user.IsDisconnected = false; user.LeftLife = UserInfo.LifeTimeOfNoHeartbeat; user.LastSaveTime = TimeUtility.GetLocalMilliseconds(); //在这里生成游戏中要用的key if (user.Key == 0) user.Key = GenerateKey(); user.CurrentState = UserState.Online; AllocUserThread(user); UserInfo oldInfo; if (m_UserInfos.TryGetValue(user.Guid, out oldInfo)) { if (oldInfo != user) { //这里需要回收旧玩家数据(复位状态等),保证引用旧数据的地方能正确处理。 FreeUserThread(oldInfo); RecycleUserInfo(oldInfo); } } m_UserInfos.AddOrUpdate(user.Guid, user, (g, u) => user); m_GuidByNickname.AddOrUpdate(user.Nickname, user.Guid, (n, g) => user.Guid); GlobalProcessThread globalProcess = UserServer.Instance.GlobalProcessThread; if (null != globalProcess) { } m_Thread.QueueAction(this.ActivateUserGuid, user.Guid); AccountInfo accountInfo = m_AccountSystem.FindAccountById(user.AccountId); if (null != accountInfo) { user.ClientInfo = accountInfo.ClientInfo; user.LastLoginTime = TimeUtility.CurTimestamp; } }
private void RecycleUserInfo(UserInfo info) { info.IsRecycled = true; info.Reset(); m_UnusedUserInfos.Enqueue(info); }