You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 15:36:17 +00:00
feat(mentions): server-side delete packet + robust direct-nick resolution
This commit is contained in:
@@ -65,26 +65,24 @@ public class MentionManager {
|
|||||||
|
|
||||||
Set<String> aliases = this.roomAliases();
|
Set<String> aliases = this.roomAliases();
|
||||||
boolean roomBroadcast = false;
|
boolean roomBroadcast = false;
|
||||||
LinkedHashSet<String> directNicks = new LinkedHashSet<>();
|
LinkedHashSet<String> directTokens = new LinkedHashSet<>();
|
||||||
|
|
||||||
for (String token : message.split("\\s+")) {
|
for (String token : message.split("\\s+")) {
|
||||||
if (token.length() < 2 || token.charAt(0) != '@') {
|
if (token.length() < 2 || token.charAt(0) != '@') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String nick = token.substring(1).replaceAll("[^A-Za-z0-9_]", "").toLowerCase();
|
String raw = token.substring(1);
|
||||||
if (nick.isEmpty()) {
|
String aliasCandidate = trimTrailingPunctuation(raw).toLowerCase();
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aliases.contains(nick)) {
|
if (!aliasCandidate.isEmpty() && aliases.contains(aliasCandidate)) {
|
||||||
roomBroadcast = true;
|
roomBroadcast = true;
|
||||||
} else {
|
} else if (!raw.isEmpty()) {
|
||||||
directNicks.add(nick);
|
directTokens.add(raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!roomBroadcast && directNicks.isEmpty()) {
|
if (!roomBroadcast && directTokens.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,8 +104,8 @@ public class MentionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (String nick : directNicks) {
|
for (String token : directTokens) {
|
||||||
Habbo habbo = room.getHabbo(nick);
|
Habbo habbo = this.resolveHabbo(room, token);
|
||||||
if (habbo == null || habbo.getHabboInfo().getId() == senderId) {
|
if (habbo == null || habbo.getHabboInfo().getId() == senderId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -208,4 +206,44 @@ public class MentionManager {
|
|||||||
LOGGER.error("Failed to mark mentions as read.", e);
|
LOGGER.error("Failed to mark mentions as read.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(int userId, int mentionId) {
|
||||||
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection();
|
||||||
|
PreparedStatement statement = connection.prepareStatement(
|
||||||
|
"DELETE FROM habbo_mentions WHERE target_user_id = ? AND id = ?")) {
|
||||||
|
statement.setInt(1, userId);
|
||||||
|
statement.setInt(2, mentionId);
|
||||||
|
statement.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Failed to delete mention.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String TRAILING_PUNCTUATION = ".,!?;:)]}\"'";
|
||||||
|
|
||||||
|
private static String trimTrailingPunctuation(String value) {
|
||||||
|
int end = value.length();
|
||||||
|
while (end > 0 && TRAILING_PUNCTUATION.indexOf(value.charAt(end - 1)) >= 0) {
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
return value.substring(0, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a present room occupant from a raw mention token. Tries the token
|
||||||
|
* verbatim first (so usernames containing allowed punctuation such as '-',
|
||||||
|
* '.', '!' still match), then falls back to a trailing-punctuation-trimmed
|
||||||
|
* form so a mention written as "@Bob!" still resolves the user "Bob".
|
||||||
|
*/
|
||||||
|
private Habbo resolveHabbo(Room room, String rawToken) {
|
||||||
|
Habbo habbo = room.getHabbo(rawToken);
|
||||||
|
if (habbo != null) {
|
||||||
|
return habbo;
|
||||||
|
}
|
||||||
|
String trimmed = trimTrailingPunctuation(rawToken);
|
||||||
|
if (!trimmed.isEmpty() && !trimmed.equals(rawToken)) {
|
||||||
|
return room.getHabbo(trimmed);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -429,6 +429,7 @@ public class PacketManager {
|
|||||||
void registerRooms() throws Exception {
|
void registerRooms() throws Exception {
|
||||||
this.registerHandler(Incoming.RequestMentionsEvent, RequestMentionsEvent.class);
|
this.registerHandler(Incoming.RequestMentionsEvent, RequestMentionsEvent.class);
|
||||||
this.registerHandler(Incoming.MarkMentionsReadEvent, MarkMentionsReadEvent.class);
|
this.registerHandler(Incoming.MarkMentionsReadEvent, MarkMentionsReadEvent.class);
|
||||||
|
this.registerHandler(Incoming.DeleteMentionEvent, DeleteMentionEvent.class);
|
||||||
this.registerHandler(Incoming.RequestRoomLoadEvent, RequestRoomLoadEvent.class);
|
this.registerHandler(Incoming.RequestRoomLoadEvent, RequestRoomLoadEvent.class);
|
||||||
this.registerHandler(Incoming.RequestHeightmapEvent, RequestRoomHeightmapEvent.class);
|
this.registerHandler(Incoming.RequestHeightmapEvent, RequestRoomHeightmapEvent.class);
|
||||||
this.registerHandler(Incoming.RequestRoomHeightmapEvent, RequestRoomHeightmapEvent.class);
|
this.registerHandler(Incoming.RequestRoomHeightmapEvent, RequestRoomHeightmapEvent.class);
|
||||||
|
|||||||
@@ -498,4 +498,5 @@ public class Incoming {
|
|||||||
public static final int SoundboardSetEnabledEvent = 9307;
|
public static final int SoundboardSetEnabledEvent = 9307;
|
||||||
public static final int RequestMentionsEvent = 4803;
|
public static final int RequestMentionsEvent = 4803;
|
||||||
public static final int MarkMentionsReadEvent = 4804;
|
public static final int MarkMentionsReadEvent = 4804;
|
||||||
|
public static final int DeleteMentionEvent = 4805;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.eu.habbo.messages.incoming.mentions;
|
||||||
|
|
||||||
|
import com.eu.habbo.Emulator;
|
||||||
|
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||||
|
|
||||||
|
public class DeleteMentionEvent extends MessageHandler {
|
||||||
|
@Override
|
||||||
|
public void handle() throws Exception {
|
||||||
|
int userId = this.client.getHabbo().getHabboInfo().getId();
|
||||||
|
int mentionId = this.packet.readInt();
|
||||||
|
|
||||||
|
Emulator.getGameEnvironment().getMentionManager().delete(userId, mentionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user