Session

class Session<R>(val ctx: ChannelHandlerContext, incomingMessageQueue: Queue<IncomingGameMessage>, outgoingMessageQueueProvider: MessageQueueProvider<OutgoingGameMessage>, counter: GameMessageCounter, consumers: Map<Class<out IncomingGameMessage>, MessageConsumer<R, IncomingGameMessage>>, globalConsumers: List<MessageConsumer<R, IncomingGameMessage>>, val loginBlock: LoginBlock<*>, incomingGameMessageConsumerExceptionHandler: IncomingGameMessageConsumerExceptionHandler<R>)

The session objects are used to link the player instances together with the respective session instances.

Parameters

R

the receiver of the game message consumers, typically a player

outgoingMessageQueueProvider

the provider for outgoing message queues. One queue is allocated for each possible game server prot category.

Constructors

Link copied to clipboard
constructor(ctx: ChannelHandlerContext, incomingMessageQueue: Queue<IncomingGameMessage>, outgoingMessageQueueProvider: MessageQueueProvider<OutgoingGameMessage>, counter: GameMessageCounter, consumers: Map<Class<out IncomingGameMessage>, MessageConsumer<R, IncomingGameMessage>>, globalConsumers: List<MessageConsumer<R, IncomingGameMessage>>, loginBlock: LoginBlock<*>, incomingGameMessageConsumerExceptionHandler: IncomingGameMessageConsumerExceptionHandler<R>)

Properties

Link copied to clipboard
val ctx: ChannelHandlerContext

the channel handler context behind this session, public in case the server needs to directly manage it

Link copied to clipboard

the inet address behind this connection

Link copied to clipboard
val loginBlock: LoginBlock<*>

the login block that resulted in this session being constructed

Functions

Link copied to clipboard
fun clear()

Clears all the remaining incoming and outgoing messages, releasing any buffers that were wrapped in a byte buffer holder. This function should be called on logout and whenever a reconnection happens, in order to get rid of any messages that got written to the session, but couldn't be flushed out in time before the session became inactive.

Link copied to clipboard
fun flush()

Flushes any queued messages to the client, if any exist. The flushing process takes place in the netty event loop, thus the calls to this function are non-blocking and fast. If not all packets were written due to writability constraints, this function will further be re-triggered when channel writability turns back to true, meaning this function can be called directly from the netty event loop, thus the check inside it.

Link copied to clipboard
fun processIncomingPackets(receiver: R): Int

Iterates through all the incoming packets over the last cycle and invokes the consumer with the receiver on them. If an exception is caught, it is propagated forward to the respective exception handler. If too many messages were received from the server during the last cycle, the decoder will have stopped accepting any new packets. If that was the case at the end of this function, the packet decoding will resume.

Link copied to clipboard
fun queue(message: OutgoingGameMessage)

Queues a game message to be written to the client based on the message's defined category

fun queue(message: OutgoingGameMessage, category: ServerProtCategory)

Queues a game message to be written to the client based on the provided message category, in case one wishes to override the categories defined by the library

Link copied to clipboard

Requests the channel to be closed once there's nothing more to write out, and the channel has been flushed.

Link copied to clipboard

Sets a disconnection hook to be triggered if the connection to this channel is lost, allowing one to safely log the player out in such case. If the channel has already disconnected by the time this function is invoked, the hook will be executed immediately.