/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using Sog.Service; using Sog.Log; using Rank; using Game; namespace Name { // 服务器入口 public class NameServer : IScript { private Guid m_guid; private ServerApp m_app; private NameMsgHandler m_messageHandler; public NameServer() { m_guid = Guid.NewGuid(); } private void CommInitOnCreateReload(ServerApp app) { m_app = app; RegisterAllService(); } public virtual void OnCreate(ServerApp app) { //打印消息统计日志 app.GetCluster().NeedLogMsgStat = true; //多线程特殊需求 app.GetCluster().EnableMultiThreadSendSafe(); m_app = app; RegisterAllDataObj(); CommInitOnCreateReload(app); TraceLog.Debug("DBServer start at {0}, guid {1}", DateTime.Now, m_guid); } public virtual void OnHotfix(ServerApp app) { m_app = app; ReadServerConfig(); CommInitOnCreateReload(app); TraceLog.Debug("DBServer hotfix at {0}, guid {1}", DateTime.Now, m_guid); } public virtual void OnReloadConfig(string excelConfigFile) { TraceLog.Debug("Server OnReloadConfig at {0}", DateTime.Now); ReadServerConfig(); } public virtual void OnTick(long nowMs) { ServerStat.Instance.Tick(nowMs); } public virtual void OnMessage(uint remoteAppID, MessageData message) { m_messageHandler.HandlerMessage(remoteAppID, message); } public virtual void OnStop() { //很多服务器停服可以直接退出 m_app.SetStopSuccess(); //关闭所有消息处理任务 MessageTaskDistributor.Instance.CloseAllTask(); } //所有引用对象置空 public void Dispose() { TraceLog.Debug("DBServer be disposed"); m_app = null; m_messageHandler = null; MessageTaskHandler.DisposeAllHandler(); } private void ReadServerConfig() { //读取配置文件 string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile; NameServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig(m_app,strLogicServerConfig); } private void RegisterAllDataObj() { TraceLog.Debug("DBServer RegisterAllDataObj"); NameServerData serverData = new NameServerData(m_app); ServerDataObjMgr.Instance.RegisterDataObj(serverData); ReadServerConfig(); } private void RegisterAllService() { TraceLog.Debug("DBServer RegisterAllService"); MessageTaskHandler.InitAllTaskHandler(); m_messageHandler = new NameMsgHandler(); ServiceMgr.Instance.RegisterService(m_messageHandler); } public IScriptHotfixCheck GetScriptHotfixCheck() { return new ServerScriptHotfixCheck(); } } }