mt-multiserver-proxy/players.go

46 lines
888 B
Go
Raw Normal View History

2021-09-06 02:03:27 -07:00
package proxy
import "sync"
var players = make(map[string]struct{})
var playersMu sync.RWMutex
2021-09-09 07:40:31 -07:00
2021-09-10 03:47:19 -07:00
// Players returns the names of all players
// that are currently connected to the proxy.
2021-09-09 07:40:31 -07:00
func Players() map[string]struct{} {
playersMu.RLock()
defer playersMu.RUnlock()
p := make(map[string]struct{})
for player := range players {
p[player] = struct{}{}
}
return p
}
2021-09-10 03:47:19 -07:00
// 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 {
2021-09-10 03:47:19 -07:00
for clt := range l.clients() {
clts[clt] = struct{}{}
}
}
return clts
}
2021-09-10 03:47:19 -07:00
// 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
}