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.
156 lines
5.7 KiB
156 lines
5.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using Sog.Service;
|
|
using ProtoCSStruct;
|
|
|
|
namespace HttpProxy
|
|
{
|
|
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 = HttpProxyServerUtils.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)CSMsgID.AccountReq:
|
|
HttpCheckAccountToken(remoteAppID, packet);
|
|
break;
|
|
case (int)SSMsgID.QueryHttpSnsFriendListReq:
|
|
HttpQuerySnsFriendList(remoteAppID, packet);
|
|
break;
|
|
case (int)SSMsgID.BindGuestFacebookHttpCheckReq:
|
|
OnBindGuestFacebookHttpCheckReq(remoteAppID, packet);
|
|
break;
|
|
case (int)SSMsgID.UnbindGuestFacebookNotifyHttp:
|
|
OnUnBindGuestFacebookNotifyHttp(remoteAppID, packet);
|
|
break;
|
|
default:
|
|
TraceLog.Error("HttpProxyMsgHandler unknow MsgID {0}", packet.MsgID);
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private int CalcLoginTaskIndex(int accountType, string accountID)
|
|
{
|
|
string strHash = AccountUtils.CalcAccountKey(accountType, accountID);
|
|
|
|
int index = AccountUtils.HashStringForIndex(strHash) % HttpProxyServerUtils.HttpProxyLoginWorkThreadCount;
|
|
|
|
return index;
|
|
}
|
|
|
|
|
|
//
|
|
//此方法其实不处理实际逻辑,只是根据account信息分发到对应的task
|
|
//具体执行逻辑在MessageTaskHandler
|
|
private void HttpCheckAccountToken(uint remoteAppID, StructPacket packet)
|
|
{
|
|
ref CSAccountAuthReq accountAuthReq = ref packet.GetMessage<CSAccountAuthReq>();
|
|
|
|
int iTaskIndex = CalcLoginTaskIndex(accountAuthReq.Account.AccountType, accountAuthReq.Account.AccountID.GetString());
|
|
|
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
|
|
|
TraceLog.Debug("HttpProxyMsgHandler.HttpCheckAccountToken type {0} id {1} distribute to task {2}"
|
|
, accountAuthReq.Account.AccountType
|
|
, accountAuthReq.Account.AccountID
|
|
, iTaskIndex);
|
|
}
|
|
|
|
private void HttpQuerySnsFriendList(uint remoteAppID, StructPacket packet)
|
|
{
|
|
ref SSQueryHttpSnsFriendListReq httpSnsReq = ref packet.GetMessage<SSQueryHttpSnsFriendListReq>();
|
|
|
|
int iTaskIndex = CalcLoginTaskIndex(httpSnsReq.Account.AccountType, httpSnsReq.Account.AccountID.GetString());
|
|
|
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
|
|
|
TraceLog.Debug("HttpProxyMsgHandler.HttpQuerySnsFriendList type {0} id {1} distribute to task {2}"
|
|
, httpSnsReq.Account.AccountType
|
|
, httpSnsReq.Account.AccountID
|
|
, iTaskIndex);
|
|
}
|
|
|
|
private void OnBindGuestFacebookHttpCheckReq(uint remoteAppID, StructPacket packet)
|
|
{
|
|
ref SSBindGuestFacebookHttpCheckReq req = ref packet.GetMessage<SSBindGuestFacebookHttpCheckReq>();
|
|
|
|
int iTaskIndex = CalcLoginTaskIndex(req.AccountInfo.AccountType, req.AccountInfo.AccountID.GetString());
|
|
|
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
|
|
|
TraceLog.Debug("HttpProxyMsgHandler.OnBindGuestFacebookHttpCheckReq type {0} id {1} distribute to task {2}"
|
|
, req.AccountInfo.AccountType
|
|
, req.AccountInfo.AccountID
|
|
, iTaskIndex);
|
|
}
|
|
|
|
private void OnUnBindGuestFacebookNotifyHttp(uint remoteAppID, StructPacket packet)
|
|
{
|
|
ref SSUnbindGuestFacebookNotifyHttp req = ref packet.GetMessage<SSUnbindGuestFacebookNotifyHttp>();
|
|
|
|
int iTaskIndex = CalcLoginTaskIndex(req.AccountInfo.AccountType, req.AccountInfo.AccountID.GetString());
|
|
|
|
MessageTaskDistributor.Instance.Distribute(remoteAppID, packet, iTaskIndex);
|
|
|
|
TraceLog.Debug("HttpProxyMsgHandler.OnUnBindGuestFacebookNotifyHttp type {0} id {1} distribute to task {2}"
|
|
, req.AccountInfo.AccountType
|
|
, req.AccountInfo.AccountID
|
|
, iTaskIndex);
|
|
}
|
|
|
|
}
|
|
}
|
|
|