Class PlayerSocketConnection
java.lang.Object
net.minestom.server.network.player.PlayerConnection
net.minestom.server.network.player.PlayerSocketConnection
Represents a socket connection.
It is the implementation used for all network client.
-
Constructor Summary
ConstructorsConstructorDescriptionPlayerSocketConnection(SocketChannel channel, SocketAddress remoteAddress, Thread readThread, Thread writeThread) -
Method Summary
Modifier and TypeMethodDescriptionvoidRetrieves the username received from the client during connection.byte[]getNonce()intGets the protocol version of a client.Gets the remote address of the client.Gets the server address that the client used to connect.intGets the server port that the client used to connect.voidread(PacketParser<ClientPacket> packetParser) voidrefreshServerInformation(@Nullable String serverAddress, int serverPort, int protocolVersion) Used inClientHandshakePacketto change the internal fields.voidsendPacket(SendablePacket packet) Serializes the packet and send it to the client.voidsendPackets(Collection<SendablePacket> packets) voidsetEncryptionKey(SecretKey secretKey) Sets the encryption key and add the codecs to the pipeline.voidsetNonce(byte[] nonce) voidsetRemoteAddress(SocketAddress remoteAddress) Changes the internal remote address field.voidEnables compression and add a new codec to the pipeline.voidUNSAFE_setLoginUsername(String loginUsername) Sets the internal login username field.voidUNSAFE_setProfile(GameProfile gameProfile) Methods inherited from class PlayerConnection
disconnect, fetchCookie, getClientState, getConnectionState, getIdentifier, getPlayer, getServerState, isOnline, kick, loginPluginMessageProcessor, playerPublicKey, receiveCookieResponse, receiveKnownPacksResponse, requestKnownPacks, sendPackets, setClientState, setPlayer, setPlayerPublicKey, setServerState, storeCookie, toString
-
Constructor Details
-
PlayerSocketConnection
public PlayerSocketConnection(SocketChannel channel, SocketAddress remoteAddress, Thread readThread, Thread writeThread)
-
-
Method Details
-
read
- Throws:
IOException
-
setEncryptionKey
Sets the encryption key and add the codecs to the pipeline.- Parameters:
secretKey- the secret key to use in the encryption- Throws:
IllegalStateException- if encryption is already enabled for this connection
-
startCompression
public void startCompression()Enables compression and add a new codec to the pipeline.- Throws:
IllegalStateException- if encryption is already enabled for this connection
-
sendPacket
Description copied from class:PlayerConnectionSerializes the packet and send it to the client.- Specified by:
sendPacketin classPlayerConnection- Parameters:
packet- the packet to send
-
sendPackets
- Overrides:
sendPacketsin classPlayerConnection
-
getRemoteAddress
Description copied from class:PlayerConnectionGets the remote address of the client.- Specified by:
getRemoteAddressin classPlayerConnection- Returns:
- the remote address
-
setRemoteAddress
Changes the internal remote address field.Mostly unsafe, used internally when interacting with a proxy.
- Parameters:
remoteAddress- the new connection remote address
-
getChannel
-
gameProfile
-
UNSAFE_setProfile
-
getLoginUsername
-
UNSAFE_setLoginUsername
Sets the internal login username field.- Parameters:
loginUsername- the new login username field
-
getServerAddress
Gets the server address that the client used to connect.WARNING: it is given by the client, it is possible for it to be wrong.
- Overrides:
getServerAddressin classPlayerConnection- Returns:
- the server address used
-
getServerPort
public int getServerPort()Gets the server port that the client used to connect.WARNING: it is given by the client, it is possible for it to be wrong.
- Overrides:
getServerPortin classPlayerConnection- Returns:
- the server port used
-
getProtocolVersion
public int getProtocolVersion()Gets the protocol version of a client.- Overrides:
getProtocolVersionin classPlayerConnection- Returns:
- protocol version of client.
-
refreshServerInformation
public void refreshServerInformation(@Nullable @Nullable String serverAddress, int serverPort, int protocolVersion) Used inClientHandshakePacketto change the internal fields.- Parameters:
serverAddress- the server address which the client usedserverPort- the server port which the client usedprotocolVersion- the protocol version which the client used
-
getNonce
public byte[] getNonce() -
setNonce
public void setNonce(byte[] nonce) -
flushSync
- Throws:
IOException
-
readThread
-
writeThread
-