Ejemplo n.º 1
0
  /**
   * Create a new role.
   *
   * @param chatserver the server hosting the role.
   * @param chatroom the room the role is valid in.
   * @param nickname the nickname of the user in the role.
   * @param role the role of the user in the room.
   * @param affiliation the affiliation of the user in the room.
   * @param chatuser the user on the chat server.
   * @param presence the presence sent by the user to join the room.
   * @param packetRouter the packet router for sending messages from this role.
   */
  public LocalMUCRole(
      MultiUserChatService chatserver,
      LocalMUCRoom chatroom,
      String nickname,
      MUCRole.Role role,
      MUCRole.Affiliation affiliation,
      LocalMUCUser chatuser,
      Presence presence,
      PacketRouter packetRouter) {
    this.room = chatroom;
    this.nick = nickname;
    this.user = chatuser;
    this.server = chatserver;
    this.router = packetRouter;
    this.role = role;
    this.affiliation = affiliation;
    // Cache the user's session (will only work for local users)
    this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom());

    extendedInformation =
        DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user"));
    calculateExtendedInformation();
    rJID = new JID(room.getName(), server.getServiceDomain(), nick);
    setPresence(presence);
    // Check if new occupant wants to be a deaf occupant
    Element element =
        presence.getElement().element(QName.get("x", "http://jivesoftware.org/protocol/muc"));
    if (element != null) {
      voiceOnly = element.element("deaf-occupant") != null;
    }
    // Add the new role to the list of roles
    user.addRole(room.getName(), this);
  }
Ejemplo n.º 2
0
  public void send(Packet packet) {
    if (packet == null) {
      return;
    }
    packet.setTo(user.getAddress());

    if (session != null && session.getStatus() == Session.STATUS_AUTHENTICATED) {
      // Send the packet directly to the local user session
      session.process(packet);
    } else {
      router.route(packet);
    }
  }
Ejemplo n.º 3
0
 /**
  * Calculates and sets the extended presence information to add to the presence. The information
  * to add contains the user's jid, affiliation and role.
  */
 private void calculateExtendedInformation() {
   ElementUtil.setProperty(extendedInformation, "x.item:jid", user.getAddress().toString());
   ElementUtil.setProperty(extendedInformation, "x.item:affiliation", affiliation.toString());
   ElementUtil.setProperty(extendedInformation, "x.item:role", role.toString());
 }
Ejemplo n.º 4
0
 public JID getUserAddress() {
   return user.getAddress();
 }
Ejemplo n.º 5
0
 public void destroy() {
   // Notify the user that he/she is no longer in the room
   user.removeRole(room.getName());
 }