public static void ProcessMessage(LunarSession session, LunarRequestInfo requestInfo) { EProtocolId id = (EProtocolId)requestInfo.ProtocolID; loger.Info($"中转{(EServerType)session.SessionType} 协议->{id} -> {session.SessionUuid} 。"); var objMsg = ProtocolDump.Dump(id, requestInfo.Body); if (objMsg == null) { loger.Warn("错误协议!"); return; } //登录服务器消息 if (id > EProtocolId.L2E_GAME_START && id < EProtocolId.L2E_GAME_END) { //检测连接状态 ESessionState SessionState = (ESessionState)session.SessionState; if (SessionState == ESessionState.Logined) { loger.Warn($"已登陆收到登陆协议-> {id} -> {(int)id} 。"); return; } else { //后期人多则会添加登录服务器获取人少的服 ((ProtocolMsgBase)objMsg).Shuttle = session.SessionID; SendToLogin(objMsg); } } else if (id > EProtocolId.B2T_GM_START && id < EProtocolId.B2T_GM_END) { if (session.SessionType != (short)EServerType.后台工具) { loger.Warn($"错误的GM协议-> {id} -> {(int)id} 。"); return; } } //游戏服消息 else { ((ProtocolMsgBase)objMsg).Puid = session.SessionUuid; SendToGame(objMsg); } }
private static void GateEventHandler(byte[] buffer) { var nbs = new NetBitStream(); nbs.BeginRead(buffer); EProtocolId id = (EProtocolId)nbs.ReadProtocolHeader(); var objMsg = ProtocolDump.Dump(id, buffer); if (objMsg == null) { loger.Error($"错误协议!{id}"); return; } if (ClientDispatcher.DictProtocolEvent.TryGetValue(id, out var protocolevent)) { protocolevent.ExecuteProtocolEvent(buffer); return; } if ((int)id < 100) { return; } long puid = ((ProtocolMsgBase)objMsg).Puid; if (puid == 0 && ((ProtocolMsgBase)objMsg).RspPuids.Count == 0) { loger.Error($"发送客户端消息错误,无发送目标!"); return; } List <long> rspId = new List <long>(); if (puid != 0) { rspId.Add(puid); } if (((ProtocolMsgBase)objMsg).RspPuids.Count > 0) { rspId.AddRange(((ProtocolMsgBase)objMsg).RspPuids); } SendMsg(objMsg, rspId); }
private static void GameEventHandler(byte[] buffer) { var nbs = new NetBitStream(); nbs.BeginRead(buffer); EProtocolId id = (EProtocolId)nbs.ReadProtocolHeader(); var objMsg = ProtocolDump.Dump(id, buffer); if (objMsg == null) { loger.Error($"错误协议!{id}"); return; } if (id == EProtocolId.S2C_SERVER_CONNECT) { var rsp = new C2S_Server_Connect() { SessionType = (short)BaseServerInfo.SessionType }; Dispatcher.SendByServerID(((S2C_Server_Connect)objMsg).ServerID, rsp); return; } if ((int)id < 100) { return; } if (!ClientDispatcher.DictProtocolEvent.TryGetValue(id, out var protocolevent)) { loger.Debug(string.Format("未注册协议-> {0} -> {1} ......", id, (int)id)); return; } try { //处理 protocolevent.ExecuteProtocolEvent(buffer); } catch (Exception ex) { loger.Error(string.Format("处理协议-> {0} -> {1}出错 ex:{2}", id, (int)id, ex.Message)); } }