Make ratelimitEnd optional in LoginResponsePacket and handle null case in serializer
This commit is contained in:
1 parent
c61f5a9e53
commit
b2544750f1
1 file changed
+6
-3
+6
-3
@@ -10,14 +10,17 @@ import java.time.LocalDateTime
|
||||
|
||||
data class LoginResponsePacket(
|
||||
val state: LoginState,
|
||||
val ratelimitEnd: LocalDateTime
|
||||
)
|
||||
val ratelimitEnd: LocalDateTime?
|
||||
) {
|
||||
constructor(state: LoginState) : this(state, null)
|
||||
}
|
||||
|
||||
class LoginResponsePacketSerializer : PacketSerializer<LoginResponsePacket> {
|
||||
override fun serialize(packet: LoginResponsePacket, buffer: ByteBuf) {
|
||||
buffer.writeByte(packet.state.id)
|
||||
val epochSeconds = packet.ratelimitEnd.toEpochSecond(java.time.ZoneOffset.UTC)
|
||||
if (packet.state == LoginState.RATE_LIMITED || packet.state == LoginState.RATE_LIMITED_2FA) {
|
||||
val epochSeconds = packet.ratelimitEnd?.toEpochSecond(java.time.ZoneOffset.UTC)
|
||||
?: throw IllegalArgumentException("ratelimitEnd must be provided for RATE_LIMITED states")
|
||||
buffer.writeLongLE(epochSeconds)
|
||||
}
|
||||
if (packet.state == LoginState.AUTHED) {
|
||||
|
||||
Reference in new issue
Block a user