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 TypeMethodDescriptionvoidaddPluginRequestEntry(int messageId, @NotNull String channel) Adds an entry to the plugin request map.voidconsumeCache(BinaryBuffer buffer) voidForcing the player to disconnect.void@Nullable GameProfile@NotNull SocketChannel@Nullable StringRetrieves the username received from the client during connection.byte[]getNonce()@Nullable StringgetPluginRequestChannel(int messageId) Gets a request channel from a message id, previously cached usingaddPluginRequestEntry(int, String).intGets the protocol version of a client.@NotNull SocketAddressGets the remote address of the client.@Nullable StringGets the server address that the client used to connect.intGets the server port that the client used to connect.voidprocessPackets(BinaryBuffer readBuffer, PacketProcessor packetProcessor) voidrefreshServerInformation(@Nullable String serverAddress, int serverPort, int protocolVersion) Used inClientHandshakePacketto change the internal fields.voidsendPacket(@NotNull SendablePacket packet) Serializes the packet and send it to the client.voidsendPackets(@NotNull Collection<SendablePacket> packets) voidsetConnectionState(@NotNull ConnectionState connectionState) voidsetEncryptionKey(@NotNull SecretKey secretKey) Sets the encryption key and add the codecs to the pipeline.voidsetNonce(byte[] nonce) voidsetRemoteAddress(@NotNull SocketAddress remoteAddress) Changes the internal remote address field.voidEnables compression and add a new codec to the pipeline.voidUNSAFE_setLoginUsername(@NotNull String loginUsername) Sets the internal login username field.voidUNSAFE_setProfile(@NotNull GameProfile gameProfile) voidwrite(@NotNull ByteBuffer buffer) voidwrite(@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:PlayerConnectionSerializes the packet and send it to the client.- Specified by:
sendPacketin classPlayerConnection- Parameters:
packet- the packet to send
-
sendPackets
- Overrides:
sendPacketsin classPlayerConnection
-
write
-
write
-
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
-
disconnect
public void disconnect()Description copied from class:PlayerConnectionForcing the player to disconnect.- Overrides:
disconnectin 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:
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
-
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 valuemessageIdalready 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:
setConnectionStatein classPlayerConnection
-
getNonce
public byte[] getNonce() -
setNonce
public void setNonce(byte[] nonce) -
flushSync
- Throws:
IOException
-