From 1d5391ff1c4ac7d358fbbfc6677ae7d0820096b7 Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 12 Oct 2020 11:18:52 +0200 Subject: [PATCH] Wired fixes. Closes #772 #786 #804 #816 #802 #791 #727 #726 #721 #705 (pets) #701 #707 #710 #607 #604 #411 --- .../com/eu/habbo/habbohotel/bots/Bot.java | 19 +++- .../eu/habbo/habbohotel/bots/ButlerBot.java | 19 +++- .../com/eu/habbo/habbohotel/games/Game.java | 4 +- .../eu/habbo/habbohotel/games/GamePlayer.java | 15 ++- .../games/battlebanzai/BattleBanzaiGame.java | 4 +- .../habbohotel/games/freeze/FreezeGame.java | 4 +- .../InteractionPressurePlate.java | 3 +- .../interactions/InteractionWiredEffect.java | 3 +- .../WiredConditionFurniHaveFurni.java | 47 ++++------ .../WiredConditionFurniHaveHabbo.java | 39 ++------ .../WiredConditionFurniTypeMatch.java | 16 ++-- .../WiredConditionNotFurniHaveFurni.java | 32 ++++--- .../WiredConditionNotFurniHaveHabbo.java | 39 ++------ .../WiredConditionNotFurniTypeMatch.java | 11 +-- .../conditions/WiredConditionNotInTeam.java | 7 +- .../WiredConditionNotTriggerOnFurni.java | 8 +- .../WiredConditionTriggerOnFurni.java | 13 +-- .../wired/effects/WiredEffectBotClothes.java | 40 +++++--- .../effects/WiredEffectBotFollowHabbo.java | 22 ++++- .../effects/WiredEffectBotGiveHandItem.java | 45 ++++++--- .../wired/effects/WiredEffectBotTalk.java | 53 +++++++---- .../effects/WiredEffectBotTalkToHabbo.java | 45 ++++++--- .../wired/effects/WiredEffectBotTeleport.java | 39 ++++++-- .../effects/WiredEffectBotWalkToFurni.java | 75 ++++++++------- .../WiredEffectChangeFurniDirection.java | 82 +++++++++++----- .../wired/effects/WiredEffectGiveScore.java | 30 ++++-- .../effects/WiredEffectGiveScoreToTeam.java | 34 ++++++- .../wired/effects/WiredEffectJoinTeam.java | 40 +++++--- .../wired/effects/WiredEffectKickHabbo.java | 13 ++- .../wired/effects/WiredEffectLeaveTeam.java | 13 ++- .../wired/effects/WiredEffectMatchFurni.java | 60 ++++++++---- .../effects/WiredEffectMoveFurniAway.java | 67 +++++++------ .../effects/WiredEffectMoveFurniTowards.java | 36 +++++-- .../effects/WiredEffectMoveRotateFurni.java | 5 +- .../wired/effects/WiredEffectTeleport.java | 34 +++++-- .../wired/effects/WiredEffectToggleFurni.java | 94 +++++++++++++++---- .../effects/WiredEffectToggleRandom.java | 92 ++++++++++++++---- .../effects/WiredEffectTriggerStacks.java | 33 +++++-- .../wired/effects/WiredEffectWhisper.java | 28 ++++-- .../interactions/wired/extra/WiredBlob.java | 2 +- .../triggers/WiredTriggerBotReachedFurni.java | 16 +--- .../triggers/WiredTriggerBotReachedHabbo.java | 11 +-- .../WiredTriggerHabboSaysKeyword.java | 13 +-- .../com/eu/habbo/habbohotel/rooms/Room.java | 22 ++++- .../eu/habbo/habbohotel/rooms/RoomUnit.java | 1 + .../habbo/habbohotel/wired/WiredHandler.java | 2 +- .../wired/WiredEffectSaveDataEvent.java | 10 +- .../incoming/wired/WiredSaveException.java | 15 +++ .../rooms/users/RoomUnitOnRollerComposer.java | 6 +- .../threading/runnables/BotFollowHabbo.java | 14 +++ .../threading/runnables/RoomUnitTeleport.java | 3 +- .../runnables/RoomUnitWalkToLocation.java | 3 +- .../teleport/TeleportActionFive.java | 11 ++- .../teleport/TeleportActionFour.java | 4 + 54 files changed, 919 insertions(+), 477 deletions(-) create mode 100644 src/main/java/com/eu/habbo/messages/incoming/wired/WiredSaveException.java diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java index 8cedc5ff..db59fdf2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java @@ -173,11 +173,11 @@ public class Bot implements Runnable { int timeOut = Emulator.getRandom().nextInt(20) * 2; this.roomUnit.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp()); } - } else { + }/* else { for (RoomTile t : this.room.getLayout().getTilesAround(this.room.getLayout().getTile(this.getRoomUnit().getX(), this.getRoomUnit().getY()))) { WiredHandler.handle(WiredTriggerType.BOT_REACHED_STF, this.roomUnit, this.room, this.room.getItemsAt(t).toArray()); } - } + }*/ } if (!this.chatLines.isEmpty() && this.chatTimeOut <= Emulator.getIntUnixTimestamp() && this.chatAuto) { @@ -188,12 +188,16 @@ public class Bot implements Runnable { this.lastChatIndex = 0; } - this.talk(this.chatLines.get(this.lastChatIndex) + String message = this.chatLines.get(this.lastChatIndex) .replace("%owner%", this.room.getOwnerName()) .replace("%item_count%", this.room.itemCount() + "") .replace("%name%", this.name) .replace("%roomname%", this.room.getName()) - .replace("%user_count%", this.room.getUserCount() + "")); + .replace("%user_count%", this.room.getUserCount() + ""); + + if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{ message })) { + this.talk(message); + } this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay; } @@ -247,7 +251,12 @@ public class Bot implements Runnable { room.giveEffect(this.roomUnit, this.effect, -1); } - this.talk(PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)]); + if(PLACEMENT_MESSAGES.length > 0) { + String message = PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)]; + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{message})) { + this.talk(message); + } + } } public void onPickUp(Habbo habbo, Room room) { diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java index d776bee9..89a66272 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -3,6 +3,8 @@ package com.eu.habbo.habbohotel.bots; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.plugin.events.bots.BotServerItemEvent; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit; @@ -78,7 +80,14 @@ public class ButlerBot extends Bot { tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0)); - tasks.add(() -> b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()))); + tasks.add(() -> { + if(this.getRoom() != null) { + String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) { + b.talk(msg); + } + } + }); List failedReached = new ArrayList(); failedReached.add(() -> { @@ -98,7 +107,13 @@ public class ButlerBot extends Bot { } } else { this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId); - this.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername())); + + if(this.getRoom() != null) { + String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) { + this.talk(msg); + } + } } return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/Game.java b/src/main/java/com/eu/habbo/habbohotel/games/Game.java index 16783eb7..e07bd287 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/Game.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/Game.java @@ -95,7 +95,9 @@ public abstract class Game implements Runnable { if (team != null && team.isMember(habbo)) { if (habbo.getHabboInfo().getGamePlayer() != null) { team.removeMember(habbo.getHabboInfo().getGamePlayer()); - habbo.getHabboInfo().getGamePlayer().reset(); + if (habbo.getHabboInfo().getGamePlayer() != null) { + habbo.getHabboInfo().getGamePlayer().reset(); + } } habbo.getHabboInfo().setCurrentGame(null); diff --git a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java index 1950c917..bfd82a59 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java @@ -13,6 +13,7 @@ public class GamePlayer { private int score; + private int wiredScore; public GamePlayer(Habbo habbo, GameTeamColors teamColor) { @@ -23,15 +24,23 @@ public class GamePlayer { public void reset() { this.score = 0; + this.wiredScore = 0; } - public synchronized void addScore(int amount) { + addScore(amount, false); + } + + public synchronized void addScore(int amount, boolean isWired) { if (habbo.getHabboInfo().getGamePlayer() != null && this.habbo.getHabboInfo().getCurrentGame() != null && this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo) != null) { this.score += amount; if (this.score < 0) this.score = 0; + if(isWired && this.score > 0) { + this.wiredScore += amount; + } + WiredHandler.handle(WiredTriggerType.SCORE_ACHIEVED, this.habbo.getRoomUnit(), this.habbo.getHabboInfo().getCurrentRoom(), new Object[]{this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo).getTotalScore(), amount}); } } @@ -49,4 +58,8 @@ public class GamePlayer { public int getScore() { return this.score; } + + public int getScoreAchievementValue() { + return this.score - this.wiredScore; + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java index 07b83048..b2ee6dcf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java @@ -178,7 +178,7 @@ public class BattleBanzaiGame extends Game { for (GameTeam team : this.teams.values()) { if (!singleTeamGame) { for (GamePlayer player : team.getMembers()) { - if (player.getScore() > 0) { + if (player.getScoreAchievementValue() > 0) { AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallPlayer")); } } @@ -192,7 +192,7 @@ public class BattleBanzaiGame extends Game { if (winningTeam != null) { if (!singleTeamGame) { for (GamePlayer player : winningTeam.getMembers()) { - if (player.getScore() > 0) { + if (player.getScoreAchievementValue() > 0) { this.room.sendComposer(new RoomUserActionComposer(player.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose()); AchievementManager.progressAchievement(player.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallWinner")); } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java index eb625350..642564d1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java @@ -287,9 +287,9 @@ public class FreezeGame extends Game { players.addAll(team.getMembers()); for (GamePlayer p : players) { - if (p.getScore() > 0) { + if (p.getScoreAchievementValue() > 0) { if (team.equals(winningTeam)) { - AchievementManager.progressAchievement(p.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FreezeWinner"), p.getScore()); + AchievementManager.progressAchievement(p.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FreezeWinner"), p.getScoreAchievementValue()); this.room.sendComposer(new RoomUserActionComposer(p.getHabbo().getRoomUnit(), RoomUserAction.WAVE).compose()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java index 0eee202b..ed6cb853 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java @@ -8,6 +8,7 @@ import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.rooms.items.ItemStateComposer; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; @@ -99,7 +100,7 @@ public class InteractionPressurePlate extends HabboItem { } this.setExtradata(occupied ? "1" : "0"); - room.updateItem(this); + room.updateItemState(this); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java index a6ae8ab4..373f1584 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer; import java.sql.ResultSet; @@ -57,7 +58,7 @@ public abstract class InteractionWiredEffect extends InteractionWired { } - public abstract boolean saveData(ClientMessage packet, GameClient gameClient); + public abstract boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException; public int getDelay() { return this.delay; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java index 4aa50beb..d83921c4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; @@ -35,39 +36,23 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { this.refresh(); - boolean foundSomething = false; - for (HabboItem item : this.items) { - boolean found = false; + if(this.items.isEmpty()) + return true; - THashSet stackedItems = room.getItemsAt(room.getLayout().getTile(item.getX(), item.getY())); - - if (stackedItems == null) - continue; - - if (stackedItems.isEmpty() && this.all) - return false; - - for (HabboItem i : stackedItems) { - if (i == item) - continue; - - if (i.getZ() >= item.getZ()) { - found = true; - foundSomething = true; - } - } - - if (this.all) { - if (!found) - return false; - } else { - if (found) - return true; - } + if(this.all) { + return this.items.stream().allMatch(item -> { + double minZ = item.getZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + }); + } + else { + return this.items.stream().anyMatch(item -> { + double minZ = item.getZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + }); } - - return this.items.isEmpty() || foundSomething; - } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java index 4895462e..3f9033f3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java @@ -51,43 +51,16 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { if (this.items.isEmpty()) return true; - THashMap> tiles = new THashMap<>(); - for (HabboItem item : this.items) { - tiles.put(item, room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); - } - Collection habbos = room.getHabbos(); Collection bots = room.getCurrentBots().valueCollection(); Collection pets = room.getCurrentPets().valueCollection(); - for (Map.Entry> set : tiles.entrySet()) { - boolean found = false; - for (Habbo habbo : habbos) { - if (set.getValue().contains(habbo.getRoomUnit().getCurrentLocation())) { - found = true; - } - } - - if (!found) { - for (Bot bot : bots) { - if (set.getValue().contains(bot.getRoomUnit().getCurrentLocation())) { - found = true; - } - } - } - - if (!found) { - for (Pet pet : pets) { - if (set.getValue().contains(pet.getRoomUnit().getCurrentLocation())) { - found = true; - } - } - } - - if (!found) return false; - } - - return true; + return this.items.stream().allMatch(item -> { + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || + bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || + pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())); + }); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java index d2a2f573..798054d0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java @@ -37,21 +37,19 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { this.refresh(); + if(items.isEmpty()) + return false; + if (stuff != null) { if (stuff.length >= 1) { if (stuff[0] instanceof HabboItem) { - HabboItem item = (HabboItem) stuff[0]; - - for (HabboItem i : this.items) { - if (i.getBaseItem().getId() == item.getBaseItem().getId()) - return true; - } - - return false; + HabboItem triggeringItem = (HabboItem)stuff[0]; + return this.items.stream().anyMatch(item -> item == triggeringItem); } } } - return true; + + return false; } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java index 7e666b33..71fbc0b6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionOperator; @@ -39,19 +40,20 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { if (this.items.isEmpty()) return true; - for (HabboItem item : this.items) { - THashSet things = room.getItemsAt(item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); - things.removeAll(this.items); - if (!things.isEmpty()) { - if (this.all) - return false; - else - continue; - } - return true; + if(this.all) { + return this.items.stream().allMatch(item -> { + double minZ = item.getZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + }); + } + else { + return this.items.stream().anyMatch(item -> { + double minZ = item.getZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + }); } - - return false; } @Override @@ -79,7 +81,7 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { String[] items = data[1].split(";"); for (String s : items) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + HabboItem item = room.getHabboItem(Integer.parseInt(s)); if (item != null) this.items.add(item); @@ -169,6 +171,8 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { @Override public WiredConditionOperator operator() { - return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR; + // NICE TRY BUT THAT'S NOT HOW IT WORKS. NOTHING IN HABBO IS AN "OR" CONDITION - EVERY CONDITION MUST BE SUCCESS FOR THE STACK TO EXECUTE, BUT LET'S LEAVE IT IMPLEMENTED FOR PLUGINS TO USE. + //return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR; + return WiredConditionOperator.AND; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java index abc5c559..b85217aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java @@ -51,43 +51,16 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { if (this.items.isEmpty()) return true; - THashMap> tiles = new THashMap<>(); - for (HabboItem item : this.items) { - tiles.put(item, room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); - } - Collection habbos = room.getHabbos(); Collection bots = room.getCurrentBots().valueCollection(); Collection pets = room.getCurrentPets().valueCollection(); - for (Map.Entry> set : tiles.entrySet()) { - if (!habbos.isEmpty()) { - for (Habbo habbo : habbos) { - if (set.getValue().contains(habbo.getRoomUnit().getCurrentLocation())) { - return false; - } - } - } - - if (!bots.isEmpty()) { - for (Bot bot : bots) { - if (set.getValue().contains(bot.getRoomUnit().getCurrentLocation())) { - return false; - } - } - } - - if (!pets.isEmpty()) { - for (Pet pet : pets) { - if (set.getValue().contains(pet.getRoomUnit().getCurrentLocation())) { - return false; - } - } - } - - } - - return true; + return this.items.stream().noneMatch(item -> { + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || + bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || + pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())); + }); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java index 754aed77..d9b6d466 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java @@ -32,15 +32,14 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { this.refresh(); + if(items.isEmpty()) + return true; + if (stuff != null) { if (stuff.length >= 1) { if (stuff[0] instanceof HabboItem) { - HabboItem item = (HabboItem) stuff[0]; - - for (HabboItem i : this.items) { - if (i.getBaseItem().getId() == item.getBaseItem().getId()) - return false; - } + HabboItem triggeringItem = (HabboItem)stuff[0]; + return this.items.stream().noneMatch(item -> item == triggeringItem); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java index fba63af0..704921fc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java @@ -31,13 +31,10 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { - if (habbo.getHabboInfo().getGamePlayer() != null) { - return !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); - } - return true; // user is not part of any team + return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team } - return false; + return true; } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java index 65dc97f1..cf31f254 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java @@ -37,12 +37,8 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { if (this.items.isEmpty()) return true; - for (HabboItem item : this.items) { - if (RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()).contains(roomUnit.getX(), roomUnit.getY())) - return false; - } - - return true; + THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); + return this.items.stream().noneMatch(itemsAtUser::contains); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java index 9d373e56..56d54325 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionOperator; @@ -37,14 +38,10 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { this.refresh(); if (this.items.isEmpty()) - return true; + return false; - for (HabboItem item : this.items) { - if (RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()).contains(roomUnit.getX(), roomUnit.getY())) - return true; - } - - return false; + THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); + return this.items.stream().anyMatch(itemsAtUser::contains); } @Override @@ -149,6 +146,6 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { @Override public WiredConditionOperator operator() { - return WiredConditionOperator.OR; + return WiredConditionOperator.AND; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java index ec22bf63..51fee02b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; @@ -9,10 +10,12 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import java.util.regex.Pattern; public class WiredEffectBotClothes extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.BOT_CLOTHES; @@ -44,18 +47,27 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - - String[] data = packet.readString().split(((char) 9) + ""); - - if (data.length == 2) { - this.botName = data[0]; - this.botLook = data[1]; - } - + String dataString = packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + String splitBy = "\t"; + if(!dataString.contains(splitBy)) + throw new WiredSaveException("Malformed data string"); + + String[] data = dataString.split(Pattern.quote(splitBy)); + + if (data.length != 2) + throw new WiredSaveException("Malformed data string. Invalid data length"); + + this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.botLook = data[1]; + this.setDelay(delay); return true; } @@ -69,13 +81,11 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { List bots = room.getBots(this.botName); - if (bots.size() != 1) { - return false; + if (bots.size() == 1) { + Bot bot = bots.get(0); + bot.setFigure(this.botLook); } - Bot bot = bots.get(0); - bot.setFigure(this.botLook); - return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java index 928068af..34c1352c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; @@ -11,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; @@ -67,13 +69,25 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); + int mode = packet.readInt(); - this.mode = packet.readInt(); - this.botName = packet.readString().replace("\t", ""); + if(mode != 0 && mode != 1) + throw new WiredSaveException("Mode is invalid"); + + String botName = packet.readString().replace("\t", ""); + botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.botName = botName; + this.mode = mode; + this.setDelay(delay); + return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index 94173cdd..e69f2000 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -7,13 +7,17 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; -import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; @@ -70,13 +74,25 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.itemId = packet.readInt(); - this.botName = packet.readString(); + int itemId = packet.readInt(); + + if(itemId < 0) + itemId = 0; + + String botName = packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.itemId = itemId; + this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.setDelay(delay); + return true; } @@ -94,15 +110,22 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { Bot bot = bots.get(0); List tasks = new ArrayList<>(); - tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId)); + tasks.add(new RoomUnitGiveHanditem(roomUnit, room, this.itemId)); tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); + tasks.add(() -> { + if(roomUnit.getRoom() != null && roomUnit.getRoom().getId() == room.getId() && roomUnit.getCurrentLocation().distance(bot.getRoomUnit().getCurrentLocation()) < 2) { + WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{}); + } + }); + + RoomTile tile = bot.getRoomUnit().getClosestAdjacentTile(roomUnit.getX(), roomUnit.getY(), true); + + if(tile != null) { + bot.getRoomUnit().setGoalLocation(tile); + } Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); - - List failedReach = new ArrayList<>(); - failedReach.add(() -> tasks.forEach(Runnable::run)); - - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach)); + Emulator.getThreading().run(new RoomUnitWalkToLocation(bot.getRoomUnit(), tile, room, tasks, tasks)); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java index 8297cde1..91cb6f37 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java @@ -9,12 +9,16 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import java.util.regex.Pattern; public class WiredEffectBotTalk extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.BOT_TALK; @@ -48,22 +52,35 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.mode = packet.readInt(); + int mode = packet.readInt(); - String[] data = packet.readString().split(((char) 9) + ""); + if(mode != 0 && mode != 1) + throw new WiredSaveException("Mode is invalid"); - if (data.length == 2) { - this.botName = data[0]; + String dataString = packet.readString(); - if (data[1].length() > 64) return false; - this.message = data[1]; - } + String splitBy = "\t"; + if(!dataString.contains(splitBy)) + throw new WiredSaveException("Malformed data string"); + + String[] data = dataString.split(Pattern.quote(splitBy)); + + if (data.length != 2) + throw new WiredSaveException("Malformed data string. Invalid data length"); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.setDelay(delay); + this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.mode = mode; return true; } @@ -88,16 +105,16 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { List bots = room.getBots(this.botName); - if (bots.size() != 1) { - return false; - } + if (bots.size() == 1) { + Bot bot = bots.get(0); - Bot bot = bots.get(0); - - if (this.mode == 1) { - bot.shout(message); - } else { - bot.talk(message); + if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) { + if (this.mode == 1) { + bot.shout(message); + } else { + bot.talk(message); + } + } } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java index 97badb10..b475ec29 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java @@ -10,14 +10,18 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.BOT_TALK_TO_AVATAR; @@ -69,21 +73,34 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.mode = packet.readInt(); - String[] data = packet.readString().split("" + ((char) 9)); + int mode = packet.readInt(); - if (data.length == 2) { - this.botName = data[0]; + if(mode != 0 && mode != 1) + throw new WiredSaveException("Mode is invalid"); - if (data[1].length() > 64) return false; - this.message = data[1]; - } + String dataString = packet.readString(); + String splitBy = "\t"; + if(!dataString.contains(splitBy)) + throw new WiredSaveException("Malformed data string"); + + String[] data = dataString.split(Pattern.quote(splitBy)); + + if (data.length != 2) + throw new WiredSaveException("Malformed data string. Invalid data length"); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.mode = mode; + this.setDelay(delay); return true; } @@ -112,10 +129,12 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { Bot bot = bots.get(0); - if (this.mode == 1) { - bot.whisper(m, habbo); - } else { - bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); + if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ m })) { + if (this.mode == 1) { + bot.whisper(m, habbo); + } else { + bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); + } } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java index 9fe3e8ef..c057f63e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; import com.eu.habbo.threading.runnables.RoomUnitTeleport; import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer; @@ -21,6 +22,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -77,6 +79,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } } + Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); } @@ -110,20 +113,36 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.botName = packet.readString(); + String botName = packet.readString(); + int itemsCount = packet.readInt(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java index 3b5543b7..0e34aea6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java @@ -12,26 +12,28 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.BOT_MOVE; - private THashSet items; + private List items; private String botName = ""; public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); + this.items = new ArrayList<>(); } public WiredEffectBotWalkToFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + this.items = new ArrayList<>(); } @Override @@ -64,20 +66,36 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.botName = packet.readString(); + String botName = packet.readString(); + int itemsCount = packet.readInt(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.setDelay(delay); return true; } @@ -92,33 +110,18 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { List bots = room.getBots(this.botName); if (this.items.isEmpty() || bots.size() != 1) { - return false; + return true; } Bot bot = bots.get(0); - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } + this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); + // wtf was that if (this.items.size() > 0) { - int i = Emulator.getRandom().nextInt(this.items.size()) + 1; - int j = 1; - for (HabboItem item : this.items) { - if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) { - if (i == j) { - bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY())); - break; - } else { - j++; - } - } + HabboItem item = this.items.get(Emulator.getRandom().nextInt(this.items.size())); + + if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) { + bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY())); } } @@ -142,7 +145,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); + this.items = new ArrayList<>(); String[] wiredData = set.getString("wired_data").split("\t"); if (wiredData.length > 1) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index 308c1bbf..d7a6d3d0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -5,13 +5,13 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; @@ -57,25 +57,29 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { } if (this.items.isEmpty()) return false; + for (Map.Entry entry : this.items.entrySet()) { - RoomUserRotation currentRotation = entry.getValue(); RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue()); int count = 1; - while ((targetTile == null || !targetTile.getAllowStack() || targetTile.state == RoomTileState.INVALID || targetTile.state == RoomTileState.BLOCKED) && count < 8) { + while ((targetTile == null || !targetTile.getAllowStack() || targetTile.state == RoomTileState.INVALID) && count < 8) { entry.setValue(this.nextRotation(entry.getValue())); targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue()); count++; } + } + + for (Map.Entry entry : this.items.entrySet()) { + RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getValue().getValue()); if (targetTile != null && targetTile.state != RoomTileState.INVALID) { boolean hasRoomUnits = false; - for (RoomUnit _roomUnit : room.getHabbosAndBotsAt(targetTile)) { + for (RoomUnit _roomUnit : room.getRoomUnitsAt(targetTile)) { hasRoomUnits = true; Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()})); } - if (!hasRoomUnits) { + if (!hasRoomUnits && targetTile.getAllowStack() && targetTile.state != RoomTileState.INVALID) { THashSet refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation()); room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, targetTile, targetTile.getStackHeight() - entry.getKey().getZ(), room).compose()); room.getLayout().getTilesAt(room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()), entry.getKey().getBaseItem().getWidth(), entry.getKey().getBaseItem().getLength(), entry.getKey().getRotation()); @@ -89,7 +93,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder data = new StringBuilder(this.getDelay() + this.startRotation.getValue() + "\t" + this.rotateAction + "\t" + this.items.size()); + StringBuilder data = new StringBuilder(this.getDelay() + "\t" + this.startRotation.getValue() + "\t" + this.rotateAction + "\t" + this.items.size()); for (Map.Entry entry : this.items.entrySet()) { data.append("\t").append(entry.getKey().getId()).append(":").append(entry.getValue().getValue()); @@ -102,17 +106,15 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { public void loadWiredData(ResultSet set, Room room) throws SQLException { String[] data = set.getString("wired_data").split("\t"); - if (data.length >= 1) { + if (data.length >= 4) { this.setDelay(Integer.parseInt(data[0])); - } - if (data.length >= 3) { - this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[0])); - this.rotateAction = Integer.parseInt(data[1]); + this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1])); + this.rotateAction = Integer.parseInt(data[2]); - int itemCount = Integer.parseInt(data[2]); + int itemCount = Integer.parseInt(data[3]); if (itemCount > 0) { - for (int i = 3; i < data.length; i++) { + for (int i = 4; i < data.length; i++) { String[] subData = data[i].split(":"); if (subData.length == 2) { @@ -161,25 +163,53 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.startRotation = RoomUserRotation.fromValue(packet.readInt()); - this.rotateAction = packet.readInt(); + int startRotationInt = packet.readInt(); + + if(startRotationInt < 0 || startRotationInt > 7 || (startRotationInt % 2) != 0) { + throw new WiredSaveException("Direction is invalid"); + } + + RoomUserRotation startRotation = RoomUserRotation.fromValue(startRotationInt); + + int rotateAction = packet.readInt(); + + if(rotateAction < 0 || rotateAction > 6) { + throw new WiredSaveException("Blocked action is invalid"); + } + packet.readString(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); + + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); + } + + THashMap newItems = new THashMap<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.put(it, startRotation); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); this.items.clear(); + this.items.putAll(newItems); + this.startRotation = startRotation; + this.rotateAction = rotateAction; + this.setDelay(delay); - for (int i = 0; i < count; i++) { - HabboItem item = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(packet.readInt()); - - if (item != null) { - this.items.put(item, this.startRotation); - } - } - this.setDelay(packet.readInt()); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java index 91475710..58b4c87d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.items.Item; @@ -11,6 +12,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.iterator.TObjectIntIterator; import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; @@ -61,7 +63,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { if (iterator.value() < this.count) { iterator.setValue(iterator.value() + 1); - habbo.getHabboInfo().getGamePlayer().addScore(this.score); + habbo.getHabboInfo().getGamePlayer().addScore(this.score, true); return true; } @@ -74,7 +76,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { this.data.put(new AbstractMap.SimpleEntry<>(game.getStartTime(), habbo.getHabboInfo().getId()), 1); if (habbo.getHabboInfo().getGamePlayer() != null) { - habbo.getHabboInfo().getGamePlayer().addScore(this.score); + habbo.getHabboInfo().getGamePlayer().addScore(this.score, true); } return true; @@ -147,14 +149,30 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.score = packet.readInt(); - this.count = packet.readInt(); + int score = packet.readInt(); + + if(score < 1 || score > 100) + throw new WiredSaveException("Score is invalid"); + + int timesPerGame = packet.readInt(); + + if(timesPerGame < 1 || timesPerGame > 10) + throw new WiredSaveException("Times per game is invalid"); + packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.score = score; + this.count = timesPerGame; + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java index 738fc508..74387b2a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeam; @@ -12,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.map.hash.TIntIntHashMap; import java.sql.ResultSet; @@ -115,15 +117,37 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.points = packet.readInt(); - this.count = packet.readInt(); - this.teamColor = GameTeamColors.values()[packet.readInt()]; + int points = packet.readInt(); + + if(points < 1 || points > 100) + throw new WiredSaveException("Points is invalid"); + + int timesPerGame = packet.readInt(); + + if(timesPerGame < 1 || timesPerGame > 10) + throw new WiredSaveException("Times per game is invalid"); + + int team = packet.readInt(); + + if(team < 1 || team > 4) + throw new WiredSaveException("Team is invalid"); + packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.points = points; + this.count = timesPerGame; + this.teamColor = GameTeamColors.values()[team]; + this.setDelay(delay); + return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java index 3285865a..48664fc6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java @@ -1,6 +1,8 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.items.Item; @@ -12,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; @@ -37,16 +40,19 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { - if (habbo.getHabboInfo().getGamePlayer() == null) { - WiredGame game = (WiredGame) room.getGame(WiredGame.class); + WiredGame game = (WiredGame) room.getGameOrCreate(WiredGame.class); - if (game == null) { - game = new WiredGame(room); - room.addGame(game); - } - - return game.addHabbo(habbo, this.teamColor); + if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != this.teamColor))) { + // remove from current game + Game currentGame = room.getGame(habbo.getHabboInfo().getCurrentGame()); + currentGame.removeHabbo(habbo); } + + if(habbo.getHabboInfo().getGamePlayer() == null) { + game.addHabbo(habbo, this.teamColor); + } + + return true; } return false; @@ -116,12 +122,22 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { + packet.readInt(); + int team = packet.readInt(); + + if(team < 1 || team > 4) + throw new WiredSaveException("Team is invalid"); + packet.readInt(); - this.teamColor = GameTeamColors.values()[packet.readInt()]; - int unknownInt = packet.readInt(); packet.readString(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.teamColor = GameTeamColors.values()[packet.readInt()]; + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java index 72897ebf..d2e0bfcf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; import com.eu.habbo.threading.runnables.RoomUnitKick; import gnu.trove.procedure.TObjectProcedure; @@ -135,11 +136,17 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.message = packet.readString(); + String message = packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java index 248adcda..10668834 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.wired.WiredGame; @@ -12,6 +13,7 @@ import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; @@ -39,7 +41,7 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { Game game = room.getGame(habbo.getHabboInfo().getCurrentGame()); if (game == null) { - game = room.getGame(WiredGame.class); + game = room.getGameOrCreate(WiredGame.class); } if (game != null) { @@ -105,11 +107,16 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); packet.readInt(); - this.setDelay(packet.readInt()); + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.setDelay(delay); return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java index 251bc2a5..efdc3366 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java @@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import gnu.trove.set.hash.THashSet; import org.slf4j.Logger; @@ -22,6 +23,9 @@ import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; public class WiredEffectMatchFurni extends InteractionWiredEffect { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMatchFurni.class); @@ -57,6 +61,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) { if (!setting.state.equals(" ")) { item.setExtradata(setting.state); + room.updateItemState(item); tilesToUpdate.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); } } @@ -180,17 +185,17 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { public void loadWiredData(ResultSet set, Room room) throws SQLException { String[] data = set.getString("wired_data").split(":"); - int itemCount = Integer.valueOf(data[0]); + int itemCount = Integer.parseInt(data[0]); - String[] items = data[1].split(";"); + String[] items = data[1].split(Pattern.quote(";")); for (int i = 0; i < items.length; i++) { try { - String[] stuff = items[i].split("-"); + String[] stuff = items[i].split(Pattern.quote("-")); if (stuff.length >= 5) { - this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4]))); + this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4]))); } } catch (Exception e) { @@ -201,7 +206,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { this.state = data[2].equals("1"); this.direction = data[3].equals("1"); this.position = data[4].equals("1"); - this.setDelay(Integer.valueOf(data[5])); + this.setDelay(Integer.parseInt(data[5])); } @Override @@ -243,33 +248,48 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.state = packet.readInt() == 1; - this.direction = packet.readInt() == 1; - this.position = packet.readInt() == 1; + boolean setState = packet.readInt() == 1; + boolean setDirection = packet.readInt() == 1; + boolean setPosition = packet.readInt() == 1; packet.readString(); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); if (room == null) - return true; + throw new WiredSaveException("Trying to save wired in unloaded room"); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); - this.settings.clear(); - - for (int i = 0; i < count; i++) { - int itemId = packet.readInt(); - HabboItem item = room.getHabboItem(itemId); - - if (item != null) - this.settings.add(new WiredMatchFurniSetting(item.getId(), this.checkForWiredResetPermission && item.allowWiredResetState() ? item.getExtradata() : " ", item.getRotation(), item.getX(), item.getY())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } + List newSettings = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY())); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.state = setState; + this.direction = setDirection; + this.position = setPosition; + this.settings.clear(); + this.settings.addAll(newSettings); this.setDelay(packet.readInt()); return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java index 23414d94..bf7f3fb4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java @@ -12,11 +12,15 @@ import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; public class WiredEffectMoveFurniAway extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.FLEE; @@ -44,45 +48,35 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { for (HabboItem item : this.items) { RoomTile t = room.getLayout().getTile(item.getX(), item.getY()); - double shortest = 1000.0D; - Habbo target = null; - - for (Habbo habbo : room.getHabbos()) { - if (habbo.getRoomUnit().getCurrentLocation().distance(t) <= shortest) { - shortest = habbo.getRoomUnit().getCurrentLocation().distance(t); - target = habbo; - } - } + RoomUnit target = room.getRoomUnits().stream().min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t))).orElse(null); if (target != null) { - if (RoomLayout.tilesAdjecent(target.getRoomUnit().getCurrentLocation(), room.getLayout().getTile(item.getX(), item.getY())) && (target.getRoomUnit().getX() == item.getX() || target.getRoomUnit().getY() == item.getY())) { - final Habbo finalTarget = target; - Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, finalTarget.getRoomUnit(), room, new Object[]{item}), 500); - + if (target.getCurrentLocation().distance(t) <= 1) { + Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, target, room, new Object[]{item}), 500); continue; } int x = 0; int y = 0; - if (target.getRoomUnit().getX() == item.getX()) { - if (item.getY() < target.getRoomUnit().getY()) + if (target.getX() == item.getX()) { + if (item.getY() < target.getY()) y--; else y++; - } else if (target.getRoomUnit().getY() == item.getY()) { - if (item.getX() < target.getRoomUnit().getX()) + } else if (target.getY() == item.getY()) { + if (item.getX() < target.getX()) x--; else x++; - } else if (target.getRoomUnit().getX() - item.getX() > target.getRoomUnit().getY() - item.getY()) { - if (target.getRoomUnit().getX() - item.getX() > 0) + } else if (target.getX() - item.getX() > target.getY() - item.getY()) { + if (target.getX() - item.getX() > 0) x--; else x++; } else { - if (target.getRoomUnit().getY() - item.getY() > 0) + if (target.getY() - item.getY() > 0) y--; else y++; @@ -182,20 +176,35 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); + int itemsCount = packet.readInt(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java index 31f692d6..e2cbb8a1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java @@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.threading.runnables.WiredCollissionRunnable; import gnu.trove.map.hash.THashMap; @@ -19,6 +20,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -128,7 +130,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { } if (startTile != null && layout.tileExists(startTile.x, startTile.y)) { - THashSet roomUnitsAtTile = room.getHabbosAndBotsAt(startTile.x, startTile.y); + Collection roomUnitsAtTile = room.getRoomUnitsAt(startTile); if (roomUnitsAtTile.size() > 0) { target = roomUnitsAtTile.iterator().next(); if (i == 0) { // i = 0 means right next to it @@ -300,20 +302,36 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java index f3d3e2ee..e7325744 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java @@ -86,9 +86,10 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect { if (newTile != null) { boolean hasRoomUnits = false; - for (RoomUnit _roomUnit : room.getHabbosAndBotsAt(newTile)) { + for (RoomUnit _roomUnit : room.getRoomUnitsAt(newTile)) { hasRoomUnits = true; - WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item}); + // this wired isn't meant to do a collision + //WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item}); } if (!hasRoomUnits && room.getStackHeight(newTile.x, newTile.y, true, item) != Short.MAX_VALUE) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java index 652f3780..bfe0ef15 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java @@ -14,6 +14,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserEffectComposer; import com.eu.habbo.threading.runnables.RoomUnitTeleport; import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer; @@ -78,6 +79,7 @@ public class WiredEffectTeleport extends InteractionWiredEffect { } } + Emulator.getThreading().run(() -> { roomUnit.isWiredTeleporting = true; }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.x, tile.y, tile.getStackHeight() + (tile.state == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); } @@ -127,20 +129,36 @@ public class WiredEffectTeleport extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java index d3025363..21f2926b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java @@ -3,12 +3,20 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTeamItem; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiPuck; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock; +import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; +import com.eu.habbo.habbohotel.items.interactions.pets.*; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; @@ -17,6 +25,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; import org.slf4j.Logger; @@ -34,6 +43,46 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { private final THashSet items; + private static final List> FORBIDDEN_TYPES = new ArrayList>() { + { + this.add(InteractionWired.class); + this.add(InteractionTeleport.class); + this.add(InteractionPushable.class); + this.add(InteractionTagPole.class); + this.add(InteractionTagField.class); + this.add(InteractionCrackable.class); + this.add(InteractionGameScoreboard.class); + this.add(InteractionGameGate.class); + this.add(InteractionFreezeTile.class); + this.add(InteractionFreezeBlock.class); + this.add(InteractionFreezeExitTile.class); + this.add(InteractionBattleBanzaiTeleporter.class); + this.add(InteractionBattleBanzaiTile.class); + this.add(InteractionMonsterPlantSeed.class); + this.add(InteractionPetBreedingNest.class); + this.add(InteractionPetDrink.class); + this.add(InteractionPetFood.class); + this.add(InteractionPetToy.class); + this.add(InteractionBadgeDisplay.class); + this.add(InteractionClothing.class); + this.add(InteractionVendingMachine.class); + this.add(InteractionGift.class); + this.add(InteractionPressurePlate.class); + this.add(InteractionMannequin.class); + this.add(InteractionGymEquipment.class); + this.add(InteractionHopper.class); + this.add(InteractionObstacle.class); + this.add(InteractionOneWayGate.class); + this.add(InteractionPuzzleBox.class); + this.add(InteractionRoller.class); + this.add(InteractionSwitch.class); + this.add(InteractionTent.class); + this.add(InteractionTrap.class); + this.add(InteractionTrophy.class); + this.add(InteractionWater.class); + } + }; + public WiredEffectToggleFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); this.items = new THashSet<>(); @@ -92,25 +141,36 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); - this.items.clear(); - - for (int i = 0; i < count; i++) { - HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) - continue; - - this.items.add(item); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } @@ -123,7 +183,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { THashSet itemsToRemove = new THashSet<>(); for (HabboItem item : this.items) { - if (item == null || item.getRoomId() == 0 || item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile) { + if (item == null || item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { itemsToRemove.add(item); continue; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java index 98b41137..3a703929 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java @@ -3,11 +3,18 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock; +import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; +import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; +import com.eu.habbo.habbohotel.items.interactions.pets.*; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -15,6 +22,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; import org.slf4j.Logger; @@ -32,6 +40,46 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { private final THashSet items = new THashSet<>(); + private static final List> FORBIDDEN_TYPES = new ArrayList>() { + { + this.add(InteractionWired.class); + this.add(InteractionTeleport.class); + this.add(InteractionPushable.class); + this.add(InteractionTagPole.class); + this.add(InteractionTagField.class); + this.add(InteractionCrackable.class); + this.add(InteractionGameScoreboard.class); + this.add(InteractionGameGate.class); + this.add(InteractionFreezeTile.class); + this.add(InteractionFreezeBlock.class); + this.add(InteractionFreezeExitTile.class); + this.add(InteractionBattleBanzaiTeleporter.class); + this.add(InteractionBattleBanzaiTile.class); + this.add(InteractionMonsterPlantSeed.class); + this.add(InteractionPetBreedingNest.class); + this.add(InteractionPetDrink.class); + this.add(InteractionPetFood.class); + this.add(InteractionPetToy.class); + this.add(InteractionBadgeDisplay.class); + this.add(InteractionClothing.class); + this.add(InteractionVendingMachine.class); + this.add(InteractionGift.class); + this.add(InteractionPressurePlate.class); + this.add(InteractionMannequin.class); + this.add(InteractionGymEquipment.class); + this.add(InteractionHopper.class); + this.add(InteractionObstacle.class); + this.add(InteractionOneWayGate.class); + this.add(InteractionPuzzleBox.class); + this.add(InteractionRoller.class); + this.add(InteractionSwitch.class); + this.add(InteractionTent.class); + this.add(InteractionTrap.class); + this.add(InteractionTrophy.class); + this.add(InteractionWater.class); + } + }; + public WiredEffectToggleRandom(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } @@ -88,24 +136,36 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); - this.items.clear(); + int itemsCount = packet.readInt(); - int count = packet.readInt(); - - for (int i = 0; i < count; i++) { - HabboItem item = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt()); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) - continue; - - this.items.add(item); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } @@ -115,7 +175,7 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { THashSet items = this.items; for (HabboItem item : items) { - if (item.getRoomId() == 0) { + if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { this.items.remove(item); continue; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java index d58b6a84..da811cd6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java @@ -13,6 +13,7 @@ import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; @@ -83,20 +84,36 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); packet.readString(); - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; + int itemsCount = packet.readInt(); - this.items.clear(); - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(packet.readInt())); + if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { + throw new WiredSaveException("Too many furni selected"); } - this.setDelay(packet.readInt()); + List newItems = new ArrayList<>(); + + for (int i = 0; i < itemsCount; i++) { + int itemId = packet.readInt(); + HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); + + if(it == null) + throw new WiredSaveException(String.format("Item %s not found", itemId)); + + newItems.add(it); + } + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.items.clear(); + this.items.addAll(newItems); + this.setDelay(delay); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java index 3cc5872a..4d27e3cd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java @@ -5,14 +5,18 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; import gnu.trove.procedure.TObjectProcedure; @@ -68,15 +72,25 @@ public class WiredEffectWhisper extends InteractionWiredEffect { } @Override - public boolean saveData(ClientMessage packet, GameClient gameClient) { + public boolean saveData(ClientMessage packet, GameClient gameClient) throws WiredSaveException { packet.readInt(); - this.message = Emulator.getGameEnvironment().getWordFilter().filter(packet.readString(), null); - if (this.message.length() > 100) { - this.message = ""; + String message = packet.readString(); + + if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { + message = Emulator.getGameEnvironment().getWordFilter().filter(message, null); + message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); } + packet.readInt(); - this.setDelay(packet.readInt()); + + int delay = packet.readInt(); + + if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) + throw new WiredSaveException("Delay too long"); + + this.message = message; + this.setDelay(delay); return true; } @@ -87,7 +101,9 @@ public class WiredEffectWhisper extends InteractionWiredEffect { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { - habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED))); + String msg = this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""); + habbo.getClient().sendResponse(new RoomUserWhisperComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED))); + Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg })); if (habbo.getRoomUnit().isIdle()) { habbo.getRoomUnit().getRoom().unIdle(habbo); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java index 0017efe8..8f859fd2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java @@ -68,7 +68,7 @@ public class WiredBlob extends InteractionDefault { GamePlayer player = habbo.getHabboInfo().getGamePlayer(); if (player != null) { - player.addScore(this.POINTS_REWARD); + player.addScore(this.POINTS_REWARD, true); BattleBanzaiGame battleBanzaiGame = (BattleBanzaiGame) room.getGame(BattleBanzaiGame.class); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java index 73c543c3..36c266b9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java @@ -25,7 +25,7 @@ import java.util.List; public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { private static final Logger LOGGER = LoggerFactory.getLogger(WiredTriggerBotReachedFurni.class); - public final static WiredTriggerType type = WiredTriggerType.BOT_REACHED_STF; + public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI; private THashSet items; private String botName = ""; @@ -73,7 +73,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { message.appendString(this.botName); message.appendInt(0); message.appendInt(0); - message.appendInt(this.getType().code); + message.appendInt(WiredTriggerType.BOT_REACHED_STF.code); if (!this.isTriggeredByRoomUnit()) { List invalidTriggers = new ArrayList<>(); @@ -114,17 +114,11 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - List bots = room.getBots(this.botName); - - for (Bot bot : bots) { - if (bot.getRoomUnit().equals(roomUnit)) { - for (Object o : stuff) { - if (this.items.contains(o)) - return true; - } + if (stuff.length >= 1) { + if (stuff[0] instanceof HabboItem) { + return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); } } - return false; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java index 7da199f7..161f2acf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java @@ -57,16 +57,7 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length == 0) - return false; - - List bots = room.getBots(this.botName); - - for (Bot bot : bots) { - if (bot.getRoomUnit().equals(stuff[0])) - return true; - } - return false; + return room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java index 9a98f41c..341f912a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java @@ -28,14 +28,11 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (this.key.length() > 0) { - if (stuff[0] instanceof String) { - if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) { - return !this.ownerOnly || room.getOwnerId() == habbo.getHabboInfo().getId(); - } + if (this.key.length() > 0) { + if (stuff[0] instanceof String) { + if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) { + Habbo habbo = room.getHabbo(roomUnit); + return !this.ownerOnly || (habbo != null && room.getOwnerId() == habbo.getHabboInfo().getId()); } } } 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 29945fef..6b26d62b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -73,6 +73,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.awt.*; +import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -1458,7 +1459,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (itemsOnRoller.isEmpty()) { HabboItem item = room.getTopItemAt(tileInFront.x, tileInFront.y); - if (item != null && itemsNewTile.contains(item)) { + if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) { Emulator.getThreading().run(() -> { if (unit.getGoal() == rollerTile) { try { @@ -2170,6 +2171,20 @@ public class Room implements Comparable, ISerialize, Runnable { return null; } + public Game getGameOrCreate(Class gameType) { + Game game = this.getGame(gameType); + if(game == null) { + try { + game = gameType.getDeclaredConstructor(Room.class).newInstance(this); + this.addGame(game); + } catch (Exception e) { + LOGGER.error("Error getting game " + gameType.getName(), e); + } + } + + return game; + } + public ConcurrentSet getGames() { return this.games; } @@ -4678,4 +4693,9 @@ public class Room implements Comparable, ISerialize, Runnable { return units; } + + public Collection getRoomUnitsAt(RoomTile tile) { + THashSet roomUnits = getRoomUnits(); + return roomUnits.stream().filter(unit -> unit.getCurrentLocation() == tile).collect(Collectors.toSet()); + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index 9521a75c..57f05c47 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -37,6 +37,7 @@ public class RoomUnit { private static final Logger LOGGER = LoggerFactory.getLogger(RoomUnit.class); public boolean isWiredTeleporting = false; + public boolean isLeavingTeleporter = false; private final ConcurrentHashMap status; private final THashMap cacheable; public boolean canRotate = true; diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index 98924182..7478b1ed 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -126,7 +126,6 @@ public class WiredHandler { public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff) { long millis = System.currentTimeMillis(); if (Emulator.isReady && trigger.canExecute(millis) && trigger.execute(roomUnit, room, stuff)) { - trigger.setCooldown(millis); trigger.activateBox(room); THashSet conditions = room.getRoomSpecialTypes().getConditions(trigger.getX(), trigger.getY()); @@ -152,6 +151,7 @@ public class WiredHandler { } } + trigger.setCooldown(millis); boolean hasExtraRandom = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraRandom.class); boolean hasExtraUnseen = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraUnseen.class); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectSaveDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectSaveDataEvent.java index 98ace187..fbf51226 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectSaveDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectSaveDataEvent.java @@ -5,6 +5,8 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorMessagesComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.UpdateFailedComposer; import com.eu.habbo.messages.outgoing.wired.WiredSavedComposer; public class WiredEffectSaveDataEvent extends MessageHandler { @@ -18,13 +20,19 @@ public class WiredEffectSaveDataEvent extends MessageHandler { if (room.hasRights(this.client.getHabbo()) || room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermission(Permission.ACC_MOVEROTATE)) { InteractionWiredEffect effect = room.getRoomSpecialTypes().getEffect(itemId); - if (effect != null) { + try { + if (effect == null) + throw new WiredSaveException(String.format("Wired effect with item id %s not found in room", itemId)); + if (effect.saveData(this.packet, this.client)) { this.client.sendResponse(new WiredSavedComposer()); effect.needsUpdate(true); Emulator.getThreading().run(effect); } } + catch (WiredSaveException e) { + this.client.sendResponse(new UpdateFailedComposer(e.getMessage())); + } } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredSaveException.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredSaveException.java new file mode 100644 index 00000000..74feda15 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredSaveException.java @@ -0,0 +1,15 @@ +package com.eu.habbo.messages.incoming.wired; + +public class WiredSaveException extends Exception { + + private final String message; + + public WiredSaveException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return this.message; + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java index 863792d7..c86de7ef 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java @@ -9,6 +9,7 @@ import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import gnu.trove.set.hash.THashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +24,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { private final Room room; private int x; private int y; + private HabboItem oldTopItem; public RoomUnitOnRollerComposer(RoomUnit roomUnit, HabboItem roller, RoomTile oldLocation, double oldZ, RoomTile newLocation, double newZ, Room room) { this.roomUnit = roomUnit; @@ -32,6 +34,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { this.newLocation = newLocation; this.newZ = newZ; this.room = room; + oldTopItem = this.room.getTopItemAt(oldLocation.x, oldLocation.y); } public RoomUnitOnRollerComposer(RoomUnit roomUnit, RoomTile newLocation, Room room) { @@ -42,6 +45,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { this.newLocation = newLocation; this.newZ = this.newLocation.getStackHeight(); this.room = room; + this.oldTopItem = null; } @Override @@ -64,7 +68,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { if (this.roller != null && room.getLayout() != null) { RoomTile rollerTile = room.getLayout().getTile(this.roller.getX(), this.roller.getY()); HabboItem topItem = this.room.getTopItemAt(this.roomUnit.getCurrentLocation().x, this.roomUnit.getCurrentLocation().y); - if (topItem != null) { + if (topItem != null && (topItem == roller || oldTopItem != topItem)) { try { topItem.onWalkOff(this.roomUnit, this.room, new Object[]{this}); } catch (Exception e) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java b/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java index b6926f62..11642074 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java @@ -5,16 +5,20 @@ import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; public class BotFollowHabbo implements Runnable { private final Bot bot; private final Habbo habbo; private final Room room; + private boolean hasReached; public BotFollowHabbo(Bot bot, Habbo habbo, Room room) { this.bot = bot; this.habbo = habbo; this.room = room; + this.hasReached = false; } @Override @@ -30,6 +34,16 @@ public class BotFollowHabbo implements Runnable { if (target.x < 0 || target.y < 0) target = this.room.getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), this.habbo.getRoomUnit().getBodyRotation().getValue()); + if(this.habbo.getRoomUnit().getCurrentLocation().distance(this.bot.getRoomUnit().getCurrentLocation()) < 2) { + if(!hasReached) { + WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{}); + hasReached = true; + } + } + else { + hasReached = false; + } + if (target.x >= 0 && target.y >= 0) { this.bot.getRoomUnit().setGoalLocation(target); this.bot.getRoomUnit().setCanWalk(true); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java index 9228596a..5aafb4e9 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java @@ -30,12 +30,11 @@ public class RoomUnitTeleport implements Runnable { this.y = y; this.z = z; this.newEffect = newEffect; - roomUnit.isWiredTeleporting = true; } @Override public void run() { - if (roomUnit == null || roomUnit.getRoom() == null || room.getLayout() == null) + if (roomUnit == null || roomUnit.getRoom() == null || room.getLayout() == null || roomUnit.isLeavingTeleporter) return; RoomTile t = this.room.getLayout().getTile((short) this.x, (short) this.y); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java index 7a648ff0..a2f65db7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import java.util.ArrayList; import java.util.List; @@ -47,7 +48,7 @@ public class RoomUnitWalkToLocation implements Runnable { return; } - if (!this.walker.getGoal().equals(this.goalTile)) { + if (!this.walker.getGoal().equals(this.goalTile) || (this.walker.getPath().size() == 0 && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { onFail(); return; } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index 674dfba3..9072a33d 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java @@ -3,11 +3,10 @@ package com.eu.habbo.threading.runnables.teleport; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer; import com.eu.habbo.threading.runnables.HabboItemNewState; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; @@ -29,6 +28,7 @@ class TeleportActionFive implements Runnable { public void run() { RoomUnit unit = this.client.getHabbo().getRoomUnit(); + unit.isLeavingTeleporter = false; unit.isTeleporting = false; unit.setCanWalk(true); @@ -46,11 +46,16 @@ class TeleportActionFive implements Runnable { List onSuccess = new ArrayList(); onSuccess.add(() -> { unit.setCanLeaveRoomByDoor(true); + + Emulator.getThreading().run(() -> { + unit.isLeavingTeleporter = false; + }, 300); }); unit.setCanLeaveRoomByDoor(false); unit.setGoalLocation(tile); unit.statusUpdate(true); + unit.isLeavingTeleporter = true; Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onSuccess, onSuccess)); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java index cd2adb5f..6379fa98 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java @@ -25,6 +25,10 @@ class TeleportActionFour implements Runnable { return; } + if(this.client.getHabbo().getRoomUnit() != null) { + this.client.getHabbo().getRoomUnit().isLeavingTeleporter = true; + } + Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 500); } }