Package com.comphenix.protocol.events

Examples of com.comphenix.protocol.events.PacketEvent


   * Enqueue a packet for asynchronous processing.
   * @param syncPacket - synchronous packet event.
   * @param asyncMarker - the asynchronous marker to use.
   */
  public synchronized void enqueueSyncPacket(PacketEvent syncPacket, AsyncMarker asyncMarker) {
    PacketEvent newEvent = PacketEvent.fromSynchronous(syncPacket, asyncMarker);
   
    if (asyncMarker.isQueued() || asyncMarker.isTransmitted())
      throw new IllegalArgumentException("Cannot queue a packet that has already been queued.");
   
    asyncMarker.setQueuedSendingIndex(asyncMarker.getNewSendingIndex());
View Full Code Here


   
    AsyncMarker marker = packetUpdated.getAsyncMarker();
   
    // Should we reorder the event?
    if (marker.getQueuedSendingIndex() != marker.getNewSendingIndex() && !marker.hasExpired()) {
      PacketEvent copy = PacketEvent.fromSynchronous(packetUpdated, marker);
     
      // "Cancel" the original event
      packetUpdated.setReadOnly(false);
      packetUpdated.setCancelled(true);
     
View Full Code Here

  public synchronized void signalPacketUpdate(List<PacketType> packetsRemoved, boolean onMainThread) {
    Set<PacketType> lookup = new HashSet<PacketType>(packetsRemoved);
   
    // Note that this is O(n), so it might be expensive
    for (PacketEventHolder holder : sendingQueue) {
      PacketEvent event = holder.getEvent();
     
      if (lookup.contains(event.getPacketType())) {
        event.getAsyncMarker().setProcessed(true);
      }
    }
   
    // This is likely to have changed the situation a bit
    trySendPackets(onMainThread);
View Full Code Here

   * @param onMainThread - TRUE if we're on the main thread, FALSE otherwise.
   * @param holder - packet container.
   * @return TRUE to continue sending packets, FALSE otherwise.
   */
  private boolean processPacketHolder(boolean onMainThread, final PacketEventHolder holder) {
    PacketEvent current = holder.getEvent();
    AsyncMarker marker = current.getAsyncMarker();
    boolean hasExpired = marker.hasExpired();
   
    // Guard in cause the queue is closed
    if (cleanedUp) {
      return true;
    }
       
    // End condition?
    if (marker.isProcessed() || hasExpired) {
      if (hasExpired) {
        // Notify timeout listeners
        onPacketTimeout(current);
       
        // Recompute
        marker = current.getAsyncMarker();
        hasExpired = marker.hasExpired();
       
        // Could happen due to the timeout listeners
        if (!marker.isProcessed() && !hasExpired) {
          return false;
        }
      }
     
      // Is it okay to send the packet?
      if (!current.isCancelled() && !hasExpired) {
        // Make sure we're on the main thread
        if (notThreadSafe) {
          try {
            boolean wantAsync = marker.isMinecraftAsync(current);
            boolean wantSync = !wantAsync;
           
            // Wait for the next main thread heartbeat if we haven't fulfilled our promise
            if (!onMainThread && wantSync) {
              return false;
            }
           
            // Let's give it what it wants
            if (onMainThread && wantAsync) {
              asynchronousSender.execute(new Runnable() {
                @Override
                public void run() {
                  // We know this isn't on the main thread
                  processPacketHolder(false, holder);
                }
              });
             
              // Scheduler will do the rest
              return true;
            }
           
          } catch (FieldAccessException e) {
            e.printStackTrace();
           
            // Just drop the packet
            return true;
          }
        }
       
        // Silently skip players that have logged out
        if (isOnline(current.getPlayer())) {
          sendPacket(current);
        }
      }
     
      // Drop the packet
View Full Code Here

        @Override
        public void run() {
          long stopTime = System.nanoTime() + unit.convert(time, TimeUnit.NANOSECONDS);
         
          while (!cancelled) {
            PacketEvent packet = queuedPackets.poll();
           
            if (packet == INTERUPT_PACKET || packet == WAKEUP_PACKET) {
              // Sorry, asynchronous threads!
              queuedPackets.add(packet);
             
              // Try again next tick
              break;
            } else if (packet != null && packet.getAsyncMarker() != null) {
              processPacket(workerID, packet, "onSyncPacket()");
            } else {
              // No more packets left - wait a tick
              break;
            }
View Full Code Here

     
      // Proceed
      started.incrementAndGet();
     
      while (!cancelled) {
        PacketEvent packet = queuedPackets.take();
       
        // Handle cancel requests
        if (packet == WAKEUP_PACKET) {
          // This is a bit slow, but it should be safe
          synchronized (stopLock) {
            // Are we the one who is supposed to stop?
            if (stoppedTasks.contains(workerID))
              return;
            if (waitForStops())
              return;
          }
        } else if (packet == INTERUPT_PACKET) {
          return;
        }
       
        if (packet != null && packet.getAsyncMarker() != null) {
          processPacket(workerID, packet, "onAsyncPacket()");
        }
      }
     
    } catch (InterruptedException e) {
View Full Code Here

    while (concurrentProcessing.tryAcquire()) {
      PacketEventHolder holder = processingQueue.poll();
     
      // Any packet queued?
      if (holder != null) {
        PacketEvent packet = holder.getEvent();
        AsyncMarker marker = packet.getAsyncMarker();
        Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketType());
       
        marker.incrementProcessingDelay();
       
        // Yes, removing the marker will cause the chain to stop
        if (list != null) {
View Full Code Here

  }
 
  @Override
  public PacketEvent packetRecieved(PacketContainer packet, Player client, byte[] buffered) {
    NetworkMarker marker = buffered != null ? new LegacyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered, packet.getType()) : null;
    PacketEvent event = PacketEvent.fromClient((Object) manager, packet, marker, client);
   
    manager.invokePacketRecieving(event);
    return event;
  }
View Full Code Here

        byte[] buffer = bufferStream != null ? bufferStream.toByteArray() : null;
       
        // Let the people know
        PacketType type = PacketType.findLegacy(packetID, Sender.CLIENT);
        PacketContainer container = new PacketContainer(type, thisObj);
        PacketEvent event = packetInjector.packetRecieved(container, input, buffer);
       
        // Handle override
        if (event != null) {
          Object result = event.getPacket().getHandle();
         
          if (event.isCancelled()) {
            override.put(thisObj, CANCEL_MARKER);
            return returnValue;
          } else if (!objectEquals(thisObj, result)) {
            override.put(thisObj, result);
          }
View Full Code Here

        NetworkMarker marker = queuedMarkers.remove(packet);
       
        // A packet has been sent guys!
        PacketType type = PacketType.findLegacy(id, Sender.SERVER);
        PacketContainer container = new PacketContainer(type, packet);
        PacketEvent event = PacketEvent.fromServer(invoker, container, marker, currentPlayer);
        invoker.invokePacketSending(event);
       
        // Cancelling is pretty simple. Just ignore the packet.
        if (event.isCancelled())
          return null;
       
        // Right, remember to replace the packet again
        Object result = event.getPacket().getHandle();
        marker = NetworkMarker.getNetworkMarker(event);

        // See if we need to proxy the write method
        if (result != null && (NetworkMarker.hasOutputHandlers(marker) || NetworkMarker.hasPostListeners(marker))) {
          result = writePacketInterceptor.constructProxy(result, event, marker);
View Full Code Here

TOP

Related Classes of com.comphenix.protocol.events.PacketEvent

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.