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.
115 lines
3.9 KiB
115 lines
3.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
|
|
namespace Gate
|
|
{
|
|
public static class GateServerUtils
|
|
{
|
|
public static GateServerData GetGateServerData()
|
|
{
|
|
return ServerDataObjMgr.GetDataObj<GateServerData>(GateDataObjType.GateServerData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取服务器配置方法
|
|
/// </summary>
|
|
public static GateServerConfig GetServerConfig()
|
|
{
|
|
return (GateServerConfig)ServerConfigMgr.Instance.m_serverConfig;
|
|
}
|
|
|
|
public static ServerRoute GetServerRoute()
|
|
{
|
|
return ServiceMgr.GetService<ServerRoute>(GateServiceType.ServerRoute);
|
|
}
|
|
|
|
public static GateClientService GetGateClientService()
|
|
{
|
|
return ServiceMgr.GetService<GateClientService>(GateServiceType.GateClientService);
|
|
}
|
|
|
|
public static ServerMsgTrans GetServerMsgTrans()
|
|
{
|
|
return ServiceMgr.GetService<ServerMsgTrans>(GateServiceType.ServerMsgTrans);
|
|
}
|
|
|
|
public static long GetTimeSecond()
|
|
{
|
|
return GateServerUtils.GetGateServerData().m_app.Time.GetTimeSecond();
|
|
}
|
|
|
|
public static void OnAddOneMessage(GateClientInfo info, GateServerConfig serverConfig,
|
|
int messageId, int messageNum, int messageLenth)
|
|
{
|
|
var gateData = GetGateServerData();
|
|
long now = GetTimeSecond();
|
|
if (info.FlowCheckInfo == null)
|
|
{
|
|
info.FlowCheckInfo = new FlowCheckInfo();
|
|
}
|
|
|
|
if (serverConfig.messageIgnoreLimitList != null && serverConfig.messageIgnoreLimitList.Contains(messageId))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var checkInfo = info.FlowCheckInfo;
|
|
if (checkInfo.nextResetTime < now)
|
|
{
|
|
checkInfo.CleanData();
|
|
checkInfo.nextResetTime = now + serverConfig.checkFlowSecCd;
|
|
}
|
|
|
|
//数量限制
|
|
if(gateData.m_messageLimitMap.TryGetValue(messageId, out int limitCount))
|
|
{
|
|
if(false == checkInfo.messageNumMap.ContainsKey(messageId))
|
|
{
|
|
checkInfo.messageNumMap.Add(messageId, 0);
|
|
}
|
|
checkInfo.messageNumMap[messageId] += messageNum;
|
|
int nowNum = checkInfo.messageNumMap[messageId];
|
|
if (nowNum >= limitCount)
|
|
{
|
|
checkInfo.CleanData();
|
|
checkInfo.nextResetTime = now + serverConfig.checkFlowSecCd;
|
|
++checkInfo.aboveLimitTimes;
|
|
TraceLog.Error("GateServerUtils.OnAddOneMessage SessionID:{0} messageID:{1} above num:{2}",
|
|
info.SessionID, messageId, nowNum);
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
checkInfo.messageNum += messageNum;
|
|
int nowNum = checkInfo.messageNum;
|
|
if (checkInfo.messageNum >= serverConfig.limitMessageNum)
|
|
{
|
|
checkInfo.CleanData();
|
|
checkInfo.nextResetTime = now + serverConfig.checkFlowSecCd;
|
|
++checkInfo.aboveLimitTimes;
|
|
TraceLog.Error("GateServerUtils.OnAddOneMessage SessionID:{0} messageNum:{1}", info.SessionID, nowNum);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//流量限制
|
|
checkInfo.messageLenth += messageLenth;
|
|
int nowLenth = checkInfo.messageLenth;
|
|
if (nowLenth >= serverConfig.limitMessageLenth)
|
|
{
|
|
checkInfo.CleanData();
|
|
checkInfo.nextResetTime = now + serverConfig.checkFlowSecCd;
|
|
++checkInfo.aboveLimitTimes;
|
|
TraceLog.Error("GateServerUtils.OnAddOneMessage SessionID:{0} messageLenth:{1}", info.SessionID, nowLenth);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|