From 1c387eff511f432e7cced75e9a6caa1c711f33e2 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 11 Aug 2019 12:13:04 +0300 Subject: [PATCH 1/4] Reset wired game stats on initialization --- src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java | 8 ++++++++ .../com/eu/habbo/habbohotel/games/wired/WiredGame.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java index 79dbc2aa..5a5ba98b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java @@ -80,6 +80,14 @@ public class GameTeam { this.members.clear(); } + public void resetScores() { + for (GamePlayer player : this.members) { + if (player == null) continue; + + player.reset(); + } + } + public THashSet getMembers() { return this.members; diff --git a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java index 21cd5469..80fe874d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java @@ -15,6 +15,10 @@ public class WiredGame extends Game { @Override public void initialise() { this.state = GameState.RUNNING; + + for (GameTeam team : this.teams.values()) { + team.resetScores(); + } } @Override From 79b02b80a6b4c49dbed409b3efa2645b9ab1b53f Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 11 Aug 2019 12:15:39 +0300 Subject: [PATCH 2/4] Fix guild admin removing --- .../messages/incoming/guilds/GuildRemoveAdminEvent.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveAdminEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveAdminEvent.java index 84bbb3fa..a26dbcc5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveAdminEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GuildRemoveAdminEvent.java @@ -22,19 +22,20 @@ public class GuildRemoveAdminEvent extends MessageHandler { int userId = this.packet.readInt(); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); - Emulator.getGameEnvironment().getGuildManager().removeAdmin(guild, userId); + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - Habbo habbo = room.getHabbo(userId); GuildRemovedAdminEvent removedAdminEvent = new GuildRemovedAdminEvent(guild, userId, habbo); Emulator.getPluginManager().fireEvent(removedAdminEvent); if (removedAdminEvent.isCancelled()) return; + Emulator.getGameEnvironment().getGuildManager().removeAdmin(guild, userId); + if (habbo != null) { habbo.getClient().sendResponse(new GuildInfoComposer(guild, this.client, false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild.getId(), userId))); - room.refreshRightsForHabbo(habbo); + if (room != null && habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom() == room) room.refreshRightsForHabbo(habbo); } GuildMember guildMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId); From 992a961814fd2d87d2c00f14d7cca602c4c87e18 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 11 Aug 2019 12:22:18 +0300 Subject: [PATCH 3/4] Add error to badge command if user is not found --- sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql | 1 + .../habbo/habbohotel/commands/BadgeCommand.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql diff --git a/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql b/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql new file mode 100644 index 00000000..14a12715 --- /dev/null +++ b/sqlupdates/2_2_0-RC-1_TO_2_2_0-RC-2.sql @@ -0,0 +1 @@ +INSERT INTO `emulator_texts`(`key`, `value`) VALUES ('commands.error.cmd_badge.unknown_user', 'Failed to find the given user.'); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java index 7e5e1208..eac670e7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/BadgeCommand.java @@ -4,6 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.users.HabboManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -38,11 +40,18 @@ public class BadgeCommand extends Command { return true; } else { + HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(params[1]); + + if (habboInfo == null) { + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_badge.unknown_user"), RoomChatMessageBubbles.ALERT); + return true; + } + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { boolean found; - try (PreparedStatement statement = connection.prepareStatement("SELECT `badge_code` FROM `users_badges` INNER JOIN `users` ON `users`.`id` = `user_id` WHERE `users`.`username` = ? AND `badge_code` = ? LIMIT 1")) { - statement.setString(1, params[1]); + try (PreparedStatement statement = connection.prepareStatement("SELECT `badge_code` FROM `users_badges` WHERE `user_id` = ? AND `badge_code` = ? LIMIT 1")) { + statement.setInt(1, habboInfo.getId()); statement.setString(2, params[2]); try (ResultSet set = statement.executeQuery()) { found = set.next(); @@ -53,8 +62,8 @@ public class BadgeCommand extends Command { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_badge.already_owns").replace("%user%", params[1]).replace("%badge%", params[2]), RoomChatMessageBubbles.ALERT); return true; } else { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges (`id`, `user_id`, `slot_id`, `badge_code`) VALUES (null, (SELECT `id` FROM `users` WHERE `username` = ? LIMIT 1), 0, ?)")) { - statement.setString(1, params[1]); + try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_badges (`id`, `user_id`, `slot_id`, `badge_code`) VALUES (null, ?, 0, ?)")) { + statement.setInt(1, habboInfo.getId()); statement.setString(2, params[2]); statement.execute(); } From 1bfc2452b7c60faf7d7382ce16caee1987881784 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sun, 11 Aug 2019 12:26:19 +0300 Subject: [PATCH 4/4] Fix NullPointerExceptions --- .../com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java | 2 +- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java index ab57f565..cb3bd3c8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java @@ -14,7 +14,7 @@ public class FreezeGameTeam extends GameTeam { @Override public void removeMember(GamePlayer gamePlayer) { - if (gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getHabboInfo().getCurrentRoom() == null) return; + if (gamePlayer == null || gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getHabboInfo().getCurrentRoom() == null) return; Game game = gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); Room room = gamePlayer.getHabbo().getRoomUnit().getRoom(); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index dcb66cdc..1450878a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -4165,6 +4165,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public void unIdle(Habbo habbo) { + if (habbo == null || habbo.getRoomUnit() == null) return; habbo.getRoomUnit().resetIdleTimer(); this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose()); WiredHandler.handle(WiredTriggerType.UNIDLES, habbo.getRoomUnit(), this, new Object[]{habbo});