From 48cef2ed70a4dfccedd284c078559ccc637c28bd Mon Sep 17 00:00:00 2001 From: Dank074 Date: Sun, 17 Jan 2021 01:50:17 -0600 Subject: [PATCH] added plugin event for getting user ip --- .../habbohotel/commands/UserInfoCommand.java | 2 +- .../habbohotel/modtool/ModToolManager.java | 8 +- .../com/eu/habbo/habbohotel/users/Habbo.java | 27 +++++- .../habbo/habbohotel/users/HabboManager.java | 2 +- .../incoming/handshake/SecureLoginEvent.java | 16 ++-- .../handshake/SecureLoginEvent_BACKUP.java | 89 ------------------- .../events/users/UserGetIPAddressEvent.java | 28 ++++++ .../plugin/events/users/UserLoginEvent.java | 5 +- 8 files changed, 68 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java index fdd621c8..b4a3ca78 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java @@ -45,7 +45,7 @@ public class UserInfoCommand extends Command { Emulator.getTexts().getValue("command.cmd_userinfo.online") + ": " + (onlineHabbo == null ? Emulator.getTexts().getValue("generic.no") : Emulator.getTexts().getValue("generic.yes")) + "\r" + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_MAIL, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.email") + ": " + habbo.getMail() + "\r") + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_register") + ": " + habbo.getIpRegister() + "\r") + - ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getClient().getChannel().remoteAddress().toString() + "\r") + + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getHabboInfo().getIpLogin() + "\r") + (onlineHabbo != null ? Emulator.getTexts().getValue("command.cmd_userinfo.achievement_score") + ": " + onlineHabbo.getHabboStats().achievementScore + "\r" : "")); ModToolBan ban = Emulator.getGameEnvironment().getModToolManager().checkForBan(habbo.getId()); diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java index c891286e..9dbd405a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -505,6 +505,7 @@ public class ModToolManager { return ban; } + @Deprecated public boolean hasIPBan(Channel habbo) { if (habbo == null) return false; @@ -512,9 +513,13 @@ public class ModToolManager { if (habbo.remoteAddress() == null || ((InetSocketAddress) habbo.remoteAddress()).getAddress() == null) return false; + return this.hasIPBan(((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress()); + } + + public boolean hasIPBan(String ipAddress) { boolean banned = false; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM bans WHERE ip = ? AND (type = 'ip' OR type = 'super') AND ban_expire > ? LIMIT 1")) { - statement.setString(1, ((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress()); + statement.setString(1, ipAddress); statement.setInt(2, Emulator.getIntUnixTimestamp()); try (ResultSet set = statement.executeQuery()) { @@ -525,7 +530,6 @@ public class ModToolManager { } catch (SQLException e) { LOGGER.error("Caught SQL exception", e); } - return banned; } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 923aeebe..dcc5a05e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -14,8 +14,10 @@ import com.eu.habbo.messages.outgoing.rooms.FloodCounterComposer; import com.eu.habbo.messages.outgoing.rooms.ForwardToRoomComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.*; +import com.eu.habbo.plugin.events.furniture.FurnitureBuildheightEvent; import com.eu.habbo.plugin.events.users.UserCreditsEvent; import com.eu.habbo.plugin.events.users.UserDisconnectEvent; +import com.eu.habbo.plugin.events.users.UserGetIPAddressEvent; import com.eu.habbo.plugin.events.users.UserPointsEvent; import gnu.trove.TIntCollection; import gnu.trove.map.hash.THashMap; @@ -114,11 +116,31 @@ public class Habbo implements Runnable { } - public void connect() { + public boolean connect() { + String ip = ""; + if (!Emulator.getConfig().getBoolean("networking.tcp.proxy") && this.client.getChannel().remoteAddress() != null) { SocketAddress address = this.client.getChannel().remoteAddress(); + ip = ((InetSocketAddress) address).getAddress().getHostAddress(); + } - if (address != null) this.habboInfo.setIpLogin(((InetSocketAddress) address).getAddress().getHostAddress()); + if (Emulator.getPluginManager().isRegistered(UserGetIPAddressEvent.class, true)) { + UserGetIPAddressEvent event = Emulator.getPluginManager().fireEvent(new UserGetIPAddressEvent(this, ip)); + if (event.hasChangedIP()) { + ip = event.getUpdatedIp(); + } + } + + if (!ip.isEmpty()) { + this.habboInfo.setIpLogin(ip); + } + + if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) { + return false; + } + + if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.habboInfo.getIpLogin())) { + return false; } this.habboInfo.setMachineID(this.client.getMachineId()); @@ -128,6 +150,7 @@ public class Habbo implements Runnable { Emulator.getGameEnvironment().getRoomManager().loadRoomsForHabbo(this); LOGGER.info("{} logged in from IP {}", this.habboInfo.getUsername(), this.habboInfo.getIpLogin()); + return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index 8975b888..e8bf5f3a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -205,7 +205,7 @@ public class HabboManager { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE ip_register = ? OR ip_current = ? AND id != ? ORDER BY id DESC LIMIT ?")) { statement.setString(1, habbo.getHabboInfo().getIpRegister()); - statement.setString(2, habbo.getClient().getChannel().remoteAddress().toString()); + statement.setString(2, habbo.getHabboInfo().getIpLogin()); statement.setInt(3, habbo.getHabboInfo().getId()); statement.setInt(4, limit); diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index bd63c760..33cc6b5f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -77,19 +77,13 @@ public class SecureLoginEvent extends MessageHandler { if (this.client.getHabbo() == null) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso); if (habbo != null) { - if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) { - Emulator.getGameServer().getGameClientManager().disposeClient(this.client); - return; - } - if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.client.getChannel())) { - Emulator.getGameServer().getGameClientManager().disposeClient(this.client); - return; - } - try { habbo.setClient(this.client); this.client.setHabbo(habbo); - this.client.getHabbo().connect(); + if(!this.client.getHabbo().connect()) { + Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + return; + } if (this.client.getHabbo().getHabboInfo() == null) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); @@ -191,7 +185,7 @@ public class SecureLoginEvent extends MessageHandler { } } - Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress())); + Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getHabbo().getHabboInfo().getIpLogin())); if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) { final Habbo finalHabbo = habbo; diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java deleted file mode 100644 index a74220f0..00000000 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.eu.habbo.messages.incoming.handshake; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.friends.FriendsComposer; -import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer; -import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer; -import com.eu.habbo.messages.outgoing.handshake.DebugConsoleComposer; -import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer; -import com.eu.habbo.messages.outgoing.handshake.SessionRightsComposer; -import com.eu.habbo.messages.outgoing.modtool.ModToolComposer; -import com.eu.habbo.messages.outgoing.navigator.*; -import com.eu.habbo.messages.outgoing.users.*; -import com.eu.habbo.plugin.events.users.UserLoginEvent; - -import java.util.ArrayList; - -public class SecureLoginEvent_BACKUP extends MessageHandler { - - - @Override - public void handle() throws Exception { - - if (!Emulator.isReady) - return; - - String sso = this.packet.readString(); - - if (this.client.getHabbo() == null) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso); - if (habbo != null) { - habbo.setClient(this.client); - this.client.setHabbo(habbo); - this.client.getHabbo().connect(); - //this.client.sendResponse(new DebugConsoleComposer()); - Emulator.getThreading().run(habbo); - Emulator.getGameEnvironment().getHabboManager().addHabbo(habbo); - - ArrayList messages = new ArrayList<>(); - - - messages.add(new SecureLoginOKComposer().compose()); - messages.add(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), 0).compose()); - messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose()); - messages.add(new UserClubComposer(this.client.getHabbo()).compose()); - messages.add(new DebugConsoleComposer(Emulator.debugging).compose()); - messages.add(new UserAchievementScoreComposer(this.client.getHabbo()).compose()); - messages.add(new NewUserIdentityComposer(habbo).compose()); - messages.add(new UserPerksComposer(habbo).compose()); - messages.add(new SessionRightsComposer().compose()); - messages.add(new FavoriteRoomsCountComposer(habbo).compose()); - //messages.add(new FriendsComposer(this.client.getHabbo()).compose()); - //messages.add(new NewUserIdentityComposer().compose()); - //messages.add(new UserDataComposer(this.client.getHabbo()).compose()); - //messages.add(new SessionRightsComposer().compose()); - //messages.add(new MinimailCountComposer().compose()); - //messages.add(new MessengerInitComposer(this.client.getHabbo()).compose()); - //messages.add(new FriendsComposer(this.client.getHabbo()).compose()); - - if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) { - messages.add(new ModToolComposer(this.client.getHabbo()).compose()); - } - - this.client.sendResponses(messages); - - //Hardcoded - this.client.sendResponse(new NewNavigatorMetaDataComposer()); - this.client.sendResponse(new NewNavigatorLiftedRoomsComposer()); - this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer()); - this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches())); - this.client.sendResponse(new NewNavigatorEventCategoriesComposer()); - //this.client.sendResponse(new HotelViewComposer()); - //this.client.sendResponse(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), this.client.getHabbo().getHabboInfo().getHomeRoom())); - //this.client.sendResponse(new UserEffectsListComposer()); - - - Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress())); - - } else { - this.client.sendResponse(new GenericAlertComposer("Can't connect *sadpanda*")); - - this.client.getChannel().close(); - } - } - } -} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java new file mode 100644 index 00000000..c77b3639 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java @@ -0,0 +1,28 @@ +package com.eu.habbo.plugin.events.users; + +import com.eu.habbo.habbohotel.users.Habbo; + +public class UserGetIPAddressEvent extends UserEvent{ + public final String oldIp; + + private String updatedIp; + private boolean changedIP = false; + + public UserGetIPAddressEvent(Habbo habbo, String ip) { + super(habbo); + this.oldIp = ip; + } + + public void setUpdatedIp(String updatedIp) { + this.updatedIp = updatedIp; + this.changedIP = true; + } + + public boolean hasChangedIP() { + return changedIP; + } + + public String getUpdatedIp() { + return updatedIp; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java index 15268bcb..d864a5fb 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java @@ -6,10 +6,9 @@ import java.net.SocketAddress; public class UserLoginEvent extends UserEvent { - public final SocketAddress ip; + public final String ip; - - public UserLoginEvent(Habbo habbo, SocketAddress ip) { + public UserLoginEvent(Habbo habbo, String ip) { super(habbo); this.ip = ip;