diff --git a/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt b/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt index 26725c9..9e28804 100644 --- a/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt +++ b/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt @@ -1,10 +1,6 @@ package de.fiereu.openmmo.common.enums -enum class Language( - val code: String, - private val english: String, - private val display: String -) { +enum class Language(val code: String, private val english: String, private val display: String) { EN("en", "english", "English"), FR("fr", "french", "Français"), DE("de", "german", "Deutsch"), @@ -30,4 +26,4 @@ enum class Language( return codeMap[code] ?: OTHER } } -} \ No newline at end of file +} diff --git a/keys/build.gradle.kts b/keys/build.gradle.kts index 058b6c4..14bf0be 100644 --- a/keys/build.gradle.kts +++ b/keys/build.gradle.kts @@ -1,37 +1,27 @@ -import org.bouncycastle.util.io.pem.PemObject -import org.bouncycastle.util.io.pem.PemWriter +import java.io.StringWriter import java.security.KeyPairGenerator import java.security.spec.ECGenParameterSpec -import java.io.StringWriter +import org.bouncycastle.util.io.pem.PemObject +import org.bouncycastle.util.io.pem.PemWriter buildscript { - repositories { - mavenCentral() - } + repositories { mavenCentral() } - dependencies { - classpath(libs.bundles.crypto) - } + dependencies { classpath(libs.bundles.crypto) } } -plugins { - id("buildsrc.convention.spotless") -} +plugins { id("buildsrc.convention.spotless") } -/** - * Abstract task for generating a certificate. - */ +/** Abstract task for generating a certificate. */ abstract class GenerateCertificateTask : DefaultTask() { - @get:OutputFile - val privateKeyOutput: RegularFileProperty = project.objects.fileProperty() + @get:OutputFile val privateKeyOutput: RegularFileProperty = project.objects.fileProperty() - @get:OutputFile - val publicKeyOutput: RegularFileProperty = project.objects.fileProperty() + @get:OutputFile val publicKeyOutput: RegularFileProperty = project.objects.fileProperty() @get:Input - val overwriteCertificates: Property = project.objects.property(Boolean::class.java) - .convention(false) + val overwriteCertificates: Property = + project.objects.property(Boolean::class.java).convention(false) init { group = "openmmo" @@ -53,21 +43,23 @@ abstract class GenerateCertificateTask : DefaultTask() { val keyPair = keyPairGenerator.generateKeyPair() // Write private key as PEM - val privateKeyPem = StringWriter().use { writer -> - PemWriter(writer).use { pemWriter -> - pemWriter.writeObject(PemObject("EC PRIVATE KEY", keyPair.private.encoded)) - } - writer.toString() - } + val privateKeyPem = + StringWriter().use { writer -> + PemWriter(writer).use { pemWriter -> + pemWriter.writeObject(PemObject("EC PRIVATE KEY", keyPair.private.encoded)) + } + writer.toString() + } privateKeyFile.writeText(privateKeyPem) // Write public key as PEM - val publicKeyPem = StringWriter().use { writer -> - PemWriter(writer).use { pemWriter -> - pemWriter.writeObject(PemObject("PUBLIC KEY", keyPair.public.encoded)) - } - writer.toString() - } + val publicKeyPem = + StringWriter().use { writer -> + PemWriter(writer).use { pemWriter -> + pemWriter.writeObject(PemObject("PUBLIC KEY", keyPair.public.encoded)) + } + writer.toString() + } publicKeyFile.writeText(publicKeyPem) } } @@ -87,4 +79,4 @@ tasks.register("generateChat") { tasks.register("generate") { group = "openmmo" dependsOn("generateGame", "generateChat") -} \ No newline at end of file +} 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 997d0b9..df2f200 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 @@ -8,8 +8,8 @@ import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer /** - * Login Protocol implementation. - * This protocol handles the login process after the TLS handshake is complete. + * Login Protocol implementation. This protocol handles the login process after the TLS handshake is + * complete. */ abstract class LoginProtocol() : Protocol() { override val async: Boolean @@ -27,4 +27,3 @@ class LoginClientProtocol() : LoginProtocol() { outgoingPacket(0x11u, LoginRequestPacket::class, LoginRequestPacketSerializer()) } } - diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt index e773446..3eeb194 100644 --- a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt @@ -9,18 +9,19 @@ import de.fiereu.openmmo.protocols.writeUtf16LE interface LoginMethod data class PasswordLogin(val password: String, val stayLoggedIn: Boolean) : LoginMethod + data class TokenLogin(val token: ByteArray) : LoginMethod data class LoginRequestPacket( - val username: String, - val manualLogin: Boolean, - val hwid: ByteArray, - val method: LoginMethod, - val language: Language, - val clientRevision: Int, - val installationRevision: Int, - val os: UByte, - val hardwareInfoCache: ByteArray + val username: String, + val manualLogin: Boolean, + val hwid: ByteArray, + val method: LoginMethod, + val language: Language, + val clientRevision: Int, + val installationRevision: Int, + val os: UByte, + val hardwareInfoCache: ByteArray ) class LoginRequestPacketSerializer : PacketSerializer { @@ -62,22 +63,23 @@ class LoginRequestPacketDeserializer : PacketDeserializer { buffer.readBytes(hwid) val methodType = buffer.readByte().toInt() - val method: LoginMethod = when (methodType) { - 0 -> { // Password - val password = buffer.readUtf16LE() - val stayLoggedIn = buffer.readBoolean() - PasswordLogin(password, stayLoggedIn) - } + val method: LoginMethod = + when (methodType) { + 0 -> { // Password + val password = buffer.readUtf16LE() + val stayLoggedIn = buffer.readBoolean() + PasswordLogin(password, stayLoggedIn) + } - 1 -> { // Token - val tokenSize = buffer.readUnsignedByte().toInt() - val token = ByteArray(tokenSize) - buffer.readBytes(token) - TokenLogin(token) - } + 1 -> { // Token + val tokenSize = buffer.readUnsignedByte().toInt() + val token = ByteArray(tokenSize) + buffer.readBytes(token) + TokenLogin(token) + } - else -> throw IllegalArgumentException("Unknown login method type: $methodType") - } + else -> throw IllegalArgumentException("Unknown login method type: $methodType") + } val languageCode = buffer.readUtf16LE() val language = Language.fromCode(languageCode) @@ -91,15 +93,14 @@ class LoginRequestPacketDeserializer : PacketDeserializer { buffer.readBytes(hardwareInfoCache) return LoginRequestPacket( - username, - manualLogin, - hwid, - method, - language, - clientRevision, - installationRevision, - os, - hardwareInfoCache - ) + username, + manualLogin, + hwid, + method, + language, + clientRevision, + installationRevision, + os, + hardwareInfoCache) } -} \ 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 776cc54..539c2bd 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 @@ -8,30 +8,29 @@ import java.security.interfaces.ECPrivateKey import java.security.interfaces.ECPublicKey /** - * TLS Protocol implementation. - * This protocol handles the initial TLS handshake before any secure communication can take place. + * TLS Protocol implementation. This protocol handles the initial TLS handshake before any secure + * communication can take place. * * The flow is as follows: * 1. Client sends a ClientHello packet to initiate the handshake. - * 2. Server responds with a ServerHello packet. - * -> The client knows the servers public key and its own private key. And it can derive a shared secret using ECDH. - * -> Every packet the client now would receive is expected to be secured. - * -> Client switches to next protocol (e.g. LoginProtocol) after the handshake is complete. - * 3. Client sends a ClientReady packet with its public key. - * -> The server can now secure its communication with the client using the shared secret. - * -> Server switches to next protocol (e.g. LoginProtocol) after the handshake is complete. + * 2. Server responds with a ServerHello packet. -> The client knows the servers public key and its + * own private key. And it can derive a shared secret using ECDH. -> Every packet the client now + * would receive is expected to be secured. -> Client switches to next protocol (e.g. + * LoginProtocol) after the handshake is complete. + * 3. Client sends a ClientReady packet with its public key. -> The server can now secure its + * communication with the client using the shared secret. -> Server switches to next protocol + * (e.g. LoginProtocol) after the handshake is complete. */ -abstract class TlsProtocol() : Protocol() { +abstract class TlsProtocol() : Protocol() { override val async: Boolean get() = false } -class TlsServerProtocol( - serverKeyPair: Pair -) : TlsProtocol() { +class TlsServerProtocol(serverKeyPair: Pair) : TlsProtocol() { init { incomingPacket(0x00u, ClientHelloPacketDeserializer()) - outgoingPacket(0x01u, ServerHelloPacket::class, ServerHelloPacketSerializer(serverKeyPair.first)) + outgoingPacket( + 0x01u, ServerHelloPacket::class, ServerHelloPacketSerializer(serverKeyPair.first)) incomingPacket(0x02u, ClientReadyPacketDeserializer()) } } @@ -43,4 +42,3 @@ class TlsClientProtocol() : TlsProtocol() { outgoingPacket(0x02u, ClientReadyPacket::class, ClientReadyPacketSerializer()) } } - diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt index c504f57..02ef5b5 100644 --- a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt @@ -7,9 +7,7 @@ import de.fiereu.openmmo.protocols.tls.util.toUncompressedPoint import io.netty.buffer.ByteBuf import java.security.interfaces.ECPublicKey -data class ClientReadyPacket( - val clientPublicKey: ECPublicKey -) +data class ClientReadyPacket(val clientPublicKey: ECPublicKey) class ClientReadyPacketSerializer : PacketSerializer { diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt index f1dc8d6..e4e42f1 100644 --- a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt @@ -16,14 +16,10 @@ import java.security.interfaces.ECPublicKey * @property publicKey The public key generated for this connection. * @property checksumSize The size of the checksum used for this connection. */ -data class ServerHelloPacket( - val publicKey: ECPublicKey, - val checksumSize: Int -) +data class ServerHelloPacket(val publicKey: ECPublicKey, val checksumSize: Int) -class ServerHelloPacketSerializer( - private val serverRootPrivateKey: ECPrivateKey -) : PacketSerializer { +class ServerHelloPacketSerializer(private val serverRootPrivateKey: ECPrivateKey) : + PacketSerializer { override fun serialize(packet: ServerHelloPacket, buffer: ByteBuf) { val publicKeyBytes = packet.publicKey.toUncompressedPoint() @@ -39,12 +35,13 @@ class ServerHelloPacketSerializer( } } -class ServerHelloPacketDeserializer : PacketDeserializer { +class ServerHelloPacketDeserializer : + PacketDeserializer { data class ServerHelloPacket( - val clientPublicKey: PublicKey, - val signature: ByteArray, - val checksumSize: Int + val clientPublicKey: PublicKey, + val signature: ByteArray, + val checksumSize: Int ) override fun deserialize(buffer: ByteBuf): ServerHelloPacket { diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt index 4e045c1..9647340 100644 --- a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt @@ -3,14 +3,13 @@ package de.fiereu.openmmo.protocols.tls.util import java.math.BigInteger import java.security.AlgorithmParameters import java.security.KeyFactory -import java.security.Security +import java.security.Signature +import java.security.interfaces.ECPrivateKey import java.security.interfaces.ECPublicKey import java.security.spec.ECGenParameterSpec import java.security.spec.ECParameterSpec import java.security.spec.ECPoint import java.security.spec.ECPublicKeySpec -import java.security.Signature -import java.security.interfaces.ECPrivateKey private const val uncompressedPointIndicator: Byte = 0x04 @@ -93,4 +92,4 @@ fun ECPublicKey.verify(data: ByteArray, signatureBytes: ByteArray): Boolean { signature.initVerify(this) signature.update(data) return signature.verify(signatureBytes) -} \ No newline at end of file +} 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 d3acd1a..9b5912a 100644 --- a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt @@ -25,4 +25,4 @@ fun ByteBuf.writeUtf16LE(value: String) { writeCharLE(c) } writeCharLE(0.toChar()) // Null-terminator -} \ 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 70eb031..e630b72 100644 --- a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt @@ -4,20 +4,17 @@ import io.github.oshai.kotlinlogging.KotlinLogging import io.netty.buffer.ByteBuf import kotlin.reflect.KClass -/** - * Value class wrapping a UByte to represent an opcode. - */ +/** Value class wrapping a UByte to represent an opcode. */ @JvmInline value class Opcode(val value: UByte) { override fun toString(): String = "0x${value.toString(16).padStart(2, '0').uppercase()}" } /** - * Packet direction enum representing the direction of packet flow. - * This is needed because depending on the current side (client or server), - * the same opcode can represent different packets. - * For example, opcode 0x01 might represent a "LoginRequest" packet on the client side, - * but a "LoginResponse" packet on the server side. + * Packet direction enum representing the direction of packet flow. This is needed because depending + * on the current side (client or server), the same opcode can represent different packets. For + * example, opcode 0x01 might represent a "LoginRequest" packet on the client side, but a + * "LoginResponse" packet on the server side. */ enum class PacketDirection { CLIENT_TO_SERVER, @@ -26,9 +23,9 @@ enum class PacketDirection { interface PacketSerializer { fun serializeObject(packet: Any, buffer: ByteBuf) { - @Suppress("UNCHECKED_CAST") - serialize(packet as T, buffer) + @Suppress("UNCHECKED_CAST") serialize(packet as T, buffer) } + fun serialize(packet: T, buffer: ByteBuf) } @@ -37,12 +34,12 @@ interface PacketDeserializer { } /** - * The base class for all protocols. - * A protocol is a collection of packets that can be sent and received. + * The base class for all protocols. A protocol is a collection of packets that can be sent and + * received. * - * We cant combine Server and Client protocols because they have different dependencies. - * For example, the server protocol needs to know about the server's root private key, - * while the client protocol should not have any knowledge about the server's private key. + * We cant combine Server and Client protocols because they have different dependencies. For + * example, the server protocol needs to know about the server's root private key, while the client + * protocol should not have any knowledge about the server's private key. */ abstract class Protocol { private val log = KotlinLogging.logger {} @@ -56,21 +53,22 @@ abstract class Protocol { return dataClassToOpcode[dataClass] } - fun registerIncoming( - opcode: Opcode, - deserializer: PacketDeserializer - ) { - log.debug { "Registering incoming packet: opcode=$opcode, deserializer=${deserializer::class.simpleName}" } + fun registerIncoming(opcode: Opcode, deserializer: PacketDeserializer) { + log.debug { + "Registering incoming packet: opcode=$opcode, deserializer=${deserializer::class.simpleName}" + } incomingPacketRegistry.put(opcode, deserializer) } fun registerOutgoing( - opcode: Opcode, - dataClass: KClass, - serializer: PacketSerializer, + opcode: Opcode, + dataClass: KClass, + serializer: PacketSerializer, ) { - log.debug { "Registering outgoing packet: opcode=$opcode, serializer=${serializer::class.simpleName}" } + log.debug { + "Registering outgoing packet: opcode=$opcode, serializer=${serializer::class.simpleName}" + } dataClassToOpcode[dataClass] = opcode outgoingPacketRegistry.put(opcode, serializer) @@ -89,18 +87,14 @@ fun Protocol.getDeserializer(opcode: UByte): PacketDeserializer<*>? { return this.getDeserializer(Opcode(opcode)) } -fun Protocol.incomingPacket( - opcode: UByte, - deserializer: PacketDeserializer -) { +fun Protocol.incomingPacket(opcode: UByte, deserializer: PacketDeserializer) { this.registerIncoming(Opcode(opcode), deserializer) } fun Protocol.outgoingPacket( - opcode: UByte, - dataClass: KClass, - serializer: PacketSerializer + opcode: UByte, + dataClass: KClass, + serializer: PacketSerializer ) { this.registerOutgoing(Opcode(opcode), dataClass, serializer) } - diff --git a/server.login/build.gradle.kts b/server.login/build.gradle.kts index df03726..087b18c 100644 --- a/server.login/build.gradle.kts +++ b/server.login/build.gradle.kts @@ -1,10 +1,6 @@ import org.flywaydb.gradle.task.AbstractFlywayTask -buildscript { - dependencies { - classpath(libs.flyway.postgresql) - } -} +buildscript { dependencies { classpath(libs.flyway.postgresql) } } plugins { application @@ -18,6 +14,7 @@ plugins { } group = "de.fiereu.openmmo" + version = "0.1.0" dependencies { @@ -39,9 +36,7 @@ dependencies { testImplementation(libs.mockk) } -application { - mainClass.set("de.fiereu.openmmo.server.login.LoginServerKt") -} +application { mainClass.set("de.fiereu.openmmo.server.login.LoginServerKt") } tasks.classes.get().apply { dependsOn("copyKeysGame") @@ -49,22 +44,25 @@ tasks.classes.get().apply { } fun env(key: String): Any { - val value = property(key) ?: - System.getenv(key) ?: - throw IllegalArgumentException("Environment variable or system property '$key' is not set.") + val value = + 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_]+)\\}") - return (PATTERN_WORD.findAll(value) + PATTERN_MULTI.findAll(value)) - .distinct() - .fold(value) { acc, match -> - val envName = match.groupValues[1] - val envValue = System.getProperty(envName) ?: System.getProperty(envName) - if (envValue == null) { - throw IllegalArgumentException("Environment variable or system property '$envName' is not set.") - } - acc.replace(match.value, envValue) + return (PATTERN_WORD.findAll(value) + PATTERN_MULTI.findAll(value)).distinct().fold(value) { + acc, + match -> + val envName = match.groupValues[1] + val envValue = System.getProperty(envName) ?: System.getProperty(envName) + if (envValue == null) { + throw IllegalArgumentException( + "Environment variable or system property '$envName' is not set.") } + acc.replace(match.value, envValue) + } } return if (value is String && (value.contains('$') || value.contains('{'))) { interpolate(value) @@ -88,16 +86,15 @@ jooq { database { name = "org.jooq.meta.postgres.PostgresDatabase" includes = ".*" - excludes = """ + excludes = + """ flyway_schema_history | pgp_armor_headers """ inputSchema = "public" } - generate { - name = "org.jooq.codegen.KotlinGenerator" - } + generate { name = "org.jooq.codegen.KotlinGenerator" } target { packageName = "de.fiereu.openmmo.server.login.jooq" directory = "src/main/jooq" @@ -116,7 +113,8 @@ flyway { cleanDisabled = false } -// Fuck this shit uhh we are not gonna update our gradle plugin bc all our enterprise customers are stuck on Java 1.6 and gradle 5 anyway +// Fuck this shit uhh we are not gonna update our gradle plugin bc all our enterprise customers are +// stuck on Java 1.6 and gradle 5 anyway tasks.withType().configureEach { notCompatibleWithConfigurationCache("https://github.com/flyway/flyway/issues/3550") } @@ -125,4 +123,14 @@ tasks.register("cleanMigrateAndGenerate") { group = "openmmo" description = "Cleans the database, migrates it and generates the jOOQ classes." dependsOn("flywayClean", "flywayMigrate", "jooqCodegen") -} \ No newline at end of file +} + +spotless { kotlin { targetExclude("src/main/jooq/**") } } + +// If someone knows a better way then this please please please help me :( +listOf("spotlessKotlinGradle", "spotlessMisc").forEach { taskName -> + tasks.named(taskName) { + dependsOn("copyPublicKeyGame") + dependsOn("copyPrivateKeyGame") + } +} diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt index 452f805..6f7fc1e 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt @@ -12,20 +12,19 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob fun main() { - val serverConfig = ServerConfig( - port = 2106 - ) - val tlsConfig = TlsConfig( - checksumSize = 16 - ) + val serverConfig = ServerConfig(port = 2106) + val tlsConfig = TlsConfig(checksumSize = 16) val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) - val server = ServerBuilder.create() - .withCoroutineScope(coroutineScope) - .withConfig(serverConfig) - .withTlsConfig(tlsConfig) - .withPublicKey(KeyLoader.loadPemECPublicKey(resource("game.public.pem"))) - .withPrivateKey(KeyLoader.loadPemECPrivateKey(resource("game.private.pem"))) - .withChannelHandlerProvider { LoginProtocolHandler(LoginServerProtocol(), coroutineScope) } - .build() + val server = + ServerBuilder.create() + .withCoroutineScope(coroutineScope) + .withConfig(serverConfig) + .withTlsConfig(tlsConfig) + .withPublicKey(KeyLoader.loadPemECPublicKey(resource("game.public.pem"))) + .withPrivateKey(KeyLoader.loadPemECPrivateKey(resource("game.private.pem"))) + .withChannelHandlerProvider { + LoginProtocolHandler(LoginServerProtocol(), coroutineScope) + } + .build() server.start() -} \ No newline at end of file +} 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 d0d094b..9917fd1 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 @@ -12,8 +12,8 @@ import kotlinx.coroutines.launch private val log = KotlinLogging.logger {} class LoginProtocolHandler( - protocol: Protocol, - private val coroutineScope: CoroutineScope, + protocol: Protocol, + private val coroutineScope: CoroutineScope, ) : ProtocolHandler(protocol) { override fun onActive(ctx: ChannelHandlerContext) { @@ -33,4 +33,4 @@ class LoginProtocolHandler( fun onLoginRequest(event: PacketEvent) { log.info { "Received login request for user '${event.packet.username}'" } } -} \ No newline at end of file +}