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.
 
 
 
 
 
 

92 lines
2.6 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Gate;
namespace Gate
{
public class ClusterChannelHandler : BaseReloadableService
{
private ServerApp m_app;
private GateClientService m_clientService;
//接口实现
public override int GetServiceType()
{
return GateServiceType.ClusterChannelHandler;
}
//接口实现
public override void Dispose()
{
m_app = null;
m_clientService = null;
}
public ClusterChannelHandler(ServerApp app, GateClientService clientService)
{
m_app = app;
m_clientService = clientService;
}
public void HandlerMessage(uint remoteAppID, MessageData message)
{
GateMsgHeader header = new GateMsgHeader();
GateMsgHeaderPacker.UnPack(message.Buffer.Data,ref header);
// trans msg to client
if (header.OpCode == (int)GateMsgOpCode.Trans)
{
m_clientService.TransChannelMessageToClient(remoteAppID, header.SessionID, message);
return;
}
if (header.OpCode == (int)GateMsgOpCode.ConnectedRes)
{
m_clientService.OnServerAckConnected(remoteAppID, header.SessionID);
return;
}
if (header.OpCode == (int)GateMsgOpCode.DisconnectedReq)
{
m_clientService.OnServerReqDisconnect(remoteAppID, header.SessionID);
return;
}
if (header.OpCode == (int)GateMsgOpCode.DisconnectedRes)
{
// skip
return;
}
if(header.OpCode == (int)GateMsgOpCode.Route)
{
GateServerUtils.GetServerRoute().RouteBackEndServer(remoteAppID, message, header);
return;
}
//广播
if(header.OpCode == (int)GateMsgOpCode.TransMulti)
{
GateMsgMultiSessionHeader mutilsession;
mutilsession.Count = 0;
GateMsgHeaderPacker.UnPackMultiSessionHeader(message.Buffer.Data,ref mutilsession);
m_clientService.TransChannelMessageToMultiClient(ref mutilsession, message);
return;
}
TraceLog.Error("recv error gate message from server, OpCode {0} length {1} session {2} message type {3} length {4}",
header.OpCode, message.Buffer.Length, header.SessionID, message.Header.Type, message.Header.Length);
}
}
}