-
hiran
Hi again. This java/smack XMPP client I am building shall make use of a MUC and users connect using nicknames. While I have seen this working once upon a time, now it does not and I am confused whether there is something I changed or there was a change on the server (that I do not manage). So my question is: How should the use of nicknames work in theory? What do I use on one side to set the nickname, how does another client connected to the same MUC receive the new nickname?
-
Ge0rG
hiran: there are two ways to convey the nickname. The most common one is as the local part of the occupant JID, i.e. jdev@muc.xmpp.org/hiran
-
Ge0rG
There is also https://xmpp.org/extensions/xep-0172.html which can embed a nickname element into presence and messages
-
Ge0rG
So by default you set a nickname while joining a room, and then all the other occupants get a presence with it
-
hiran
Is there a chance to change the nickname while being connected? Is the nickname per MUC or per XMPP connection?
-
Ge0rG
hiran: the nickname is per room and can be changed
-
Ge0rG
hiran: https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#changeNickname(org.jxmpp.jid.parts.Resourcepart)
-
hiran
Ok. So what I have is (using the smack client library): resourcePart = Resourcepart.from(nickname); muc.changeNickname(resourcePart); From what you say probably I am creating the resourcePart wrongly
-
Ge0rG
hiran: no, that looks good. But you can only change the nickname after you are already joined to the room.
-
hiran
Ok, first join the muc, then change the nickname. Hmm, when changing the nickname while I am in the MUC I receive exceptions. I programmed the client to leave the muc and join in again, then setting a new nickname.
-
Zash
There's also a way to register the nickname with the room, which is independent from the one that is used. It's then reserved and others may be prevented from using it.
-
hiran
But ok, now that we looked at the setting of the nickname - how would the other side see the nickname? I this a presence event on the other side?
-
Ge0rG
hiran: why are you trying to *change* the nickname?
-
hiran
The XMPP client connects to the XMPP server on one side, then connects to a game on the other side. When the user loads a savegame the nick is changed to whatever character is in there.
-
hiran
Does that make sense?
-
Ge0rG
hiran: a little bit. You need to have a nickname already when joining.
-
Ge0rG
also which part is the MUC? Game server?
-
hiran
The MUC shall connect the users to each othere. Currently it is a peer to peer system - no dedicated server
-
Ge0rG
hiran: also nicknames must be unique in a room.
-
hiran
That is not so much a problem. If the nick is not unique I get an error message, and users can rename themselves if need be
-
Zash
> also nicknames must be unique in a room. per user, or per connected client, depending on the server
-
hiran
Ok. I will check if the nicknames are set properly. How does another client get aware of the changed nick?
-
Zash
They should get a signal
-
Ge0rG
hiran: there is a join presence for each change and each new member, see https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#addParticipantListener(org.jivesoftware.smack.PresenceListener) and https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#addParticipantStatusListener(org.jivesoftware.smackx.muc.ParticipantStatusListener)
-
hiran
What signal? I guess it should be a presence stanza
-
hiran
ParticipantListener? That might be something. So far I tried PresenceListener and PresenceEventListeners, but not yet Participants...
-
Ge0rG
hiran: the ParticipantStatusListener will pre-process the presence for you
-
Ge0rG
hiran: so you can add your business logic right into it
-
hiran
Even better
-
hiran
I will try those listeners :-)