From 3edc5f190775646036b4cdd2920668665fbab3a7 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 13 Jun 2021 12:56:43 +0100 Subject: [PATCH] Add InitGameConnection codec Signed-off-by: Graham --- .../kotlin/org/openrs2/protocol/Protocol.kt | 2 ++ .../protocol/login/InitGameConnectionCodec.kt | 20 +++++++++++++++++++ .../openrs2/protocol/login/LoginRequest.kt | 1 + 3 files changed, 23 insertions(+) create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/login/InitGameConnectionCodec.kt diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt b/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt index 1a7af93435..ce703b6b10 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/Protocol.kt @@ -2,6 +2,7 @@ package org.openrs2.protocol import org.openrs2.protocol.login.ClientOutOfDateCodec import org.openrs2.protocol.login.InitCrossDomainConnectionCodec +import org.openrs2.protocol.login.InitGameConnectionCodec import org.openrs2.protocol.login.InitJaggrabConnectionCodec import org.openrs2.protocol.login.InitJs5RemoteConnectionCodec import org.openrs2.protocol.login.IpLimitCodec @@ -32,6 +33,7 @@ public class Protocol(vararg codecs: PacketCodec<*>) { public companion object { public val LOGIN_UPSTREAM: Protocol = Protocol( + InitGameConnectionCodec, InitJs5RemoteConnectionCodec, InitJaggrabConnectionCodec, RequestWorldListCodec, diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/InitGameConnectionCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/InitGameConnectionCodec.kt new file mode 100644 index 0000000000..2650ebcb56 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/InitGameConnectionCodec.kt @@ -0,0 +1,20 @@ +package org.openrs2.protocol.login + +import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher +import org.openrs2.protocol.PacketCodec + +public object InitGameConnectionCodec : PacketCodec( + opcode = 14, + length = 1, + type = LoginRequest.InitGameConnection::class.java +) { + override fun decode(input: ByteBuf, cipher: StreamCipher): LoginRequest.InitGameConnection { + val usernameHash = input.readUnsignedByte().toInt() + return LoginRequest.InitGameConnection(usernameHash) + } + + override fun encode(input: LoginRequest.InitGameConnection, output: ByteBuf, cipher: StreamCipher) { + output.writeByte(input.usernameHash) + } +} diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/LoginRequest.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/LoginRequest.kt index 81c25b832e..82214ce9f0 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/LoginRequest.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/LoginRequest.kt @@ -3,6 +3,7 @@ package org.openrs2.protocol.login import org.openrs2.protocol.Packet public sealed class LoginRequest : Packet { + public data class InitGameConnection(public val usernameHash: Int) : LoginRequest() public data class InitJs5RemoteConnection(public val build: Int) : LoginRequest() public object InitJaggrabConnection : LoginRequest() public data class RequestWorldList(public val checksum: Int) : LoginRequest()