Package org.xmpp.packet

Examples of org.xmpp.packet.Presence


          if(result != null)
            manager.sendPacket(this,result);
        }
      }
    } else if(packet instanceof Presence) {
      Presence presence = (Presence)packet;
      if(presence.getTo().equals(componentJID)) {
        Kernel.debug(this,"Presence packet to: " + packet.getTo().toString() + " .. type: " + presence.getType(),3);
        if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
          Presence reply = new Presence();
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
        } else if(presence.getType() == Presence.Type.subscribe) {
          Presence reply = new Presence(Presence.Type.subscribed);
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
        }
      } else {
        if(presence.getType() == Presence.Type.subscribe) {
          Presence reply = new Presence(Presence.Type.subscribed);
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
          //addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
        } else if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
          //Kernel.debug(this,"Available presence packet to: " + presence.getTo().toString(),2);
          Presence reply = new Presence();
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
          //addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
        }
      }
    }
View Full Code Here


              else {
                if(registration == null)
                  db.sendInsert(null,"goim_component_registrations","subdomain,jid,username,password",getSubdomain(),iq.getFrom().toBareJID(),username,"");
                else
                  db.sendUpdate(null,"goim_component_registrations","username=?,password=?",new Object[]{username,""},"id=?",registration.get("id"));
                Presence presence = new Presence(Presence.Type.subscribe);
                presence.setTo(iq.getFrom());
                presence.setFrom(componentJID);
                manager.sendPacket(this,presence);
              }
            }
          } else
            result = null;
          if(result != null)
            manager.sendPacket(this,result);
        }
      }
    } else if(packet instanceof Presence) {
      Presence presence = (Presence)packet;
      if(presence.getTo().equals(componentJID)) {
        Kernel.debug(this,"Presence packet to: " + packet.getTo().toString() + " .. type: " + presence.getType(),3);
        if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
          Presence reply = new Presence();
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
        } else if(presence.getType() == Presence.Type.subscribe) {
          Presence reply = new Presence(Presence.Type.subscribed);
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
        }
      } else {
        if(presence.getType() == Presence.Type.subscribe) {
          Presence reply = new Presence(Presence.Type.subscribed);
          reply.setTo(presence.getFrom());
          reply.setFrom(presence.getTo());
          manager.sendPacket(this,reply);
          addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
        } else if(presence.getType() == null || presence.getType() == Presence.Type.probe) { // available
          // Kernel.debug(this,"Available presence packet to: " +
          // presence.getTo().toString(),2);
          if(presence.getType() == Presence.Type.probe) {
            Presence reply = new Presence(Presence.Type.unavailable);
            reply.setTo(presence.getFrom());
            reply.setFrom(presence.getTo());
            manager.sendPacket(this,reply);
          }
          addSubscription(presence.getFrom().toBareJID(),presence.getTo().getNode());
        }
      }
    } else if(packet instanceof Message) {
      Message message = (Message)packet;
      if(message.getBody().startsWith("show")) {
        Message reply = new Message();
        reply.setTo(message.getFrom());
        reply.setFrom(message.getTo());
        reply.setType(message.getType());
        reply.setThread(message.getThread());
        StringBuffer subs = new StringBuffer("Your Subscriptions:\n");
        for(String lfsusername : subscriptions.keySet()) {
          List<String> jids = subscriptions.get(lfsusername.toLowerCase());
          if(jids == null) continue;
          if(jids.contains(message.getFrom().toBareJID()))
            subs.append("- ").append(lfsusername).append("\n");
        }
        reply.setBody(subs.toString());
        manager.sendPacket(this,reply);
      }
    } else
      Kernel.debug(this,"Received packet: " + packet.getClass().toString() + " " + packet.toXML(),2);
  }
View Full Code Here

    Kernel.debug(this, "debug()", 3);
  }

  public void sendPresence(JID from, String jid, String lfsusername,
      LFSHost host) {
    Presence presence = new Presence();
    presence.setFrom(from);
    presence.setTo(new JID(jid));
    presence.setShow(Presence.Show.away);
    String servername = host.name.replaceAll("\\^\\d", "");
    presence.setStatus("Playing on server " + servername + " with "
        + host.nrofracers + " other racers. (Servername with colors: "
        + host.name + ")");
    Element x = presence.addChildElement("x",
        "http://goim.sphene.net/gameStatus");
    x.addAttribute("game", "lfss2");
    x.addAttribute("target", "127.0.0.1:100"); // We need to add a dummy
                          // target.
    x.addAttribute("servername", host.name);
View Full Code Here

    List<String> jids = subscriptions.get(lfsusername.toLowerCase());
    if (jids == null)
      return;
    JID from = new JID(lfsusername, componentJID.getDomain(), null);
    for (String jid : jids) {
      Presence presence = new Presence(Presence.Type.unavailable);
      presence.setFrom(from);
      presence.setTo(new JID(jid));
      manager.sendPacket(this, presence);
    }
  }
