-
Notifications
You must be signed in to change notification settings - Fork 6
/
players.go
45 lines (36 loc) · 888 Bytes
/
players.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
package proxy
import "sync"
var players = make(map[string]struct{})
var playersMu sync.RWMutex
// Players returns the names of all players
// that are currently connected to the proxy.
func Players() map[string]struct{} {
playersMu.RLock()
defer playersMu.RUnlock()
p := make(map[string]struct{})
for player := range players {
p[player] = struct{}{}
}
return p
}
// Clts returns all ClientConns currently connected to the proxy.
func Clts() map[*ClientConn]struct{} {
clts := make(map[*ClientConn]struct{})
lm := allListeners()
for l := range lm {
for clt := range l.clients() {
clts[clt] = struct{}{}
}
}
return clts
}
// Find returns the ClientConn that has the specified player name.
// If no ClientConn is found, nil is returned.
func Find(name string) *ClientConn {
for clt := range Clts() {
if clt.Name() == name {
return clt
}
}
return nil
}