Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
package org.openrs2.game.net.js5
|
|
|
|
import io.netty.channel.ChannelHandlerContext
|
|
import io.netty.channel.SimpleChannelInboundHandler
|
|
import org.openrs2.protocol.js5.Js5Request
|
|
import org.openrs2.protocol.js5.XorEncoder
|
|
import javax.inject.Inject
|
|
|
|
public class Js5ChannelHandler @Inject constructor(
|
|
private val service: Js5Service
|
|
) : SimpleChannelInboundHandler<Js5Request>() {
|
|
private lateinit var client: Js5Client
|
|
|
|
override fun handlerAdded(ctx: ChannelHandlerContext) {
|
|
client = Js5Client(ctx.read())
|
|
}
|
|
|
|
override fun channelRead0(ctx: ChannelHandlerContext, msg: Js5Request) {
|
|
when (msg) {
|
|
is Js5Request.Group -> service.push(client, msg)
|
|
is Js5Request.Rekey -> handleRekey(ctx, msg)
|
|
is Js5Request.Disconnect -> ctx.close()
|
|
}
|
|
}
|
|
|
|
private fun handleRekey(ctx: ChannelHandlerContext, msg: Js5Request.Rekey) {
|
|
val encoder = ctx.pipeline().get(XorEncoder::class.java)
|
|
encoder.key = msg.key
|
|
}
|
|
|
|
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
|
service.readIfNotFull(client)
|
|
}
|
|
|
|
override fun channelWritabilityChanged(ctx: ChannelHandlerContext) {
|
|
if (ctx.channel().isWritable) {
|
|
service.notifyIfNotEmpty(client)
|
|
}
|
|
}
|
|
}
|
|
|