private void HandleChangeName(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid nameMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != nameMsg) { GameFrameworkMessage.ChangeName protoData = msg.m_ProtoData as GameFrameworkMessage.ChangeName; if (null != protoData) { m_UserProcessScheduler.DefaultUserThread.QueueAction(m_UserProcessScheduler.DoChangeName, nameMsg.m_Guid, protoData.m_Nickname); } } }
private void HandleAddFriend(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid nodeMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != nodeMsg) { GameFrameworkMessage.Msg_CL_AddFriend protoData = msg.m_ProtoData as GameFrameworkMessage.Msg_CL_AddFriend; if (null != protoData) { UserThread userThread = m_UserProcessScheduler.GetUserThread(nodeMsg.m_Guid); if (null != userThread) { userThread.QueueAction(userThread.AddFriend, nodeMsg.m_Guid, protoData); } } } }
//------------------------------------------------------------------------------------------------------ private void HandleAccountLogin(NodeMessage msg, int handle, uint seq) { StringBuilder stringBuilder = new StringBuilder(1024); int size = stringBuilder.Capacity; CenterHubApi.TargetName(UserServerConfig.WorldId, handle, stringBuilder, size); string node_name = stringBuilder.ToString(); GameFrameworkMessage.NodeMessageWithAccount loginMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithAccount; if (null != loginMsg) { GameFrameworkMessage.AccountLogin protoData = msg.m_ProtoData as GameFrameworkMessage.AccountLogin; if (null != protoData) { m_UserProcessScheduler.DefaultUserThread.QueueAction(m_UserProcessScheduler.DoAccountLogin, loginMsg.m_Account, protoData.m_Password, protoData.m_ClientInfo, node_name); } } }
private void HandleChangeSceneRoom(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.ChangeSceneRoom protoMsg = msg.m_ProtoData as GameFrameworkMessage.ChangeSceneRoom; if (null != protoMsg) { ulong guid = headerMsg.m_Guid; int sceneId = protoMsg.m_SceneId; int wantRoomId = protoMsg.m_RoomId; byte[] originalMsgData = msg.m_OriginalMsgData; UserInfo info = UserServer.Instance.UserProcessScheduler.GetUserInfo(guid); if (null != info) { UserServer.Instance.ForwardToBigworld(info, originalMsgData); } } } }
//------------------------------------------------------------------------------------------------------ private bool FilterMessage(NodeMessage msg, int handle, uint seq) { bool isContinue = true; if (handle > 0) { if (msg.m_ID == 0) { //�⼸����Ϣ����������ͳ�� } else { GameFrameworkMessage.NodeMessageWithGuid msgWithGuid = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != msgWithGuid) { ulong guid = msgWithGuid.m_Guid; isContinue = OperationMeasure.Instance.CheckOperation(msgWithGuid.m_Guid); if (!isContinue) { NodeMessage retMsg = new NodeMessage(LobbyMessageDefine.TooManyOperations, guid); NodeMessageDispatcher.SendNodeMessage(handle, retMsg); } } } } return isContinue; }
private void HandleChangeSceneRoom(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.ChangeSceneRoom protoMsg = msg.m_ProtoData as GameFrameworkMessage.ChangeSceneRoom; if (null != protoMsg) { ulong guid = headerMsg.m_Guid; int sceneId = protoMsg.m_SceneId; int wantRoomId = protoMsg.m_RoomId; byte[] originalMsgData = msg.m_OriginalMsgData; UserInfo info = UserServer.Instance.UserProcessScheduler.GetUserInfo(guid); if (null != info) { UserServer.Instance.ForwardToBigworld(info, originalMsgData); } } } }
internal void HighlightPrompt(UserInfo user, int dictId, params object[] args) { //0--null 1--int 2--float 3--string GameFrameworkMessage.Msg_CLC_StoryMessage protoData = new GameFrameworkMessage.Msg_CLC_StoryMessage(); protoData.m_MsgId = string.Format("highlightprompt{0}", args.Length); GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg item0 = new GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg(); item0.val_type = LobbyArgType.INT; item0.str_val = dictId.ToString(); protoData.m_Args.Add(item0); for (int i = 0; i < args.Length; ++i) { GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg item = new GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg(); item.val_type = LobbyArgType.STRING; item.str_val = args[i].ToString(); protoData.m_Args.Add(item); } NodeMessage msg = new NodeMessage(LobbyMessageDefine.Msg_CLC_StoryMessage, user.Guid); msg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(user.NodeName, msg); }
//------------------------------------------------------------------------------------------------------ private void ObserveEnterSceneResult(NodeMessage msg, int handle, uint seq) { if (handle != 0) { return; } GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.EnterSceneResult protoMsg = msg.m_ProtoData as GameFrameworkMessage.EnterSceneResult; if (null != protoMsg) { UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(headerMsg.m_Guid); if (user != null && protoMsg.result == 0) { user.CurrentState = UserState.Room; user.SceneId = protoMsg.scene_type; } } } }
internal void SendUserMail(TableMailInfoWrap userMail, int validityPeriod) { userMail.Guid = GenMailGuid(); userMail.SendDate = DateTime.Now; userMail.ExpiryDate = userMail.SendDate.AddDays(validityPeriod); List <TableMailInfoWrap> mails = null; if (!m_UserMails.TryGetValue(userMail.Receiver, out mails)) { mails = new List <TableMailInfoWrap>(); m_UserMails.Add(userMail.Receiver, mails); } mails.Add(userMail); UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo((ulong)userMail.Receiver); if (null != user && user.CurrentState != UserState.DropOrOffline) { NodeMessage newMailMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_NotifyNewMail, (ulong)userMail.Receiver); NodeMessageDispatcher.SendNodeMessage(user.NodeName, newMailMsg); } }
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; }
internal static void HandleNodeMessage( uint seq, int source_handle, int dest_handle, byte[] data) { if (s_Inited) { NodeMessage msg = DecodeNodeMessage(data); if (null != msg) { bool isContinue = true; if (null != s_MessageFilter) { isContinue = s_MessageFilter(msg, source_handle, seq); } if (isContinue) { HandleNodeMessage(msg, source_handle, seq); } } } }
internal void SendStoryMessage(UserInfo user, string msgId, params object[] args) { //0--null 1--int 2--float 3--string GameFrameworkMessage.Msg_CLC_StoryMessage protoData = new GameFrameworkMessage.Msg_CLC_StoryMessage(); protoData.m_MsgId = msgId; for (int i = 0; i < args.Length; ++i) { object arg = args[i]; GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg item = new GameFrameworkMessage.Msg_CLC_StoryMessage.MessageArg(); if (null != arg) { if (arg is int) { item.val_type = LobbyArgType.INT; } else if (arg is float) { item.val_type = LobbyArgType.FLOAT; } else { item.val_type = LobbyArgType.STRING; } item.str_val = arg.ToString(); } else { item.val_type = LobbyArgType.NULL; item.str_val = ""; } protoData.m_Args.Add(item); } NodeMessage msg = new NodeMessage(LobbyMessageDefine.Msg_CLC_StoryMessage, user.Guid); msg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(user.NodeName, msg); }
private void HandleEnterScene(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.EnterScene protoMsg = msg.m_ProtoData as GameFrameworkMessage.EnterScene; if (null != protoMsg) { ulong guid = headerMsg.m_Guid; int sceneId = protoMsg.m_SceneId; int wantRoomId = protoMsg.m_RoomId; UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(guid); if (user != null) { Msg_LB_RequestEnterScene builder = new Msg_LB_RequestEnterScene(); Msg_LB_BigworldUserBaseInfo baseInfoBuilder = new Msg_LB_BigworldUserBaseInfo(); baseInfoBuilder.AccountId = user.AccountId; baseInfoBuilder.NodeName = user.NodeName; baseInfoBuilder.WorldId = UserServerConfig.WorldId; baseInfoBuilder.ClientInfo = user.ClientInfo; baseInfoBuilder.StartServerTime = UserServerConfig.StartServerTime; baseInfoBuilder.SceneId = user.SceneId; builder.BaseInfo = baseInfoBuilder; builder.User = UserThread.BuildRoomUserInfo(user, 0, 0); builder.SceneId = sceneId; builder.WantRoomId = wantRoomId; builder.FromSceneId = user.SceneId; UserServer.Instance.BigworldChannel.Send(builder); } } } }
internal void DoRoleEnter(string accountId, string nickname) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); if (accountInfo != null) { ulong userGuid = accountInfo.UserGuid; UserInfo user = GetUserInfo(userGuid); if (null != user) { if (user.CurrentState == UserState.DropOrOffline) { //用户处在下线过程中,需要等待lobby离线流程完成 NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountId, user.Guid); GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult(); protoData.Result = RoleEnterResult.RoleEnterResultEnum.Wait; roleEnterResultMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(user.NodeName, roleEnterResultMsg); LogSys.Log(LOG_TYPE.WARN, "RoleEnter AccountId:{0} Guid:{1} Wait Offline", accountId, userGuid); } else { if (user.AccountId.Equals(accountInfo.AccountId)) { user.NodeName = accountInfo.NodeName; user.LeftLife = UserInfo.LifeTimeOfNoHeartbeat; DoUserRelogin(user); LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_8a: Role Reenter SUCCESS. AccountId:{0}, UserGuid:{1}, Nickname:{2}", accountId, userGuid, user.Nickname); //回复客户端 NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, user.AccountId, user.Guid); GameFrameworkMessage.RoleEnterResult protoData = CreateRoleEnterResultMsg(user); protoData.Result = RoleEnterResult.RoleEnterResultEnum.Reconnect; roleEnterResultMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, roleEnterResultMsg); } else { //角色AccountId与账号AccountId不匹配,进入游戏失败 NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountId, user.Guid); GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult(); protoData.Result = RoleEnterResult.RoleEnterResultEnum.UnknownError; roleEnterResultMsg.m_ProtoData = protoData; LogSys.Log(LOG_TYPE.ERROR, "LoginStep_8a: Role Reenter FAILED. AccountId:{0}, UserGuid:{1}, Nickname:{2}, UserAccountId:{3}", accountId, userGuid, user.Nickname, user.AccountId); } } } else { var ds_thread = UserServer.Instance.DataCacheThread; if (ds_thread.DataStoreAvailable == true) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_8b: Load UserInfo. AccountId:{0}, UserGuid:{1}", accountId, userGuid); ds_thread.DispatchAction(ds_thread.DSPLoadUser, userGuid, accountId, nickname); } else { CreateRole(accountId, nickname, 1); } } } }
internal void DoAccountLoginWithoutQueueing(string accountId, string password, string clientInfo, string nodeName) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); if (accountInfo == null) { //当前accountId不在线 accountInfo = new AccountInfo(); accountInfo.AccountId = accountId; accountInfo.Password = password; accountInfo.ClientInfo = clientInfo; accountInfo.NodeName = nodeName; accountInfo.CurrentState = AccountState.Unloaded; accountInfo.UserGuid = UserServer.Instance.GlobalProcessThread.GenerateUserGuid(); var dsThread = UserServer.Instance.DataCacheThread; if (dsThread.DataStoreAvailable == true) { m_AccountSystem.AddAccountById(accountId, accountInfo); LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_4: Load account from DataStore . AccountId:{0}", accountId); dsThread.DispatchAction(dsThread.DSPLoadAccount, accountId); } else { accountInfo.CurrentState = AccountState.Online; m_AccountSystem.AddAccountById(accountId, accountInfo); LogSys.Log(LOG_TYPE.INFO, "Account login success. Account:{0}", accountId); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.FirstLogin; protoMsg.m_UserGuid = accountInfo.UserGuid; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(nodeName, replyMsg); } } else { //当前账号在线 if (accountInfo.CurrentState == AccountState.Dropped || clientInfo == accountInfo.ClientInfo) { //账号处在离线状态或同一设备重复登录,登录成功 LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_5a: Account is dropped. Login SUCCESS. AccountId:{0}", accountId); accountInfo.AccountId = accountId; accountInfo.Password = password; accountInfo.ClientInfo = clientInfo; accountInfo.NodeName = nodeName; accountInfo.CurrentState = AccountState.Online; NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; if (null != GetUserInfo(accountInfo.UserGuid)) protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.Success; else protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.FirstLogin; protoMsg.m_UserGuid = accountInfo.UserGuid; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(nodeName, replyMsg); } else { //账号在别的设备上登录,登录失败 LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "LoginStep_5b: Account is online. Login FAILED. AccountId:{0}", accountId); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.AlreadyOnline; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(nodeName, replyMsg); } } }
internal void DoChangeName(ulong guid, string nickname) { UserInfo ui = GetUserInfo(guid); if (null != ui) { NicknameSystem.CheckNicknameResult ret = m_NicknameSystem.CheckNickname(ui.AccountId, nickname); if (ret == NicknameSystem.CheckNicknameResult.Success) { ui.Nickname = nickname; LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "ChangeName SUCCESS. AccountId:{0}, Nickname:{1}", ui.AccountId, nickname); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.ChangeNameResult, ui.AccountId); GameFrameworkMessage.ChangeNameResult protoMsg = new GameFrameworkMessage.ChangeNameResult(); protoMsg.m_Result = ChangeNameResult.ChangeNameResultEnum.Success; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(ui.NodeName, replyMsg); } else { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "ChangeName FAILED. AccountId:{0}, Nickname:{1}", ui.AccountId, nickname); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.ChangeNameResult, ui.AccountId); GameFrameworkMessage.ChangeNameResult protoMsg = new GameFrameworkMessage.ChangeNameResult(); if (ret == NicknameSystem.CheckNicknameResult.AlreadyUsed) { //昵称已经被使用 protoMsg.m_Result = ChangeNameResult.ChangeNameResultEnum.NicknameError; } else { //昵称不合法 protoMsg.m_Result = ChangeNameResult.ChangeNameResultEnum.UnknownError; } replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(ui.NodeName, replyMsg); } } }
private void HandleStoryMessage(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid storyMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != storyMsg) { GameFrameworkMessage.Msg_CLC_StoryMessage protoData = msg.m_ProtoData as GameFrameworkMessage.Msg_CLC_StoryMessage; if (null != protoData) { ulong guid = storyMsg.m_Guid; UserThread userThread = m_UserProcessScheduler.GetUserThread(guid); if (null != userThread) { //�ͻ��˷�������Ϣ������ǰclient����ֱֹ�ӵ��÷�������������������Ϣ������clientǰ���� string msgId = string.Format("client:{0}", protoData.m_MsgId); ArrayList args = new ArrayList(); args.Add(guid); for (int i = 0; i < protoData.m_Args.Count; i++) { switch (protoData.m_Args[i].val_type) { case LobbyArgType.NULL://null args.Add(null); break; case LobbyArgType.INT://int args.Add(int.Parse(protoData.m_Args[i].str_val)); break; case LobbyArgType.FLOAT://float args.Add(float.Parse(protoData.m_Args[i].str_val)); break; default://string args.Add(protoData.m_Args[i].str_val); break; } } object[] objArgs = args.ToArray(); userThread.QueueAction(userThread.SendStoryMessage, msgId, objArgs); } } } }
internal void GetMailList(ulong userGuid) { UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(userGuid); if (null != user) { List<MailInfoForMessage> mailList = new List<MailInfoForMessage>(); List<MailInfo> mails; if (m_UserMails.TryGetValue(userGuid, out mails)) { int ct = mails.Count; for (int ix = 0; ix < ct; ++ix) { MailInfo mailInfo = mails[ix]; if (mailInfo.m_ExpiryDate >= DateTime.Now) { MailInfoForMessage mailInfoForMsg = new MailInfoForMessage(); mailInfoForMsg.m_AlreadyRead = mailInfo.m_AlreadyRead; mailInfoForMsg.m_MailGuid = mailInfo.m_MailGuid; mailInfoForMsg.m_Title = mailInfo.m_Title; mailInfoForMsg.m_Sender = mailInfo.m_Sender; mailInfoForMsg.m_SendTime = mailInfo.m_SendTime.ToString("yyyyMMddHHmmss"); mailInfoForMsg.m_Text = mailInfo.m_Text; mailInfoForMsg.m_Money = mailInfo.m_Money; mailInfoForMsg.m_Gold = mailInfo.m_Gold; int itemCt = mailInfo.m_Items.Count; if (itemCt > 0) { for (int index = 0; index < itemCt; ++index) { MailItemForMessage mailItem = new MailItemForMessage(); mailItem.m_ItemId = mailInfo.m_Items[index].m_ItemId; mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum; mailInfoForMsg.m_Items.Add(mailItem); } } mailList.Add(mailInfoForMsg); } } } MailStateInfo mailStateInfo = user.MailStateInfo; //这里不对用户数据加锁,因为用户的邮件状态的改变都在这个线程完成(除上线时的数据加载) int wholeMailCt = m_WholeMails.Count; for (int ix = 0; ix < wholeMailCt; ++ix) { MailInfo mailInfo = m_WholeMails[ix]; if (mailInfo.m_LevelDemand <= user.Level && mailInfo.m_SendTime >= user.CreateTime && mailInfo.m_ExpiryDate >= DateTime.Now && !mailStateInfo.IsAlreadyReceived(mailInfo.m_MailGuid)) { if (!mailStateInfo.HaveMail(mailInfo.m_MailGuid)) { mailStateInfo.AddMail(mailInfo.m_MailGuid, mailInfo.m_ExpiryDate); } MailInfoForMessage mailInfoForMsg = new MailInfoForMessage(); mailInfoForMsg.m_AlreadyRead = mailStateInfo.IsAlreadyRead(mailInfo.m_MailGuid); mailInfoForMsg.m_MailGuid = mailInfo.m_MailGuid; mailInfoForMsg.m_Title = mailInfo.m_Title; mailInfoForMsg.m_Sender = mailInfo.m_Sender; mailInfoForMsg.m_SendTime = mailInfo.m_SendTime.ToString("yyyyMMddHHmmss"); mailInfoForMsg.m_Text = mailInfo.m_Text; mailInfoForMsg.m_Money = mailInfo.m_Money; mailInfoForMsg.m_Gold = mailInfo.m_Gold; int itemCt = mailInfo.m_Items.Count; if (itemCt > 0) { for (int index = 0; index < itemCt; ++index) { MailItemForMessage mailItem = new MailItemForMessage(); mailItem.m_ItemId = mailInfo.m_Items[index].m_ItemId; mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum; mailInfoForMsg.m_Items.Add(mailItem); } } mailList.Add(mailInfoForMsg); } } NodeMessage syncMailListMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_SyncMailList, userGuid); GameFrameworkMessage.Msg_LC_SyncMailList protoMsg = new Msg_LC_SyncMailList(); protoMsg.m_Mails.AddRange(mailList); syncMailListMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(user.NodeName, syncMailListMsg); } }
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; }
internal void SendWholeMail(MailInfo wholeMail, int validityPeriod) { wholeMail.m_MailGuid = GenMailGuid(); wholeMail.m_SendTime = DateTime.Now; wholeMail.m_ExpiryDate = wholeMail.m_SendTime.AddDays(validityPeriod); m_WholeMails.Add(wholeMail); NodeMessage newMailMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_NotifyNewMail); NodeMessageWithGuid headerData = new NodeMessageWithGuid(); newMailMsg.m_NodeHeader = headerData; UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; dataProcess.VisitUsers((UserInfo userInfo) => { headerData.m_Guid = userInfo.Guid; NodeMessageDispatcher.SendNodeMessage(userInfo.NodeName, newMailMsg); }); }
internal void SendUserMail(MailInfo userMail, int validityPeriod) { userMail.m_MailGuid = GenMailGuid(); userMail.m_SendTime = DateTime.Now; userMail.m_ExpiryDate = userMail.m_SendTime.AddDays(validityPeriod); List<MailInfo> mails = null; if (!m_UserMails.TryGetValue(userMail.m_Receiver, out mails)) { mails = new List<MailInfo>(); m_UserMails.Add(userMail.m_Receiver, mails); } mails.Add(userMail); UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(userMail.m_Receiver); if (null != user && user.CurrentState != UserState.DropOrOffline) { NodeMessage newMailMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_NotifyNewMail, userMail.m_Receiver); NodeMessageDispatcher.SendNodeMessage(user.NodeName, newMailMsg); } }
private void CreateRole(string accountId, string nickname, int heroId) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); var ds_thread = UserServer.Instance.DataCacheThread; if (accountInfo != null) { //检查昵称是否可用 NicknameSystem.CheckNicknameResult ret = m_NicknameSystem.CheckNickname(accountId, nickname); if (ret == NicknameSystem.CheckNicknameResult.Success) { UserInfo ui = NewUserInfo(); ui.Guid = accountInfo.UserGuid; ui.AccountId = accountInfo.AccountId; ui.Nickname = nickname; ui.HeroId = heroId; InitUserinfo(ui); m_NicknameSystem.UpdateUsedNickname(nickname, ui.Guid); LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_7a: Create new role SUCCESS. AccountId:{0}, UserGuid:{1}, Nickname:{2}, HeroId:{3}", accountId, accountInfo.AccountId, ui.Guid, ui.Nickname, ui.HeroId); if (ds_thread.DataStoreAvailable) { ds_thread.DSPSaveCreateUser(accountInfo, nickname, ui.Guid); ds_thread.DSPSaveUser(ui, ui.NextUserSaveCount); } //游戏角色创建成功,直接进入游戏 ui.NodeName = accountInfo.NodeName; this.DoUserLogin(ui); LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_8c: New role enter SUCCESS. AccountId:{0}, UserGuid:{1}, Nickname:{2}", accountId, ui.Guid, ui.Nickname); NodeMessage enterMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, ui.AccountId, ui.Guid); GameFrameworkMessage.RoleEnterResult protoData = CreateRoleEnterResultMsg(ui); protoData.Result = RoleEnterResult.RoleEnterResultEnum.Success; enterMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, enterMsg); } else { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "LoginStep_7b: Create new role FAILED. AccountId:{0}, Nickname:{1}", accountId, nickname); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.ChangeNameResult, accountId); GameFrameworkMessage.ChangeNameResult protoMsg = new GameFrameworkMessage.ChangeNameResult(); if (ret == NicknameSystem.CheckNicknameResult.AlreadyUsed) { //昵称已经被使用 protoMsg.m_Result = ChangeNameResult.ChangeNameResultEnum.NicknameError; } else { //昵称不合法 protoMsg.m_Result = ChangeNameResult.ChangeNameResultEnum.UnknownError; } replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg); } } }
internal void DSPLoadUserCallback(Msg_DL_LoadResult ret, string accountId, string nickname) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); if (accountInfo == null) { return; } ulong userGuid = 0;// accountInfo.UserGuid; if (Msg_DL_LoadResult.ErrorNoEnum.Success == ret.ErrorNo) { TableUserInfo dataUser = null; foreach (var result in ret.Results) { object _msg; if (DbDataSerializer.Decode(result.Data, DataEnum2Type.Query(result.MsgId), out _msg)) { DataEnum msgEnum = (DataEnum)result.MsgId; switch (msgEnum) { case DataEnum.TableUserInfo: dataUser = _msg as TableUserInfo; break; default: LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Decode user data ERROR. Wrong message id. UserGuid:{0}, WrongId:{1}", userGuid, msgEnum); break; } } } #region 由数据库数据构建UserInfo UserInfo ui = NewUserInfo(); //基础数据 ui.FromProto(dataUser); ui.SetMoneyForDB(dataUser.Money); ui.SetGoldForDB(dataUser.Gold); #endregion ui.NodeName = accountInfo.NodeName; this.DoUserLogin(ui); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, ui.AccountId, ui.Guid); GameFrameworkMessage.RoleEnterResult protoData = CreateRoleEnterResultMsg(ui); protoData.Result = RoleEnterResult.RoleEnterResultEnum.Success; replyMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg); } else if (Msg_DL_LoadResult.ErrorNoEnum.NotFound == ret.ErrorNo) { CreateRole(accountId, nickname, 1); } else { NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountInfo.AccountId, userGuid); GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult(); protoData.Result = RoleEnterResult.RoleEnterResultEnum.UnknownError; replyMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg); } LogSys.Log(LOG_TYPE.INFO, "UserProcessScheduler-OnRoleEnter-EndLoadUser. AccountId:{0}, UserGuid:{1}, Result:{2}", accountId, userGuid, ret.ErrorNo); }
internal void DSPLoadAccountCallback(string accountId, Msg_DL_LoadResult ret) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); if (accountInfo == null) { return; } NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.Error; try { if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.Success) { foreach (var result in ret.Results) { object _msg; if (DbDataSerializer.Decode(result.Data, DataEnum2Type.Query(result.MsgId), out _msg)) { DataEnum msgEnum = (DataEnum)result.MsgId; switch (msgEnum) { case DataEnum.TableAccount: accountInfo.TableAccount.FromProto(_msg as TableAccount); break; default: LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Decode account data ERROR. Wrong message id. Account:{0}, WrongId:{1}", result.PrimaryKeys[0], msgEnum); break; } } } if (accountInfo.TableAccount.IsBanned) { //账号被封停 protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.Banned; } else { accountInfo.CurrentState = AccountState.Online; accountInfo.LastLoginTime = TimeUtility.CurTimestamp; m_AccountSystem.AddAccountById(accountId, accountInfo); LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_4a: Account login SUCCESS . AccountId:{0}, LogicServerId:{1}, AccountId:{2}", accountId, 0, accountId); protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.Success; protoMsg.m_UserGuid = accountInfo.UserGuid; } } else if (ret.ErrorNo == Msg_DL_LoadResult.ErrorNoEnum.NotFound) { //账号首次进入游戏 LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_4b: Load account NotFound . AccountId:{0}, LogicServerId:{1}, AccountId:{2}", accountId, 0, accountId); accountInfo.CurrentState = AccountState.Online; accountInfo.TableAccount.AccountId = accountId; accountInfo.TableAccount.IsBanned = false; m_AccountSystem.AddAccountById(accountId, accountInfo); protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.FirstLogin; protoMsg.m_UserGuid = accountInfo.UserGuid; //norm log accountInfo.LastLoginTime = TimeUtility.CurTimestamp; } else { //数据加载失败 LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "LoginStep_4c: Load account FAILED . AccountId:{0}, LogicServerId:{1}, AccountId:{2}", accountId, 0, accountId); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Red, "ERROR LoginStep_4d. AccountId:{0}, LogicServerId:{1}, AccountId:{2}\nERROR Message:{3}\nStackTrace:{4}", accountId, 0, accountId, ex.Message, ex.StackTrace); } finally { if (protoMsg.m_Result != AccountLoginResult.AccountLoginResultEnum.Success && protoMsg.m_Result != AccountLoginResult.AccountLoginResultEnum.FirstLogin) { m_AccountSystem.RemoveAccountById(accountId); } replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg); } }
private void HandleRequestSceneRoomList(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { ulong guid = headerMsg.m_Guid; byte[] originalMsgData = msg.m_OriginalMsgData; UserInfo info = UserServer.Instance.UserProcessScheduler.GetUserInfo(guid); if (null != info) { UserServer.Instance.ForwardToBigworld(info, originalMsgData); } } }
private void HandleRoleEnter(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithAccount enterMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithAccount; if (null != enterMsg) { GameFrameworkMessage.RoleEnter protoData = msg.m_ProtoData as GameFrameworkMessage.RoleEnter; if (null != protoData) { m_UserProcessScheduler.DefaultUserThread.QueueAction(m_UserProcessScheduler.DoRoleEnter, enterMsg.m_Account, protoData.m_Nickname); } } }
private void HandleEnterScene(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.EnterScene protoMsg = msg.m_ProtoData as GameFrameworkMessage.EnterScene; if (null != protoMsg) { ulong guid = headerMsg.m_Guid; int sceneId = protoMsg.m_SceneId; int wantRoomId = protoMsg.m_RoomId; UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(guid); if (user != null) { Msg_LB_RequestEnterScene builder = new Msg_LB_RequestEnterScene(); Msg_LB_BigworldUserBaseInfo baseInfoBuilder = new Msg_LB_BigworldUserBaseInfo(); baseInfoBuilder.AccountId = user.AccountId; baseInfoBuilder.NodeName = user.NodeName; baseInfoBuilder.WorldId = UserServerConfig.WorldId; baseInfoBuilder.ClientInfo = user.ClientInfo; baseInfoBuilder.StartServerTime = UserServerConfig.StartServerTime; baseInfoBuilder.SceneId = user.SceneId; builder.BaseInfo = baseInfoBuilder; builder.User = UserThread.BuildRoomUserInfo(user, 0, 0); builder.SceneId = sceneId; builder.WantRoomId = wantRoomId; builder.FromSceneId = user.SceneId; UserServer.Instance.BigworldChannel.Send(builder); } } } }
//------------------------------------------------------------------------------------------------------ private void HandleUserHeartbeat(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid heartbeatMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != heartbeatMsg) { if (null == m_UserProcessScheduler.GetUserInfo(heartbeatMsg.m_Guid)) { NodeMessage retMsg = new NodeMessage(LobbyMessageDefine.KickUser, heartbeatMsg.m_Guid); NodeMessageDispatcher.SendNodeMessage(handle, retMsg); LogSys.Log(LOG_TYPE.DEBUG, "HandleUserHeartbeat, guid:{0} can't found, kick.", heartbeatMsg.m_Guid); } else { //echo NodeMessageDispatcher.SendNodeMessage(handle, msg); //������ m_UserProcessScheduler.GetUserThread(heartbeatMsg.m_Guid).QueueAction(m_UserProcessScheduler.DoUserHeartbeat, heartbeatMsg.m_Guid); } } }
internal void NotifyUser(ulong guid, LobbyMessageDefine id, object msg) { UserInfo user = GetUserInfo(guid); if (null != user) { NodeMessage retMsg = new NodeMessage(id, guid); retMsg.m_ProtoData = msg; NodeMessageDispatcher.SendNodeMessage(user.NodeName, retMsg); } }
//------------------------------------------------------------------------------------------------------ private void ObserveEnterSceneResult(NodeMessage msg, int handle, uint seq) { if (handle != 0) return; GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.EnterSceneResult protoMsg = msg.m_ProtoData as GameFrameworkMessage.EnterSceneResult; if (null != protoMsg) { UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(headerMsg.m_Guid); if (user != null && protoMsg.result == 0) { user.CurrentState = UserState.Room; user.SceneId = protoMsg.scene_type; } } } }
//------------------------------------------------------------------------------------------------------ private void HandleNodeRegister(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeRegister nodeRegMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeRegister; if (null != nodeRegMsg) { NodeMessage retMsg = new NodeMessage(LobbyMessageDefine.NodeRegisterResult); GameFrameworkMessage.NodeRegisterResult nodeRegResultMsg = new NodeRegisterResult(); nodeRegResultMsg.m_IsOk = true; retMsg.m_NodeHeader = nodeRegResultMsg; NodeMessageDispatcher.SendNodeMessage(handle, retMsg); } }
//-------------------------------------------------------------------------------------------------------------------------- //供GM消息调用的方法,实际执行线程是在线程池的某个线程里执行,实现时需要注意并发问题,需要加锁的加锁。 //逻辑功能不要直接调用此类处理(会有gm权限判断,正式服会导致功能失效),应该调用逻辑上一个功能相同的方法(通常以Do开头命名)。 //-------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------- //供外部通过QueueAction调用的方法,实际执行线程是在线程池的某个线程里执行,实现时需要注意并发问题,需要加锁的加锁。 //-------------------------------------------------------------------------------------------------------------------------- //登录流程相关方法 internal void DoAccountLogin(string accountId, string password, string clientInfo, string nodeName) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); QueueingThread queueingThread = UserServer.Instance.QueueingThread; if (null != accountInfo || !queueingThread.NeedQueueing()) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_3a: DoLogin without queueing. AccountId:{0}", accountId); DoAccountLoginWithoutQueueing(accountId, password, clientInfo, nodeName); } else { if (queueingThread.IsQueueingFull()) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "LoginStep_3b1: Start queueing but queue full. AccountId:{0}", accountId); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.QueueFull; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(nodeName, replyMsg); } else { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "LoginStep_3b2: Start queueing. AccountId:{0}", accountId); queueingThread.QueueAction(queueingThread.StartQueueing, accountId, password, clientInfo, nodeName); NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.AccountLoginResult, accountId); GameFrameworkMessage.AccountLoginResult protoMsg = new GameFrameworkMessage.AccountLoginResult(); protoMsg.m_AccountId = accountId; protoMsg.m_Result = AccountLoginResult.AccountLoginResultEnum.Queueing; replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(nodeName, replyMsg); } } }
internal void DoLastSaveUserData() { m_LastSaveFinished = false; //服务器关闭前的最后一次存储操作 var ds_thread = UserServer.Instance.DataCacheThread; if (ds_thread.DataStoreAvailable == true) { //1.通知客户端服务器关闭 foreach (var guidPair in m_ActiveUserGuids) { UserInfo user = GetUserInfo(guidPair.Key); if (user != null) { NodeMessage retMsg = new NodeMessage(LobbyMessageDefine.ServerShutdown, user.Guid); NodeMessageDispatcher.SendNodeMessage(user.NodeName, retMsg); } } LogSys.Log(LOG_TYPE.MONITOR, "DoLastSaveUserData Step_1: Notice game client ServerShutdown. UserCount:{0}", m_ActiveUserGuids.Count); //2.等待10s Thread.Sleep(10000); LogSys.Log(LOG_TYPE.MONITOR, "DoLastSaveUserData Step_2: Wait for 10s."); //3.关闭Node CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs1", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs2", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs3", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs4", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs5", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs6", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs7", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs8", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "NodeJs9", "QuitNodeJs"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr1", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr2", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr3", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr4", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr5", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr6", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr11", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr12", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr13", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr14", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr15", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "RoomSvr16", "QuitRoomServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "GmServer", "QuitGmServer"); CenterHubApi.SendCommandByName(UserServerConfig.WorldId, "ServerBridge", "QuitServerBridge"); LogSys.Log(LOG_TYPE.MONITOR, "DoLastSaveUserData Step_3: Close Servers."); //4.保存玩家数据 foreach (var guidPair in m_ActiveUserGuids) { UserInfo user = GetUserInfo(guidPair.Key); if (user != null) { user.NextUserSaveCount = DataCacheThread.UltimateSaveCount; this.GetUserThread(user).QueueAction(ds_thread.DSPSaveUser, user, user.NextUserSaveCount); } } LogSys.Log(LOG_TYPE.MONITOR, "DoLastSaveUserData Step_4: Start to save UserData for last. UserCount:{0}", m_ActiveUserGuids.Count); } m_IsLastSave = true; }
private void HandleQuitRoom(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid headerMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != headerMsg) { GameFrameworkMessage.QuitRoom protoMsg = msg.m_ProtoData as GameFrameworkMessage.QuitRoom; if (null != protoMsg) { ulong guid = headerMsg.m_Guid; bool is_quit_room = protoMsg.m_IsQuitRoom; byte[] originalMsgData = msg.m_OriginalMsgData; UserInfo user = UserServer.Instance.UserProcessScheduler.GetUserInfo(guid); if (user != null) { if (user.CurrentState == UserState.Room) { UserServer.Instance.ForwardToBigworld(user, originalMsgData); } else { user.CurrentState = UserState.Online; } LogSys.Log(LOG_TYPE.INFO, "QuitRoom Guid {0} state {1}", guid, user.CurrentState); } } } }
private void HandleReceiveMail(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid receiveMailMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != receiveMailMsg) { GameFrameworkMessage.Msg_CL_ReceiveMail protoData = msg.m_ProtoData as GameFrameworkMessage.Msg_CL_ReceiveMail; if (null != protoData) { m_GlobalProcessThread.QueueAction(m_GlobalProcessThread.ReceiveMail, receiveMailMsg.m_Guid, protoData.m_MailGuid); } } }
internal void GetMailList(ulong userGuid) { UserProcessScheduler dataProcess = UserServer.Instance.UserProcessScheduler; UserInfo user = dataProcess.GetUserInfo(userGuid); if (null != user) { List<MailInfoForMessage> mailList = new List<MailInfoForMessage>(); List<MailInfo> mails; if (m_UserMails.TryGetValue(userGuid, out mails)) { int ct = mails.Count; for (int ix = 0; ix < ct; ++ix) { MailInfo mailInfo = mails[ix]; if (mailInfo.m_ExpiryDate >= DateTime.Now) { MailInfoForMessage mailInfoForMsg = new MailInfoForMessage(); mailInfoForMsg.m_AlreadyRead = mailInfo.m_AlreadyRead; mailInfoForMsg.m_MailGuid = mailInfo.m_MailGuid; mailInfoForMsg.m_Title = mailInfo.m_Title; mailInfoForMsg.m_Sender = mailInfo.m_Sender; mailInfoForMsg.m_SendTime = mailInfo.m_SendTime.ToString("yyyyMMddHHmmss"); mailInfoForMsg.m_Text = mailInfo.m_Text; mailInfoForMsg.m_Money = mailInfo.m_Money; mailInfoForMsg.m_Gold = mailInfo.m_Gold; int itemCt = mailInfo.m_Items.Count; if (itemCt > 0) { for (int index = 0; index < itemCt; ++index) { MailItemForMessage mailItem = new MailItemForMessage(); mailItem.m_ItemId = mailInfo.m_Items[index].m_ItemId; mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum; mailInfoForMsg.m_Items.Add(mailItem); } } mailList.Add(mailInfoForMsg); } } } MailStateInfo mailStateInfo = user.MailStateInfo; //这里不对用户数据加锁,因为用户的邮件状态的改变都在这个线程完成(除上线时的数据加载) int wholeMailCt = m_WholeMails.Count; for (int ix = 0; ix < wholeMailCt; ++ix) { MailInfo mailInfo = m_WholeMails[ix]; if (mailInfo.m_LevelDemand <= user.Level && mailInfo.m_SendTime >= user.CreateTime && mailInfo.m_ExpiryDate >= DateTime.Now && !mailStateInfo.IsAlreadyReceived(mailInfo.m_MailGuid)) { if (!mailStateInfo.HaveMail(mailInfo.m_MailGuid)) { mailStateInfo.AddMail(mailInfo.m_MailGuid, mailInfo.m_ExpiryDate); } MailInfoForMessage mailInfoForMsg = new MailInfoForMessage(); mailInfoForMsg.m_AlreadyRead = mailStateInfo.IsAlreadyRead(mailInfo.m_MailGuid); mailInfoForMsg.m_MailGuid = mailInfo.m_MailGuid; mailInfoForMsg.m_Title = mailInfo.m_Title; mailInfoForMsg.m_Sender = mailInfo.m_Sender; mailInfoForMsg.m_SendTime = mailInfo.m_SendTime.ToString("yyyyMMddHHmmss"); mailInfoForMsg.m_Text = mailInfo.m_Text; mailInfoForMsg.m_Money = mailInfo.m_Money; mailInfoForMsg.m_Gold = mailInfo.m_Gold; int itemCt = mailInfo.m_Items.Count; if (itemCt > 0) { for (int index = 0; index < itemCt; ++index) { MailItemForMessage mailItem = new MailItemForMessage(); mailItem.m_ItemId = mailInfo.m_Items[index].m_ItemId; mailItem.m_ItemNum = mailInfo.m_Items[index].m_ItemNum; mailInfoForMsg.m_Items.Add(mailItem); } } mailList.Add(mailInfoForMsg); } } NodeMessage syncMailListMsg = new NodeMessage(LobbyMessageDefine.Msg_LC_SyncMailList, userGuid); GameFrameworkMessage.Msg_LC_SyncMailList protoMsg = new Msg_LC_SyncMailList(); protoMsg.m_Mails.AddRange(mailList); syncMailListMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(user.NodeName, syncMailListMsg); } }
private void HandleRequestNickname(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithAccount nickMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithAccount; if (null != nickMsg) { GameFrameworkMessage.RequestNickname protoData = msg.m_ProtoData as GameFrameworkMessage.RequestNickname; if (null != protoData) { m_UserProcessScheduler.DefaultUserThread.QueueAction(m_UserProcessScheduler.DoRequestNickname, nickMsg.m_Account); } } }
private void HandleGetMailList(NodeMessage msg, int handle, uint seq) { GameFrameworkMessage.NodeMessageWithGuid getMailListMsg = msg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithGuid; if (null != getMailListMsg) { if (m_GlobalProcessThread.CurActionNum > m_MaxGlobalActionNum) { NodeMessage retMsg = new NodeMessage(LobbyMessageDefine.TooManyOperations, getMailListMsg.m_Guid); NodeMessageDispatcher.SendNodeMessage(handle, retMsg); return; } m_GlobalProcessThread.QueueAction(m_GlobalProcessThread.GetMailList, getMailListMsg.m_Guid); } }
internal void DoRequestNickname(string accountId) { AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId); if (accountInfo != null) { NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.RequestNicknameResult, accountId); GameFrameworkMessage.RequestNicknameResult protoMsg = new GameFrameworkMessage.RequestNicknameResult(); List<string> nicknameList = m_NicknameSystem.RequestNicknames(accountId); protoMsg.m_Nicknames.AddRange(nicknameList); replyMsg.m_ProtoData = protoMsg; NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg); } }