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.
 
 
 
 
 
 

151 lines
4.1 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.Threading;
using Sog;
using SimpleHttpServer;
using Sog.Service;
using Sog.Log;
namespace HttpProxyWorld
{
// 服务器入口
public class HttpProxyWorldServer : IScript
{
private Guid m_guid;
private ServerApp m_app;
private HttpProxyMsgHandler m_messageHandler;
public HttpProxyWorldServer()
{
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("HttpProxyWorldServer start at {0}, guid {1}", DateTime.Now, m_guid);
}
public virtual void OnHotfix(ServerApp app)
{
m_app = app;
ReadServerConfig();
CommInitOnCreateReload(app);
TraceLog.Debug("HttpProxyWorldServer 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("HttpProxyWorldServer be disposed");
m_app = null;
m_messageHandler = null;
//关闭所有消息处理任务
MessageTaskDistributor.Instance.CloseAllTask();
}
private void ReadServerConfig()
{
//读取配置文件
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
HttpProxyWorldServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig<HttpProxyWorldServerConfig>(m_app,strLogicServerConfig);
}
private void RegisterAllDataObj()
{
HttpProxyWorldServerData serverData = new HttpProxyWorldServerData(m_app);
ServerDataObjMgr.Instance.RegisterDataObj(serverData);
ReadServerConfig();
}
private void RegisterAllService()
{
TraceLog.Debug("HttpProxyServer RegisterAllService");
InitMessageTask();
m_messageHandler = new HttpProxyMsgHandler(m_app);
ServiceMgr.Instance.RegisterService(m_messageHandler);
GmCmdSvc gmCmdSvc = new GmCmdSvc();
ServiceMgr.Instance.RegisterService(gmCmdSvc);
}
/// <summary>
/// 初始化消息处理任务
/// </summary>
private void InitMessageTask()
{
//分配消息任务,写死10个正常的,1个推送的
uint iTotalTaskCount = HttpProxyWorldServerUtils.PayTaskCount + HttpProxyWorldServerUtils.PushTaskCount;
TraceLog.Debug("HttpProxyWorldServer.InitMessageTask messageTaskCount is {0}", iTotalTaskCount);
MessageTaskDistributor.Instance.InitTask(iTotalTaskCount);
MessageTaskDistributor.Instance.StartAllTask(MessageTaskHandler.HandlerPacket);
}
}
}