Synchronize voice broadcast.

This commit is contained in:
Mikkel Krautz 2010-11-20 20:28:23 +01:00
parent d7dd29b45c
commit 37262d6889
3 changed files with 40 additions and 14 deletions

View file

@ -140,15 +140,23 @@ func (client *Client) udpreceiver() {
outgoing.PutUint32(client.Session) outgoing.PutUint32(client.Session)
outgoing.PutBytes(buf[1 : 1+(len(buf)-1)]) outgoing.PutBytes(buf[1 : 1+(len(buf)-1)])
outbuf[0] = kind
// Sever loopback // VoiceTarget
if target == 0x1f { if target != 0x1f {
outbuf[0] = kind client.server.voicebroadcast <- &VoiceBroadcast{
client: client,
buf: outbuf[0 : 1+outgoing.Size()],
target: target,
}
// Server loopback
} else {
client.sendUdp(&Message{ client.sendUdp(&Message{
buf: outbuf[0 : 1+outgoing.Size()], buf: outbuf[0 : 1+outgoing.Size()],
client: client, client: client,
}) })
} }
case UDPMessagePing: case UDPMessagePing:
client.server.udpsend <- &Message{ client.server.udpsend <- &Message{
buf: buf, buf: buf,

View file

@ -65,6 +65,15 @@ type Message struct {
address net.Addr address net.Addr
} }
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) { func (server *Server) handleCryptSetup(client *Client, msg *Message) {
cs := &mumbleproto.CryptSetup{} cs := &mumbleproto.CryptSetup{}
err := proto.Unmarshal(msg.buf, cs) err := proto.Unmarshal(msg.buf, cs)

View file

@ -41,9 +41,10 @@ type Server struct {
port int port int
udpconn *net.UDPConn udpconn *net.UDPConn
incoming chan *Message incoming chan *Message
outgoing chan *Message outgoing chan *Message
udpsend chan *Message udpsend chan *Message
voicebroadcast chan *VoiceBroadcast
// Config-related // Config-related
MaxUsers int MaxUsers int
@ -90,6 +91,7 @@ func NewServer(addr string, port int) (s *Server, err os.Error) {
s.outgoing = make(chan *Message) s.outgoing = make(chan *Message)
s.incoming = make(chan *Message) s.incoming = make(chan *Message)
s.udpsend = make(chan *Message) s.udpsend = make(chan *Message)
s.voicebroadcast = make(chan *VoiceBroadcast)
s.MaxBandwidth = 300000 s.MaxBandwidth = 300000
s.MaxUsers = 10 s.MaxUsers = 10
@ -157,13 +159,20 @@ func (server *Server) RemoveClient(client *Client) {
// to keep server state synchronized. // to keep server state synchronized.
func (server *Server) handler() { func (server *Server) handler() {
for { for {
msg := <-server.incoming select {
client := msg.client // Control channel messages
case msg := <-server.incoming:
if client.state == StateClientAuthenticated { client := msg.client
server.handleIncomingMessage(client, msg) if client.state == StateClientAuthenticated {
} else if client.state == StateClientSentVersion { server.handleIncomingMessage(client, msg)
server.handleAuthenticate(client, msg) } else if client.state == StateClientSentVersion {
server.handleAuthenticate(client, msg)
}
// Voice broadcast
case vb := <-server.voicebroadcast:
log.Printf("VoiceBroadcast!")
if vb.target == 0 {
}
} }
} }
} }
@ -445,7 +454,7 @@ func (s *Server) SendUDP() {
} else if msg.address != nil { } else if msg.address != nil {
s.udpconn.WriteTo(msg.buf, msg.address) s.udpconn.WriteTo(msg.buf, msg.address)
} else { } else {
// Skipping // Skipping
} }
} }
} }