fix(rcon): allow online motto updates outside rooms

SetMotto updated the in-memory motto and then unconditionally broadcast RoomUserData through the current room. Online users without a current room could throw a null-pointer exception after the state change, making the RCON call report an error despite mutating the user. Only broadcast room data when a room is present and cover the invariant with a contract test.
This commit is contained in:
simoleo89
2026-06-13 15:28:01 +02:00
parent d8260ec461
commit 4eafb54c57
2 changed files with 26 additions and 2 deletions
@@ -24,7 +24,9 @@ public class SetMotto extends RCONMessage<SetMotto.SetMottoJSON> {
if (habbo != null) {
habbo.getHabboInfo().setMotto(json.motto);
habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserDataComposer(habbo).compose());
if (habbo.getHabboInfo().getCurrentRoom() != null) {
habbo.getHabboInfo().getCurrentRoom().sendComposer(new RoomUserDataComposer(habbo).compose());
}
} else {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
try (PreparedStatement statement = connection.prepareStatement("UPDATE users SET motto = ? WHERE id = ? LIMIT 1")) {
@@ -45,4 +47,4 @@ public class SetMotto extends RCONMessage<SetMotto.SetMottoJSON> {
public String motto;
}
}
}
@@ -0,0 +1,22 @@
package com.eu.habbo.messages.rcon;
import org.junit.jupiter.api.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SetMottoContractTest {
private static String setMottoSource() throws Exception {
return Files.readString(Path.of("src/main/java/com/eu/habbo/messages/rcon/SetMotto.java"));
}
@Test
void onlineMottoUpdateDoesNotRequireCurrentRoom() throws Exception {
String source = setMottoSource();
assertTrue(source.contains("getCurrentRoom() != null"),
"RCON SetMotto must not fail for online users outside a room");
}
}