Don't use LocalDate to represent date of birth in packets

The client's UI makes it easy to submit invalid dates not supported by
LocalDate. Rather than throwing an exception in a codec, it'd be good to
support representing these for:

* Allowing the development of a debugging proxy server that sits between
  the client and game server.

* Making it easier to send the invalid date of birth response to the
  creation request.

We'll still switch to LocalDate as early as possible in the packet
handler in the future.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 2 years ago
parent 650e298bc9
commit 0a99813932
  1. 11
      protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateAccountCodec.kt
  2. 11
      protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/CreateCheckDateOfBirthCountryCodec.kt
  3. 9
      protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/LoginRequest.kt

@ -16,7 +16,6 @@ import org.openrs2.crypto.xteaDecrypt
import org.openrs2.crypto.xteaEncrypt
import org.openrs2.protocol.VariableShortPacketCodec
import org.openrs2.util.Base37
import java.time.LocalDate
import javax.inject.Inject
import javax.inject.Singleton
@ -68,7 +67,9 @@ public class CreateAccountCodec @Inject constructor(
username,
password,
affiliate,
dateOfBirth = LocalDate.of(year, month + 1, day),
year,
month,
day,
country,
email
)
@ -100,10 +101,10 @@ public class CreateAccountCodec @Inject constructor(
plaintext.writeString(input.password)
plaintext.writeInt(xteaKey.k1)
plaintext.writeShort(input.affiliate)
plaintext.writeByte(input.dateOfBirth.dayOfMonth)
plaintext.writeByte(input.dateOfBirth.monthValue - 1)
plaintext.writeByte(input.day)
plaintext.writeByte(input.month)
plaintext.writeInt(xteaKey.k2)
plaintext.writeShort(input.dateOfBirth.year)
plaintext.writeShort(input.year)
plaintext.writeShort(input.country)
plaintext.writeInt(xteaKey.k3)

@ -3,7 +3,6 @@ package org.openrs2.protocol.login.upstream
import io.netty.buffer.ByteBuf
import org.openrs2.crypto.StreamCipher
import org.openrs2.protocol.FixedPacketCodec
import java.time.LocalDate
import javax.inject.Singleton
@Singleton
@ -14,17 +13,17 @@ public class CreateCheckDateOfBirthCountryCodec : FixedPacketCodec<LoginRequest.
) {
override fun decode(input: ByteBuf, cipher: StreamCipher): LoginRequest.CreateCheckDateOfBirthCountry {
val day = input.readUnsignedByte().toInt()
val month = input.readUnsignedByte().toInt() + 1
val month = input.readUnsignedByte().toInt()
val year = input.readUnsignedShort()
val country = input.readUnsignedShort()
return LoginRequest.CreateCheckDateOfBirthCountry(LocalDate.of(year, month, day), country)
return LoginRequest.CreateCheckDateOfBirthCountry(year, month, day, country)
}
override fun encode(input: LoginRequest.CreateCheckDateOfBirthCountry, output: ByteBuf, cipher: StreamCipher) {
output.writeByte(input.dateOfBirth.dayOfMonth)
output.writeByte(input.dateOfBirth.monthValue - 1)
output.writeShort(input.dateOfBirth.year)
output.writeByte(input.day)
output.writeByte(input.month)
output.writeShort(input.year)
output.writeShort(input.country)
}
}

@ -1,14 +1,15 @@
package org.openrs2.protocol.login.upstream
import org.openrs2.protocol.Packet
import java.time.LocalDate
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 CreateCheckDateOfBirthCountry(
public val dateOfBirth: LocalDate,
public val year: Int,
public val month: Int,
public val day: Int,
public val country: Int
) : LoginRequest()
public data class CreateCheckName(public val username: String) : LoginRequest()
@ -20,7 +21,9 @@ public sealed class LoginRequest : Packet {
public val username: String,
public val password: String,
public val affiliate: Int,
public val dateOfBirth: LocalDate,
public val year: Int,
public val month: Int,
public val day: Int,
public val country: Int,
public val email: String
) : LoginRequest()

Loading…
Cancel
Save