/* Sog 游戏基础库 2016 by zouwei */ using System; using Sog; using Sog.Log; namespace Realmlist { // 帐号服务器入口 public class RealmlistServer : IScript { private Guid m_guid; private ServerApp m_app; private RootMessageHandler m_rootMessageHandler; public RealmlistServer() { m_guid = Guid.NewGuid(); } private void CommInitOnCreateReload(ServerApp app) { m_app = app; RegisterAllService(); } public IScriptHotfixCheck GetScriptHotfixCheck() { return new ServerScriptHotfixCheck(); } public virtual void OnCreate(ServerApp app) { //打印消息统计日志 app.GetCluster().NeedLogMsgStat = true; m_app = app; //不需要全部文件 if (GameConfigMgr.Instance.m_isBin) { //GameConfigMgr.Instance.ReadOneConfig("ServerInfoDesc.bin"); } else { //GameConfigMgr.Instance.ReadOneConfig("ServerInfoDesc.txt"); } RegisterAllDataObj(); CommInitOnCreateReload(app); TraceLog.Debug("RealmlistServer start at {0}, guid {1} timeSecond {2}", DateTime.Now, m_guid, app.GetTimeSecond()); } public virtual void OnHotfix(ServerApp app) { m_app = app; ReadServerConfig(); CommInitOnCreateReload(app); TraceLog.Debug("RealmlistServer hotfix at {0}, guid {1}", DateTime.Now, m_guid); } public virtual void OnReloadConfig(string excelConfigFile) { TraceLog.Debug("Server OnReloadConfig at {0}", DateTime.Now); LimitIPList.Clear(); ReadServerConfig(); RealmlistDBSvc.UpdateRelamConfigFromDB(); } public virtual void OnTick(long nowMs) { long nowSec = m_app.GetTimeSecond(); TickThirtySecond(nowMs, nowSec); ServerStat.Instance.Tick(nowMs); TickOneSecond(nowMs, nowSec); Tick5Second(nowMs, nowSec); } private void TickOneSecond(long nowMs, long nowSec) { if (nowMs < RealmlistServerUtils.GetRealmlistServerData().m_oneSecondMs + 1000) { return; } RealmlistServerUtils.GetRealmlistServerData().m_oneSecondMs = nowMs; //RealmlistDBSvc.TickOneSec(nowSec); } private void Tick5Second(long nowMs, long nowSec) { if (nowMs < RealmlistServerUtils.GetRealmlistServerData().m_5SecondMs + 5000) { return; } RealmlistServerUtils.GetRealmlistServerData().m_5SecondMs = nowMs; RealmlistDBSvc.Tick5Second(nowSec); } public virtual void OnMessage(uint remoteAppID, MessageData message) { m_rootMessageHandler.HandlerMessage(remoteAppID, message); } public virtual void OnStop() { //很多服务器停服可以直接退出 m_app.SetStopSuccess(); } public static void TestConfigTimeWithTimeZone() { string beiJinTime = "2022-05-21 05:00:00"; int targetZone = 0; long time1 = ConfigStringTimeParse.ParseConfigTimeWithTimeZone(beiJinTime, 8, targetZone); TraceLog.Debug("TestConfigTimeWithTimeZone beiJinTime {0} targetZone {1} time {2} string {3}", beiJinTime, targetZone, time1, AppTime.ConvertUnixTimeToDateTime(1000L * time1)); beiJinTime = "2022-05-21 05:00:00"; targetZone = -4; time1 = ConfigStringTimeParse.ParseConfigTimeWithTimeZone(beiJinTime, 8, targetZone); TraceLog.Debug("TestConfigTimeWithTimeZone beiJinTime {0} targetZone {1} time {2} string {3}", beiJinTime, targetZone, time1, AppTime.ConvertUnixTimeToDateTime(1000L * time1)); beiJinTime = "2022-05-21 05:00:00"; targetZone = -6; time1 = ConfigStringTimeParse.ParseConfigTimeWithTimeZone(beiJinTime, 8, targetZone); TraceLog.Debug("TestConfigTimeWithTimeZone beiJinTime {0} targetZone {1} time {2} string {3}", beiJinTime, targetZone, time1, AppTime.ConvertUnixTimeToDateTime(1000L * time1)); beiJinTime = "2022-05-21 05:00:00"; targetZone = 10; time1 = ConfigStringTimeParse.ParseConfigTimeWithTimeZone(beiJinTime, 8, targetZone); TraceLog.Debug("TestConfigTimeWithTimeZone beiJinTime {0} targetZone {1} time {2} string {3}", beiJinTime, targetZone, time1, AppTime.ConvertUnixTimeToDateTime(1000L * time1)); } private void ReadServerConfig(bool notSave = false) { //读取部分表格配置文件 GameConfigMgr.Instance.ReadOneConfig("CountryAreaNameMapDesc.bin"); TestConfigTimeWithTimeZone(); TraceLog.Debug("RealmlistServer.ReadServerConfig timezone {0}", AppTime.TimeZone); //读取配置文件 string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile; RealmlistServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig(m_app, strLogicServerConfig); //读取游戏服务器开服列表 var serverData = RealmlistServerUtils.GetRealmlistServerData(); string strRealmListFile = m_app.GetCluster().GetAppConfigPath() + "/" + serverConfig.realmListFile; RealmlistSvc.ReadRealmListConfig(m_app, strRealmListFile, notSave); RecommendRealmByIP.OnReloadConfig(); } private long m_thirtySecondMs = 0; private void TickThirtySecond(long nowMs, long nowSec) { if (nowMs < m_thirtySecondMs + 30000) { return; } m_thirtySecondMs = nowMs; RealmlistSvc.UpdateRealmStatus(nowSec); } //所有引用对象置空 public void Dispose() { TraceLog.Debug("RealmlistServer be disposed"); m_app = null; m_rootMessageHandler = null; } private void RegisterAllDataObj() { TraceLog.Debug("RealmlistServer RegisterAllDataObj"); RealmlistServerData realmServerData = new RealmlistServerData(m_app); ServerDataObjMgr.Instance.RegisterDataObj(realmServerData); ReadServerConfig(true); } private void RegisterAllService() { TraceLog.Debug("RealmlistServer RegisterAllService"); m_rootMessageHandler = new RootMessageHandler(m_app); ServiceMgr.Instance.RegisterService(m_rootMessageHandler); GmCmdSvc gmCmdSvc = new GmCmdSvc(); ServiceMgr.Instance.RegisterService(gmCmdSvc); } } }