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);
}
Exemple #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;
}
Exemple #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);
	}
}
Exemple #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);
	}
}
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);
	}
}
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);
	}
}
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()));
	}
}
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;
}
Exemple #9
0
void FavoriteUser::update(const OnlineUser& info) {
	setNick(info.getIdentity().getNick());
	setUrl(info.getClient().getHubUrl());
}