You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 23:36:19 +00:00
fix(rcon): upsert offline pixel grants
RCON GivePixels previously used an UPDATE for offline users, so users without an existing users_currency type 0 row received no pixels while the command still returned success. Match the GivePoints and housekeeping paths with an upsert and add a contract test that keeps offline pixel grants creating missing currency rows.
This commit is contained in:
@@ -26,10 +26,11 @@ public class GivePixels extends RCONMessage<GivePixels.JSONGivePixels> {
|
|||||||
if (habbo != null) {
|
if (habbo != null) {
|
||||||
habbo.givePixels(object.pixels);
|
habbo.givePixels(object.pixels);
|
||||||
} else {
|
} else {
|
||||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_currency SET users_currency.amount = users_currency.amount + ? WHERE users_currency.user_id = ? AND users_currency.type = 0")) {
|
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_currency (`user_id`, `type`, `amount`) VALUES (?, 0, ?) ON DUPLICATE KEY UPDATE amount = amount + ?")) {
|
||||||
statement.setInt(1, object.pixels);
|
statement.setInt(1, object.user_id);
|
||||||
statement.setInt(2, object.user_id);
|
statement.setInt(2, object.pixels);
|
||||||
statement.execute();
|
statement.setInt(3, object.pixels);
|
||||||
|
statement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
this.status = RCONMessage.SYSTEM_ERROR;
|
this.status = RCONMessage.SYSTEM_ERROR;
|
||||||
LOGGER.error("Caught SQL exception", e);
|
LOGGER.error("Caught SQL exception", e);
|
||||||
|
|||||||
@@ -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 GivePixelsContractTest {
|
||||||
|
private static String givePixelsSource() throws Exception {
|
||||||
|
return Files.readString(Path.of("src/main/java/com/eu/habbo/messages/rcon/GivePixels.java"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void offlinePixelGrantCreatesMissingCurrencyRow() throws Exception {
|
||||||
|
String source = givePixelsSource();
|
||||||
|
|
||||||
|
assertTrue(source.contains("INSERT INTO users_currency"),
|
||||||
|
"Offline RCON pixel grants must create the users_currency type 0 row when it is missing");
|
||||||
|
assertTrue(source.contains("ON DUPLICATE KEY UPDATE"),
|
||||||
|
"Offline RCON pixel grants should increment existing rows with an upsert");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user