You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-19 15:06:19 +00:00
fix(moderation): harden ban and modtool edge cases
Use executeUpdate with generated keys for offline ban inserts, return an empty result when an offline target cannot be loaded, and make ban commands handle empty results instead of indexing blindly. Modtool chatlog requests now guard missing users instead of dereferencing null.
This commit is contained in:
@@ -9,6 +9,8 @@ import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboInfo;
|
||||
import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BanCommand extends Command {
|
||||
public BanCommand() {
|
||||
super("cmd_ban", Emulator.getTexts().getValue("commands.keys.cmd_ban").split(";"));
|
||||
@@ -72,7 +74,13 @@ public class BanCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
ModToolBan ban = Emulator.getGameEnvironment().getModToolManager().ban(target.getId(), gameClient.getHabbo(), reason.toString(), banTime, ModToolBanType.ACCOUNT, -1).get(0);
|
||||
List<ModToolBan> bans = Emulator.getGameEnvironment().getModToolManager().ban(target.getId(), gameClient.getHabbo(), reason.toString(), banTime, ModToolBanType.ACCOUNT, -1);
|
||||
if (bans == null || bans.isEmpty()) {
|
||||
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_ban.user_offline"), RoomChatMessageBubbles.ALERT);
|
||||
return true;
|
||||
}
|
||||
|
||||
ModToolBan ban = bans.get(0);
|
||||
gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_ban.ban_issued").replace("%user%", target.getUsername()).replace("%time%", ban.expireDate - Emulator.getIntUnixTimestamp() + "").replace("%reason%", ban.reason), RoomChatMessageBubbles.ALERT);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboInfo;
|
||||
import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IPBanCommand extends Command {
|
||||
public final static int TEN_YEARS = 315569260;
|
||||
|
||||
@@ -50,12 +52,12 @@ public class IPBanCommand extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
Emulator.getGameEnvironment().getModToolManager().ban(habbo.getId(), gameClient.getHabbo(), reason.toString(), TEN_YEARS, ModToolBanType.IP, -1);
|
||||
count++;
|
||||
List<?> bans = Emulator.getGameEnvironment().getModToolManager().ban(habbo.getId(), gameClient.getHabbo(), reason.toString(), TEN_YEARS, ModToolBanType.IP, -1);
|
||||
count += bans != null ? bans.size() : 0;
|
||||
for (Habbo h : Emulator.getGameServer().getGameClientManager().getHabbosWithIP(habbo.getIpLogin())) {
|
||||
if (h != null) {
|
||||
count++;
|
||||
Emulator.getGameEnvironment().getModToolManager().ban(h.getHabboInfo().getId(), gameClient.getHabbo(), reason.toString(), TEN_YEARS, ModToolBanType.IP, -1);
|
||||
bans = Emulator.getGameEnvironment().getModToolManager().ban(h.getHabboInfo().getId(), gameClient.getHabbo(), reason.toString(), TEN_YEARS, ModToolBanType.IP, -1);
|
||||
count += bans != null ? bans.size() : 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.eu.habbo.habbohotel.users.Habbo;
|
||||
import com.eu.habbo.habbohotel.users.HabboInfo;
|
||||
import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MachineBanCommand extends Command {
|
||||
public MachineBanCommand() {
|
||||
super("cmd_machine_ban", Emulator.getTexts().getValue("commands.keys.cmd_machine_ban").split(";"));
|
||||
@@ -46,7 +48,8 @@ public class MachineBanCommand extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
count = Emulator.getGameEnvironment().getModToolManager().ban(habbo.getId(), gameClient.getHabbo(), reason.toString(), IPBanCommand.TEN_YEARS, ModToolBanType.MACHINE, -1).size();
|
||||
List<?> bans = Emulator.getGameEnvironment().getModToolManager().ban(habbo.getId(), gameClient.getHabbo(), reason.toString(), IPBanCommand.TEN_YEARS, ModToolBanType.MACHINE, -1);
|
||||
count = bans != null ? bans.size() : 0;
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
@@ -378,7 +378,9 @@ public class ModToolManager {
|
||||
statement.setString(6, reason);
|
||||
statement.setString(7, type.getType());
|
||||
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
statement.executeUpdate();
|
||||
|
||||
try (ResultSet set = statement.getGeneratedKeys()) {
|
||||
if (set.next()) {
|
||||
try (PreparedStatement selectBanStatement = connection.prepareStatement("SELECT * FROM bans WHERE id = ? LIMIT 1")) {
|
||||
selectBanStatement.setInt(1, set.getInt(1));
|
||||
@@ -434,6 +436,10 @@ public class ModToolManager {
|
||||
Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(targetUserId);
|
||||
HabboInfo offlineInfo = target != null ? target.getHabboInfo() : HabboManager.getOfflineHabboInfo(targetUserId);
|
||||
|
||||
if (offlineInfo == null) {
|
||||
return bans;
|
||||
}
|
||||
|
||||
if (moderator.getHabboInfo().getRank().getId() < offlineInfo.getRank().getId()) {
|
||||
return bans;
|
||||
}
|
||||
@@ -454,7 +460,7 @@ public class ModToolManager {
|
||||
bans.add(ban);
|
||||
|
||||
if (target != null) {
|
||||
Emulator.getGameServer().getGameClientManager().disposeClient(target.getClient());
|
||||
Emulator.getGameServer().getGameClientManager().forceDisposeClient(target.getClient());
|
||||
}
|
||||
|
||||
if ((type == ModToolBanType.IP || type == ModToolBanType.SUPER) && target != null && !ban.ip.equals("offline")) {
|
||||
@@ -465,7 +471,7 @@ public class ModToolManager {
|
||||
Emulator.getPluginManager().fireEvent(new SupportUserBannedEvent(moderator, h, ban));
|
||||
Emulator.getThreading().run(ban);
|
||||
bans.add(ban);
|
||||
Emulator.getGameServer().getGameClientManager().disposeClient(h.getClient());
|
||||
Emulator.getGameServer().getGameClientManager().forceDisposeClient(h.getClient());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,7 +483,7 @@ public class ModToolManager {
|
||||
Emulator.getPluginManager().fireEvent(new SupportUserBannedEvent(moderator, h, ban));
|
||||
Emulator.getThreading().run(ban);
|
||||
bans.add(ban);
|
||||
Emulator.getGameServer().getGameClientManager().disposeClient(h.getClient());
|
||||
Emulator.getGameServer().getGameClientManager().forceDisposeClient(h.getClient());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -3,6 +3,7 @@ package com.eu.habbo.messages.incoming.modtool;
|
||||
import com.eu.habbo.Emulator;
|
||||
import com.eu.habbo.habbohotel.modtool.ScripterManager;
|
||||
import com.eu.habbo.habbohotel.permissions.Permission;
|
||||
import com.eu.habbo.habbohotel.users.HabboInfo;
|
||||
import com.eu.habbo.habbohotel.users.HabboManager;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.modtool.ModToolUserChatlogComposer;
|
||||
@@ -12,7 +13,11 @@ public class ModToolRequestUserChatlogEvent extends MessageHandler {
|
||||
public void handle() throws Exception {
|
||||
if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) {
|
||||
int userId = this.packet.readInt();
|
||||
String username = HabboManager.getOfflineHabboInfo(userId).getUsername();
|
||||
HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(userId);
|
||||
if (habboInfo == null) {
|
||||
return;
|
||||
}
|
||||
String username = habboInfo.getUsername();
|
||||
|
||||
this.client.sendResponse(new ModToolUserChatlogComposer(Emulator.getGameEnvironment().getModToolManager().getUserRoomVisitsAndChatlogs(userId), userId, username));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user