예제 #1
0
        public static void Browse(AresClient client, TCPPacketReader packet)
        {
            ushort     ident  = packet;
            byte       mime   = packet;
            String     name   = packet.ReadString(client);
            AresClient target = UserPool.AUsers.Find(x => x.Name == name);

            if (target == null && ServerCore.Linker.Busy && ServerCore.Linker.LoginPhase == LinkLeaf.LinkLogin.Ready)
            {
                IClient linked = ServerCore.Linker.FindUser(x => x.Name == name && x.FileCount > 0 && x.Browsable);

                if (linked != null)
                {
                    ServerCore.Linker.SendPacket(LinkLeaf.LeafOutbound.LeafBrowse(ServerCore.Linker,
                                                                                  linked.IUser.Link.Ident, linked.Name, client.Name, ident, mime));

                    return;
                }
            }

            if (target == null)
            {
                client.SendPacket(TCPOutbound.BrowseError(ident));
            }
            else if (target.SharedFiles.Count == 0)
            {
                client.SendPacket(TCPOutbound.BrowseError(ident));
            }
            else
            {
                var linq = from x in target.SharedFiles
                           where (mime == 0 || mime == 255) || (byte)x.Mime == (mime == 8 ? 0 : mime)
                           select TCPOutbound.BrowseItem(ident, x);

                client.SendPacket(TCPOutbound.StartOfBrowse(ident, (ushort)linq.Count()));

                List <byte> buffer = new List <byte>();

                foreach (byte[] x in linq)
                {
                    buffer.AddRange(x);

                    if (buffer.Count > 1024)
                    {
                        client.SendPacket(TCPOutbound.ClientCompressed(buffer.ToArray()));
                        buffer.Clear();
                    }
                }

                if (buffer.Count > 0)
                {
                    client.SendPacket(TCPOutbound.ClientCompressed(buffer.ToArray()));
                }

                client.SendPacket(TCPOutbound.EndOfBrowse(ident));
            }
        }