private void HandleMessages(int maxCount) { try { for (int i = 0; i < maxCount; ++i) { if (m_MsgQueue.Count > 0) { NodeMessageInfo info = null; m_MsgQueue.TryDequeue(out info); if (null != info) { try { if (info.IsGmTool) { JsonGmMessageDispatcher.HandleNodeMessage(info.Seq, info.SourceHandle, info.DestHandle, info.Data); } else { NodeMessageDispatcher.HandleNodeMessage(info.Seq, info.SourceHandle, info.DestHandle, info.Data); } m_MsgPool.Enqueue(info); } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "NodeMessageThread JsonMessageDispatcher.HandleDcoreMessage() throw exception:{0}\n{1}", ex.Message, ex.StackTrace); } } } else { break; } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "NodeMessageThread.HandleMessages throw exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
//------------------------------------------------------------------------------------------------------ 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); }
/// <summary> /// 注意,node来的消息处理需要分发到DataProcess的用户线程里进行处理! /// </summary> private void InstallNodeHandlers() { NodeMessageDispatcher.Init(UserServerConfig.WorldId); NodeMessageDispatcher.SetMessageFilter(this.FilterMessage); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.NodeRegister, typeof(GameFrameworkMessage.NodeRegister), typeof(GameFrameworkMessage.NodeRegister), HandleNodeRegister); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.AccountLogin, typeof(GameFrameworkMessage.NodeMessageWithAccount), typeof(GameFrameworkMessage.AccountLogin), HandleAccountLogin); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.RequestNickname, typeof(GameFrameworkMessage.NodeMessageWithAccount), typeof(GameFrameworkMessage.RequestNickname), HandleRequestNickname); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.RoleEnter, typeof(GameFrameworkMessage.NodeMessageWithAccount), typeof(GameFrameworkMessage.RoleEnter), HandleRoleEnter); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.UserHeartbeat, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.UserHeartbeat), HandleUserHeartbeat); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.ChangeName, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.ChangeName), HandleChangeName); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.EnterScene, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.EnterScene), HandleEnterScene); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.ChangeSceneRoom, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.ChangeSceneRoom), HandleChangeSceneRoom); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.RequestSceneRoomInfo, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.RequestSceneRoomInfo), HandleRequestSceneRoomInfo); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.RequestSceneRoomList, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.RequestSceneRoomList), HandleRequestSceneRoomList); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.QuitRoom, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.QuitRoom), HandleQuitRoom); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_GetMailList, typeof(GameFrameworkMessage.NodeMessageWithGuid), null, HandleGetMailList); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_ReceiveMail, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_ReceiveMail), HandleReceiveMail); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_ReadMail, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_ReadMail), HandleReadMail); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_DeleteMail, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_DeleteMail), HandleDeleteMail); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_AddFriend, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_AddFriend), HandleAddFriend); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_RemoveFriend, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_RemoveFriend), HandleRemoveFriend); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_MarkBlack, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_MarkBlack), HandleMarkBlack); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_UseItem, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_UseItem), HandleUseItem); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CL_DiscardItem, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CL_DiscardItem), HandleDiscardItem); NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.Msg_CLC_StoryMessage, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.Msg_CLC_StoryMessage), HandleStoryMessage); //--------------------------------------------------------------------------------------------------------------- //大世界发给客户端的消息的观察者处理,此类消息的handle被置为0,如果非0不应该处理(消息为客户端伪造)。 //--------------------------------------------------------------------------------------------------------------- NodeMessageDispatcher.RegisterMessageHandler((int)LobbyMessageDefine.EnterSceneResult, typeof(GameFrameworkMessage.NodeMessageWithGuid), typeof(GameFrameworkMessage.EnterSceneResult), ObserveEnterSceneResult); //-------------------------------------------------------------------------------------- //GM指令消息统一放一块,处理函数放到LobbyServer_GmJsonHandler.cs里,便于安全检查 //不要在这个注释后注册消息!!! //-------------------------------------------------------------------------------------- }
private bool CheckBagCapacity(UserInfo user, TableMailInfoWrap 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.Guid; opMsg.m_ProtoData = protoData; NodeMessageDispatcher.SendNodeMessage(user.NodeName, opMsg); return(result); }
internal void NotifyAllUser(LobbyMessageDefine id, object msg) { UserServer.Instance.UserProcessScheduler.VisitUsers((UserInfo user) => { NodeMessage retMsg = new NodeMessage(id, user.Guid); retMsg.m_ProtoData = msg; NodeMessageDispatcher.SendNodeMessage(user.NodeName, retMsg); }); }
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 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); } }
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); }); }
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 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 HandleGeneralMessage(Msg_LBL_Message msg_, PBChannel channel, int src, uint session) { try { if (msg_.MsgType == Msg_LBL_Message.MsgTypeEnum.Node) { byte[] msgData = msg_.Data; //观察 m_UserProcessScheduler.DispatchJsonMessage(false, session, 0, 0, msgData); //转发 NodeMessageDispatcher.ForwardMessage(msg_.TargetName, msgData); } else if (msg_.MsgType == Msg_LBL_Message.MsgTypeEnum.Room) { m_BigworldChannel.Dispatch(src, session, msg_.Data); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
//------------------------------------------------------------------------------------------------------ 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 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); }
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); }
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); } }