aboutsummaryrefslogtreecommitdiff
path: root/internal/game/core_command_queue.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-18 18:38:35 -0400
committerhistoria <[not public]>2026-09-18 18:38:35 -0400
commit1f118d79e319da4e765502e9ca5b661772de94f1 (patch)
treebca8a3fd1e538f1c302480511e6ba872c92e10b8 /internal/game/core_command_queue.go
parent5ad42a51df4dcc5ccc3aa6a6d902085ce2ee4239 (diff)
downloadthehouseoficarus-1f118d79e319da4e765502e9ca5b661772de94f1.tar.gz
refactor: casino table core; fix: stake/migration/validation gaps
Diffstat (limited to 'internal/game/core_command_queue.go')
-rw-r--r--internal/game/core_command_queue.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/internal/game/core_command_queue.go b/internal/game/core_command_queue.go
index 28b7a36..8fce71d 100644
--- a/internal/game/core_command_queue.go
+++ b/internal/game/core_command_queue.go
@@ -106,23 +106,32 @@ func (q *CommandQueue) DeleteActive(name string) {
delete(q.activeQueue, name)
}
-// ActivePositions returns the sorted names of every player holding an active
-// command, and the position (1-indexed) of the named player among them, or 0
-// when that player has no active command. Used by the `queued` command to
-// show queue order.
+// ActivePositions returns the names of every player holding an active command
+// in actual resolution order (earliest Timestamp first, matching
+// ProcessQueuedCommands), and the 1-based position of the named player among
+// them, or 0 when that player has no active command. Used by the `queued`
+// command to show queue order.
func (q *CommandQueue) ActivePositions(name string) (names []string, pos int) {
q.mu.Lock()
defer q.mu.Unlock()
- for n := range q.activeQueue {
- names = append(names, n)
+ type entry struct {
+ name string
+ at time.Time
}
- sort.Strings(names)
- for i, n := range names {
- if n == name {
- return names, i + 1
+ entries := make([]entry, 0, len(q.activeQueue))
+ for n, qc := range q.activeQueue {
+ entries = append(entries, entry{name: n, at: qc.Timestamp})
+ }
+ sort.SliceStable(entries, func(i, j int) bool {
+ return entries[i].at.Before(entries[j].at)
+ })
+ for _, e := range entries {
+ names = append(names, e.name)
+ if e.name == name {
+ pos = len(names)
}
}
- return names, 0
+ return names, pos
}
// ClearPlayer drops every queued command for the player: free, active, and
@@ -145,11 +154,3 @@ func (q *CommandQueue) DrainConsume(name string) (*QueuedCommand, bool) {
delete(q.consumeQueue, name)
return qc, ok
}
-
-// ActiveCount returns the number of players with active commands. Used by the
-// `queued` command to show position.
-func (q *CommandQueue) ActiveCount() int {
- q.mu.Lock()
- defer q.mu.Unlock()
- return len(q.activeQueue)
-}