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.

209 lines
5.3 KiB

1 month ago
/*
Sog
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Sog;
using Sog.Log;
using ProtoCSStruct;
namespace Version
{
// 服务器入口
public class VersionServer : IScript
{
private ServerApp m_app;
private VersionMsgHandler m_msgHandler;
public VersionServer()
{
}
public IScriptHotfixCheck GetScriptHotfixCheck()
{
return new ServerScriptHotfixCheck();
}
/// <summary>
/// reload一次调用一次
/// </summary>
/// <param name="app"></param>
private void CommInitOnCreateReload(ServerApp app)
{
m_app = app;
RegisterAllService();
}
public virtual void OnCreate(ServerApp app)
{
//打印消息统计日志
app.GetCluster().NeedLogMsgStat = true;
m_app = app;
GameConfigMgr.Instance.ReadAllConfig();
AppTime.UpdateGameResetHour(CommParamDescMgr.Instance.CrossDaysTime.int_val);
RegisterAllDataObj();
CommInitOnCreateReload(app);
TraceLog.Debug("VersionServer start at {0}", DateTime.Now);
}
public virtual void OnHotfix(ServerApp app)
{
m_app = app;
ReadServerConfig();
CommInitOnCreateReload(app);
TraceLog.Debug("VersionServer hotfix at {0}", DateTime.Now);
}
public virtual void OnReloadConfig(string excelConfigFile)
{
TraceLog.Debug("Server OnReloadConfig at {0}", DateTime.Now);
ReadServerConfig();
m_msgHandler.GetVersionSvcObj().ClearAllCache();
m_msgHandler.GetVersionSvcObj().InitVersionServerConfig();
//重新读ip白名单,黑名单
LimitIPList.Clear();
}
public virtual void OnTick(long nowMs)
{
ServerStat.Instance.Tick(nowMs);
m_msgHandler.UpdateClientConnect();
}
public virtual void OnMessage(uint remoteAppID, MessageData message)
{
m_msgHandler.HandlerMessage(remoteAppID, message);
}
public virtual void OnStop()
{
m_msgHandler.GetVersionSvcObj().WriteMd5CacheFile();
//很多服务器停服可以直接退出
m_app.SetStopSuccess();
}
//所有引用对象置空
public void Dispose()
{
TraceLog.Debug("VersionServer be disposed");
m_app = null;
m_msgHandler.Dispose();
m_msgHandler = null;
}
private void ReadServerConfig()
{
//读取配置文件
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
ServerConfigMgr.Instance.ReloadServerConfig<VersionServerConfig>(m_app,strLogicServerConfig);
var serverConfig = (VersionServerConfig)ServerConfigMgr.Instance.m_serverConfig;
foreach(var spver in serverConfig.specialVersions)
{
TraceLog.Trace("specialVerison:{0} os:{1} url:{2} review:{3}", spver.version, spver.os, spver.gateUrl, spver.review);
}
}
private void RegisterAllDataObj()
{
TraceLog.Debug("VersionServer RegisterAllDataObj");
VersionServerData serverData = new VersionServerData(m_app);
ServerDataObjMgr.Instance.RegisterDataObj(serverData);
//运营日志
BillLogWriter.Instance.Init(m_app.ServerID, VersionServerUtils.GetPacketSender());
ReadServerConfig();
}
private void RegisterAllService()
{
TraceLog.Debug("VersionServer RegisterAllService");
m_msgHandler = new VersionMsgHandler(m_app);
m_msgHandler.GetVersionSvcObj().InitVersionServerConfig();
GmCmdSvc gmCmdSvc = new GmCmdSvc();
ServiceMgr.Instance.RegisterService(gmCmdSvc);
//test_new_struct_perf();
//test_clear_struct_perf();
}
private void test_new_struct_perf()
{
Stopwatch sw = new Stopwatch();
sw.Start();
long iTotal = 0;
for(int i=0; i<100000;i++)
{
CSQueryRoleRes res = new CSQueryRoleRes();
res.FreezeTime = 1;
iTotal += res.FreezeTime;
}
sw.Stop();
TraceLog.Debug("test_new_struct_perf cost {0} ms", sw.ElapsedMilliseconds);
//Console.ReadLine();
}
private void test_clear_struct_perf()
{
Stopwatch sw = new Stopwatch();
sw.Start();
long iTotal = 0;
//CSQueryRoleRes[] resArray = new CSQueryRoleRes[2];
for (int i = 0; i < 100000; i++)
{
ref CSQueryRoleRes res = ref CSStructPool<CSQueryRoleRes>.Instance.GetObjRef();
res.Clear();
res.FreezeTime = 1;
iTotal += res.FreezeTime;
}
sw.Stop();
TraceLog.Debug("test_clear_struct_perf cost {0} ms", sw.ElapsedMilliseconds);
}
}
}