Class PlayerSocketConnection

java.lang.Object
net.minestom.server.network.player.PlayerConnection
net.minestom.server.network.player.PlayerSocketConnection

@Internal public class PlayerSocketConnection extends PlayerConnection
Represents a socket connection.

It is the implementation used for all network client.

  • Constructor Details

    • PlayerSocketConnection

      public PlayerSocketConnection(@NotNull @NotNull Worker worker, @NotNull @NotNull SocketChannel channel, SocketAddress remoteAddress)
  • Method Details

    • processPackets

      public void processPackets(BinaryBuffer readBuffer, PacketProcessor packetProcessor)
    • consumeCache

      public void consumeCache(BinaryBuffer buffer)
    • setEncryptionKey

      public void setEncryptionKey(@NotNull @NotNull SecretKey secretKey)
      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

      public void sendPacket(@NotNull @NotNull SendablePacket packet)
      Description copied from class: PlayerConnection
      Serializes the packet and send it to the client.
      Specified by:
      sendPacket in class PlayerConnection
      Parameters:
      packet - the packet to send
    • sendPackets

      public void sendPackets(@NotNull @NotNull Collection<SendablePacket> packets)
      Overrides:
      sendPackets in class PlayerConnection
    • write

      @Internal public void write(@NotNull @NotNull ByteBuffer buffer, int index, int length)
    • write

      @Internal public void write(@NotNull @NotNull ByteBuffer buffer)
    • getRemoteAddress

      @NotNull public @NotNull SocketAddress getRemoteAddress()
      Description copied from class: PlayerConnection
      Gets the remote address of the client.
      Specified by:
      getRemoteAddress in class PlayerConnection
      Returns:
      the remote address
    • setRemoteAddress

      @Internal public void setRemoteAddress(@NotNull @NotNull SocketAddress remoteAddress)
      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 class PlayerConnection
    • getChannel

      @NotNull public @NotNull SocketChannel getChannel()
    • gameProfile

      @Nullable public @Nullable GameProfile gameProfile()
    • UNSAFE_setProfile

      public void UNSAFE_setProfile(@NotNull @NotNull GameProfile gameProfile)
    • getLoginUsername

      @Nullable public @Nullable String 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

      public void UNSAFE_setLoginUsername(@NotNull @NotNull String loginUsername)
      Sets the internal login username field.
      Parameters:
      loginUsername - the new login username field
    • getServerAddress

      @Nullable public @Nullable String 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 class PlayerConnection
      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 class PlayerConnection
      Returns:
      the server port used
    • getProtocolVersion

      public int getProtocolVersion()
      Gets the protocol version of a client.
      Overrides:
      getProtocolVersion in class PlayerConnection
      Returns:
      protocol version of client.
    • refreshServerInformation

      public void refreshServerInformation(@Nullable @Nullable String serverAddress, int serverPort, int protocolVersion)
      Used in ClientHandshakePacket to change the internal fields.
      Parameters:
      serverAddress - the server address which the client used
      serverPort - the server port which the client used
      protocolVersion - the protocol version which the client used
    • getNonce

      public byte[] getNonce()
    • setNonce

      public void setNonce(byte[] nonce)
    • flushSync

      public void flushSync() throws IOException
      Throws:
      IOException