From 4360507fa819b670fcfe2ae4d6faceede6c31ca6 Mon Sep 17 00:00:00 2001 From: David Silva Date: Wed, 22 Jan 2020 16:15:44 +0100 Subject: [PATCH] feat(ModToolUserInfoComposer): display last sanction + small improv. --- .../incoming/handshake/SecureLoginEvent.java | 46 +++++++------ .../modtool/ModToolSanctionAlertEvent.java | 5 +- .../modtool/ModToolSanctionBanEvent.java | 5 +- .../modtool/ModToolSanctionMuteEvent.java | 5 +- .../ModToolSanctionTradeLockEvent.java | 5 +- .../modtool/ModToolSanctionInfoComposer.java | 69 ++++++++++--------- .../modtool/ModToolUserInfoComposer.java | 25 +++++-- 7 files changed, 93 insertions(+), 67 deletions(-) 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 9559fc7f..d579482c 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 @@ -142,33 +142,35 @@ public class SecureLoginEvent extends MessageHandler { 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 (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + 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 (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.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.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)); + 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)); + } } } 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 078808e0..98e27cc6 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 @@ -26,10 +26,11 @@ public class ModToolSanctionAlertEvent extends MessageHandler { if (habbo != null) { 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")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + if (modToolSanctionItems != null && !modToolSanctionItems.isEmpty()) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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 92940e79..59e05e89 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 @@ -50,10 +50,11 @@ public class ModToolSanctionBanEvent extends MessageHandler { } if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) { ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); - THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); - ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); + if (modToolSanctionItems != null && !modToolSanctionItemsHashMap.isEmpty()) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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 aed5ca93..b7451cfe 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 @@ -28,10 +28,11 @@ public class ModToolSanctionMuteEvent extends MessageHandler { if (habbo != null) { 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")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); + if (modToolSanctionItems != null && !modToolSanctionItemsHashMap.isEmpty()) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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 c7c5a1c8..1969da0f 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 @@ -26,10 +26,11 @@ public class ModToolSanctionTradeLockEvent extends MessageHandler { if (habbo != null) { ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); - THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); - ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(userId); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(userId); + if (modToolSanctionItems != null && !modToolSanctionItems.isEmpty()) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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 288d2ff9..e6b87afc 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 @@ -26,49 +26,52 @@ public class ModToolSanctionInfoComposer extends MessageComposer { @Override public ServerMessage compose() { 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; - if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { - ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(habbo.getHabboInfo().getId()); - boolean prevItem = modToolSanctionItems.size() > 1; + if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); - ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); - ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1); + boolean prevItem = modToolSanctionItems.size() > 1; - if (item.probationTimestamp > 0) { - probationEndTime = new Date((long) item.probationTimestamp * 1000); + ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); + ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1); - probationStartTime = new DateTime(probationEndTime).minusDays(modToolSanctions.getProbationDays(modToolSanctionLevelItem)).toDate(); + if (item.probationTimestamp > 0) { + probationEndTime = new Date((long) item.probationTimestamp * 1000); + + 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(modToolSanctions.getTimeOfSanction(modToolSanctionLevelItem)); // time of current sanction + this.response.appendInt(30); // TODO: 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(0); // TODO: unused? + 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); // TODO: unused? + this.response.appendBoolean(item.isMuted); // muted + this.response.appendString(tradeLockedUntil == null ? "" : tradeLockedUntil.toString()); // trade locked until } - - 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(modToolSanctions.getTimeOfSanction(modToolSanctionLevelItem)); // time of current sanction - this.response.appendInt(30); // TODO: 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(0); // TODO: unused? - 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); // TODO: unused? - this.response.appendBoolean(item.isMuted); // muted - this.response.appendString(tradeLockedUntil == null ? "" : tradeLockedUntil.toString()); // trade locked until - } else { this.response.init(Outgoing.ModToolSanctionInfoComposer); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolUserInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolUserInfoComposer.java index 804ec6e1..59723fdb 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolUserInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModToolUserInfoComposer.java @@ -1,12 +1,17 @@ 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.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; +import gnu.trove.map.hash.THashMap; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; public class ModToolUserInfoComposer extends MessageComposer { private final ResultSet set; @@ -37,11 +42,23 @@ public class ModToolUserInfoComposer extends MessageComposer { this.response.appendString(this.set.getString("mail")); this.response.appendString("Rank (" + this.set.getInt("rank_id") + "): " + this.set.getString("rank_name")); //user_class_txt - if (false) //has sanction - { - this.response.appendString("SOME SANCTION"); - this.response.appendInt(31); + ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); + + if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { + THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(this.set.getInt("user_id")); + ArrayList modToolSanctionItems = modToolSanctionItemsHashMap.get(this.set.getInt("user_id")); + + if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) //has sanction + { + ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); + ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); + + this.response.appendString(modToolSanctions.getSanctionType(modToolSanctionLevelItem)); + this.response.appendInt(31); + } + } + return this.response; } catch (SQLException e) { Emulator.getLogging().logSQLException(e);