コード例 #1
0
        public static void Search(AresClient client, TCPPacketReader packet)
        {
            ushort ident = packet;

            packet.SkipByte();
            byte          mime  = packet;
            ushort        len   = packet;
            List <byte[]> items = new List <byte[]>();

            List <String> search_words = new List <String>(
                Encoding.UTF8.GetString(packet.ReadBytes(len)).ToUpper().Replace("\0",
                                                                                 " ").Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                );

            UserPool.AUsers.ForEachWhere(x =>
            {
                x.SharedFiles.ForEachWhere(y =>
                {
                    String[] words = y.FileName.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    words          = words.Concat(y.Title.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries)).ToArray();

                    foreach (String str in words)
                    {
                        if (search_words.Contains(str.ToUpper()))
                        {
                            items.Add(TCPOutbound.SearchHit(client, ident, x, y));
                            break;
                        }
                    }
                },
                                           y => (mime == 0 || mime == 255) || (byte)y.Mime == (mime == 8 ? 0 : mime));
            },
                                         x => x.SocketConnected && x.Browsable);

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

            foreach (byte[] x in items)
            {
                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.EndOfSearch(ident));
        }