You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

920 lines
47 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Linq;
using Sog;
using ProtoCSStruct;
using Sog.Gate;
namespace Game
{
public class RootMessageHandler : BaseReloadableService
{
private ServerApp m_app;
private GameServerData m_data;
public override int GetServiceType()
{
return GameServiceType.RootMessageHandler;
}
//销毁的时候置空
public override void Dispose()
{
m_app = null;
m_data = null;
}
public RootMessageHandler(ServerApp app, GameServerData serverData)
{
m_app = app;
m_data = serverData;
m_data.m_packetHandlerTable.Clear();
}
public ServerApp GetApp()
{
return m_app;
}
public void RegisterPacketHandler(int iMsgID, IPacketHandler handler)
{
if (m_data.m_packetHandlerTable.ContainsKey(iMsgID))
{
TraceLog.Error("msgtype {0} already be registed!", iMsgID);
return;
}
TraceLog.Debug("register MsgID {0} by handler {1}", iMsgID, handler.GetType().FullName);
m_data.m_packetHandlerTable.Add(iMsgID, handler);
}
public void RegisterAllPacketHandler()
{
//每次都是创建RootMessageHandler的时候注册一次,清理就放在构建函数里吧
//m_data.m_packetHandlerTable.Clear();
//login
LoginHandler loginHandler = GameServerUtils.GetLoginHandler();
RegisterPacketHandler((int)CSGameMsgID.WrapGameListReq, loginHandler);
RegisterPacketHandler((int)CSMsgID.GameListRes, loginHandler);
RegisterPacketHandler((int)SSMsgID.LoginCheckValidRes, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.LoginReq, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRoleReq, loginHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryRoleDbRes, loginHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryRoleDropDbRes, loginHandler);
RegisterPacketHandler((int)SSGameMsgID.SaveRoleRes, loginHandler);
RegisterPacketHandler((int)CSMsgID.BindGuestFacebookReq, loginHandler);
RegisterPacketHandler((int)CSMsgID.BindGuestFacebookRes, loginHandler);
RegisterPacketHandler((int)CSMsgID.UnbindGuestFacebookReq, loginHandler);
RegisterPacketHandler((int)CSMsgID.UnbindGuestFacebookRes, loginHandler);
RegisterPacketHandler((int)CSMsgID.QueryLoginsysnoticeReq, loginHandler);
RegisterPacketHandler((int)CSMsgID.QueryLoginsysnoticeRes, loginHandler);
RegisterPacketHandler((int)CSMsgID.UpdateAccountGradeReq, loginHandler);
RegisterPacketHandler((int)CSMsgID.UpdateAccountGradeRes, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.DownloadResourceReq, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.DownloadResourceRes, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.FirebaseIdReportReq, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.ReportInviteMeFbuserid, loginHandler);
RegisterPacketHandler((int)SSMsgID.QueryUidByFbuseridRes, loginHandler);
RegisterPacketHandler((int)SSGameMsgID.GmSetFreezeTimeRes, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.AdidReportReq, loginHandler);
RegisterPacketHandler((int)SSGameMsgID.WorldtogameDeleteplayersession, loginHandler);
RegisterPacketHandler((int)SSMsgID.GameReportRealmlistRes, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.WaitplayerRemaintimeNotify, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientBdcInfoReq, loginHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientBdcInfoRes, loginHandler);
//sys
SysHandler sysHandler = GameServerUtils.GetSysHandler();
RegisterPacketHandler((int)CSGameMsgID.Ping, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.Gmcmd, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.RenameReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.ChangeIconReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.CliReportBillReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.SaveClientDataReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.SaveClientBitFlagReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.TipOffPlayerReq, sysHandler);
//RegisterPacketHandler((int)CSGameMsgID.GagChatNotify, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.HideMyInfoReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.StatisticsChg, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.RolebaseChgReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.RolebaseChgRes, sysHandler);
//RegisterPacketHandler((int)SSGameMsgID.SysNoticeLampReq, sysHandler);
//RegisterPacketHandler((int)SSGameMsgID.ChatConsumeReq, sysHandler);
//RegisterPacketHandler((int)SSGameMsgID.ChatConsumeRes, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.DealgmcmdNotify, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlayerQueryOfflineRoleReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.PlayerSearchRoleBynameReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlayerSearchRoledbBynameRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.PlayerQueryOtherRoleInfoReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.PlayerQueryOtherRoleInfoRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientBdcReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientBdcRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientTaReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.LogClientTaRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.SetLanguageReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlayerPowerUpdate, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlayerMainlandUpdate, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlaydataOpReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.PlaydataOpRes, sysHandler);
RegisterPacketHandler((int)SSMsgID.RealmRoleBriefRes, sysHandler);
RegisterPacketHandler((int)SSMsgID.RealmBriefRes, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.CheckDirtyStringReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.CheckDirtyStringRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.ChangeIconFrameReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.SyspaychanelReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.SyspaychanelRes, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.PowerCliReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.TalentActiveReq, sysHandler);
RegisterPacketHandler((int)CSGameMsgID.TalentOptionsReq, sysHandler);
RegisterPacketHandler((int)SSGameMsgID.GmChangeRoleNameReq, sysHandler);
DynamicMsgHandler dynamicHandler = GameServerUtils.GetDynamicMsgHandler();
RegisterPacketHandler((int)CSGameMsgID.CommonDynamicReq, dynamicHandler);
RegisterPacketHandler((int)CSGameMsgID.CommonDynamicRes, dynamicHandler);
//bag
BagHandler bagHandler = GameServerUtils.GetBagHandler();
RegisterPacketHandler((int)CSGameMsgID.UseItemReq, bagHandler);
RegisterPacketHandler((int)SSGameMsgID.Reward, bagHandler);
RegisterPacketHandler((int)CSGameMsgID.SetItemNewgetReq, bagHandler);
RegisterPacketHandler((int)CSGameMsgID.GainPowerReq, bagHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryBagChangeHistoryListReq, bagHandler);
RegisterPacketHandler((int)SSGameMsgID.OperationCostItemReq, bagHandler);
//pay
PayHandler payHandler = GameServerUtils.GetPayHandler();
RegisterPacketHandler((int)CSGameMsgID.PayGoogleReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.PayGoogleSuccessReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.PayGetFreeItemReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.ClientTriggerItemArriveReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.PayItemStockInfoReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.CardGetDailyAwardReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.BattlePassAwardReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.SignGetAwardReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.SignReSingReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.FistPaymentAwardReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.PayWsjsapiReq, payHandler);
RegisterPacketHandler((int)CSGameMsgID.PayWsjsapiRes, payHandler);
RegisterPacketHandler((int)CSGameMsgID.FreeRewardReq, payHandler);
RegisterPacketHandler((int)SSGameMsgID.PayGoogleRes, payHandler);
RegisterPacketHandler((int)SSGameMsgID.PayGoogleSuccessRes, payHandler);
RegisterPacketHandler((int)SSGameMsgID.PayDbAddDiamondStatusRes, payHandler);
RegisterPacketHandler((int)SSGameMsgID.PayItemStockInfoRes, payHandler);
RegisterPacketHandler((int)SSGameMsgID.NotifyItemStockInfo, payHandler);
RegisterPacketHandler((int)SSGameMsgID.OperationFakepay, payHandler);
//mail
MailHandler mailHandler = GameServerUtils.GetMailHandler();
RegisterPacketHandler((int)SSGameMsgID.QueryMailRes, mailHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryMailReq, mailHandler);
RegisterPacketHandler((int)CSGameMsgID.MailOpReq, mailHandler);
RegisterPacketHandler((int)SSGameMsgID.MailOpRes, mailHandler);
RegisterPacketHandler((int)CSGameMsgID.MailSendToPlayerReq, mailHandler);
RegisterPacketHandler((int)CSGameMsgID.MailSendToPlayerRes, mailHandler);
RegisterPacketHandler((int)SSGameMsgID.OperationMailDeleteReq, mailHandler);
MonitorHandler monitorHandler = GameServerUtils.GetMonitorHandler();
RegisterPacketHandler((int)SSGameMsgID.OperationMonitorReq, monitorHandler);
RegisterPacketHandler((int)SSGameMsgID.SyncPresetRes, monitorHandler);
RegisterPacketHandler((int)SSGameMsgID.GmUpdateUserRoleReq, monitorHandler);
RegisterPacketHandler((int)SSGameMsgID.GmImportUserRoleReq, monitorHandler);
RegisterPacketHandler((int)SSGameMsgID.GmImportUserRoleRes, monitorHandler);
RegisterPacketHandler((int)CSGameMsgID.GmCmdReq, monitorHandler);
//friend
FriendHandler friendHandler = GameServerUtils.GetFriendHandler();
RegisterPacketHandler((int)CSGameMsgID.QueryFriendListReq, friendHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryFriendListRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendSelfChgNotify, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendListChgNotify, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryFriendStatusReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryFriendStatusRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryOtherDetailReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryOtherDetailRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGiftOpReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGiftOpRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGiftAutoOpReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGiftAutoOpRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.GetFriendGiftDataReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.GetFriendGiftDataRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendSendGiftNotify, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendQueryBlacklistReq, friendHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryBlacklistRes, friendHandler);
//personalized sign
RegisterPacketHandler((int)CSGameMsgID.SetPersonalizedSignatureReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.SetPersonalizedSignatureRes, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendSetSettingReq, friendHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendSetSettingRes, friendHandler);
//friend op
FriendOpHandler friendOpHandler = GameServerUtils.GetFriendOpHandler();
RegisterPacketHandler((int)CSGameMsgID.FriendOpReq, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendOpRes, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryFriendOpReq, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryFriendOpRes, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendOpListChgNotify, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendStrangerListChgNotify, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendStrangerListDeleteNotify, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendQueryStrangerReq, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendQueryStrangerRes, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendQueryInfoByUidReq, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendQueryInfoByUidRes, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGetRecommenderReq, friendOpHandler);
RegisterPacketHandler((int)CSGameMsgID.FriendGetRecommenderRes, friendOpHandler);
//rank
RankHandler rankHandler = GameServerUtils.GetRankHandler();
RegisterPacketHandler((int)CSGameMsgID.QueryRankListReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankListRes, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankSelfReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankSelfRes, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankDetailReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankDetailRes, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankTopReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryRankTopRes, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.AddRankDataReq, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.AddRankDataRes, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.UpdateAwardRank, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.PlayerShowinfoUpdate, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.NoticeRankChange, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.UpdateSelfRankscore, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.ClearRankReq, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.ClearRankRes, rankHandler);
//活动排行
RegisterPacketHandler((int)SSGameMsgID.QueryActRankDbReq, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryActRankDbRes, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.AddActRankDataReq, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.AddActRankDataRes, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryActRankListReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryActRankListRes, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.SaveActRankDataReq, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.SaveActRankDataRes, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryActRankActivityListReq, rankHandler);
RegisterPacketHandler((int)CSGameMsgID.QueryActRankActivityListRes, rankHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryRankOneRes, rankHandler);
RegisterPacketHandler((int)SSMsgID.QueryUidByWxidRes, rankHandler);
// task ex
TaskEXHandler taskEXHandler = GameServerUtils.GetTaskEXHandler();
RegisterPacketHandler((int)CSGameMsgID.TaskexAcceptTaskReq, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexAcceptTaskRes, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexHandoverTaskReq, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.BatchTaskexHandoverTaskReq, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexHandoverTaskRes, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexChangeNotify, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexDeleteNotify, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexUpexinfoReq, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexUpexinfoRes, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexBatchUpexinfoReq, taskEXHandler);
RegisterPacketHandler((int)CSGameMsgID.TaskexBatchUpexinfoRes, taskEXHandler);
RegisterPacketHandler((int)SSGameMsgID.OperationUpdateTaskReq, taskEXHandler);
//battle match
//hero
//Equipment start
EquipmentHandler equipmentHandler = GameServerUtils.GetEquipmentHandler();
RegisterPacketHandler((int)CSGameMsgID.EquipShowChangeReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.RecruitReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.RecruitChooseRewardReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipBatchsell, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipOpReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipBuyDepot, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipSetNewget, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipPutDepot, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.SkinPuton, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.SkinSetNewget, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemWear, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemCompose, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemComposeOne, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemComposeOneSave, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemLock, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.GemSetnewget, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.PresetSaveReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.PresetApplyReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.PresetBuyOneReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.PresetRenameReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.EquipCombatPreview, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.OnChangeStarWearReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.OnChangeWingSkinReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.OnUpgradeMainWingReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.OnUpgradeWingSkinReq, equipmentHandler);
RegisterPacketHandler((int)CSGameMsgID.OnMarkWingNewGetReq, equipmentHandler);
LevelHandler levelHandler = GameServerUtils.GetLevelHandler();
RegisterPacketHandler((int)CSGameMsgID.PeaklevelAddpoint, levelHandler);
RegisterPacketHandler((int)CSGameMsgID.PeaklevelResetpoint, levelHandler);
RegisterPacketHandler((int)CSGameMsgID.BuyPowerReq, levelHandler);
//battleTeamHandler
//mainland start
//MarketShop
MarketShopHandler marketShopHandler = GameServerUtils.GetMarketShopHandler();
RegisterPacketHandler((int)CSGameMsgID.MarketShopBuyGoodsReq, marketShopHandler);
RegisterPacketHandler((int)CSGameMsgID.MarketShopBuyGoodsRes, marketShopHandler);
RegisterPacketHandler((int)CSGameMsgID.MarketShopRefreshReq, marketShopHandler);
RegisterPacketHandler((int)CSGameMsgID.MarketShopRefreshRes, marketShopHandler);
NameHandler nameHandler = GameServerUtils.GetNameHandle();
RegisterPacketHandler((int)CSGameMsgID.NameQueryUsedReq, nameHandler);
RegisterPacketHandler((int)CSGameMsgID.NameQueryUsedRes, nameHandler);
RegisterPacketHandler((int)SSMsgID.NameQueryRes, nameHandler);
HomeAdHandler homeAdHandler = GameServerUtils.GetHomeAdHandler();
RegisterPacketHandler((int)CSGameMsgID.HomeadAdLoadSyn, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.HomeadAdGetAwardReq, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.HomeadAdGetAwardRes, homeAdHandler);
RegisterPacketHandler((int)SSGameMsgID.HomeAdSendAwardSyn, homeAdHandler);
RegisterPacketHandler((int)SSGameMsgID.HomeAdShowAdSyn, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.HomeadAdPassReq, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.HomeadAdPassRes, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdStartReq, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdStartRes, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdEndReq, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdEndRes, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdGetInfoReq, homeAdHandler);
RegisterPacketHandler((int)CSGameMsgID.AdGetInfoRes, homeAdHandler);
BeginnerGuideHandler beginnerGuideHandler = GameServerUtils.GetBeginnerGuideHandler();
RegisterPacketHandler((int)CSGameMsgID.BeginnerGuideChangeReq, beginnerGuideHandler);
RegisterPacketHandler((int)CSGameMsgID.BeginnerGuideChangeRes, beginnerGuideHandler);
RegisterPacketHandler((int)CSGameMsgID.BeginnerGuideAwardReq, beginnerGuideHandler);
//聊天屏蔽
ChatHandler chatHandler = GameServerUtils.GetChatHandler();
RegisterPacketHandler((int)CSGameMsgID.GetChatBlacklistReq, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.GetChatBlacklistRes, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.AddChatBlacklistReq, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.AddChatBlacklistRes, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.DelChatBlacklistReq, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.DelChatBlacklistRes, chatHandler);
RegisterPacketHandler((int)SSGameMsgID.QueryRoleBaseInfoListRes, chatHandler);
RegisterPacketHandler((int)CSGameMsgID.ReportCheatReq, chatHandler);
var chapterHandler = new ChapterHandler();
RegisterPacketHandler((int)CSGameMsgID.BattleBeginReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.BattleOptionReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OntickBattleEntityReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.KilledMonsterReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.BattleActiveAltarReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OnPickupMonsterRewardReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.MopUpReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OnBattlePushPropDataReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OnGainBattleRewardReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OnGainAllBattleRewardReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.CbStartReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.CbFinishReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.CbGetlayerrewardReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.CbLeaveReq, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.RankPlayerBylevelRes, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.CbcPlayerSync, chapterHandler);
RegisterPacketHandler((int)CSGameMsgID.OnBattleDefeatReq, chapterHandler);
var activityHandler = new ActivityHandler();
RegisterPacketHandler((int)CSGameMsgID.HandbookGetAwardReq, activityHandler);
RegisterPacketHandler((int)CSGameMsgID.QuestionnaireRewardReq, activityHandler);
RegisterPacketHandler((int)CSGameMsgID.GetActivityInfoReq, activityHandler);
}
public void HandlerMessage(uint remoteAppID, MessageData message)
{
int iServerType = ServerIDUtils.GetServerType(remoteAppID);
if (iServerType == (int)ServerType.GameGate)
{
TraceLog.Trace("RootMessageHandler recv msg from gate length {0}, serverid {1}"
, message.Header.Length, ServerIDUtils.IDToString(remoteAppID));
HandlerGateMessage(remoteAppID, message);
return;
}
else
{
TraceLog.Trace("RootMessageHandler recv msg from server type {0} length {1} serverid {2}"
, iServerType, message.Header.Length, ServerIDUtils.IDToString(remoteAppID));
HandlerOtherServerMessage(remoteAppID, message);
return;
}
}
private void HandlerGateMessage(uint remoteAppID, MessageData message)
{
GateMsgHeader header = new GateMsgHeader();
GateMsgHeaderPacker.UnPack(message.Buffer.Data, ref header);
// trans msg to client
if (header.OpCode == (int)GateMsgOpCode.Trans)
{
//停服不处理任何客户端来的消息
//注意:disconnect消息还是需要处理
if (m_app.CurrStopStage == ServerStopStage.stopping)
{
return;
}
HandlerClientGateMessage(remoteAppID, header.SessionID, message);
return;
}
if (header.OpCode == (int)GateMsgOpCode.ConnectedReq)
{
//停服不处理任何客户端来的消息
//注意:disconnect消息还是需要处理
if (m_app.CurrStopStage == ServerStopStage.stopping)
{
return;
}
GateClientConnectedReq req = GateClientConnectedReq.ParseFrom(message.Buffer.Data, GateMsgHeaderPacker.GetLength());
OnSessionConnected(remoteAppID, header.SessionID, req);
return;
}
if (header.OpCode == (int)GateMsgOpCode.DisconnectedReq)
{
OnSessionDisconnected(remoteAppID, header.SessionID);
return;
}
if (header.OpCode == (int)GateMsgOpCode.ClientCount)
{
//通知world
SSGameReportReq gameReportReq = new SSGameReportReq();
gameReportReq.GameSvrid = remoteAppID;
gameReportReq.OnlinePlayer = (int)header.SessionID;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GameReportReq, ref gameReportReq, 0);
}
}
//这里不再应答
private void OnSessionConnected(uint gateServerID, long sessionID, GateClientConnectedReq req)
{
SSGameConnectNotify notify = new SSGameConnectNotify();
notify.GateServerID = gateServerID;
notify.PlayerSessionID = sessionID;
notify.IPAddr.SetString(req.IPAddress);
notify.IsConnect = true; //表示连接
notify.CurLoginSerialNum = 0;
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GametoworldConnectnotify, ref notify, sessionID, GameServerUtils.GetAppID());
}
private void OnSessionDisconnected(uint gateServerID, long sessionID)
{
//这里处理下特殊情况
//1:玩家刚好connect上,也发送了登录请求,就立即下线了
//这个时候OnLoginCheckRes会正常返回并创建playersession,但是之后消息是到不了前端的,这个playersession将一直存在
//这里要通知下world,这个连接已经无效了,
//2:如果这条消息在world 的 OnLoginCheckReq之前收到,那么这里可以不做任何处理
//如果在这之后,就要world再通知下game
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(sessionID);
if (playerSession == null)
{
SSGameConnectNotify notify = new SSGameConnectNotify();
notify.GateServerID = gateServerID;
notify.PlayerSessionID = sessionID;
notify.IsConnect = false;
notify.CurLoginSerialNum = 0; //这个只能是0,逻辑依赖world
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GametoworldConnectnotify, ref notify, sessionID, GameServerUtils.GetAppID());
}
else
{
//不为空的情况下
GameServerUtils.GetPlayerDataSvc().OnSessionDisconnected(gateServerID, sessionID);
}
}
private void HandlerClientGateMessage(uint gateServerID, long sessionID, MessageData gateMessage)
{
int headLength = GateMsgHeaderPacker.GetLength();
MessageData message = new MessageData();
message.Header.Type = gateMessage.Header.Type;
message.Header.Length = gateMessage.Header.Length - headLength;
if (message.Header.Length < 0)
{
TraceLog.Error("RootMessageHandler.HandlerClientGateMessage recv playersession {0} message ,gateMessage length error ", sessionID);
return;
}
message.MallocData(message.Header.Length);
//message.Data = new byte[message.Header.Length];
Buffer.BlockCopy(gateMessage.Buffer.Data, headLength, message.Buffer.Data, 0, message.Buffer.Length);
try
{
if (message.Header.Type == (int)CSGameMsgID.LoginReq)
{
HandlerClientLoginReqMessage(sessionID, message);
return;
}
PlayerSession playerSession = GameServerUtils.GetPlayerTableOp().GetPlayerSession(sessionID);
if (playerSession == null)
{
TraceLog.Error("RootMessageHandler can not find PlayerSession on trans msg, sessionid {0}.messType {1}",
sessionID, message.Header.Type);
return;
}
HandlerClientMessage(gateServerID, playerSession, message);
}
finally
{
message.FreeData();
}
}
//这里是登陆的真正转发逻辑
private void HandlerClientLoginReqMessage(long sessionID, MessageData message)
{
try
{
StructPacket packet = null;
bool result = false;
try
{
result = GameServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
}
catch (Exception ex)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage type {0} UnpackMessage error {1}"
, message.Header.Type, ex.Message);
return;
}
// StructPacket packet;
// bool result = GameServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
if (result)
{
ref CSLoginReq loginReq = ref packet.GetMessage<CSLoginReq>();
TraceLog.Trace("RootMessageHandler.HandlerClientLoginReqMessage session {0} accType {1} accId {2} accToken {3} accPlatform {4} apkver {5} ip {6} realm {7}",
sessionID,
loginReq.Account.AccountType,
loginReq.Account.AccountID,
loginReq.Account.AccountToken,
loginReq.Account.PlatformType,
loginReq.ApkVersion,
loginReq.IPAddr,
loginReq.RealmId);
if (loginReq.RealmId <= 0)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage invalid realmId {0}", loginReq.RealmId);
return;
}
if (loginReq.Account.AccountID.Length == 0)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage no account info ");
return;
}
if (loginReq.Version.Os.Length == 0)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage no version info ");
return;
}
if (loginReq.Version.Language.Length == 0)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage language info empty!");
return;
}
//校验realm
int loginRealmId = loginReq.RealmId;
var realmList = GameServerUtils.GetGameServerData().m_configRealm;
RealmBriefInfo realm = realmList.FirstOrDefault(r => r.realmId == loginRealmId);
if (realm == null)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage realmId {0} is null, realmCount {1}", loginRealmId, realmList.Count);
return;
}
// 不可见的服务器只有ip白名单可以进入
if (GameServerUtils.GetServerConfig().checkRealmVisible == 1
&& GameServerUtils.GetTimeSecond() < realm.visibleTime)
{
if (!LimitIPList.IsInWhiteList(loginReq.IPAddr.GetString(), loginReq.DeviceId.GetString()))
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage realm {0} visibletime {1} can't login"
, realm.realmId, realm.visibleTime);
return;
}
}
TraceLog.Trace("accid {0} client language {1}", loginReq.Account.AccountID.GetString(), loginReq.Version.Language.GetString());
loginReq.Version.Language.SetString(Sog.Lang.LanguageUtils.GetLangByClientOsLanguage(loginReq.Version.Language.GetString()));
//发给WorldServer,由WorldServer校验
GameServerUtils.GetPacketSender().SendToWorldServer<CSLoginReq>(packet, sessionID, GameServerUtils.GetAppID());
}
else
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage packet id {0} UnpackMessage login failed, sessionID {1}"
, message.Header.Type, sessionID);
string dataHex = StringUtils.ToHexString(message.Buffer.Data, message.Buffer.Length);
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage data {0}", dataHex);
}
}
catch (Exception ex)
{
TraceLog.Error("RootMessageHandler.HandlerClientLoginReqMessage Received from playersession:{0} get exception,handler error:{1}"
, sessionID, ex.Message);
//TraceLog.Exception(ex);
throw;
}
}
private void HandlerClientMessage(uint gateServerID, PlayerSession playerSession, MessageData message)
{
try
{
//这种情况只处理登录相关消息,其他一律丢掉,减少没必要的错误日志,客户端代码没太关注这块
if (playerSession.UserID == 0
&& message.Header.Type != (int)CSGameMsgID.LoginReq)
{
TraceLog.Error("Drop message type {0} session {1} not login"
, message.Header.Type, playerSession.SessionID);
return;
}
// 这种情况只处理登录相关消息,其他一律丢掉,减少没必要的错误日志,客户端代码没太关注这块
if (playerSession.UserID != 0
&& playerSession.Player == null
&& message.Header.Type != (int)CSGameMsgID.QueryRoleReq
&& message.Header.Type != (int)CSGameMsgID.LogClientBdcReq
&& message.Header.Type != (int)CSGameMsgID.LogClientTaReq
&& message.Header.Type != (int)CSGameMsgID.LogClientBdcInfoReq)
{
TraceLog.Error("Drop message type {0} session {1} uid {2} not query role"
, message.Header.Type, playerSession.SessionID, playerSession.UserID);
return;
}
StructPacket packet = null;
bool result = false;
try
{
result = GameServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
}
catch (Exception ex)
{
TraceLog.Error("RootMessageHandler.HandlerClientMessage type {0} UnpackMessage error {1}"
, message.Header.Type, ex.Message);
return;
}
// StructPacket packet;
// bool result = GameServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
if (result)
{
if (TraceLog.IsSkipLogMsgID(packet.MsgID))
{
//预先判断,提高效率
if (TraceLog.NeedLogUserTraceLevel(playerSession.UserID))
{
// log message
playerSession.TraceDetail("RootMessageHandler.HandlerClientMessage recv from playersession {0}-{1} from gateServer {2}, message type {3} length {4} : {5}"
, playerSession.SessionID
, playerSession.UserID
, ServerIDUtils.IDToString(playerSession.GateServerID)
, message.Header.Type
, message.Header.Length
, packet.MessageName());
}
else
{
if (TraceLog.GetLogLevel() <= Sog.Log.LogLevel.TraceDetail)
{
TraceLog.TraceDetail("RootMessageHandler.HandlerClientMessage recv from playersession {0}-{1} from gateServer {2}, message type {3} length {4} : {5}"
, playerSession.SessionID
, playerSession.UserID
, ServerIDUtils.IDToString(playerSession.GateServerID)
, message.Header.Type
, message.Header.Length
, packet.MessageName());
}
}
}
else
{
//预先判断,提高效率
if (TraceLog.NeedLogUserTraceLevel(playerSession.UserID))
{
// log message
playerSession.TraceDetail("RootMessageHandler.HandlerClientMessage recv from playersession {0}-{1} from gateServer {2}, message type {3} length {4} : {5}->{6}"
, playerSession.SessionID
, playerSession.UserID
, ServerIDUtils.IDToString(playerSession.GateServerID)
, message.Header.Type
, message.Header.Length
, packet.MessageName()
, packet.ToString());
}
else
{
if (TraceLog.GetLogLevel() <= Sog.Log.LogLevel.TraceDetail)
{
TraceLog.TraceDetail("RootMessageHandler.HandlerClientMessage recv from playersession {0}-{1} from gateServer {2}, message type {3} length {4} : {5}->{6}"
, playerSession.SessionID
, playerSession.UserID
, ServerIDUtils.IDToString(playerSession.GateServerID)
, message.Header.Type
, message.Header.Length
, packet.MessageName()
, packet.ToString());
}
}
}
IPacketHandler handler;
m_data.m_packetHandlerTable.TryGetValue(packet.MsgID, out handler);
if (handler == null)
{
playerSession.Error("RootMessageHandler.HandlerClientMessage packet id {0} not handler,please register a IPacketHandler first!"
, packet.MsgID);
return;
}
handler.HandlerClientPacket(playerSession, packet);
//收到客户端的任何消息都相当于收到ping,设置一下时间
if (playerSession.Player != null)
{
playerSession.Player.PingInfo.LastRecvPingTime = GameServerUtils.GetTimeSecond();
}
}
else
{
playerSession.Error("RootMessageHandler.HandlerClientMessage packet id {0} UnpackMessage failed, uid {1}"
, message.Header.Type, playerSession.UserID);
string dataHex = StringUtils.ToHexString(message.Buffer.Data, message.Buffer.Length);
playerSession.Error("RootMessageHandler.HandlerClientMessage data {0}", dataHex);
}
}
catch (Exception ex)
{
TraceLog.Error("RootMessageHandler.HandlerClientMessage Received from playersession:{0} get exception,handler error:{1}"
, playerSession.SessionID, ex.Message);
//TraceLog.Exception(ex);
throw;
}
}
private void HandlerOtherServerMessage(uint remoteAppID, MessageData message)
{
try
{
StructPacket packet;
bool result = GameServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
if (result)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (TraceLog.IsSkipLogMsgID(packet.MsgID) == false)
{
//预先判断,提高效率
if (player != null && TraceLog.NeedLogUserTraceLevel(player.UserID))
{
// log message
player.TraceDetail("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());
}
else
{
if (TraceLog.GetLogLevel() <= Sog.Log.LogLevel.TraceDetail)
{
TraceLog.TraceDetail("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());
}
}
}
IPacketHandler handler;
m_data.m_packetHandlerTable.TryGetValue(packet.MsgID, out handler);
if (handler == null)
{
TraceLog.Error("RootMessageHandler.HandlerOtherServerMessage packet id {0} not handler,please register it first!"
, packet.MsgID);
return;
}
int iServerType = ServerIDUtils.GetServerType(remoteAppID);
handler.HandlerServerPacket(remoteAppID, packet);
}
}
catch (Exception ex)
{
TraceLog.Error("Received from server:{0} error:{1}", ServerIDUtils.IDToString(remoteAppID), ex.Message);
//TraceLog.Exception(ex);
throw;
}
}
}
}