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 ClientManager::updateUser(const OnlineUser& user) noexcept { if(!user.getIdentity().getNick().empty()) { Lock l(cs); auto i = nicks.find(user.getUser()->getCID()); if(i == nicks.end()) { nicks[user.getUser()->getCID()] = std::make_pair(user.getIdentity().getNick(), false); } else { i->second.first = user.getIdentity().getNick(); } } fire(ClientManagerListener::UserUpdated(), user); }
bool UserMatch::match(OnlineUser& user) const { const auto& identity = user.getIdentity(); if(isSet(FAVS) && !FavoriteManager::getInstance()->isFavoriteUser(identity.getUser())) { return false; } if(isSet(OPS) && !identity.isOp()) { return false; } if(isSet(BOTS) && !identity.isBot()) { return false; } for(auto& i: rules) { string str; switch(i.field) { case UserMatch::Rule::NICK: str = identity.getNick(); break; case UserMatch::Rule::CID: str = identity.getUser()->getCID().toBase32(); break; case UserMatch::Rule::IP: str = identity.getIp(); break; case UserMatch::Rule::HUB_ADDRESS: str = user.getClient().getHubUrl(); break; case UserMatch::Rule::FIELD_LAST: break; } if(!i.match(str)) { return false; } } return true; }
void ConnectionManager::adcConnect(const OnlineUser& aUser, uint16_t aPort, const string& aToken, bool secure) { if(shuttingDown) return; UserConnection* uc = getConnection(false, secure); uc->setToken(aToken); uc->setState(UserConnection::STATE_CONNECT); if(aUser.getIdentity().isOp()) { uc->setFlag(UserConnection::FLAG_OP); } try { uc->connect(aUser.getIdentity().getIp(), aPort); } catch(const Exception&) { putConnection(uc); delete uc; } }
void ClientManager::userCommand(const HintedUser& user, const UserCommand& uc, ParamMap& params, bool compatibility) { Lock l(cs); OnlineUser* ou = findOnlineUserHint(user.user->getCID(), user.hint.empty() ? uc.getHub() : user.hint); if(!ou) return; ou->getIdentity().getParams(params, "user", compatibility); ou->getClient().getHubIdentity().getParams(params, "hub", false); ou->getClient().getMyIdentity().getParams(params, "my", compatibility); ou->getClient().sendUserCmd(uc, params); }
void SearchManager::respond(const AdcCommand& cmd, const OnlineUser& user) { // Filter own searches if(user.getUser() == ClientManager::getInstance()->getMe()) return; auto results = ShareManager::getInstance()->search(cmd.getParameters(), user.getIdentity().isUdpActive() ? 10 : 5); if(results.empty()) return; string token; cmd.getParam("TO", 0, token); for(auto& i: results) { AdcCommand res = i->toRES(AdcCommand::TYPE_UDP); if(!token.empty()) res.addParam("TO", token); ClientManager::getInstance()->sendUDP(res, user); } }
void CommandQueue::addCommand(const OnlineUser& ou, int actionId) { FavoriteHubEntry* hub = FavoriteManager::getInstance()->getFavoriteHubEntry(clientPtr->getHubUrl()); if(hub) { Action* a = RawManager::getInstance()->findAction(actionId); if(a != NULL) { if(FavoriteManager::getInstance()->getEnabledAction(hub, actionId)) { uint64_t delayTime = GET_TICK(); for(auto i = a->raw.begin(); i != a->raw.end(); ++i) { if(i->getEnabled() && !(i->getRaw().empty())) { if(FavoriteManager::getInstance()->getEnabledRaw(hub, actionId, i->getId())) { ParamMap params; const UserCommand uc = UserCommand(0, 0, 0, 0, "", i->getRaw(),"", ""); CommandItem item; item.name = i->getName(); item.uc = uc; item.ou = &ou; if(SETTING(USE_SEND_DELAYED_RAW)) { delayTime += (i->getTime() * 1000) + 1; addCommandDelayed(delayTime, item); } else { execCommand(item); } if(SETTING(LOG_RAW_CMD)) { ou.getIdentity().getParams(params, "user", true); clientPtr->getHubIdentity().getParams(params, "hub", false); clientPtr->getMyIdentity().getParams(params, "my", true); string formattedCmd = Util::formatParams(uc.getCommand(), params); params["rawCommand"] = formattedCmd; LOG(LogManager::RAW, params); } } } } } } } }
QString WulforUtil::getNickViaOnlineUser(const QString &cid, const QString &hintUrl) { OnlineUser* user = ClientManager::getInstance()->findOnlineUser(CID(_tq(cid)), _tq(hintUrl), true); return user ? _q(user->getIdentity().getNick()) : QString(); }
// [->] IRainman moved from User.cpp uint8_t UserInfoBase::getImage(const OnlineUser& ou) { #ifdef _DEBUG // static int g_count = 0; // dcdebug("UserInfoBase::getImage count = %d ou = %p\n", ++g_count, &ou); #endif const auto& id = ou.getIdentity(); const auto& u = ou.getUser(); uint8_t image; if (id.isOp()) { image = 0; } else if (u->isServer()) { image = 1; } else { auto speed = id.getLimit(); if (!speed) { speed = id.getDownloadSpeed(); } /* if (!speed) { // TODO: needs icon for user with no limit? } */ if (speed >= 10 * 1024 * 1024) // over 10 MB { image = 2; } else if (speed > 1024 * 1024 / 10) // over 100 KB { image = 3; } else { image = 4; //-V112 } } if (u->isAway()) { //User away... image += 5; } /* TODO const string freeSlots = identity.get("FS"); if(!freeSlots.empty() && identity.supports(AdcHub::ADCS_FEATURE) && identity.supports(AdcHub::SEGA_FEATURE) && ((identity.supports(AdcHub::TCP4_FEATURE) && identity.supports(AdcHub::UDP4_FEATURE)) || identity.supports(AdcHub::NAT0_FEATURE))) { image += 10; }*/ if (!id.isTcpActive()) { // Users we can't connect to... image += 10;// 20 } return image; }
void FavoriteUser::update(const OnlineUser& info) { setNick(info.getIdentity().getNick()); setUrl(info.getClient().getHubUrl()); }