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); } }
internal void GMLoadUser(string gmAccount, ulong userGuid, LobbyGmMessageDefine jsonMsgId, int nodeHandle) { string key = userGuid.ToString(); Msg_LD_Load msg = new Msg_LD_Load(); msg.MsgId = (int)DataEnum.TableUserInfo; msg.PrimaryKeys.Add(key); Msg_LD_SingleLoadRequest reqUser = new Msg_LD_SingleLoadRequest(); reqUser.MsgId = (int)DataEnum.TableUserInfo; reqUser.LoadType = Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadSingle; reqUser.Keys.Add(key); msg.LoadRequests.Add(reqUser); RequestLoad(msg, (ret) => { JsonMessage resultMsg = new JsonMessage(jsonMsgId, gmAccount); GameFrameworkMessage.Msg_LC_GmQueryUser protoData = new GameFrameworkMessage.Msg_LC_GmQueryUser(); protoData.m_Result = GameFrameworkMessage.GmResultEnum.Failed; protoData.m_Info = null; KeyString primaryKey = KeyString.Wrap(ret.PrimaryKeys); if (Msg_DL_LoadResult.ErrorNoEnum.Success == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, "DataCache Load Success: Msg:{0}, Key:{1}", "GmUser", primaryKey); 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; } } } protoData.m_Result = GameFrameworkMessage.GmResultEnum.Success; protoData.m_Info = CreateGmUserInfo(dataUser); } else if (Msg_DL_LoadResult.ErrorNoEnum.NotFound == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "DataCache Load NotFound: Msg:{0}, Key:{1}", "GmUser", primaryKey); } else { LogSys.Log(LOG_TYPE.ERROR, "DataCache Load Failed: Msg:{0}, Key:{1}, ERROR:{2}", "GmUser", primaryKey, ret.ErrorInfo); } resultMsg.m_ProtoData = protoData; JsonGmMessageDispatcher.SendNodeMessage(nodeHandle, resultMsg); }); }
/// <summary> /// 注意,node来的消息处理需要分发到DataProcess的用户线程里进行处理! /// 注意,GM工具消息与客户端GM消息不要混用,实现代码要分开放(后面代码里有有标注,客户端的GM消息处理在前,GM工具的在后,中间有分隔区)!!! /// </summary> private void InstallGmJsonHandlers() { //客户端GM消息 if (UserServerConfig.WorldIdNum > 0) { JsonGmMessageDispatcher.Init(UserServerConfig.WorldId1); //GM工具消息 } }
// internal void GMLoadAccount(string gmAccount, string accountId, int nodeHandle) { Msg_LD_Load msg = new Msg_LD_Load(); msg.MsgId = (int)DataEnum.TableAccount; msg.PrimaryKeys.Add(accountId); Msg_LD_SingleLoadRequest reqAccount = new Msg_LD_SingleLoadRequest(); reqAccount.MsgId = (int)DataEnum.TableAccount; reqAccount.LoadType = Msg_LD_SingleLoadRequest.LoadTypeEnum.LoadSingle; reqAccount.Keys.Add(accountId); msg.LoadRequests.Add(reqAccount); RequestLoad(msg, (ret) => { JsonMessage resultMsg = new JsonMessage(LobbyGmMessageDefine.Msg_CL_GmQueryAccount, gmAccount); GameFrameworkMessage.Msg_LC_GmQueryAccount protoData = new GameFrameworkMessage.Msg_LC_GmQueryAccount(); protoData.m_Result = GameFrameworkMessage.GmResultEnum.Failed; protoData.m_QueryAccount = accountId; protoData.m_AccountState = GameFrameworkMessage.GmStateEnum.Offline; resultMsg.m_ProtoData = protoData; KeyString primaryKey = KeyString.Wrap(ret.PrimaryKeys); if (Msg_DL_LoadResult.ErrorNoEnum.Success == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "DataCache Load Success: Msg:{0}, Key:{1}", "GmAccount", primaryKey); TableAccount dataAccount = 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.TableAccount: dataAccount = _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; } } } protoData.m_Result = GameFrameworkMessage.GmResultEnum.Success; protoData.m_QueryAccount = dataAccount.AccountId; protoData.m_AccountState = GameFrameworkMessage.GmStateEnum.Online; if (dataAccount.IsBanned) { protoData.m_AccountState = GameFrameworkMessage.GmStateEnum.Banned; } } else if (Msg_DL_LoadResult.ErrorNoEnum.NotFound == ret.ErrorNo) { LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Yellow, "DataCache Load NotFound: Msg:{0}, Key:{1}", "GmAccount", primaryKey); } else { LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "DataCache Load Failed: Msg:{0}, Key:{1}, ERROR:{2}", "GmAccount", primaryKey, ret.ErrorInfo); } resultMsg.m_ProtoData = protoData; JsonGmMessageDispatcher.SendNodeMessage(nodeHandle, resultMsg); }); }