From f5e18d8540ab9b12cebfe74b02c161539cd4d6ea Mon Sep 17 00:00:00 2001 From: fiereu Date: Fri, 29 Aug 2025 22:12:51 +0200 Subject: [PATCH] Run spotless --- .../de/fiereu/openmmo/common/enums/Arch.kt | 5 +- .../de/fiereu/openmmo/common/enums/Bitness.kt | 5 +- .../fiereu/openmmo/common/enums/LoginState.kt | 50 ++-- .../fiereu/openmmo/common/enums/Platform.kt | 36 +-- protocol.game/build.gradle.kts | 2 +- .../openmmo/protocols/game/GameProtocol.kt | 10 +- .../protocols/game/packets/JoinGamePacket.kt | 250 +++++++++--------- .../openmmo/protocols/tls/LoginProtocol.kt | 39 +-- .../tls/packets/ExistingSessionPacket.kt | 18 +- .../tls/packets/GameServerListPacket.kt | 16 +- .../tls/packets/GameServerNodesPacket.kt | 51 ++-- .../tls/packets/JoinGameServerPacket.kt | 6 +- .../protocols/tls/packets/LoginKickPacket.kt | 17 +- .../tls/packets/LoginResponsePacket.kt | 13 +- .../tls/packets/MfaChallengePacket.kt | 7 +- .../tls/packets/MfaResponsePacket.kt | 6 +- .../packets/RequestGameServerListPacket.kt | 2 +- .../tls/packets/SentCredentialsPacket.kt | 27 +- .../tls/packets/ToSConfirmationPacket.kt | 6 +- .../protocols/tls/packets/ToSPacket.kt | 13 +- .../builders/GameServerListPacketBuilder.kt | 24 +- .../builders/GameServerNodesPacketBuilder.kt | 45 ++-- .../builders/LoginResponsePacketBuilder.kt | 4 +- .../openmmo/protocols/tls/TlsProtocol.kt | 3 +- .../openmmo/protocols/ByteBufExtension.kt | 2 +- .../de/fiereu/openmmo/protocols/Protocol.kt | 1 - server.game/build.gradle.kts | 25 +- .../game/protocol/game/GameProtocolHandler.kt | 4 +- server.login/build.gradle.kts | 13 +- .../protocol/login/LoginProtocolHandler.kt | 46 ++-- .../login/ext/JoinGameServerPacket.kt | 11 +- .../login/ext/LoginRequestPacketExtensions.kt | 6 +- .../RequestGameServerListPacketExtensions.kt | 2 +- 33 files changed, 360 insertions(+), 405 deletions(-) diff --git a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Arch.kt b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Arch.kt index 286c65d..1382faa 100644 --- a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Arch.kt +++ b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Arch.kt @@ -8,7 +8,8 @@ enum class Arch { companion object { fun from(ordinal: Int): Arch { - return entries.firstOrNull { it.ordinal == ordinal } ?: throw IllegalArgumentException("Unknown arch: $ordinal") + return entries.firstOrNull { it.ordinal == ordinal } + ?: throw IllegalArgumentException("Unknown arch: $ordinal") } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Bitness.kt b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Bitness.kt index d67093a..62a007d 100644 --- a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Bitness.kt +++ b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Bitness.kt @@ -7,7 +7,8 @@ enum class Bitness { companion object { fun from(ordinal: Int): Bitness { - return entries.firstOrNull { it.ordinal == ordinal } ?: throw IllegalArgumentException("Unknown bitness: $ordinal") + return entries.firstOrNull { it.ordinal == ordinal } + ?: throw IllegalArgumentException("Unknown bitness: $ordinal") } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/LoginState.kt b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/LoginState.kt index 9aec8c9..40d94f1 100644 --- a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/LoginState.kt +++ b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/LoginState.kt @@ -1,28 +1,28 @@ package de.fiereu.openmmo.common.enums enum class LoginState(val id: Int) { - AUTHED(0), - SYSTEM_ERROR(1), - INVALID_PASSWORD(2), - AUTHED_HALF(3), - NO_GS_AVAILABLE(6), - ALREADY_LOGGED_IN(7), - SERVER_DOWN(8), - ACCOUNT_ISSUE(9), - GM_ONLY(16), - BAN_IP(22), - RATE_LIMITED(23), - ERROR_CONNECTING_AUTH_SERVER(24), - INVALID_TOS_REVSION(25), - BLOCKLIST_IP(26), - ANDROID_ALPHA_PERMISSION(27), - BLOCKLIST_IP_RANGE(28), - ERROR_CONNECTING_GAME_SERVER(29), - INVALID_SAVED_CREDENTIALS(30), - ERROR_CONNECTING_FIREWALL(31), - RATE_LIMITED_2FA(32), - WRONG_CODE_2FA(33), - CLIENT_OUT_OF_DATE(34), - EXTRA_VALIDATION_FAILED(35), - REQUIRE_QQ_FOR_ACCOUNT(36); -} \ No newline at end of file + AUTHED(0), + SYSTEM_ERROR(1), + INVALID_PASSWORD(2), + AUTHED_HALF(3), + NO_GS_AVAILABLE(6), + ALREADY_LOGGED_IN(7), + SERVER_DOWN(8), + ACCOUNT_ISSUE(9), + GM_ONLY(16), + BAN_IP(22), + RATE_LIMITED(23), + ERROR_CONNECTING_AUTH_SERVER(24), + INVALID_TOS_REVSION(25), + BLOCKLIST_IP(26), + ANDROID_ALPHA_PERMISSION(27), + BLOCKLIST_IP_RANGE(28), + ERROR_CONNECTING_GAME_SERVER(29), + INVALID_SAVED_CREDENTIALS(30), + ERROR_CONNECTING_FIREWALL(31), + RATE_LIMITED_2FA(32), + WRONG_CODE_2FA(33), + CLIENT_OUT_OF_DATE(34), + EXTRA_VALIDATION_FAILED(35), + REQUIRE_QQ_FOR_ACCOUNT(36) +} diff --git a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Platform.kt b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Platform.kt index 798e81a..3c12cce 100644 --- a/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Platform.kt +++ b/common/src/main/kotlin/de/fiereu/openmmo/common/enums/Platform.kt @@ -1,23 +1,23 @@ package de.fiereu.openmmo.common.enums enum class Platform { - WINDOWS, - LINUX, - MACOS, - ANDROID, - IOS, - UNKNOWN; + WINDOWS, + LINUX, + MACOS, + ANDROID, + IOS, + UNKNOWN; - companion object { - fun from(value: Int): Platform { - return when (value) { - 0x00 -> WINDOWS - 0x01 -> LINUX - 0x02 -> MACOS - 0x03 -> IOS - 0x04 -> ANDROID - else -> UNKNOWN - } - } + companion object { + fun from(value: Int): Platform { + return when (value) { + 0x00 -> WINDOWS + 0x01 -> LINUX + 0x02 -> MACOS + 0x03 -> IOS + 0x04 -> ANDROID + else -> UNKNOWN + } } -} \ No newline at end of file + } +} diff --git a/protocol.game/build.gradle.kts b/protocol.game/build.gradle.kts index bbdb9a3..025b0dd 100644 --- a/protocol.game/build.gradle.kts +++ b/protocol.game/build.gradle.kts @@ -8,4 +8,4 @@ dependencies { api(project(":common")) testImplementation(libs.bundles.kotest) -} \ No newline at end of file +} diff --git a/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/GameProtocol.kt b/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/GameProtocol.kt index 711b3e7..49caea0 100644 --- a/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/GameProtocol.kt +++ b/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/GameProtocol.kt @@ -1,15 +1,15 @@ package de.fiereu.openmmo.protocols.game import de.fiereu.openmmo.protocols.Protocol -import de.fiereu.openmmo.protocols.incomingPacket -import de.fiereu.openmmo.protocols.outgoingPacket import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket import de.fiereu.openmmo.protocols.game.packets.JoinPacketDeserializer import de.fiereu.openmmo.protocols.game.packets.JoinPacketSerializer +import de.fiereu.openmmo.protocols.incomingPacket +import de.fiereu.openmmo.protocols.outgoingPacket /** - * Game Protocol implementation. This protocol handles in-game communication after the TLS handshake is - * complete. + * Game Protocol implementation. This protocol handles in-game communication after the TLS handshake + * is complete. */ abstract class GameProtocol : Protocol() { override val async: Boolean @@ -26,4 +26,4 @@ class GameClientProtocol : GameProtocol() { init { outgoingPacket(0x01u, JoinPacketSerializer(), JoinGamePacket::class) } -} \ No newline at end of file +} diff --git a/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/packets/JoinGamePacket.kt b/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/packets/JoinGamePacket.kt index dc286a6..f655a1b 100644 --- a/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/packets/JoinGamePacket.kt +++ b/protocol.game/src/main/kotlin/de/fiereu/openmmo/protocols/game/packets/JoinGamePacket.kt @@ -9,28 +9,22 @@ import de.fiereu.openmmo.protocols.readUtf16LE import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf -data class RomInfo( - val code: String, - val id: Byte, - val type: Byte -) +data class RomInfo(val code: String, val id: Byte, val type: Byte) abstract class GameAuthenticationData /** - * Used when a player reconnects to the game server after a disconnection. - * This data typically includes the player's unique identifier and a session key - * that was issued by the login server to re-establish the session. + * Used when a player reconnects to the game server after a disconnection. This data typically + * includes the player's unique identifier and a session key that was issued by the login server to + * re-establish the session. */ -data class ReconnectAuthData( - val playerId: Long, - val sessionKey: ByteArray -) : GameAuthenticationData() +data class ReconnectAuthData(val playerId: Long, val sessionKey: ByteArray) : + GameAuthenticationData() /** - * Used when a player is joining the game server for the first time after logging in. - * This data typically includes the user's unique identifier and a session key - * that was issued by the login server to authenticate the session. + * Used when a player is joining the game server for the first time after logging in. This data + * typically includes the user's unique identifier and a session key that was issued by the login + * server to authenticate the session. */ data class NewAuthData( val userId: Int, @@ -55,123 +49,125 @@ data class JoinGamePacket( ) class JoinPacketSerializer : PacketSerializer { - override fun serialize(packet: JoinGamePacket, buffer: ByteBuf) { - when (packet.authData) { - is NewAuthData -> { - buffer.writeByte(0x00) - buffer.writeIntLE(packet.authData.userId) - buffer.writeByte(packet.authData.sessionKey.size) - buffer.writeBytes(packet.authData.sessionKey) - } - is ReconnectAuthData -> { - buffer.writeByte(0x01) - buffer.writeLongLE(packet.authData.playerId) - buffer.writeByte(packet.authData.sessionKey.size) - buffer.writeBytes(packet.authData.sessionKey) - } - else -> throw IllegalArgumentException("Unsupported authentication data type: ${packet.authData::class.simpleName}") - } - buffer.writeBytes(packet.mac) - buffer.writeIntLE(packet.clientRevision) - buffer.writeIntLE(packet.installationRevision) - buffer.writeByte(packet.currentChatLanguage.toInt()) - buffer.writeShortLE(packet.chatLanguages.toInt()) - buffer.writeShortLE(packet.matchmakingLanguages.toInt()) - buffer.writeByte(packet.romMask.toInt()) - - buffer.writeByte(packet.roms.size) - for (rom in packet.roms) { - buffer.writeUtf16LE(rom.code) - buffer.writeByte(rom.id.toInt()) - buffer.writeByte(rom.type.toInt()) - } - - buffer.writeByte(packet.clientInfo.size) - for ((key, value) in packet.clientInfo) { - buffer.writeByte(key.toInt()) - buffer.writeUtf16LE(value) - } - - buffer.writeByte(packet.platform.ordinal) - buffer.writeByte(packet.arch.ordinal) - buffer.writeByte(packet.bitness.ordinal) - - buffer.writeByte(packet.unk1.size) - buffer.writeBytes(packet.unk1) + override fun serialize(packet: JoinGamePacket, buffer: ByteBuf) { + when (packet.authData) { + is NewAuthData -> { + buffer.writeByte(0x00) + buffer.writeIntLE(packet.authData.userId) + buffer.writeByte(packet.authData.sessionKey.size) + buffer.writeBytes(packet.authData.sessionKey) + } + is ReconnectAuthData -> { + buffer.writeByte(0x01) + buffer.writeLongLE(packet.authData.playerId) + buffer.writeByte(packet.authData.sessionKey.size) + buffer.writeBytes(packet.authData.sessionKey) + } + else -> + throw IllegalArgumentException( + "Unsupported authentication data type: ${packet.authData::class.simpleName}") } + buffer.writeBytes(packet.mac) + buffer.writeIntLE(packet.clientRevision) + buffer.writeIntLE(packet.installationRevision) + buffer.writeByte(packet.currentChatLanguage.toInt()) + buffer.writeShortLE(packet.chatLanguages.toInt()) + buffer.writeShortLE(packet.matchmakingLanguages.toInt()) + buffer.writeByte(packet.romMask.toInt()) + + buffer.writeByte(packet.roms.size) + for (rom in packet.roms) { + buffer.writeUtf16LE(rom.code) + buffer.writeByte(rom.id.toInt()) + buffer.writeByte(rom.type.toInt()) + } + + buffer.writeByte(packet.clientInfo.size) + for ((key, value) in packet.clientInfo) { + buffer.writeByte(key.toInt()) + buffer.writeUtf16LE(value) + } + + buffer.writeByte(packet.platform.ordinal) + buffer.writeByte(packet.arch.ordinal) + buffer.writeByte(packet.bitness.ordinal) + + buffer.writeByte(packet.unk1.size) + buffer.writeBytes(packet.unk1) + } } class JoinPacketDeserializer : PacketDeserializer { - override fun deserialize(buffer: ByteBuf): JoinGamePacket { - val authOption = buffer.readByte() - val authenticationData = when (authOption) { - 0x00.toByte() -> { - val userId = buffer.readIntLE() - val sessionKeyLength = buffer.readUnsignedByte().toInt() - val sessionKey = ByteArray(sessionKeyLength) - buffer.readBytes(sessionKey) - NewAuthData(userId, sessionKey) - } - 0x01.toByte() -> { - val playerId = buffer.readLongLE() - val sessionKeyLength = buffer.readUnsignedByte().toInt() - val sessionKey = ByteArray(sessionKeyLength) - buffer.readBytes(sessionKey) - ReconnectAuthData(playerId, sessionKey) - } - else -> throw IllegalArgumentException("Unsupported authentication option: $authOption") + override fun deserialize(buffer: ByteBuf): JoinGamePacket { + val authOption = buffer.readByte() + val authenticationData = + when (authOption) { + 0x00.toByte() -> { + val userId = buffer.readIntLE() + val sessionKeyLength = buffer.readUnsignedByte().toInt() + val sessionKey = ByteArray(sessionKeyLength) + buffer.readBytes(sessionKey) + NewAuthData(userId, sessionKey) + } + 0x01.toByte() -> { + val playerId = buffer.readLongLE() + val sessionKeyLength = buffer.readUnsignedByte().toInt() + val sessionKey = ByteArray(sessionKeyLength) + buffer.readBytes(sessionKey) + ReconnectAuthData(playerId, sessionKey) + } + else -> throw IllegalArgumentException("Unsupported authentication option: $authOption") } - - val mac = ByteArray(6) - buffer.readBytes(mac) - - val clientRevision = buffer.readIntLE() - val installationRevision = buffer.readIntLE() - val currentChatLanguage = buffer.readByte() - val chatLanguages = buffer.readShortLE() - val ignoreLanguages = buffer.readShortLE() - val romMask = buffer.readByte() - - val romCount = buffer.readUnsignedByte().toInt() - val roms = mutableListOf() - for (i in 0 until romCount) { - val code = buffer.readUtf16LE() - val id = buffer.readByte() - val type = buffer.readByte() - roms.add(RomInfo(code, id, type)) - } - - val clientInfoCount = buffer.readUnsignedByte().toInt() - val clientInfo = mutableMapOf() - for (i in 0 until clientInfoCount) { - val key = buffer.readByte() - val value = buffer.readUtf16LE() - clientInfo[key] = value - } - - val platform = Platform.from(buffer.readByte().toInt()) - val arch = Arch.from(buffer.readByte().toInt()) - val bitness = Bitness.from(buffer.readByte().toInt()) - val unk1 = buffer.readByte().toInt() - val unk2 = ByteArray(unk1) - buffer.readBytes(unk2) - - return JoinGamePacket( - authenticationData, - mac, - clientRevision, - installationRevision, - currentChatLanguage, - chatLanguages, - ignoreLanguages, - romMask, - roms, - clientInfo, - platform, - arch, - bitness, - unk2 - ) + val mac = ByteArray(6) + buffer.readBytes(mac) + + val clientRevision = buffer.readIntLE() + val installationRevision = buffer.readIntLE() + val currentChatLanguage = buffer.readByte() + val chatLanguages = buffer.readShortLE() + val ignoreLanguages = buffer.readShortLE() + val romMask = buffer.readByte() + + val romCount = buffer.readUnsignedByte().toInt() + val roms = mutableListOf() + for (i in 0 until romCount) { + val code = buffer.readUtf16LE() + val id = buffer.readByte() + val type = buffer.readByte() + roms.add(RomInfo(code, id, type)) } + + val clientInfoCount = buffer.readUnsignedByte().toInt() + val clientInfo = mutableMapOf() + for (i in 0 until clientInfoCount) { + val key = buffer.readByte() + val value = buffer.readUtf16LE() + clientInfo[key] = value + } + + val platform = Platform.from(buffer.readByte().toInt()) + val arch = Arch.from(buffer.readByte().toInt()) + val bitness = Bitness.from(buffer.readByte().toInt()) + + val unk1 = buffer.readByte().toInt() + val unk2 = ByteArray(unk1) + buffer.readBytes(unk2) + + return JoinGamePacket( + authenticationData, + mac, + clientRevision, + installationRevision, + currentChatLanguage, + chatLanguages, + ignoreLanguages, + romMask, + roms, + clientInfo, + platform, + arch, + bitness, + unk2) + } } diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt index 3bacaae..57fcab3 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt @@ -3,45 +3,45 @@ package de.fiereu.openmmo.protocols.tls import de.fiereu.openmmo.protocols.Protocol import de.fiereu.openmmo.protocols.incomingPacket import de.fiereu.openmmo.protocols.outgoingPacket +import de.fiereu.openmmo.protocols.tls.packets.ExistingSessionPacket +import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacket +import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacket import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketSerializer +import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacket +import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacket import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket -import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacket -import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacket -import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacket -import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacket -import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacket import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketSerializer import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacket import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketSerializer +import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket +import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketSerializer +import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacket +import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer +import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer +import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacket +import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketSerializer import de.fiereu.openmmo.protocols.tls.packets.ToSPacket import de.fiereu.openmmo.protocols.tls.packets.ToSPacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer -import de.fiereu.openmmo.protocols.tls.packets.ExistingSessionPacket -import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer -import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer /** * Login Protocol implementation. This protocol handles the login process after the TLS handshake is @@ -73,7 +73,8 @@ class LoginServerProtocol() : LoginProtocol() { class LoginClientProtocol() : LoginProtocol() { init { incomingPacket(0x01u, LoginResponsePacketDeserializer()) - outgoingPacket(0x02u, RequestGameServerListPacketSerializer(), RequestGameServerListPacket::class) + outgoingPacket( + 0x02u, RequestGameServerListPacketSerializer(), RequestGameServerListPacket::class) outgoingPacket(0x03u, JoinGameServerPacketSerializer(), JoinGameServerPacket::class) incomingPacket(0x03u, GameServerNodesPacketDeserializer()) outgoingPacket(0x04u, ToSConfirmationPacketSerializer(), ToSConfirmationPacket::class) diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ExistingSessionPacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ExistingSessionPacket.kt index f29dde7..7f0bbe8 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ExistingSessionPacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ExistingSessionPacket.kt @@ -4,16 +4,16 @@ import com.github.maltalex.ineter.base.IPv4Address import com.github.maltalex.ineter.base.IPv6Address import de.fiereu.openmmo.protocols.PacketDeserializer import de.fiereu.openmmo.protocols.PacketSerializer -import de.fiereu.openmmo.protocols.readUtf16LE -import de.fiereu.openmmo.protocols.writeUtf16LE -import de.fiereu.openmmo.protocols.writeIpLE import de.fiereu.openmmo.protocols.readIpLE +import de.fiereu.openmmo.protocols.readUtf16LE +import de.fiereu.openmmo.protocols.writeIpLE +import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf data class ExistingSessionPacket( - val sessionId: Long, - val sessionKey: ByteArray, - val serverName: String + val sessionId: Long, + val sessionKey: ByteArray, + val serverName: String ) { override fun equals(other: Any?): Boolean { if (this === other) return true @@ -76,10 +76,10 @@ class SentExistingSessionPacketDeserializer : PacketDeserializer -) +data class GameServerListPacket(val gameServers: List) class GameServerListPacketSerializer : PacketSerializer { override fun serialize(packet: GameServerListPacket, buffer: ByteBuf) { @@ -46,7 +44,7 @@ class GameServerListPacketSerializer : PacketSerializer { class GameServerListPacketDeserializer : PacketDeserializer { override fun deserialize(buffer: ByteBuf): GameServerListPacket { val serverCount = buffer.readUnsignedByte().toInt() - + if (serverCount == 0) { buffer.readByte() // skip first server id (0) buffer.readByte() // skip second byte (0) diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/GameServerNodesPacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/GameServerNodesPacket.kt index 5b91cfe..7e6763d 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/GameServerNodesPacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/GameServerNodesPacket.kt @@ -13,32 +13,31 @@ import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf /** - * Nodes are address entries for game servers that the client can connect to. - * The nodes are selected by a weighted random algorithm on the client side. - * The weight is a value between 0 and 255, where 0 means the node - * will never be selected and 255 means the node will always be selected. + * Nodes are address entries for game servers that the client can connect to. The nodes are selected + * by a weighted random algorithm on the client side. The weight is a value between 0 and 255, where + * 0 means the node will never be selected and 255 means the node will always be selected. * Typically, nodes are assigned weights based on their capacity or priority. */ data class GameServerNode( - val iPv4Address: IPv4Address, - val iPv6Address: IPv6Address, - val port: UShort = 7777u, - val weight: UByte + val iPv4Address: IPv4Address, + val iPv6Address: IPv6Address, + val port: UShort = 7777u, + val weight: UByte ) data class GameServerData( - val gameServerId: UByte, - val userId: Int, - val sessionToken: ByteArray, - val localAddress: IPAddress, - val localHostname: String, - val port: UShort, + val gameServerId: UByte, + val userId: Int, + val sessionToken: ByteArray, + val localAddress: IPAddress, + val localHostname: String, + val port: UShort, ) data class GameServerNodesPacket( - val loginState: LoginState, - val gameServerData: GameServerData? = null, - val nodes: List = emptyList() + val loginState: LoginState, + val gameServerData: GameServerData? = null, + val nodes: List = emptyList() ) class GameServerNodesPacketSerializer : PacketSerializer { @@ -48,7 +47,8 @@ class GameServerNodesPacketSerializer : PacketSerializer return } - val gsd = requireNotNull(packet.gameServerData) { "GameServerData must be provided for AUTHED state" } + val gsd = + requireNotNull(packet.gameServerData) { "GameServerData must be provided for AUTHED state" } buffer.writeIntLE(gsd.userId) buffer.writeByte(gsd.sessionToken.size) @@ -115,17 +115,8 @@ class GameServerNodesPacketDeserializer : PacketDeserializer { override fun serialize(packet: JoinGameServerPacket, buffer: ByteBuf) { @@ -19,4 +17,4 @@ class JoinGameServerPacketDeserializer : PacketDeserializer { override fun serialize(packet: LoginKickPacket, buffer: ByteBuf) { @@ -68,8 +66,9 @@ class LoginKickPacketDeserializer : PacketDeserializer { } val reasonOrdinal = buffer.readUnsignedByte().toInt() - val reason = KickReason.entries.getOrNull(reasonOrdinal) - ?: throw IllegalArgumentException("Unknown kick reason: $reasonOrdinal") + val reason = + KickReason.entries.getOrNull(reasonOrdinal) + ?: throw IllegalArgumentException("Unknown kick reason: $reasonOrdinal") when (reason) { KickReason.A -> { @@ -103,4 +102,4 @@ class LoginKickPacketDeserializer : PacketDeserializer { return LoginKickPacket(reason) } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginResponsePacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginResponsePacket.kt index a5d978c..f1cdb30 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginResponsePacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginResponsePacket.kt @@ -8,10 +8,7 @@ import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf import java.time.LocalDateTime -data class LoginResponsePacket( - val state: LoginState, - val ratelimitEnd: LocalDateTime? -) { +data class LoginResponsePacket(val state: LoginState, val ratelimitEnd: LocalDateTime?) { constructor(state: LoginState) : this(state, null) } @@ -19,8 +16,10 @@ class LoginResponsePacketSerializer : PacketSerializer { override fun serialize(packet: LoginResponsePacket, buffer: ByteBuf) { buffer.writeByte(packet.state.id) 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") + 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) { @@ -45,4 +44,4 @@ class LoginResponsePacketDeserializer : PacketDeserializer return LoginResponsePacket(state, ratelimitEnd) } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaChallengePacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaChallengePacket.kt index e735960..2c3be78 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaChallengePacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaChallengePacket.kt @@ -6,10 +6,7 @@ import de.fiereu.openmmo.protocols.readUtf16LE import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf -data class MfaChallengePacket( - val unk: Byte, - val email: String -) +data class MfaChallengePacket(val unk: Byte, val email: String) class MfaChallengePacketSerializer : PacketSerializer { override fun serialize(packet: MfaChallengePacket, buffer: ByteBuf) { @@ -24,4 +21,4 @@ class MfaChallengePacketDeserializer : PacketDeserializer { val email = buffer.readUtf16LE() return MfaChallengePacket(unk, email) } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaResponsePacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaResponsePacket.kt index 92f2044..ecf46f3 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaResponsePacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/MfaResponsePacket.kt @@ -6,9 +6,7 @@ import de.fiereu.openmmo.protocols.readUtf16LE import de.fiereu.openmmo.protocols.writeUtf16LE import io.netty.buffer.ByteBuf -data class MfaResponsePacket( - val mfaCode: String -) +data class MfaResponsePacket(val mfaCode: String) class MfaResponsePacketSerializer : PacketSerializer { override fun serialize(packet: MfaResponsePacket, buffer: ByteBuf) { @@ -21,4 +19,4 @@ class MfaResponsePacketDeserializer : PacketDeserializer { val mfaCode = buffer.readUtf16LE() return MfaResponsePacket(mfaCode) } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/RequestGameServerListPacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/RequestGameServerListPacket.kt index 56b976f..c48e6b8 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/RequestGameServerListPacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/RequestGameServerListPacket.kt @@ -17,4 +17,4 @@ class RequestGameServerListPacketDeserializer : PacketDeserializer { override fun serialize(packet: ToSConfirmationPacket, buffer: ByteBuf) { @@ -19,4 +17,4 @@ class ToSConfirmationPacketDeserializer : PacketDeserializer { override fun serialize(packet: ToSPacket, buffer: ByteBuf) { buffer.writeByte(packet.confirmationKey.toInt()) - + val compressedText = compressString(packet.tosText) buffer.writeShortLE(compressedText.size) buffer.writeBytes(compressedText) @@ -38,7 +35,7 @@ class ToSPacketDeserializer : PacketDeserializer { val tosLength = buffer.readUnsignedShortLE() val compressedTosText = ByteArray(tosLength) buffer.readBytes(compressedTosText) - + val decompressedText = decompressBytes(compressedTosText) return ToSPacket(confirmationKey, decompressedText) } @@ -49,4 +46,4 @@ class ToSPacketDeserializer : PacketDeserializer { String(gzipIn.readAllBytes(), StandardCharsets.UTF_8) } } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerListPacketBuilder.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerListPacketBuilder.kt index 9c45d74..a89412a 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerListPacketBuilder.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerListPacketBuilder.kt @@ -5,32 +5,32 @@ import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacket class GameServerListPacketBuilder { private val servers = mutableListOf() - + companion object { fun create(): GameServerListPacketBuilder = GameServerListPacketBuilder() - + fun withServers(servers: List): GameServerListPacket { return GameServerListPacket(servers) } - + fun empty(): GameServerListPacket = GameServerListPacket(emptyList()) } - + fun addServer( - id: UByte, - name: String, - currentPlayers: UShort = 0u, - maxPlayers: UShort = 0u, - joinable: Boolean = true + id: UByte, + name: String, + currentPlayers: UShort = 0u, + maxPlayers: UShort = 0u, + joinable: Boolean = true ): GameServerListPacketBuilder { servers.add(GameServer(id, name, currentPlayers, maxPlayers, joinable)) return this } - + fun addServer(server: GameServer): GameServerListPacketBuilder { servers.add(server) return this } - + fun build(): GameServerListPacket = GameServerListPacket(servers.toList()) -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerNodesPacketBuilder.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerNodesPacketBuilder.kt index 6e229a2..5f6e354 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerNodesPacketBuilder.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/GameServerNodesPacketBuilder.kt @@ -12,57 +12,48 @@ class GameServerNodesPacketBuilder { require(loginState != LoginState.AUTHED) { "Use forAuthedUser() for AUTHED state" } return GameServerNodesPacket(loginState) } - + fun forAuthedUser( - userId: Int, - sessionToken: ByteArray, - gameServerId: UByte + userId: Int, + sessionToken: ByteArray, + gameServerId: UByte ): AuthedPacketBuilder { return AuthedPacketBuilder(userId, sessionToken, gameServerId) } } } -class AuthedPacketBuilder internal constructor( - private val userId: Int, - private val sessionToken: ByteArray, - private val gameServerId: UByte +class AuthedPacketBuilder +internal constructor( + private val userId: Int, + private val sessionToken: ByteArray, + private val gameServerId: UByte ) { private var localAddress: IPAddress? = null private var localHostname: String? = null private var port: UShort? = null private var nodes: List = emptyList() - - fun withLocalEndpoint( - address: IPAddress, - hostname: String, - port: UShort - ): AuthedPacketBuilder { + + fun withLocalEndpoint(address: IPAddress, hostname: String, port: UShort): AuthedPacketBuilder { this.localAddress = address this.localHostname = hostname this.port = port return this } - + fun withNodes(nodes: List): AuthedPacketBuilder { this.nodes = nodes return this } - + fun build(): GameServerNodesPacket { requireNotNull(localAddress) { "Local address must be set for AUTHED packets" } requireNotNull(localHostname) { "Local hostname must be set for AUTHED packets" } requireNotNull(port) { "Port must be set for AUTHED packets" } - - val gameServerData = GameServerData( - gameServerId, - userId, - sessionToken, - localAddress!!, - localHostname!!, - port!! - ) - + + val gameServerData = + GameServerData(gameServerId, userId, sessionToken, localAddress!!, localHostname!!, port!!) + return GameServerNodesPacket(LoginState.AUTHED, gameServerData, nodes) } -} \ No newline at end of file +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/LoginResponsePacketBuilder.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/LoginResponsePacketBuilder.kt index 2dc9cca..3823736 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/LoginResponsePacketBuilder.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/builders/LoginResponsePacketBuilder.kt @@ -12,7 +12,7 @@ class LoginResponsePacketBuilder { } return LoginResponsePacket(state) } - + fun withRateLimit(state: LoginState, ratelimitEnd: LocalDateTime): LoginResponsePacket { require(state == LoginState.RATE_LIMITED || state == LoginState.RATE_LIMITED_2FA) { "Rate limit end time can only be used with RATE_LIMITED states" @@ -20,4 +20,4 @@ class LoginResponsePacketBuilder { return LoginResponsePacket(state, ratelimitEnd) } } -} \ No newline at end of file +} diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt index 6ca9e60..55db2e1 100644 --- a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt @@ -30,8 +30,7 @@ class TlsServerProtocol(serverKeyPair: Pair) : TlsPro init { incomingPacket(0x00u, ClientHelloPacketDeserializer()) outgoingPacket( - 0x01u, ServerHelloPacketSerializer(serverKeyPair.first), ServerHelloPacket::class - ) + 0x01u, ServerHelloPacketSerializer(serverKeyPair.first), ServerHelloPacket::class) incomingPacket(0x02u, ClientReadyPacketDeserializer()) } } diff --git a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt index edecfbd..fe6d95d 100644 --- a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt @@ -74,4 +74,4 @@ fun ByteBuf.readIpRangeLE(): Pair { fun ByteBuf.writeIpRangeLE(start: IPAddress, end: IPAddress) { writeIpLE(start) writeIpLE(end) -} \ No newline at end of file +} diff --git a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt index 0dc7e33..730092f 100644 --- a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt @@ -3,7 +3,6 @@ package de.fiereu.openmmo.protocols import io.github.oshai.kotlinlogging.KotlinLogging import io.netty.buffer.ByteBuf import kotlin.reflect.KClass -import kotlin.reflect.jvm.jvmErasure /** Value class wrapping a UByte to represent an opcode. */ @JvmInline diff --git a/server.game/build.gradle.kts b/server.game/build.gradle.kts index 9f0e486..ef16a8a 100644 --- a/server.game/build.gradle.kts +++ b/server.game/build.gradle.kts @@ -30,13 +30,12 @@ dependencies { application { mainClass.set("de.fiereu.openmmo.server.game.GameServerKt") } - fun env(key: String): Any { val value = - property(key) - ?: System.getenv(key) - ?: throw IllegalArgumentException( - "Environment variable or system property '$key' is not set.") + property(key) + ?: System.getenv(key) + ?: throw IllegalArgumentException( + "Environment variable or system property '$key' is not set.") fun interpolate(value: String): Any { val PATTERN_WORD = Regex("\\$([a-zA-Z0-9_]+)") val PATTERN_MULTI = Regex("\\$\\{([a-zA-Z0-9_]+)\\}") @@ -47,7 +46,7 @@ fun env(key: String): Any { val envValue = System.getProperty(envName) ?: System.getProperty(envName) if (envValue == null) { throw IllegalArgumentException( - "Environment variable or system property '$envName' is not set.") + "Environment variable or system property '$envName' is not set.") } acc.replace(match.value, envValue) } @@ -75,7 +74,7 @@ jooq { name = "org.jooq.meta.postgres.PostgresDatabase" includes = ".*" excludes = - """ + """ flyway_schema_history | pgp_armor_headers """ @@ -116,9 +115,9 @@ tasks.register("cleanMigrateAndGenerate") { spotless { kotlin { targetExclude("src/main/jooq/**") } } // If someone knows a better way then this please please please help me :( -listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc").forEach { taskName -> - tasks.named(taskName) { - listOf("copyPublicKeyGame", "copyPrivateKeyGame") - .forEach { dependsOn(it) } - } -} +listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc") + .forEach { taskName -> + tasks.named(taskName) { + listOf("copyPublicKeyGame", "copyPrivateKeyGame").forEach { dependsOn(it) } + } + } diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/protocol/game/GameProtocolHandler.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/protocol/game/GameProtocolHandler.kt index 7f7f0a7..9f30cec 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/protocol/game/GameProtocolHandler.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/protocol/game/GameProtocolHandler.kt @@ -32,7 +32,9 @@ class GameProtocolHandler( fun onJoinGame(event: PacketEvent) { log.info { "Player joined the game." } - log.debug { "This is what the Game knows about you:\n${event.packet.clientInfo.values.joinToString("\n")}" } + log.debug { + "This is what the Game knows about you:\n${event.packet.clientInfo.values.joinToString("\n")}" + } // TODO handle player joining the game } } diff --git a/server.login/build.gradle.kts b/server.login/build.gradle.kts index 42da5f6..98f4ef5 100644 --- a/server.login/build.gradle.kts +++ b/server.login/build.gradle.kts @@ -123,10 +123,9 @@ tasks.register("cleanMigrateAndGenerate") { spotless { kotlin { targetExclude("src/main/jooq/**") } } // If someone knows a better way then this please please please help me :( -listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc").forEach { taskName -> - tasks.named(taskName) { - listOf("copyPublicKeyGame", "copyPrivateKeyGame") - .forEach { dependsOn(it) } - } -} - +listOf("classes", "processResources", "spotlessKotlin", "spotlessKotlinGradle", "spotlessMisc") + .forEach { taskName -> + tasks.named(taskName) { + listOf("copyPublicKeyGame", "copyPrivateKeyGame").forEach { dependsOn(it) } + } + } diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt index 58504f5..c51593b 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt @@ -10,10 +10,10 @@ import de.fiereu.openmmo.protocols.tls.packets.GameServerNode import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket -import de.fiereu.openmmo.server.login.protocol.login.ext.respondTo import de.fiereu.openmmo.server.login.protocol.login.ext.respondForAuthedUser -import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithState +import de.fiereu.openmmo.server.login.protocol.login.ext.respondTo import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithServers +import de.fiereu.openmmo.server.login.protocol.login.ext.respondWithState import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler import de.fiereu.openmmo.server.protocol.PacketEvent import io.github.oshai.kotlinlogging.KotlinLogging @@ -37,7 +37,8 @@ class LoginProtocolHandler( coroutineScope.launch { when (event.packet) { is LoginRequestPacket -> onLoginRequest(event as PacketEvent) - is RequestGameServerListPacket -> onGameServerListRequest(event as PacketEvent) + is RequestGameServerListPacket -> + onGameServerListRequest(event as PacketEvent) is JoinGameServerPacket -> onServerSelection(event as PacketEvent) else -> log.warn { "Unhandled login packet type: ${event.packet::class.simpleName}" } } @@ -53,32 +54,27 @@ class LoginProtocolHandler( fun onGameServerListRequest(event: PacketEvent) { log.info { "Received game server list request" } // TODO replace hardcoded server list with actual server list from database or config - event.respondWithServers(listOf( - GameServer(0x00u, "OpenMMO", 0u, 1u, true) - )) + event.respondWithServers(listOf(GameServer(0x00u, "OpenMMO", 0u, 1u, true))) } fun onServerSelection(event: PacketEvent) { log.info { "Received server selection for server id ${event.packet.gameServerId}" } - // TODO proper server node selection handling (depends on onGameServerListRequest implementation) + // TODO proper server node selection handling (depends on onGameServerListRequest + // implementation) // Example refuse connection: event.respondWithState(LoginState.INVALID_PASSWORD) - event.respondForAuthedUser( - userId = 1, - sessionToken = ByteArray(16) { 0x42 } - ) - .withLocalEndpoint( - address = IPAddress.of("127.0.0.1"), - hostname = "localhost", - port = 7777u - ) - .withNodes(listOf( - GameServerNode( - iPv4Address = IPv4Address.of("127.0.0.1"), - iPv6Address = IPv6Address.of("::1"), - port = 7777u, - weight = 0x01u // Always select this node (only one node available in this example) - ) - )) - .respondTo(event) + event + .respondForAuthedUser(userId = 1, sessionToken = ByteArray(16) { 0x42 }) + .withLocalEndpoint( + address = IPAddress.of("127.0.0.1"), hostname = "localhost", port = 7777u) + .withNodes( + listOf( + GameServerNode( + iPv4Address = IPv4Address.of("127.0.0.1"), + iPv6Address = IPv6Address.of("::1"), + port = 7777u, + weight = + 0x01u // Always select this node (only one node available in this example) + ))) + .respondTo(event) } } diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/JoinGameServerPacket.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/JoinGameServerPacket.kt index fd52131..7b518e3 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/JoinGameServerPacket.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/JoinGameServerPacket.kt @@ -12,16 +12,13 @@ fun PacketEvent.respondWithErrorState(state: LoginState) { } fun PacketEvent.respondForAuthedUser( - userId: Int, - sessionToken: ByteArray + userId: Int, + sessionToken: ByteArray ): AuthedPacketBuilder { return GameServerNodesPacketBuilder.forAuthedUser( - userId = userId, - sessionToken = sessionToken, - gameServerId = this.packet.gameServerId - ) + userId = userId, sessionToken = sessionToken, gameServerId = this.packet.gameServerId) } fun AuthedPacketBuilder.respondTo(event: PacketEvent<*>) { event.respond(this.build()) -} \ No newline at end of file +} diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/LoginRequestPacketExtensions.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/LoginRequestPacketExtensions.kt index 257a897..aeb8964 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/LoginRequestPacketExtensions.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/LoginRequestPacketExtensions.kt @@ -12,8 +12,8 @@ fun PacketEvent.respondWithState(state: LoginState) { } fun PacketEvent.respondWithRateLimit( - state: LoginState, - ratelimitEnd: LocalDateTime + state: LoginState, + ratelimitEnd: LocalDateTime ) { this.respond(LoginResponsePacketBuilder.withRateLimit(state, ratelimitEnd)) -} \ No newline at end of file +} diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/RequestGameServerListPacketExtensions.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/RequestGameServerListPacketExtensions.kt index e69e9bb..4520bef 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/RequestGameServerListPacketExtensions.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/ext/RequestGameServerListPacketExtensions.kt @@ -20,4 +20,4 @@ fun PacketEvent.respondWithServerList(): GameServer fun GameServerListPacketBuilder.respondTo(event: PacketEvent<*>) { event.respond(this.build()) -} \ No newline at end of file +}