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(WritablePacket<? extends Client<T>> packet)Sends the packet and close the underlying Connection to the client.abstract booleandecrypt(byte[] data, int offset, int size)Decrypt the data in-placeprotected voiddisconnect()abstract intencrypt(byte[] data, int offset, int size)Encrypt the data in-place.java.lang.StringgetHostAddress()protected 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.
-
-
-
Constructor Detail
-
Client
public 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 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.
-
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.
-
disconnect
protected final void disconnect()
-
getHostAddress
public java.lang.String getHostAddress()
- Returns:
- The client's IP address.
-
isConnected
protected boolean isConnected()
-
encrypt
public abstract int encrypt(byte[] 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:
- The data size after encrypted
-
decrypt
public abstract boolean decrypt(byte[] 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. The Packets can be sent only after this method is called.
-
-