fix(rcon): report missing offline credit targets

GiveCredits treated offline UPDATE execution as success without checking whether any user row was changed. Nonexistent user ids could therefore return an offline success response while granting nothing. Use executeUpdate(), return HABBO_NOT_FOUND when no row is affected, and keep SQL errors from falling through to the offline success message.
This commit is contained in:
simoleo89
2026-06-13 15:19:53 +02:00
parent 4330bf5a62
commit b94acdf719
2 changed files with 29 additions and 1 deletions
@@ -29,10 +29,14 @@ public class GiveCredits extends RCONMessage<GiveCredits.JSONGiveCredits> {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users SET credits = credits + ? WHERE id = ? LIMIT 1")) {
statement.setInt(1, object.credits);
statement.setInt(2, object.user_id);
statement.execute();
if (statement.executeUpdate() == 0) {
this.status = RCONMessage.HABBO_NOT_FOUND;
return;
}
} catch (SQLException e) {
this.status = RCONMessage.SYSTEM_ERROR;
LOGGER.error("Caught SQL exception", e);
return;
}
this.message = "offline";
@@ -0,0 +1,24 @@
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 GiveCreditsContractTest {
private static String giveCreditsSource() throws Exception {
return Files.readString(Path.of("src/main/java/com/eu/habbo/messages/rcon/GiveCredits.java"));
}
@Test
void offlineCreditGrantReportsMissingUsersWhenNoRowsChange() throws Exception {
String source = giveCreditsSource();
assertTrue(source.contains("executeUpdate()"),
"Offline RCON credit grants must inspect the affected row count");
assertTrue(source.contains("HABBO_NOT_FOUND"),
"Offline RCON credit grants must report missing users when the UPDATE changes no rows");
}
}