Merge branch '299-sanctionlevelzero' into 'dev'

fix(sanctions): check if sanctions are active/ignore level 0's

See merge request morningstar/Arcturus-Community!80
This commit is contained in:
Harmonic 2020-01-22 11:14:59 -05:00
commit bd9b3b41f3
3 changed files with 58 additions and 50 deletions

View File

@ -51,7 +51,7 @@ public class ModToolSanctions {
public THashMap<Integer, ArrayList<ModToolSanctionItem>> getSanctions(int habboId) { public THashMap<Integer, ArrayList<ModToolSanctionItem>> getSanctions(int habboId) {
synchronized (this.sanctionHashmap) { 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")) { 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); statement.setInt(1, habboId);
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
@ -91,11 +91,10 @@ public class ModToolSanctions {
} }
} }
public void updateSanction(int rowId, int sanctionLevel, int probationTimestamp) { public void updateSanction(int rowId, int probationTimestamp) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET sanction_level = ? AND probation_timestamp = ? WHERE id = ?")) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE sanctions SET probation_timestamp = ? WHERE id = ?")) {
statement.setInt(1, sanctionLevel); statement.setInt(1, probationTimestamp);
statement.setInt(2, probationTimestamp); statement.setInt(2, rowId);
statement.setInt(3, rowId);
statement.execute(); statement.execute();
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -150,10 +150,10 @@ public class SecureLoginEvent extends MessageHandler {
if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) {
ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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())); this.client.sendResponse(new ModToolSanctionInfoComposer(this.client.getHabbo()));
} else if (item.sanctionLevel > 0 && item.probationTimestamp <= Emulator.getIntUnixTimestamp()) { } else if (item.sanctionLevel > 0 && item.probationTimestamp != 0 && item.probationTimestamp <= Emulator.getIntUnixTimestamp()) {
modToolSanctions.updateSanction(item.id, 0, 0); modToolSanctions.updateSanction(item.id, 0);
} }
if (item.tradeLockedUntil > 0 && item.tradeLockedUntil <= Emulator.getIntUnixTimestamp()) { if (item.tradeLockedUntil > 0 && item.tradeLockedUntil <= Emulator.getIntUnixTimestamp()) {

View File

@ -28,7 +28,7 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions(); ModToolSanctions modToolSanctions = Emulator.getGameEnvironment().getModToolSanctions();
Date probationEndTime; Date probationEndTime;
Date probationStartTime = null; Date probationStartTime;
if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) { if (Emulator.getConfig().getBoolean("hotel.sanctions.enabled")) {
THashMap<Integer, ArrayList<ModToolSanctionItem>> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId()); THashMap<Integer, ArrayList<ModToolSanctionItem>> modToolSanctionItemsHashMap = Emulator.getGameEnvironment().getModToolSanctions().getSanctions(habbo.getHabboInfo().getId());
@ -37,7 +37,10 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) { if (modToolSanctionItems != null && modToolSanctionItems.size() > 0) {
ModToolSanctionItem item = modToolSanctionItems.get(modToolSanctionItems.size() - 1); 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 modToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel);
ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1); ModToolSanctionLevelItem nextModToolSanctionLevelItem = modToolSanctions.getSanctionLevelItem(item.sanctionLevel + 1);
@ -47,8 +50,6 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
probationStartTime = new DateTime(probationEndTime).minusDays(modToolSanctions.getProbationDays(modToolSanctionLevelItem)).toDate(); probationStartTime = new DateTime(probationEndTime).minusDays(modToolSanctions.getProbationDays(modToolSanctionLevelItem)).toDate();
}
Date tradeLockedUntil = null; Date tradeLockedUntil = null;
if (item.tradeLockedUntil > 0) { if (item.tradeLockedUntil > 0) {
@ -57,7 +58,7 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
this.response.init(Outgoing.ModToolSanctionInfoComposer); this.response.init(Outgoing.ModToolSanctionInfoComposer);
this.response.appendBoolean(prevItem); // has prev sanction this.response.appendBoolean(prevItem != null && prevItem.probationTimestamp > 0); // has prev sanction
this.response.appendBoolean(item.probationTimestamp >= Emulator.getIntUnixTimestamp()); // is on probation this.response.appendBoolean(item.probationTimestamp >= Emulator.getIntUnixTimestamp()); // is on probation
this.response.appendString(modToolSanctions.getSanctionType(modToolSanctionLevelItem)); // current sanction type this.response.appendString(modToolSanctions.getSanctionType(modToolSanctionLevelItem)); // current sanction type
this.response.appendInt(modToolSanctions.getTimeOfSanction(modToolSanctionLevelItem)); // time of current sanction this.response.appendInt(modToolSanctions.getTimeOfSanction(modToolSanctionLevelItem)); // time of current sanction
@ -70,9 +71,19 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
this.response.appendInt(30); // TODO: unused? this.response.appendInt(30); // TODO: unused?
this.response.appendBoolean(item.isMuted); // muted this.response.appendBoolean(item.isMuted); // muted
this.response.appendString(tradeLockedUntil == null ? "" : tradeLockedUntil.toString()); // trade locked until this.response.appendString(tradeLockedUntil == null ? "" : tradeLockedUntil.toString()); // trade locked until
}
} else { } else {
return cleanResponse();
}
} else {
return cleanResponse();
}
}
return this.response;
}
private ServerMessage cleanResponse() {
this.response.init(Outgoing.ModToolSanctionInfoComposer); this.response.init(Outgoing.ModToolSanctionInfoComposer);
this.response.appendBoolean(false); // has prev sanction this.response.appendBoolean(false); // has prev sanction
@ -89,8 +100,6 @@ public class ModToolSanctionInfoComposer extends MessageComposer {
this.response.appendBoolean(false); // muted this.response.appendBoolean(false); // muted
this.response.appendString(""); // trade locked until this.response.appendString(""); // trade locked until
}
return this.response; return this.response;
} }
} }