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.
126 lines
3.9 KiB
126 lines
3.9 KiB
1 month ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
using Sog;
|
||
|
using Sog.Service;
|
||
|
using ProtoCSStruct;
|
||
|
|
||
|
namespace HttpProxyWorld
|
||
|
{
|
||
|
public class HttpProxyMsgHandler : BaseReloadableService
|
||
|
{
|
||
|
private ServerApp m_app;
|
||
|
|
||
|
|
||
|
|
||
|
public override int GetServiceType()
|
||
|
{
|
||
|
return HttpProxyServiceType.HttpProxyMsgHandler;
|
||
|
}
|
||
|
|
||
|
//销毁的时候置空
|
||
|
public override void Dispose()
|
||
|
{
|
||
|
m_app = null;
|
||
|
}
|
||
|
|
||
|
public HttpProxyMsgHandler(ServerApp app)
|
||
|
{
|
||
|
m_app = app;
|
||
|
}
|
||
|
|
||
|
public ServerApp GetApp()
|
||
|
{
|
||
|
return m_app;
|
||
|
}
|
||
|
|
||
|
public void HandlerMessage(uint remoteAppID, MessageData message)
|
||
|
{
|
||
|
StructPacket packet;
|
||
|
bool bSuccess = HttpProxyWorldServerUtils.GetProtoPacker().UnpackMessage(message, out packet);
|
||
|
if(bSuccess == false)
|
||
|
{
|
||
|
TraceLog.Error("HttpProxyMsgHandler.HandlerMessage ,unpack msg failed {0}, remoteAppID {1}"
|
||
|
, message.Header.Type, remoteAppID);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//消息多线程处理,这里需要clone一个才行
|
||
|
packet = packet.Clone();
|
||
|
|
||
|
//预先判断,提高效率
|
||
|
if (TraceLog.GetLogLevel() <= Sog.Log.LogLevel.TraceDetail
|
||
|
&& TraceLog.IsSkipLogMsgID(packet.MsgID) == false)
|
||
|
{
|
||
|
TraceLog.TraceDetail("HttpProxyMsgHandler recv message from server {0}, message type {1} length {2} : {3}->{4}"
|
||
|
, ServerIDUtils.IDToString(remoteAppID)
|
||
|
, message.Header.Type
|
||
|
, message.Header.Length
|
||
|
, packet.MessageName()
|
||
|
, packet.ToString());
|
||
|
}
|
||
|
|
||
|
switch (packet.MsgID)
|
||
|
{
|
||
|
case (int)SSMsgID.GcmGooglePushInfo:
|
||
|
OnHttpReqGooglePushInfo(remoteAppID, packet);
|
||
|
break;
|
||
|
case (int)SSGameMsgID.PayDiamondHolderQueryReq:
|
||
|
case (int)SSGameMsgID.PayDiamondHolderAddReq:
|
||
|
case (int)SSGameMsgID.PayDiamondHolderCostReq:
|
||
|
case (int)SSGameMsgID.PayDiamondHolderCostCancelReq:
|
||
|
OnPayDiamondHolderReq(remoteAppID, packet);
|
||
|
break;
|
||
|
default:
|
||
|
TraceLog.Error("HttpProxyMsgHandler unknow MsgID {0}", packet.MsgID);
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private int CalcPushTaskIndex()
|
||
|
{
|
||
|
int randIndex = HttpProxyWorldServerUtils.GetApp().Rand.Next(HttpProxyWorldServerUtils.PushTaskCount);
|
||
|
int index = HttpProxyWorldServerUtils.PayTaskCount + randIndex;
|
||
|
|
||
|
return index;
|
||
|
}
|
||
|
|
||
|
private int CalcPayTaskIndex(long uid)
|
||
|
{
|
||
|
int payIndex = (int)(uid % HttpProxyWorldServerUtils.PayTaskCount);
|
||
|
|
||
|
int index = payIndex;
|
||
|
|
||
|
return index;
|
||
|
}
|
||
|
|
||
|
|
||
|
private void OnHttpReqGooglePushInfo(uint remoteAppID, StructPacket packet)
|
||
|
{
|
||
|
int iTaskIndex = CalcPushTaskIndex();
|
||
|
|
||
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
||
|
|
||
|
ref var data = ref packet.GetMessage<SSGoogleFirebasePush>();
|
||
|
|
||
|
TraceLog.Debug("HttpProxyMsgHandler.OnHttpReqGooglePushInfo remoteAppID {0} Content {1}",
|
||
|
remoteAppID,data.Content);
|
||
|
}
|
||
|
|
||
|
|
||
|
private void OnPayDiamondHolderReq(uint remoteAppID, StructPacket packet)
|
||
|
{
|
||
|
int iTaskIndex = CalcPayTaskIndex(packet.ObjectID);
|
||
|
|
||
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
||
|
|
||
|
TraceLog.Debug("HttpProxyMsgHandler.OnPayDiamondHolderReq remoteAppID {0} uid {1}",
|
||
|
remoteAppID, packet.ObjectID);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|