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.
202 lines
5.7 KiB
202 lines
5.7 KiB
1 month ago
|
using Battle;
|
||
|
using Sog;
|
||
|
using Sog.Log;
|
||
|
|
||
|
namespace FrameSync;
|
||
|
|
||
|
public class FrameServer: IScript
|
||
|
{
|
||
|
private ServerApp m_app;
|
||
|
private FrameSyncMsgHandler m_messageHandler;
|
||
|
|
||
|
public FrameServer()
|
||
|
{
|
||
|
}
|
||
|
public IScriptHotfixCheck GetScriptHotfixCheck()
|
||
|
{
|
||
|
return new ServerScriptHotfixCheck();
|
||
|
}
|
||
|
private void CommInitOnCreateReload(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
RegisterAllService();
|
||
|
|
||
|
//BattleBuffEffect.Init();
|
||
|
// BattleServerUtils.GetEventHandlerMgr().RegisterAllEventHandler();
|
||
|
}
|
||
|
|
||
|
public virtual void OnCreate(ServerApp app)
|
||
|
{
|
||
|
//打印消息统计日志
|
||
|
app.GetCluster().NeedLogMsgStat = true;
|
||
|
|
||
|
m_app = app;
|
||
|
MatchSystem.Init(app);
|
||
|
|
||
|
|
||
|
RegisterAllDataObj();
|
||
|
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("BattleServer start at {0}", DateTime.Now);
|
||
|
}
|
||
|
|
||
|
public virtual void OnHotfix(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
ReadServerConfig();
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("BattleServer hotfix at {0}", DateTime.Now);
|
||
|
}
|
||
|
|
||
|
public virtual void OnReloadConfig(string excelConfigFile)
|
||
|
{
|
||
|
TraceLog.Debug("Server OnReloadConfig at {0}", DateTime.Now);
|
||
|
|
||
|
ReadServerConfig();
|
||
|
|
||
|
//BattleControl.OnReloadConfig();
|
||
|
}
|
||
|
|
||
|
|
||
|
public virtual void OnTick(long nowMs)
|
||
|
{
|
||
|
// BattleServerStat.Tick(nowMs);
|
||
|
//
|
||
|
MatchSystem.Tick(nowMs, m_app);
|
||
|
|
||
|
if(m_app.CurrStopStage == ServerStopStage.stopping)
|
||
|
{
|
||
|
m_app.SetStopSuccess();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public virtual void OnMessage(uint remoteAppID, MessageData message)
|
||
|
{
|
||
|
m_messageHandler.HandlerMessage(remoteAppID, message);
|
||
|
}
|
||
|
|
||
|
public virtual void OnStop()
|
||
|
{
|
||
|
// 强制踢人停服
|
||
|
// BattleServerUtils.GetBattleServerData().forceLeaveOnSvrStop = 1;
|
||
|
}
|
||
|
|
||
|
//所有引用对象置空
|
||
|
public void Dispose()
|
||
|
{
|
||
|
TraceLog.Debug("BattleServer be disposed");
|
||
|
|
||
|
m_app = null;
|
||
|
m_messageHandler = null;
|
||
|
}
|
||
|
|
||
|
private void RegisterAllDataObj()
|
||
|
{
|
||
|
TraceLog.Debug("BattleServer RegisterAllDataObj");
|
||
|
|
||
|
//战斗服务器起服就需要设置configFilePath
|
||
|
if (m_app.AppParam.ServerConfig.configDataPath != null && m_app.AppParam.ServerConfig.configDataPath != "")
|
||
|
{
|
||
|
GameConfigMgr.Instance.SetFilePath(m_app.AppParam.ServerConfig.configDataPath);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GameConfigMgr.Instance.SetFilePath("../cfg/data/");
|
||
|
}
|
||
|
|
||
|
//读取游戏数据文件
|
||
|
GameConfigMgr.Instance.ReadAllConfig();
|
||
|
AppTime.UpdateGameResetHour(CommParamDescMgr.Instance.CrossDaysTime.int_val);
|
||
|
|
||
|
BattleServerData serverData = new BattleServerData(m_app);
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(serverData);
|
||
|
|
||
|
PlayerTable playerTable = new PlayerTable();
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(playerTable);
|
||
|
|
||
|
BattleTable battleTable = new BattleTable();
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(battleTable);
|
||
|
|
||
|
BillLogWriter.Instance.Init(m_app.ServerID, serverData.m_packetSender);
|
||
|
|
||
|
ReadServerConfig();
|
||
|
|
||
|
//检查战斗有哪些没有加载的
|
||
|
// BattleServerUtils.CheckNeedRegisterFile();
|
||
|
}
|
||
|
|
||
|
private void ReadServerConfig()
|
||
|
{
|
||
|
//读取配置文件
|
||
|
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
|
||
|
FrameServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig<FrameServerConfig>(m_app,strLogicServerConfig);
|
||
|
|
||
|
//战斗日志初始化
|
||
|
TraceLog.InitBattleLog(serverConfig.battleLog.logpath
|
||
|
, serverConfig.battleLog.logname
|
||
|
, LogLevel.ParseFromString(serverConfig.battleLog.loglevel)
|
||
|
, serverConfig.battleLog.userlogAll
|
||
|
, serverConfig.battleLog.userlogSome
|
||
|
, serverConfig.battleLog.logByBattleId);
|
||
|
|
||
|
//设置战斗版本号
|
||
|
// BattleServerUtils.SetBattleVersion();
|
||
|
// TraceLog.Debug("BattleServer.ReadServerConfig onlyCheckResult {0}", serverConfig.onlyCheckResult);
|
||
|
}
|
||
|
|
||
|
private void RegisterAllService()
|
||
|
{
|
||
|
TraceLog.Debug("BattleServer RegisterAllService");
|
||
|
|
||
|
m_messageHandler = new FrameSyncMsgHandler(m_app);
|
||
|
ServiceMgr.Instance.RegisterService(m_messageHandler);
|
||
|
|
||
|
// PlayerTableOp playerTableOp = new PlayerTableOp(BattleServerUtils.GetPlayerTable());
|
||
|
// ServiceMgr.Instance.RegisterService(playerTableOp);
|
||
|
|
||
|
// GmCmdSvc gmCmdSvc = new GmCmdSvc();
|
||
|
// ServiceMgr.Instance.RegisterService(gmCmdSvc);
|
||
|
|
||
|
//BattleTableOp battleTableOp = new BattleTableOp(BattleServerUtils.GetBattleTable());
|
||
|
//ServiceMgr.Instance.RegisterService(battleTableOp);
|
||
|
|
||
|
// EventHandlerMgr eventHandlerMgr = new EventHandlerMgr();
|
||
|
// ServiceMgr.Instance.RegisterService(eventHandlerMgr);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
private int ReadConfig(string filename, IConfigManager configMgr)
|
||
|
{
|
||
|
string fullPath = FrameServerUtils.GetConfigDataPath() + filename;
|
||
|
|
||
|
if (!File.Exists(fullPath))
|
||
|
{
|
||
|
TraceLog.Error("BattleServer.ReadConfig desc file {0} not exists", filename);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
string content = File.ReadAllText(fullPath);
|
||
|
|
||
|
bool ret = configMgr.Init(filename, content);
|
||
|
if (ret == false)
|
||
|
{
|
||
|
TraceLog.Error("BattleServer.ReadConfig desc file {0} read failed", filename);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
configMgr.ReadComplete();
|
||
|
|
||
|
if (configMgr.GetErrorCount() > 0)
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
TraceLog.Debug("BattleServer.ReadConfig desc file {0} read success", filename);
|
||
|
return 0;
|
||
|
}
|
||
|
}
|