-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.go
1675 lines (1449 loc) · 46.7 KB
/
message.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2010 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.
package main
import (
"crypto/aes"
"crypto/tls"
"fmt"
"strconv"
"time"
"google.golang.org/protobuf/proto"
"github.com/wfjsw/hall/mumbleproto"
)
// Message describes an incoming proto message
type Message struct {
buf []byte
kind uint16
client *Client
}
// VoiceBroadcast describes an incoming voice packet
type VoiceBroadcast struct {
// The client who is performing the broadcast
client *Client
// The VoiceTarget identifier.
target byte
// The voice packet itself.
buf []byte
}
func (server *Server) handleCryptSetup(client *Client, msg *Message) {
cs := &mumbleproto.CryptSetup{}
err := proto.Unmarshal(msg.buf, cs)
if err != nil {
panic(err) // Caught by incoming message hub
}
// No client nonce. This means the client
// is requesting that we re-sync our nonces.
if len(cs.ClientNonce) == 0 {
client.Debugf("Client requested crypt-nonce resync")
cs.ServerNonce = make([]byte, aes.BlockSize)
func() {
client.crypt.Lock()
defer client.crypt.Unlock()
if copy(cs.ServerNonce, client.crypt.EncryptIV[0:]) != aes.BlockSize {
panic("Unable to copy nonce to server state")
}
}()
err := client.sendMessage(cs)
if err != nil {
panic(err) // Caught by incoming message hub
}
} else {
client.Debugf("Received client nonce")
if len(cs.ClientNonce) != aes.BlockSize {
panic(fmt.Sprintf("Invalid client nonce length: %d", len(cs.ClientNonce)))
}
func() {
client.crypt.Lock()
defer client.crypt.Unlock()
client.crypt.Resync++
if copy(client.crypt.DecryptIV[0:], cs.ClientNonce) != aes.BlockSize {
panic("Unable to copy nonce to client state")
}
client.Debugf("Crypt re-sync successful")
}()
}
}
func (server *Server) handlePingMessage(client *Client, msg *Message) {
defer client.recover(nil)
ping := &mumbleproto.Ping{}
err := proto.Unmarshal(msg.buf, ping)
if err != nil {
panic(err) // Caught by tlsRecvLoop
}
client.statsMutex.Lock()
defer client.statsMutex.Unlock()
client.crypt.Lock()
defer client.crypt.Unlock()
client.LastPing = time.Now().Unix()
if ping.Good != nil {
client.crypt.RemoteGood = *ping.Good
}
if ping.Late != nil {
client.crypt.RemoteLate = *ping.Late
}
if ping.Lost != nil {
client.crypt.RemoteLost = *ping.Lost
}
if ping.Resync != nil {
client.crypt.RemoteResync = *ping.Resync
}
if ping.UdpPingAvg != nil {
client.UDPPingAvg = *ping.UdpPingAvg
}
if ping.UdpPingVar != nil {
client.UDPPingVar = *ping.UdpPingVar
}
if ping.UdpPackets != nil {
client.UDPPackets = *ping.UdpPackets
}
if ping.TcpPingAvg != nil {
client.TCPPingAvg = *ping.TcpPingAvg
}
if ping.TcpPingVar != nil {
client.TCPPingVar = *ping.TcpPingVar
}
if ping.TcpPackets != nil {
client.TCPPackets = *ping.TcpPackets
}
err = client.sendMessage(&mumbleproto.Ping{
Timestamp: ping.Timestamp,
Good: proto.Uint32(client.crypt.Good),
Late: proto.Uint32(client.crypt.Late),
Lost: proto.Uint32(client.crypt.Lost),
Resync: proto.Uint32(client.crypt.Resync),
})
if err != nil {
panic(err) // Caught by tlsRecvLoop
}
client.recalcUnstableUDP()
}
func (server *Server) handleChannelRemoveMessage(client *Client, msg *Message) {
chanremove := &mumbleproto.ChannelRemove{}
err := proto.Unmarshal(msg.buf, chanremove)
if err != nil {
panic(err) // Caught by incoming message hub
}
if chanremove.ChannelId == nil {
return
}
channel := server.GetChannel(int(*chanremove.ChannelId))
if channel == nil {
return
}
if !HasPermission(channel, client, WritePermission, []string{}) {
client.sendPermissionDenied(client, channel, WritePermission)
return
}
server.RemoveChannel(channel)
}
// Handle channel state change.
func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
chanstate := &mumbleproto.ChannelState{}
err := proto.Unmarshal(msg.buf, chanstate)
if err != nil {
panic(err) // Caught by incoming message hub
}
var channel *Channel
var parent *Channel
// var ok bool
// Lookup channel for channel ID
if chanstate.ChannelId != nil {
channel = server.GetChannel(int(*chanstate.ChannelId))
if channel == nil {
panic("Invalid channel specified in ChannelState message") // Caught by incoming message hub
}
}
// Lookup parent
if chanstate.Parent != nil {
parent = server.GetChannel(int(*chanstate.Parent))
if parent == nil {
panic("Invalid parent channel specified in ChannelState message") // Caught by incoming message hub
}
}
// The server can't receive links through the links field in the ChannelState message,
// because clients are supposed to send modifications to a channel's link state through
// the links_add and links_remove fields.
// Make sure the links field is clear so we can transmit the channel's link state in our reply.
chanstate.Links = nil
var name string
var description string
// Extract the description and perform sanity checks.
if chanstate.Description != nil {
description, err = server.FilterText(*chanstate.Description)
if err != nil {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
return
}
}
// Extract the the name of channel and check whether it's valid.
// A valid channel name is a name that:
// a) Isn't already used by a channel at the same level as the channel itself (that is, channels
// that have a common parent can't have the same name.
// b) A name must be a valid name on the server (it must pass the channel name regexp)
if chanstate.Name != nil {
name = *chanstate.Name
// We don't allow renames for the root channel.
if channel != nil && channel.ID > 0 {
// Pick a parent. If the name change is part of a re-parent (a channel move),
// we must evaluate the parent variable. Since we're explicitly exlcuding the root
// channel from renames, channels that are the target of renames are guaranteed to have
// a parent.
evalp := parent
if evalp == nil {
evalp = channel.Parent()
}
for _, iter := range evalp.Childrens() {
if iter.Name == name {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_ChannelName)
return
}
}
}
}
// If the channel does not exist already, the ChannelState message is a create operation.
if channel == nil {
if parent == nil || len(name) == 0 {
return
}
// Check whether the client has permission to create the channel in parent.
perm := Permission(NonePermission)
if *chanstate.Temporary {
// perm = Permission(acl.TempChannelPermission)
client.sendPermissionDeniedText("Temporary channel is not implemented.")
return
}
perm = Permission(MakeChannelPermission)
if !HasPermission(parent, client, perm, []string{}) {
client.sendPermissionDenied(client, parent, perm)
return
}
// Only registered users can create channels.
if !client.IsRegistered() && !client.HasCertificate() {
client.sendPermissionDeniedTypeUser(mumbleproto.PermissionDenied_MissingCertificate, client)
return
}
// We can't add channels to a temporary channel
if parent.IsTemporary() {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TemporaryChannel)
return
}
key := ""
if len(description) > 0 {
key, err = blobStore.Put([]byte(description))
if err != nil {
server.Fatalf("Blobstore error: %v", err)
}
}
// Add the new channel
channel = server.NewChannel(name)
channel.DescriptionBlob = key
// channel.temporary = *chanstate.Temporary
channel.Position = int(*chanstate.Position)
if chanstate.MaxUsers != nil {
channel.MaxUsers = int(*chanstate.MaxUsers)
} else {
channel.MaxUsers = 0
}
channel.Save()
channel.SetParent(parent)
// If the client wouldn't have WritePermission in the just-created channel,
// add a +write ACL for the user's hash.
if !HasPermission(channel, client, WritePermission, []string{}) {
aclEntry := ACL{}
aclEntry.ApplyHere = true
aclEntry.ApplySubs = true
if client.IsRegistered() {
aclEntry.UserID = client.UserId()
} else {
aclEntry.Group = "$" + client.CertHash()
}
aclEntry.Deny = Permission(NonePermission)
aclEntry.Allow = Permission(WritePermission | TraversePermission)
channel.AppendACL(&aclEntry)
}
chanstate.ChannelId = proto.Uint32(uint32(channel.ID))
server.ClearCaches()
// Broadcast channel add
server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool {
return client.Version < 0x10202
})
// Remove description if client knows how to handle blobs.
if chanstate.Description != nil && channel.HasDescription() {
chanstate.Description = nil
chanstate.DescriptionHash = channel.DescriptionBlobHashBytes()
}
server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool {
return client.Version >= 0x10202
})
// If it's a temporary channel, move the creator in there.
if channel.IsTemporary() {
client.MoveChannel(channel, nil)
// userstate := &mumbleproto.UserState{}
// userstate.Session = proto.Uint32(client.Session())
// userstate.ChannelId = proto.Uint32(uint32(channel.ID))
// server.userEnterChannel(client, channel, userstate)
// server.broadcastUserState(userstate)
}
} else {
// Edit existing channel.
// First, check whether the actor has the neccessary permissions.
// Name change.
if chanstate.Name != nil {
// The client can only rename the channel if it has WritePermission in the channel.
// Also, clients cannot change the name of the root channel.
if !HasPermission(channel, client, WritePermission, []string{}) || channel.ID == 0 {
client.sendPermissionDenied(client, channel, WritePermission)
return
}
}
// Description change
if chanstate.Description != nil {
if !HasPermission(channel, client, WritePermission, []string{}) {
client.sendPermissionDenied(client, channel, WritePermission)
return
}
}
// Position change
if chanstate.Position != nil {
if !HasPermission(channel, client, WritePermission, []string{}) {
client.sendPermissionDenied(client, channel, WritePermission)
return
}
}
// Parent change (channel move)
if parent != nil {
// No-op?
if parent.ID == channel.ParentID {
return
}
// Make sure that channel we're operating on is not a parent of the new parent.
iter := parent
for iter != nil {
if iter.ID == channel.ID {
client.sendPermissionDeniedText("Illegal channel reparent")
return
}
iter = iter.Parent()
}
// A temporary channel must not have any subchannels, so deny it.
if parent.IsTemporary() {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TemporaryChannel)
return
}
// To move a channel, the user must have WritePermission in the channel
if !HasPermission(channel, client, WritePermission, []string{}) {
client.sendPermissionDenied(client, channel, WritePermission)
return
}
// And the user must also have MakeChannel permission in the new parent
if !HasPermission(parent, client, MakeChannelPermission, []string{}) {
client.sendPermissionDenied(client, parent, MakeChannelPermission)
return
}
// If a sibling of parent already has this name, don't allow it.
for _, iter := range parent.Childrens() {
if iter.Name == channel.Name {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_ChannelName)
return
}
}
}
// Links
linkadd := []*Channel{}
linkremove := []*Channel{}
if len(chanstate.LinksAdd) > 0 || len(chanstate.LinksRemove) > 0 {
// Client must have permission to link
if !HasPermission(channel, client, LinkChannelPermission, []string{}) {
client.sendPermissionDenied(client, channel, LinkChannelPermission)
return
}
// Add any valid channels to linkremove slice
for _, cid := range chanstate.LinksRemove {
if iter := server.GetChannel(int(cid)); iter != nil {
linkremove = append(linkremove, iter)
}
}
// Add any valid channels to linkadd slice
for _, cid := range chanstate.LinksAdd {
if iter := server.GetChannel(int(cid)); iter != nil {
if !HasPermission(iter, client, LinkChannelPermission, []string{}) {
client.sendPermissionDenied(client, iter, LinkChannelPermission)
return
}
linkadd = append(linkadd, iter)
}
}
}
// Permission checks done!
// Channel move
if parent != nil {
channel.SetParent(parent)
}
// Rename
if chanstate.Name != nil {
channel.Name = *chanstate.Name
}
// Description change
if chanstate.Description != nil {
if len(description) == 0 {
channel.DescriptionBlob = ""
} else {
key, err := blobStore.Put([]byte(description))
if err == nil {
channel.DescriptionBlob = key
// server.Panicf("Blobstore error: %v", err)
}
}
}
// Position change
if chanstate.Position != nil {
channel.Position = int(*chanstate.Position)
}
if chanstate.MaxUsers != nil {
channel.MaxUsers = int(*chanstate.MaxUsers)
}
channel.Save()
// Add links
for _, iter := range linkadd {
server.LinkChannels(channel, iter)
}
// Remove links
for _, iter := range linkremove {
server.UnlinkChannels(channel, iter)
}
server.ClearCaches()
// Broadcast the update
server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool {
return client.Version < 0x10202
})
// Remove description blob when sending to 1.2.2 >= users. Only send the blob hash.
if channel.HasDescription() {
chanstate.Description = nil
chanstate.DescriptionHash = channel.DescriptionBlobHashBytes()
}
chanstate.DescriptionHash = channel.DescriptionBlobHashBytes()
server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool {
return client.Version >= 0x10202
})
}
// Update channel in datastore
// if !channel.IsTemporary() {
// server.UpdateFrozenChannel(channel, chanstate)
// }
}
// Handle a user remove packet. This can either be a client disconnecting, or a
// user kicking or kick-banning another player.
func (server *Server) handleUserRemoveMessage(client *Client, msg *Message) {
userremove := &mumbleproto.UserRemove{}
err := proto.Unmarshal(msg.buf, userremove)
if err != nil {
panic(err) // Caught by incoming message hub
}
// Get the client to be removed.
removeClient, ok := server.clients.Get(*userremove.Session)
if !ok {
client.sendMessage(&mumbleproto.UserRemove{
Session: proto.Uint32(*userremove.Session),
})
client.Print("Invalid session in UserState message")
return
}
isBan := false
if userremove.Ban != nil {
isBan = *userremove.Ban
}
// Check client's permissions
perm := Permission(KickPermission)
if isBan {
perm = Permission(BanPermission)
}
rootChan := server.RootChannel()
if removeClient.IsSuperUser() || !HasPermission(rootChan, client, perm, []string{}) {
client.sendPermissionDenied(client, rootChan, perm)
return
}
if isBan {
ban := Ban{}
ban.Address = removeClient.realip.IP
ban.Mask = 128
if userremove.Reason != nil {
ban.Reason = *userremove.Reason
}
ban.Name = removeClient.ShownName()
ban.Hash = removeClient.CertHash()
ban.Start = time.Now().Unix()
ban.Duration = 0
server.AppendBan(&ban)
}
userremove.Actor = proto.Uint32(client.Session())
func() {
server.userStateLock.Lock()
defer server.userStateLock.Unlock()
server.broadcastProtoMessage(userremove)
}()
if isBan {
client.Printf("Kick-banned %v (%v)", removeClient.ShownName(), removeClient.Session())
} else {
client.Printf("Kicked %v (%v)", removeClient.ShownName(), removeClient.Session())
}
removeClient.ForceDisconnect()
server.ClearCachesByUser(removeClient)
}
// Handle user state changes
func (server *Server) handlePreConnectUserStateMessage(client *Client, msg *Message) {
// GOROUTINE START
defer client.recover(nil)
userstate := &mumbleproto.UserState{}
err := proto.Unmarshal(msg.buf, userstate)
if err != nil {
panic(err) // Caught by this function
}
if userstate.Session != nil {
if *userstate.Session != client.Session() && *userstate.Session != 0 {
panic(fmt.Sprintf("Non self-targeted state change is not allowed in pre-connect state. Target session: %d, Self session: %d", *userstate.Session, client.Session())) // Caught by this function
}
}
if userstate.SelfDeaf != nil {
client.SelfDeaf = *userstate.SelfDeaf
}
if userstate.SelfMute != nil {
client.SelfMute = *userstate.SelfMute
}
if userstate.PluginContext != nil {
client.PluginContext = userstate.PluginContext
}
if userstate.PluginIdentity != nil {
client.PluginIdentity = *userstate.PluginIdentity
}
}
// Handle user state changes
func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
userstate := &mumbleproto.UserState{}
err := proto.Unmarshal(msg.buf, userstate)
if err != nil {
panic(err) // Caught by incoming message hub
}
actor, ok := server.clients.Get(client.Session())
if !ok {
server.Printf("Client %d not found in server's client map.", client.Session())
return
}
target := actor
if userstate.Session != nil {
target, ok = server.clients.Get(*userstate.Session)
if !ok {
client.sendMessage(&mumbleproto.UserRemove{
Session: proto.Uint32(*userstate.Session),
})
client.Print("Invalid session in UserState message")
return
}
}
userstate.Session = proto.Uint32(target.Session())
userstate.Actor = proto.Uint32(actor.Session())
// Does it have a channel ID?
if userstate.ChannelId != nil {
// Destination channel
dstChan := server.GetChannel(int(*userstate.ChannelId))
if dstChan == nil {
return
}
// If the user and the actor aren't the same, check whether the actor has MovePermission on
// the user's curent channel.
// Check whether the actor has MovePermission on dstChan. Check whether user has EnterPermission
// on dstChan.
// if !HasPermission(dstChan, actor, MovePermission) && !HasPermission(dstChan, target, EnterPermission) {
//if actor != target && (!HasPermission(target.Channel(), actor, MovePermission) || !HasPermission(dstChan, actor, EnterPermission) || !HasPermission(dstChan, actor, MovePermission)) {
// client.sendPermissionDenied(actor, target.Channel(), MovePermission)
// return
//} else if actor == target && !HasPermission(dstChan, target, EnterPermission) {
// client.sendPermissionDenied(target, dstChan, EnterPermission)
// return
//}
if actor.Session() != target.Session() {
// Moving others
// if target does not have TraversePermission on dstChan, deny
if !HasPermission(dstChan, target, TraversePermission, []string{}) {
client.sendPermissionDenied(target, dstChan, TraversePermission)
return
}
// if target has EnterPermission on dstChan, only check MovePermission of actor on target's current channel
if !HasPermission(dstChan, target, EnterPermission, []string{}) {
if !HasPermission(target.Channel(), actor, MovePermission, []string{}) {
client.sendPermissionDenied(actor, target.Channel(), MovePermission)
return
}
} else {
// Otherwise actor need to have MovePermission on dstChan
if !HasPermission(dstChan, actor, MovePermission, []string{}) {
client.sendPermissionDenied(actor, dstChan, MovePermission)
return
}
}
} else {
temporaryTokens := userstate.GetTemporaryAccessTokens()
// Moving self
if !HasPermission(dstChan, target, EnterPermission, temporaryTokens) {
client.sendPermissionDenied(target, dstChan, EnterPermission)
return
}
}
maxChannelUsers := server.cfg.MaxChannelUsers
if dstChan.MaxUsers > 0 {
maxChannelUsers = dstChan.MaxUsers
}
if maxChannelUsers != 0 && len(dstChan.Clients()) >= maxChannelUsers && !client.IsSuperUser() {
client.sendPermissionDeniedFallback(mumbleproto.PermissionDenied_ChannelFull,
0x010201, "Channel is full")
return
}
}
if userstate.Mute != nil || userstate.Deaf != nil || userstate.Suppress != nil || userstate.PrioritySpeaker != nil {
// Disallow for SuperUser
// if target.IsSuperUser() {
// client.sendPermissionDeniedType(mumbleproto.PermissionDenied_SuperUser)
// return
// }
// Check whether the actor has 'mutedeafen' permission on user's channel.
if !HasPermission(target.Channel(), actor, MuteDeafenPermission, []string{}) {
client.sendPermissionDenied(actor, target.Channel(), MuteDeafenPermission)
return
}
// Check if this was a suppress operation. Only the server can suppress users.
if userstate.Suppress != nil && *userstate.Suppress == true {
client.sendPermissionDenied(actor, target.Channel(), MuteDeafenPermission)
return
}
}
// Comment set/clear
if userstate.Comment != nil {
comment := *userstate.Comment
// Clearing another user's comment.
if target != actor {
// Check if actor has 'move' permissions on the root channel. It is needed
// to clear another user's comment.
rootChan := server.RootChannel()
if !HasPermission(rootChan, actor, MovePermission, []string{}) {
client.sendPermissionDenied(actor, rootChan, MovePermission)
return
}
// Only allow empty text.
if len(comment) > 0 {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
return
}
}
filtered, err := server.FilterText(comment)
if err != nil {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
return
}
userstate.Comment = proto.String(filtered)
}
// Texture change
if userstate.Texture != nil {
maximg := server.cfg.MaxImageMessageLength
if maximg > 0 && len(userstate.Texture) > maximg {
client.sendPermissionDeniedType(mumbleproto.PermissionDenied_TextTooLong)
return
}
}
// Registration
if userstate.UserId != nil {
// If user == actor, check for SelfRegisterPermission on root channel.
// If user != actor, check for RegisterPermission permission on root channel.
perm := Permission(RegisterPermission)
if actor == target {
perm = Permission(SelfRegisterPermission)
}
rootChan := server.RootChannel()
if target.IsRegistered() || !HasPermission(rootChan, actor, perm, []string{}) {
client.sendPermissionDenied(actor, rootChan, perm)
return
}
if !target.HasCertificate() {
client.sendPermissionDeniedTypeUser(mumbleproto.PermissionDenied_MissingCertificate, target)
return
}
}
// Prevent self-targetting state changes to be applied to other users
// That is, if actor != user, then:
// Discard message if it has any of the following things set:
// - SelfDeaf
// - SelfMute
// - Texture
// - PluginContext
// - PluginIdentity
// - Recording
if actor != target && (userstate.SelfDeaf != nil || userstate.SelfMute != nil ||
userstate.Texture != nil || userstate.PluginContext != nil || userstate.PluginIdentity != nil ||
userstate.Recording != nil) {
panic("Invalid UserState") // Caught by incoming message hub
}
broadcast := false
// TODO: Lots of things here
// if userstate.Texture != nil {
// key, err := blobStore.Put(userstate.Texture)
// if err != nil {
// server.Panicf("Blobstore error: %v", err)
// return
// }
// if target.user.TextureBlob != key {
// target.user.TextureBlob = key
// } else {
// userstate.Texture = nil
// }
// broadcast = true
// }
if userstate.SelfDeaf != nil {
target.SelfDeaf = *userstate.SelfDeaf
if target.SelfDeaf {
userstate.SelfDeaf = proto.Bool(true)
target.SelfMute = true
}
broadcast = true
}
if userstate.SelfMute != nil {
target.SelfMute = *userstate.SelfMute
if !target.SelfMute {
userstate.SelfDeaf = proto.Bool(false)
target.SelfDeaf = false
}
}
if userstate.PluginContext != nil {
target.PluginContext = userstate.PluginContext
}
if userstate.PluginIdentity != nil {
target.PluginIdentity = *userstate.PluginIdentity
}
// if userstate.Comment != nil {
// key, err := blobStore.Put([]byte(*userstate.Comment))
// if err != nil {
// server.Panicf("Blobstore error: %v", err)
// }
// if target.user.CommentBlob != key {
// target.user.CommentBlob = key
// } else {
// userstate.Comment = nil
// }
// broadcast = true
// }
if userstate.Mute != nil || userstate.Deaf != nil || userstate.Suppress != nil || userstate.PrioritySpeaker != nil {
if userstate.Deaf != nil {
target.Deaf = *userstate.Deaf
if target.Deaf {
userstate.Mute = proto.Bool(true)
}
}
if userstate.Mute != nil {
target.Mute = *userstate.Mute
if !target.Mute {
userstate.Deaf = proto.Bool(false)
target.Deaf = false
}
}
if userstate.Suppress != nil {
target.Suppress = *userstate.Suppress
}
if userstate.PrioritySpeaker != nil {
target.PrioritySpeaker = *userstate.PrioritySpeaker
}
broadcast = true
}
if userstate.Recording != nil && *userstate.Recording != target.Recording {
target.Recording = *userstate.Recording
txtmsg := &mumbleproto.TextMessage{}
txtmsg.TreeId = append(txtmsg.TreeId, uint32(0))
if target.Recording {
txtmsg.Message = proto.String(fmt.Sprintf("User '%s' started recording", target.ShownName()))
} else {
txtmsg.Message = proto.String(fmt.Sprintf("User '%s' stopped recording", target.ShownName()))
}
server.broadcastProtoMessageWithPredicate(txtmsg, func(client *Client) bool {
return client.Version < 0x10203 && client != actor
})
broadcast = true
}
// userRegistrationChanged := false
// if userstate.UserId != nil {
// uid, err := server.RegisterClient(target)
// if err != nil {
// client.Printf("Unable to register: %v", err)
// userstate.UserId = nil
// } else {
// userstate.UserId = proto.Uint32(uid)
// client.user = server.Users[uid]
// userRegistrationChanged = true
// }
// broadcast = true
// }
if userstate.ChannelId != nil {
channel := server.GetChannel(int(*userstate.ChannelId))
if channel != nil {
server.userEnterChannel(target, channel, userstate)
broadcast = true
}
}
if userstate.ListeningChannelAdd != nil {
for _, channelId := range userstate.ListeningChannelAdd {
channel := server.GetChannel(int(channelId))
if channel != nil && HasPermission(channel, client, ListenPermission, []string{}) {
client.ListenChannel(channel)
} else {
client.sendPermissionDenied(client, channel, ListenPermission)
return
}
}
broadcast = true
}
if userstate.ListeningChannelRemove != nil {
for _, channelId := range userstate.ListeningChannelRemove {
channel := server.GetChannel(int(channelId))
if channel != nil {
client.UnlistenChannel(channel)
}
}
broadcast = true
}
if broadcast {
server.ClearVTCache()
// This variable denotes the length of a zlib-encoded "old-style" texture.
// Mumble and Murmur used qCompress and qUncompress from Qt to compress
// textures that were sent over the wire. We can use this to determine
// whether a texture is a "new style" or an "old style" texture.
texture := userstate.Texture
texlen := uint32(0)
if texture != nil && len(texture) > 4 {
texlen = uint32(texture[0])<<24 | uint32(texture[1])<<16 | uint32(texture[2])<<8 | uint32(texture[3])
}
if texture != nil && len(texture) > 4 && texlen != 600*60*4 {
// The sent texture is a new-style texture. Strip it from the message
// we send to pre-1.2.2 clients.
userstate.Texture = nil
server.broadcastUserStateWithPredicate(userstate, func(client *Client) bool {
return client.Version < 0x10202 && client.hasFullUserList
})
// Re-add it to the message, so that 1.2.2+ clients *do* get the new-style texture.
userstate.Texture = texture
} else {
// Old style texture. We can send the message as-is.
server.broadcastUserStateWithPredicate(userstate, func(client *Client) bool {
return client.Version < 0x10202 && client.hasFullUserList
})
}
// If a texture hash is set on user, we transmit that instead of
// the texture itself. This allows the client to intelligently fetch
// the blobs that it does not already have in its local storage.
// if userstate.Texture != nil && target.user != nil && target.user.HasTexture() {
// userstate.Texture = nil
// userstate.TextureHash = target.user.TextureBlobHashBytes()
// } else if target.user == nil {
// userstate.Texture = nil
// userstate.TextureHash = nil
// }
// Ditto for comments.
// if userstate.Comment != nil && target.user.HasComment() {
// userstate.Comment = nil
// userstate.CommentHash = target.user.CommentBlobHashBytes()
// } else if target.user == nil {
// userstate.Comment = nil
// userstate.CommentHash = nil
// }
// if userRegistrationChanged {