예제 #1
0
    /**
     * <code>receivedPacket</code> of PacketListener handler, this filters for jabber:iq:auth
     * extensions, then broadcasts those events on a special RosterListener interface.
     *
     * @param p incoming <code>PacketEvent</code>
     */
    public void receivedPacket(PacketEvent p) {
      if (!(p.getPacket() instanceof InfoQuery)) return;
      Enumeration e = ((InfoQuery) p.getPacket()).Extensions();
      Extension ext;
      if ((e == null) || (!e.hasMoreElements())) return;

      ext = (Extension) e.nextElement();

      if (!(ext instanceof Roster)) return;

      // TODO: add code to modify current roster image based on
      // new data. Replacement is basically shown by if the type is not
      // 'result' of the IQ
      Roster rext = (Roster) ext;

      if (((InfoQuery) p.getPacket()).getType().equals("result")) {
        // the results of a get will be the results of a full fetch
        Enumeration enumx = rext.items();
        currentRoster.clear();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }
        fireUserRosterReplaced(rext);
      } else {
        Enumeration enumx = rext.items();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }

        fireUserRosterChanged(rext);
      }
    }
예제 #2
0
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
        throws Exception {
      for (Entry<PacketListener, List<Method>> listener : OUT.entrySet()) {
        for (Method method : listener.getValue()) {

          PacketHandler ann = method.getAnnotation(PacketHandler.class);
          if (!ann.packet().getName().equals(msg.getClass().getSimpleName())) continue;
          PacketEvent evt = new PacketEvent(player, msg);
          method.setAccessible(true);
          method.invoke(listener.getKey(), evt);
          msg = evt.getPacket();
        }
      }

      if (msg != null) {
        super.write(ctx, msg, promise);
      }
    }
예제 #3
0
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
      final Channel channel = ctx.channel();
      handleLoginStart(channel, msg);

      for (Entry<PacketListener, List<Method>> listener : IN.entrySet()) {
        for (Method method : listener.getValue()) {
          PacketHandler ann = method.getAnnotation(PacketHandler.class);
          if (!ann.packet().getName().equals(msg.getClass().getSimpleName())) continue;

          PacketEvent evt = new PacketEvent(player, msg);
          method.setAccessible(true);
          method.invoke(listener.getKey(), evt);
          method.setAccessible(false);
          msg = evt.getPacket();
        }
      }
      if (msg != null) {
        super.channelRead(ctx, msg);
      }
    }
예제 #4
0
  @Override
  public void onPacketSending(PacketEvent event) {

    if (!event.isCancelled() && event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {

      PacketContainer packet = event.getPacket();
      StructureModifier<String> text = packet.getSpecificModifier(String.class);

      try {
        String tag = text.read(0);
        Player observer = event.getPlayer();
        Entity watched = packet.getEntityModifier(observer.getWorld()).read(0);

        if (watched instanceof Player) {
          ReceiveNameTagEvent nameTagEvent =
              new ReceiveNameTagEvent(event.getPlayer(), (Player) watched, tag);
          pluginManager.callEvent(nameTagEvent);

          if (nameTagEvent.isModified()) {
            // Trim excess
            tag = nameTagEvent.getTrimmedTag();

            // Uh, ok.
            if (tag == null) tag = "";
            text.write(0, tag);
          }

        } else {
          // Might as well notify about this
          logger.log(
              Level.WARNING,
              "Cannot find entity id " + packet.getSpecificModifier(int.class).read(0));
        }

      } catch (FieldAccessException e) {
        logger.log(Level.SEVERE, "Cannot read field.", e);
      }
    }
  }
예제 #5
0
  // ------------------------------------------------------------------------
  // *****---Packet Recieved event handler---******//
  // this function will be called by the thread running the packetReciever
  // everytime a new packet is recieved
  // make sure it is synchronized if it modifies any of your data
  public synchronized void PacketReceived(PacketEvent e) {
    // this function defines what you do when a new packet is heard by the system (recall that the
    // parent class (PacketAnalyzer) already registered you to listen for new packets automatically)
    // if this is a long function, you should call it in a seperate thread to allow the
    // PacketReciever thread to continue recieving packets

    Packet packet = e.GetPacket();
    Vector node_list = packet.CreateRoutePathArray();
    for (int i = 0; i < node_list.size() - 1; i++) {
      Integer currentNodeNumber = (Integer) node_list.elementAt(i);
      NodeInfo currentNodeInfo;
      if ((currentNodeInfo = (NodeInfo) proprietaryNodeInfo.get(currentNodeNumber)) != null) {
        currentNodeInfo.SetValue(packet.getValue());
      }
    }
  }
 /**
  * called immediately after any packet is successfully sent. This is implemented here as a default
  * do-nothing function.
  *
  * @param p PacketEvent that has just been sent
  */
 public void sentPacket(PacketEvent p) {
   sentPacket(p.getPacket());
 }
 /**
  * called when a packet is received and has been processed into a packet. This is just a
  * do-nothing implementation
  *
  * @param p PacketEvent that has just been received.
  */
 public void receivedPacket(PacketEvent p) {
   receivedPacket(p.getPacket());
 }