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);
}
Beispiel #2
0
	void UserApi::on(ClientManagerListener::UserUpdated, const OnlineUser& aUser) noexcept {
		if (aUser.getUser()->getCID() == CID())
			return;

		maybeSend("user_updated", [&] {
			return Serializer::serializeUser(aUser);
		});
	}
Beispiel #3
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 },
			});
		});
	}
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);
	}
}
// [->] 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;
}