internal static void OnServerInfo(LunarSession session, LunarRequestInfo requestInfo) { var Req = new G2D_Game_Server(requestInfo.Body); var Rsp = new D2G_Game_Server(); //Rsp.Data = RedisGame.KvGet($"{RdsServerData}:{Req.ServerID}"); //Send(session,Rsp); }
internal static void OnLogin(LunarSession session, LunarRequestInfo requestInfo) { var Req = new L2E_Game_LoginServer(requestInfo.Body); var player = new Player(Req.Puid); if (!player.Load()) { } player.XY.Uid = player.Id; DictPlayerOnline[Req.Puid] = player; var rsp = new G2E_Game_MapIn(); rsp.PlayerXY = player.XY; SendAll(session, rsp, player.Id); var rsp2 = new G2E_Game_MapInOther(); foreach (var item in DictPlayerOnline.Values) { if (item.Id == player.Id) { continue; } item.XY.Uid = item.Id; rsp2.ListPlayerXY.Add(item.XY); //rsp.Shuttle = Req.Shuttle; } rsp2.Puid = player.Id; session.Send(rsp2); }
internal static void OnBaseServer(LunarSession session, LunarRequestInfo requestInfo) { //var rsp = new S2C_Server_Connect() //{ // SessionType = (short)BaseServerInfo.SessionType //}; //Dispatcher.SendByServerID(((S2C_Server_Connect)objMsg).ServerID, rsp); }
public static void OnBasePing(LunarSession session, LunarRequestInfo requestInfo) { var Rsp = new All_Base_Ping() { ServerTime = DateTime.Now, }; BaseDispatch.Send(session, Rsp); }
/// <summary> /// 返回通用错误 /// </summary> public static void Result(LunarSession session, EProtocolResult result = EProtocolResult.失败) { var objMsg = new All_Base_Result() { Result = result, }; Send(session, objMsg); }
/// <summary> /// 新连接事件 /// </summary> /// <param name="session"></param> public static void OnSessionConnected(LunarSession session) { loger.Debug("接收到连接: " + session.SessionID); BaseServerInfo.AllSessions.TryAdd(session.SessionID, session); BaseDispatch.Send(session, new S2C_Server_Connect() { ServerID = BaseServerInfo.ServerID }); }
//清除负载列表 public static void RemoveServerLinkList(LunarSession session) { if (DictServerLink.ContainsKey((int)session.SessionUuid)) { DictServerLink.Remove((int)session.SessionUuid); loger.Debug("服务器关闭 清除负载列表ID: " + session.SessionUuid.ToString()); } RefreshServerLinkList(); }
/// <summary> /// 有连接断开 /// </summary> /// <param name="session"></param> /// <param name="reason"></param> public static void OnSessionClosed(LunarSession session, CloseReason reason) { loger.Debug("连接断开: " + session.SessionID); //当连接断开时 检查连接类型 如果类型为服务器 去清除负载列表 if (session.SessionType != (long)EServerType.客户端) { BaseServerLinkManager.RemoveServerLinkList(session); } }
internal static void OnSessionClosed(LunarSession session, CloseReason value) { BaseServerInfo.AllSessions.TryRemove(session.SessionID, out var tt); { var rsp = new E2G_Game_LoginOut(); rsp.Puid = session.SessionUuid; SendToGame(rsp); DictPuidSession.TryRemove(rsp.Puid.ToString(), out var t); } }
/// <summary> /// 消息分发 /// </summary> /// <param name="session"></param> /// <param name="requestInfo"></param> public static void OnDispatch(LunarSession session, LunarRequestInfo requestInfo) { if (requestInfo.ProtocolID == 0) { loger.Warn("收到空消息"); return; } loger.Info($"收到消息 {(EProtocolId)requestInfo.ProtocolID}"); //ProcessMessage(session, requestInfo); session.ListReq.Enqueue(requestInfo); }
private static void Server_NewRequestReceived(LunarSession session, LunarRequestInfo requestInfo) { Reload(); // 发送消息Event_01 Event evt1 = new Event(); evt1.EventID = (int)EventDefines.Event_01; evt1.PushUserData <string>("SomeData For Event01"); ThisSession = session; ety.DispatchEvent(evt1); }
internal static void OnDispatch(LunarSession session, LunarRequestInfo requestInfo) { if (!session.Connected) { loger.Warn("收到断开连接的客户端消息"); return; } if (requestInfo.ProtocolID <= 0) { loger.Warn("收到空消息"); return; } session.ListReq.Enqueue(requestInfo); //ProcessMessage(session,requestInfo); }
public static void SendAll(LunarSession session, INbsSerializer objMsg, long selfid = 0) { foreach (var item in DictPlayerOnline.Values) { if (item.Id == selfid) { continue; } ((ProtocolMsgBase)objMsg).RspPuids.Add(item.Id); } ((ProtocolMsgBase)objMsg).Puid = selfid; if (((ProtocolMsgBase)objMsg).RspPuids.Count > 0 || ((ProtocolMsgBase)objMsg).Puid != 0) { session.SendMerge(objMsg); } }
/// <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; } }
internal static void OnLogin(LunarSession session, LunarRequestInfo requestInfo) { var Req = new E2L_Game_LoginServer(requestInfo.Body); var Rsp = new L2E_Game_LoginServer(); Rsp.Shuttle = Req.Shuttle; if (!DataCache.TryGetValue(Req.Account, out var user)) { Rsp.Result = EProtocolResult.账号不存在; BaseDispatch.Send(session, Rsp); return; } if (Req.Password != user.Password) { Rsp.Result = EProtocolResult.密码错误; BaseDispatch.Send(session, Rsp); return; } Rsp.Puid = user.Uuid; BaseDispatch.Send(session, Rsp); }
internal static void OnLoginOut(LunarSession session, LunarRequestInfo requestInfo) { var Req = new E2G_Game_LoginOut(requestInfo.Body); DictPlayerOnline.Remove(Req.Puid); foreach (var item in DictPlayerOnline.Values) { if (item.Id == Req.Puid) { continue; } var rsp = new G2E_Game_LoginOut(); rsp.Puid = item.Id; session.Send(rsp); } }
/// <summary> /// 立即发送消息(通过session) /// </summary> public static void Send(LunarSession session, INbsSerializer objMsg) { try { if (session.Connected) { var nbs = objMsg.Serialize(); ushort id = nbs.ReadProtocolHeader(); ushort result = nbs.ReadProtocolResult(); loger.Info($"发送{(EServerType)session.SessionType}数据包 协议号:{(EProtocolId)id}->{id} 错误码:{(EProtocolResult)result}->{result} 长度:{nbs.Length}"); session.Send(nbs.BYTES, 0, nbs.Length); } } catch (Exception ex) { loger.Fatal("立即发送消息失败", ex); } }
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 bool isMove = false; public static void OnPlayerXY(LunarSession session, LunarRequestInfo requestInfo) { var Req = new E2G_Game_PlayerXY(requestInfo.Body); DictPlayerOnline.TryGetValue(Req.Puid, out var player); Req.PlayerXY.Uid = player.XY.Uid; player.XY = Req.PlayerXY; var rsp = new G2E_Game_PlayerXYOther(); rsp.PlayerXY = Req.PlayerXY; SendAll(session, rsp, player.Id); var rspself = new G2E_Game_PlayerXY(); rspself.PlayerXY = Req.PlayerXY; rspself.Puid = Req.Puid; session.Send(rspself); }
internal static void OnRegister(LunarSession session, LunarRequestInfo requestInfo) { var Req = new E2L_Game_Register(requestInfo.Body); var Rsp = new L2E_Game_Register(); Rsp.Shuttle = Req.Shuttle; if (DataCache.TryGetValue(Req.Account, out var user)) { Rsp.Result = EProtocolResult.账号已存在; BaseDispatch.Send(session, Rsp); return; } Rsp.Puid = CreateUuid(); user = new User(); user.Uuid = Rsp.Puid; user.Account = Req.Account; user.Password = Req.Password; DataCache[Req.Account] = user; user.Save(); BaseDispatch.Send(session, Rsp); }
internal static void OnRegister(LunarSession session, LunarRequestInfo requestInfo) { }
private static void Server_SessionClosed(LunarSession session, CloseReason value) { throw new NotImplementedException(); }
/// <summary> /// 新连接事件 /// </summary> /// <param name="session"></param> public static void OnSessionConnected(LunarSession session) { loger.Debug("接收到连接: " + session.SessionID); }
/// <summary> /// 有连接断开 /// </summary> /// <param name="session"></param> /// <param name="reason"></param> public static void OnSessionClosed(LunarSession session, CloseReason reason) { loger.Debug("连接断开: " + session.SessionID); BaseServerInfo.AllSessions.TryRemove(session.SessionID, out var tt); }
private static void Server_NewSessionConnected(LunarSession session) { m_DictSession[1] = (session); Console.WriteLine("接收到连接\r\n当前用户数:{0}", m_DictSession.Count); }
internal static void OnSessionConnected(LunarSession session) { loger.Debug("接收到连接: " + session.SessionID); session.SessionType = (short)EServerType.客户端; BaseServerInfo.AllSessions.TryAdd(session.SessionID, session); }