From ad96c6e74bfb4d9e961e408d534d52d75bce5b97 Mon Sep 17 00:00:00 2001 From: David Silva Date: Sun, 19 Jan 2020 18:18:15 -0500 Subject: [PATCH] Sanctions. Credits to zGrav (David Silva) --- .../eu/habbo/habbohotel/GameEnvironment.java | 7 + .../modtool/ModToolSanctionItem.java | 25 +++ .../modtool/ModToolSanctionLevelItem.java | 15 ++ .../habbohotel/modtool/ModToolSanctions.java | 174 ++++++++++++++++++ .../com/eu/habbo/messages/PacketManager.java | 2 + .../eu/habbo/messages/incoming/Incoming.java | 3 + .../incoming/handshake/SecureLoginEvent.java | 37 ++++ .../helper/MySanctionStatusEvent.java | 12 ++ .../modtool/ModToolSanctionAlertEvent.java | 26 ++- .../modtool/ModToolSanctionBanEvent.java | 26 ++- .../modtool/ModToolSanctionMuteEvent.java | 36 +++- .../ModToolSanctionTradeLockEvent.java | 27 ++- .../modtool/ModToolSanctionInfoComposer.java | 100 ++++++++-- .../events/sanctions/SanctionEvent.java | 17 ++ 14 files changed, 486 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionItem.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionLevelItem.java create mode 100644 src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/helper/MySanctionStatusEvent.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/sanctions/SanctionEvent.java diff --git a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java index 02704bd3..93312b2c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java +++ b/src/main/java/com/eu/habbo/habbohotel/GameEnvironment.java @@ -15,6 +15,7 @@ import com.eu.habbo.habbohotel.guilds.GuildManager; import com.eu.habbo.habbohotel.hotelview.HotelViewManager; import com.eu.habbo.habbohotel.items.ItemManager; import com.eu.habbo.habbohotel.modtool.ModToolManager; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.modtool.WordFilter; import com.eu.habbo.habbohotel.navigation.NavigatorManager; import com.eu.habbo.habbohotel.permissions.PermissionsManager; @@ -39,6 +40,7 @@ public class GameEnvironment { private PermissionsManager permissionsManager; private BotManager botManager; private ModToolManager modToolManager; + private ModToolSanctions modToolSanctions; private PetManager petManager; private AchievementManager achievementManager; private GuideManager guideManager; @@ -62,6 +64,7 @@ public class GameEnvironment { this.navigatorManager = new NavigatorManager(); this.commandHandler = new CommandHandler(); this.modToolManager = new ModToolManager(); + this.modToolSanctions = new ModToolSanctions(); this.achievementManager = new AchievementManager(); this.achievementManager.reload(); this.guideManager = new GuideManager(); @@ -145,6 +148,10 @@ public class GameEnvironment { return this.modToolManager; } + public ModToolSanctions getModToolSanctions() { + return this.modToolSanctions; + } + public PetManager getPetManager() { return this.petManager; } diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionItem.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionItem.java new file mode 100644 index 00000000..70d2b375 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionItem.java @@ -0,0 +1,25 @@ +package com.eu.habbo.habbohotel.modtool; + +public class ModToolSanctionItem { + public int id; + public int habboId; + public int sanctionLevel; + public int probationTimestamp; + public boolean isMuted; + public int muteDuration; + public int tradeLockedUntil; + public String reason; + + public ModToolSanctionItem(int id, int habboId, int sanctionLevel, int probationTimestamp, boolean isMuted, int muteDuration, int tradeLockedUntil, String reason) { + this.id = id; + this.habboId = habboId; + this.sanctionLevel = sanctionLevel; + this.probationTimestamp = probationTimestamp; + this.isMuted = isMuted; + this.muteDuration = muteDuration; + this.tradeLockedUntil = tradeLockedUntil; + this.reason = reason; + } + + +} diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionLevelItem.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionLevelItem.java new file mode 100644 index 00000000..d893b4e2 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctionLevelItem.java @@ -0,0 +1,15 @@ +package com.eu.habbo.habbohotel.modtool; + +public class ModToolSanctionLevelItem { + public int sanctionLevel; + public String sanctionType; + public int sanctionHourLength; + public int sanctionProbationDays; + + public ModToolSanctionLevelItem(int sanctionLevel, String sanctionType, int sanctionHourLength, int sanctionProbationDays) { + this.sanctionLevel = sanctionLevel; + this.sanctionType = sanctionType; + this.sanctionHourLength = sanctionHourLength; + this.sanctionProbationDays = sanctionProbationDays; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java new file mode 100644 index 00000000..020f04f0 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java @@ -0,0 +1,174 @@ +package com.eu.habbo.habbohotel.modtool; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.plugin.events.sanctions.SanctionEvent; +import gnu.trove.map.hash.THashMap; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; + +public class ModToolSanctions { + + private final THashMap> sanctionHashmap; + private final THashMap sanctionLevelsHashmap; + + public ModToolSanctions() { + long millis = System.currentTimeMillis(); + this.sanctionHashmap = new THashMap<>(); + this.sanctionLevelsHashmap = new THashMap<>(); + this.loadModSanctions(); + Emulator.getLogging().logStart("Sanctions Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); + + } + + public synchronized void loadModSanctions() { + this.sanctionHashmap.clear(); + this.sanctionLevelsHashmap.clear(); + + this.loadSanctionLevels(); + } + + private void loadSanctionLevels() { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM sanction_levels")) { + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + this.sanctionLevelsHashmap.put(set.getInt("level"), new ModToolSanctionLevelItem(set.getInt("level"), set.getString("type"), set.getInt("hour_length"), set.getInt("probation_days"))); + } + } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + + public ModToolSanctionLevelItem getSanctionLevelItem(int sanctionLevel) { + return this.sanctionLevelsHashmap.get(sanctionLevel); + } + + public THashMap> getSanctions(int habboId) { + synchronized (this.sanctionHashmap) { + //this.sanctionHashmap.clear(); // TODO: unsure if needed at some point. + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM sanctions WHERE habbo_id = ? ORDER BY id ASC")) { + statement.setInt(1, habboId); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + if (this.sanctionHashmap.get(set.getInt("habbo_id")) == null) { + this.sanctionHashmap.put(set.getInt("habbo_id"), new ArrayList<>()); + } + + ModToolSanctionItem item = new ModToolSanctionItem(set.getInt("id"), set.getInt("habbo_id"), set.getInt("sanction_level"), set.getInt("probation_timestamp"), set.getBoolean("is_muted"), set.getInt("mute_duration"), set.getInt("trade_locked_until"), set.getString("reason")); + + if (!this.sanctionHashmap.get(set.getInt("habbo_id")).contains(item)) { + this.sanctionHashmap.get(set.getInt("habbo_id")).add(item); + } + } + } + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + + return this.sanctionHashmap; + } + } + + private void insertSanction(int habboId, int sanctionLevel, int probationTimestamp, String reason, int tradeLockedUntil, boolean isMuted, int muteDuration) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO sanctions (habbo_id, sanction_level, probation_timestamp, reason, trade_locked_until, is_muted, mute_duration) VALUES (?, ?, ?, ?, ?, ?, ?)")) { + statement.setInt(1, habboId); + statement.setInt(2, sanctionLevel); + statement.setInt(3, probationTimestamp); + statement.setString(4, reason); + statement.setInt(5, tradeLockedUntil); + statement.setBoolean(6, isMuted); + statement.setInt(7, muteDuration); + + statement.execute(); + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + + public void updateSanction(int rowId, int sanctionLevel, int probationTimestamp) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET sanction_level = ? AND probation_timestamp = ? WHERE id = ?")) { + statement.setInt(1, sanctionLevel); + statement.setInt(2, probationTimestamp); + statement.setInt(3, rowId); + + statement.execute(); + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + + public void updateTradeLockedUntil(int rowId, int tradeLockedUntil) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET trade_locked_until = ? WHERE id = ?")) { + statement.setInt(1, tradeLockedUntil); + statement.setInt(2, rowId); + + statement.execute(); + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + + public void updateMuteDuration(int rowId, int muteDuration) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET muted_duration = ? WHERE id = ?")) { + statement.setInt(1, muteDuration); + statement.setInt(2, rowId); + + statement.execute(); + } catch (SQLException e) { + Emulator.getLogging().logSQLException(e); + } + } + + public void run(int habboId, Habbo self, int sanctionLevel, int cfhTopic, String reason, int tradeLockedUntil, boolean isMuted, int muteDuration) { + sanctionLevel++; + + ModToolSanctionLevelItem sanctionLevelItem = getSanctionLevelItem(sanctionLevel); + + insertSanction(habboId, sanctionLevel, buildProbationTimestamp(sanctionLevelItem), reason, tradeLockedUntil, isMuted, muteDuration); + + runSanctionBasedOnLevel(sanctionLevelItem, habboId, reason, cfhTopic, self, muteDuration); + + Emulator.getPluginManager().fireEvent(new SanctionEvent(self, Emulator.getGameEnvironment().getHabboManager().getHabbo(habboId), sanctionLevel)); + } + + private int buildProbationTimestamp(ModToolSanctionLevelItem sanctionLevelItem) { + return Emulator.getIntUnixTimestamp() + (sanctionLevelItem.sanctionProbationDays * 24 * 60 * 60); + } + + public int getProbationDays(ModToolSanctionLevelItem sanctionLevelItem) { + return sanctionLevelItem.sanctionProbationDays; + } + + private void runSanctionBasedOnLevel(ModToolSanctionLevelItem sanctionLevelItem, int habboId, String reason, int cfhTopic, Habbo self, int muteDuration) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(habboId); + + int muteDurationSeconds = 0; + + if (muteDuration > 0) { + Date muteDurationDate = new Date((long) muteDuration * 1000); + long diff = muteDurationDate.getTime() - Emulator.getDate().getTime(); + muteDurationSeconds = Math.toIntExact(diff / 1000); + } + + switch (sanctionLevelItem.sanctionType) { + case "ALERT": habbo.alert(reason); break; + case "BAN": Emulator.getGameEnvironment().getModToolManager().ban(habboId, self, reason, sanctionLevelItem.sanctionHourLength, ModToolBanType.ACCOUNT, cfhTopic); break; + case "MUTE": habbo.mute(muteDurationSeconds == 0 ? 3600 : muteDurationSeconds); break; + default: break; + } + } + + public String getSanctionType(ModToolSanctionLevelItem sanctionLevelItem) { + return sanctionLevelItem.sanctionType; + } + + public int getTimeOfSanction(ModToolSanctionLevelItem sanctionLevelItem) { + return sanctionLevelItem.sanctionHourLength; + } +} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 7cda01db..8bd37ca8 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -31,6 +31,7 @@ import com.eu.habbo.messages.incoming.guides.*; import com.eu.habbo.messages.incoming.guilds.*; import com.eu.habbo.messages.incoming.guilds.forums.*; import com.eu.habbo.messages.incoming.handshake.*; +import com.eu.habbo.messages.incoming.helper.MySanctionStatusEvent; import com.eu.habbo.messages.incoming.helper.RequestTalentTrackEvent; import com.eu.habbo.messages.incoming.hotelview.*; import com.eu.habbo.messages.incoming.inventory.RequestInventoryBadgesEvent; @@ -561,6 +562,7 @@ public class PacketManager { this.registerHandler(Incoming.RequestResolutionEvent, RequestResolutionEvent.class); this.registerHandler(Incoming.RequestTalenTrackEvent, RequestTalentTrackEvent.class); this.registerHandler(Incoming.UnknownEvent1, UnknownEvent1.class); + this.registerHandler(Incoming.MySanctionStatusEvent, MySanctionStatusEvent.class); } void registerFloorPlanEditor() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index 0b70e95b..87fb1494 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -216,6 +216,9 @@ public class Incoming { public static final int PostItRequestDataEvent = 3964; public static final int PostItSaveDataEvent = 3666; public static final int PostItDeleteEvent = 3336; + + public static final int MySanctionStatusEvent = 2746; + public static final int MoodLightSaveSettingsEvent = 1648; public static final int ModToolRequestIssueChatlogEvent = 211; public static final int ModToolRequestRoomUserChatlogEvent = -1; diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 28d985e7..9559fc7f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -2,6 +2,8 @@ package com.eu.habbo.messages.incoming.handshake; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.messenger.Messenger; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; @@ -25,13 +27,17 @@ import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; import com.eu.habbo.messages.outgoing.inventory.UserEffectsListComposer; import com.eu.habbo.messages.outgoing.modtool.CfhTopicsMessageComposer; import com.eu.habbo.messages.outgoing.modtool.ModToolComposer; +import com.eu.habbo.messages.outgoing.modtool.ModToolSanctionInfoComposer; import com.eu.habbo.messages.outgoing.navigator.*; import com.eu.habbo.messages.outgoing.unknown.BuildersClubExpiredComposer; import com.eu.habbo.messages.outgoing.users.*; import com.eu.habbo.plugin.events.emulator.SSOAuthenticationEvent; import com.eu.habbo.plugin.events.users.UserLoginEvent; +import gnu.trove.map.hash.THashMap; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; @NoAuthMessage public class SecureLoginEvent extends MessageHandler { @@ -135,6 +141,37 @@ public class SecureLoginEvent extends MessageHandler { this.client.sendResponse(new InventoryAchievementsComposer()); this.client.sendResponse(new AchievementListComposer(this.client.getHabbo())); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + + + if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + if (item.sanctionLevel > 0 && item.probationTimestamp > Emulator.getIntUnixTimestamp()) { + this.client.sendResponse(new ModToolSanctionInfoComposer(this.client.getHabbo())); + } else if (item.sanctionLevel > 0 && item.probationTimestamp <= Emulator.getIntUnixTimestamp()) { + modToolSanctions.updateSanction(item.id, 0, 0); + } + + if (item.tradeLockedUntil > 0 && item.tradeLockedUntil <= Emulator.getIntUnixTimestamp()) { + modToolSanctions.updateTradeLockedUntil(item.id, 0); + habbo.getHabboStats().setAllowTrade(true); + } else if (item.tradeLockedUntil > 0 && item.tradeLockedUntil > Emulator.getIntUnixTimestamp()) { + habbo.getHabboStats().setAllowTrade(false); + } + + if (item.isMuted && item.muteDuration <= Emulator.getIntUnixTimestamp()) { + modToolSanctions.updateMuteDuration(item.id, 0); + habbo.unMute(); + } else if (item.isMuted && item.muteDuration > Emulator.getIntUnixTimestamp()) { + Date muteDuration = new Date((long) item.muteDuration * 1000); + long diff = muteDuration.getTime() - Emulator.getDate().getTime(); + habbo.mute(Math.toIntExact(diff)); + } + } + Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress())); if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/helper/MySanctionStatusEvent.java b/src/main/java/com/eu/habbo/messages/incoming/helper/MySanctionStatusEvent.java new file mode 100644 index 00000000..8608708f --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/helper/MySanctionStatusEvent.java @@ -0,0 +1,12 @@ +package com.eu.habbo.messages.incoming.helper; + +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.modtool.ModToolSanctionInfoComposer; + +public class MySanctionStatusEvent extends MessageHandler { + + @Override + public void handle() throws Exception { + this.client.sendResponse(new ModToolSanctionInfoComposer(this.client.getHabbo())); + } +} diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionAlertEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionAlertEvent.java index 26cfbda9..078808e0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionAlertEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionAlertEvent.java @@ -1,10 +1,18 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ModToolBanType; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.ModToolIssueHandledComposer; +import gnu.trove.map.hash.THashMap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; public class ModToolSanctionAlertEvent extends MessageHandler { @Override @@ -17,7 +25,23 @@ public class ModToolSanctionAlertEvent extends MessageHandler { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { - habbo.alert(message); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + if (modToolSanctionItems != null && !modToolSanctionItems.isEmpty()) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + if (item != null && item.probationTimestamp > 0 && item.probationTimestamp >= Emulator.getIntUnixTimestamp()) { + modToolSanctions.run(userId, this.client.getHabbo(), item.sanctionLevel, cfhTopic, message, 0, false, 0); + } + } else { + modToolSanctions.run(userId, this.client.getHabbo(), 0, cfhTopic, message, 0, false, 0); + } + } else { + habbo.alert(message); + } } else { this.client.sendResponse(new ModToolIssueHandledComposer(Emulator.getTexts().getValue("generic.user.not_found").replace("%user%", Emulator.getConfig().getValue("hotel.player.name")))); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java index f317c8d6..92940e79 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionBanEvent.java @@ -2,9 +2,16 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolBanType; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.messages.incoming.MessageHandler; +import gnu.trove.map.hash.THashMap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; public class ModToolSanctionBanEvent extends MessageHandler { public static final int BAN_18_HOURS = 3; @@ -42,7 +49,24 @@ public class ModToolSanctionBanEvent extends MessageHandler { duration = Emulator.getIntUnixTimestamp(); } if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) { - Emulator.getGameEnvironment().getModToolManager().ban(userId, this.client.getHabbo(), message, duration, ModToolBanType.ACCOUNT, cfhTopic); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); + + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + if (modToolSanctionItems != null && !modToolSanctionItemsHashMap.isEmpty()) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + if (item.probationTimestamp > 0 && item.probationTimestamp >= Emulator.getIntUnixTimestamp()) { + modToolSanctions.run(userId, this.client.getHabbo(), item.sanctionLevel, cfhTopic, message, 0, false, 0); + } + } else { + modToolSanctions.run(userId, this.client.getHabbo(), 0, cfhTopic, message, 0, false, 0); + } + } else { + Emulator.getGameEnvironment().getModToolManager().ban(userId, this.client.getHabbo(), message, duration, ModToolBanType.ACCOUNT, cfhTopic); + } + } else { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ban").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionMuteEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionMuteEvent.java index f5664f93..aed5ca93 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionMuteEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionMuteEvent.java @@ -1,10 +1,20 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ModToolBanType; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionLevelItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.ModToolIssueHandledComposer; +import gnu.trove.map.hash.THashMap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; public class ModToolSanctionMuteEvent extends MessageHandler { @Override @@ -17,9 +27,29 @@ public class ModToolSanctionMuteEvent extends MessageHandler { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { - habbo.mute(60 * 60); - habbo.alert(message); - this.client.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_mute.muted").replace("%user%", habbo.getHabboInfo().getUsername())); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + if (modToolSanctionItems != null && !modToolSanctionItemsHashMap.isEmpty()) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + if (item.probationTimestamp > 0 && item.probationTimestamp >= Emulator.getIntUnixTimestamp()) { + ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); + + int muteDurationTimestamp = Math.toIntExact(new Date( System.currentTimeMillis() + (modToolSanctionLevelItem.sanctionHourLength * 60 * 60)).getTime() / 1000); + + modToolSanctions.run(userId, this.client.getHabbo(), item.sanctionLevel, cfhTopic, message, 0, true, muteDurationTimestamp); + } + } else { + modToolSanctions.run(userId, this.client.getHabbo(), 0, cfhTopic, message, 0, false, 0); + } + } else { + habbo.mute(60 * 60); + habbo.alert(message); + this.client.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_mute.muted").replace("%user%", habbo.getHabboInfo().getUsername())); + } } else { this.client.sendResponse(new ModToolIssueHandledComposer(Emulator.getTexts().getValue("generic.user.not_found").replace("%user%", Emulator.getConfig().getValue("hotel.player.name")))); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionTradeLockEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionTradeLockEvent.java index ed8ad7af..c7c5a1c8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionTradeLockEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionTradeLockEvent.java @@ -1,10 +1,17 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.ModToolIssueHandledComposer; +import gnu.trove.map.hash.THashMap; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; public class ModToolSanctionTradeLockEvent extends MessageHandler { @Override @@ -18,8 +25,24 @@ public class ModToolSanctionTradeLockEvent extends MessageHandler { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { - habbo.getHabboStats().setAllowTrade(false); - habbo.alert(message); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); + + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + if (modToolSanctionItems != null && !modToolSanctionItems.isEmpty()) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + if (item.probationTimestamp > 0 && item.probationTimestamp >= Emulator.getIntUnixTimestamp()) { + modToolSanctions.run(userId, this.client.getHabbo(), item.sanctionLevel, cfhTopic, message, duration, false, 0); + } + } else { + modToolSanctions.run(userId, this.client.getHabbo(), 0, cfhTopic, message, duration, false, 0); + } + } else { + habbo.getHabboStats().setAllowTrade(false); + habbo.alert(message); + } } else { this.client.sendResponse(new ModToolIssueHandledComposer(Emulator.getTexts().getValue("generic.user.not_found").replace("%user%", Emulator.getConfig().getValue("hotel.player.name")))); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolSanctionInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolSanctionInfoComposer.java index 3e24b6a8..5acfeaf3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolSanctionInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolSanctionInfoComposer.java @@ -1,26 +1,98 @@ package com.eu.habbo.messages.outgoing.modtool; +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctionLevelItem; +import com.eu.habbo.habbohotel.modtool.ModToolSanctions; +import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import gnu.trove.map.hash.THashMap; +import org.joda.time.DateTime; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; public class ModToolSanctionInfoComposer extends MessageComposer { + + private final Habbo habbo; + + public ModToolSanctionInfoComposer(Habbo habbo) { + this.habbo = habbo; + } + @Override public ServerMessage compose() { - this.response.init(Outgoing.ModToolSanctionInfoComposer); - this.response.appendBoolean(false); //Has Last Sanction. - this.response.appendBoolean(false); //Is probabtion. - this.response.appendString("<< Last Sanction >>"); - this.response.appendInt(0); //Value | Probation days left. - this.response.appendInt(-1); //Unused - this.response.appendString("<< Reason >>"); //Reason - this.response.appendString("1/1/1970 00:00"); //Start Time - this.response.appendInt(0); //Probation Days Left - this.response.appendString("<< Next Sanction >>"); //Next Sanction - this.response.appendInt(0); //Value - this.response.appendInt(-1); //Unused - this.response.appendBoolean(false); //Trade Locked - this.response.appendString("1/1/1970 00:00"); //Trade Locked Untill + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + + Date probationEndTime; + Date probationStartTime = null; + long numberOfDaysProbation = 0; + long numberOfHoursProbation = 0; + + if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + + boolean prevItem = modToolSanctionItems.size() > 1; + + ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); + ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1); + + if (item.probationTimestamp > 0) { + probationEndTime = new Date((long) item.probationTimestamp * 1000); + long diff = probationEndTime.getTime() - Emulator.getDate().getTime(); + numberOfDaysProbation = diff / 1000 / 60 / 60 / 24; + numberOfHoursProbation = diff / 1000 / 60 / 60; + + probationStartTime = new DateTime(probationEndTime).minusDays(modToolSanctions.getProbationDays(modToolSanctionLevelItem)).toDate(); + + } + + Date tradeLockedUntil = null; + + if (item.tradeLockedUntil > 0) { + tradeLockedUntil = new Date((long) item.tradeLockedUntil * 1000); + } + + this.response.init(Outgoing.ModToolSanctionInfoComposer); + + this.response.appendBoolean(prevItem); // has prev sanction + this.response.appendBoolean(item.probationTimestamp >= Emulator.getIntUnixTimestamp()); // is on probation + this.response.appendString(modToolSanctions.getSanctionType(modToolSanctionLevelItem)); // current sanction type + this.response.appendInt(Math.toIntExact(numberOfDaysProbation)); // probation days left + this.response.appendInt(30); // unused? + this.response.appendString(item.reason.equals("") ? "cfh.reason.EMPTY" : item.reason); // reason + this.response.appendString(probationStartTime == null ? Emulator.getDate().toString() : probationStartTime.toString()); // probation start time + this.response.appendInt(Math.toIntExact(numberOfHoursProbation)); // days of probation in hours? + this.response.appendString(modToolSanctions.getSanctionType(nextModToolSanctionLevelItem)); // next sanction type + this.response.appendInt(modToolSanctions.getTimeOfSanction(nextModToolSanctionLevelItem)); // time to be applied in next sanction (in hours) + this.response.appendInt(30); // unused? + this.response.appendBoolean(item.isMuted); // muted + this.response.appendString(tradeLockedUntil == null ? "" : tradeLockedUntil.toString()); // trade locked until + + } else { + this.response.init(Outgoing.ModToolSanctionInfoComposer); + + this.response.appendBoolean(false); // has prev sanction + this.response.appendBoolean(false); // is on probation + this.response.appendString("ALERT"); // last sanction type + this.response.appendInt(0); // probation days left + this.response.appendInt(30); // unused? + this.response.appendString("cfh.reason.EMPTY"); // reason + this.response.appendString(Emulator.getDate().toString()); // probation start time + this.response.appendInt(0); // days of probation in hours? + this.response.appendString("ALERT"); // next sanction type + this.response.appendInt(0); // time to be applied in next sanction (in hours) + this.response.appendInt(30); // unused? + this.response.appendBoolean(false); // muted + this.response.appendString(""); // trade locked until + + } + return this.response; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/plugin/events/sanctions/SanctionEvent.java b/src/main/java/com/eu/habbo/plugin/events/sanctions/SanctionEvent.java new file mode 100644 index 00000000..1a73c4f0 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/sanctions/SanctionEvent.java @@ -0,0 +1,17 @@ +package com.eu.habbo.plugin.events.sanctions; + +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.plugin.events.support.SupportEvent; + +public class SanctionEvent extends SupportEvent { + public Habbo target; + + public int sanctionLevel; + + public SanctionEvent(Habbo moderator, Habbo target, int sanctionLevel) { + super(moderator); + + this.target = target; + this.sanctionLevel = sanctionLevel; + } +}