commit 85a2e8d6a4628cf8f37f3cb2a16d84d1aecb39ab
parent f197debe1cb08aca0a9058860337c8a6e430b01c
Author: anon <anon@example.com>
Date: Fri, 6 Nov 2026 06:11:36 +0000
Preserve save-time name conflicts for visitor retry
Diffstat:
5 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/docs/browser-accounts.md b/docs/browser-accounts.md
@@ -95,6 +95,16 @@ stored password credential, not the name's spelling, so a visitor can adopt
its generated name without losing its character or mistaking itself for a
duplicate account.
+Focused account and creation checks pass with generated names, including cold
+loading, keeping a generated name during adoption, 32 concurrent launches,
+case-insensitive collisions and failed-save cleanup. The launch collision and
+concurrency checks also pass under the race detector. An INSERT-boundary
+collision regression verifies rollback and retry when a name becomes unavailable
+after the initial lookup: player insertion ignores only an existing ID, allowing
+the name uniqueness error to reach the retry loop. The shared team fixture now
+uses distinct member names; its team, chat, buddy, inspection and affected armor
+checks pass. The full server regression run is still pending.
+
User-chosen names follow the original creator: remove characters other than
ASCII letters and digits, capitalize the first letter and lowercase the rest,
then require
diff --git a/server/database.go b/server/database.go
@@ -159,7 +159,7 @@ func (record characterRecord) character() *character {
}
func insertRecord(tx *sql.Tx, table string, id uint32, columns string, fields []any) error {
- query := "INSERT OR IGNORE INTO " + table + " (id, " + columns + ") VALUES (?" + strings.Repeat(", ?", len(fields)) + ")"
+ query := "INSERT INTO " + table + " (id, " + columns + ") VALUES (?" + strings.Repeat(", ?", len(fields)) + ") ON CONFLICT(id) DO NOTHING"
_, err := tx.Exec(query, append([]any{id}, fields...)...)
return err
}
diff --git a/server/team_chat_test.go b/server/team_chat_test.go
@@ -328,7 +328,7 @@ func TestTeamChatRestartRestoresMembershipAndOnlyReceivedHistory(t *testing.T) {
expectTeamChatGroup(t, reconnected, 60, team)
kind, body, err := readChatPacket(reconnected)
- if err != nil || kind != 36 || !bytes.Contains(body, []byte("[Team] Member: before restart")) {
+ if err != nil || kind != 36 || !bytes.Contains(body, []byte("[Team] Member1: before restart")) {
t.Fatalf("private restored history: %d %s %v", kind, body, err)
}
expectChatPing(t, reconnected)
diff --git a/server/teams_test.go b/server/teams_test.go
@@ -2,6 +2,7 @@ package main
import (
"encoding/binary"
+ "fmt"
"reflect"
"strings"
"sync"
@@ -17,7 +18,7 @@ func newTeamWorld(t *testing.T) (*server, []*combatTestConn) {
player := world.newCharacter()
player.stats = testCharacterStats()
player.health = player.maximumHealth()
- player.name = "Member"
+ player.name = fmt.Sprintf("Member%d", id)
if err := world.saveUser_locked(player); err != nil {
t.Fatal(err)
}
diff --git a/server/visitor_names_test.go b/server/visitor_names_test.go
@@ -108,6 +108,41 @@ func TestBrowserLaunchRetriesCaseInsensitiveNameCollision(t *testing.T) {
}
}
+func TestBrowserLaunchRetriesNameClaimedDuringSave(t *testing.T) {
+ world := newTestServer(t)
+ existing := world.newCharacter()
+ profile := existing.userData()
+ profile.Name = "Existing"
+ if err := world.updateUser(profile); err != nil {
+ t.Fatal(err)
+ }
+ // Claim the candidate after the availability check, at the INSERT boundary.
+ if _, err := world.db.Exec("CREATE TRIGGER claim_candidate BEFORE INSERT ON characters WHEN NEW.id=2 AND NEW.name='Bababa' BEGIN UPDATE characters SET name=NEW.name WHERE id=1; END"); err != nil {
+ t.Fatal(err)
+ }
+ original := visitorNameRoll
+ t.Cleanup(func() { visitorNameRoll = original })
+ calls := 0
+ visitorNameRoll = func(int) int {
+ calls++
+ if calls == 6 {
+ return 1
+ }
+ return 0
+ }
+ response := httptest.NewRecorder()
+
+ world.browserLaunch(response, httptest.NewRequest("POST", "/browser-launch", nil))
+
+ var savedName string
+ if err := world.db.QueryRow("SELECT name FROM characters WHERE id=1").Scan(&savedName); err != nil {
+ t.Fatal(err)
+ }
+ if response.Code != http.StatusOK || calls != 6 || world.characters[2].name != "Bababe" || savedName != "Existing" {
+ t.Fatal("save-time name conflict did not roll back and retry", response.Code, calls, savedName, response.Body)
+ }
+}
+
func TestBrowserLaunchConcurrentNamesStayUnique(t *testing.T) {
world := newTestServer(t)
responses := make(chan *httptest.ResponseRecorder, 32)