dev_minimal_login (#7)
### Summary Implement minimal login flow without any authentication. Implement basic game server module with JoingGamePacket implemented. ### Type of Change New feature (non-breaking change which adds functionality) ### Affected Modules - [x] common/ - [ ] protocol/ - [ ] protocol.tls/ - [x] protocol.login/ - [ ] server/ - [x] server.login/ - [ ] keys/ - [ ] patcher/ - [ ] buildSrc/ ### Additional Notes _No response_ Reviewed-on: https://forge.fiereu.de/OpenMMO/OpenMMO/pulls/7 Co-authored-by: fiereu <contact@fiereu.de> Co-committed-by: fiereu <contact@fiereu.de>
This commit is contained in:
1 parent
9fabe28642
commit
a9bb88b246
33 files changed
+906
-86
No files matched your search
@@ -0,0 +1 @@
|
||||
src/main/resources/game.*.pem
|
||||
@@ -0,0 +1,61 @@
|
||||
# Multi-stage build for OpenMMO Game Server
|
||||
FROM azul/zulu-openjdk:24-latest AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy gradle files first for better caching
|
||||
COPY ./gradle gradle/
|
||||
COPY ./gradlew gradlew.bat gradle.properties settings.gradle.kts gradle.env ./
|
||||
COPY ./buildSrc buildSrc/
|
||||
|
||||
# remove all includ("...") from settings.gradle.kts
|
||||
RUN sed -i '/include(/d' settings.gradle.kts
|
||||
# manually include only the required modules
|
||||
RUN echo 'include("common")' >> settings.gradle.kts
|
||||
RUN echo 'include("keys")' >> settings.gradle.kts
|
||||
RUN echo 'include("protocol")' >> settings.gradle.kts
|
||||
RUN echo 'include("protocol.tls")' >> settings.gradle.kts
|
||||
RUN echo 'include("protocol.game")' >> settings.gradle.kts
|
||||
RUN echo 'include("server")' >> settings.gradle.kts
|
||||
RUN echo 'include("server.game")' >> settings.gradle.kts
|
||||
|
||||
# Copy all module build files
|
||||
COPY ./build.gradle.kts ./
|
||||
COPY ./common/build.gradle.kts common/
|
||||
COPY ./keys/build.gradle.kts keys/
|
||||
COPY ./protocol/build.gradle.kts protocol/
|
||||
COPY ./protocol.tls/build.gradle.kts protocol.tls/
|
||||
COPY ./protocol.game/build.gradle.kts protocol.game/
|
||||
COPY ./server/build.gradle.kts server/
|
||||
COPY ./server.game/build.gradle.kts server.game/
|
||||
|
||||
# Download dependencies
|
||||
RUN ./gradlew dependencies --no-daemon
|
||||
|
||||
# Copy source code
|
||||
COPY ./common/src common/src/
|
||||
COPY ./protocol/src protocol/src/
|
||||
COPY ./protocol.tls/src protocol.tls/src/
|
||||
COPY ./protocol.game/src protocol.game/src/
|
||||
COPY ./server/src server/src/
|
||||
COPY ./server.game/src server.game/src/
|
||||
|
||||
# Build the application
|
||||
RUN ./gradlew :server.game:distTar --no-daemon
|
||||
|
||||
# Extract the distribution
|
||||
RUN cd server.game/build/distributions && \
|
||||
tar -xf server.game-*.tar && \
|
||||
mv server.game-*/ server.game/
|
||||
|
||||
# Runtime stage
|
||||
FROM azul/zulu-openjdk:24-jre-latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the extracted distribution from builder
|
||||
COPY --from=builder /app/server.game/build/distributions/server.game/ .
|
||||
|
||||
EXPOSE 2106
|
||||
|
||||
ENTRYPOINT ["./bin/server.game"]
|
||||
@@ -0,0 +1,9 @@
|
||||
# Server.Game Module
|
||||
|
||||
The server.game module implements the game server for OpenMMO.
|
||||
|
||||
## Development
|
||||
- Run with: `./gradlew :server.game:run`
|
||||
- Database setup: `./gradlew cleanMigrateAndGenerate`
|
||||
- Code generation: `./gradlew jooqCodegen`
|
||||
- Docker build: `docker build -t openmmo-game server.game/`
|
||||
@@ -0,0 +1,124 @@
|
||||
import org.flywaydb.gradle.task.AbstractFlywayTask
|
||||
|
||||
buildscript { dependencies { classpath(libs.flyway.postgresql) } }
|
||||
|
||||
plugins {
|
||||
application
|
||||
distribution
|
||||
id("buildsrc.convention.kotlin-jvm")
|
||||
id("buildsrc.convention.spotless")
|
||||
id("buildsrc.common.keys")
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
alias(libs.plugins.jooq)
|
||||
alias(libs.plugins.flyway)
|
||||
}
|
||||
|
||||
group = "de.fiereu.openmmo"
|
||||
|
||||
version = "0.1.0"
|
||||
|
||||
dependencies {
|
||||
implementation(project(":server"))
|
||||
implementation(project(":protocol.game"))
|
||||
implementation(libs.logback)
|
||||
implementation(libs.kotlinx.coroutines)
|
||||
|
||||
testImplementation(libs.bundles.kotest)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
testImplementation(libs.mockk)
|
||||
}
|
||||
|
||||
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.")
|
||||
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 if (value is String && (value.contains('$') || value.contains('{'))) {
|
||||
interpolate(value)
|
||||
} else value
|
||||
}
|
||||
|
||||
val dbPort = env("openmmo.db.game.port") as String
|
||||
val dbName = env("openmmo.db.game.name") as String
|
||||
val dbUser = env("openmmo.db.game.user") as String
|
||||
val dbPassword = env("openmmo.db.game.password") as String
|
||||
|
||||
jooq {
|
||||
configuration {
|
||||
jdbc {
|
||||
driver = "org.postgresql.Driver"
|
||||
url = "jdbc:postgresql://localhost:$dbPort/$dbName"
|
||||
user = dbUser
|
||||
password = dbPassword
|
||||
}
|
||||
generator {
|
||||
database {
|
||||
name = "org.jooq.meta.postgres.PostgresDatabase"
|
||||
includes = ".*"
|
||||
excludes =
|
||||
"""
|
||||
flyway_schema_history |
|
||||
pgp_armor_headers
|
||||
"""
|
||||
inputSchema = "public"
|
||||
}
|
||||
|
||||
generate { name = "org.jooq.codegen.KotlinGenerator" }
|
||||
target {
|
||||
packageName = "de.fiereu.openmmo.server.game.jooq"
|
||||
directory = "src/main/jooq"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flyway {
|
||||
driver = "org.postgresql.Driver"
|
||||
url = "jdbc:postgresql://localhost:$dbPort/$dbName"
|
||||
user = dbUser
|
||||
password = dbPassword
|
||||
schemas = arrayOf("public")
|
||||
locations = arrayOf("filesystem:src/main/resources/db/migration")
|
||||
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
|
||||
tasks.withType<AbstractFlywayTask>().configureEach {
|
||||
notCompatibleWithConfigurationCache("https://github.com/flyway/flyway/issues/3550")
|
||||
}
|
||||
|
||||
tasks.register("cleanMigrateAndGenerate") {
|
||||
group = "openmmo"
|
||||
description = "Cleans the database, migrates it and generates the jOOQ classes."
|
||||
dependsOn("flywayClean", "flywayMigrate", "jooqCodegen")
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.fiereu.openmmo.server.game
|
||||
|
||||
import de.fiereu.openmmo.protocols.game.GameServerProtocol
|
||||
import de.fiereu.openmmo.server.ServerBuilder
|
||||
import de.fiereu.openmmo.server.config.ServerConfig
|
||||
import de.fiereu.openmmo.server.config.TlsConfig
|
||||
import de.fiereu.openmmo.server.game.protocol.game.GameProtocolHandler
|
||||
import de.fiereu.openmmo.server.io.resource
|
||||
import de.fiereu.openmmo.server.keys.KeyLoader
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
||||
fun main() {
|
||||
val serverConfig = ServerConfig(port = 7777)
|
||||
val tlsConfig = TlsConfig(checksumSize = 2)
|
||||
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 { GameProtocolHandler(GameServerProtocol(), coroutineScope) }
|
||||
.build()
|
||||
server.start()
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package de.fiereu.openmmo.server.game.protocol.game
|
||||
|
||||
import de.fiereu.openmmo.protocols.Protocol
|
||||
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
||||
import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler
|
||||
import de.fiereu.openmmo.server.protocol.PacketEvent
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
class GameProtocolHandler(
|
||||
protocol: Protocol,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
) : ProtocolHandler(protocol) {
|
||||
|
||||
override fun onActive(ctx: ChannelHandlerContext) {
|
||||
log.info { "Client ${ctx.channel().remoteAddress()} connected to game server." }
|
||||
}
|
||||
|
||||
@Suppress("unchecked_cast") // Even here i personally check every cast. i live in ur jvm >:(
|
||||
override fun onPacketReceived(event: PacketEvent<*>) {
|
||||
coroutineScope.launch {
|
||||
when (event.packet) {
|
||||
is JoinGamePacket -> onJoinGame(event as PacketEvent<JoinGamePacket>)
|
||||
else -> log.warn { "Unhandled game packet type: ${event.packet::class.simpleName}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onJoinGame(event: PacketEvent<JoinGamePacket>) {
|
||||
log.info { "Player joined the game." }
|
||||
log.debug { "This is what the Game knows about you:\n${event.packet.clientInfo.values.joinToString("\n")}" }
|
||||
// TODO handle player joining the game
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
server.port = 2106
|
||||
Whitespace-only changes.
@@ -0,0 +1,11 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in new issue
Block a user