From 8be461354cefafd1613841862c698f94a208aac4 Mon Sep 17 00:00:00 2001 From: David Silva Date: Wed, 22 Jan 2020 17:07:24 +0100 Subject: [PATCH] fix(sanctions): check if sanctions are active/ignore level 0's --- .../habbohotel/modtool/ModToolSanctions.java | 11 +-- .../incoming/handshake/SecureLoginEvent.java | 6 +- .../modtool/ModToolSanctionInfoComposer.java | 91 ++++++++++--------- 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java index ca72f787..91ad713b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolSanctions.java @@ -51,7 +51,7 @@ public class ModToolSanctions { public THashMap> getSanctions(int habboId) { synchronized (this.sanctionHashmap) { - //this.sanctionHashmap.clear(); // TODO: unsure if needed at some point. + this.sanctionHashmap.clear(); 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()) { @@ -91,11 +91,10 @@ public class ModToolSanctions { } } - 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); + public void updateSanction(int rowId, int probationTimestamp) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET probation_timestamp = ? WHERE id = ?")) { + statement.setInt(1, probationTimestamp); + statement.setInt(2, rowId); statement.execute(); } catch (SQLException e) { 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 d579482c..ca7834d2 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 @@ -150,10 +150,10 @@ public class SecureLoginEvent extends MessageHandler { if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); - if (item.sanctionLevel > 0 && item.probationTimestamp > Emulator.getIntUnixTimestamp()) { + if (item.sanctionLevel > 0 && item.probationTimestamp != 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); + } else if (item.sanctionLevel > 0 && item.probationTimestamp != 0 && item.probationTimestamp <= Emulator.getIntUnixTimestamp()) { + modToolSanctions.updateSanction(item.id, 0); } if (item.tradeLockedUntil > 0 && item.tradeLockedUntil <= Emulator.getIntUnixTimestamp()) { 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 e6b87afc..54ae2d60 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 @@ -28,7 +28,7 @@ public class ModToolSanctionInfoComposer extends MessageComposer { ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); Date probationEndTime; - Date probationStartTime = null; + Date probationStartTime; if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { THashMap> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); @@ -37,7 +37,10 @@ public class ModToolSanctionInfoComposer extends MessageComposer { if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); - boolean prevItem = modToolSanctionItems.size() > 1; + ModToolSanctionItem prevItem = null; + if (modToolSanctionItems.get(modToolSanctionItems.size() - 2) != null) { + prevItem = modToolSanctionItems.get(modToolSanctionItems.size() - 2); + } ModToolSanctionLevelItem modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel); ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1); @@ -47,50 +50,56 @@ public class ModToolSanctionInfoComposer extends MessageComposer { 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 != null && prevItem.probationTimestamp > 0); // 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 { + return cleanResponse(); } - 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 { + return cleanResponse(); } - } 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); // time of current sanction - this.response.appendInt(30); // TODO: unused? - this.response.appendString("cfh.reason.EMPTY"); // reason - this.response.appendString(Emulator.getDate().toString()); // probation start time - this.response.appendInt(0); // TODO: unused? - this.response.appendString("ALERT"); // next sanction type - this.response.appendInt(0); // time to be applied in next sanction (in hours) - this.response.appendInt(30); // TODO: unused? - this.response.appendBoolean(false); // muted - this.response.appendString(""); // trade locked until - } return this.response; } + + private ServerMessage cleanResponse() { + 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); // time of current sanction + this.response.appendInt(30); // TODO: unused? + this.response.appendString("cfh.reason.EMPTY"); // reason + this.response.appendString(Emulator.getDate().toString()); // probation start time + this.response.appendInt(0); // TODO: unused? + this.response.appendString("ALERT"); // next sanction type + this.response.appendInt(0); // time to be applied in next sanction (in hours) + this.response.appendInt(30); // TODO: unused? + this.response.appendBoolean(false); // muted + this.response.appendString(""); // trade locked until + + return this.response; + } } \ No newline at end of file