Exemplo n.º 1
0
        public CServerSearchResults(MemoryStream buffer, CSearcher search, bool esUDP)
        {
            BinaryReader reader = new BinaryReader(buffer);

            if (!esUDP)
            {
                uint nResultados = reader.ReadUInt32();
                for (uint i = 0; i < nResultados; i++)
                {
                    m_ExtractResult(reader, search);
                }
                search.OnTCPSearchEnded();
            }
            else
            {
                m_ExtractResult(reader, search);
                while ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
                {
                    Debug.WriteLine("MoreUDP results in one packet");
                    if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey)
                    {
                        break;
                    }
                    if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalSearchResult))
                    {
                        break;
                    }
                    m_ExtractResult(reader, search);
                }
            }
            reader.Close();
            buffer.Close();
            reader = null;
            buffer = null;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Send a search packet via TCP to server.
 /// </summary>
 /// <param name="packet">packet</param>
 /// <param name="searcher">searcher</param>
 public void SendTCPSearch(MemoryStream packet, CSearcher searcher)
 {
     m_LastSearcher = searcher;
     if (m_ServerConnection != null)
     {
         m_ServerConnection.SendPacket(packet);
     }
 }
Exemplo n.º 3
0
        internal static void DeleteSearch(int searchID)
        {
            CSearcher searcher = (CSearcher)Searchs[searchID];

            if (searcher != null)
            {
                searcher.CancelSearch();
            }
            Searchs.Remove(searchID);
        }
Exemplo n.º 4
0
        internal static void NewSearch(int searchID, string searchString, bool matchAnyWords, string type, uint maxSize, uint minSize, uint avaibility, string exclude)
        {
            CKernel.LastSearch = searchID;
            if (ServersList.ActiveServer == null)
            {
                SearchEnded(searchID);
                return;
            }
            CSearcher search = new CSearcher(searchString, matchAnyWords, type, maxSize, minSize, avaibility, exclude);

            Searchs.Add(searchID, search);
        }
Exemplo n.º 5
0
        internal static void ExtendSearch(int searchID)
        {
            CSearcher searcher = (CSearcher)Searchs[searchID];

            for (int i = 0; i < 5; i++)
            {
                if (searcher != null)
                {
                    searcher.ExtendSearch();
                }
            }
            if (ServersList.ActiveServer != null)
            {
                ServersList.ActiveServer.QueryMoreResults();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Send a search packet via UDP to server.
 /// </summary>
 /// <param name="packet">packet</param>
 /// <param name="searcher">searcher</param>
 public void SendUDPSearch(MemoryStream packet, CSearcher searcher)
 {
     m_LastSearcher = searcher;
     m_SendPacketUDP(packet);
 }
Exemplo n.º 7
0
        private uint m_ExtractResult(BinaryReader reader, CSearcher search)
        {
            CParameterReader parameterReader;

            byte[] HashEncontrado = reader.ReadBytes(16);
            uint   ip             = reader.ReadUInt32();
            ushort port           = reader.ReadUInt16();
            uint   nParametros    = reader.ReadUInt32();
            string fileName       = "?";
            uint   fileSize       = 0;
            uint   nSources       = 1;
            string codec          = "";
            uint   bitrate        = 0;
            string length         = "";
            bool   complete       = false;

            for (uint param = 0; param != nParametros; param++)
            {
                parameterReader = new CParameterReader(reader);
                switch ((Protocol.FileTag)parameterReader.id)
                {
                case Protocol.FileTag.Name:
                    fileName = parameterReader.valorString;
                    break;

                case Protocol.FileTag.Size:
                    fileSize = parameterReader.valorNum;
                    break;

                case Protocol.FileTag.Sources:
                    nSources = parameterReader.valorNum;
                    break;

                case Protocol.FileTag.Completed:
                    complete = parameterReader.valorNum > 0;
                    break;

                default:
                    if (parameterReader.nombreParam == Protocol.FileExtraTags.codec.ToString())
                    {
                        codec = parameterReader.valorString;
                    }
                    else if (parameterReader.nombreParam == Protocol.FileExtraTags.length.ToString())
                    {
                        length = parameterReader.valorString;
                    }
                    else if (parameterReader.nombreParam == Protocol.FileExtraTags.bitrate.ToString())
                    {
                        bitrate = parameterReader.valorNum;
                    }
                    //Debug.WriteLine(parameterReader.id+" name: "+parameterReader.nombreParam+" valString:"+parameterReader.valorString+" valNum: "+parameterReader.valorNum);
                    break;
                }
            }
            if (fileSize < Protocol.PartSize)
            {
                complete = true;
            }
            search.AddFileFound(HashEncontrado, fileName, fileSize, nSources, codec, length, bitrate, complete, ip, port);
            return(nSources);
        }