-
Notifications
You must be signed in to change notification settings - Fork 0
/
vip.go
87 lines (69 loc) · 1.9 KB
/
vip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package rcon
import (
"fmt"
"strconv"
"strings"
)
// VIP represents a Player with some elevated privileges.
type VIP struct {
Player
}
// SetVIPSlots will update the current number of joinable VIPs.
func (c *Conn) SetVIPSlots(slots int) error {
_, err := c.send("setnumvipslots", strconv.Itoa(slots))
if err != nil {
return fmt.Errorf("failed to set vip slots: %v", err)
}
return nil
}
var x = make(chan bool)
// Admins will return a slice of active Admins.
func (c *Conn) VIPs() ([]VIP, error) {
result, err := c.send("get", "vipids")
if err != nil {
return nil, fmt.Errorf("failed to get information for all vips: %v", err)
}
args := strings.Split(result, "\t")
if len(args) == 0 {
return nil, fmt.Errorf("failed to parse information for all vips")
}
vips := []VIP{}
for _, v := range args[1 : len(args)-1] {
nameID := strings.Split(v, " ")
vips = append(vips, VIP{
Player: Player{
Name: strings.Trim(strings.TrimSpace(nameID[1]), `"`),
ID64: strings.TrimSpace(nameID[0]),
},
})
}
return vips, nil
}
// Add will add a new VIP.
func (c *Conn) VIPAdd(v VIP) error {
_, err := c.send("vipadd", q(v.ID64), q(v.Name))
if err != nil {
return fmt.Errorf("failed to add vip %s: %v", v.String(), err)
}
return nil
}
// Remove will remove a VIP.
func (c *Conn) VIPRemove(v VIP) error {
_, err := c.send("vipdel", v.ID64)
if err != nil {
return fmt.Errorf("failed to remove vip %s: %v", v.String(), err)
}
return nil
}
// VIPSlots will return the current number of joinable VIPs.
func (c *Conn) VIPSlots() (int, error) {
result, err := c.send("get", "numvipslots")
if err != nil {
return -1, fmt.Errorf("failed to get vip slots: %v", err)
}
s, err := strconv.Atoi(result)
if err != nil {
return -1, fmt.Errorf("failed to parse information for vip slots: %v", err)
}
return s, nil
}