private void MetadataPacketHandler(Packet pa)
        {
            MetadataPacket p = pa as MetadataPacket;

            switch (p.SData[0])
            {
            case "admin_login":
                if (p.SData[1] != "true")
                {
                    FailureMessage = "You are not an admin.";
                    CurrentStep    = ProgressStep.LoginFailed;
                }
                break;

            case "server_name":
                Server.Name = p.SData[1];
                break;
            }
        }
예제 #2
0
        public FLVFile(Stream stream)
        {
            sourceStream = stream;
            Size         = stream.Length;
            DataStream ds = new DataStream(stream);

            ds.BigEndian = true;
            ds.Unsecure  = true;

            Header = new FLVHeader(ds);
            while (stream.Position < stream.Length)
            {
                BasePacket packet = PacketFactory.ReadPacket(ds);

                if (packet.PacketType == 0 && packet.PayloadSize == 0)
                {
                    if (stream.Position < stream.Length)
                    {
                        Console.WriteLine("Zero data detected at {0}. Integrity is unrecoverable. Dropping the rest of stream ({1} bytes remains).", stream.Position, stream.Length - stream.Position);
                    }

                    break;
                }

                if (packet is MetadataPacket metadataPacket)
                {
                    if (Metadata != null)
                    {
                        Console.WriteLine("Discarding duplicate metadata packet at: {0}", metadataPacket.Offset);
                        continue;
                    }

                    Metadata = metadataPacket;
                }

                Packets.Add(packet);
            }
        }
예제 #3
0
        public void FixMetadata()
        {
            if (Metadata == null)
            {
                logger.Log("No metadata packet found. Creating new.");
                Metadata = new MetadataPacket(FLVHeader.HEADER_SIZE);
                Packets.Insert(0, Metadata);
            }

            // remove meaningless stuff
            Metadata.Variables.Remove("metadatacreator");
            Metadata.Variables.Remove("creationdate");
            Metadata.Variables.Remove("metadatadate");
            Metadata.Variables.Remove("datasize");
            Metadata.Variables.Remove("videodatarate");
            Metadata.Variables.Remove("audiodatarate");

            // lil` improvement
            Metadata.Variables["canSeekToEnd"] = true;

            // latest frame
            TimeSpan maxTimeStamp = Packets.Max(e => e.TimeStamp);

            // update seeking fields
            Metadata.Variables["duration"]      = maxTimeStamp.TotalSeconds;
            Metadata.Variables["lasttimestamp"] = maxTimeStamp.TotalSeconds;

            // update last key frame, if possible
            BasePacket lastKeyFrame = Packets.LastOrDefault(e => e.PacketType == PacketType.VideoPayload && ((VideoPacket)e).FrameType == VideoFrameType.KeyFrame);

            if (lastKeyFrame != null)
            {
                Metadata.Variables["lastkeyframetimestamp"] = lastKeyFrame.TimeStamp.TotalSeconds;
            }

            logger.Log(" -- Video duration: {0} seconds", maxTimeStamp.TotalSeconds);

            // first audio/video packets
            VideoPacket videoPacket = (VideoPacket)Packets.First(e => e.PacketType == PacketType.VideoPayload);
            AudioPacket audioPacket = (AudioPacket)Packets.FirstOrDefault(e => e.PacketType == PacketType.AudioPayload);

            if (audioPacket == null)
            {
                Header.Flags &= ~FLVFlags.Audio;

                Metadata.Variables.Remove("audiosamplerate");
                Metadata.Variables.Remove("audiosamplesize");
                Metadata.Variables.Remove("stereo");
                Metadata.Variables.Remove("audiocodecid");
                Metadata.Variables.Remove("audiodelay");
                Metadata.Variables.Remove("audiosize");

                logger.Log(" -- Audio: no");
            }
            else
            {
                // update audio data
                Metadata.Variables["audiosamplerate"] = audioPacket.GetSampleRate();
                Metadata.Variables["audiosamplesize"] = audioPacket.GetSoundSize();
                Metadata.Variables["stereo"]          = audioPacket.GetStereo();
                Metadata.Variables["audiocodecid"]    = audioPacket.GetSoundFormat();
                Metadata.Variables["audiodelay"]      = videoPacket.TimeStamp.TotalSeconds;
                Metadata.Variables["audiosize"]       = (double)AudioDataBytes;
                logger.Log(
                    " -- Audio: {0} Hz {1} bits {2} Codec: {3} Delay {4} sec",
                    audioPacket.GetSampleRate(),
                    audioPacket.GetSoundSize(),
                    audioPacket.GetStereo() ? "stereo" : "mono",
                    audioPacket.SoundFormat,
                    videoPacket.TimeStamp.TotalSeconds
                    );
            }

            // update video data
            Metadata.Variables["videosize"]    = (double)VideoDataBytes;
            Metadata.Variables["videocodecid"] = videoPacket.GetCodecId();
            logger.Log(" -- Video codec: {0}", videoPacket.CodecId);

            videoPacket = (VideoPacket)Packets.FirstOrDefault(e => e.PacketType == PacketType.VideoPayload && ((VideoPacket)e).Width > 0 && ((VideoPacket)e).Height > 0);
            if (videoPacket != null)
            {
                Metadata.Variables["width"]  = (double)videoPacket.Width;
                Metadata.Variables["height"] = (double)videoPacket.Height;
                logger.Log(" -- Video dimensions: {0}x{1}", videoPacket.Width, videoPacket.Height);
            }
        }
