Advertisement
Guest User

Untitled

a guest
Mar 18th, 2015
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. void ClientManager::on(NmdcSearch, Client* aClient, const string& aSeeker, int aSearchType, int64_t aSize,
  2.                                     int aFileType, const string& aString) noexcept
  3. {
  4.     bool isPassive = (aSeeker.compare(0, 4, "Hub:") == 0);
  5.  
  6.     // We don't wan't to answer passive searches if we're in passive mode...
  7.     if(isPassive && !ClientManager::getInstance()->isActive()) {
  8.         return;
  9.     }
  10.  
  11.     auto l = ShareManager::getInstance()->search(aString, aSearchType, aSize, aFileType, isPassive ? 5 : 10);
  12. //      dcdebug("Found %d items (%s)\n", l.size(), aString.c_str());
  13.     if(!l.empty()) {
  14.         if(isPassive) {
  15.             string name = aSeeker.substr(4);
  16.             // Good, we have a passive seeker, those are easier...
  17.             string str;
  18.             for(const auto& sr: l) {
  19.                 str += sr->toSR(*aClient);
  20.                 str[str.length()-1] = 5;
  21.                 str += name;
  22.                 str += '|';
  23.             }
  24.  
  25.             if(!str.empty())
  26.                 aClient->send(str);
  27.  
  28.         } else {
  29.             string ip, port;
  30.  
  31.             auto ipPort = static_cast<NmdcHub*>(aClient)->parseIpPort(aSeeker);
  32.  
  33.             port = ipPort.second;
  34.             ip = Socket::resolve(ipPort.first, AF_INET);
  35.  
  36.             if(static_cast<NmdcHub*>(aClient)->isProtectedIP(ip))
  37.                 return;
  38.  
  39.             if(port.empty())
  40.                 port = "412";
  41.  
  42.             for(const auto& sr: l) {
  43.                 sendUDP(ip, port, sr->toSR(*aClient));
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement