func (vt *VoiceTarget) SendVoiceBroadcast(vb *VoiceBroadcast) {
	buf := vb.buf
	client := vb.client
	server := client.server

	direct := vt.directCache
	fromChannels := vt.fromChannelsCache

	if direct == nil || fromChannels == nil {
		direct = make(map[uint32]*Client)
		fromChannels = make(map[uint32]*Client)

		for _, vtc := range vt.channels {
			channel := server.Channels[int(vtc.id)]
			if channel == nil {
				continue
			}

			if !vtc.subChannels && !vtc.links && vtc.onlyGroup == "" {
				if acl.HasPermission(&channel.ACL, client, acl.WhisperPermission) {
					for _, target := range channel.clients {
						fromChannels[target.Session()] = target
					}
				}
			} else {
				server.Printf("%v", vtc)
				newchans := make(map[int]*Channel)
				if vtc.links {
					newchans = channel.AllLinks()
				} else {
					newchans[channel.Id] = channel
				}
				if vtc.subChannels {
					subchans := channel.AllSubChannels()
					for k, v := range subchans {
						newchans[k] = v
					}
				}
				for _, newchan := range newchans {
					if acl.HasPermission(&newchan.ACL, client, acl.WhisperPermission) {
						for _, target := range newchan.clients {
							if vtc.onlyGroup == "" || acl.GroupMemberCheck(&newchan.ACL, &newchan.ACL, vtc.onlyGroup, target) {
								fromChannels[target.Session()] = target
							}
						}
					}
				}
			}
		}

		for _, session := range vt.sessions {
			target := server.clients[session]
			if target != nil {
				if _, alreadyInFromChannels := fromChannels[target.Session()]; !alreadyInFromChannels {
					direct[target.Session()] = target
				}
			}
		}

		// Make sure we don't send to ourselves.
		delete(direct, client.Session())
		delete(fromChannels, client.Session())

		if vt.directCache == nil {
			vt.directCache = direct
		}

		if vt.fromChannelsCache == nil {
			vt.fromChannelsCache = fromChannels
		}
	}

	kind := buf[0] & 0xe0

	if len(fromChannels) > 0 {
		for _, target := range fromChannels {
			buf[0] = kind | 2
			err := target.SendUDP(buf)
			if err != nil {
				target.Panicf("Unable to send UDP packet: %v", err.Error())
			}
		}
	}

	if len(direct) > 0 {
		for _, target := range direct {
			buf[0] = kind | 2
			target.SendUDP(buf)
			err := target.SendUDP(buf)
			if err != nil {
				target.Panicf("Unable to send UDP packet: %v", err.Error())
			}
		}
	}
}
// Send the contents of the VoiceBroadcast to all targets specified in the
// VoiceTarget.
Send the contents of the VoiceBroadcast to all targets specified in the
VoiceTarget.
// Send the contents of the VoiceBroadcast to all targets specified in the // VoiceTarget .
func (vt *VoiceTarget) SendVoiceBroadcast(vb *VoiceBroadcast) {
	buf := vb.buf
	client := vb.client
	server := client.server
	direct := vt.directCache
	fromChannels := vt.fromChannelsCache
	if direct == nil || fromChannels == nil {
		direct = make(map[uint32]*Client)
		fromChannels = make(map[uint32]*Client)
		for _, vtc := range vt.channels {
			channel := server.Channels[int(vtc.id)]
			if channel == nil {
				continue
			}
			if !vtc.subChannels && !vtc.links && vtc.onlyGroup == "" {
				if acl.HasPermission(&channel.ACL, client, acl.WhisperPermission) {
					for _, target := range channel.clients {
						fromChannels[target.Session()] = target
					}
				}
			} else {
				server.Printf("%v", vtc)
				newchans := make(map[int]*Channel)
				if vtc.links {
					newchans = channel.AllLinks()
				} else {
					newchans[channel.Id] = channel
				}
				if vtc.subChannels {
					subchans := channel.AllSubChannels()
					for k, v := range subchans {
						newchans[k] = v
					}
				}
				for _, newchan := range newchans {
					if acl.HasPermission(&newchan.ACL, client, acl.WhisperPermission) {
						for _, target := range newchan.clients {
							if vtc.onlyGroup == "" || acl.GroupMemberCheck(&newchan.ACL, &newchan.ACL, vtc.onlyGroup, target) {
								fromChannels[target.Session()] = target
							}
						}
					}
				}
			}
		}
		for _, session := range vt.sessions {
			target := server.clients[session]
			if target != nil {
				if _, alreadyInFromChannels := fromChannels[target.Session()]; !alreadyInFromChannels {
					direct[target.Session()] = target
				}
			}
		}
		delete(direct, client.Session())
		delete(fromChannels, client.Session())
		if vt.directCache == nil {
			vt.directCache = direct
		}
		if vt.fromChannelsCache == nil {
			vt.fromChannelsCache = fromChannels
		}
	}
	kind := buf[0] & 0xe0
	if len(fromChannels) > 0 {
		for _, target := range fromChannels {
			buf[0] = kind | 2
			err := target.SendUDP(buf)
			if err != nil {
				target.Panicf("Unable to send UDP packet: %v", err.Error())
			}
		}
	}
	if len(direct) > 0 {
		for _, target := range direct {
			buf[0] = kind | 2
			target.SendUDP(buf)
			err := target.SendUDP(buf)
			if err != nil {
				target.Panicf("Unable to send UDP packet: %v", err.Error())
			}
		}
	}
}
func ( vt * VoiceTarget ) SendVoiceBroadcast ( vb * VoiceBroadcast ) { buf := vb . buf client := vb . client server := client . server direct := vt . directCache fromChannels := vt . fromChannelsCache if direct == nil || fromChannels == nil { direct = make ( map [ uint32 ] * Client ) fromChannels = make ( map [ uint32 ] * Client ) for _ , vtc := range vt . channels { channel := server . Channels [ int ( vtc . id ) ] if channel == nil { continue } if ! vtc . subChannels && ! vtc . links && vtc . onlyGroup == " " { if acl . HasPermission ( & channel . ACL , client , acl . WhisperPermission ) { for _ , target := range channel . clients { fromChannels [ target . Session ( ) ] = target } } } else { server . Printf ( " " , vtc ) newchans := make ( map [ int ] * Channel ) if vtc . links { newchans = channel . AllLinks ( ) } else { newchans [ channel . Id ] = channel } if vtc . subChannels { subchans := channel . AllSubChannels ( ) for k , v := range subchans { newchans [ k ] = v } } for _ , newchan := range newchans { if acl . HasPermission ( & newchan . ACL , client , acl . WhisperPermission ) { for _ , target := range newchan . clients { if vtc . onlyGroup == " " || acl . GroupMemberCheck ( & newchan . ACL , & newchan . ACL , vtc . onlyGroup , target ) { fromChannels [ target . Session ( ) ] = target } } } } } } for _ , session := range vt . sessions { target := server . clients [ session ] if target != nil { if _ , alreadyInFromChannels := fromChannels [ target . Session ( ) ] ; ! alreadyInFromChannels { direct [ target . Session ( ) ] = target } } } delete ( direct , client . Session ( ) ) delete ( fromChannels , client . Session ( ) ) if vt . directCache == nil { vt . directCache = direct } if vt . fromChannelsCache == nil { vt . fromChannelsCache = fromChannels } } kind := buf [ 0 ] & 0xe0 if len ( fromChannels ) > 0 { for _ , target := range fromChannels { buf [ 0 ] = kind | 2 err := target . SendUDP ( buf ) if err != nil { target . Panicf ( " " , err . Error ( ) ) } } } if len ( direct ) > 0 { for _ , target := range direct { buf [ 0 ] = kind | 2 target . SendUDP ( buf ) err := target . SendUDP ( buf ) if err != nil { target . Panicf ( " " , err . Error ( ) ) } } } }
Send the contents of the VoiceBroadcast to all targets specified in the
VoiceTarget.
Send the contents of the VoiceBroadcast to all targets specified in the VoiceTarget .
// Make sure we don't send to ourselves.