1
0
Fork 0
forked from External/grumble

gofmt run.

This commit is contained in:
Mikkel Krautz 2010-11-20 01:10:08 +01:00
parent a57908b487
commit c2f3f0de47
3 changed files with 55 additions and 54 deletions

View file

@ -19,8 +19,8 @@ import (
// A client connection
type Client struct {
// Connection-related
tcpaddr *net.TCPAddr
udpaddr *net.UDPAddr
tcpaddr *net.TCPAddr
udpaddr *net.UDPAddr
conn net.Conn
reader *bufio.Reader
writer *bufio.Writer
@ -32,9 +32,9 @@ type Client struct {
disconnected bool
crypt *cryptstate.CryptState
codecs []int32
udp bool
crypt *cryptstate.CryptState
codecs []int32
udp bool
// Personal
Session uint32
@ -82,8 +82,8 @@ func (client *Client) readProtoMessage() (msg *Message, err os.Error) {
}
msg = &Message{
buf: buf,
kind: kind,
buf: buf,
kind: kind,
client: client,
}
@ -114,44 +114,46 @@ func (client *Client) udpreceiver() {
return
}
kind := (buf[0] >> 5) & 0x07;
kind := (buf[0] >> 5) & 0x07
switch kind {
case UDPMessageVoiceSpeex: fallthrough;
case UDPMessageVoiceCELTAlpha: fallthrough;
case UDPMessageVoiceSpeex:
fallthrough
case UDPMessageVoiceCELTAlpha:
fallthrough
case UDPMessageVoiceCELTBeta:
kind := buf[0] & 0xe0
target := buf[0] & 0x1f
var counter uint8
outbuf := make([]byte, 1024)
incoming := packetdatastream.New(buf[1:1+(len(buf)-1)])
outgoing := packetdatastream.New(outbuf[1:1+(len(outbuf)-1)])
incoming := packetdatastream.New(buf[1 : 1+(len(buf)-1)])
outgoing := packetdatastream.New(outbuf[1 : 1+(len(outbuf)-1)])
_ = incoming.GetUint32()
for {
counter = incoming.Next8()
incoming.Skip(int(counter & 0x7f))
if !((counter & 0x80) != 0 && incoming.IsValid()) {
if !((counter&0x80) != 0 && incoming.IsValid()) {
break
}
}
outgoing.PutUint32(client.Session)
outgoing.PutBytes(buf[1:1+(len(buf)-1)])
outgoing.PutBytes(buf[1 : 1+(len(buf)-1)])
// Sever loopback
if target == 0x1f {
outbuf[0] = kind
client.sendUdp(&Message{
buf: outbuf[0:1+outgoing.Size()],
client: client,
buf: outbuf[0 : 1+outgoing.Size()],
client: client,
})
}
case UDPMessagePing:
client.server.udpsend <- &Message{
buf: buf,
client: client,
buf: buf,
client: client,
}
}
}
@ -240,8 +242,8 @@ func (client *Client) receiver() {
// what version of the protocol it should speak.
if client.state == StateClientConnected {
client.sendProtoMessage(MessageVersion, &mumbleproto.Version{
Version: proto.Uint32(0x10203),
Release: proto.String("1.2.2"),
Version: proto.Uint32(0x10203),
Release: proto.String("1.2.2"),
})
// 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.
@ -280,8 +282,8 @@ func (client *Client) sendChannelList() {
// Start at the root channel.
err := client.sendProtoMessage(MessageChannelState, &mumbleproto.ChannelState{
ChannelId: proto.Uint32(uint32(root.Id)),
Name: proto.String(root.Name),
ChannelId: proto.Uint32(uint32(root.Id)),
Name: proto.String(root.Name),
Description: proto.String(root.Description),
})
if err != nil {
@ -295,8 +297,8 @@ func (client *Client) sendUserList() {
server := client.server
for _, client := range server.clients {
err := client.sendProtoMessage(MessageUserState, &mumbleproto.UserState{
Session: proto.Uint32(client.Session),
Name: proto.String(client.Username),
Session: proto.Uint32(client.Session),
Name: proto.String(client.Username),
ChannelId: proto.Uint32(0),
})
if err != nil {
@ -305,4 +307,3 @@ func (client *Client) sendUserList() {
}
}
}

View file

@ -51,7 +51,7 @@ const (
)
type Message struct {
buf []byte
buf []byte
// Kind denotes a message kind for TCP packets. This field
// is ignored for UDP packets.
@ -61,7 +61,7 @@ type Message struct {
// If there is no connection established, address must be used.
// If the datagram comes from an already-connected client, the
// client field should point to that client.
client *Client
client *Client
address net.Addr
}
@ -141,7 +141,7 @@ func (server *Server) handleTextMessage(client *Client, msg *Message) {
return
}
users := []*Client{};
users := []*Client{}
for i := 0; i < len(txtmsg.Session); i++ {
user, ok := server.clients[txtmsg.Session[i]]
if !ok {

View file

@ -20,10 +20,10 @@ import (
)
// The default port a Murmur server listens on
const DefaultPort = 64738
const UDPPacketSize = 1024
const DefaultPort = 64738
const UDPPacketSize = 1024
const CeltCompatBitstream = -2147483638
const CeltCompatBitstream = -2147483638
// Client connection states
const (
@ -43,23 +43,23 @@ type Server struct {
incoming chan *Message
outgoing chan *Message
udpsend chan *Message
udpsend chan *Message
// Config-related
MaxUsers int
MaxUsers int
MaxBandwidth uint32
// Clients
session uint32
clients map[uint32]*Client
clients map[uint32]*Client
hmutex *sync.RWMutex
hmutex *sync.RWMutex
hclients map[string][]*Client
hpclients map[string]*Client
// Codec information
AlphaCodec int32
BetaCodec int32
AlphaCodec int32
BetaCodec int32
PreferAlphaCodec bool
root *Channel
@ -67,12 +67,12 @@ type Server struct {
// A Mumble channel
type Channel struct {
Id int
Name string
Id int
Name string
Description string
Temporary bool
Position int
Channels *list.List
Temporary bool
Position int
Channels *list.List
}
// Allocate a new Murmur instance
@ -96,7 +96,7 @@ func NewServer(addr string, port int) (s *Server, err os.Error) {
s.MaxUsers = 10
s.root = &Channel{
Id: 0,
Id: 0,
Name: "Root",
}
@ -186,7 +186,7 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
// Send CryptState information to the client so it can establish an UDP connection,
// if it wishes.
err = client.sendProtoMessage(MessageCryptSetup, &mumbleproto.CryptSetup{
Key: client.crypt.RawKey[0:],
Key: client.crypt.RawKey[0:],
ClientNonce: client.crypt.DecryptIV[0:],
ServerNonce: client.crypt.EncryptIV[0:],
})
@ -214,9 +214,9 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
// Broadcast the the user entered a channel
err = server.broadcastProtoMessage(MessageUserState, &mumbleproto.UserState{
Session: proto.Uint32(client.Session),
Name: proto.String(client.Username),
ChannelId: proto.Uint32(0),
Session: proto.Uint32(client.Session),
Name: proto.String(client.Username),
ChannelId: proto.Uint32(0),
})
if err != nil {
client.Panic(err.String())
@ -225,8 +225,8 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
server.sendUserList(client)
err = client.sendProtoMessage(MessageServerSync, &mumbleproto.ServerSync{
Session: proto.Uint32(client.Session),
MaxBandwidth: proto.Uint32(server.MaxBandwidth),
Session: proto.Uint32(client.Session),
MaxBandwidth: proto.Uint32(server.MaxBandwidth),
})
if err != nil {
client.Panic(err.String())
@ -234,8 +234,8 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
}
err = client.sendProtoMessage(MessageServerConfig, &mumbleproto.ServerConfig{
AllowHtml: proto.Bool(true),
MessageLength: proto.Uint32(1000),
AllowHtml: proto.Bool(true),
MessageLength: proto.Uint32(1000),
ImageMessageLength: proto.Uint32(1000),
})
if err != nil {
@ -282,7 +282,7 @@ func (server *Server) updateCodecVersions() {
server.PreferAlphaCodec = !server.PreferAlphaCodec
}
if (server.PreferAlphaCodec) {
if server.PreferAlphaCodec {
server.AlphaCodec = winner
} else {
server.BetaCodec = winner
@ -330,7 +330,7 @@ func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err o
if client.state != StateClientAuthenticated {
continue
}
err :=client.sendProtoMessage(kind, msg)
err := client.sendProtoMessage(kind, msg)
if err != nil {
return
}
@ -454,7 +454,7 @@ func (server *Server) ListenUDP() {
_ = binary.Write(buffer, binary.BigEndian, uint32(server.MaxBandwidth))
server.udpsend <- &Message{
buf: buffer.Bytes(),
buf: buffer.Bytes(),
address: udpaddr,
}
} else {