Added the ability to retrieve the input buffer as a stream.
Dieser Commit ist enthalten in:
Ursprung
fefad5d806
Commit
9f0d3a5054
@ -1,5 +1,7 @@
|
||||
package com.comphenix.protocol.events;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -11,13 +13,19 @@ import javax.annotation.Nonnull;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* Marker containing the serialized packet data seen from the network,
|
||||
* or output handlers that will serialize the current packet.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class NetworkMarker {
|
||||
// Custom network handler
|
||||
private PriorityQueue<PacketOutputHandler> outputHandlers;
|
||||
// The input buffer
|
||||
private ByteBuffer inputBuffer;
|
||||
|
||||
private ConnectionSide side;
|
||||
private final ConnectionSide side;
|
||||
|
||||
/**
|
||||
* Construct a new network marker.
|
||||
@ -57,6 +65,24 @@ public class NetworkMarker {
|
||||
return inputBuffer != null ? inputBuffer.asReadOnlyBuffer() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the serialized packet data as an input stream.
|
||||
* <p>
|
||||
* The data is exactly the same as in {@link #getInputBuffer()}.
|
||||
* @see {@link #getInputBuffer()}
|
||||
* @return The incoming serialized packet data as a stream, or NULL if the packet was transmitted locally.
|
||||
*/
|
||||
public DataInputStream getInputStream() {
|
||||
if (side.isForServer())
|
||||
throw new IllegalStateException("Server-side packets have no input buffer.");
|
||||
if (inputBuffer == null)
|
||||
return null;
|
||||
|
||||
return new DataInputStream(
|
||||
new ByteArrayInputStream(inputBuffer.array())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue the given output handler for managing how the current packet will be written to the network stream.
|
||||
* <p>
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren