示例#1
0
        public static byte[] BrowseItem(ushort id, SharedFile file)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt16(id);
            packet.WriteByte((byte)file.Mime);
            packet.WriteUInt32(file.Size);
            packet.WriteBytes(file.Data);
            return(packet.ToAresPacket(TCPMsg.MSG_CHAT_SERVER_BROWSEITEM));
        }
        public static void FileReceived(IClient client, SharedFile file)
        {
            if (DefaultCommands)
            {
                cmds.FileReceived(client != null ? client.IUser : null, file.FileName, file.Title, file.Mime);
            }

            js.FileReceived(client != null ? client.IUser : null, file.FileName, file.Title, file.Mime);

            ExtensionManager.Plugins.ForEach(x =>
            {
                try { x.Plugin.FileReceived(client != null ? client.IUser : null, file.FileName, file.Title, file.Mime); }
                catch { }
            });
        }
示例#3
0
        public static void AddShare(AresClient client, TCPPacketReader packet)
        {
            if (client.SharedFiles.Count > 12000)
            {
                throw new Exception("addshare max limit exceeded");
            }

            SharedFile file = new SharedFile();

            file.Mime = (MimeType)(byte)packet;
            file.Size = packet;
            ushort len = packet;

            packet.SkipBytes(len);
            file.Data = packet;

            if (PopulateMetaData(file))
            {
                client.SharedFiles.Add(file);
                Events.FileReceived(client, file);
            }
        }
示例#4
0
        private static bool PopulateMetaData(SharedFile file)
        {
            TCPPacketReader packet = new TCPPacketReader(file.Data);

            packet.SkipBytes(16);

            if (file.Mime == MimeType.ARES_MIME_MP3)
            {
                packet.SkipBytes(4);
            }
            else if (file.Mime == MimeType.ARES_MIME_VIDEO)
            {
                packet.SkipBytes(6);
            }
            else if (file.Mime == MimeType.ARES_MIME_IMAGE)
            {
                packet.SkipBytes(5);
            }

            ushort len     = packet;
            ushort counter = 0;

            file.FileName = String.Empty;
            file.Title    = String.Empty;

            while (packet.Remaining >= 2)
            {
                byte length = packet;
                byte type   = packet;

                if (length > packet.Remaining)
                {
                    return(false);
                }

                switch (type)
                {
                case 1:
                    file.Title = Encoding.UTF8.GetString(packet.ReadBytes(length));
                    break;

                case 15:
                    file.FileName = Encoding.UTF8.GetString(packet.ReadBytes(length));
                    break;

                default:
                    packet.SkipBytes(length);
                    break;
                }

                counter += 2;
                counter += length;

                if (counter >= len)
                {
                    break;
                }
            }

            return(true);
        }
示例#5
0
        public static byte[] SearchHit(AresClient client, ushort id, AresClient target, SharedFile file)
        {
            TCPPacketWriter packet = new TCPPacketWriter();

            packet.WriteUInt16(id);
            packet.WriteByte((byte)file.Mime);
            packet.WriteUInt32(file.Size);
            packet.WriteBytes(file.Data);
            packet.WriteString(client, target.Name);
            packet.WriteIP(target.ExternalIP);
            packet.WriteUInt16(target.DataPort);
            packet.WriteIP(target.NodeIP);
            packet.WriteUInt16(target.NodePort);
            packet.WriteIP(target.LocalIP);
            packet.WriteByte(target.CurrentUploads);
            packet.WriteByte(target.MaxUploads);
            packet.WriteByte(target.CurrentQueued);
            packet.WriteByte(1);
            return(packet.ToAresPacket(TCPMsg.MSG_CHAT_SERVER_SEARCHHIT));
        }