示例#1
0
            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();
                    }
                }
            }