Ejemplo n.º 1
0
 public byte getPacketId(Packet packet) {
   for (Map.Entry<Byte, Class<? extends Packet>> entry : packets.entrySet()) {
     if (entry.getValue() == packet.getClass()) {
       return entry.getKey();
     }
   }
   return -1;
 }
Ejemplo n.º 2
0
  protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_)
      throws IOException, InstantiationException, IllegalAccessException {
    if (p_decode_2_.readableBytes() != 0) {
      PacketBuffer var4 = new PacketBuffer(p_decode_2_);
      int var5 = var4.readVarIntFromBuffer();
      Packet var6 =
          ((EnumConnectionState)
                  p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get())
              .getPacket(this.direction, var5);

      if (var6 == null) {
        throw new IOException("Bad packet id " + var5);
      } else {
        var6.readPacketData(var4);

        if (var4.readableBytes() > 0) {
          throw new IOException(
              "Packet "
                  + ((EnumConnectionState)
                          p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get())
                      .getId()
                  + "/"
                  + var5
                  + " ("
                  + var6.getClass().getSimpleName()
                  + ") was larger than I expected, found "
                  + var4.readableBytes()
                  + " bytes extra whilst reading packet "
                  + var5);
        } else {
          p_decode_3_.add(var6);

          if (logger.isDebugEnabled()) {
            logger.debug(
                RECEIVED_PACKET_MARKER,
                " IN: [{}:{}] {}",
                new Object[] {
                  p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get(),
                  Integer.valueOf(var5),
                  var6.getClass().getName()
                });
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
 public void registerPacket(Packet par1Packet) {
   logger.warning(
       (new StringBuilder())
           .append(getClass())
           .append(" wasn't prepared to deal with a ")
           .append(par1Packet.getClass())
           .toString());
   kickPlayerFromServer("Protocol error, unexpected packet");
 }
  /**
   * Implements {@link PacketListener}. Notifies this instance that a specific {@link Packet} (which
   * this instance has already expressed interest into by returning <tt>true</tt> from {@link
   * #accept(Packet)}) has been received.
   *
   * @param packet the <tt>Packet</tt> which has been received and which this instance is given a
   *     chance to process
   */
  public void processPacket(Packet packet) {
    /*
     * As we do elsewhere, acknowledge the receipt of the Packet first and
     * then go about our business with it.
     */
    IQ iq = (IQ) packet;

    if (iq.getType() == IQ.Type.SET)
      protocolProvider.getConnection().sendPacket(IQ.createResultIQ(iq));

    /*
     * Now that the acknowledging is out of the way, do go about our
     * business with the Packet.
     */
    ColibriConferenceIQ conferenceIQ = (ColibriConferenceIQ) iq;
    boolean interrupted = false;

    try {
      processColibriConferenceIQ(conferenceIQ);
    } catch (Throwable t) {
      logger.error(
          "An error occurred during the processing of a " + packet.getClass().getName() + " packet",
          t);

      if (t instanceof InterruptedException) {
        /*
         * We cleared the interrupted state of the current Thread by
         * catching the InterruptedException. However, we do not really
         * care whether the current Thread has been interrupted - we
         * caught the InterruptedException because we want to swallow
         * any Throwable. Consequently, we should better restore the
         * interrupted state.
         */
        interrupted = true;
      } else if (t instanceof ThreadDeath) throw (ThreadDeath) t;
    }
    if (interrupted) Thread.currentThread().interrupt();
  }
Ejemplo n.º 5
0
 public static void encapsulatePacket(ByteBuf buffer, Packet packet) throws IOException {
   Class<? extends Packet> clazz = packet.getClass();
   Packet.encodePrimitive(buffer, clazz.getName());
   packet.writePacket(buffer);
 }
Ejemplo n.º 6
0
 public void registerPacket(Packet par1Packet) {
   logger.warning(this.getClass() + " wasn\'t prepared to deal with a " + par1Packet.getClass());
   this.kickPlayer("Protocol error, unexpected packet");
 }