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) {
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) {

View File

@ -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()) {

View File

@ -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<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) {
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;
}
}