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.
113 lines
3.3 KiB
113 lines
3.3 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Game
|
|
{
|
|
// 游戏服务器上报消息
|
|
public class GameReportSvc : BaseReloadableService
|
|
{
|
|
private long lastReportTime = 0;
|
|
private int m_ReportTimeInterVal = 1;
|
|
|
|
//最大上报时间间隔
|
|
private const int ReportTimeInterValMax = 10;
|
|
|
|
private static long lastForceGetAllRealmTime = 0;
|
|
|
|
public override int GetServiceType()
|
|
{
|
|
return GameServiceType.GameReportSvc;
|
|
}
|
|
|
|
//销毁的时候置空
|
|
public override void Dispose()
|
|
{
|
|
}
|
|
|
|
public GameReportSvc()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public void OnTick(long nowSecond)
|
|
{
|
|
//启动的时候上报快一点,后面慢一点
|
|
if (nowSecond - lastReportTime < m_ReportTimeInterVal)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
lastReportTime = nowSecond;
|
|
|
|
if (m_ReportTimeInterVal < ReportTimeInterValMax)
|
|
{
|
|
m_ReportTimeInterVal += 1;
|
|
}
|
|
|
|
ReportGameInfoToWorld();
|
|
}
|
|
|
|
private void ReportGameInfoToWorld()
|
|
{
|
|
SSGameReportReq gameReportReq = new SSGameReportReq();
|
|
|
|
gameReportReq.GameSvrid = GameServerUtils.GetAppID();
|
|
gameReportReq.OnlinePlayer = GameServerUtils.GetPlayerTableOp().GetOnlinePlayer();
|
|
gameReportReq.RecvConfigRealmListMd5.SetString(GameServerUtils.GetGameServerData().recvConfigRealmListMd5);
|
|
|
|
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.GameReportReq, ref gameReportReq, 0);
|
|
}
|
|
|
|
public static void GetAllRealmBrief(long nowSec)
|
|
{
|
|
var realmReq = new SSRealmBriefReq { GameSvrId = GameServerUtils.GetAppID() };
|
|
//为了以防万一,每10分钟强制拉一次全量
|
|
if (nowSec - lastForceGetAllRealmTime >= 600)
|
|
{
|
|
lastForceGetAllRealmTime = nowSec;
|
|
}
|
|
else
|
|
{
|
|
realmReq.RealmListMd5.SetString(GameServerUtils.GetGameServerData().recvRealmListMd5);
|
|
}
|
|
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSMsgID.RealmBriefReq, ref realmReq, 0);
|
|
}
|
|
|
|
public static void ReportRealmOnlineToWorld()
|
|
{
|
|
var online = GameServerUtils.GetGameServerData().realmOnline;
|
|
|
|
var report = new SSOnlineReport();
|
|
foreach (KeyValuePair<int, int> pair in online)
|
|
{
|
|
if (report.RealmOnline.Count < report.RealmOnline.GetMaxCount())
|
|
{
|
|
var item = new IDValue32 {Id = pair.Key, Value = pair.Value};
|
|
report.RealmOnline.Add(ref item);
|
|
}
|
|
else
|
|
{
|
|
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.OnlineReport, ref report, 0);
|
|
report.RealmOnline.Clear();
|
|
}
|
|
}
|
|
|
|
if (report.RealmOnline.Count > 0)
|
|
{
|
|
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.OnlineReport, ref report, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|