-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientManger.go
83 lines (64 loc) · 1.13 KB
/
ClientManger.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
package model
import (
"ServerCommon/model"
"sync"
)
//保存所有对应IM的服务器
var clients ClientSet
var mutex sync.Mutex
func init() {
clients = NewClientSet()
}
func AddClient(client *Client) {
mutex.Lock()
defer mutex.Unlock()
clients.Add(client)
}
func RemoveClient(client *Client) {
mutex.Lock()
defer mutex.Unlock()
clients.Remove(client)
}
//clone clients
func GetClientSet() ClientSet {
mutex.Lock()
defer mutex.Unlock()
s := NewClientSet()
for c := range clients {
s.Add(c)
}
return s
}
func FindClientSet(id *model.AppUserID) ClientSet {
mutex.Lock()
defer mutex.Unlock()
s := NewClientSet()
for c := range clients {
if c.ContainAppUserID(id) {
s.Add(c)
}
}
return s
}
func FindRoomClientSet(id *model.AppRoomID) ClientSet {
mutex.Lock()
defer mutex.Unlock()
s := NewClientSet()
for c := range clients {
if c.ContainAppRoomID(id) {
s.Add(c)
}
}
return s
}
func IsUserOnline(appid, uid int64) bool {
mutex.Lock()
defer mutex.Unlock()
id := &model.AppUserID{Appid: appid, Uid: uid}
for c := range clients {
if c.IsAppUserOnline(id) {
return true
}
}
return false
}