public void Process()
            {
                if (!_client.Connected)
                {
                    throw new InvalidOperationException("Not connected");
                }

                if (!_netStream.DataAvailable)
                {
                    return;
                }

                lock (_ssl)
                {
                    PacketType type = (PacketType)IPAddress.NetworkToHostOrder(_reader.ReadInt16());
                    Console.WriteLine("{0:HH:mm:ss}: {1}", DateTime.Now, type.ToString());

                    switch (type)
                    {
                    case PacketType.Version:
                        _protocol.Version(Serializer.DeserializeWithLengthPrefix <MumbleProto.Version>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.CryptSetup:
                        var cryptSetup = Serializer.DeserializeWithLengthPrefix <CryptSetup>(_ssl, PrefixStyle.Fixed32BigEndian);
                        _connection.ProcessCryptState(cryptSetup);
                        SendPing();
                        break;

                    case PacketType.ChannelState:
                        _protocol.ChannelState(Serializer.DeserializeWithLengthPrefix <ChannelState>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.UserState:
                        _protocol.UserState(Serializer.DeserializeWithLengthPrefix <UserState>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.CodecVersion:
                        _protocol.CodecVersion(Serializer.DeserializeWithLengthPrefix <CodecVersion>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.ContextAction:
                        _protocol.ContextAction(Serializer.DeserializeWithLengthPrefix <ContextAction>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.ContextActionModify:
                        _protocol.ContextActionModify(Serializer.DeserializeWithLengthPrefix <ContextActionModify>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.PermissionQuery:
                        _protocol.PermissionQuery(Serializer.DeserializeWithLengthPrefix <PermissionQuery>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.ServerSync:
                        _protocol.ServerSync(Serializer.DeserializeWithLengthPrefix <ServerSync>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.ServerConfig:
                        _protocol.ServerConfig(Serializer.DeserializeWithLengthPrefix <ServerConfig>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.UDPTunnel:
                        var length = IPAddress.NetworkToHostOrder(_reader.ReadInt32());
                        _connection.ReceiveDecryptedUdp(_reader.ReadBytes(length));
                        break;

                    case PacketType.Ping:
                        var ping = Serializer.DeserializeWithLengthPrefix <Ping>(_ssl, PrefixStyle.Fixed32BigEndian);
                        _connection.ReceivePing(ping);
                        _protocol.Ping(ping);
                        break;

                    case PacketType.UserRemove:
                        _protocol.UserRemove(Serializer.DeserializeWithLengthPrefix <UserRemove>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.ChannelRemove:
                        _protocol.ChannelRemove(Serializer.DeserializeWithLengthPrefix <ChannelRemove>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.TextMessage:
                        var message = Serializer.DeserializeWithLengthPrefix <TextMessage>(_ssl, PrefixStyle.Fixed32BigEndian);
                        _protocol.TextMessage(message);
                        break;

                    case PacketType.Reject:
                        throw new NotImplementedException();

                    case PacketType.UserList:
                        _protocol.UserList(Serializer.DeserializeWithLengthPrefix <UserList>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.SuggestConfig:
                        _protocol.SuggestConfig(Serializer.DeserializeWithLengthPrefix <SuggestConfig>(_ssl, PrefixStyle.Fixed32BigEndian));
                        break;

                    case PacketType.Authenticate:
                    case PacketType.PermissionDenied:
                    case PacketType.ACL:
                    case PacketType.QueryUsers:
                    case PacketType.VoiceTarget:
                    case PacketType.UserStats:
                    case PacketType.RequestBlob:
                    case PacketType.BanList:
                    default:
                        throw new NotImplementedException();
                    }
                }
            }
Exemple #2
0
        public bool Process()
        {
            if (!_client.Connected)
            {
                throw new InvalidOperationException("Not connected");
            }

            if (!_netStream.DataAvailable)
            {
                return(false);
            }

            lock (_ssl)
            {
                PacketType type = (PacketType)IPAddress.NetworkToHostOrder(_reader.ReadInt16());
#if DEBUG
                Console.WriteLine("{0:HH:mm:ss}: {1}", DateTime.Now, type.ToString());
#endif

                switch (type)
                {
                case PacketType.Version:
                    _protocol.Version(Serializer.DeserializeWithLengthPrefix <MumbleProto.Version>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.CryptSetup:
                {
                    var cryptSetup = Serializer.DeserializeWithLengthPrefix <CryptSetup>(_ssl, PrefixStyle.Fixed32BigEndian);
                    _connection.ProcessCryptState(cryptSetup);
                    SendPing();
                }
                break;

                case PacketType.ChannelState:
                    _protocol.ChannelState(Serializer.DeserializeWithLengthPrefix <ChannelState>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.UserState:
                    _protocol.UserState(Serializer.DeserializeWithLengthPrefix <UserState>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.CodecVersion:
                    _protocol.CodecVersion(Serializer.DeserializeWithLengthPrefix <CodecVersion>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.ContextAction:
                    _protocol.ContextAction(Serializer.DeserializeWithLengthPrefix <ContextAction>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.PermissionQuery:
                    _protocol.PermissionQuery(Serializer.DeserializeWithLengthPrefix <PermissionQuery>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.ServerSync:
                    _protocol.ServerSync(Serializer.DeserializeWithLengthPrefix <ServerSync>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.ServerConfig:
                    _protocol.ServerConfig(Serializer.DeserializeWithLengthPrefix <ServerConfig>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.UDPTunnel:
                {
                    var length = IPAddress.NetworkToHostOrder(_reader.ReadInt32());
                    _connection.ReceiveDecryptedUdp(_reader.ReadBytes(length));
                }
                break;

                case PacketType.Ping:
                {
                    var ping = Serializer.DeserializeWithLengthPrefix <Ping>(_ssl, PrefixStyle.Fixed32BigEndian);
                    _connection.ReceivePing(ping);
                    _protocol.Ping(ping);
                }
                break;

                case PacketType.UserRemove:
                    _protocol.UserRemove(Serializer.DeserializeWithLengthPrefix <UserRemove>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.ChannelRemove:
                    _protocol.ChannelRemove(Serializer.DeserializeWithLengthPrefix <ChannelRemove>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.TextMessage:
                {
                    var message = Serializer.DeserializeWithLengthPrefix <TextMessage>(_ssl, PrefixStyle.Fixed32BigEndian);
                    _protocol.TextMessage(message);
                }
                break;

                case PacketType.Reject:
                    _protocol.Reject(Serializer.DeserializeWithLengthPrefix <Reject>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.UserList:
                    _protocol.UserList(Serializer.DeserializeWithLengthPrefix <UserList>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.SuggestConfig:
                    _protocol.SuggestConfig(Serializer.DeserializeWithLengthPrefix <SuggestConfig>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.PermissionDenied:
                    _protocol.PermissionDenied(Serializer.DeserializeWithLengthPrefix <PermissionDenied>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.ACL:
                    _protocol.Acl(Serializer.DeserializeWithLengthPrefix <Acl>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.QueryUsers:
                    _protocol.QueryUsers(Serializer.DeserializeWithLengthPrefix <QueryUsers>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.UserStats:
                    _protocol.UserStats(Serializer.DeserializeWithLengthPrefix <UserStats>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;

                case PacketType.BanList:
                    _protocol.BanList(Serializer.DeserializeWithLengthPrefix <BanList>(_ssl, PrefixStyle.Fixed32BigEndian));
                    break;


                //The following PacketTypes are only sent from client to server (see https://github.com/mumble-voip/mumble/blob/master/src/Mumble.proto)
                case PacketType.Authenticate:
                case PacketType.ContextActionModify:
                case PacketType.RequestBlob:
                case PacketType.VoiceTarget:
                default:
                    throw new NotImplementedException($"{nameof(Process)} {nameof(PacketType)}.{type.ToString()}");
                }
            }

            return(true);
        }