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.
207 lines
6.2 KiB
207 lines
6.2 KiB
1 month ago
|
/*
|
||
|
Sog 游戏基础库
|
||
|
2016 by zouwei
|
||
|
*/
|
||
|
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using ProtoCSStruct;
|
||
|
using Sog;
|
||
|
using Sog.Log;
|
||
|
using Sog.Service;
|
||
|
|
||
|
namespace Chat
|
||
|
{
|
||
|
// Chat 服务器入口
|
||
|
public class ChatServer : IScript
|
||
|
{
|
||
|
private const string m_dirtyListFile = "../cfg/sog/dirty.txt";
|
||
|
private Guid m_guid;
|
||
|
private ServerApp m_app;
|
||
|
private RootMessageHandler m_rootMessageHandler;
|
||
|
private ChatServerConfig m_chatServerConfig;
|
||
|
private long m_lastReportTime = 0;
|
||
|
//上报时间间隔
|
||
|
private const int m_ReportTimeInterVal = 30000;
|
||
|
|
||
|
public ChatServer()
|
||
|
{
|
||
|
m_guid = Guid.NewGuid();
|
||
|
}
|
||
|
public IScriptHotfixCheck GetScriptHotfixCheck()
|
||
|
{
|
||
|
return new ServerScriptHotfixCheck();
|
||
|
}
|
||
|
private void CommInitOnCreateReload(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
RegisterAllService();
|
||
|
|
||
|
// 舆情系统初始化
|
||
|
HeroSentimentSvc.Init();
|
||
|
}
|
||
|
|
||
|
public virtual void OnCreate(ServerApp app)
|
||
|
{
|
||
|
//打印消息统计日志
|
||
|
app.GetCluster().NeedLogMsgStat = true;
|
||
|
|
||
|
m_app = app;
|
||
|
//不需要全部文件
|
||
|
if (GameConfigMgr.Instance.m_isBin)
|
||
|
{
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("SysNoticeLampDesc.bin");
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("SysNoticeDesc.bin");
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("ArenaPeakSeasonInfoDesc.bin");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("SysNoticeLampDesc.txt");
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("SysNoticeDesc.txt");
|
||
|
//GameConfigMgr.Instance.ReadOneConfig("DirtyStringDesc.txt");
|
||
|
}
|
||
|
|
||
|
RegisterAllDataObj();
|
||
|
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
|
||
|
//载入聊天文件
|
||
|
ChatCacheOp.LoadCacheFromFile();
|
||
|
|
||
|
TraceLog.Debug("ChatServer start at {0}, guid {1}", DateTime.Now, m_guid);
|
||
|
}
|
||
|
|
||
|
public virtual void OnHotfix(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
|
||
|
ReadServerConfig();
|
||
|
CommInitOnCreateReload(app);
|
||
|
|
||
|
TraceLog.Debug("ChatServer hotfix at {0}, guid {1}", DateTime.Now, m_guid);
|
||
|
}
|
||
|
|
||
|
public virtual void OnReloadConfig(string excelConfigFile)
|
||
|
{
|
||
|
TraceLog.Debug("ChatServer OnReloadConfig at {0}", DateTime.Now);
|
||
|
ReadServerConfig();
|
||
|
|
||
|
|
||
|
DirtyServiceAc.Instance.InitFromFile(m_dirtyListFile);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public virtual void OnTick(long nowMs)
|
||
|
{
|
||
|
ServerStat.Instance.Tick(nowMs);
|
||
|
|
||
|
|
||
|
|
||
|
ChatServerUtils.OnTick(nowMs);
|
||
|
|
||
|
RealmlistSvc.OnTick(nowMs);
|
||
|
|
||
|
ArenaSvc.OnTick(nowMs);
|
||
|
}
|
||
|
|
||
|
|
||
|
private void TickReport(long nowMs)
|
||
|
{
|
||
|
if (nowMs - m_lastReportTime < m_ReportTimeInterVal)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
m_lastReportTime = nowMs;
|
||
|
ReportGameInfoToWorld();
|
||
|
}
|
||
|
//上报下当前chatserver连接数量(chatServer现在只打算一个,不上报也行,之后看看要不要扩展)
|
||
|
private void ReportGameInfoToWorld()
|
||
|
{
|
||
|
SSGameReportReq gameReportReq = new SSGameReportReq();
|
||
|
|
||
|
gameReportReq.GameSvrid = ChatServerUtils.GetAppID();
|
||
|
gameReportReq.OnlinePlayer = ChatServerUtils.GetPlayerTableOp().GetPlayerOnChatCount();
|
||
|
|
||
|
ChatServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GameReportReq, ref gameReportReq, 0);
|
||
|
|
||
|
}
|
||
|
|
||
|
public virtual void OnMessage(uint remoteAppID, MessageData message)
|
||
|
{
|
||
|
m_rootMessageHandler.HandlerMessage(remoteAppID, message);
|
||
|
}
|
||
|
|
||
|
public virtual void OnStop()
|
||
|
{
|
||
|
//很多服务器停服可以直接退出
|
||
|
m_app.SetStopSuccess();
|
||
|
}
|
||
|
|
||
|
private void ReadServerConfig()
|
||
|
{
|
||
|
//读取配置文件
|
||
|
string strLogicServerConfig = m_app.GetCluster().GetAppConfigPath() + "/" + m_app.AppParam.ServerConfig.configfile;
|
||
|
m_chatServerConfig = ServerConfigMgr.Instance.ReloadServerConfig<ChatServerConfig>(m_app, strLogicServerConfig);
|
||
|
ChatCacheOp.InitChatCacheConfig(m_chatServerConfig);
|
||
|
}
|
||
|
|
||
|
//所有引用对象置空
|
||
|
public void Dispose()
|
||
|
{
|
||
|
TraceLog.Debug("ChatServer be disposed");
|
||
|
|
||
|
m_app = null;
|
||
|
m_rootMessageHandler = null;
|
||
|
|
||
|
}
|
||
|
|
||
|
private void RegisterAllDataObj()
|
||
|
{
|
||
|
TraceLog.Debug("ChatServer RegisterAllDataObj");
|
||
|
ReadServerConfig();
|
||
|
ChatServerData chatServerData = new ChatServerData(m_app);
|
||
|
if (m_chatServerConfig != null
|
||
|
&& m_chatServerConfig.TotalCacheNum > 0
|
||
|
&& chatServerData.m_chatCacheInfo == null)
|
||
|
{
|
||
|
chatServerData.m_chatCacheInfo = new ChatCache(m_chatServerConfig.TotalCacheNum);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
TraceLog.Error("ChatServer RegisterAllDataObj chatServerCongi need set");
|
||
|
throw new Exception("need set chatServer config");
|
||
|
}
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(chatServerData);
|
||
|
//运营日志
|
||
|
BillLogWriter.Instance.Init(m_app.ServerID, ChatServerUtils.GetPacketSender());
|
||
|
|
||
|
PlayerTable playerTable = new PlayerTable();
|
||
|
ServerDataObjMgr.Instance.RegisterDataObj(playerTable);
|
||
|
}
|
||
|
|
||
|
private void RegisterAllService()
|
||
|
{
|
||
|
|
||
|
TraceLog.Debug("ChatServer RegisterAllService");
|
||
|
|
||
|
m_rootMessageHandler = new RootMessageHandler(m_app, ChatServerUtils.GetChatServerData());
|
||
|
ServiceMgr.Instance.RegisterService(m_rootMessageHandler);
|
||
|
|
||
|
|
||
|
PlayerTableOp playerTableOp = new PlayerTableOp(ChatServerUtils.GetPlayerTable());
|
||
|
ServiceMgr.Instance.RegisterService(playerTableOp);
|
||
|
|
||
|
GmCmdSvc gmCmdSvc = new GmCmdSvc();
|
||
|
ServiceMgr.Instance.RegisterService(gmCmdSvc);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|