mirror of
https://github.com/mumble-voip/grumble.git
synced 2025-12-19 21:59:59 -08:00
Add a server#broadcastProtoMessageWithPredicate that takes a VersionPredicate function that can limit the sent message to clients with a particular version.
This commit is contained in:
parent
925e23b0f9
commit
3529993601
2 changed files with 40 additions and 3 deletions
31
client.go
31
client.go
|
|
@ -18,6 +18,7 @@ import (
|
||||||
|
|
||||||
// A client connection
|
// A client connection
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
|
||||||
// Connection-related
|
// Connection-related
|
||||||
tcpaddr *net.TCPAddr
|
tcpaddr *net.TCPAddr
|
||||||
udpaddr *net.UDPAddr
|
udpaddr *net.UDPAddr
|
||||||
|
|
@ -36,6 +37,12 @@ type Client struct {
|
||||||
codecs []int32
|
codecs []int32
|
||||||
udp bool
|
udp bool
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Version uint32
|
||||||
|
ClientName string
|
||||||
|
OSName string
|
||||||
|
OSVersion string
|
||||||
|
|
||||||
// Personal
|
// Personal
|
||||||
UserId int
|
UserId int
|
||||||
Session uint32
|
Session uint32
|
||||||
|
|
@ -320,7 +327,7 @@ func (client *Client) receiver() {
|
||||||
if client.state == StateClientConnected {
|
if client.state == StateClientConnected {
|
||||||
client.sendProtoMessage(MessageVersion, &mumbleproto.Version{
|
client.sendProtoMessage(MessageVersion, &mumbleproto.Version{
|
||||||
Version: proto.Uint32(0x10203),
|
Version: proto.Uint32(0x10203),
|
||||||
Release: proto.String("1.2.2"),
|
Release: proto.String("Grumble"),
|
||||||
})
|
})
|
||||||
// fixme(mkrautz): Re-add OS information... Does it break anything? It seems like
|
// fixme(mkrautz): Re-add OS information... Does it break anything? It seems like
|
||||||
// the client discards the version message if there is no OS information in it.
|
// the client discards the version message if there is no OS information in it.
|
||||||
|
|
@ -345,7 +352,27 @@ func (client *Client) receiver() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't really do anything with it...
|
if version.Version != nil {
|
||||||
|
client.Version = *version.Version
|
||||||
|
} else {
|
||||||
|
client.Version = 0x10200
|
||||||
|
}
|
||||||
|
|
||||||
|
if version.Release != nil {
|
||||||
|
client.ClientName = *version.Release
|
||||||
|
}
|
||||||
|
|
||||||
|
if version.Os != nil {
|
||||||
|
client.OSName = *version.Os
|
||||||
|
}
|
||||||
|
|
||||||
|
if version.OsVersion != nil {
|
||||||
|
client.OSVersion = *version.OsVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("version = 0x%x", client.Version)
|
||||||
|
log.Printf("os = %s %s", client.OSName, client.OSVersion)
|
||||||
|
log.Printf("client = %s", client.ClientName)
|
||||||
|
|
||||||
client.state = StateClientSentVersion
|
client.state = StateClientSentVersion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
server.go
12
server.go
|
|
@ -464,8 +464,13 @@ func (server *Server) sendClientPermissions(client *Client, channel *Channel) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err os.Error) {
|
type VersionPredicate func(version uint32) bool
|
||||||
|
|
||||||
|
func (server *Server) broadcastProtoMessageWithPredicate(kind uint16, msg interface{}, vercheck VersionPredicate) (err os.Error) {
|
||||||
for _, client := range server.clients {
|
for _, client := range server.clients {
|
||||||
|
if !vercheck(client.Version) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if client.state != StateClientAuthenticated {
|
if client.state != StateClientAuthenticated {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -478,6 +483,11 @@ func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err o
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err os.Error) {
|
||||||
|
err = server.broadcastProtoMessageWithPredicate(kind, msg, func(version uint32) bool { return true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) handleIncomingMessage(client *Client, msg *Message) {
|
func (server *Server) handleIncomingMessage(client *Client, msg *Message) {
|
||||||
log.Printf("Handle Incoming Message")
|
log.Printf("Handle Incoming Message")
|
||||||
switch msg.kind {
|
switch msg.kind {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue