public class ClientConnection extends Object
Modifier and Type | Field and Description |
---|---|
protected InetSocketAddress |
address
The client's connection address
|
protected Channel |
channel
The data channel
|
protected static ConcurrentMap<InetSocketAddress,ClientConnection> |
clientData
Map of client connections registered
|
protected boolean |
compressionEnabled
Whether or not encryption is enabled
|
protected ThreadLocal<Cipher> |
decryptCipher |
protected ThreadLocal<Cipher> |
encryptCipher
The RSA cipher used to encrypt client data
|
protected boolean |
encryptionEnabled
Whether or not encryption is enabled for the client
|
protected KeyPair |
loginKeyPair
The login key pair
|
protected SecretKey |
sharedSecret
The secret key shared between the client and server
|
protected static SecureRandom |
SR
Random for generating the verification token
|
protected Protocol.ClientStage |
stage
The client stage during login
|
protected byte[] |
verificationToken
The verification token
|
Modifier | Constructor and Description |
---|---|
protected |
ClientConnection() |
protected |
ClientConnection(Channel channel)
Creates a new connection handler for the joining channel stream
|
Modifier and Type | Method and Description |
---|---|
InetSocketAddress |
address()
The IP address of the client handled by this connection wrapper
|
Channel |
channel()
Gets the channel context for the connection stream
|
static ClientConnection |
connection(ChannelHandlerContext chx)
Gets the connection of a channel handler context
|
ByteBuf |
decrypt(ByteBuf data)
Decrypts the given
byte encryption data |
void |
enableCompression()
Allows compression on the server and client
|
void |
enableEncryption(byte... secret)
Enables client data encryption
|
ByteBuf |
encrypt(ByteBuf data)
Encrypts the given
byte data |
void |
generateToken()
Generates the client token and stores it in the
verificationToken |
static ClientConnection |
getConnection(InetSocketAddress address)
Gets the connection by the IP address
|
boolean |
isCompressionEnabled() |
boolean |
isEncryptionEnabled()
Whether or not encryption is enabled
|
static boolean |
isLoggedIn(InetSocketAddress address)
Checks if an IP address is logged into the server
|
KeyPair |
loginKeyPair()
Gets the key pair for client login
|
void |
logout()
Removes the client's server side client handler
|
static ClientConnection |
registerConnection(Channel channel)
Registers the client channel with a protocol connection wrapper
|
void |
sendPacket(Packet packet)
Sends protocol data through the client stream
|
void |
setLoginKeyPair(KeyPair keyPair)
Sets the client login key pair
|
void |
setStage(Protocol.ClientStage stage)
Sets the client state, should only be used by the ClientConnectionHandler
|
void |
setUuid(UUID uuid)
Sets the UUID of the connection
|
SecretKey |
sharedSecret()
The protocol login encryption secret
|
Protocol.ClientStage |
stage()
Gets the current state of the connection
|
byte[] |
verificationToken()
Gets the client verification token
|
protected static final ConcurrentMap<InetSocketAddress,ClientConnection> clientData
protected static final SecureRandom SR
protected final ThreadLocal<Cipher> encryptCipher
protected final ThreadLocal<Cipher> decryptCipher
protected InetSocketAddress address
protected Channel channel
protected volatile KeyPair loginKeyPair
protected volatile Protocol.ClientStage stage
protected volatile boolean encryptionEnabled
protected volatile SecretKey sharedSecret
protected volatile byte[] verificationToken
protected volatile boolean compressionEnabled
protected ClientConnection(Channel channel)
protected ClientConnection()
public static boolean isLoggedIn(InetSocketAddress address)
address
- the address to check if onlinetrue
if the IP is on the server, false
if notpublic static ClientConnection getConnection(InetSocketAddress address)
address
- the IP to lookup the connection handlernull
if not registeredpublic static ClientConnection connection(ChannelHandlerContext chx)
chx
- the context of which to find the client fromnull
if not registeredpublic static ClientConnection registerConnection(Channel channel)
channel
- the channel of which the player is connected bypublic void sendPacket(Packet packet)
packet
- the packet to send, encoded and written to the streampublic ByteBuf encrypt(ByteBuf data) throws Exception
byte
datadata
- the data to encryptException
- if something wrong occurspublic ByteBuf decrypt(ByteBuf data) throws Exception
byte
encryption datadata
- the data to decryptException
- if something wrong occurspublic void generateToken()
verificationToken
public void enableEncryption(byte... secret)
secret
- the client secret to encrypt data withpublic void enableCompression()
@InternalUseOnly public void setUuid(UUID uuid)
uuid
- the uuid of the connectionpublic Channel channel()
public InetSocketAddress address()
public Protocol.ClientStage stage()
public void setStage(Protocol.ClientStage stage)
stage
- the state to set the client topublic byte[] verificationToken()
public boolean isEncryptionEnabled()
true
if encryption is enabled, false
if it is notpublic boolean isCompressionEnabled()
public KeyPair loginKeyPair()
KeyPair
for the clientpublic void setLoginKeyPair(KeyPair keyPair)
keyPair
- the key pair used by the clientpublic SecretKey sharedSecret()
SecretKey
shared between the server and clientpublic void logout()
Copyright © 2016. All rights reserved.