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.
 
 
 
 
 
 

172 lines
5.1 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using Sog;
using Sog.Log;
namespace Account
{
// 帐号服务器入口
public class AccountServer : IScript
{
private Guid m_guid;
private ServerApp m_app;
private AccountMsgHandler m_accountHandler;
private RootMessageHandler m_rootMessageHandler;
private GmCmdSvc m_gmCmdSvcHandler;
private long m_tick30Ms;
public AccountServer()
{
m_guid = Guid.NewGuid();
}
public IScriptHotfixCheck GetScriptHotfixCheck()
{
return new ServerScriptHotfixCheck();
}
private void CommInitOnCreateReload(ServerApp app)
{
m_app = app;
RegisterAllService();
DBServerSelect.Init(app);
HttpProxySelect.Init(app);
}
public virtual void OnCreate(ServerApp app)
{
//打印消息统计日志
app.GetCluster().NeedLogMsgStat = true;
m_app = app;
RegisterAllDataObj();
CommInitOnCreateReload(app);
TraceLog.Debug("AccountServer.OnCreate start at {0}, guid {1}", DateTime.Now, m_guid);
}
public virtual void OnHotfix(ServerApp app)
{
m_app = app;
ReadServerConfig();
CommInitOnCreateReload(app);
TraceLog.Debug("AccountServer.OnHotfix {0}, guid {1}", DateTime.Now, m_guid);
}
public virtual void OnReloadConfig(string excelConfigFile)
{
TraceLog.Debug("AccountServer.OnReloadConfig {0}", DateTime.Now);
ReadServerConfig();
}
public virtual void OnTick(long nowMs)
{
ServerStat.Instance.Tick(nowMs);
m_gmCmdSvcHandler.Tick(nowMs);
Tick30Sec(nowMs);
}
private void Tick30Sec(long nowMs)
{
if (nowMs < m_tick30Ms + 30000)
{
return;
}
m_tick30Ms = nowMs;
}
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;
AccountServerConfig serverConfig = ServerConfigMgr.Instance.ReloadServerConfig<AccountServerConfig>(m_app,strLogicServerConfig);
//if (ServerIDUtils.GetInstanceID(m_app.ServerID) > serverConfig.accountServerCount)
//{
// throw new Exception("account server config error! serverConfig.accountServerCount invalid");
//}
//重新读ip白名单,黑名单
LimitIPList.Clear();
}
//所有引用对象置空
public void Dispose()
{
TraceLog.Debug("AccountServer.Dispose");
m_app = null;
m_accountHandler = null;
m_rootMessageHandler = null;
}
private void RegisterAllDataObj()
{
TraceLog.Debug("AccountServer.RegisterAllDataObj");
AccountServerData accountServerData = new AccountServerData(m_app);
ServerDataObjMgr.Instance.RegisterDataObj(accountServerData);
AccountTable accountTable = new AccountTable();
ServerDataObjMgr.Instance.RegisterDataObj(accountTable);
SnsFriendAccountInfoCache friendCacheInfo = new SnsFriendAccountInfoCache();
ServerDataObjMgr.Instance.RegisterDataObj(friendCacheInfo);
ReadServerConfig();
PlayerTable playerTable = new PlayerTable();
ServerDataObjMgr.Instance.RegisterDataObj(playerTable);
BillLogWriter.Instance.Init(m_app.ServerID, accountServerData.m_packetSender);
}
private void RegisterAllService()
{
TraceLog.Debug("AccountServer.RegisterAllService");
m_accountHandler = new AccountMsgHandler(m_app);
ServiceMgr.Instance.RegisterService(m_accountHandler);
m_rootMessageHandler = new RootMessageHandler(m_app, AccountServerUtils.GetAccountServerData(), m_accountHandler);
ServiceMgr.Instance.RegisterService(m_rootMessageHandler);
PlayerTableOp playerTableOp = new PlayerTableOp(AccountServerUtils.GetPlayerTable());
ServiceMgr.Instance.RegisterService(playerTableOp);
AccountTableOp accountTableOp = new AccountTableOp(AccountServerUtils.GetAccountTable());
ServiceMgr.Instance.RegisterService(accountTableOp);
SnsFriendCacheOp snsFriendCacheOp = new SnsFriendCacheOp(AccountServerUtils.GetSnsFriendCache());
ServiceMgr.Instance.RegisterService(snsFriendCacheOp);
m_gmCmdSvcHandler = new GmCmdSvc();
ServiceMgr.Instance.RegisterService(m_gmCmdSvcHandler);
}
}
}