using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using ProtoCSStruct; namespace World { public static class WorldServerUtils { public static WorldServerData GetWorldServerData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldServerData); } public static WorldBattleRecordDataCache GetWorldMainlandRecordData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.MainlandRecord); } public static LogicWorldRecordInfo GetLogicWorldRecordInfo(int logicWorldId) { var data = GetWorldMainlandRecordData(); if(data.m_logicWorldMap.TryGetValue(logicWorldId, out var oneInfo)) { return oneInfo; } return null; } //public static WorldBattleReplayAllInfoCache GetWorldReplayCahceData() //{ // return ServerDataObjMgr.GetDataObj(WorldDataObjType.BattleReplayData); //} public static ProtoCSStructPacker GetProtoPacker() { return ProtoPackerFactory.Instance.GetProtoCSStructPacker(); } public static StructPacketSender GetPacketSender() { return GetWorldServerData().m_packetSender; } public static PlayerTable GetPlayerTable() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.PlayerTable); } public static WorldRankData GetWorldRankData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldRankData); } public static WorldGlobalData GetWorldGlobalData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldGlobalData); } public static WaitInLinePlayerTableData GetWaitInLinePlayerTableData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WaitInLinePlayerTableData); } public static RoleCacheInfoSvc GetRoleCacheInfoSvc() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.RoleCacheInfo); } public static WorldHomeData GetWorldHomeData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldHomeData); } public static WorldLoginLoadingData GetWorldLoginLoadingData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldLoginLoadingData); } public static WorldUnionChangeCacheData GetUnionChangeCacheData() { return ServerDataObjMgr.GetDataObj(WorldDataObjType.WorldUnionChangeCacheData); } ///service public static PlayerTableOp GetPlayerTableOp() { return ServiceMgr.GetService(WorldServiceType.PlayerTableOp); } public static WaitInLinePlayerTableDataOp GetWaitInLinePlayerTableDataOp() { return ServiceMgr.GetService(WorldServiceType.WaitInLinePlayerTableOp); } public static WorldMsgHandler GetWorldMsgHandler() { return ServiceMgr.GetService(WorldServiceType.WorldMsgHandler); } public static EventHandlerMgr GetEventHandlerMgr() { return ServiceMgr.GetService(WorldServiceType.EventHandlerMgr); } public static long GetTimeMs() { return GetWorldServerData().m_app.Time.GetTime(); } public static long GetTimeSecond() { return GetWorldServerData().m_app.Time.GetTimeSecond(); } public static DateTime GetDateTime() { return GetWorldServerData().m_app.Time.GetDateTime(); } public static ServerApp GetApp() { return GetWorldServerData().m_app; } public static uint GetAppID() { return GetWorldServerData().m_app.ServerID; } public static int SetBit(ref int value, int bit) { value |= (1 << bit); return value; } public static bool IsBitSet(int value, int bit) { return (value & (1 << bit)) > 0; } public static int ClearBit(ref int value, int bit) { value &= (~(1 << bit)); return value; } /// /// 获取服务器配置方法 /// public static WorldServerConfig GetServerConfig() { return (WorldServerConfig)ServerConfigMgr.Instance.m_serverConfig; } public static int GetLogicWorldId(int realmId) { var serverData = GetWorldServerData(); if (serverData.m_configRealmMap.TryGetValue(realmId, out var briefInfo)) { return briefInfo.logicWorldId; } TraceLog.Error("WorldServerUtils.GetLogicWorldId fail {0}", realmId); return 0; } public static bool CheckIsSameLogicWorld(int realm1, int realm2) { if (realm1 == realm2) { return true; } int logicWorld1 = GetLogicWorldId(realm1); int logicWorld2 = GetLogicWorldId(realm2); return logicWorld1 == logicWorld2; } public static string GetRealmName(int realmId) { var configRealm = GetWorldServerData().m_configRealm; var realmBrief = configRealm.FirstOrDefault(r => r.realmId == realmId); if (realmBrief != null) { return realmBrief.realmName; } return realmId.ToString(); } } }