/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using ProtoCSStruct; using Sog.Gate; namespace Realmlist { public class RootMessageHandler : BaseReloadableService { private ServerApp m_app; public override int GetServiceType() { return RealmlistServiceType.RootMessageHandler; } //销毁的时候置空 public override void Dispose() { m_app = null; } public RootMessageHandler(ServerApp app) { m_app = app; } public ServerApp GetApp() { return m_app; } public void HandlerMessage(uint remoteAppID, MessageData message) { int iServerType = ServerIDUtils.GetServerType(remoteAppID); TraceLog.Trace("RootMessageHandler.HandlerMessage recv msg from server type {0} length {1}", iServerType, message.Header.Length); HandlerOtherServerMessage(remoteAppID, message); return; } private void HandlerOtherServerMessage(uint remoteAppID, MessageData message) { try { StructPacket packet; bool result = RealmlistServerUtils.GetProtoPacker().UnpackMessage(message, out packet); if (result) { //预先判断,提高效率 if (TraceLog.GetLogLevel() <= (int)Sog.Log.LogLevel.TraceDetail && TraceLog.IsSkipLogMsgID(packet.MsgID) == false) { // log message TraceLog.TraceDetail("RootMessageHandler.HandlerOtherServerMessage 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()); } int iServerType = ServerIDUtils.GetServerType(remoteAppID); HandlerServerPacket(remoteAppID, packet); } } catch (Exception ex) { TraceLog.Error("RootMessageHandler.HandlerOtherServerMessage Received from server:{0} error:{1}" , ServerIDUtils.IDToString(remoteAppID), ex.Message); //TraceLog.Exception(ex); throw; } } private void HandlerServerPacket(uint remoteAppID, StructPacket packet) { switch (packet.MsgID) { // CS消息是accountsvr转发过来的 case (int)CSMsgID.GameListReq: RealmInfoHandler.OnClientGameListReq(remoteAppID, packet); break; case (int)SSMsgID.GameReportRealmlistReq: RealmInfoHandler.OnGameWorldReport(remoteAppID, packet); break; case (int)SSMsgID.RealmBriefReq: RealmInfoHandler.OnRealmBriefReq(remoteAppID, packet); break; case (int)SSMsgID.RealmAllbriefReq: RealmInfoHandler.OnRealmAllBriefReq(remoteAppID, packet); break; case (int)SSMsgID.AllRealmReq: RealmInfoHandler.OnAllRealmReq(remoteAppID, packet); break; case (int)SSMsgID.SsAddRealmReq: RealmInfoHandler.OnSsAddRealmReq(remoteAppID, packet); break; case (int)SSGameMsgID.AddServerTimeSync: OnAddServerTimeSync(remoteAppID, packet); break; case (int)SSMsgID.SsRealmOperationReq: RealmInfoHandler.OnRealmOperationReq(remoteAppID, packet); break; case (int)SSMsgID.SsRealmDbsaveRes: RealmlistDBSvc.OnRealmDBCfgSaveRes(remoteAppID, packet); break; case (int)SSMsgID.SsRealmDbqueryRes: RealmlistDBSvc.OnRealmCfgDBQueryRes(remoteAppID, packet); break; case (int)SSGameMsgID.OperationLimitReq: LimitIPList.OpLimitIPList(remoteAppID,packet); break; case (int)SSMsgID.SsRealmNewPlayer: RealmInfoHandler.SsRealmNewPlayer(remoteAppID, packet); break; default: break; } } private void OnAddServerTimeSync(uint remoteAppID, StructPacket packet) { ref SSAddServerTimeSync sync = ref packet.GetMessage(); TraceLog.Debug("RootMessageHandler.OnAddServerTimeSync serverid {0} offset {1}" , ServerIDUtils.IDToString(remoteAppID), sync.Offset); RealmlistServerUtils.GetApp().Time.SetOffset(sync.Offset); RealmlistServerUtils.GetApp().Time.UpdateTime(); TraceLog.Debug("RootMessageHandler.OnAddServerTimeSync serverid {0} offset {1} set time success" , ServerIDUtils.IDToString(remoteAppID), sync.Offset); } } }