Exemplo n.º 1
0
void UserConnection::handlePM(const AdcCommand& c, bool echo) noexcept{
	const string& message = c.getParam(0);
	OnlineUserPtr peer = nullptr;
	OnlineUserPtr me = nullptr;

	auto cm = ClientManager::getInstance();
	{
		RLock l(cm->getCS());
		peer = cm->findOnlineUser(user->getCID(), getHubUrl());
		//try to use the same hub so nicks match to a hub, not the perfect solution for CCPM, nicks keep changing when hubs go offline.
		if(peer && peer->getHubUrl() != hubUrl) 
			setHubUrl(peer->getHubUrl());
		me = cm->findOnlineUser(cm->getMe()->getCID(), getHubUrl());
	}

	if (!me || !peer){ //ChatMessage cant be formatted without the OnlineUser!
		disconnect(true);
		return;
	}

	if (echo) {
		std::swap(peer, me);
	}

	string tmp;

	auto msg = make_shared<ChatMessage>(message, peer, me, peer);
	if (c.getParam("TS", 1, tmp)) {
		msg->setTime(Util::toInt64(tmp));
	}

	msg->setThirdPerson(c.hasFlag("ME", 1));
	fire(UserConnectionListener::PrivateMessage(), this, msg);
}
Exemplo n.º 2
0
	std::string OnlineUserUtils::getStringInfo(const OnlineUserPtr& aUser, int aPropertyName) noexcept {
		switch (aPropertyName) {
		case HubInfo::PROP_NICK: return aUser->getIdentity().getNick();
		case HubInfo::PROP_DESCRIPTION: return aUser->getIdentity().getDescription();
		case HubInfo::PROP_EMAIL: return aUser->getIdentity().getEmail();
		case HubInfo::PROP_TAG: return aUser->getIdentity().getTag();
		case HubInfo::PROP_HUB_URL: return aUser->getHubUrl();
		case HubInfo::PROP_HUB_NAME: return aUser->getClient()->getHubName();
		case HubInfo::PROP_IP4: return aUser->getIdentity().getIp4();
		case HubInfo::PROP_IP6: return aUser->getIdentity().getIp6();
		case HubInfo::PROP_CID: return aUser->getUser()->getCID().toBase32();
		default: dcassert(0); return 0;
		}
	}