using Sog; using Sog.Service; using ProtoCSStruct; using Sog.Gate; namespace Operation { public class OperationMsgHandler : BaseReloadableService { private ServerApp m_app; private static int seq = 0; public override int GetServiceType() { return OperationServiceType.OperationMsgHandler; } //销毁的时候置空 public override void Dispose() { m_app = null; } LitJson.JsonData builder = new LitJson.JsonData(); public OperationMsgHandler(ServerApp app) { m_app = app; } public ServerApp GetApp() { return m_app; } public void HandlerMessage(uint remoteAppID, MessageData message) { StructPacket packet; bool bSuccess = OperationServerUtils.GetProtoPacker().UnpackMessage(message, out packet); if (bSuccess == false) { TraceLog.Error("OperationMsgHandler.HandlerMessage unpack msg failed {0}, remoteAppID {1}", message.Header.Type, remoteAppID); return; } //预先判断,提高效率 if (TraceLog.GetLogLevel() <= (int)Sog.Log.LogLevel.TraceDetail) { TraceLog.TraceDetail("OperationMsgHandler.HandlerMessage recv message from server {0}, message type {1} length {2} : {3}->{4}" , ServerIDUtils.IDToString(remoteAppID) , message.Header.Type , message.Header.Length , packet.MessageName() , packet.ToString()); } packet = packet.Clone(); switch (packet.MsgID) { case (int)SSMsgID.RealmBriefRes: OperationServerUtils.GetRealmlistSvc().OnRealmBriefRes(remoteAppID, packet); break; case (int)SSMsgID.RealmAllbriefRes: OperationServerUtils.GetRealmlistSvc().OnRealmAllbriefRes(remoteAppID, packet); break; case (int)SSMsgID.SsAddRealmRes: OperationServerUtils.GetRealmlistSvc().OnAddRealmRes(remoteAppID, packet); break; case (int)SSMsgID.SsRealmOperationRes: OperationServerUtils.GetRealmlistSvc().OnRealmOperationRes(remoteAppID, packet); break; case (int)SSMsgID.AllRealmRes: OperationServerUtils.GetRealmlistSvc().OnAllRealmRes(remoteAppID, packet); break; case (int)SSMsgID.RealmOnlineplayerToOpsvr: OperationServerUtils.GetRealmlistSvc().OnRealmOnlinePlayer(remoteAppID, packet); break; case (int)SSGameMsgID.GmQueryUserPayRecordRes: PayRecordReq.Instance.OnUserPayRes(remoteAppID, packet); break; case (int)SSGameMsgID.GmQueryUserAccountinfoRes: PayRecordReq.Instance.OnUserAccountInfoRes(remoteAppID, packet); break; case (int)SSGameMsgID.GmQueryUserRoleRes: PayRecordReq.Instance.OnUserRoleInfoRes(remoteAppID, packet); break; case (int)SSGameMsgID.GmChangeRoleNameRes: ChangeName.OnChangeRoleNameRes(remoteAppID, packet); break; case (int)SSGameMsgID.GmImportUserRoleRes: PlayerMonitor.OnImportRoleDataRes(remoteAppID, packet); break; case (int)SSMsgID.SyncRoleinfoToOpsvr: RoleInfoMap.OnSyncRoleinfoToOpsvr(remoteAppID, packet); break; case (int)SSGameMsgID.BillLogReq: break; case (int)SSGameMsgID.ExchangeQueryDbRes: OperationServerUtils.GetExchangeSvc().OnExchangeQueryDbRes(remoteAppID, packet); break; case (int)SSGameMsgID.ExchangeSaveDbRes: OperationServerUtils.GetExchangeSvc().OnExchangeSaveDbRes(remoteAppID, packet); break; case (int)SSGameMsgID.ExchangeStatusChangeRes: OperationServerUtils.GetExchangeSvc().OnExchangeChangeStatusDbRes(remoteAppID, packet); break; case (int)SSGameMsgID.OperationCostItemRes: break; case (int)SSGameMsgID.OperationMailSearchRes: PlayerMonitor.OnSearchMailRes(remoteAppID, packet); break; case (int)SSGameMsgID.GmUpdateUserRoleRes: PlayerMonitor.OnUpdateRoleDataRes(remoteAppID, packet); break; case (int)SSGameMsgID.OperationMailDeleteRes: PlayerMonitor.OnDeleteMailRes(remoteAppID, packet); break; case (int)SSGameMsgID.OperationMonitorRes: ServerMonitor.OnServerMonitorMsg(remoteAppID, packet); break; case (int)SSGameMsgID.OperationLimitRes: Limit.OnSelectLimitIpRes(remoteAppID, packet); break; case (int)SSGameMsgID.NoticeBackgroundsReq: case (int)SSGameMsgID.GmSetFreezeTimeRes: case (int)SSGameMsgID.EnableSendMsgRes: case (int)SSGameMsgID.GetMailWithRuleReq: case (int)SSGameMsgID.SendMailWithRuleRes: case (int)SSGameMsgID.PlaydataOpReq: case(int)SSGameMsgID.OperationFakepayRes: case (int)SSGameMsgID.OperationUpdateTaskRes: case (int)SSGameMsgID.SyncPresetReq: AddMessageTaskDistributor(remoteAppID, packet); break; case (int)SSGameMsgID.RewardRes: { GMReward.OnRewardRes(remoteAppID, packet); break; } default: TraceLog.Error("OperationMsgHandler.HandlerMessage unknow MsgID {0}", packet.MsgID); break; } } //http api发来的,按httpContextId分配 public static void AddMessageTaskDistributor(uint httpContextId, uint serverID, StructPacket packet) { int iTaskIndex = (int)(httpContextId % MessageTaskHandler.DBWorkThreadCount); TraceLog.Debug("OperationMsgHandler.AddMessageTaskDistributor from http api iTaskIndex {0} httpContextId {1}", iTaskIndex, httpContextId); MessageTaskDistributor.Instance.Distribute(serverID, packet, iTaskIndex); } //服务发来的,按轮询分配 public static void AddMessageTaskDistributor(uint serverID, StructPacket packet) { int iTaskIndex = (int)(seq++ % MessageTaskHandler.DBWorkThreadCount); TraceLog.Debug("OperationMsgHandler.AddMessageTaskDistributor from server iTaskIndex {0} seq {1}", iTaskIndex, seq-1); MessageTaskDistributor.Instance.Distribute(serverID, packet, iTaskIndex); } //玩家发来的,按玩家uid分配 public static void AddMessageTaskDistributor(long uid, uint serverID, StructPacket packet) { int iTaskIndex = (int)(uid % MessageTaskHandler.DBWorkThreadCount); TraceLog.Debug("OperationMsgHandler.AddMessageTaskDistributor from player iTaskIndex {0} uid {1}", iTaskIndex, uid); MessageTaskDistributor.Instance.Distribute(serverID, packet, iTaskIndex); } } }