mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-17 21:12:11 +00:00
feat(multiplayer): bind admissions to durable leases
This commit is contained in:
@@ -641,7 +641,7 @@ func TestPostgreSQLConnectionReceiptsStartCompleteRelaxedCasualRoster(t *testing
|
||||
if _, err := ClaimPlayerConnection(ctx, db, binding, "connect-player-0", 0, "connect-receipt-key-0000", now.Add(4*time.Second)); !errors.Is(err, domain.ErrConflict) {
|
||||
t.Fatalf("stale connect replay err=%v, want conflict", err)
|
||||
}
|
||||
if generation, err := ClaimPlayerConnection(ctx, db, binding, "connect-player-0", 1, "reconnect-receipt-0000", now.Add(63*time.Second)); err != nil || generation != 2 {
|
||||
if generation, err := ClaimPlayerConnection(ctx, db, binding, "connect-player-0", 0, "reconnect-receipt-0000", now.Add(63*time.Second)); err != nil || generation != 2 {
|
||||
t.Fatalf("grace-boundary reconnect generation=%d err=%v", generation, err)
|
||||
}
|
||||
if err := RecordPlayerDisconnected(ctx, db, binding, "connect-player-0", 1, "stale-disconnect-0000", now.Add(64*time.Second)); !errors.Is(err, domain.ErrConflict) {
|
||||
|
||||
@@ -78,7 +78,10 @@ func ClaimPlayerConnection(ctx context.Context, db *sql.DB, binding domain.Workl
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if current != expectedGeneration || expectedGeneration == ^uint64(0) {
|
||||
// A fresh process has no in-memory generation. It may recover only a
|
||||
// durably disconnected lease; an active row still fences it. All
|
||||
// nonzero expectations remain exact CAS operations.
|
||||
if (current != expectedGeneration && !(expectedGeneration == 0 && current > 0 && disconnectedAt.Valid)) || expectedGeneration == ^uint64(0) {
|
||||
return domain.ErrConflict
|
||||
}
|
||||
if current == 0 {
|
||||
|
||||
Reference in New Issue
Block a user