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.
170 lines
5.5 KiB
170 lines
5.5 KiB
1 month ago
|
/*
|
||
|
Sog 游戏基础库
|
||
|
2016 by zouwei
|
||
|
*/
|
||
|
|
||
|
using System;
|
||
|
|
||
|
using ProtoCSStruct;
|
||
|
using Sog;
|
||
|
using Sog.Log;
|
||
|
using Sog.Service;
|
||
|
|
||
|
namespace PlayerOp
|
||
|
{
|
||
|
// 服务器入口
|
||
|
public class PlayerOpServer : IScript
|
||
|
{
|
||
|
private Guid m_guid = Guid.NewGuid();
|
||
|
private ServerApp m_app;
|
||
|
private PlayerOpMsgHandler m_messageHandler;
|
||
|
private long m_stopServerTime;
|
||
|
|
||
|
private void CommInitOnCreateReload(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
if (GameConfigMgr.Instance.m_isBin)
|
||
|
{
|
||
|
GameConfigMgr.Instance.ReadAllConfig();
|
||
|
AppTime.UpdateGameResetHour(CommParamDescMgr.Instance.CrossDaysTime.int_val);
|
||
|
}
|
||
|
|
||
|
DBServerSelect.Init(app);
|
||
|
|
||
|
RegisterAllService();
|
||
|
}
|
||
|
public IScriptHotfixCheck GetScriptHotfixCheck()
|
||
|
{
|
||
|
return new ServerScriptHotfixCheck();
|
||
|
}
|
||
|
public virtual void OnCreate(ServerApp app)
|
||
|
{
|
||
|
//打印消息统计日志
|
||
|
app.GetCluster().NeedLogMsgStat = true;
|
||
|
|
||
|
m_app = app;
|
||
|
|
||
|
RegisterAllDataObj();
|
||
|
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("PlayerOpServer start at {0}, guid {1}", DateTime.Now, m_guid);
|
||
|
|
||
|
TraceLog.Debug("PlayerOpServer timezone {0}, nowsec {1}", AppTime.TimeZone, PlayerOpServerUtils.GetTimeSecond());
|
||
|
}
|
||
|
|
||
|
public virtual void OnHotfix(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
ReadServerConfig();
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("PlayerOpServer hotfix at {0}, guid {1}", DateTime.Now, m_guid);
|
||
|
}
|
||
|
|
||
|
public virtual void OnReloadConfig(string excelConfigFile)
|
||
|
{
|
||
|
TraceLog.Debug("PlayerOpServer Server OnReloadConfig at {0}", DateTime.Now);
|
||
|
|
||
|
ReadServerConfig();
|
||
|
}
|
||
|
|
||
|
public virtual void OnTick(long nowMs)
|
||
|
{
|
||
|
ServerStat.Instance.Tick(nowMs);
|
||
|
|
||
|
PlayerOpServerUtils.GetExchangeSvc().OnTick(nowMs / 1000, nowMs);
|
||
|
if ((m_stopServerTime > 0)
|
||
|
&& (nowMs / 1000 - m_stopServerTime > 5)
|
||
|
&& PlayerOpServerUtils.GetExchangeSvc().IsAllDataSave()
|
||
|
&& PlayerOpServerUtils.GetExchangeSvc().IsAllReqHandle())
|
||
|
{
|
||
|
// 进程可以退出
|
||
|
TraceLog.Debug("PlayerOpServer tick stop!!!");
|
||
|
m_app.SetStopSuccess();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public virtual void OnMessage(uint remoteAppID, MessageData message)
|
||
|
{
|
||
|
m_messageHandler.HandlerMessage(remoteAppID, message);
|
||
|
}
|
||
|
|
||
|
public virtual void OnStop()
|
||
|
{
|
||
|
//很多服务器停服可以直接退出
|
||
|
m_stopServerTime = PlayerOpServerUtils.GetTimeSecond();
|
||
|
TraceLog.Debug("PlayerOpServer set stop time");
|
||
|
|
||
|
//关闭所有消息处理任务
|
||
|
MessageTaskDistributor.Instance.CloseAllTask();
|
||
|
}
|
||
|
|
||
|
//所有引用对象置空
|
||
|
public void Dispose()
|
||
|
{
|
||
|
TraceLog.Debug("PlayerOpServer be disposed");
|
||
|
|
||
|
m_app = null;
|
||
|
m_messageHandler = null;
|
||
|
MessageTaskHandler.DisposeAllHandler();
|
||
|
}
|
||
|
|
||
|
private void ReadServerConfig()
|
||
|
{
|
||
|
// 旧的数据库配置
|
||
|
var oldServerConfig = ServerConfigMgr.Instance.m_serverConfig;
|
||
|
//读取配置文件
|
||
|
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
|
||
|
ServerConfigMgr.Instance.ReloadServerConfig<PlayerOpServerConfig>(m_app, strLogicServerConfig);
|
||
|
|
||
|
var serverConfig = ServerConfigMgr.Instance.ReloadServerConfig<PlayerOpServerConfig>(m_app, strLogicServerConfig);
|
||
|
|
||
|
if (serverConfig != null && oldServerConfig != null && oldServerConfig is PlayerOpServerConfig)
|
||
|
{
|
||
|
if (string.Compare(((PlayerOpServerConfig)oldServerConfig).dbip, serverConfig.dbip) != 0)
|
||
|
{
|
||
|
TraceLog.Debug("PlayerOpServer.ReadServerConfig Trans MYSQLDB {0} to {1}", ((PlayerOpServerConfig)oldServerConfig).dbip, serverConfig.dbip);
|
||
|
//数据库切换
|
||
|
MessageTaskHandler.AfterReloadServerConfigChangeDB(m_app);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void RegisterAllDataObj()
|
||
|
{
|
||
|
ReadServerConfig();
|
||
|
|
||
|
PlayerOpServerData serverData = new PlayerOpServerData(m_app);
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(serverData);
|
||
|
|
||
|
GameConfigMgr.Instance.ReadAllConfig();
|
||
|
AppTime.UpdateGameResetHour(CommParamDescMgr.Instance.CrossDaysTime.int_val);
|
||
|
|
||
|
ExchangeCodeCache exchangeCodeCache = new ExchangeCodeCache(PlayerOpConfigDef.MaxExchangeCodeCount);
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(exchangeCodeCache);
|
||
|
}
|
||
|
|
||
|
private void RegisterAllService()
|
||
|
{
|
||
|
TraceLog.Debug("PlayerOpServer RegisterAllService");
|
||
|
|
||
|
MessageTaskHandler.InitAllTaskHandler(m_app);
|
||
|
|
||
|
m_messageHandler = new PlayerOpMsgHandler(m_app);
|
||
|
ServiceMgr.Instance.RegisterService(m_messageHandler);
|
||
|
|
||
|
GmCmdSvc gmcmd = new GmCmdSvc();
|
||
|
ServiceMgr.Instance.RegisterService(gmcmd);
|
||
|
|
||
|
ExchangeSvc ExchangeSvc = new ExchangeSvc();
|
||
|
ServiceMgr.Instance.RegisterService(ExchangeSvc);
|
||
|
|
||
|
ExchangeOp ExchangeOp = new ExchangeOp();
|
||
|
ServiceMgr.Instance.RegisterService(ExchangeOp);
|
||
|
}
|
||
|
}
|
||
|
}
|