Add timeout support for all services on the RS2 port

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent a43e98e8f4
commit 29693a39cf
  1. 12
      game/src/main/kotlin/org/openrs2/game/net/Rs2ChannelInitializer.kt
  2. 1
      game/src/main/kotlin/org/openrs2/game/net/http/Http.kt
  3. 6
      game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelInitializer.kt
  4. 7
      game/src/main/kotlin/org/openrs2/game/net/jaggrab/JaggrabChannelHandler.kt
  5. 7
      game/src/main/kotlin/org/openrs2/game/net/js5/Js5ChannelHandler.kt
  6. 10
      game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt

@ -2,10 +2,12 @@ package org.openrs2.game.net
import io.netty.channel.Channel
import io.netty.channel.ChannelInitializer
import io.netty.handler.timeout.IdleStateHandler
import org.openrs2.game.net.login.LoginChannelHandler
import org.openrs2.protocol.Protocol
import org.openrs2.protocol.Rs2Decoder
import org.openrs2.protocol.Rs2Encoder
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Provider
import javax.inject.Singleton
@ -16,9 +18,19 @@ public class Rs2ChannelInitializer @Inject constructor(
) : ChannelInitializer<Channel>() {
override fun initChannel(ch: Channel) {
ch.pipeline().addLast(
IdleStateHandler(true, TIMEOUT_SECS, TIMEOUT_SECS, TIMEOUT_SECS, TimeUnit.SECONDS),
Rs2Decoder(Protocol.LOGIN_UPSTREAM),
Rs2Encoder(Protocol.LOGIN_DOWNSTREAM),
handlerProvider.get()
)
}
private companion object {
/*
* On the OSRS servers, login connections take 60 seconds to time out,
* but a JS5 connection only takes 30 seconds. It'd be awkward for us
* to change the timeouts at runtime to fully emulate that behaviour.
*/
private const val TIMEOUT_SECS: Long = 30
}
}

@ -17,7 +17,6 @@ import org.openrs2.buffer.copiedBuffer
import org.openrs2.buffer.use
public object Http {
public const val TIMEOUT_SECS: Long = 30
public const val MAX_CONTENT_LENGTH: Int = 65536
public const val TEXT_X_CROSS_DOMAIN_POLICY: String = "text/x-cross-domain-policy"
private const val BANNER = "OpenRS2"

@ -16,11 +16,15 @@ public class HttpChannelInitializer @Inject constructor(
) : ChannelInitializer<Channel>() {
override fun initChannel(ch: Channel) {
ch.pipeline().addLast(
IdleStateHandler(true, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, TimeUnit.SECONDS),
IdleStateHandler(true, TIMEOUT_SECS, TIMEOUT_SECS, TIMEOUT_SECS, TimeUnit.SECONDS),
HttpRequestDecoder(),
HttpResponseEncoder(),
HttpObjectAggregator(Http.MAX_CONTENT_LENGTH),
handler
)
}
private companion object {
private const val TIMEOUT_SECS: Long = 30
}
}

@ -4,6 +4,7 @@ import io.netty.channel.ChannelFutureListener
import io.netty.channel.ChannelHandler
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.timeout.IdleStateEvent
import org.openrs2.buffer.use
import org.openrs2.game.net.FileProvider
import org.openrs2.protocol.jaggrab.JaggrabRequest
@ -33,4 +34,10 @@ public class JaggrabChannelHandler @Inject constructor(
override fun channelReadComplete(ctx: ChannelHandlerContext) {
ctx.flush()
}
override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) {
if (evt is IdleStateEvent) {
ctx.close()
}
}
}

@ -2,6 +2,7 @@ package org.openrs2.game.net.js5
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.timeout.IdleStateEvent
import org.openrs2.protocol.js5.Js5Request
import org.openrs2.protocol.js5.XorEncoder
import javax.inject.Inject
@ -37,4 +38,10 @@ public class Js5ChannelHandler @Inject constructor(
service.notifyIfNotEmpty(client)
}
}
override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) {
if (evt is IdleStateEvent) {
ctx.close()
}
}
}

@ -9,7 +9,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator
import io.netty.handler.codec.http.HttpRequestDecoder
import io.netty.handler.codec.http.HttpResponseEncoder
import io.netty.handler.codec.string.StringDecoder
import io.netty.handler.timeout.IdleStateHandler
import io.netty.handler.timeout.IdleStateEvent
import org.openrs2.buffer.copiedBuffer
import org.openrs2.game.net.crossdomain.CrossDomainChannelHandler
import org.openrs2.game.net.http.Http
@ -23,7 +23,6 @@ import org.openrs2.protocol.js5.Js5ResponseEncoder
import org.openrs2.protocol.js5.XorDecoder
import org.openrs2.protocol.login.LoginRequest
import org.openrs2.protocol.login.LoginResponse
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Provider
@ -77,7 +76,6 @@ public class LoginChannelHandler @Inject constructor(
private fun handleInitCrossDomainConnection(ctx: ChannelHandlerContext) {
ctx.pipeline().addLast(
IdleStateHandler(true, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, Http.TIMEOUT_SECS, TimeUnit.SECONDS),
HttpRequestDecoder(),
HttpResponseEncoder(),
HttpObjectAggregator(Http.MAX_CONTENT_LENGTH),
@ -95,6 +93,12 @@ public class LoginChannelHandler @Inject constructor(
ctx.flush()
}
override fun userEventTriggered(ctx: ChannelHandlerContext, evt: Any) {
if (evt is IdleStateEvent) {
ctx.close()
}
}
private companion object {
private const val BUILD = 550
private const val JAGGRAB_MAX_FRAME_LENGTH = 4096

Loading…
Cancel
Save