Persist first Lobby admission before queuing requests
All checks were successful
Lobby Account Provisioning Build / lobby-account (push) Successful in 41s
DuneRealms Plugin CI / plugins (push) Successful in 2m53s

This commit is contained in:
unimatrixgit 2026-12-02 12:04:59 +01:00
commit 22ec139d4a
5 changed files with 36 additions and 15 deletions

View file

@ -1,6 +1,6 @@
plugins { java } plugins { java }
group = "com.dunerealms" group = "com.dunerealms"
version = "1.0.0" version = "1.0.1"
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -50,6 +50,14 @@ final class AccountJournal {
} }
} }
Entry admit(UUID player, String name) throws IOException {
Entry entry = read(player);
if (entry != null) return entry;
entry = new Entry(player, UUID.randomUUID(), name, Phase.PENDING);
write(entry);
return entry;
}
void write(Entry entry) throws IOException { void write(Entry entry) throws IOException {
if (!validName(entry.name())) throw new IOException("Invalid verified player name"); if (!validName(entry.name())) throw new IOException("Invalid verified player name");
Path tmp = Files.createTempFile(folder, ".receipt-", ".tmp", permissions("rw-------")); Path tmp = Files.createTempFile(folder, ".receipt-", ".tmp", permissions("rw-------"));

View file

@ -104,29 +104,31 @@ public final class DuneLobbyAccount extends JavaPlugin implements Listener {
private void attempt(Player player) { private void attempt(Player player) {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
String liveName = player.getName(); String liveName = player.getName();
if (!running || !AccountJournal.validName(liveName) || finished.contains(uuid) || !active.add(uuid)) return;
String admittedName = firstAdmissions.get(uuid); String admittedName = firstAdmissions.get(uuid);
if (admittedName != null) {
try {
journal.admit(uuid, admittedName);
firstAdmissions.remove(uuid);
} catch (IOException unavailable) {
return; // Retry the local receipt before admitting any network work.
}
}
if (!running || !AccountJournal.validName(liveName) || finished.contains(uuid) || !active.add(uuid)) return;
try { try {
executor.execute(() -> process(player, uuid, liveName, admittedName)); executor.execute(() -> process(player, uuid, liveName));
} catch (RejectedExecutionException full) { } catch (RejectedExecutionException full) {
active.remove(uuid); active.remove(uuid);
} }
} }
private void process(Player player, UUID uuid, String liveName, String admittedName) { private void process(Player player, UUID uuid, String liveName) {
boolean terminal = false; boolean terminal = false;
boolean recorded = false;
try { try {
AccountJournal.Entry entry = journal.read(uuid); AccountJournal.Entry entry = journal.read(uuid);
if (entry == null) { if (entry == null) {
if (admittedName == null) { terminal = true;
terminal = true; return;
return;
}
entry = new AccountJournal.Entry(uuid, UUID.randomUUID(), admittedName, PENDING);
journal.write(entry);
} }
recorded = true;
if (entry.phase() == DONE || entry.phase() == HELD) { if (entry.phase() == DONE || entry.phase() == HELD) {
terminal = true; terminal = true;
return; return;
@ -137,10 +139,9 @@ public final class DuneLobbyAccount extends JavaPlugin implements Listener {
} catch (IOException | TimeoutException | ExecutionException unavailable) { } catch (IOException | TimeoutException | ExecutionException unavailable) {
// An uncertain response is retried using the same durable request on the next timer or join. // An uncertain response is retried using the same durable request on the next timer or join.
} finally { } finally {
boolean complete = terminal, hasReceipt = recorded; boolean complete = terminal;
onMain(() -> { onMain(() -> {
active.remove(uuid); active.remove(uuid);
if (hasReceipt) firstAdmissions.remove(uuid);
if (complete) finished.add(uuid); if (complete) finished.add(uuid);
}); });
} }

View file

@ -1,5 +1,5 @@
name: DuneLobbyAccount name: DuneLobbyAccount
version: 1.0.0 version: 1.0.1
main: com.dunerealms.lobbyaccount.DuneLobbyAccount main: com.dunerealms.lobbyaccount.DuneLobbyAccount
api-version: '1.21.8' api-version: '1.21.8'
description: Provisions ordinary DuneRealms accounts from authenticated first Lobby joins description: Provisions ordinary DuneRealms accounts from authenticated first Lobby joins

View file

@ -32,6 +32,18 @@ class LobbyAccountContractTest {
assertThrows(IOException.class, () -> restarted.write(new AccountJournal.Entry(request.player(), request.request(), "x\ny", PENDING))); assertThrows(IOException.class, () -> restarted.write(new AccountJournal.Entry(request.player(), request.request(), "x\ny", PENDING)));
} }
@Test void aPendingFirstJoinCanBeRecoveredBeforeAnyWorkerRan(@TempDir Path temp) throws Exception {
UUID player = request.player();
var first = new AccountJournal(temp.resolve("receipts"));
var admitted = first.admit(player, request.name());
var restarted = new AccountJournal(temp.resolve("receipts"));
assertEquals(admitted, restarted.read(player));
assertEquals(PENDING, admitted.phase());
assertEquals(admitted, restarted.admit(player, "Renamed"));
restarted.write(admitted.advance(ACK));
assertEquals(admitted.advance(ACK), first.admit(player, request.name()));
}
@Test void requestAndAcknowledgementHaveExactWireFields() { @Test void requestAndAcknowledgementHaveExactWireFields() {
JsonObject provision = LobbyAccountApi.request(request, false); JsonObject provision = LobbyAccountApi.request(request, false);
assertEquals(Set.of("action", "schema", "requestId", "uuid", "name"), provision.keySet()); assertEquals(Set.of("action", "schema", "requestId", "uuid", "name"), provision.keySet());