using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; namespace Chat { public static class ChatServerUtils { //ChatData public static ChatServerData GetChatServerData() { return ServerDataObjMgr.GetDataObj(ChatDataObjType.ChatServerData); } public static ProtoCSStructPacker GetProtoPacker() { return ProtoPackerFactory.Instance.GetProtoCSStructPacker(); } public static StructPacketSender GetPacketSender() { return GetChatServerData().m_packetSender; } public static DirtyString GetDirtyStringData() { return GetChatServerData().m_dirtyStringData; } public static PlayerTable GetPlayerTable() { return ServerDataObjMgr.GetDataObj(ChatDataObjType.PlayerTable); } //ChatService public static PlayerTableOp GetPlayerTableOp() { return ServiceMgr.GetService(ChatServiceType.PlayerTableOp); } //public static SysNoticeSvc GetSysNoticeSvc() //{ // return ServiceMgr.GetService(ChatServiceType.SysNotice); //} public static long GetTimeSecond() { return GetChatServerData().m_app.Time.GetTimeSecond(); } // 时间戳转为C#格式时间 public static DateTime StampToDateTime(long timeStamp) { DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); return dateTimeStart.Add(toNow); } // DateTime时间格式转换为Unix时间戳格式 public static int GetTimeStamp(System.DateTime time) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds; } public static uint GetAppID() { return GetChatServerData().m_app.ServerID; } public static ServerApp GetApp() { return GetChatServerData().m_app; } /// /// 获取服务器配置方法 /// public static ChatServerConfig GetServerConfig() { return (ChatServerConfig)ServerConfigMgr.Instance.m_serverConfig; } public static void OnTick(long nowMs) { long nowSec = (int)(nowMs / 1000); ChatCacheOp.ChatCacheTick(nowSec); } public static int GetLogicWorldId(int realmId) { var serverData = GetChatServerData(); if (serverData.m_allRealmMap.TryGetValue(realmId, out var briefInfo)) { return briefInfo.logicWorldId; } TraceLog.Error("ChatServerUtils.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; } } }