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.
189 lines
4.9 KiB
189 lines
4.9 KiB
1 month ago
|
/*
|
||
|
Sog 游戏基础库
|
||
|
2016 by zouwei
|
||
|
*/
|
||
|
|
||
|
using System;
|
||
|
using Sog;
|
||
|
using Sog.Service;
|
||
|
using Sog.Log;
|
||
|
|
||
|
namespace GameDB
|
||
|
{
|
||
|
// 服务器入口
|
||
|
public class GameDBServer : IScript
|
||
|
{
|
||
|
private Guid m_guid;
|
||
|
private ServerApp m_app;
|
||
|
private GameDBMsgHandler m_messageHandler;
|
||
|
|
||
|
public GameDBServer()
|
||
|
{
|
||
|
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;
|
||
|
//多线程特殊需求
|
||
|
app.GetCluster().EnableMultiThreadSendSafe();
|
||
|
|
||
|
m_app = app;
|
||
|
|
||
|
RegisterAllDataObj();
|
||
|
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("GameDBServer start at {0}, guid {1}", DateTime.Now, m_guid);
|
||
|
}
|
||
|
|
||
|
public virtual void OnHotfix(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
ReadServerConfig();
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("GameDBServer 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("GameDBServer be disposed");
|
||
|
|
||
|
m_app = null;
|
||
|
m_messageHandler = null;
|
||
|
|
||
|
MessageTaskHandler.DisposeAllHandler();
|
||
|
|
||
|
}
|
||
|
|
||
|
private void ReadServerConfig()
|
||
|
{
|
||
|
//读取配置文件
|
||
|
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
|
||
|
var oldServerConfig = ServerConfigMgr.Instance.m_serverConfig;
|
||
|
GameDBServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig<GameDBServerConfig>(m_app,strLogicServerConfig);
|
||
|
if (serverConfig != null && oldServerConfig != null && oldServerConfig is GameDBServerConfig)
|
||
|
{
|
||
|
//数据库切换
|
||
|
if (string.Compare(((GameDBServerConfig) oldServerConfig).dbip, serverConfig.dbip) != 0)
|
||
|
{
|
||
|
TraceLog.Debug("ReadServerConfig Trans MySql {0} to {1}",
|
||
|
((GameDBServerConfig) oldServerConfig).dbip, serverConfig.dbip);
|
||
|
|
||
|
MessageTaskHandler.AfterReloadServerConfigChangeDB(m_app);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void RegisterAllDataObj()
|
||
|
{
|
||
|
TraceLog.Debug("GameDBServer RegisterAllDataObj");
|
||
|
|
||
|
GameDBServerData dbServerData = new GameDBServerData(m_app);
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(dbServerData);
|
||
|
|
||
|
ReadServerConfig();
|
||
|
|
||
|
//读取游戏数据文件
|
||
|
GameConfigMgr.Instance.ReadAllConfig();
|
||
|
AppTime.UpdateGameResetHour(CommParamDescMgr.Instance.CrossDaysTime.int_val);
|
||
|
}
|
||
|
|
||
|
private void RegisterAllService()
|
||
|
{
|
||
|
TraceLog.Debug("GameDBServer RegisterAllService");
|
||
|
|
||
|
MessageTaskHandler.InitAllTaskHandler(m_app);
|
||
|
|
||
|
m_messageHandler = new GameDBMsgHandler();
|
||
|
ServiceMgr.Instance.RegisterService(m_messageHandler);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
private ServerApp m_app;
|
||
|
private AppParam m_appParam;
|
||
|
|
||
|
public DBServer(AppParam appParam)
|
||
|
{
|
||
|
m_appParam = appParam;
|
||
|
|
||
|
TraceLog.SetLogPathName(m_appParam.ServerConfig.logpath, m_appParam.ServerConfig.logname);
|
||
|
|
||
|
m_app = new ServerApp(appParam.AppID);
|
||
|
}
|
||
|
|
||
|
public void Init()
|
||
|
{
|
||
|
// config
|
||
|
|
||
|
ServiceMgrDB.Init(m_app);
|
||
|
|
||
|
m_app.GetCluster().ReadConfigFromFile(m_appParam.ServerConfig.clusterfile);
|
||
|
|
||
|
m_app.OnClusterMessage += ServiceMgrDB.MsgHandler.HandlerMessage;
|
||
|
|
||
|
m_app.OnTick += OnTick;
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
private void OnTick(long nowMs)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public void Start()
|
||
|
{
|
||
|
Init();
|
||
|
|
||
|
Console.WriteLine("DBServer start at {0}", DateTime.Now);
|
||
|
|
||
|
m_app.Run();
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
}
|