Beispiel #1
0
        private void HubSearchRequest(object sender, SearchRequestEventArgs e)
        {
            var ea = new EngineSearchRequestEventArgs
            {
                HubConnection = (HubConnection)sender,
                Message       = e.Message
            };

            OnSearchRequest(ea);

            if (ea.Cancel)
            {
                return;
            }

            if (Share != null && e.Message.SearchType == SearchType.TTH)
            {
                _searchesAverage.Update(1);

                var results = Share.Search(new SearchQuery {
                    Query = e.Message.SearchRequest, SearchType = SearchType.TTH
                });
                if (results.Count > 0)
                {
                    var result = results[0];
                    var hub    = (HubConnection)sender;
                    var res    = new SRMessage
                    {
                        FileName  = result.VirtualPath,
                        FileSize  = result.Magnet.Size,
                        Nickname  = hub.Settings.Nickname,
                        FreeSlots =
                            Settings.MaxUploadThreads > 0
                                              ? Settings.MaxUploadThreads - TransferManager.TransfersCount
                                              : 0,
                        HubAddress = hub.RemoteAddressString,
                        HubName    = "TTH:" + result.Magnet.TTH,
                        TotalSlots = Settings.MaxUploadThreads
                    };

                    if (e.Message.SearchAddress.StartsWith("Hub:"))
                    {
                        res.TargetNickname = e.Message.SearchAddress.Remove(0, 4);
                        hub.SendMessage(res.Raw);
                    }
                    else
                    {
                        UdpConnection.SendMessage(res.Raw, e.Message.SearchAddress);
                    }
                }
            }
        }
Beispiel #2
0
 private void OnSearchRequest(EngineSearchRequestEventArgs e)
 {
     SearchRequest?.Invoke(this, e);
 }