forked from layeh/gumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
222 lines (189 loc) · 6.5 KB
/
event.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package gumble
import (
"github.com/bmmcginty/gumble/gumble/MumbleProto"
)
// EventListener is the interface that must be implemented by a type if it
// wishes to be notified of Client events.
//
// Listener methods are executed synchronously as event happen. They also block
// network reads from happening until all handlers for an event are called.
// Therefore, it is not recommended to do any long processing from inside of
// these methods.
type EventListener interface {
OnConnect(e *ConnectEvent)
OnDisconnect(e *DisconnectEvent)
OnTextMessage(e *TextMessageEvent)
OnUserChange(e *UserChangeEvent)
OnChannelChange(e *ChannelChangeEvent)
OnPermissionDenied(e *PermissionDeniedEvent)
OnUserList(e *UserListEvent)
OnACL(e *ACLEvent)
OnBanList(e *BanListEvent)
OnContextActionChange(e *ContextActionChangeEvent)
OnServerConfig(e *ServerConfigEvent)
}
// ConnectEvent is the event that is passed to EventListener.OnConnect.
type ConnectEvent struct {
Client *Client
WelcomeMessage *string
MaximumBitrate *int
}
// DisconnectType specifies why a Client disconnected from a server.
type DisconnectType int
// Client disconnect reasons.
const (
DisconnectError DisconnectType = iota + 1
DisconnectKicked
DisconnectBanned
DisconnectUser
)
// Has returns true if the DisconnectType has changeType part of its bitmask.
func (d DisconnectType) Has(changeType DisconnectType) bool {
return d&changeType == changeType
}
// DisconnectEvent is the event that is passed to EventListener.OnDisconnect.
type DisconnectEvent struct {
Client *Client
Type DisconnectType
String string
}
// TextMessageEvent is the event that is passed to EventListener.OnTextMessage.
type TextMessageEvent struct {
Client *Client
TextMessage
}
// UserChangeType is a bitmask of items that changed for a user.
type UserChangeType int
// User change items.
const (
UserChangeConnected UserChangeType = 1 << iota
UserChangeDisconnected
UserChangeKicked
UserChangeBanned
UserChangeRegistered
UserChangeUnregistered
UserChangeName
UserChangeChannel
UserChangeComment
UserChangeAudio
UserChangeTexture
UserChangePrioritySpeaker
UserChangeRecording
UserChangeStats
)
// Has returns true if the UserChangeType has changeType part of its bitmask.
func (u UserChangeType) Has(changeType UserChangeType) bool {
return u&changeType == changeType
}
// UserChangeEvent is the event that is passed to EventListener.OnUserChange.
type UserChangeEvent struct {
Client *Client
Type UserChangeType
User *User
Actor *User
String string
}
// ChannelChangeType is a bitmask of items that changed for a channel.
type ChannelChangeType int
// Channel change items.
const (
ChannelChangeCreated ChannelChangeType = 1 << iota
ChannelChangeRemoved
ChannelChangeMoved
ChannelChangeName
ChannelChangeLinks
ChannelChangeDescription
ChannelChangePosition
ChannelChangePermission
ChannelChangeMaxUsers
)
// Has returns true if the ChannelChangeType has changeType part of its
// bitmask.
func (c ChannelChangeType) Has(changeType ChannelChangeType) bool {
return c&changeType == changeType
}
// ChannelChangeEvent is the event that is passed to
// EventListener.OnChannelChange.
type ChannelChangeEvent struct {
Client *Client
Type ChannelChangeType
Channel *Channel
}
// PermissionDeniedType specifies why a Client was denied permission to perform
// a particular action.
type PermissionDeniedType int
// Permission denied types.
const (
PermissionDeniedOther PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_Text)
PermissionDeniedPermission PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_Permission)
PermissionDeniedSuperUser PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_SuperUser)
PermissionDeniedInvalidChannelName PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_ChannelName)
PermissionDeniedTextTooLong PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_TextTooLong)
PermissionDeniedTemporaryChannel PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_TemporaryChannel)
PermissionDeniedMissingCertificate PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_MissingCertificate)
PermissionDeniedInvalidUserName PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_UserName)
PermissionDeniedChannelFull PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_ChannelFull)
PermissionDeniedNestingLimit PermissionDeniedType = PermissionDeniedType(MumbleProto.PermissionDenied_NestingLimit)
)
// Has returns true if the PermissionDeniedType has changeType part of its
// bitmask.
func (p PermissionDeniedType) Has(changeType PermissionDeniedType) bool {
return p&changeType == changeType
}
// PermissionDeniedEvent is the event that is passed to
// EventListener.OnPermissionDenied.
type PermissionDeniedEvent struct {
Client *Client
Type PermissionDeniedType
Channel *Channel
User *User
Permission Permission
String string
}
// UserListEvent is the event that is passed to EventListener.OnUserList.
type UserListEvent struct {
Client *Client
UserList RegisteredUsers
}
// ACLEvent is the event that is passed to EventListener.OnACL.
type ACLEvent struct {
Client *Client
ACL *ACL
}
// BanListEvent is the event that is passed to EventListener.OnBanList.
type BanListEvent struct {
Client *Client
BanList BanList
}
// ContextActionChangeType specifies how a ContextAction changed.
type ContextActionChangeType int
// ContextAction change types.
const (
ContextActionAdd ContextActionChangeType = ContextActionChangeType(MumbleProto.ContextActionModify_Add)
ContextActionRemove ContextActionChangeType = ContextActionChangeType(MumbleProto.ContextActionModify_Remove)
)
// ContextActionChangeEvent is the event that is passed to
// EventListener.OnContextActionChange.
type ContextActionChangeEvent struct {
Client *Client
Type ContextActionChangeType
ContextAction *ContextAction
}
// ServerConfigEvent is the event that is passed to
// EventListener.OnServerConfig.
type ServerConfigEvent struct {
Client *Client
MaximumBitrate *int
WelcomeMessage *string
AllowHTML *bool
MaximumMessageLength *int
MaximumImageMessageLength *int
MaximumUsers *int
CodecAlpha *int32
CodecBeta *int32
CodecPreferAlpha *bool
CodecOpus *bool
SuggestVersion *Version
SuggestPositional *bool
SuggestPushToTalk *bool
}