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.
35 lines
1020 B
35 lines
1020 B
3 years ago
|
package org.openrs2.game.net.jaggrab
|
||
|
|
||
|
import io.netty.channel.ChannelFutureListener
|
||
|
import io.netty.channel.ChannelHandler
|
||
|
import io.netty.channel.ChannelHandlerContext
|
||
|
import io.netty.channel.SimpleChannelInboundHandler
|
||
|
import org.openrs2.game.net.FileProvider
|
||
|
import org.openrs2.protocol.jaggrab.JaggrabRequest
|
||
|
import javax.inject.Inject
|
||
|
import javax.inject.Singleton
|
||
|
|
||
|
@Singleton
|
||
|
@ChannelHandler.Sharable
|
||
|
public class JaggrabChannelHandler @Inject constructor(
|
||
|
private val fileProvider: FileProvider
|
||
|
) : SimpleChannelInboundHandler<JaggrabRequest>() {
|
||
|
override fun handlerAdded(ctx: ChannelHandlerContext) {
|
||
|
ctx.read()
|
||
|
}
|
||
|
|
||
|
override fun channelRead0(ctx: ChannelHandlerContext, msg: JaggrabRequest) {
|
||
|
val file = fileProvider.get(msg.path)
|
||
|
if (file == null) {
|
||
|
ctx.close()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx.write(file).addListener(ChannelFutureListener.CLOSE)
|
||
|
}
|
||
|
|
||
|
override fun channelReadComplete(ctx: ChannelHandlerContext) {
|
||
|
ctx.flush()
|
||
|
}
|
||
|
}
|