From 0c2108d750a95d9eb4b9ab6428d42c898c7cad3a Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 19 Jul 2022 17:56:38 +0100 Subject: [PATCH] Add separate Protocol for INIT_JS5REMOTE_CONNECTION responses This allows us to deal with a single corner case of the same opcode being used for two slightly different login response packets, depending on the request. --- .../archive/cache/OsrsJs5ChannelInitializer.kt | 2 +- .../openrs2/game/net/login/LoginChannelHandler.kt | 5 ++++- .../main/kotlin/org/openrs2/protocol/Protocol.kt | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt index 7c53c615d0..538459621e 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt @@ -12,7 +12,7 @@ public class OsrsJs5ChannelInitializer(private val handler: OsrsJs5ChannelHandle ch.pipeline().addLast( ReadTimeoutHandler(30), Rs2Encoder(Protocol.LOGIN_UPSTREAM), - Rs2Decoder(Protocol.LOGIN_DOWNSTREAM) + Rs2Decoder(Protocol.LOGIN_DOWNSTREAM_JS5REMOTE) ) ch.pipeline().addLast("handler", handler) } diff --git a/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt index 94f00d3829..f52b986d1d 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/login/LoginChannelHandler.kt @@ -49,6 +49,9 @@ public class LoginChannelHandler @Inject constructor( } private fun handleInitJs5RemoteConnection(ctx: ChannelHandlerContext, msg: LoginRequest.InitJs5RemoteConnection) { + val encoder = ctx.pipeline().get(Rs2Encoder::class.java) + encoder.protocol = Protocol.LOGIN_DOWNSTREAM_JS5REMOTE + if (msg.build != BUILD) { ctx.write(LoginResponse.ClientOutOfDate).addListener(ChannelFutureListener.CLOSE) return @@ -64,7 +67,7 @@ public class LoginChannelHandler @Inject constructor( ctx.write(LoginResponse.Js5Ok).addListener { future -> if (future.isSuccess) { - ctx.pipeline().remove(Rs2Encoder::class.java) + ctx.pipeline().remove(encoder) ctx.pipeline().remove(this) } } diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt b/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt index ce703b6b10..9de4868599 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt @@ -39,12 +39,27 @@ public class Protocol(vararg codecs: PacketCodec<*>) { RequestWorldListCodec, InitCrossDomainConnectionCodec ) + public val LOGIN_DOWNSTREAM: Protocol = Protocol( + ClientOutOfDateCodec, + ServerFullCodec, + IpLimitCodec + ) + + /** + * Unfortunately the Js5Ok packet's opcode overlaps with the exchange + * session keys opcode - the only case where this happens. We therefore + * have two LOGIN_DOWNSTREAM protocols to avoid ambiguity: one for + * responses to the InitJs5RemoteConnection packet, and one for + * responses to all other login packets. + */ + public val LOGIN_DOWNSTREAM_JS5REMOTE: Protocol = Protocol( Js5OkCodec, ClientOutOfDateCodec, ServerFullCodec, IpLimitCodec ) + public val WORLD_LIST_DOWNSTREAM: Protocol = Protocol( WorldListResponseCodec )