void SearchManager::respond(const AdcCommand& adc, const CID& from) { // Filter own searches if(from == ClientManager::getInstance()->getMe()->getCID()) return; User::Ptr p = ClientManager::getInstance()->findUser(from); if(!p) return; SearchResult::List results; ShareManager::getInstance()->search(results, adc.getParameters(), 10); string token; adc.getParam("TO", 0, token); if(results.empty()) return; for(SearchResult::Iter i = results.begin(); i != results.end(); ++i) { AdcCommand cmd = (*i)->toRES(AdcCommand::TYPE_UDP); if(!token.empty()) cmd.addParam("TO", token); ClientManager::getInstance()->send(cmd, from); (*i)->decRef(); } }
void ClientManager::on(NmdcSearch, Client* aClient, const string& aSeeker, int aSearchType, int64_t aSize, int aFileType, const string& aString) throw() { Speaker<ClientManagerListener>::fire(ClientManagerListener::IncomingSearch(), aString); bool isPassive = (aSeeker.compare(0, 4, "Hub:") == 0); // We don't wan't to answer passive searches if we're in passive mode... if(isPassive && !ClientManager::getInstance()->isActive()) { return; } SearchResult::List l; ShareManager::getInstance()->search(l, aString, aSearchType, aSize, aFileType, aClient, isPassive ? 5 : 10); // dcdebug("Found %d items (%s)\n", l.size(), aString.c_str()); if(l.size() > 0) { if(isPassive) { string name = aSeeker.substr(4); // Good, we have a passive seeker, those are easier... string str; for(SearchResult::Iter i = l.begin(); i != l.end(); ++i) { SearchResult* sr = *i; str += sr->toSR(*aClient); str[str.length()-1] = 5; str += name; str += '|'; sr->decRef(); } if(str.size() > 0) aClient->send(str); } else { try { string ip, file; uint16_t port = 0; Util::decodeUrl(aSeeker, ip, port, file); ip = Socket::resolve(ip); // Temporary fix to avoid spamming hublist.org and dcpp.net if(ip == "70.85.55.252" || ip == "207.44.220.108") { LogManager::getInstance()->message("Someone is trying to use your client to spam " + ip + ", please urge hub owner to fix this"); return; } if(port == 0) port = 412; for(SearchResult::Iter i = l.begin(); i != l.end(); ++i) { SearchResult* sr = *i; udp.writeTo(ip, port, sr->toSR(*aClient)); sr->decRef(); } } catch(const SocketException& /* e */) { dcdebug("Search caught error\n"); } } } }