Package io.github.joealisson.mmocore
Class Client<T extends Connection<?>>
- java.lang.Object
-
- io.github.joealisson.mmocore.Client<T>
-
public abstract class Client<T extends Connection<?>> extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()close the underlying Connection to the client.voidclose(WritablePacket<? extends Client<T>> packet)Sends the packet and close the underlying Connection to the client.abstract booleandecrypt(Buffer data, int offset, int size)Decrypt the data in-placeabstract booleanencrypt(Buffer data, int offset, int size)Encrypt the data in-place.intgetEstimateQueueSize()java.lang.StringgetHostAddress()booleanisConnected()abstract voidonConnected()Handles the client's connection.protected abstract voidonDisconnection()Handles the client's disconnection.protected voidwritePacket(WritablePacket<? extends Client<T>> packet)Sends a packet to this client.protected voidwritePackets(java.util.Collection<WritablePacket<? extends Client<T>>> packets)
-
-
-
Constructor Detail
-
Client
protected Client(T connection)
Construct a new Client- Parameters:
connection- - The Connection to the client.- Throws:
java.lang.IllegalArgumentException- if the connection is null or closed.
-
-
Method Detail
-
writePacket
protected final void writePacket(WritablePacket<? extends Client<T>> packet)
Sends a packet to this client. If another packet is been sent to this client, the actual packet is put on a queue to be sent after all previous packets. Otherwise the packet is sent immediately.- Parameters:
packet- to be sent.
-
writePackets
protected final void writePackets(java.util.Collection<WritablePacket<? extends Client<T>>> packets)
-
close
public void close()
close the underlying Connection to the client. All pending packets are cancelled.
-
close
public void close(WritablePacket<? extends Client<T>> packet)
Sends the packet and close the underlying Connection to the client. All others pending packets are cancelled.- Parameters:
packet- to be sent before the connection is closed.
-
getHostAddress
public java.lang.String getHostAddress()
- Returns:
- The client's IP address.
-
isConnected
public boolean isConnected()
- Returns:
- if client still connected
-
getEstimateQueueSize
public int getEstimateQueueSize()
- Returns:
- the estimate amount of packet queued to send
-
encrypt
public abstract boolean encrypt(Buffer data, int offset, int size)
Encrypt the data in-place.- Parameters:
data- - the data to be encryptedoffset- - the initial index to be encryptedsize- - the length of data to be encrypted- Returns:
- if data was encrypted
-
decrypt
public abstract boolean decrypt(Buffer data, int offset, int size)
Decrypt the data in-place- Parameters:
data- - data to be decryptedoffset- - the initial index to be encrypted.size- - the length of data to be encrypted.- Returns:
- if the data was decrypted.
-
onDisconnection
protected abstract void onDisconnection()
Handles the client's disconnection. This method must save all data and release all resources related to the client. No more packet can be sent after this method is called.
-
onConnected
public abstract void onConnected()
Handles the client's connection. This method should not use blocking operations. The Packets can be sent only after this method is called.
-
-