Пример #1
0
        protected override void PacketRecieved(string packetstr) {
            VoicePacket packet = new VoicePacket(packetstr);
            VoicePacketType type = packet.GetPacketType();

            if (type == VoicePacketType.Hello) {
                Logger.Info("Voice server says hello!");
                SendIdentityPacket();
            } else if (type == VoicePacketType.Ready) {
                readyData = packet.GetData<VoiceChannelReady>();

                try {
                    stream = new AudioStream(readyData);
                    stream.Connect();

                    BasicPacket spacket = new SelectProtocol(readyData.ip, readyData.port);
                    Send(spacket);
                } catch (Exception e) {
                    Logger.Error($"AudioStream connection error: {e.Message}");
                    Disconnect();
                }
            } else if (type == VoicePacketType.ClientDisconnect) {
                Disconnect();
            } else if (type == VoicePacketType.CodecInformation) {
                CodecInformation codecinfo = packet.GetData<CodecInformation>();
                Logger.Info($"Audio codec is {codecinfo.audio_codec}");
                stream.SetCodec(codecinfo.audio_codec);
            } else {
                Logger.Debug($"Unchecked type: {type}");
            }
        }