From 537b1589281cb897dda03a8224430dd1a7b1c1f7 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 24 Jul 2022 17:26:02 +0100 Subject: [PATCH] Add CREATE_CHECK_NAME packet --- .../org/openrs2/protocol/ProtocolModule.kt | 2 ++ .../login/upstream/CreateCheckNameCodec.kt | 23 +++++++++++++++++++ .../protocol/login/upstream/LoginRequest.kt | 1 + 3 files changed, 26 insertions(+) create mode 100644 protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateCheckNameCodec.kt diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt b/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt index 25c38b7161..6d4a22b73d 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/ProtocolModule.kt @@ -14,6 +14,7 @@ import org.openrs2.protocol.login.downstream.LoginDownstream import org.openrs2.protocol.login.downstream.ServerFullCodec import org.openrs2.protocol.login.upstream.CheckWorldSuitabilityCodec import org.openrs2.protocol.login.upstream.CreateCheckDateOfBirthCountryCodec +import org.openrs2.protocol.login.upstream.CreateCheckNameCodec import org.openrs2.protocol.login.upstream.InitCrossDomainConnectionCodec import org.openrs2.protocol.login.upstream.InitGameConnectionCodec import org.openrs2.protocol.login.upstream.InitJaggrabConnectionCodec @@ -34,6 +35,7 @@ public object ProtocolModule : AbstractModule() { InitJs5RemoteConnectionCodec::class.java, InitJaggrabConnectionCodec::class.java, CreateCheckDateOfBirthCountryCodec::class.java, + CreateCheckNameCodec::class.java, RequestWorldListCodec::class.java, CheckWorldSuitabilityCodec::class.java, InitCrossDomainConnectionCodec::class.java diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateCheckNameCodec.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateCheckNameCodec.kt new file mode 100644 index 0000000000..c3bac27166 --- /dev/null +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateCheckNameCodec.kt @@ -0,0 +1,23 @@ +package org.openrs2.protocol.login.upstream + +import io.netty.buffer.ByteBuf +import org.openrs2.crypto.StreamCipher +import org.openrs2.protocol.PacketCodec +import org.openrs2.util.Base37 +import javax.inject.Singleton + +@Singleton +public class CreateCheckNameCodec : PacketCodec( + type = LoginRequest.CreateCheckName::class.java, + opcode = 21, + length = 8 +) { + override fun decode(input: ByteBuf, cipher: StreamCipher): LoginRequest.CreateCheckName { + val username = Base37.decodeLowerCase(input.readLong()) + return LoginRequest.CreateCheckName(username) + } + + override fun encode(input: LoginRequest.CreateCheckName, output: ByteBuf, cipher: StreamCipher) { + output.writeLong(Base37.encode(input.username)) + } +} diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/LoginRequest.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/LoginRequest.kt index 8468fff8fb..a1b5c62c50 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/LoginRequest.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/LoginRequest.kt @@ -11,6 +11,7 @@ public sealed class LoginRequest : Packet { public val dateOfBirth: LocalDate, public val country: Int ) : LoginRequest() + public data class CreateCheckName(public val username: String) : LoginRequest() public data class RequestWorldList(public val checksum: Int) : LoginRequest() public data class CheckWorldSuitability( public val build: Int,