From dc8c0e0bcb768a4b95f448488ee9192c36c1a2da Mon Sep 17 00:00:00 2001 From: Snaiker Date: Sun, 3 Jan 2021 21:58:43 +0000 Subject: [PATCH 1/8] Fix issue #934 --- src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 5 +++++ 1 file changed, 5 insertions(+) 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 d0704c82..b5e171dc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1506,6 +1506,11 @@ public class Room implements Comparable, ISerialize, Runnable { if (unit.hasStatus(RoomUnitStatus.SIT)) { unit.sitUpdate = true; } + + unit.setPreviousLocation(unit.getPreviousLocation()); + unit.setPreviousLocationZ(unit.getPreviousLocation().getStackHeight()); + unit.setCurrentLocation(this.getLayout().getTile(tile.x, tile.y)); + unit.setZ(unit.getCurrentLocation().getStackHeight()); } } From 64b75a0be6b950d2d1e14388cd9d7f0ebf4cdaca Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 1 Feb 2021 19:09:11 +0100 Subject: [PATCH 2/8] Fixed wired Condition: Trigger is NOT on furni --- .../WiredConditionNotTriggerOnFurni.java | 131 +----------------- .../WiredConditionTriggerOnFurni.java | 14 +- 2 files changed, 14 insertions(+), 131 deletions(-) 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 f80f7df6..21ea027e 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 @@ -1,27 +1,16 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -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.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ClientMessage; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; -public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { +public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI; - private THashSet items = new THashSet<>(); - public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } @@ -32,129 +21,19 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) return false; + if (roomUnit == null) + return false; + this.refresh(); if (this.items.isEmpty()) return true; - THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); - return this.items.stream().noneMatch(itemsAtUser::contains); - } - - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(";"); - - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) { - this.items.add(item); - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); + return !triggerOnFurni(roomUnit, room); } @Override public WiredConditionType getType() { return type; } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().code); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(ClientMessage packet) { - - packet.readInt(); - packet.readString(); - - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(packet.readInt()); - - if (item != null) { - this.items.add(item); - } - } - } - - return true; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (item.getRoomId() != room.getId()) - items.add(item); - } - } - - this.items.removeAll(items); - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } - } } 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 733c8581..250d4751 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 @@ -22,7 +22,7 @@ import java.util.stream.Collectors; public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; - private THashSet items = new THashSet<>(); + protected THashSet items = new THashSet<>(); public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,10 +42,14 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { if (this.items.isEmpty()) return false; + return triggerOnFurni(roomUnit, room); + } + + protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) { /* - * 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles. - * 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items - * */ + * 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles. + * 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items + * */ if (!roomUnit.isWalking()) { THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); return this.items.stream().anyMatch(itemsAtUser::contains); @@ -158,7 +162,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { return true; } - private void refresh() { + protected void refresh() { THashSet items = new THashSet<>(); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); From d7e96d94753dfc7f1f16bdcfc5e8b7ffcb5bff9b Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 2 Feb 2021 18:18:08 +0100 Subject: [PATCH 3/8] Mannequin save look event now checks for acc_anyroomowner --- .../incoming/rooms/items/MannequinSaveLookEvent.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java index 5def4dee..4e46eb30 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java @@ -1,16 +1,19 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; public class MannequinSaveLookEvent extends MessageHandler { @Override public void handle() throws Exception { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Habbo habbo = this.client.getHabbo(); + Room room = habbo.getHabboInfo().getCurrentRoom(); - if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId()) + if (room == null || !room.isOwner(habbo)) return; HabboItem item = room.getHabboItem(this.packet.readInt()); From 4c096ae8d14c5a951ac707bf78242b17c113a19b Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 2 Feb 2021 18:21:02 +0100 Subject: [PATCH 4/8] Mannequin save look event now checks for acc_anyroomowner --- .../incoming/rooms/items/MannequinSaveLookEvent.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java index 4e46eb30..6713af89 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; @@ -25,7 +24,7 @@ public class MannequinSaveLookEvent extends MessageHandler { StringBuilder look = new StringBuilder(); - for (String s : this.client.getHabbo().getHabboInfo().getLook().split("\\.")) { + for (String s : habbo.getHabboInfo().getLook().split("\\.")) { if (!s.contains("hr") && !s.contains("hd") && !s.contains("he") && !s.contains("ea") && !s.contains("ha") && !s.contains("fa")) { look.append(s).append("."); } @@ -36,9 +35,9 @@ public class MannequinSaveLookEvent extends MessageHandler { } if (data.length == 3) { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); + item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); } else { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + this.client.getHabbo().getHabboInfo().getUsername() + "'s look."); + item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + habbo.getHabboInfo().getUsername() + "'s look."); } item.needsUpdate(true); From 2bb55a8e3897cba3a65121ea86c1aa0460410a02 Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 3 Feb 2021 17:53:00 +0100 Subject: [PATCH 5/8] MannequinSaveNameEvent now checks for acc_anyroomowner --- .../messages/incoming/rooms/items/MannequinSaveNameEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java index 7715ffd2..ad09fc3c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java @@ -9,7 +9,7 @@ public class MannequinSaveNameEvent extends MessageHandler { @Override public void handle() throws Exception { Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId()) + if (room == null || !room.isOwner(this.client.getHabbo())) return; HabboItem item = room.getHabboItem(this.packet.readInt()); From 35f81f96c4eb5f7b373198fc6e81d21dd96b0b1d Mon Sep 17 00:00:00 2001 From: Dank074 Date: Wed, 3 Feb 2021 19:16:50 -0600 Subject: [PATCH 6/8] fix ban behavior for empty machine id/ip address --- .../eu/habbo/habbohotel/modtool/ModToolManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java index 9dbd405a..9bb9f5da 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -428,6 +428,16 @@ public class ModToolManager { return bans; } + //if machine id is empty, downgrade ban type to IP ban + if( (type == ModToolBanType.MACHINE || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getMachineID().isEmpty())) { + type = ModToolBanType.IP; + } + + //if ip address is empty, downgrade ban type to account ban + if( (type == ModToolBanType.IP || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getIpLogin().isEmpty())) { + type = ModToolBanType.ACCOUNT; + } + ModToolBan ban = new ModToolBan(targetUserId, offlineInfo != null ? offlineInfo.getIpLogin() : "offline", offlineInfo != null ? offlineInfo.getMachineID() : "offline", moderator.getHabboInfo().getId(), Emulator.getIntUnixTimestamp() + duration, reason, type, cfhTopic); Emulator.getPluginManager().fireEvent(new SupportUserBannedEvent(moderator, target, ban)); Emulator.getThreading().run(ban); From 8ad3aeb6b20fe3f143750ae06c308b6cdd9ed898 Mon Sep 17 00:00:00 2001 From: Remco Date: Thu, 4 Feb 2021 19:59:16 +0100 Subject: [PATCH 7/8] Fixed game timer threading issue --- .../games/InteractionGameTimer.java | 60 +++++++++---------- .../threading/runnables/games/GameTimer.java | 46 ++++++++++++++ 2 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java index 1f7396e9..bb868c6d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java @@ -14,6 +14,7 @@ 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.ServerMessage; +import com.eu.habbo.threading.runnables.games.GameTimer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +64,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { String[] data = set.getString("extra_data").split("\t"); if (data.length >= 2) { - this.baseTime = Integer.valueOf(data[1]); + this.baseTime = Integer.parseInt(data[1]); this.timeNow = this.baseTime; } @@ -149,33 +150,6 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (this.needsUpdate() || this.needsDelete()) { super.run(); } - - if (this.getRoomId() == 0) { - this.threadActive = false; - return; - } - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null || !this.isRunning || this.isPaused) { - this.threadActive = false; - return; - } - - this.timeNow--; - if (this.timeNow < 0) this.timeNow = 0; - - if (this.timeNow > 0) { - this.threadActive = true; - Emulator.getThreading().run(this, 1000); - } else { - this.threadActive = false; - this.timeNow = 0; - this.endGame(room); - WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); - } - - room.updateItem(this); } @Override @@ -248,7 +222,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this, 1000); + Emulator.getThreading().run(new GameTimer(this), 1000); } } else if (client != null) { if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))) @@ -271,7 +245,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this); + Emulator.getThreading().run(new GameTimer(this)); } } } else { @@ -285,7 +259,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this, 1000); + Emulator.getThreading().run(new GameTimer(this), 1000); } } @@ -350,10 +324,30 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } public boolean isRunning() { - return isRunning; + return this.isRunning; } public void setRunning(boolean running) { - isRunning = running; + this.isRunning = running; + } + + public void setThreadActive(boolean threadActive) { + this.threadActive = threadActive; + } + + public boolean isPaused() { + return this.isPaused; + } + + public void reduceTime() { + this.timeNow--; + } + + public int getTimeNow() { + return this.timeNow; + } + + public void setTimeNow(int timeNow) { + this.timeNow = timeNow; } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java b/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java new file mode 100644 index 00000000..f1e903e7 --- /dev/null +++ b/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java @@ -0,0 +1,46 @@ +package com.eu.habbo.threading.runnables.games; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +public class GameTimer implements Runnable { + + private final InteractionGameTimer timer; + + public GameTimer(InteractionGameTimer timer) { + this.timer = timer; + } + + @Override + public void run() { + if (timer.getRoomId() == 0) { + timer.setRunning(false); + return; + } + + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(timer.getRoomId()); + + if (room == null || !timer.isRunning() || timer.isPaused()) { + timer.setThreadActive(false); + return; + } + + timer.reduceTime(); + if (timer.getTimeNow() < 0) timer.setTimeNow(0); + + if (timer.getTimeNow() > 0) { + timer.setThreadActive(true); + Emulator.getThreading().run(this, 1000); + } else { + timer.setThreadActive(false); + timer.setTimeNow(0); + timer.endGame(room); + WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); + } + + room.updateItem(timer); + } +} From f527527787feec0751cf90ec1eaf90d2e8da4b10 Mon Sep 17 00:00:00 2001 From: Remco Date: Thu, 4 Feb 2021 21:05:38 +0100 Subject: [PATCH 8/8] Gifting yourself won't progress achievements anymore --- .../incoming/catalog/CatalogBuyItemAsGiftEvent.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java index 7504c50a..13ffb72a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java @@ -336,7 +336,10 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { return; } - AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver")); + if (this.client.getHabbo().getHabboInfo().getId() != userId) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver")); + } + if (habbo != null) { habbo.getClient().sendResponse(new AddHabboItemComposer(gift)); habbo.getClient().getHabbo().getInventory().getItemsComponent().addItem(gift); @@ -351,7 +354,9 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys)); } - AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver")); + if (this.client.getHabbo().getHabboInfo().getId() != userId) { + AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver")); + } if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) { if (totalCredits > 0) {