Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/usercommands/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Go(rest string, user *users.UserRecord, room *rooms.Room, flags UserCommand

if exitInfo.ExitMessage != `` && !flags.Has(CmdIsRequeue) {
user.SendText(exitInfo.ExitMessage)
user.CommandFlagged(rest, uint64(flags)|uint64(CmdIsRequeue), configs.GetConfig().SecondsToTurns(1))
user.CommandFlagged(rest, uint64(flags|CmdIsRequeue|BlockInput), configs.GetConfig().SecondsToTurns(1))
return true, nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/usercommands/usercommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func (f UserCommandFlag) Has(flag UserCommandFlag) bool {
const (
CmdNone UserCommandFlag = 0
CmdSecretly UserCommandFlag = 1 << iota // User beahvior should not be alerted to the room
CmdIsRequeue // This command was a requeue. The flag is intended to avoid a infinite requeue loop.
CmdIsRequeue // This command was a requeue. The flag is intended to help avoid a infinite requeue loop.
BlockInput // If queuing for multiple turns, use this to block any user input in the meantime.
)

var (
Expand Down
25 changes: 25 additions & 0 deletions world.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (wi WorldInput) Id() int {

type World struct {
worldInput chan WorldInput
ignoreInput map[int]struct{}
enterWorldUserId chan [2]int
leaveWorldUserId chan int
logoutConnectionId chan connections.ConnectionId
Expand All @@ -59,6 +60,7 @@ func NewWorld(osSignalChan chan os.Signal) *World {

w := &World{
worldInput: make(chan WorldInput),
ignoreInput: make(map[int]struct{}),
enterWorldUserId: make(chan [2]int),
leaveWorldUserId: make(chan int),
logoutConnectionId: make(chan connections.ConnectionId),
Expand All @@ -73,6 +75,9 @@ func NewWorld(osSignalChan chan os.Signal) *World {
// Send input to the world.
// Just sends via a channel. Will block until read.
func (w *World) SendInput(i WorldInput) {
if _, ok := w.ignoreInput[i.FromId]; ok {
return // discard
}
w.worldInput <- i
}

Expand Down Expand Up @@ -1356,7 +1361,14 @@ func (w *World) TurnTick() {
}

if input.WaitTurns < 0 { // -1 and below, process immediately and don't count towards limit

w.processInput(input.UserId, input.InputText, usercommands.UserCommandFlag(input.Flags))

// If this command was potentially blocking input, unblock it now.
if input.Flags&uint64(usercommands.BlockInput) == uint64(usercommands.BlockInput) {
delete(w.ignoreInput, input.UserId)
}

continue
}

Expand All @@ -1366,9 +1378,22 @@ func (w *World) TurnTick() {
}

if input.WaitTurns == 0 { // 0 means process immediately but wait another turn before processing another from this user

w.processInput(input.UserId, input.InputText, usercommands.UserCommandFlag(input.Flags))

// If this command was potentially blocking input, unblock it now.
if input.Flags&uint64(usercommands.BlockInput) == uint64(usercommands.BlockInput) {
delete(w.ignoreInput, input.UserId)
}

alreadyProcessed[input.UserId] = struct{}{}
} else {

// If this is a multi-turn wait, block further input if flagged to do so
if input.Flags&uint64(usercommands.BlockInput) == uint64(usercommands.BlockInput) {
w.ignoreInput[input.UserId] = struct{}{}
}

input.WaitTurns--
events.Requeue(input)
}
Expand Down
Loading