void TextFrame::on(SettingsManagerListener::Repaint) { dcassert(!ClientManager::isShutdown()); if (!ClientManager::isShutdown()) { RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); } }
Client::~Client() throw() { dcassert(!sock); // In case we were deleted before we Failed FavoriteManager::getInstance()->removeUserCommand(getHubUrl()); TimerManager::getInstance()->removeListener(this); updateCounts(true); }
UserManager::UserManager() { dcassert(!g_ignoreListLoaded); CFlylinkDBManager::getInstance()->load_ignore(g_ignoreList); dcdrun(g_ignoreListLoaded = true); SettingsManager::getInstance()->addListener(this); }
void UserConnection::connect(const string& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole) { dcassert(!socket); port = aPort; socket = BufferedSocket::getSocket(0); socket->addListener(this); socket->connect(aServer, aPort, localPort, natRole, secure, SETTING(ALLOW_UNTRUSTED_CLIENTS), true); }
void ConnectionManager::putUploadConnection(UserConnection* aSource) { { Lock l(cs); dcassert(find(active.begin(), active.end(), aSource->getCQI()) != active.end()); active.erase(find(active.begin(), active.end(), aSource->getCQI())); } putConnection(aSource); }
/** * Nick received. If it's a downloader, fine, otherwise it must be an uploader. */ void ConnectionManager::on(UserConnectionListener::MyNick, UserConnection* aSource, const string& aNick) throw() { if(aSource->getState() != UserConnection::STATE_NICK) { // Already got this once, ignore... dcdebug("CM::onMyNick %p sent nick twice\n", aSource); return; } dcassert(aNick.size() > 0); dcdebug("ConnectionManager::onMyNick %p, %s\n", aSource, aNick.c_str()); dcassert(!aSource->getUser()); // First, we try looking in the pending downloads...hopefully it's one of them... { Lock l(cs); for(ConnectionQueueItem::Iter i = pendingDown.begin(); i != pendingDown.end(); ++i) { ConnectionQueueItem* cqi = *i; if(cqi->getUser()->getNick() == aNick) { aSource->setUser(cqi->getUser()); // Indicate that we're interested in this file... aSource->setFlag(UserConnection::FLAG_DOWNLOAD); } } } if(!aSource->getUser()) { // Make sure we know who it is, i e that he/she is connected... if(!ClientManager::getInstance()->isOnline(aNick)) { dcdebug("CM::onMyNick Incoming connection from unknown user %s\n", aNick.c_str()); putConnection(aSource); return; } aSource->setUser(ClientManager::getInstance()->getUser(aNick)); // We don't need this connection for downloading...make it an upload connection instead... aSource->setFlag(UserConnection::FLAG_UPLOAD); } if( aSource->isSet(UserConnection::FLAG_INCOMING) ) { aSource->myNick(aSource->getUser()->getClientNick()); aSource->lock(CryptoManager::getInstance()->getLock(), CryptoManager::getInstance()->getPk()); } aSource->setState(UserConnection::STATE_LOCK); }
Client::~Client() { dcassert(!m_client_sock); if (m_client_sock) { LogManager::getInstance()->message("[Error] Client::~Client() sock == nullptr"); } FavoriteManager::getInstance()->removeUserCommand(getHubUrl()); dcassert(FavoriteManager::getInstance()->countUserCommand(getHubUrl()) == 0); // In case we were deleted before we Failed // [-] TimerManager::getInstance()->removeListener(this); [-] IRainman fix: please see shutdown(). updateCounts(true); //[+]FlylinkDC // [-] IRainman. //if (m_hEventClientInitialized) // CloseHandle(m_hEventClientInitialized); //[~]FlylinkDC }
double ShareUtils::getNumericInfo(const ShareDirectoryInfoPtr& aItem, int aPropertyName) noexcept { switch (aPropertyName) { case ShareRootApi::PROP_SIZE: return (double)aItem->size; case ShareRootApi::PROP_INCOMING: return (double)aItem->incoming; case ShareRootApi::PROP_LAST_REFRESH_TIME: return (double)aItem->lastRefreshTime; case ShareRootApi::PROP_REFRESH_STATE: return (double)aItem->refreshState; default: dcassert(0); return 0; } }
void Client::send(const char* aMessage, size_t aLen) { if (!isConnected() || !sock) { dcassert(0); return; } updateActivity(); sock->write(aMessage, aLen); COMMAND_DEBUG(aMessage, DebugManager::TYPE_HUB, DebugManager::OUTGOING, getIpPort()); }
void HttpConnection::abortRequest(bool disconnect) { dcassert(socket); socket->removeListener(this); if(disconnect) socket->disconnect(); BufferedSocket::putSocket(socket); socket = NULL; }
void UserQueue::getUserQIs(const UserPtr& aUser, QueueItemList& ql) noexcept{ /* Returns all queued items from an user */ /* Highest prio */ auto i = userPrioQueue.find(aUser); if(i != userPrioQueue.end()) { dcassert(!i->second.empty()); copy_if(i->second.begin(), i->second.end(), back_inserter(ql), [](const QueueItemPtr& q) { return !q->getBundle(); }); //bundle items will be added from the bundle queue } /* Bundles */ auto s = userBundleQueue.find(aUser); if(s != userBundleQueue.end()) { dcassert(!s->second.empty()); for(auto& b: s->second) b->getItems(aUser, ql); } }
void Client::send(const char* aMessage, size_t aLen) { if(!isReady()) { dcassert(0); return; } updateActivity(); sock->write(aMessage, aLen); COMMAND_DEBUG(aMessage, DebugManager::HUB_OUT, getIpPort()); }
std::string ShareUtils::getStringInfo(const ShareDirectoryInfoPtr& aItem, int aPropertyName) noexcept { switch (aPropertyName) { case ShareRootApi::PROP_VIRTUAL_NAME: return aItem->virtualName; case ShareRootApi::PROP_PATH: return aItem->path; case ShareRootApi::PROP_REFRESH_STATE: return formatRefreshState(aItem); case ShareRootApi::PROP_TYPE: return Format::formatFolderContent(aItem->fileCount, aItem->folderCount); default: dcassert(0); return Util::emptyString; } }
void PublicHubsFrame::updateList() { //CLockRedraw<> l_lock_draw(m_ctrlHubs); m_ctrlHubs.DeleteAllItems(); users = 0; visibleHubs = 0; double size = -1; FilterModes mode = NONE; int sel = ctrlFilterSel.GetCurSel(); bool doSizeCompare = parseFilter(mode, size); auto cnt = m_ctrlHubs.GetItemCount(); for (auto i = m_hubs.cbegin(); i != m_hubs.cend(); ++i) { if (matchFilter(*i, sel, doSizeCompare, mode, size)) { TStringList l; l.resize(COLUMN_LAST); l[COLUMN_NAME] = Text::toT(i->getName()); string l_description = i->getDescription(); boost::replace_all(l_description, ".px.", ""); l[COLUMN_DESCRIPTION] = Text::toT(l_description); l[COLUMN_USERS] = Util::toStringW(i->getUsers()); l[COLUMN_SERVER] = Text::toT(i->getServer()); l[COLUMN_COUNTRY] = Text::toT(i->getCountry()); // !SMT!-IP l[COLUMN_SHARED] = Util::formatBytesW(i->getShared()); l[COLUMN_MINSHARE] = Util::formatBytesW(i->getMinShare()); l[COLUMN_MINSLOTS] = Util::toStringW(i->getMinSlots()); l[COLUMN_MAXHUBS] = Util::toStringW(i->getMaxHubs()); l[COLUMN_MAXUSERS] = Util::toStringW(i->getMaxUsers()); l[COLUMN_RELIABILITY] = Util::toStringW(i->getReliability()); l[COLUMN_RATING] = Text::toT(i->getRating()); const auto l_country = i->getCountry(); dcassert(!l_country.empty()); const auto l_index_country = WinUtil::getFlagIndexByName(l_country.c_str()); //const auto l_index = m_ctrlHubs.insert(cnt++, l, l_index_country); // !SMT!-IP /* LVITEM lvItem = { 0 }; lvItem.mask = LVIF_IMAGE; lvItem.iItem = l_index; lvItem.iImage = isOnline(i->getServer()) ? 0 : 1; m_ctrlHubs.SetItem(&lvItem); */ visibleHubs++; users += i->getUsers(); } } m_ctrlHubs.resort(); updateStatus(); }
void QueueItem::addSource(const UserPtr& aUser) { dcassert(!isSource(aUser)); SourceIter i = getBadSource(aUser); if(i != badSources.end()) { sources.push_back(*i); badSources.erase(i); } else { sources.push_back(Source(aUser)); } }
string Serializer::getDownloadStateId(TrackableDownloadItem::State aState) noexcept { switch (aState) { case TrackableDownloadItem::STATE_DOWNLOAD_PENDING: return "download_pending"; case TrackableDownloadItem::STATE_DOWNLOADING: return "downloading"; case TrackableDownloadItem::STATE_DOWNLOADED: return "downloaded"; } dcassert(0); return Util::emptyString; }
void QueueItem::removeSource(const UserPtr& aUser, Flags::MaskType reason) { SourceIter i = getSource(aUser); dcassert(i != sources.end()); if(i == sources.end()) return; i->setFlag(reason); badSources.push_back(*i); sources.erase(i); }
double OnlineUserUtils::getNumericInfo(const OnlineUserPtr& aUser, int aPropertyName) noexcept { switch (aPropertyName) { case PROP_SHARED: return Util::toDouble(aUser->getIdentity().getShareSize()); case PROP_UPLOAD_SPEED: return (double)aUser->getIdentity().getAdcConnectionSpeed(false); case PROP_DOWNLOAD_SPEED: return (double)aUser->getIdentity().getAdcConnectionSpeed(true); case PROP_FILES: return Util::toDouble(aUser->getIdentity().getSharedFiles()); case PROP_UPLOAD_SLOTS: return aUser->getIdentity().getSlots(); default: dcassert(0); return 0; } }
void UserQueue::removeBundle(BundlePtr& aBundle, const UserPtr& aUser) noexcept { auto j = userBundleQueue.find(aUser); dcassert(j != userBundleQueue.end()); if (j == userBundleQueue.end()) { return; } auto& l = j->second; auto s = find(l.begin(), l.end(), aBundle); dcassert(s != l.end()); if (s == l.end()) { return; } l.erase(s); if(l.empty()) { userBundleQueue.erase(j); } }
void PopupManager::on(TimerManagerListener::Second /*type*/, uint64_t tick) noexcept { dcassert(WinUtil::g_mainWnd); if (ClientManager::isBeforeShutdown()) return; if (WinUtil::g_mainWnd) { ::PostMessage(WinUtil::g_mainWnd, WM_SPEAKER, MainFrame::REMOVE_POPUP, (LPARAM)tick); // [!] IRainman opt. } }
string FavoriteHubUtils::formatConnectState(const FavoriteHubEntryPtr& aEntry) noexcept { switch (aEntry->getConnectState()) { case FavoriteHubEntry::STATE_DISCONNECTED: return STRING(DISCONNECTED); case FavoriteHubEntry::STATE_CONNECTING: return STRING(CONNECTING); case FavoriteHubEntry::STATE_CONNECTED: return STRING(CONNECTED); } dcassert(0); return Util::emptyString; }
string PrivateChatInfo::formatCCPMState(PrivateChat::CCPMState aState) noexcept { switch (aState) { case PrivateChat::DISCONNECTED: return "disconnected"; case PrivateChat::CONNECTING: return "connecting"; case PrivateChat::CONNECTED: return "connected"; } dcassert(0); return Util::emptyString; }
void ClientManager::sendUDP(AdcCommand& cmd, const OnlineUser& user) { dcassert(cmd.getType() == AdcCommand::TYPE_UDP); if(!user.getIdentity().isUdpActive()) { cmd.setType(AdcCommand::TYPE_DIRECT); cmd.setTo(user.getIdentity().getSID()); const_cast<Client&>(user.getClient()).send(cmd); } else { sendUDP(user.getIdentity().getIp(), user.getIdentity().getUdpPort(), cmd.toString(getMe()->getCID())); } }
void IpBlocksLoader::startTag(const string& name, StringPairList& attribs, bool /*simple*/) { if (name == "block") { m_currentBlockId = Util::toInt(getAttrib(attribs, "id", 0)); m_currentBlockName = getAttrib(attribs, "name", 1); #ifdef _DEBUG __dcdebug("block %d:%s\n", m_currentBlockId, Text::fromUtf8(m_currentBlockName).c_str()); dcassert(m_operatorIds.insert(m_currentBlockId).second); #endif } }
void BufferedSocket::write(const char* aBuf, size_t aLen) throw() { dcassert(sock); if(!sock) return; Lock l(cs); if(writeBuf.empty()) addTask(SEND_DATA, 0); writeBuf.insert(writeBuf.end(), aBuf, aBuf+aLen); }
string SystemApi::getAwayState(AwayMode aAwayMode) noexcept { switch (aAwayMode) { case AWAY_OFF: return "off"; case AWAY_MANUAL: return "manual"; case AWAY_IDLE: return "idle"; } dcassert(0); return ""; }
void UserConnection::connect(const Socket::AddressInfo& aServer, const string& aPort, const string& localPort, BufferedSocket::NatRoles natRole) { dcassert(!socket); socket = BufferedSocket::getSocket(0); socket->addListener(this); // TODO: verify that this KeyPrint was mediated by a trusted hub? string expKP = user ? ClientManager::getInstance()->getField(user->getCID(), hubUrl, "KP") : Util::emptyString; socket->connect(aServer, aPort, localPort, natRole, secure, SETTING(ALLOW_UNTRUSTED_CLIENTS), true, expKP); }
string AdcCommand::getHeaderString(const CID& cid) const { dcassert(type == TYPE_UDP); string tmp; tmp += getType(); tmp += cmdChar; tmp += ' '; tmp += cid.toBase32(); return tmp; }
bool CAGEmotion::Create(const tstring& strEmotionText, string& strEmotionBmpPath) { m_EmotionBmp = (HBITMAP) ::LoadImage(0, Text::toT(strEmotionBmpPath).c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (m_EmotionBmp == NULL) { dcassert(FALSE); return false; } m_EmotionText = strEmotionText; m_EmotionBmpPath = strEmotionBmpPath; return true; }
void UserQueue::removeQI(QueueItemPtr& qi, const UserPtr& aUser, bool removeRunning /*true*/, bool addBad /*false*/, bool fireSources /*false*/) { if(removeRunning) { qi->removeDownloads(aUser); } dcassert(qi->isSource(aUser)); BundlePtr bundle = qi->getBundle(); if (bundle) { if (!bundle->isSource(aUser)) { return; } if (qi->getBundle()->removeUserQueue(qi, aUser, addBad)) { removeBundle(bundle, aUser); if (fireSources) { QueueManager::getInstance()->fire(QueueManagerListener::BundleSources(), bundle); } } else { dcassert(userBundleQueue.find(aUser) != userBundleQueue.end()); } } if (qi->getPriority() == QueueItem::HIGHEST) { auto j = userPrioQueue.find(aUser); dcassert(j != userPrioQueue.end()); if (j == userPrioQueue.end()) { return; } auto& l = j->second; auto i = find(l.begin(), l.end(), qi); dcassert(i != l.end()); if (i == l.end()) { return; } l.erase(i); if(l.empty()) { userPrioQueue.erase(j); } } }