public void Relay_LoginHandler(RelayServer server, RelaySession session, Message.Relay.CRequestLoginMessage message) { var ip = (IPEndPoint)((TcpTransport)session.Transport).Socket.RemoteEndPoint; Logger.Info() .Account(message.AccountId, "") .Message("Login from {0}", ip) .Write(); var plr = server.GameServer.PlayerManager[message.AccountId]; if (plr == null) { Logger.Error() .Account(message.AccountId, "") .Message("Login failed") .Write(); session.Send(new Message.Relay.SNotifyLoginResultMessage(1)); return; } if (plr.RelaySession != null) { Logger.Error() .Account(session) .Message("Already online") .Write(); session.Send(new Message.Relay.SNotifyLoginResultMessage(2)); return; } var gameIp = (IPEndPoint)((TcpTransport)plr.Session.Transport).Socket.RemoteEndPoint; if (!gameIp.Address.Equals(ip.Address)) { Logger.Error() .Account(message.AccountId, "") .Message("Suspicious login") .Write(); session.Send(new Message.Relay.SNotifyLoginResultMessage(3)); return; } if (plr.Room == null || plr.Room?.Id != message.RoomLocation.RoomId) { Logger.Error() .Account(message.AccountId, "") .Message("Suspicious login(Not in a room/Invalid room id)") .Write(); session.Send(new Message.Relay.SNotifyLoginResultMessage(4)); return; } session.GameSession = plr.Session; plr.RelaySession = session; Logger.Info().Account(session).Message("Login success").Write(); session.Send(new Message.Relay.SEnterLoginPlayerMessage(plr.RoomInfo.Slot, plr.Account.Id, plr.Account.Nickname)); foreach (var p in plr.Room.Players.Values.Where(p => p.RelaySession?.P2PGroup != null && p.Account.Id != plr.Account.Id)) { p.RelaySession.Send(new Message.Relay.SEnterLoginPlayerMessage(plr.RoomInfo.Slot, plr.Account.Id, plr.Account.Nickname)); session.Send(new Message.Relay.SEnterLoginPlayerMessage(p.RoomInfo.Slot, p.Account.Id, p.Account.Nickname)); } plr.Room.Group.Join(session.HostId, true); session.Send(new Message.Relay.SNotifyLoginResultMessage(0)); plr.RoomInfo.IsConnecting = false; plr.Room.OnPlayerJoined(new RoomPlayerEventArgs(plr)); }