/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using ProtoCSStruct; namespace Game { public static class GameServerUtils { public static GameServerData GetGameServerData() { return ServerDataObjMgr.GetDataObj(GameDataObjType.GameServerData); } public static PlayerTable GetPlayerTable() { return ServerDataObjMgr.GetDataObj(GameDataObjType.PlayerTable); } public static DiamondHolderData GetDiamondHolderData() { return ServerDataObjMgr.GetDataObj(GameDataObjType.DiamondHolderData); ; } public static BattleServerVersionData GetBattleServerVersionData() { return ServerDataObjMgr.GetDataObj(GameDataObjType.battleServerVersionData); } public static RealmBriefInfo GetRealmBriefInfo(int realmID) { GetGameServerData().m_allRealm.TryGetValue(realmID, out var realmBriefInfo); return realmBriefInfo; } /// /// 获取开服天数 /// /// /// public static int GetOpenDay(int realmID, long nowTime = 0) { var realmInfo = GetRealmBriefInfo(realmID); if(realmInfo == null) { return 1; } if (nowTime <= 0) { nowTime = GetTimeSecond(); } int openDay = AppTime.GetDayElapse(nowTime, realmInfo.openTime) + 1; return openDay; } /// /// 获取开服当天的时间戳(秒) /// /// public static int GetServerOpenTimeSpan(int realmID) { var realmInfo = GetRealmBriefInfo(realmID); if (realmInfo == null) { return 1; } return realmInfo.openTime; } public static ProtoCSStructPacker GetProtoPacker() { return ProtoPackerFactory.Instance.GetProtoCSStructPacker(); } public static StructPacketSender GetPacketSender() { return GetGameServerData().m_packetSender; } public static uint GetWorldServerID() { return GetGameServerData().m_packetSender.GetWorldServerID(); } public static DirtyString GetDirtyStringData() { return GetGameServerData().m_dirtyStringData; } public static LoginHandler GetLoginHandler() { return ServiceMgr.GetService(GameServiceType.LoginHandler); } public static PlayerTableOp GetPlayerTableOp() { return ServiceMgr.GetService(GameServiceType.PlayerTableOp); } public static Dictionary GetServerInfoMap() { return GetGameServerData().m_realmIdServerInfoMap; } public static ServerApp GetApp() { return GetGameServerData().m_app; } public static uint GetAppID() { return GetGameServerData().m_app.ServerID; } public static string GetAppIDStr() { return GetGameServerData().m_app.StrServerID; } public static long GetTimeSecond() { return GetGameServerData().m_app.Time.GetTimeSecond(); } public static long GetTimeMs() { return GetGameServerData().m_app.Time.GetTime(); } public static DateTime GetDateTime() { return GetGameServerData().m_app.Time.GetDateTime(); } public static RealmServerInfo GetRealmServerInfo(int realmId) { var map = GetGameServerData().m_realmIdServerInfoMap; if (map.ContainsKey(realmId) == false) { TraceLog.Error("GameServerUtils.GetRealmServerInfo no info {0}", realmId); return null; } return map[realmId]; } public static GameRankInfo GetGameRankInfo(int realmId) { var serverInfo = GetRealmServerInfo(realmId); if(serverInfo == null) { return null; } return serverInfo.rankInfo; } public static GameReportSvc GetGameReportSvc() { return ServiceMgr.GetService(GameServiceType.GameReportSvc); } public static PlayerDataSvc GetPlayerDataSvc() { return ServiceMgr.GetService(GameServiceType.PlayerDataSvc); } public static PayHandler GetPayHandler() { return ServiceMgr.GetService(GameServiceType.PayHandler); } public static SysHandler GetSysHandler() { return ServiceMgr.GetService(GameServiceType.SysHandler); } public static FriendHandler GetFriendHandler() { return ServiceMgr.GetService(GameServiceType.FriendHandler); } public static FriendOpHandler GetFriendOpHandler() { return ServiceMgr.GetService(GameServiceType.FriendOpHandler); } public static MailHandler GetMailHandler() { return ServiceMgr.GetService(GameServiceType.MailHandler); } public static MonitorHandler GetMonitorHandler() { return ServiceMgr.GetService(GameServiceType.MonitorHandler); } public static EventHandlerMgr GetEventHandlerMgr() { return ServiceMgr.GetService(GameServiceType.EventHandlerMgr); } public static BagHandler GetBagHandler() { return ServiceMgr.GetService(GameServiceType.BagHandler); } public static DynamicMsgHandler GetDynamicMsgHandler() { return ServiceMgr.GetService(GameServiceType.DynamicMsgHandler); } public static RankHandler GetRankHandler() { return ServiceMgr.GetService(GameServiceType.RankHandler); } public static EquipmentHandler GetEquipmentHandler() { return ServiceMgr.GetService(GameServiceType.EquipmentHandler); } public static LevelHandler GetLevelHandler() { return ServiceMgr.GetService(GameServiceType.LevelHandler); } public static MarketShopHandler GetMarketShopHandler() { return ServiceMgr.GetService(GameServiceType.MarketShopHandler); } public static NameHandler GetNameHandle() { return ServiceMgr.GetService(GameServiceType.NameHandler); } public static TaskEXHandler GetTaskEXHandler() { return ServiceMgr.GetService(GameServiceType.TaskEXHandler); } public static HomeAdHandler GetHomeAdHandler() { return ServiceMgr.GetService(GameServiceType.HomeAdHandler); } public static BeginnerGuideHandler GetBeginnerGuideHandler() { return ServiceMgr.GetService(GameServiceType.BeginnerGuideHandler); } public static ChatHandler GetChatHandler() { return ServiceMgr.GetService(GameServiceType.ChatHandler); } public static ActivityHandler GetActivityHandler() { return ServiceMgr.GetService(GameServiceType.ActivityHandler); } /// /// 获取服务器配置方法 /// public static GameServerConfig GetServerConfig() { return (GameServerConfig)ServerConfigMgr.Instance.m_serverConfig; } public static void ReadAllCsvConfig() { TraceLog.Error("ReadAllCsvConfig begin"); TraceLog.Error("ReadAllCsvConfig end"); } public static int GetLogicWorldId(int realmId) { var realmInfo = GetRealmServerInfo(realmId); if (realmInfo != null) { return realmInfo.logicWorldId; } return 0; } public static int GetStarArenaBigRealm(int realmId) { var realmInfo = GetRealmServerInfo(realmId); if (realmInfo != null) { return realmInfo.bigRealmId; } return 0; } public static void GetSequenceCheckIndex(int ID,out int rIndex, out int index, out int byteIndex) { CoreHelper.GetSequenceCheckIndex(ID,out rIndex,out index,out byteIndex); } public static bool CheckInSequence(int byteIndex, int sequence) { return CoreHelper.CheckInSequence(byteIndex,sequence); } public static void SetSequence(int byteIndex, ref int sequence) { CoreHelper.SetSequence(byteIndex,ref sequence); } public static void ClearSequence(int byteIndex, ref int sequence) { CoreHelper.ClearSequence(byteIndex,ref sequence); } public static List GetConfigLogicWorldIds() { var data = GetGameServerData(); return data.m_configLogicWorldIds; } } }