From 851ef8e4e9dcc11e4aea8edad63ceec1c6b7e13e Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 26 Jul 2022 21:19:47 +0100 Subject: [PATCH] Separate LoginResponse and Js5LoginResponse I'm currently working on a CreateResponse class, which is even more distinct from LoginResponse - so I've decided to separate it. For consistency, separating the JS5 login responses seems sensible too. Signed-off-by: Graham --- .../openrs2/archive/cache/OsrsJs5ChannelHandler.kt | 8 ++++---- .../archive/cache/OsrsJs5ChannelInitializer.kt | 6 +++--- .../org/openrs2/game/net/login/LoginChannelHandler.kt | 6 +++--- .../kotlin/org/openrs2/protocol/ProtocolModule.kt | 11 +++++++---- .../js5/downstream/Js5ClientOutOfDateCodec.kt | 10 ++++++++++ .../protocol/js5/downstream/Js5IpLimitCodec.kt | 10 ++++++++++ .../protocol/js5/downstream/Js5LoginResponse.kt | 10 ++++++++++ .../org/openrs2/protocol/js5/downstream/Js5OkCodec.kt | 10 ++++++++++ .../protocol/js5/downstream/Js5ServerFullCodec.kt | 10 ++++++++++ .../openrs2/protocol/login/downstream/Js5OkCodec.kt | 10 ---------- .../protocol/login/downstream/LoginResponse.kt | 1 - 11 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ClientOutOfDateCodec.kt create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5IpLimitCodec.kt create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5LoginResponse.kt create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5OkCodec.kt create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ServerFullCodec.kt delete mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/Js5OkCodec.kt diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelHandler.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelHandler.kt index f5581efa..6e1c082b 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelHandler.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelHandler.kt @@ -6,12 +6,12 @@ import io.netty.channel.ChannelPipeline import org.openrs2.cache.MasterIndexFormat import org.openrs2.protocol.Rs2Decoder import org.openrs2.protocol.Rs2Encoder +import org.openrs2.protocol.js5.downstream.Js5LoginResponse import org.openrs2.protocol.js5.downstream.Js5Response import org.openrs2.protocol.js5.downstream.Js5ResponseDecoder import org.openrs2.protocol.js5.downstream.XorDecoder import org.openrs2.protocol.js5.upstream.Js5Request import org.openrs2.protocol.js5.upstream.Js5RequestEncoder -import org.openrs2.protocol.login.downstream.LoginResponse import org.openrs2.protocol.login.upstream.LoginRequest import kotlin.coroutines.Continuation @@ -66,9 +66,9 @@ public class OsrsJs5ChannelHandler( override fun channelRead0(ctx: ChannelHandlerContext, msg: Any) { when (msg) { - is LoginResponse.Js5Ok -> handleOk(ctx) - is LoginResponse.ClientOutOfDate -> handleClientOutOfDate(ctx) - is LoginResponse -> throw Exception("Invalid response: $msg") + is Js5LoginResponse.Ok -> handleOk(ctx) + is Js5LoginResponse.ClientOutOfDate -> handleClientOutOfDate(ctx) + is Js5LoginResponse -> throw Exception("Invalid response: $msg") is Js5Response -> handleResponse(ctx, msg.prefetch, msg.archive, msg.group, msg.data) else -> throw Exception("Unknown message type: ${msg.javaClass.name}") } 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 64f046fc..3473710a 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/OsrsJs5ChannelInitializer.kt @@ -6,8 +6,8 @@ import io.netty.handler.timeout.ReadTimeoutHandler import org.openrs2.protocol.Protocol import org.openrs2.protocol.Rs2Decoder import org.openrs2.protocol.Rs2Encoder -import org.openrs2.protocol.login.downstream.ClientOutOfDateCodec -import org.openrs2.protocol.login.downstream.Js5OkCodec +import org.openrs2.protocol.js5.downstream.Js5ClientOutOfDateCodec +import org.openrs2.protocol.js5.downstream.Js5OkCodec import org.openrs2.protocol.login.upstream.InitJs5RemoteConnectionCodec public class OsrsJs5ChannelInitializer(private val handler: OsrsJs5ChannelHandler) : ChannelInitializer() { @@ -15,7 +15,7 @@ public class OsrsJs5ChannelInitializer(private val handler: OsrsJs5ChannelHandle ch.pipeline().addLast( ReadTimeoutHandler(30), Rs2Encoder(Protocol(InitJs5RemoteConnectionCodec())), - Rs2Decoder(Protocol(Js5OkCodec(), ClientOutOfDateCodec())) + Rs2Decoder(Protocol(Js5OkCodec(), Js5ClientOutOfDateCodec())) ) 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 c7b745f3..e6c84d98 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 @@ -20,11 +20,11 @@ import org.openrs2.protocol.Protocol import org.openrs2.protocol.Rs2Decoder import org.openrs2.protocol.Rs2Encoder import org.openrs2.protocol.jaggrab.upstream.JaggrabRequestDecoder +import org.openrs2.protocol.js5.downstream.Js5LoginResponse import org.openrs2.protocol.js5.downstream.Js5RemoteDownstream import org.openrs2.protocol.js5.downstream.Js5ResponseEncoder import org.openrs2.protocol.js5.downstream.XorDecoder import org.openrs2.protocol.js5.upstream.Js5RequestDecoder -import org.openrs2.protocol.login.downstream.LoginResponse import org.openrs2.protocol.login.upstream.LoginRequest import org.openrs2.protocol.world.downstream.WorldListDownstream import org.openrs2.protocol.world.downstream.WorldListResponse @@ -59,7 +59,7 @@ public class LoginChannelHandler @Inject constructor( encoder.protocol = js5RemoteDownstreamProtocol if (msg.build != BUILD) { - ctx.write(LoginResponse.ClientOutOfDate).addListener(ChannelFutureListener.CLOSE) + ctx.write(Js5LoginResponse.ClientOutOfDate).addListener(ChannelFutureListener.CLOSE) return } @@ -71,7 +71,7 @@ public class LoginChannelHandler @Inject constructor( ) ctx.pipeline().remove(Rs2Decoder::class.java) - ctx.write(LoginResponse.Js5Ok).addListener { future -> + ctx.write(Js5LoginResponse.Ok).addListener { future -> if (future.isSuccess) { ctx.pipeline().remove(encoder) ctx.pipeline().remove(this) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt b/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt index a0f96a45..e3cd645f 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt @@ -6,10 +6,13 @@ import com.google.inject.TypeLiteral import com.google.inject.multibindings.Multibinder import org.openrs2.buffer.BufferModule import org.openrs2.crypto.CryptoModule +import org.openrs2.protocol.js5.downstream.Js5ClientOutOfDateCodec +import org.openrs2.protocol.js5.downstream.Js5IpLimitCodec +import org.openrs2.protocol.js5.downstream.Js5OkCodec import org.openrs2.protocol.js5.downstream.Js5RemoteDownstream +import org.openrs2.protocol.js5.downstream.Js5ServerFullCodec import org.openrs2.protocol.login.downstream.ClientOutOfDateCodec import org.openrs2.protocol.login.downstream.IpLimitCodec -import org.openrs2.protocol.login.downstream.Js5OkCodec import org.openrs2.protocol.login.downstream.LoginDownstream import org.openrs2.protocol.login.downstream.ServerFullCodec import org.openrs2.protocol.login.upstream.CheckWorldSuitabilityCodec @@ -33,9 +36,9 @@ public object ProtocolModule : AbstractModule() { bindProtocol( Js5RemoteDownstream::class.java, Js5OkCodec::class.java, - ClientOutOfDateCodec::class.java, - ServerFullCodec::class.java, - IpLimitCodec::class.java + Js5ClientOutOfDateCodec::class.java, + Js5ServerFullCodec::class.java, + Js5IpLimitCodec::class.java ) bindProtocol( diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ClientOutOfDateCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ClientOutOfDateCodec.kt new file mode 100644 index 00000000..ad28fee2 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ClientOutOfDateCodec.kt @@ -0,0 +1,10 @@ +package org.openrs2.protocol.js5.downstream + +import org.openrs2.protocol.EmptyPacketCodec +import javax.inject.Singleton + +@Singleton +public class Js5ClientOutOfDateCodec : EmptyPacketCodec( + packet = Js5LoginResponse.ClientOutOfDate, + opcode = 6 +) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5IpLimitCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5IpLimitCodec.kt new file mode 100644 index 00000000..785dffe8 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5IpLimitCodec.kt @@ -0,0 +1,10 @@ +package org.openrs2.protocol.js5.downstream + +import org.openrs2.protocol.EmptyPacketCodec +import javax.inject.Singleton + +@Singleton +public class Js5IpLimitCodec : EmptyPacketCodec( + packet = Js5LoginResponse.IpLimit, + opcode = 9 +) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5LoginResponse.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5LoginResponse.kt new file mode 100644 index 00000000..4de0947a --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5LoginResponse.kt @@ -0,0 +1,10 @@ +package org.openrs2.protocol.js5.downstream + +import org.openrs2.protocol.Packet + +public sealed class Js5LoginResponse : Packet { + public object Ok : Js5LoginResponse() + public object ClientOutOfDate : Js5LoginResponse() + public object ServerFull : Js5LoginResponse() + public object IpLimit : Js5LoginResponse() +} diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5OkCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5OkCodec.kt new file mode 100644 index 00000000..95cfcd01 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5OkCodec.kt @@ -0,0 +1,10 @@ +package org.openrs2.protocol.js5.downstream + +import org.openrs2.protocol.EmptyPacketCodec +import javax.inject.Singleton + +@Singleton +public class Js5OkCodec : EmptyPacketCodec( + packet = Js5LoginResponse.Ok, + opcode = 0 +) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ServerFullCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ServerFullCodec.kt new file mode 100644 index 00000000..24bf31f0 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/downstream/Js5ServerFullCodec.kt @@ -0,0 +1,10 @@ +package org.openrs2.protocol.js5.downstream + +import org.openrs2.protocol.EmptyPacketCodec +import javax.inject.Singleton + +@Singleton +public class Js5ServerFullCodec : EmptyPacketCodec( + packet = Js5LoginResponse.ServerFull, + opcode = 7 +) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/Js5OkCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/Js5OkCodec.kt deleted file mode 100644 index 0d2f02f4..00000000 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/Js5OkCodec.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.openrs2.protocol.login.downstream - -import org.openrs2.protocol.EmptyPacketCodec -import javax.inject.Singleton - -@Singleton -public class Js5OkCodec : EmptyPacketCodec( - packet = LoginResponse.Js5Ok, - opcode = 0 -) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/LoginResponse.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/LoginResponse.kt index f45c07b4..8fa2571a 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/LoginResponse.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/downstream/LoginResponse.kt @@ -3,7 +3,6 @@ package org.openrs2.protocol.login.downstream import org.openrs2.protocol.Packet public sealed class LoginResponse : Packet { - public object Js5Ok : LoginResponse() public object ClientOutOfDate : LoginResponse() public object ServerFull : LoginResponse() public object IpLimit : LoginResponse()