Unlock commands now support a given time, e.g 10 minutes.
This commit is contained in:
@@ -145,6 +145,41 @@ func (g *Hall) SetLocked(locked bool, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
type ConditionalUnlockResult uint8
|
||||
|
||||
const (
|
||||
ConditionalUnlockSucceeded ConditionalUnlockResult = iota
|
||||
ConditionalUnlockAlreadyUnlocked
|
||||
ConditionalUnlockClientAbsent
|
||||
ConditionalUnlockClientNotOperator
|
||||
)
|
||||
|
||||
// UnlockIfOperatorPresent atomically verifies that c is still in this hall
|
||||
// with operator permission and unlocks the hall if so.
|
||||
func (g *Hall) UnlockIfOperatorPresent(c Client) ConditionalUnlockResult {
|
||||
g.mu.Lock()
|
||||
if g.locked == nil {
|
||||
g.mu.Unlock()
|
||||
return ConditionalUnlockAlreadyUnlocked
|
||||
}
|
||||
if g.getClientUnlocked(c.Id()) != c {
|
||||
g.mu.Unlock()
|
||||
return ConditionalUnlockClientAbsent
|
||||
}
|
||||
if !member("op", c.Permissions()) {
|
||||
g.mu.Unlock()
|
||||
return ConditionalUnlockClientNotOperator
|
||||
}
|
||||
g.locked = nil
|
||||
clients := g.getClientsUnlocked(nil)
|
||||
g.mu.Unlock()
|
||||
|
||||
for _, client := range clients {
|
||||
client.Joined(g.Name(), "change")
|
||||
}
|
||||
return ConditionalUnlockSucceeded
|
||||
}
|
||||
|
||||
func (g *Hall) Data() map[string]interface{} {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user