Compare commits

...

17 Commits

Author SHA1 Message Date
github-actions[bot] 0b142d184c 🆙 Bump version to 4.2.37 [skip ci] 2026-06-05 19:21:31 +00:00
DuckieTM 867c8ff857 Merge pull request #155 from duckietm/dev
🆙 Fix the Admin Catalogue stuff
2026-06-05 21:20:31 +02:00
duckietm 5094d6ce4f 🆙 Fix the Admin Catalogue stuff 2026-06-05 14:23:05 +02:00
github-actions[bot] 2c0ef9873c 🆙 Bump version to 4.2.36 [skip ci] 2026-06-04 08:44:19 +00:00
DuckieTM dadc1b8aaf Merge pull request #153 from duckietm/dev
Dev
2026-06-04 10:43:21 +02:00
duckietm 85758b53fa 🆙 Updates Mention 2026-06-04 10:43:05 +02:00
DuckieTM 2171b5f2ec Merge pull request #152 from medievalshell/feat/mentions-hotelwide-figure
feat(mentions): hotel-wide @nick delivery + sender figure + disable-m…
2026-06-04 08:50:49 +02:00
medievalshell 46306c8205 feat(mentions): hotel-wide @nick delivery + sender figure + disable-mention persistence
- resolveHabbo() falls back to a hotel-wide online lookup so a direct @nick
  mention reaches the target even when they are in a different room (was
  resolved only within the sender's room).
- HabboMention now carries the sender figure (live from the sender Habbo,
  history from a users.look JOIN); MentionReceived/MentionsList composers
  append it so the client can render the sender avatar in the notification.
- 009: add users_settings.mentions_enabled / mass_mentions_enabled columns
  so :disablementions / :disablemassmentions actually persist.
2026-06-04 01:27:45 +02:00
github-actions[bot] fadec887cd 🆙 Bump version to 4.2.35 [skip ci] 2026-06-03 14:45:16 +00:00
DuckieTM e614c1d64f Merge pull request #150 from duckietm/dev
Merge pull request #149 from duckietm/main
2026-06-03 16:44:04 +02:00
DuckieTM e7deea7d9d Merge pull request #149 from duckietm/main
sync to dev
2026-06-03 16:39:01 +02:00
github-actions[bot] 44ea3abd4e 🆙 Bump version to 4.2.34 [skip ci] 2026-06-03 14:37:38 +00:00
DuckieTM 609cd20ab2 Merge pull request #143 from simoleo89/feat/command-autocomplete-refactor
Structure commands alert output
2026-06-03 16:36:33 +02:00
github-actions[bot] 717a7f184f 🆙 Bump version to 4.2.33 [skip ci] 2026-06-03 14:23:40 +00:00
DuckieTM 2862446686 Merge pull request #148 from duckietm/dev
🆙 More updates mentions
2026-06-03 16:22:39 +02:00
duckietm e97e680006 🆙 More updates mentions 2026-06-03 16:20:02 +02:00
simoleo89 9f36d95dbc fix(commands): structure commands alert output 2026-06-02 18:34:50 +02:00
19 changed files with 412 additions and 89 deletions
+82 -19
View File
@@ -1,26 +1,89 @@
CREATE TABLE IF NOT EXISTS `habbo_mentions` ( CREATE TABLE IF NOT EXISTS `habbo_mentions` (
`id` INT NOT NULL AUTO_INCREMENT, `id` INT(11) NOT NULL AUTO_INCREMENT,
`target_user_id` INT NOT NULL, `target_user_id` INT(11) NOT NULL,
`sender_user_id` INT NOT NULL, `sender_user_id` INT(11) NOT NULL,
`sender_username` VARCHAR(64) NOT NULL DEFAULT '', `sender_username` VARCHAR(64) NOT NULL DEFAULT '',
`room_id` INT NOT NULL, `room_id` INT(11) NOT NULL DEFAULT 0,
`room_name` VARCHAR(255) NOT NULL DEFAULT '', `room_name` VARCHAR(64) NOT NULL DEFAULT '',
`message` VARCHAR(255) NOT NULL DEFAULT '', `message` VARCHAR(255) NOT NULL DEFAULT '',
`mention_type` TINYINT NOT NULL DEFAULT 0, `mention_type` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0 = direct (@nick), 1 = broadcast (@all/@friends/@room)',
`timestamp` INT NOT NULL DEFAULT 0, `timestamp` INT(11) NOT NULL DEFAULT 0,
`read` TINYINT NOT NULL DEFAULT 0, `read` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
INDEX `idx_target_read` (`target_user_id`, `read`) KEY `idx_target_id` (`target_user_id`, `id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; KEY `idx_target_unread` (`target_user_id`, `read`),
KEY `idx_target_timestamp` (`target_user_id`, `timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO `emulator_settings` (`key`, `value`) VALUES
('mentions.enabled', '1'),
('mentions.room.aliases', 'amici,friends,all,everyone,tutti,room,stanza'),
('mentions.max.targets', '50'), INSERT INTO `permission_definitions`
('mentions.cooldown.ms', '3000'), (`permission_key`, `max_value`, `comment`,
('mentions.store.limit', '50'); `rank_1`, `rank_2`, `rank_3`, `rank_4`, `rank_5`, `rank_6`, `rank_7`, `rank_8`)
VALUES
('acc_mention_everyone', 1,
'Allow sending @all / @everyone / @tutti broadcast mentions (hotel-wide).',
0, 0, 0, 0, 1, 1, 1, 1),
('acc_mention_friends', 1,
'Allow sending @friends / @amici broadcast mentions (sender''s online buddies).',
0, 0, 0, 0, 1, 1, 1, 1),
('cmd_disablementions', 1,
'Allow toggling :disablementions to stop receiving any @mention notifications.',
1, 1, 1, 1, 1, 1, 1, 1),
('cmd_disablemassmentions', 1,
'Allow toggling :disablemassmentions to stop receiving broadcast mentions (direct @nick still works).',
1, 1, 1, 1, 1, 1, 1, 1)
ON DUPLICATE KEY UPDATE
`comment` = VALUES(`comment`);
-- ----------------------------------------------------------------------------
-- 3. Emulator settings: cooldowns, caps and alias lists
--
-- Only inserted when missing - existing tuned values are preserved.
-- ----------------------------------------------------------------------------
INSERT IGNORE INTO `emulator_settings` (`key`, `value`, `comment`) VALUES
('mentions.enabled', '1',
'Master switch. 1 = process @mentions, 0 = disable the feature entirely.'),
('mentions.max.targets', '50',
'Hard cap on how many users a single broadcast (@all / @friends / @room) can fan out to.'),
('mentions.cooldown.ms', '3000',
'Per-sender cooldown between any two mentions, in milliseconds.'),
('mentions.room.cooldown.ms', '15000',
'Extra per-sender cooldown for broadcast mentions (@all / @friends / @room) on top of mentions.cooldown.ms.'),
('mentions.store.limit', '50',
'Number of mentions returned in the initial RequestMentionsList response.'),
('mentions.request.cooldown.ms', '2000',
'Per-user cooldown between RequestMentionsList packets.'),
('mentions.markread.cooldown.ms', '500',
'Per-user cooldown between mark-single-as-read packets.'),
('mentions.markall.cooldown.ms', '5000',
'Per-user cooldown between mark-all-as-read packets (bulk DB update).'),
('mentions.delete.cooldown.ms', '500',
'Per-user cooldown between delete-mention packets.'),
('mentions.everyone.aliases', 'all,everyone,tutti',
'Comma-separated aliases that trigger an @everyone broadcast (requires acc_mention_everyone).'),
('mentions.friends.aliases', 'friends,amici',
'Comma-separated aliases that trigger an @friends broadcast (requires acc_mention_friends).'),
('mentions.room.aliases', 'room,stanza',
'Comma-separated aliases that trigger an @room broadcast (no permission required, room scope only).');
ALTER TABLE `wordfilter` ALTER TABLE `wordfilter`
ADD COLUMN `prefix_only` ENUM('0','1') NOT NULL DEFAULT '0' ADD COLUMN `prefix_only` ENUM('0','1') NOT NULL DEFAULT '0'
COMMENT 'When 1, this word only applies to custom prefixes, not to chat/motto/guild.' AFTER `mute`; COMMENT 'When 1, this word only applies to custom prefixes, not to chat/motto/guild.' AFTER `mute`;
-- ----------------------------------------------------------------------------
-- 5. Per-user mention preferences (:disablementions / :disablemassmentions)
--
-- Read by HabboStats (default '1' = enabled), toggled by the commands.
-- Without these columns the toggle commands cannot persist.
-- ----------------------------------------------------------------------------
ALTER TABLE `users_settings`
ADD COLUMN IF NOT EXISTS `mentions_enabled` ENUM('0','1') NOT NULL DEFAULT '1'
COMMENT 'Receive @nick mention notifications.',
ADD COLUMN IF NOT EXISTS `mass_mentions_enabled` ENUM('0','1') NOT NULL DEFAULT '1'
COMMENT 'Receive broadcast (@all / @friends / @room) mentions.';
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.eu.habbo</groupId> <groupId>com.eu.habbo</groupId>
<artifactId>Habbo</artifactId> <artifactId>Habbo</artifactId>
<version>4.2.32</version> <version>4.2.37</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -191,6 +191,8 @@ public class CommandHandler {
addCommand(new CreditsCommand()); addCommand(new CreditsCommand());
addCommand(new DanceCommand()); addCommand(new DanceCommand());
addCommand(new DiagonalCommand()); addCommand(new DiagonalCommand());
addCommand(new DisableMassMentionsCommand());
addCommand(new DisableMentionsCommand());
addCommand(new DisconnectCommand()); addCommand(new DisconnectCommand());
addCommand(new EjectAllCommand()); addCommand(new EjectAllCommand());
addCommand(new EmptyInventoryCommand()); addCommand(new EmptyInventoryCommand());
@@ -17,7 +17,22 @@ public class CommandsCommand extends Command {
message.append("(").append(commands.size()).append("):\r\n"); message.append("(").append(commands.size()).append("):\r\n");
for (Command c : commands) { for (Command c : commands) {
message.append(Emulator.getTexts().getValue("commands.description." + c.permission, "commands.description." + c.permission)).append("\r"); String textKey = "commands.description." + c.permission;
String commandText = Emulator.getTexts().getValue(textKey, "");
String commandLine = ":" + c.keys[0];
String description = "";
if (commandText.startsWith(":")) {
commandLine = commandText;
} else if (!commandText.isEmpty() && !commandText.equals(textKey)) {
description = commandText;
}
message.append(commandLine).append("\r");
if (!description.isEmpty()) {
message.append(description).append("\r");
}
} }
gameClient.getHabbo().alert(new String[]{message.toString()}); gameClient.getHabbo().alert(new String[]{message.toString()});
@@ -0,0 +1,25 @@
package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.users.Habbo;
public class DisableMassMentionsCommand extends Command {
public DisableMassMentionsCommand() {
super("cmd_disablemassmentions", new String[]{"disablemassmentions", "togglemassmentions"});
}
@Override
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (gameClient == null) return true;
Habbo habbo = gameClient.getHabbo();
if (habbo == null || habbo.getHabboStats() == null) return true;
boolean newState = !habbo.getHabboStats().massMentionsEnabled();
habbo.getHabboStats().setMassMentionsEnabled(newState);
habbo.whisper(newState
? "Broadcast mentions (@all / @friends / @room) are now ENABLED for you."
: "Broadcast mentions (@all / @friends / @room) are now DISABLED for you. Direct @nick mentions still work.");
return true;
}
}
@@ -0,0 +1,25 @@
package com.eu.habbo.habbohotel.commands;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.users.Habbo;
public class DisableMentionsCommand extends Command {
public DisableMentionsCommand() {
super("cmd_disablementions", new String[]{"disablementions", "togglementions"});
}
@Override
public boolean handle(GameClient gameClient, String[] params) throws Exception {
if (gameClient == null) return true;
Habbo habbo = gameClient.getHabbo();
if (habbo == null || habbo.getHabboStats() == null) return true;
boolean newState = !habbo.getHabboStats().mentionsEnabled();
habbo.getHabboStats().setMentionsEnabled(newState);
habbo.whisper(newState
? "@mention notifications are now ENABLED for you."
: "@mention notifications are now DISABLED for you. You will not receive direct or broadcast mentions.");
return true;
}
}
@@ -21,6 +21,7 @@ public class HabboMention {
private final int mentionType; private final int mentionType;
private final int timestamp; private final int timestamp;
private final boolean read; private final boolean read;
private final String senderFigure;
public HabboMention(ResultSet set) throws SQLException { public HabboMention(ResultSet set) throws SQLException {
this.id = set.getInt("id"); this.id = set.getInt("id");
@@ -33,6 +34,16 @@ public class HabboMention {
this.mentionType = set.getInt("mention_type"); this.mentionType = set.getInt("mention_type");
this.timestamp = set.getInt("timestamp"); this.timestamp = set.getInt("timestamp");
this.read = set.getInt("read") == 1; this.read = set.getInt("read") == 1;
this.senderFigure = hasSenderFigure(set) ? set.getString("sender_figure") : "";
}
private static boolean hasSenderFigure(ResultSet set) {
try {
set.findColumn("sender_figure");
return true;
} catch (SQLException e) {
return false;
}
} }
public HabboMention(int targetUserId, int id, Habbo sender, Room room, String roomName, String message, int mentionType, int timestamp) { public HabboMention(int targetUserId, int id, Habbo sender, Room room, String roomName, String message, int mentionType, int timestamp) {
@@ -46,6 +57,7 @@ public class HabboMention {
this.mentionType = mentionType; this.mentionType = mentionType;
this.timestamp = timestamp; this.timestamp = timestamp;
this.read = false; this.read = false;
this.senderFigure = sender.getHabboInfo().getLook();
} }
public int getId() { public int getId() {
@@ -87,4 +99,8 @@ public class HabboMention {
public boolean isRead() { public boolean isRead() {
return this.read; return this.read;
} }
public String getSenderFigure() {
return this.senderFigure == null ? "" : this.senderFigure;
}
} }
@@ -19,11 +19,8 @@ public class MentionManager {
private static final int ROOM_NAME_MAX_LENGTH = 64; private static final int ROOM_NAME_MAX_LENGTH = 64;
private static final int MESSAGE_MAX_LENGTH = 255; private static final int MESSAGE_MAX_LENGTH = 255;
private final ConcurrentHashMap<Integer, Long> cooldowns = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Long> cooldowns = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, Long> roomBroadcastCooldowns = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Long> roomBroadcastCooldowns = new ConcurrentHashMap<>();
// Per-user request rate limits for the incoming packets that hit the DB.
private final ConcurrentHashMap<Integer, Long> requestListCooldowns = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Long> requestListCooldowns = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, Long> markReadCooldowns = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Long> markReadCooldowns = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, Long> markAllCooldowns = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Long> markAllCooldowns = new ConcurrentHashMap<>();
@@ -36,20 +33,14 @@ public class MentionManager {
return Emulator.getConfig().getInt("mentions.enabled", 1) == 1; return Emulator.getConfig().getInt("mentions.enabled", 1) == 1;
} }
/** Broadcast category resolved from a mention alias. */
public enum BroadcastScope { public enum BroadcastScope {
NONE, NONE,
// @room / @stanza - reaches the people currently in the room.
ROOM, ROOM,
// @friends / @amici - reaches the sender's online friends, requires acc_mention_friends.
FRIENDS, FRIENDS,
// @all / @everyone / @tutti - reaches every online user, requires acc_mention_everyone.
EVERYONE EVERYONE
} }
/** Permission key (DB column) required to send an "everyone" broadcast. */
public static final String PERMISSION_EVERYONE = "acc_mention_everyone"; public static final String PERMISSION_EVERYONE = "acc_mention_everyone";
/** Permission key (DB column) required to send a "friends" broadcast. */
public static final String PERMISSION_FRIENDS = "acc_mention_friends"; public static final String PERMISSION_FRIENDS = "acc_mention_friends";
private Set<String> parseAliases(String configKey, String defaultValue) { private Set<String> parseAliases(String configKey, String defaultValue) {
@@ -76,14 +67,6 @@ public class MentionManager {
return parseAliases("mentions.everyone.aliases", "all,everyone,tutti"); return parseAliases("mentions.everyone.aliases", "all,everyone,tutti");
} }
/**
* Classify an alias candidate (lowercased, punctuation-trimmed) into a
* broadcast scope. {@link BroadcastScope#EVERYONE} wins over
* {@link BroadcastScope#FRIENDS} which wins over {@link BroadcastScope#ROOM}
* so an admin who's also configured the same word into two lists gets the
* most permissive scope (which is also the one requiring the strongest
* permission, so it can't be misused).
*/
private BroadcastScope classifyAlias(String alias, private BroadcastScope classifyAlias(String alias,
Set<String> everyone, Set<String> everyone,
Set<String> friends, Set<String> friends,
@@ -135,8 +118,6 @@ public class MentionManager {
BroadcastScope scope = this.classifyAlias(aliasCandidate, everyoneAliases, friendsAliases, roomAliases); BroadcastScope scope = this.classifyAlias(aliasCandidate, everyoneAliases, friendsAliases, roomAliases);
if (scope != BroadcastScope.NONE) { if (scope != BroadcastScope.NONE) {
// Promote to the strongest detected scope so a message with
// both @room and @all routes through the @all permission.
if (scope.ordinal() > broadcastScope.ordinal()) { if (scope.ordinal() > broadcastScope.ordinal()) {
broadcastScope = scope; broadcastScope = scope;
} }
@@ -145,9 +126,6 @@ public class MentionManager {
} }
} }
// Gate the broadcast on the matching permission. If the sender does
// not have the right to use it, drop the broadcast entirely but
// keep processing any direct @nick tokens in the same message.
if (broadcastScope == BroadcastScope.EVERYONE && !sender.hasPermission(PERMISSION_EVERYONE)) { if (broadcastScope == BroadcastScope.EVERYONE && !sender.hasPermission(PERMISSION_EVERYONE)) {
broadcastScope = BroadcastScope.NONE; broadcastScope = BroadcastScope.NONE;
} else if (broadcastScope == BroadcastScope.FRIENDS && !sender.hasPermission(PERMISSION_FRIENDS)) { } else if (broadcastScope == BroadcastScope.FRIENDS && !sender.hasPermission(PERMISSION_FRIENDS)) {
@@ -158,9 +136,6 @@ public class MentionManager {
return; return;
} }
// Stricter cooldown for broadcasts: one @all/@friends/@room expands to
// up to mentions.max.targets DB writes and packet sends, so rate-limit it
// separately from direct mentions.
if (broadcastScope != BroadcastScope.NONE) { if (broadcastScope != BroadcastScope.NONE) {
long roomCooldownMs = Emulator.getConfig().getInt("mentions.room.cooldown.ms", 15000); long roomCooldownMs = Emulator.getConfig().getInt("mentions.room.cooldown.ms", 15000);
Long lastRoom = this.roomBroadcastCooldowns.get(senderId); Long lastRoom = this.roomBroadcastCooldowns.get(senderId);
@@ -171,9 +146,6 @@ public class MentionManager {
int maxTargets = Emulator.getConfig().getInt("mentions.max.targets", 50); int maxTargets = Emulator.getConfig().getInt("mentions.max.targets", 50);
if (maxTargets <= 0) maxTargets = 1; if (maxTargets <= 0) maxTargets = 1;
// Bound the number of direct tokens we even attempt to resolve so a
// crafted message can't push us through the room iteration N times.
int maxDirectTokens = Math.min(directTokens.size(), maxTargets); int maxDirectTokens = Math.min(directTokens.size(), maxTargets);
List<Habbo> targets = new ArrayList<>(); List<Habbo> targets = new ArrayList<>();
@@ -187,7 +159,7 @@ public class MentionManager {
this.collectFriendsTargets(sender, senderId, targets, seen, maxTargets); this.collectFriendsTargets(sender, senderId, targets, seen, maxTargets);
break; break;
case ROOM: case ROOM:
this.collectRoomTargets(room, senderId, targets, seen, maxTargets); this.collectRoomTargets(room, senderId, targets, seen, maxTargets, true);
break; break;
case NONE: case NONE:
default: default:
@@ -198,6 +170,9 @@ public class MentionManager {
if (habbo == null || habbo.getHabboInfo().getId() == senderId) { if (habbo == null || habbo.getHabboInfo().getId() == senderId) {
continue; continue;
} }
if (!acceptsMention(habbo, false)) {
continue;
}
if (seen.add(habbo.getHabboInfo().getId())) { if (seen.add(habbo.getHabboInfo().getId())) {
targets.add(habbo); targets.add(habbo);
} }
@@ -229,9 +204,10 @@ public class MentionManager {
} }
} }
private void collectRoomTargets(Room room, int senderId, List<Habbo> targets, Set<Integer> seen, int maxTargets) { private void collectRoomTargets(Room room, int senderId, List<Habbo> targets, Set<Integer> seen, int maxTargets, boolean isBroadcast) {
for (Habbo habbo : room.getHabbos()) { for (Habbo habbo : room.getHabbos()) {
if (habbo == null || habbo.getHabboInfo().getId() == senderId) continue; if (habbo == null || habbo.getHabboInfo().getId() == senderId) continue;
if (!acceptsMention(habbo, isBroadcast)) continue;
if (seen.add(habbo.getHabboInfo().getId())) targets.add(habbo); if (seen.add(habbo.getHabboInfo().getId())) targets.add(habbo);
if (targets.size() >= maxTargets) break; if (targets.size() >= maxTargets) break;
} }
@@ -246,6 +222,7 @@ public class MentionManager {
if (buddyId == senderId) continue; if (buddyId == senderId) continue;
Habbo online = habboManager.getHabbo(buddyId); Habbo online = habboManager.getHabbo(buddyId);
if (online == null) continue; if (online == null) continue;
if (!acceptsMention(online, true)) continue;
if (seen.add(buddyId)) targets.add(online); if (seen.add(buddyId)) targets.add(online);
if (targets.size() >= maxTargets) break; if (targets.size() >= maxTargets) break;
} }
@@ -254,11 +231,21 @@ public class MentionManager {
private void collectEveryoneTargets(int senderId, List<Habbo> targets, Set<Integer> seen, int maxTargets) { private void collectEveryoneTargets(int senderId, List<Habbo> targets, Set<Integer> seen, int maxTargets) {
for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) { for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) {
if (habbo == null || habbo.getHabboInfo().getId() == senderId) continue; if (habbo == null || habbo.getHabboInfo().getId() == senderId) continue;
if (!acceptsMention(habbo, true)) continue;
if (seen.add(habbo.getHabboInfo().getId())) targets.add(habbo); if (seen.add(habbo.getHabboInfo().getId())) targets.add(habbo);
if (targets.size() >= maxTargets) break; if (targets.size() >= maxTargets) break;
} }
} }
private boolean acceptsMention(Habbo recipient, boolean isBroadcast) {
if (recipient == null) return false;
if (recipient.getClient() == null) return false;
if (recipient.getHabboStats() == null) return false;
if (!recipient.getHabboStats().mentionsEnabled()) return false;
if (isBroadcast && !recipient.getHabboStats().massMentionsEnabled()) return false;
return true;
}
private void store(Habbo target, Habbo sender, Room room, String message, int mentionType, int timestamp, String roomName) { private void store(Habbo target, Habbo sender, Room room, String message, int mentionType, int timestamp, String roomName) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement( PreparedStatement statement = connection.prepareStatement(
@@ -281,9 +268,6 @@ public class MentionManager {
} }
} }
// Don't push a notification to the client when the INSERT did not
// return an id - the client dedup keys on id and a 0 would skip
// dedup entirely, opening a flood path on the next packet.
if (generatedId <= 0) { if (generatedId <= 0) {
return; return;
} }
@@ -304,7 +288,7 @@ public class MentionManager {
if (limit > 200) limit = 200; if (limit > 200) limit = 200;
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement( PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM habbo_mentions WHERE target_user_id = ? ORDER BY id DESC LIMIT ?")) { "SELECT habbo_mentions.*, users.look AS sender_figure FROM habbo_mentions LEFT JOIN users ON users.id = habbo_mentions.sender_user_id WHERE target_user_id = ? ORDER BY id DESC LIMIT ?")) {
statement.setInt(1, userId); statement.setInt(1, userId);
statement.setInt(2, limit); statement.setInt(2, limit);
try (ResultSet set = statement.executeQuery()) { try (ResultSet set = statement.executeQuery()) {
@@ -319,7 +303,6 @@ public class MentionManager {
} }
public void markRead(int userId, int mode, int mentionId) { public void markRead(int userId, int mode, int mentionId) {
// Caller has already validated mode and mentionId; this method is defensive only.
if (mode != 0 && mode != 1) return; if (mode != 0 && mode != 1) return;
if (mode == 1 && mentionId <= 0) return; if (mode == 1 && mentionId <= 0) return;
@@ -351,20 +334,11 @@ public class MentionManager {
} }
} }
/**
* Per-user rate limit for {@code RequestMentionsEvent}. Returns true when
* the caller should be served, false when it must be silently dropped.
*/
public boolean tryAcquireRequestList(int userId) { public boolean tryAcquireRequestList(int userId) {
long cooldownMs = Emulator.getConfig().getInt("mentions.request.cooldown.ms", 2000); long cooldownMs = Emulator.getConfig().getInt("mentions.request.cooldown.ms", 2000);
return tryAcquire(this.requestListCooldowns, userId, cooldownMs); return tryAcquire(this.requestListCooldowns, userId, cooldownMs);
} }
/**
* Per-user rate limit for {@code MarkMentionsReadEvent}. The mark-single
* path (mode == 1) is cheap and gets a short window; the mark-all path
* (mode != 1) is a bulk UPDATE and gets a longer one.
*/
public boolean tryAcquireMarkRead(int userId, int mode) { public boolean tryAcquireMarkRead(int userId, int mode) {
long cooldownMs; long cooldownMs;
ConcurrentHashMap<Integer, Long> bucket; ConcurrentHashMap<Integer, Long> bucket;
@@ -378,9 +352,6 @@ public class MentionManager {
return tryAcquire(bucket, userId, cooldownMs); return tryAcquire(bucket, userId, cooldownMs);
} }
/**
* Per-user rate limit for {@code DeleteMentionEvent}.
*/
public boolean tryAcquireDelete(int userId) { public boolean tryAcquireDelete(int userId) {
long cooldownMs = Emulator.getConfig().getInt("mentions.delete.cooldown.ms", 500); long cooldownMs = Emulator.getConfig().getInt("mentions.delete.cooldown.ms", 500);
return tryAcquire(this.deleteCooldowns, userId, cooldownMs); return tryAcquire(this.deleteCooldowns, userId, cooldownMs);
@@ -397,11 +368,6 @@ public class MentionManager {
return true; return true;
} }
/**
* Periodically drop cooldown entries older than the largest window so the
* maps don't accumulate one entry per user-that-ever-played for the entire
* server lifetime.
*/
private void pruneCooldownsIfDue(long now) { private void pruneCooldownsIfDue(long now) {
if (now - this.lastPrune < PRUNE_INTERVAL_MS) return; if (now - this.lastPrune < PRUNE_INTERVAL_MS) return;
this.lastPrune = now; this.lastPrune = now;
@@ -448,20 +414,49 @@ public class MentionManager {
return value.substring(0, max); return value.substring(0, max);
} }
/** private boolean isBotOrPetName(Room room, String token) {
* Resolve a present room occupant from a raw mention token. Tries the token if (room == null || token == null || token.isEmpty()) return false;
* verbatim first (so usernames containing allowed punctuation such as '-',
* '.', '!' still match), then falls back to a trailing-punctuation-trimmed List<com.eu.habbo.habbohotel.bots.Bot> bots = room.getBots(token);
* form so a mention written as "@Bob!" still resolves the user "Bob". if (bots != null && !bots.isEmpty()) return true;
*/
if (room.getUnitManager() != null && room.getUnitManager().getPets() != null) {
for (com.eu.habbo.habbohotel.pets.Pet pet : room.getUnitManager().getPets()) {
if (pet != null && pet.getName() != null && pet.getName().equalsIgnoreCase(token)) {
return true;
}
}
}
return false;
}
private Habbo resolveHabbo(Room room, String rawToken) { private Habbo resolveHabbo(Room room, String rawToken) {
if (isBotOrPetName(room, rawToken)) {
return null;
}
String trimmedForBotCheck = trimTrailingPunctuation(rawToken);
if (!trimmedForBotCheck.equals(rawToken) && isBotOrPetName(room, trimmedForBotCheck)) {
return null;
}
Habbo habbo = room.getHabbo(rawToken); Habbo habbo = room.getHabbo(rawToken);
if (habbo != null) { if (habbo != null) {
return habbo; return habbo;
} }
HabboManager habboManager = Emulator.getGameEnvironment().getHabboManager();
habbo = habboManager.getHabbo(rawToken);
if (habbo != null) {
return habbo;
}
String trimmed = trimTrailingPunctuation(rawToken); String trimmed = trimTrailingPunctuation(rawToken);
if (!trimmed.isEmpty() && !trimmed.equals(rawToken)) { if (!trimmed.isEmpty() && !trimmed.equals(rawToken)) {
return room.getHabbo(trimmed); habbo = room.getHabbo(trimmed);
if (habbo != null) {
return habbo;
}
return habboManager.getHabbo(trimmed);
} }
return null; return null;
} }
@@ -94,6 +94,8 @@ public class HabboStats implements Runnable {
public boolean hasGottenDefaultSavedSearches; public boolean hasGottenDefaultSavedSearches;
private HabboInfo habboInfo; private HabboInfo habboInfo;
private boolean allowTrade; private boolean allowTrade;
private boolean mentionsEnabled;
private boolean massMentionsEnabled;
private int clubExpireTimestamp; private int clubExpireTimestamp;
private int muteEndTime; private int muteEndTime;
public int maxFriends; public int maxFriends;
@@ -131,6 +133,8 @@ public class HabboStats implements Runnable {
this.guilds = new ArrayList<>(); this.guilds = new ArrayList<>();
this.tags = set.getString("tags").split(";"); this.tags = set.getString("tags").split(";");
this.allowTrade = set.getString("can_trade").equals("1"); this.allowTrade = set.getString("can_trade").equals("1");
this.mentionsEnabled = "1".equals(safeColumnString(set, "mentions_enabled", "1"));
this.massMentionsEnabled = "1".equals(safeColumnString(set, "mass_mentions_enabled", "1"));
this.votedRooms = new TIntArrayStack(); this.votedRooms = new TIntArrayStack();
this.clubExpireTimestamp = set.getInt("club_expire_timestamp"); this.clubExpireTimestamp = set.getInt("club_expire_timestamp");
this.loginStreak = set.getInt("login_streak"); this.loginStreak = set.getInt("login_streak");
@@ -749,13 +753,6 @@ public class HabboStats implements Runnable {
return 0; return 0;
} }
/**
* Ignore an user.
*
* @param gameClient The client to which this HabboStats instance belongs.
* @param userId The user to ignore.
* @return true if successfully ignored, false otherwise.
*/
public boolean ignoreUser(GameClient gameClient, int userId) { public boolean ignoreUser(GameClient gameClient, int userId) {
final Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); final Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId);
@@ -805,6 +802,44 @@ public class HabboStats implements Runnable {
else return this.allowTrade; else return this.allowTrade;
} }
public boolean mentionsEnabled() {
return this.mentionsEnabled;
}
public boolean massMentionsEnabled() {
return this.massMentionsEnabled;
}
public void setMentionsEnabled(boolean enabled) {
this.mentionsEnabled = enabled;
persistFlag("mentions_enabled", enabled);
}
public void setMassMentionsEnabled(boolean enabled) {
this.massMentionsEnabled = enabled;
persistFlag("mass_mentions_enabled", enabled);
}
private void persistFlag(String column, boolean enabled) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement("UPDATE users_settings SET `" + column + "` = ? WHERE user_id = ? LIMIT 1")) {
statement.setString(1, enabled ? "1" : "0");
statement.setInt(2, this.habboInfo.getId());
statement.executeUpdate();
} catch (SQLException e) {
LOGGER.error("Failed to persist users_settings.{} for user {}", column, this.habboInfo.getId(), e);
}
}
private static String safeColumnString(ResultSet set, String column, String defaultValue) {
try {
String value = set.getString(column);
return value == null ? defaultValue : value;
} catch (SQLException e) {
return defaultValue;
}
}
public void setAllowTrade(boolean allowTrade) { public void setAllowTrade(boolean allowTrade) {
this.allowTrade = allowTrade; this.allowTrade = allowTrade;
} }
@@ -298,6 +298,8 @@ public class PacketManager {
this.registerHandler(Incoming.CatalogAdminPublishEvent, CatalogAdminPublishEvent.class); this.registerHandler(Incoming.CatalogAdminPublishEvent, CatalogAdminPublishEvent.class);
this.registerHandler(Incoming.CatalogAdminSavePageImagesEvent, CatalogAdminSavePageImagesEvent.class); this.registerHandler(Incoming.CatalogAdminSavePageImagesEvent, CatalogAdminSavePageImagesEvent.class);
this.registerHandler(Incoming.CatalogAdminSavePageIconEvent, CatalogAdminSavePageIconEvent.class); this.registerHandler(Incoming.CatalogAdminSavePageIconEvent, CatalogAdminSavePageIconEvent.class);
this.registerHandler(Incoming.CatalogAdminLoadOfferEvent, CatalogAdminLoadOfferEvent.class);
this.registerHandler(Incoming.CatalogAdminLoadPageEvent, CatalogAdminLoadPageEvent.class);
} }
private void registerEvent() throws Exception { private void registerEvent() throws Exception {
@@ -444,6 +444,8 @@ public class Incoming {
public static final int CatalogAdminPublishEvent = 10058; public static final int CatalogAdminPublishEvent = 10058;
public static final int CatalogAdminSavePageImagesEvent = 10060; public static final int CatalogAdminSavePageImagesEvent = 10060;
public static final int CatalogAdminSavePageIconEvent = 10061; public static final int CatalogAdminSavePageIconEvent = 10061;
public static final int CatalogAdminLoadOfferEvent = 10062;
public static final int CatalogAdminLoadPageEvent = 10063;
// Custom Prefixes // Custom Prefixes
public static final int RequestUserPrefixesEvent = 7011; public static final int RequestUserPrefixesEvent = 7011;
@@ -0,0 +1,55 @@
package com.eu.habbo.messages.incoming.catalog.catalogadmin;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogPageType;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminOfferDetailsComposer;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminResultComposer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class CatalogAdminLoadOfferEvent extends MessageHandler {
@Override
public void handle() throws Exception {
if (!this.client.getHabbo().hasPermission(Permission.ACC_CATALOGFURNI)) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "No permission"));
return;
}
int offerId = this.packet.readInt();
CatalogPageType pageType = CatalogPageType.fromString(this.packet.readString());
String sql = (pageType == CatalogPageType.BUILDER)
? "SELECT id, order_number FROM catalog_items_bc WHERE id = ? LIMIT 1"
: "SELECT id, offer_id, limited_stack, order_number FROM catalog_items WHERE id = ? LIMIT 1";
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, offerId);
try (ResultSet set = statement.executeQuery()) {
if (!set.next()) return;
if (pageType == CatalogPageType.BUILDER) {
this.client.sendResponse(new CatalogAdminOfferDetailsComposer(
set.getInt("id"),
0,
0,
set.getInt("order_number")
));
} else {
this.client.sendResponse(new CatalogAdminOfferDetailsComposer(
set.getInt("id"),
set.getInt("offer_id"),
set.getInt("limited_stack"),
set.getInt("order_number")
));
}
}
}
}
}
@@ -0,0 +1,28 @@
package com.eu.habbo.messages.incoming.catalog.catalogadmin;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.catalog.CatalogPage;
import com.eu.habbo.habbohotel.catalog.CatalogPageType;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.messages.incoming.MessageHandler;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminPageDetailsComposer;
import com.eu.habbo.messages.outgoing.catalog.catalogadmin.CatalogAdminResultComposer;
public class CatalogAdminLoadPageEvent extends MessageHandler {
@Override
public void handle() throws Exception {
if (!this.client.getHabbo().hasPermission(Permission.ACC_CATALOGFURNI)) {
this.client.sendResponse(new CatalogAdminResultComposer(false, "No permission"));
return;
}
int pageId = this.packet.readInt();
CatalogPageType pageType = CatalogPageType.fromString(this.packet.readString());
CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().getCatalogPage(pageId, pageType);
if (page == null) return;
this.client.sendResponse(new CatalogAdminPageDetailsComposer(page));
}
}
@@ -573,6 +573,8 @@ public class Outgoing {
// Catalog Admin // Catalog Admin
public static final int CatalogAdminResultComposer = 10059; public static final int CatalogAdminResultComposer = 10059;
public static final int CatalogAdminOfferDetailsComposer = 10062;
public static final int CatalogAdminPageDetailsComposer = 10063;
// Custom Prefixes // Custom Prefixes
public static final int UserPrefixesComposer = 7001; public static final int UserPrefixesComposer = 7001;
@@ -0,0 +1,29 @@
package com.eu.habbo.messages.outgoing.catalog.catalogadmin;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class CatalogAdminOfferDetailsComposer extends MessageComposer {
private final int offerId;
private final int offerIdGroup;
private final int limitedStack;
private final int orderNumber;
public CatalogAdminOfferDetailsComposer(int offerId, int offerIdGroup, int limitedStack, int orderNumber) {
this.offerId = offerId;
this.offerIdGroup = offerIdGroup;
this.limitedStack = limitedStack;
this.orderNumber = orderNumber;
}
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.CatalogAdminOfferDetailsComposer);
this.response.appendInt(this.offerId);
this.response.appendInt(this.offerIdGroup);
this.response.appendInt(this.limitedStack);
this.response.appendInt(this.orderNumber);
return this.response;
}
}
@@ -0,0 +1,27 @@
package com.eu.habbo.messages.outgoing.catalog.catalogadmin;
import com.eu.habbo.habbohotel.catalog.CatalogPage;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
public class CatalogAdminPageDetailsComposer extends MessageComposer {
private final CatalogPage page;
public CatalogAdminPageDetailsComposer(CatalogPage page) {
this.page = page;
}
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.CatalogAdminPageDetailsComposer);
this.response.appendInt(this.page.getId());
this.response.appendString(this.page.getCaption());
this.response.appendString(this.page.getPageName());
this.response.appendInt(this.page.getRank());
this.response.appendInt(this.page.getOrderNum());
this.response.appendBoolean(this.page.isVisible());
this.response.appendBoolean(this.page.isEnabled());
return this.response;
}
}
@@ -18,6 +18,7 @@ public class MentionReceivedComposer extends MessageComposer {
this.response.appendInt(this.mention.getId()); this.response.appendInt(this.mention.getId());
this.response.appendInt(this.mention.getSenderUserId()); this.response.appendInt(this.mention.getSenderUserId());
this.response.appendString(this.mention.getSenderUsername()); this.response.appendString(this.mention.getSenderUsername());
this.response.appendString(this.mention.getSenderFigure());
this.response.appendInt(this.mention.getRoomId()); this.response.appendInt(this.mention.getRoomId());
this.response.appendString(this.mention.getRoomName()); this.response.appendString(this.mention.getRoomName());
this.response.appendString(this.mention.getMessage()); this.response.appendString(this.mention.getMessage());
@@ -23,6 +23,7 @@ public class MentionsListComposer extends MessageComposer {
this.response.appendInt(mention.getId()); this.response.appendInt(mention.getId());
this.response.appendInt(mention.getSenderUserId()); this.response.appendInt(mention.getSenderUserId());
this.response.appendString(mention.getSenderUsername()); this.response.appendString(mention.getSenderUsername());
this.response.appendString(mention.getSenderFigure());
this.response.appendInt(mention.getRoomId()); this.response.appendInt(mention.getRoomId());
this.response.appendString(mention.getRoomName()); this.response.appendString(mention.getRoomName());
this.response.appendString(mention.getMessage()); this.response.appendString(mention.getMessage());
+1 -1
View File
@@ -10,7 +10,7 @@ and is developed for free by talented developers and is compatible with the foll
[Latest compiled version](https://github.com/duckietm/Arcturus-Morningstar-Extended/tree/main/Latest_Compiled_Version) [Latest compiled version](https://github.com/duckietm/Arcturus-Morningstar-Extended/tree/main/Latest_Compiled_Version)
## Connection ## ## Connection ##
Use the Websocket plugin! Use the BUILD-IN Websocket so do NOT load any websocket plugin!
### How do I connect to my emulator using Secure Websockets (wss)? ### How do I connect to my emulator using Secure Websockets (wss)?
You have several options to add WSS support to your websocket server. You have several options to add WSS support to your websocket server.