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
(@NotNull Worker worker, @NotNull SocketChannel channel, SocketAddress remoteAddress) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPluginRequestEntry
(int messageId, @NotNull String channel) Adds an entry to the plugin request map.void
consumeCache
(BinaryBuffer buffer) void
Forcing the player to disconnect.void
@Nullable GameProfile
@NotNull SocketChannel
@Nullable String
Retrieves the username received from the client during connection.byte[]
getNonce()
@Nullable String
getPluginRequestChannel
(int messageId) Gets a request channel from a message id, previously cached usingaddPluginRequestEntry(int, String)
.int
Gets the protocol version of a client.@NotNull SocketAddress
Gets the remote address of the client.@Nullable String
Gets the server address that the client used to connect.int
Gets the server port that the client used to connect.void
processPackets
(BinaryBuffer readBuffer, PacketProcessor packetProcessor) void
refreshServerInformation
(@Nullable String serverAddress, int serverPort, int protocolVersion) Used inHandshakePacket
to change the internal fields.void
sendPacket
(@NotNull SendablePacket packet) Serializes the packet and send it to the client.void
sendPackets
(@NotNull Collection<SendablePacket> packets) void
setConnectionState
(@NotNull ConnectionState connectionState) void
setEncryptionKey
(@NotNull SecretKey secretKey) Sets the encryption key and add the codecs to the pipeline.void
setNonce
(byte[] nonce) void
setRemoteAddress
(@NotNull SocketAddress remoteAddress) Changes the internal remote address field.void
Enables compression and add a new codec to the pipeline.void
UNSAFE_setLoginUsername
(@NotNull String loginUsername) Sets the internal login username field.void
UNSAFE_setProfile
(@NotNull GameProfile gameProfile) void
write
(@NotNull ByteBuffer buffer) void
write
(@NotNull ByteBuffer buffer, int index, int length) Methods inherited from class net.minestom.server.network.player.PlayerConnection
getConnectionState, getIdentifier, getPlayer, isOnline, playerPublicKey, sendPackets, setPlayer, setPlayerPublicKey, toString
-
Constructor Details
-
PlayerSocketConnection
public PlayerSocketConnection(@NotNull @NotNull Worker worker, @NotNull @NotNull SocketChannel channel, SocketAddress remoteAddress)
-
-
Method Details
-
processPackets
-
consumeCache
-
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:PlayerConnection
Serializes the packet and send it to the client.- Specified by:
sendPacket
in classPlayerConnection
- Parameters:
packet
- the packet to send
-
sendPackets
- Overrides:
sendPackets
in classPlayerConnection
-
write
-
write
-
getRemoteAddress
Description copied from class:PlayerConnection
Gets the remote address of the client.- Specified by:
getRemoteAddress
in 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
-
disconnect
public void disconnect()Description copied from class:PlayerConnection
Forcing the player to disconnect.- Overrides:
disconnect
in classPlayerConnection
-
getChannel
-
gameProfile
-
UNSAFE_setProfile
-
getLoginUsername
Retrieves the username received from the client during connection.This value has not been checked and could be anything.
- Returns:
- the username given by the client, unchecked
-
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:
getServerAddress
in 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:
getServerPort
in classPlayerConnection
- Returns:
- the server port used
-
getProtocolVersion
public int getProtocolVersion()Gets the protocol version of a client.- Overrides:
getProtocolVersion
in classPlayerConnection
- Returns:
- protocol version of client.
-
refreshServerInformation
public void refreshServerInformation(@Nullable @Nullable String serverAddress, int serverPort, int protocolVersion) Used inHandshakePacket
to 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
-
addPluginRequestEntry
Adds an entry to the plugin request map.Only working if
PlayerConnection.getConnectionState()
isConnectionState.LOGIN
.- Parameters:
messageId
- the message idchannel
- the packet channel- Throws:
IllegalStateException
- if a messageId with the valuemessageId
already exists for this connection
-
getPluginRequestChannel
Gets a request channel from a message id, previously cached usingaddPluginRequestEntry(int, String)
.Be aware that the internal map is cleared once the player enters the play state.
- Parameters:
messageId
- the message id- Returns:
- the channel linked to the message id, null if not found
-
setConnectionState
- Overrides:
setConnectionState
in classPlayerConnection
-
getNonce
public byte[] getNonce() -
setNonce
public void setNonce(byte[] nonce) -
flushSync
- Throws:
IOException
-