public async Task Chat_LoginHandler(ChatServer server, ChatSession session, LoginReqMessage message) { Logger.ForAccount(message.AccountId, "") .Information("ChatServer login from {remoteEndPoint}", session.RemoteEndPoint); //uint sessionId; //if (!uint.TryParse(message.SessionId, out sessionId)) //{ // Logger.ForAccount(message.AccountId, "") // .Error("Invalid sessionId"); // session.SendAsync(new LoginAckMessage(2)); // return; //} var plr = GameServer.Instance.PlayerManager[message.AccountId]; if (plr == null) { Logger.ForAccount(message.AccountId, "") .Error("Login failed"); await session.SendAsync(new LoginAckMessage(3)); return; } if (plr.ChatSession != null) { Logger.ForAccount(session) .Error("Already online"); await session.SendAsync(new LoginAckMessage(4)); return; } session.GameSession = plr.Session; plr.ChatSession = session; Logger.ForAccount(session) .Information("Login success"); await session.SendAsync(new LoginAckMessage(0)); await session.SendAsync(new DenyListAckMessage(plr.DenyManager.Select(d => d.Map <Deny, DenyDto>()).ToArray())); if (plr.Club != null) { await session.SendAsync(new ClubMemberLoginStateAckMessage() { Unk1 = 0, AccountId = plr.Account.Id }); await session.SendAsync(new ClubSystemMessageMessage() { Unk1 = plr.Account.Id, Unk2 = "Welcome!", }); } }
public async Task Chat_LoginHandler(ChatServer server, ChatSession session, LoginReqMessage message) { Logger.ForAccount(message.AccountId, "") .Information("ChatServer login from {remoteEndPoint}", session.RemoteEndPoint); //uint sessionId; //if (!uint.TryParse(message.SessionId, out sessionId)) //{ // Logger.ForAccount(message.AccountId, "") // .Error("Invalid sessionId"); // session.SendAsync(new LoginAckMessage(2)); // return; //} var plr = GameServer.Instance.PlayerManager[message.AccountId]; if (plr == null) { Logger.ForAccount(message.AccountId, "") .Error("Login failed"); await session.SendAsync(new LoginAckMessage(3)); return; } if (plr.ChatSession != null) { Logger.ForAccount(session) .Error("Already online"); await session.SendAsync(new LoginAckMessage(4)); return; } session.GameSession = plr.Session; plr.ChatSession = session; Logger.ForAccount(session) .Information("Login success"); await session.SendAsync(new LoginAckMessage(0)); await session.SendAsync( new DenyListAckMessage(plr.DenyManager.Select(d => d.Map <Deny, DenyDto>()).ToArray())); if (plr.Club != null) { Club.LogOn(plr); await session.SendAsync(new ClanMemberListAckMessage(GameServer.Instance.PlayerManager .Where(x => (x.Club?.Id ?? 0) == plr.Club.Id).Select(x => x.Map <Player, PlayerInfoDto>()) .ToArray())); } await session.SendAsync(new ChatPlayerInfoAckMessage(plr.Map <Player, PlayerInfoDto>())); }
public async Task ChatLoginHandler(ChatSession session, LoginReqMessage message) { var plr = GameServer.Instance.PlayerManager[message.AccountId]; if (plr == null) { await session.SendAsync(new LoginAckMessage(3)); await session.CloseAsync(); return; } Logger.ForAccount(plr) .Information("ChatServer login from {remoteEndPoint}", session.RemoteEndPoint); var ip = session.RemoteEndPoint; var gameIp = plr.Session.RemoteEndPoint; if (!gameIp.Address.Equals(ip.Address)) { Logger.ForAccount(plr).Warning("Suspicious login"); await session.SendAsync(new LoginAckMessage(4)); await session.CloseAsync(); return; } if (Config.Instance.ResCheck) { if (plr.Session?.ValidRes == 0) { Logger.ForAccount(plr).Warning("Missing Reshash"); await plr.SendAsync(new LoginReguestAckMessage(GameLoginResult.WrongVersion)); await session.CloseAsync(); return; } if (plr.Session?.ValidRes == 1) { Logger.ForAccount(plr) .Warning("Invalid Reshash (1)"); if (plr.Account.SecurityLevel <= SecurityLevel.User) { await plr.SendAsync(new LoginReguestAckMessage(GameLoginResult.WrongVersion)); await session.CloseAsync(); return; } } if (plr.Session?.ValidRes == 2) { Logger.ForAccount(plr).Information("Valid Reshash"); } } if (plr.ChatSession != null) { Logger.ForAccount(plr).Warning("Already online"); await session.SendAsync(new LoginAckMessage(5)); await session.CloseAsync(); return; } session.GameSession = plr.Session; plr.ChatSession = session; Logger.ForAccount(plr) .Information("Login success"); try { await session.SendAsync(new LoginAckMessage(0)); try { await session.SendAsync(new DenyListAckMessage(plr.DenyManager.Select(d => d.Map <Deny, DenyDto>()).ToArray())); await session.SendAsync( new FriendListAckMessage(plr.FriendManager.Select(d => d.GetFriend()) .Where(x => x.State != 0).ToArray())); var playerInfoList = plr.FriendManager.Select(d => d.Map <Friend, PlayerInfoDto>()).ToList(); if (plr.Club?.Id > 0) { foreach (var newPlr in plr.Club.Players.Select(d => d.Value.Map <ClubPlayerInfo, PlayerInfoDto>())) { if (!playerInfoList.Contains(newPlr)) { playerInfoList.Add(newPlr); } } Club.LogOn(plr); } await session.SendAsync(new ChatPlayerInfoListAckMessage(playerInfoList.ToArray())); } finally { await session.SendAsync(new ChatPlayerInfoAckMessage(plr.Map <Player, PlayerInfoDto>())); } } catch (Exception ex) { session.Channel.Pipeline.FireExceptionCaught(ex); } }