jdev - 2021-11-16

  1. 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?

  2. 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

  3. Ge0rG

    There is also https://xmpp.org/extensions/xep-0172.html which can embed a nickname element into presence and messages

  4. Ge0rG

    So by default you set a nickname while joining a room, and then all the other occupants get a presence with it

  5. hiran

    Is there a chance to change the nickname while being connected? Is the nickname per MUC or per XMPP connection?

  6. Ge0rG

    hiran: the nickname is per room and can be changed

  7. Ge0rG

    hiran: https://download.igniterealtime.org/smack/docs/latest/javadoc/org/jivesoftware/smackx/muc/MultiUserChat.html#changeNickname(org.jxmpp.jid.parts.Resourcepart)

  8. 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

  9. Ge0rG

    hiran: no, that looks good. But you can only change the nickname after you are already joined to the room.

  10. 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.

  11. 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.

  12. 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?

  13. Ge0rG

    hiran: why are you trying to *change* the nickname?

  14. 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.

  15. hiran

    Does that make sense?

  16. Ge0rG

    hiran: a little bit. You need to have a nickname already when joining.

  17. Ge0rG

    also which part is the MUC? Game server?

  18. hiran

    The MUC shall connect the users to each othere. Currently it is a peer to peer system - no dedicated server

  19. Ge0rG

    hiran: also nicknames must be unique in a room.

  20. 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

  21. Zash

    > also nicknames must be unique in a room. per user, or per connected client, depending on the server

  22. hiran

    Ok. I will check if the nicknames are set properly. How does another client get aware of the changed nick?

  23. Zash

    They should get a signal

  24. 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)

  25. hiran

    What signal? I guess it should be a presence stanza

  26. hiran

    ParticipantListener? That might be something. So far I tried PresenceListener and PresenceEventListeners, but not yet Participants...

  27. Ge0rG

    hiran: the ParticipantStatusListener will pre-process the presence for you

  28. Ge0rG

    hiran: so you can add your business logic right into it

  29. hiran

    Even better

  30. hiran

    I will try those listeners :-)