예제 #4
0
        void ph_Metadata(Packet pa)
        {
            MetadataPacket p  = pa as MetadataPacket;
            StringBuilder  sb = new StringBuilder();

            for (int i = 0; i < p.SData.Length; i++)
            {
                sb.AppendFormat("StringData {0}: {1}\r\n", i, p.SData[i]);
            }
            for (int i = 0; i < p.IData.Length; i++)
            {
                sb.AppendFormat("IntData {0}: {1}\r\n", i, p.IData[i]);
            }
            for (int i = 0; i < p.FData.Length; i++)
            {
                sb.AppendFormat("FloatData {0}: {1}\r\n", i, p.FData[i]);
            }
            Debug.Assert(sb.ToString());
            if (p.SData[0] == "shutdown")
            {
                Server.Shutdown = true;
                if (SplashScreen.GetScreen() != null)
                {
                    SplashScreen.UpdateStatusTextWithStatus(p.SData[1], TypeOfMessage.Error);
                    SplashScreen.GetScreen().Progress.StartColor = Color.FromArgb(210, 202, 0);
                    SplashScreen.GetScreen().Progress.EndColor = Color.FromArgb(210, 202, 0);
                }
                else
                {
                    MessageBox.Show(p.SData[1], "Server Shutdown");
                }
                MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Server Shutdown.  Reason: " + p.SData[1]);
            }
            else if (p.SData[0] == "server_name")
            {
                Server.Name     = p.SData[1];
                Server.FontSize = p.FData[0];
                Properties.Settings.Default.MinecraftPath = Environment.CurrentDirectory + "/Minecraft/" + ServerFolder;
                MinecraftModUpdater.Logger.Log(Logger.Level.Info, string.Format("Minecraft path set to: {0}", Properties.Settings.Default.MinecraftPath));
            }
            else if (p.SData[0] == "splash_display")
            {
                SplashScreen.UpdateStatusText(p.SData[1]);
            }
            else if (p.SData[0] == "require_version")
            {
                warnDisconnect = false;
                SplashScreen.UpdateStatusTextWithStatus("This server requires API version " + p.SData[1] + " for you to connect.", TypeOfMessage.Error);
                Thread.Sleep(3000);
                SplashScreen.CloseSplashScreen();
                Thread.Sleep(1000);
                Program.RunOnUIThread(delegate
                {
                    Close();
                });
            }
            else if (p.SData[0] == "version_downgrade")
            {
                ClientVersion = p.SData[1];
            }
        }