fix ID out of bounds detection; less unnecessary code
This commit is contained in:
parent
f17522a5d1
commit
2e7dd71bad
@ -490,8 +490,12 @@ func commandSwap(c *Client, args []string) {
|
|||||||
id--
|
id--
|
||||||
ids[i] = int(id)
|
ids[i] = int(id)
|
||||||
}
|
}
|
||||||
c.Messagef("Swapping: %d and %d.", ids[0]+1, ids[1]+1)
|
if c.QueueSwap(ids[0], ids[1]) {
|
||||||
c.QueueSwap(ids[0], ids[1])
|
c.Messagef("Swapped %d and %d.", ids[0]+1, ids[1]+1)
|
||||||
|
} else {
|
||||||
|
c.Messagef("ID out of bounds.")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandShuffle(c *Client) {
|
func commandShuffle(c *Client) {
|
||||||
|
14
main.go
14
main.go
@ -130,7 +130,7 @@ func (c *Client) QueueLen() int {
|
|||||||
// ok field returns false if the index is out of bounds.
|
// ok field returns false if the index is out of bounds.
|
||||||
func (c *Client) QueueAt(i int) (t Track, ok bool) {
|
func (c *Client) QueueAt(i int) (t Track, ok bool) {
|
||||||
l := c.QueueLen()
|
l := c.QueueLen()
|
||||||
if i >= l {
|
if i >= l || i < 0 {
|
||||||
return Track{}, false
|
return Track{}, false
|
||||||
}
|
}
|
||||||
c.RLock()
|
c.RLock()
|
||||||
@ -180,7 +180,7 @@ func (c *Client) QueueSwap(a, b int) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
l := c.QueueLen()
|
l := c.QueueLen()
|
||||||
if a >= l || b >= l {
|
if a >= l || b >= l || a < 0 || b < 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
c.Lock()
|
c.Lock()
|
||||||
@ -195,16 +195,6 @@ func (c *Client) QueueClear() {
|
|||||||
c.Unlock()
|
c.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) QueueFront() (t Track, ok bool) {
|
|
||||||
c.Lock()
|
|
||||||
defer c.Unlock()
|
|
||||||
if len(c.Queue) == 0 {
|
|
||||||
return Track{}, false
|
|
||||||
}
|
|
||||||
ret := *c.Queue[0]
|
|
||||||
return ret, true
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// Global variables.
|
// Global variables.
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user