internal static void OnServerConnect(byte[] buffer) { var req = new S2C_Server_Connect(buffer); var rsp = new C2S_Server_Connect() { SessionType = (short)BaseServerInfo.SessionType }; loger.Debug($"服务器连接:{req.ServerID}"); Dispatcher.SendByServerID(req.ServerID, rsp); }
/// <summary> /// 处理消息立即 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public static void ProcessMessage(LunarSession session, LunarRequestInfo requestInfo) { EProtocolId id = (EProtocolId)requestInfo.ProtocolID; if (id == EProtocolId.C2S_SERVER_CONNECT) { var sessiontemp = GetSession(session.SessionID); if (sessiontemp != null) { var Req = new C2S_Server_Connect(requestInfo.Body); sessiontemp.SessionType = Req.SessionType; loger.Debug($"连接类型:{(EServerType)sessiontemp.SessionType}"); } else { loger.Error($"连接不存在:{session.SessionUuid}"); } return; } if (DictProtocolEvent.TryGetValue(id, out DispatcherEventHandler handle)) { try { var StopwatchProcess = Stopwatch.StartNew(); handle(session, requestInfo); StopwatchProcess.Stop(); var UseMs = StopwatchProcess.ElapsedMilliseconds; if (UseMs > 500) { loger.Error($"消息处理超时,消息:{id} 玩家ID:{session.SessionUuid} 耗时:{UseMs} Ms__{CountMsgs}"); } } catch (Exception e) { loger.Fatal($"处理协议-> {id} -> {(int)id}出错 玩家ID:{session.SessionUuid}", e); Result(session, EProtocolResult.失败); return; } } else { loger.Fatal($"处理协议-> {id} -> {(int)id} 未注册"); Result(session, EProtocolResult.失败); return; } }
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)); } }