You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
3.9 KiB
142 lines
3.9 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using Sog;
|
|
using Sog.Log;
|
|
using Sog.Service;
|
|
|
|
namespace BillLog
|
|
{
|
|
// 服务器入口
|
|
public class BillLogServer : IScript
|
|
{
|
|
private Guid m_guid;
|
|
private ServerApp m_app;
|
|
private BillLogMsgHandler m_messageHandler;
|
|
|
|
public BillLogServer()
|
|
{
|
|
m_guid = Guid.NewGuid();
|
|
}
|
|
public IScriptHotfixCheck GetScriptHotfixCheck()
|
|
{
|
|
return new ServerScriptHotfixCheck();
|
|
}
|
|
private void CommInitOnCreateReload(ServerApp app)
|
|
{
|
|
m_app = app;
|
|
|
|
RegisterAllService();
|
|
}
|
|
|
|
public virtual void OnCreate(ServerApp app)
|
|
{
|
|
//打印消息统计日志
|
|
app.GetCluster().NeedLogMsgStat = true;
|
|
|
|
m_app = app;
|
|
//创建时初始化(要放在配置表格加载前)
|
|
LogTransferHandler.InitLogTransferHandler();
|
|
|
|
RegisterAllDataObj();
|
|
|
|
CommInitOnCreateReload(app);
|
|
|
|
TraceLog.Debug("BillLogServer start at {0}, guid {1}", DateTime.Now, m_guid);
|
|
}
|
|
|
|
public virtual void OnHotfix(ServerApp app)
|
|
{
|
|
m_app = app;
|
|
|
|
ReadServerConfig();
|
|
CommInitOnCreateReload(app);
|
|
|
|
TraceLog.Debug("BillLogServer 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);
|
|
//tick 检查日志迁移
|
|
LogTransferHandler.TickDaily(nowMs);
|
|
}
|
|
|
|
public virtual void OnMessage(uint remoteAppID, MessageData message)
|
|
{
|
|
m_messageHandler.HandlerMessage(remoteAppID, message);
|
|
}
|
|
|
|
public virtual void OnStop()
|
|
{
|
|
LogTransferHandler.OnStop();
|
|
//很多服务器停服可以直接退出
|
|
m_app.SetStopSuccess();
|
|
}
|
|
|
|
//所有引用对象置空
|
|
public void Dispose()
|
|
{
|
|
TraceLog.Debug("BillLogServer be disposed");
|
|
|
|
m_app = null;
|
|
m_messageHandler = null;
|
|
|
|
MessageTaskHandler.DisposeAllHandler();
|
|
|
|
LogTransferHandler.OnDispose();
|
|
}
|
|
|
|
private void RegisterAllDataObj()
|
|
{
|
|
BillLogServerData serverData = new BillLogServerData(m_app);
|
|
ServerDataObjMgr.Instance.RegisterDataObj(serverData);
|
|
|
|
ReadServerConfig();
|
|
}
|
|
|
|
private void RegisterAllService()
|
|
{
|
|
TraceLog.Debug("BillLogServer.RegisterAllService");
|
|
|
|
m_messageHandler = new BillLogMsgHandler(m_app);
|
|
ServiceMgr.Instance.RegisterService(m_messageHandler);
|
|
|
|
GmCmdSvc gmCmdSvc = new GmCmdSvc();
|
|
ServiceMgr.Instance.RegisterService(gmCmdSvc);
|
|
|
|
MessageTaskHandler.InitAllTaskHandler();
|
|
}
|
|
|
|
private void ReadServerConfig()
|
|
{
|
|
//读取配置文件
|
|
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
|
|
ServerConfigMgr.Instance.ReloadServerConfig<BillLogServerConfig>(m_app, strLogicServerConfig);
|
|
var cfgFile = BillLogServerUtils.GetServerConfig().configFile;
|
|
if (!string.IsNullOrEmpty(cfgFile))
|
|
{
|
|
cfgFile = m_app.GetCluster().GetAppConfigPath() + "/" + cfgFile;
|
|
TraceLog.Trace("this is config file path :{0}", cfgFile);
|
|
ServerConfigMgr.Instance.ReloadServerConfig<BillLogServerConfig>(m_app, cfgFile);
|
|
}
|
|
LogTransferHandler.InitLogPath();
|
|
}
|
|
}
|
|
}
|
|
|