View Full Code Here

        return SessionManager.getInstance().isAnonymousRoute(getAddress());
    }

    public boolean isInitialized() {
        if (initialized == -1) {
            Presence presence = getPresence();
            if (presence != null && presence.isAvailable()) {
                // Optimization to avoid making a remote call
                initialized = 1;
            }
            else {
                ClusterTask task = getRemoteSessionTask(RemoteSessionTask.Operation.isInitialized);
View Full Code Here

        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
            super.readExternal(in);
            Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
            presence = new Presence(packetElement, true);
        }
View Full Code Here

        if (itemToRemove != null) {
            RosterItem.SubType subType = itemToRemove.getSubStatus();

            // Cancel any existing presence subscription between the user and the contact
            if (subType == RosterItem.SUB_TO || subType == RosterItem.SUB_BOTH) {
                Presence presence = new Presence();
                presence.setFrom(server.createJID(username, null));
                presence.setTo(itemToRemove.getJid());
                presence.setType(Presence.Type.unsubscribe);
                server.getPacketRouter().route(presence);
            }

            // cancel any existing presence subscription between the contact and the user
            if (subType == RosterItem.SUB_FROM || subType == RosterItem.SUB_BOTH) {
                Presence presence = new Presence();
                presence.setFrom(server.createJID(username, null));
                presence.setTo(itemToRemove.getJid());
                presence.setType(Presence.Type.unsubscribed);
                server.getPacketRouter().route(presence);
            }

            // If removing the user was successful, remove the user from the subscriber list:
            RosterItem item = rosterItems.remove(user.toBareJID());

            if (item != null) {
                // Delete the item from the provider if the item is persistent. RosteItems that only
                // belong to shared groups won't be persistent
                if (item.getID() > 0) {
                    // If removing the user was successful, remove the user from the backend store
                    rosterItemProvider.deleteItem(username, item.getID());
                }

                // Broadcast the update to the user
                org.xmpp.packet.Roster roster = new org.xmpp.packet.Roster();
                roster.setType(IQ.Type.set);
                roster.addItem(user, org.xmpp.packet.Roster.Subscription.remove);
                broadcast(roster);
                // Fire event indicating that a roster item has been deleted
                RosterEventDispatcher.contactDeleted(this, item);
            }

            return item;
        }
        else {
            // Verify if the item being removed is an implicit roster item
            // that only exists due to some shared group
            RosterItem item = getImplicitRosterItem(user);
            if (item != null) {
                implicitFrom.remove(user.toBareJID());
                // If the contact being removed is not a local user then ACK unsubscription
                if (!server.isLocal(user)) {
                    Presence presence = new Presence();
                    presence.setFrom(server.createJID(username, null));
                    presence.setTo(user);
                    presence.setType(Presence.Type.unsubscribed);
                    server.getPacketRouter().route(presence);
                }
                // Fire event indicating that a roster item has been deleted
                RosterEventDispatcher.contactDeleted(this, item);
            }
View Full Code Here

                reply.setChildElement(((IQ) packet).getChildElement().createCopy());
                reply.setError(PacketError.Condition.remote_server_not_found);
                routingTable.routePacket(reply.getTo(), reply, true);
            }
            else if (packet instanceof Presence) {
                Presence reply = new Presence();
                reply.setID(packet.getID());
                reply.setTo(packet.getFrom());
                reply.setFrom(packet.getTo());
                reply.setError(PacketError.Condition.remote_server_not_found);
                routingTable.routePacket(reply.getTo(), reply, true);
            }
            else if (packet instanceof Message) {
                Message reply = new Message();
                reply.setID(packet.getID());
                reply.setTo(packet.getFrom());
                reply.setFrom(packet.getTo());
                reply.setType(((Message)packet).getType());
                reply.setThread(((Message)packet).getThread());
                reply.setError(PacketError.Condition.remote_server_not_found);
                routingTable.routePacket(reply.getTo(), reply, true);
            }
        }
        catch (Exception e) {
            Log.warn("Error returning error to sender. Original packet: " + packet, e);
        }
View Full Code Here

        return answer;
    }

    public void run() {
        try {
            Presence presence = getRoom().updateOccupant(this);
            if (presence != null) {
                answer = presence.getElement();
            }
        } catch (NotAllowedException e) {
            // Do nothing. A null return value means that the operation failed
        }
    }
View Full Code Here

    @Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        super.readExternal(in);
        Element packetElement = (Element) ExternalizableUtil.getInstance().readSerializable(in);
        presence = new Presence(packetElement, true);
    }
View Full Code Here

TOP

Related Classes of org.xmpp.packet.Presence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.