void UserInfoBase::ungrantSlot(const string& hubHint) // [!] IRainman fix: add hubhint. { if (getUser()) { UploadManager::unreserveSlot(HintedUser(getUser(), hubHint)); } }
void UserInfoBase::doReport(const string& hubHint) { if (getUser()) { ClientManager::getInstance()->reportUser(HintedUser(getUser(), hubHint)); } }
LRESULT ChatCtrl::onPrivateMessage(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { OnlineUserPtr ou = client->findUser(Text::fromT(selectedUser)); if(ou) PrivateFrame::openWindow(HintedUser(ou->getUser(), client->getHubUrl()), Util::emptyStringT, client); return 0; }
void QueuedUsers::slotContextMenu(){ QModelIndexList indexes = treeView_USERS->selectionModel()->selectedRows(0); if (indexes.isEmpty()) return; QMenu *m = new QMenu(this); m->addAction(tr("Grant slot")); if (m->exec(QCursor::pos())){ for (const auto &i : indexes){ QueuedUserItem *item = reinterpret_cast<QueuedUserItem*>(i.internalPointer()); if (!item) continue; QString id = item->cid; if (!id.isEmpty()){ UserPtr user = ClientManager::getInstance()->findUser(CID(id.toStdString())); if (user){ try { UploadManager::getInstance()->reserveSlot(HintedUser(user, _tq(item->hub))); } catch ( ... ) {} } } } } m->deleteLater(); }
void UserManager::checkUser(const OnlineUserPtr& user) { if (BOOLSETTING(CHECK_NEW_USERS)) { if (!ClientManager::getInstance()->isMe(user)) { const Client& client = user->getClient(); if (!client.getExcludeCheck() && client.isOp() && (client.isActive() || user->getIdentity().isTcpActive())) { if (!BOOLSETTING(PROT_FAVS) || !FavoriteManager::getInstance()->isNoFavUserOrUserBanUpload(user->getUser())) // !SMT!-opt { if (!isInProtectedUserList(user->getIdentity().getNick())) { try { QueueManager::getInstance()->addList(HintedUser(user->getUser(), client.getHubUrl()), QueueItem::FLAG_USER_CHECK); } catch (const Exception& e) { LogManager::getInstance()->message(e.getError()); } } } } } } }
HintedUser ClientManager::findLegacyUser(const string& nick) const noexcept { if(nick.empty()) return HintedUser(); Lock l(cs); for(auto i: clients) { auto nmdc = dynamic_cast<NmdcHub*>(i); if(nmdc) { /** @todo run the search directly on non-UTF-8 nicks when we store them. */ auto ou = nmdc->findUser(nmdc->toUtf8(nick)); if(ou) { return HintedUser(*ou); } } } return HintedUser(); }
LRESULT ChatCtrl::onCheckList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { const OnlineUserPtr ou = client->findUser(Text::fromT(selectedUser)); if(ou) { try { QueueManager::getInstance()->addList(HintedUser(ou->getUser(), client->getHubUrl()), QueueItem::FLAG_USER_CHECK, client->getHubUrl()); } catch(const Exception& e) { LogManager::getInstance()->message(e.getError()); } } return 0; }
void SearchManager::onRES(const AdcCommand& cmd, const UserPtr& from, const string& remoteIp) { int freeSlots = -1; int64_t size = -1; string file; string tth; string token; for(auto& str: cmd.getParameters()) { if(str.compare(0, 2, "FN") == 0) { file = Util::toNmdcFile(str.substr(2)); } else if(str.compare(0, 2, "SL") == 0) { freeSlots = Util::toInt(str.substr(2)); } else if(str.compare(0, 2, "SI") == 0) { size = Util::toInt64(str.substr(2)); } else if(str.compare(0, 2, "TR") == 0) { tth = str.substr(2); } else if(str.compare(0, 2, "TO") == 0) { token = str.substr(2); } } if(file.empty() || freeSlots == -1 || size == -1) { return; } auto type = (*(file.end() - 1) == '\\' ? SearchResult::TYPE_DIRECTORY : SearchResult::TYPE_FILE); if(type == SearchResult::TYPE_FILE && tth.empty()) { return; } string hubUrl; // token format: [per-hub unique id] "/" [per-search actual token] (see AdcHub::search) auto slash = token.find('/'); if(slash == string::npos) { return; } { auto uniqueId = Util::toUInt32(token.substr(0, slash)); auto lock = ClientManager::getInstance()->lock(); auto& clients = ClientManager::getInstance()->getClients(); auto i = boost::find_if(clients, [uniqueId](const Client* client) { return client->getUniqueId() == uniqueId; }); if(i == clients.end()) { return; } hubUrl = (*i)->getHubUrl(); } token.erase(0, slash + 1); StringList names = ClientManager::getInstance()->getHubNames(from->getCID()); string hubName = names.empty() ? _("Offline") : Util::toString(names); /// @todo Something about the slots fire(SearchManagerListener::SR(), SearchResultPtr(new SearchResult(HintedUser(from, hubUrl), type, 0, freeSlots, size, file, hubName, remoteIp, TTHValue(tth), token))); }
LRESULT ChatCtrl::onGrantSlot(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { const OnlineUserPtr ou = client->findUser(Text::fromT(selectedUser)); if(ou) { uint64_t time = 0; switch(wID) { case IDC_GRANTSLOT: time = 600; break; case IDC_GRANTSLOT_DAY: time = 3600; break; case IDC_GRANTSLOT_HOUR: time = 24*3600; break; case IDC_GRANTSLOT_WEEK: time = 7*24*3600; break; case IDC_UNGRANTSLOT: time = 0; break; } if(time > 0) UploadManager::getInstance()->reserveSlot(HintedUser(ou->getUser(), client->getHubUrl()), time); else UploadManager::getInstance()->unreserveSlot(ou->getUser()); } return 0; }
void MessageManager::onPrivateMessage(const ChatMessagePtr& aMessage) { bool myPM = aMessage->getReplyTo()->getUser() == ClientManager::getInstance()->getMe(); const UserPtr& user = myPM ? aMessage->getTo()->getUser() : aMessage->getReplyTo()->getUser(); size_t wndCnt; { WLock l(cs); wndCnt = chats.size(); auto i = chats.find(user); if (i != chats.end()) { i->second->handleMessage(aMessage); //We should have a listener in the frame return; } } auto c = aMessage->getFrom()->getClient(); if (wndCnt > 200 || (!myPM && isIgnoredOrFiltered(aMessage, c.get(), true))) { DisconnectCCPM(user); return; } const auto& identity = aMessage->getReplyTo()->getIdentity(); if ((identity.isBot() && !SETTING(POPUP_BOT_PMS)) || (identity.isHub() && !SETTING(POPUP_HUB_PMS))) { c->Message(STRING(PRIVATE_MESSAGE_FROM) + " " + identity.getNick() + ": " + aMessage->format()); return; } auto chat = addChat(HintedUser(user, aMessage->getReplyTo()->getClient()->getHubUrl()), true); chat->handleMessage(aMessage); if (AirUtil::getAway() && (!SETTING(NO_AWAYMSG_TO_BOTS) || !user->isSet(User::BOT))) { ParamMap params; aMessage->getFrom()->getIdentity().getParams(params, "user", false); string error; chat->sendMessage(AirUtil::getAwayMessage(c->get(HubSettings::AwayMsg), params), error, false); } }
// !SMT!-UI void UserInfoBase::grantSlotPeriod(const string& hubHint, const uint64_t period) { if (period && getUser()) UploadManager::getInstance()->reserveSlot(HintedUser(getUser(), hubHint), period); }
SearchResult::SearchResult(Types aType, int64_t aSize, const string& aPath, const TTHValue& aTTH, time_t aDate, int aFiles, int aDirCount) : path(aPath), user(HintedUser(ClientManager::getInstance()->getMe(), Util::emptyString)), size(aSize), type(aType), totalSlots(UploadManager::getInstance()->getSlots()), freeSlots(UploadManager::getInstance()->getFreeSlots()), files(aFiles), folders(aDirCount), tth(aTTH), date(aDate) { }
HintedUser Deserializer::deserializeHintedUser(const json& aJson, bool aAllowMe, const string& aFieldName) { auto user = JsonUtil::getRawValue(aFieldName, aJson); return HintedUser(deserializeUser(user), JsonUtil::getField<string>("hub_url", user, false)); }
HintedUser Deserializer::deserializeHintedUser(const json& aJson, bool aAllowMe, const string& aFieldName) { auto userJson = JsonUtil::getRawValue(aFieldName, aJson); auto user = parseUser(userJson, aAllowMe); return HintedUser(user, JsonUtil::getField<string>("hub_url", userJson, aAllowMe && user == ClientManager::getInstance()->getMe())); }
void ListLoader::startTag(const string& name, StringPairList& attribs, bool simple) { #ifdef _DEBUG static size_t g_max_attribs_size = 0; if (g_max_attribs_size != attribs.size()) { g_max_attribs_size = attribs.size(); // dcdebug("ListLoader::startTag g_max_attribs_size = %d , attribs.capacity() = %d\n", g_max_attribs_size, attribs.capacity()); } #endif if (ClientManager::isBeforeShutdown()) { throw AbortException("ListLoader::startTag - ClientManager::isBeforeShutdown()"); } if (m_list->getAbort()) { throw AbortException("ListLoader::startTag - " + STRING(ABORT_EM)); } if (m_is_in_listing) { if (name == g_SFile) { dcassert(attribs.size() >= 3); // Иногда есть Shared - 4-тый атрибут. // это тэг от грея. его тоже можно обработать и записать в TS. хотя там 64 битное время const string& l_name = getAttrib(attribs, g_SName, 0); if (l_name.empty()) { dcassert(0); return; } const string& l_s = getAttrib(attribs, g_SSize, 1); if (l_s.empty()) { dcassert(0); return; } const auto l_size = Util::toInt64(l_s); const string& l_h = getAttrib(attribs, g_STTH, 2); if (l_h.empty() || (m_is_own_list == false && l_h.compare(0, 39, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 39) == 0)) { //dcassert(0); return; } const TTHValue l_tth(l_h); /// @todo verify validity? dcassert(l_tth != TTHValue()); if (m_is_updating) { // just update the current file if it is already there. for (auto i = m_cur->m_files.cbegin(); i != m_cur->m_files.cend(); ++i) { auto& file = **i; /// @todo comparisons should be case-insensitive but it takes too long - add a cache if (file.getName() == l_name || file.getTTH() == l_tth) { file.setName(l_name); file.setSize(l_size); file.setTTH(l_tth); return; } } } // [+] FlylinkDC std::shared_ptr<CFlyMediaInfo> l_mediaXY; uint32_t l_i_ts = 0; int l_i_hit = 0; string l_hit; #ifdef FLYLINKDC_USE_DIRLIST_FILE_EXT_STAT auto& l_item = DirectoryListing::g_ext_stat[Util::getFileExtWithoutDot(Text::toLower(l_name))]; l_item.m_count++; if (l_size > l_item.m_max_size) l_item.m_max_size = l_size; if (l_size < l_item.m_min_size) l_item.m_min_size = l_size; #endif if (attribs.size() >= 4) // 3 - стандартный DC++, 4 - GreyLinkDC++ { if (attribs.size() == 4 || attribs.size() >= 11) // Хитрый расширенный формат от http://p2p.toom.su/fs/hms/FCYECUWQ7F5A2FABW32UTMCT6MEMI3GPXBZDQCQ/) { const string l_sharedGL = getAttrib(attribs, g_SShared, 4); if (!l_sharedGL.empty()) { const int64_t tmp_ts = _atoi64(l_sharedGL.c_str()) - 116444736000000000L ; if (tmp_ts <= 0L) l_i_ts = 0; else l_i_ts = uint32_t(tmp_ts / 10000000L); } } string l_ts; if (l_i_ts == 0) { l_ts = getAttrib(attribs, g_STS, 3); // TODO проверить attribs.size() >= 4 если = 4 или 3 то TS нет и можно не искать } if (!m_is_first_check_mediainfo_list) { m_is_first_check_mediainfo_list = true; m_is_mediainfo_list = !l_ts.empty(); } if (!l_ts.empty() // Extended tags - exists only FlylinkDC++ or StrongDC++ sqlite or clones || l_i_ts // Грейлинк - время расшаривания ) { if (!l_ts.empty()) { l_i_ts = atoi(l_ts.c_str()); } if (attribs.size() > 4) // TODO - собрать комбинации всех случаев { l_hit = getAttrib(attribs, g_SHit, 3); const std::string& l_audio = getAttrib(attribs, g_SMAudio, 3); const std::string& l_video = getAttrib(attribs, g_SMVideo, 3); if (!l_audio.empty() || !l_video.empty()) { const string& l_br = getAttrib(attribs, g_SBR, 4); l_mediaXY = std::make_shared<CFlyMediaInfo>(getAttrib(attribs, g_SWH, 3), atoi(l_br.c_str()), l_audio, l_video ); } } #if 0 if (attribs.size() > 4) // TODO - собрать комбинации всех случаев { CFlyMediainfoRAW l_media_item; { l_media_item.m_audio = getAttrib(attribs, g_SMAudio, 3); const size_t l_pos = l_media_item.m_audio.find('|', 0); if (l_pos != string::npos && l_pos) { if (l_pos + 2 < l_media_item.m_audio.length()) { l_media_item.m_audio = l_media_item.m_audio.substr(l_pos + 2); } } } l_media_item.m_video = getAttrib(attribs, g_SMVideo, 3); l_hit = getAttrib(attribs, g_SHit, 3); l_media_item.m_WH = getAttrib(attribs, g_SWH, 3); if (!l_media_item.m_audio.empty() || !l_media_item.m_video.empty()) { l_media_item.m_br = getAttrib(attribs, g_SBR, 4); auto& l_find_mi = g_cache_mediainfo[l_media_item]; if (!l_find_mi) { l_find_mi = std::make_shared<CFlyMediaInfo>(l_media_item.m_WH, atoi(l_media_item.m_br.c_str()), l_media_item.m_audio, l_media_item.m_video ); l_mediaXY = l_find_mi; } } } #endif } l_i_hit = l_hit.empty() ? 0 : atoi(l_hit.c_str()); } auto f = new DirectoryListing::File(m_cur, l_name, l_size, l_tth, l_i_hit, l_i_ts, l_mediaXY); m_cur->m_virus_detect.add(l_name, l_size); m_cur->m_files.push_back(f); if (l_size) { if (m_is_own_list)//[+] FlylinkDC++ { f->setFlag(DirectoryListing::FLAG_SHARED_OWN); // TODO - убить FLAG_SHARED_OWN } else { if (ShareManager::isTTHShared(f->getTTH())) { f->setFlag(DirectoryListing::FLAG_SHARED); } else { if (QueueManager::is_queue_tth(f->getTTH())) { f->setFlag(DirectoryListing::FLAG_QUEUE); } // TODO if(l_size >= 100 * 1024 *1024) { if (!CFlyServerConfig::isParasitFile(f->getName())) // TODO - опимизнуть по расширениям { f->setFlag(DirectoryListing::FLAG_NOT_SHARED); const auto l_status_file = CFlylinkDBManager::getInstance()->get_status_file(f->getTTH()); // TODO - унести в отдельную нитку? if (l_status_file & CFlylinkDBManager::PREVIOUSLY_DOWNLOADED) f->setFlag(DirectoryListing::FLAG_DOWNLOAD); if (l_status_file & CFlylinkDBManager::VIRUS_FILE_KNOWN) f->setFlag(DirectoryListing::FLAG_VIRUS_FILE); if (l_status_file & CFlylinkDBManager::PREVIOUSLY_BEEN_IN_SHARE) f->setFlag(DirectoryListing::FLAG_OLD_TTH); } } } }//[+] FlylinkDC++ } } else if (name == g_SDirectory) { string l_file_name = getAttrib(attribs, g_SName, 0); if (l_file_name.empty()) { // throw SimpleXMLException("Directory missing name attribute"); l_file_name = "empty_file_name_" + Util::toString(++m_empty_file_name_counter); } const bool incomp = getAttrib(attribs, sIncomplete, 1) == "1"; DirectoryListing::Directory* d = nullptr; if (m_is_updating) { for (auto i = m_cur->directories.cbegin(); i != m_cur->directories.cend(); ++i) { /// @todo comparisons should be case-insensitive but it takes too long - add a cache if ((*i)->getName() == l_file_name) { d = *i; if (!d->getComplete()) { d->setComplete(!incomp); } break; } } } if (d == nullptr) { d = new DirectoryListing::Directory(m_list, m_cur, l_file_name, false, !incomp, isMediainfoList()); m_cur->directories.push_back(d); } m_cur = d; if (simple) { // To handle <Directory Name="..." /> endTag(name, Util::emptyString); } } } else if (name == sFileListing) { const string& b = getAttrib(attribs, sBase, 2); if (b.size() >= 1 && b[0] == '/' && b[b.size() - 1] == '/') { m_base = b; } if (m_base.size() > 1) // [+]PPA fix for [4](("Version", "1"),("CID", "EDI7OWB6TZWH6X6L2D3INC6ORQSG6RQDJ6AJ5QY"),("Base", "/"),("Generator", "DC++ 0.785")) { const StringTokenizer<string> sl(m_base.substr(1), '/'); for (auto i = sl.getTokens().cbegin(); i != sl.getTokens().cend(); ++i) { DirectoryListing::Directory* d = nullptr; for (auto j = m_cur->directories.cbegin(); j != m_cur->directories.cend(); ++j) { if ((*j)->getName() == *i) { d = *j; break; } } if (d == nullptr) { d = new DirectoryListing::Directory(m_list, m_cur, *i, false, false, isMediainfoList()); m_cur->directories.push_back(d); } m_cur = d; } } m_cur->setComplete(true); // [+] IRainman Delayed loading (dclst support) const string& l_cidStr = getAttrib(attribs, sCID, 2); if (l_cidStr.size() == 39) { const CID l_CID(l_cidStr); if (!l_CID.isZero()) { if (!m_user) { m_user = ClientManager::createUser(l_CID, "", 0); m_list->setHintedUser(HintedUser(m_user, Util::emptyString)); } } } const string& l_getIncludeSelf = getAttrib(attribs, sIncludeSelf, 2); m_list->setIncludeSelf(l_getIncludeSelf == "1"); // [~] IRainman Delayed loading (dclst support) m_is_in_listing = true; if (simple) { // To handle <Directory Name="..." /> endTag(name, Util::emptyString); } } }