You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 07:26:18 +00:00
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:
@@ -24,7 +24,9 @@ public class SetMotto extends RCONMessage<SetMotto.SetMottoJSON> {
|
|||||||
|
|
||||||
if (habbo != null) {
|
if (habbo != null) {
|
||||||
habbo.getHabboInfo().setMotto(json.motto);
|
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 {
|
} else {
|
||||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) {
|
||||||
try (PreparedStatement statement = connection.prepareStatement("UPDATE users SET motto = ? WHERE id = ? LIMIT 1")) {
|
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;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user