Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ClientManager::on(NmdcSearch, Client* aClient, const string& aSeeker, int aSearchType, int64_t aSize,
- int aFileType, const string& aString) noexcept
- {
- 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;
- }
- auto l = ShareManager::getInstance()->search(aString, aSearchType, aSize, aFileType, isPassive ? 5 : 10);
- // dcdebug("Found %d items (%s)\n", l.size(), aString.c_str());
- if(!l.empty()) {
- if(isPassive) {
- string name = aSeeker.substr(4);
- // Good, we have a passive seeker, those are easier...
- string str;
- for(const auto& sr: l) {
- str += sr->toSR(*aClient);
- str[str.length()-1] = 5;
- str += name;
- str += '|';
- }
- if(!str.empty())
- aClient->send(str);
- } else {
- string ip, port;
- auto ipPort = static_cast<NmdcHub*>(aClient)->parseIpPort(aSeeker);
- port = ipPort.second;
- ip = Socket::resolve(ipPort.first, AF_INET);
- if(static_cast<NmdcHub*>(aClient)->isProtectedIP(ip))
- return;
- if(port.empty())
- port = "412";
- for(const auto& sr: l) {
- sendUDP(ip, port, sr->toSR(*aClient));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement