示例#1
0
void SearchUserReplyPacket::parseBody( )
{
	if( bodyLength == 0 || decryptedBuf[0] == NULL_FIELD && decryptedBuf[1] == TQQ_SEARCH_ALL) {
		finished = true;
		return;
	}
	finished = false;
	int offset=0;
	users.clear();
	offset += 4;// 4 unknown bytes, 00 01 00 00
	if(  decryptedBuf[offset] == TQQ_SEARCH_ALL && decryptedBuf[offset + 1] == DIVIDER) {
		offset += 2;
	}else{
		OnlineUser user;
		offset += user.readData(decryptedBuf + offset);
		users.push_back(user);
		// still some useless bytes left, don't care about
               return;
	}
	while(offset<bodyLength) {
		OnlineUser onlineUser;
		offset+=onlineUser.readData(decryptedBuf + offset);
		users.push_back(onlineUser);
	}
}
示例#2
0
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;
}
示例#3
0
void ClientManager::privateMessage(const User::Ptr& p, const string& msg) {
	Lock l(cs);
	OnlineIter i = onlineUsers.find(p->getCID());
	if(i != onlineUsers.end()) {
		OnlineUser* u = i->second;
		u->getClient().privateMessage(*u, msg);
	}
}
示例#4
0
void ClientManager::connect(const User::Ptr& p) {
	Lock l(cs);
	OnlineIter i = onlineUsers.find(p->getCID());
	if(i != onlineUsers.end()) {
		OnlineUser* u = i->second;
		u->getClient().connect(*u);
	}
}
示例#5
0
void ClientManager::privateMessage(const HintedUser& user, const string& msg, bool thirdPerson) {
	Lock l(cs);
	OnlineUser* u = findOnlineUser(user);

	if(u && !PluginManager::getInstance()->runHook(HOOK_CHAT_PM_OUT, u, msg)) {
		u->getClient().privateMessage(*u, msg, thirdPerson);
	}
}
示例#6
0
void ClientManager::connect(const HintedUser& user, const string& token, ConnectionType type) {
	Lock l(cs);
	OnlineUser* u = findOnlineUser(user);

	if(u) {
		u->getClient().connect(*u, token, type);
	}
}
示例#7
0
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()));
	}
}
示例#8
0
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);
}
示例#9
0
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);
}
示例#10
0
OnlineUser* ClientManager::findOnlineUserHint(const CID& cid, const string& hintUrl, OnlinePairC& p) const {
	p = onlineUsers.equal_range(cid);
	if(p.first == p.second) // no user found with the given CID.
		return 0;

	if(!hintUrl.empty()) {
		for(auto i = p.first; i != p.second; ++i) {
			OnlineUser* u = i->second;
			if(u->getClient().getHubUrl() == hintUrl) {
				return u;
			}
		}
	}

	return 0;
}
示例#11
0
	void UserApi::on(ClientManagerListener::UserUpdated, const OnlineUser& aUser) noexcept {
		if (aUser.getUser()->getCID() == CID())
			return;

		maybeSend("user_updated", [&] {
			return Serializer::serializeUser(aUser);
		});
	}
示例#12
0
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;
    }
}
示例#13
0
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);
	}
}
示例#14
0
	void UserApi::on(ClientManagerListener::UserConnected, const OnlineUser& aUser, bool aWasOffline) noexcept {
		if (aUser.getUser()->getCID() == CID())
			return;

		maybeSend("user_connected", [&] {
			return json({
				{ "user", Serializer::serializeUser(aUser) },
				{ "was_offline", aWasOffline },
			});
		});
	}
示例#15
0
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);
							}
						}
					}
				}

			}
		}
	}
}
示例#16
0
// [->] 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;
}
示例#17
0
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();
}
示例#18
0
void FavoriteUser::update(const OnlineUser& info) {
	setNick(info.getIdentity().getNick());
	setUrl(info.getClient().getHubUrl());
}