Class TcpSession
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<Packet>
org.geysermc.mcprotocollib.network.tcp.TcpSession
- All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, Session
- Direct Known Subclasses:
TcpClientSession, TcpServerSession
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SessionListener listener) Adds a listener to this session.voidvoidcallDisconnected(net.kyori.adventure.text.Component reason, Throwable cause) voidcallDisconnecting(net.kyori.adventure.text.Component reason, Throwable cause) booleancallPacketError(Throwable throwable) voidcallPacketReceived(Packet packet) Notifies all listeners that a packet was just received.callPacketSending(Packet packet) voidcallPacketSent(Packet packet) Notifies all listeners that a packet was just sent.voidchannelActive(io.netty.channel.ChannelHandlerContext ctx) voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, Packet packet) voidconnect()Connects this session to its host and port.voidconnect(boolean wait) Connects this session to its host and port.voidconnect(boolean wait, boolean transferring) Connects this session to its host and port.voiddisconnect(@NonNull net.kyori.adventure.text.Component reason, @Nullable Throwable cause) Disconnects the session.voidEnables encryption for this session.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) voidflush()Flushes all pending packets.io.netty.channel.ChannelReturns the underlying netty channel of this session.intGets the compression packet length threshold for this session (-1 = disabled).intGets the connect timeout for this session in seconds.<T> TGets the value of the given flag as an instance of the given type.<T> TGets the value of the given flag as an instance of the given type.getFlags()Gets this session's set flags.getHost()Gets the host the session is connected to.Gets the listeners listening on this session.Gets the local address of the session.Gets the packet protocol of the session.intgetPort()Gets the port the session is connected to.intGets the read timeout for this session in seconds.Gets the remote address of the session.intGets the write timeout for this session in seconds.booleanChecks whether this session has a flag set.booleanReturns true if the session is connected.booleanprotected voidprotected voidrefreshReadTimeoutHandler(io.netty.channel.Channel channel) protected voidprotected voidrefreshWriteTimeoutHandler(io.netty.channel.Channel channel) voidremoveListener(SessionListener listener) Removes a listener from this session.io.netty.channel.ChannelFutureSends a packet.voidvoidSends a packet on the event loopvoidvoidsendBundle(@NonNull List<Packet> packets) voidsendBundle(@NonNull Packet... packets) voidsendBundleDirect(@NonNull List<Packet> packets) voidsendBundleDirect(@NonNull Packet... packets) io.netty.channel.ChannelFuturesendDelayed(@NonNull Packet packet) Writes a packet without flushingvoidsendDelayed(@NonNull Packet packet, @NonNull io.netty.channel.ChannelFutureListener listener) Writes a packet without flushingvoidsendDelayedDirect(@NotNull Packet packet) Writes a packet without calling listeners and without flushingio.netty.channel.ChannelFuturesendDirect(@NotNull Packet packet) Sends a packet without calling listenersvoidsendScheduledAsync(@NonNull Packet packet, long delay, TimeUnit unit) voidsetAutoRead(boolean autoRead) Auto read in netty means that the server is automatically reading from the channel.voidsetChannel(io.netty.channel.Channel channel) voidsetCompressionThreshold(int compressionThreshold) voidsetCompressionThreshold(int threshold, int level, boolean validateDecompression) Sets the compression packet length threshold for this session (-1 = disabled).voidsetConnectTimeout(int timeout) Sets the connect timeout for this session in seconds.voidsetDisconnected(boolean disconnected) <T> voidSets the value of a flag.voidSets the values for a collection of flags.voidvoidsetListeners(SessionListener[] listeners) voidsetPort(int port) voidsetReadTimeout(int timeout) Sets the read timeout for this session in seconds.voidsetWriteTimeout(int timeout) Sets the write timeout for this session in seconds.Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemovedMethods inherited from interface Session
disconnect, disconnect, disconnect, getPalettedWorldState, switchInboundState, switchOutboundState
-
Field Details
-
ID
- See Also:
-
READ_TIMEOUT_HANDLER_ID
- See Also:
-
WRITE_TIMEOUT_HANDLER_ID
- See Also:
-
PROXY_HANDLER_ID
- See Also:
-
HA_PROXY_ENCODER_ID
- See Also:
-
host
-
port
protected int port -
disconnected
protected boolean disconnected
-
-
Constructor Details
-
TcpSession
-
-
Method Details
-
connect
-
connect
-
connect
public void connect(boolean wait, boolean transferring) Description copied from interface:SessionConnects this session to its host and port. -
getHost
-
getPort
-
getLocalAddress
Description copied from interface:SessionGets the local address of the session.- Specified by:
getLocalAddressin interfaceSession- Returns:
- The local address, or null if the session is not connected.
-
getRemoteAddress
Description copied from interface:SessionGets the remote address of the session.- Specified by:
getRemoteAddressin interfaceSession- Returns:
- The remote address, or null if the session is not connected.
-
getPacketProtocol
Description copied from interface:SessionGets the packet protocol of the session.- Specified by:
getPacketProtocolin interfaceSession- Returns:
- The session's packet protocol.
-
getFlags
-
hasFlag
Description copied from interface:SessionChecks whether this session has a flag set. If this session belongs to a server, the server's flags will also be checked. -
getFlag
Description copied from interface:SessionGets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well. -
getFlag
Description copied from interface:SessionGets the value of the given flag as an instance of the given type. If this session belongs to a server, the server's flags will be checked for the flag as well. If the flag is not set, the specified default value will be returned. -
setFlag
Description copied from interface:SessionSets the value of a flag. This does not change a server's flags if this session belongs to a server. -
setFlags
-
getListeners
Description copied from interface:SessionGets the listeners listening on this session.- Specified by:
getListenersin interfaceSession- Returns:
- This session's listeners.
-
addListener
Description copied from interface:SessionAdds a listener to this session.- Specified by:
addListenerin interfaceSession- Parameters:
listener- Listener to add.
-
removeListener
Description copied from interface:SessionRemoves a listener from this session.- Specified by:
removeListenerin interfaceSession- Parameters:
listener- Listener to remove.
-
callPacketSending
- Specified by:
callPacketSendingin interfaceSession
-
callConnected
public void callConnected()- Specified by:
callConnectedin interfaceSession
-
callDisconnecting
- Specified by:
callDisconnectingin interfaceSession
-
callDisconnected
- Specified by:
callDisconnectedin interfaceSession
-
callPacketError
- Specified by:
callPacketErrorin interfaceSession
-
callPacketReceived
Description copied from interface:SessionNotifies all listeners that a packet was just received.- Specified by:
callPacketReceivedin interfaceSession- Parameters:
packet- Packet to notify.
-
callPacketSent
Description copied from interface:SessionNotifies all listeners that a packet was just sent.- Specified by:
callPacketSentin interfaceSession- Parameters:
packet- Packet to notify.
-
getCompressionThreshold
public int getCompressionThreshold()Description copied from interface:SessionGets the compression packet length threshold for this session (-1 = disabled).- Specified by:
getCompressionThresholdin interfaceSession- Returns:
- This session's compression threshold.
-
setCompressionThreshold
public void setCompressionThreshold(int threshold, int level, boolean validateDecompression) Description copied from interface:SessionSets the compression packet length threshold for this session (-1 = disabled).- Specified by:
setCompressionThresholdin interfaceSession- Parameters:
threshold- The new compression threshold.level- Higher level = more compression, but more CPU. -1 = default levelvalidateDecompression- whether to validate that the decompression fits within size checks.
-
enableEncryption
Description copied from interface:SessionEnables encryption for this session.- Specified by:
enableEncryptionin interfaceSession- Parameters:
key- the secret key to encrypt with
-
getConnectTimeout
public int getConnectTimeout()Description copied from interface:SessionGets the connect timeout for this session in seconds.- Specified by:
getConnectTimeoutin interfaceSession- Returns:
- The session's connect timeout.
-
setConnectTimeout
public void setConnectTimeout(int timeout) Description copied from interface:SessionSets the connect timeout for this session in seconds.- Specified by:
setConnectTimeoutin interfaceSession- Parameters:
timeout- Connect timeout to set.
-
getReadTimeout
public int getReadTimeout()Description copied from interface:SessionGets the read timeout for this session in seconds.- Specified by:
getReadTimeoutin interfaceSession- Returns:
- The session's read timeout.
-
setReadTimeout
public void setReadTimeout(int timeout) Description copied from interface:SessionSets the read timeout for this session in seconds.- Specified by:
setReadTimeoutin interfaceSession- Parameters:
timeout- Read timeout to set.
-
getWriteTimeout
public int getWriteTimeout()Description copied from interface:SessionGets the write timeout for this session in seconds.- Specified by:
getWriteTimeoutin interfaceSession- Returns:
- The session's write timeout.
-
setWriteTimeout
public void setWriteTimeout(int timeout) Description copied from interface:SessionSets the write timeout for this session in seconds.- Specified by:
setWriteTimeoutin interfaceSession- Parameters:
timeout- Write timeout to set.
-
isConnected
public boolean isConnected()Description copied from interface:SessionReturns true if the session is connected.- Specified by:
isConnectedin interfaceSession- Returns:
- True if the session is connected.
-
send
-
sendAwait
-
send
-
sendDirect
Description copied from interface:SessionSends a packet without calling listeners- Specified by:
sendDirectin interfaceSession- Parameters:
packet- Packet to send- Returns:
-
sendDelayedDirect
Description copied from interface:SessionWrites a packet without calling listeners and without flushing- Specified by:
sendDelayedDirectin interfaceSession- Parameters:
packet- Packet to send
-
sendDelayed
Description copied from interface:SessionWrites a packet without flushing- Specified by:
sendDelayedin interfaceSession
-
sendDelayed
public void sendDelayed(@NonNull Packet packet, @NonNull io.netty.channel.ChannelFutureListener listener) Description copied from interface:SessionWrites a packet without flushing- Specified by:
sendDelayedin interfaceSession
-
flush
-
sendBundleDirect
- Specified by:
sendBundleDirectin interfaceSession
-
sendBundleDirect
- Specified by:
sendBundleDirectin interfaceSession
-
sendBundle
- Specified by:
sendBundlein interfaceSession
-
sendBundle
- Specified by:
sendBundlein interfaceSession
-
sendAsync
-
sendScheduledAsync
- Specified by:
sendScheduledAsyncin interfaceSession
-
disconnect
public void disconnect(@NonNull net.kyori.adventure.text.Component reason, @Nullable Throwable cause) Description copied from interface:SessionDisconnects the session.- Specified by:
disconnectin interfaceSession- Parameters:
reason- Reason for disconnecting.cause- Throwable responsible for disconnecting.
-
setAutoRead
public void setAutoRead(boolean autoRead) Description copied from interface:SessionAuto read in netty means that the server is automatically reading from the channel. Turning it off means that we won't get more packets being decoded until we turn it back on. We use this to hold off on reading packets until we are ready to process them. For example this is used for switching inbound states withSession.switchInboundState(ProtocolState).- Specified by:
setAutoReadin interfaceSession- Parameters:
autoRead- Whether to enable auto read. Default is true.
-
refreshReadTimeoutHandler
protected void refreshReadTimeoutHandler() -
refreshReadTimeoutHandler
protected void refreshReadTimeoutHandler(io.netty.channel.Channel channel) -
refreshWriteTimeoutHandler
protected void refreshWriteTimeoutHandler() -
refreshWriteTimeoutHandler
protected void refreshWriteTimeoutHandler(io.netty.channel.Channel channel) -
channelActive
-
channelInactive
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-
channelRead0
-
getProtocol
-
getChannel
public io.netty.channel.Channel getChannel()Description copied from interface:SessionReturns the underlying netty channel of this session.- Specified by:
getChannelin interfaceSession- Returns:
- The netty channel
-
isDisconnected
public boolean isDisconnected() -
setHost
-
setPort
public void setPort(int port) -
setCompressionThreshold
public void setCompressionThreshold(int compressionThreshold) -
setListeners
-
setChannel
public void setChannel(io.netty.channel.Channel channel) -
setDisconnected
public void setDisconnected(boolean disconnected)
-