Trouble getting Client \ User information from Private frame

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
Pothead
Posts: 223
Joined: 2005-01-15 06:55

Trouble getting Client \ User information from Private frame

Post by Pothead » 2006-05-22 06:59

I've been trying to colour text in Priavte frame, and to get a few parameters to affect text colouring, i've got a bit stuck, trying to get MyNick, and Op status the user who is talking, but having trouble with both.

To get mynick I've tried using getFirstNick() from clientmananger, but that always seems to return the nick from settings, and not the one from favourite hubs. So as an alternative i've tried this

Code: Select all

	string hubUrl = Util::toString(ClientManager::getInstance()->getHubs(replyTo->getCID()));
	Client* aClient = ClientManager::getInstance()->getClient(hubUrl);
	string myNick = aClient->getMyNick();
Now this gets the hub url, appears to get the client object, but mynick is returned as "".

For op status, i realise getting OnLineUser object would be best, but i couldn't figure that one out, so i've been trying

Code: Select all

	bool opStatus = false;
	string speakersNick = ExtraUtil::findNickInTString(aLine);
	User::Ptr aUser = ClientManager::getInstance()->findUser(speakersNick, aClient->getHubUrl());
	if (aUser) {
		opStatus = ClientManager::getInstance()->isOp(aUser, aClient->getHubUrl());
	}
But this always fails the if (aUser) part.

Any help, advice or pointers would be welcome. :)

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2006-05-22 17:47

Do your tests reveal the same behavior on ADC and NMDC hubs? i.e. does your code work on one but not the other? To tell the truth, I can't see where the MyNick is set - it must be set along with a bunch of other variables in an Identity somewhere.

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-05-22 19:36

It works in neither NMDC or ADC hubs.
It's not really set, it's more of referenced . . .
Client.h
const string& getMyNick() const { return getMyIdentity().getNick(); }

poy
Posts: 83
Joined: 2006-04-03 15:55

Post by poy » 2006-05-23 07:02

why not just client->getNick() instead of getMyNick() ?

Quattro
Posts: 166
Joined: 2006-01-11 09:23

Post by Quattro » 2006-05-23 09:05

that would return the nick of the connected user i believe...
in this case the one of the user you're talking to
You can send a message around the world in 1/7 of a second; yet it may take several years to move a simple idea through a 1/4 inch of human skull.

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-05-23 09:13

Because getNick() isn't a member of client.

Quattro
Posts: 166
Joined: 2006-01-11 09:23

Post by Quattro » 2006-05-23 09:27

Pothead wrote:Because getNick() isn't a member of client.
ah that would a better reason, as i was not sure about what i said earlier....
You can send a message around the world in 1/7 of a second; yet it may take several years to move a simple idea through a 1/4 inch of human skull.

poy
Posts: 83
Joined: 2006-04-03 15:55

Post by poy » 2006-05-23 14:02

Quattro wrote:that would return the nick of the connected user i believe...
in this case the one of the user you're talking to
no, the class "client" manages the hub, and in older DC++ versions (my bad, didn't know it had changed...), client->getNick() was the right thing to do to get my nick.
it was set with a GETSET ; you could also do client->getMe() which type was User::Ptr, so this then gave all the information about My "profile" on the hub.

i've looked at the current client.h, and indeed, no more getNick()...
however, i still found the nice getMe(), so i would suggest this :

client->getMe()->getNick()

as there is GETSET(string, nick, Nick); in user.h, i believe this one should be ok...

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-05-23 19:50

poy wrote: client->getMe()->getNick()

as there is GETSET(string, nick, Nick); in user.h, i believe this one should be ok...
getMe() is from ClientManager and getNick() is part of OnlineUser class. getFirstNick() is a member of User, cannot get it going at moment (to test again), but when it was working a few days ago, it returned the nick from settings. Not the actual nick used (from fav hubs).

But thanks for making me look at clientmanager again,

Code: Select all

ClientManager::getInstance()->getIdentity(ClientManager::getInstance()->getMe()).getNick();
works :)

And from same function (getIdentity), eventually got isOp working properly.

Code: Select all

bool opStatus = false;
	try {
		opStatus = ClientManager::getInstance()->getIdentity(ClientManager::getInstance()->getUser(speakersNick, hubUrl)).isOp();
	} catch (...) {	}
Neither look very nice though, with the multiple usage of getInstance :roll:
Suppose i could clean up a bit by adding a few tiny functions to clientmanger.

Edit, that getMe() for mynick doesn't seem to work for multiple hubs though. Typical.

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-05-24 20:43

For anybody interested this copy, pasted and edited a little bit of dc++ code returns your correct username, from a specific url. :)

Code: Select all

string ClientManager::getMyNick(const string& aHubUrl) {
	Lock l(cs);
	pair<OnlineIter> p = onlineUsers.equal_range(getMe()->getCID());
	for(OnlineIter i = p.first; i != p.second; ++i) {
		if(i->second->getClient().getHubUrl() == aHubUrl) {
			return i->second->getIdentity().getNick();
		}
	}
	return "";
}

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2006-05-26 05:48

heh, but turns out getUser(nick, url) doesn't work for adc hubs (which i'm trying to use to get Opstatus).
Again made by just editig the above code a little bit. Would be better to provide functionality for getUser, but since i only wanted opstatus, this gets the correct one :)

Code: Select all

bool ClientManager::isOp(const string& aNick, const string& aHubUrl) {
	Lock l(cs);
	for(OnlineIter i = onlineUsers.begin(); i != onlineUsers.end(); ++i) {
		if(i->second->getIdentity().getNick() == aNick) {
			if(i->second->getClient().getHubUrl() == aHubUrl) {
				return i->second->getIdentity().isOp();
			}
		}
	}
	return false;
}

Locked