Package io.github.joealisson.mmocore
Class WritablePacket<T extends Client<Connection<T>>>
- java.lang.Object
-
- io.github.joealisson.mmocore.WritablePacket<T>
-
public abstract class WritablePacket<T extends Client<Connection<T>>> extends java.lang.ObjectThis class represents a Packet that can be sent to clients. All data sent must have a header with 2 bytes and an optional payload. The first and second bytes is a 16 bits integer holding the size of the packet.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWritablePacket()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancanBeDropped(T client)If this method returns true, the packet will be considered disposable.voidsendInBroadcast(boolean broadcast)Mark this packet as broadcast.java.lang.StringtoString()protected abstract booleanwrite(T client, WritableBuffer buffer)Writes the data to the client
-
-
-
Method Detail
-
sendInBroadcast
public void sendInBroadcast(boolean broadcast)
Mark this packet as broadcast. A broadcast packet is sent to more than one client. Caution: This method should be called beforeClient.writePacket(WritablePacket)A broadcast packet will create a Buffer cache where the data is written once and only the copy is sent to the client. note: Each copy will be encrypted to each client- Parameters:
broadcast- true if the packet is sent to more than one client
-
canBeDropped
public boolean canBeDropped(T client)
If this method returns true, the packet will be considered disposable.- Parameters:
client- client to send data to- Returns:
- if the packet is disposable or not.
-
write
protected abstract boolean write(T client, WritableBuffer buffer)
Writes the data to the client- Parameters:
client- client to send databuffer- where the data is written into- Returns:
- the packet was written successful
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-