From beb1df24f1cf472e032c4b4484d698d9e4919d88 Mon Sep 17 00:00:00 2001 From: phinner <62483793+phinner@users.noreply.github.com> Date: Thu, 23 Nov 2023 02:56:49 +0100 Subject: [PATCH] fix: Bugfixes and stuff --- docker-compose.yaml | 9 ++++++ .../common/content/MindustryMapManager.kt | 28 +++++++++++-------- .../common/security/PunishmentManager.kt | 3 +- .../common/security/PunishmentTable.kt | 4 +-- imperium-discord/build.gradle.kts | 3 +- .../imperium/discord/commands/MapCommand.kt | 6 ++-- imperium-mindustry/build.gradle.kts | 1 + 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 299d8427..e0019335 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,3 +9,12 @@ services: ports: - "5672:5672" - "15672:15672" + + # The Mariadb database + # login is root:root + mariadb: + image: mariadb:latest + ports: + - "3306:3306" + environment: + MARIADB_ROOT_PASSWORD: root diff --git a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/content/MindustryMapManager.kt b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/content/MindustryMapManager.kt index a3b705b8..dddbff6d 100644 --- a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/content/MindustryMapManager.kt +++ b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/content/MindustryMapManager.kt @@ -23,11 +23,13 @@ import com.xpdustry.imperium.common.misc.exists import com.xpdustry.imperium.common.snowflake.Snowflake import com.xpdustry.imperium.common.snowflake.SnowflakeGenerator import java.io.InputStream +import java.util.function.Supplier import kotlin.math.roundToInt import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.map import org.jetbrains.exposed.sql.ColumnSet +import org.jetbrains.exposed.sql.Join import org.jetbrains.exposed.sql.ResultRow import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq @@ -65,7 +67,7 @@ interface MindustryMapManager { author: String?, width: Int, height: Int, - stream: InputStream + stream: Supplier ): Snowflake suspend fun updateMap( @@ -74,7 +76,7 @@ interface MindustryMapManager { author: String?, width: Int, height: Int, - stream: InputStream + stream: Supplier ): Boolean suspend fun getMapInputStream(map: Snowflake): InputStream? @@ -174,7 +176,7 @@ class SimpleMindustryMapManager( author: String?, width: Int, height: Int, - stream: InputStream + stream: Supplier ): Snowflake = provider.newSuspendTransaction { val snowflake = generator.generate() @@ -185,7 +187,7 @@ class SimpleMindustryMapManager( it[MindustryMapTable.author] = author it[MindustryMapTable.width] = width it[MindustryMapTable.height] = height - it[file] = ExposedBlob(stream) + it[file] = ExposedBlob(stream.get().use(InputStream::readAllBytes)) } snowflake } @@ -196,7 +198,7 @@ class SimpleMindustryMapManager( author: String?, width: Int, height: Int, - stream: InputStream + stream: Supplier ): Boolean = provider.newSuspendTransaction { val rows = @@ -205,17 +207,19 @@ class SimpleMindustryMapManager( it[MindustryMapTable.author] = author it[MindustryMapTable.width] = width it[MindustryMapTable.height] = height - it[file] = ExposedBlob(stream) + it[file] = ExposedBlob(stream.get().use(InputStream::readAllBytes)) } rows != 0 } override suspend fun getMapInputStream(map: Snowflake): InputStream? = - MindustryMapTable.slice(MindustryMapTable.file) - .select { MindustryMapTable.id eq map } - .firstOrNull() - ?.get(MindustryMapTable.file) - ?.inputStream + provider.newSuspendTransaction { + MindustryMapTable.slice(MindustryMapTable.file) + .select { MindustryMapTable.id eq map } + .firstOrNull() + ?.get(MindustryMapTable.file) + ?.inputStream + } override suspend fun searchMapByName(query: String): Flow = provider.newSuspendTransaction { @@ -242,7 +246,7 @@ class SimpleMindustryMapManager( } private fun ColumnSet.sliceWithoutFile() = - MindustryMapTable.slice(columns - MindustryMapTable.file) + slice((if (this is Join) table.columns else columns) - MindustryMapTable.file) private suspend fun getMapGamemodes(map: Snowflake): Set = provider.newSuspendTransaction { diff --git a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentManager.kt b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentManager.kt index 7ff8563b..2be260c3 100644 --- a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentManager.kt +++ b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentManager.kt @@ -193,8 +193,7 @@ class SimplePunishmentManager( this[PunishmentTable.targetAddressMask]) val author = - Punishment.Author( - this[PunishmentTable.authorId].value, this[PunishmentTable.authorType]) + Punishment.Author(this[PunishmentTable.authorId], this[PunishmentTable.authorType]) val pardon = if (this[PunishmentTable.pardonTimestamp] == null) { diff --git a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentTable.kt b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentTable.kt index 33018031..d55784b4 100644 --- a/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentTable.kt +++ b/imperium-common/src/main/kotlin/com/xpdustry/imperium/common/security/PunishmentTable.kt @@ -18,13 +18,11 @@ package com.xpdustry.imperium.common.security import com.xpdustry.imperium.common.snowflake.SnowflakeIdTable -import com.xpdustry.imperium.common.user.UserTable -import org.jetbrains.exposed.sql.ReferenceOption import org.jetbrains.exposed.sql.javatime.duration import org.jetbrains.exposed.sql.javatime.timestamp object PunishmentTable : SnowflakeIdTable("punishment") { - val authorId = reference("author_id", UserTable, onDelete = ReferenceOption.SET_NULL) + val authorId = long("author_id") val authorType = enumerationByName("author_type", 32) val targetAddress = binary("target_address", 16) val targetAddressMask = byte("target_address_mask") diff --git a/imperium-discord/build.gradle.kts b/imperium-discord/build.gradle.kts index 2619e276..bf080208 100644 --- a/imperium-discord/build.gradle.kts +++ b/imperium-discord/build.gradle.kts @@ -49,8 +49,9 @@ tasks.shadowJar { exclude(dependency("org.apache.logging.log4j:log4j-to-slf4j:.*")) exclude(dependency("com.sksamuel.hoplite:hoplite-.*:.*")) exclude(dependency("org.javacord:javacord-core:.*")) - exclude(dependency(libs.sqlite.get())) exclude(dependency(libs.exposed.jdbc.get())) + exclude(dependency(libs.sqlite.get())) + exclude(dependency(libs.mariadb.get())) } } diff --git a/imperium-discord/src/main/kotlin/com/xpdustry/imperium/discord/commands/MapCommand.kt b/imperium-discord/src/main/kotlin/com/xpdustry/imperium/discord/commands/MapCommand.kt index a5dbe6f1..f834f36b 100644 --- a/imperium-discord/src/main/kotlin/com/xpdustry/imperium/discord/commands/MapCommand.kt +++ b/imperium-discord/src/main/kotlin/com/xpdustry/imperium/discord/commands/MapCommand.kt @@ -139,7 +139,7 @@ class MapCommand(instances: InstanceManager) : ImperiumApplication.Listener { @ButtonCommand(MAP_UPLOAD_BUTTON, Rank.ADMIN) private suspend fun onMapUpload(actor: InteractionSender.Button) { val attachment = actor.message.attachments.first() - val meta = content.getMapMetadata(attachment.asInputStream()).getOrThrow() + val meta = attachment.asInputStream().use { content.getMapMetadata(it).getOrThrow() } val map = maps.findMapByName(meta.name.stripMindustryColors()) val snowflake: Snowflake @@ -151,7 +151,7 @@ class MapCommand(instances: InstanceManager) : ImperiumApplication.Listener { author = meta.author?.stripMindustryColors(), width = meta.width, height = meta.height, - stream = attachment.asInputStream()) + stream = attachment::asInputStream) } else { snowflake = map.snowflake maps.updateMap( @@ -160,7 +160,7 @@ class MapCommand(instances: InstanceManager) : ImperiumApplication.Listener { author = meta.author?.stripMindustryColors(), width = meta.width, height = meta.height, - stream = attachment.asInputStream()) + stream = attachment::asInputStream) } updateSubmissionEmbed(actor, Color.GREEN, "uploaded") diff --git a/imperium-mindustry/build.gradle.kts b/imperium-mindustry/build.gradle.kts index a51c7602..c0b55cf2 100644 --- a/imperium-mindustry/build.gradle.kts +++ b/imperium-mindustry/build.gradle.kts @@ -54,6 +54,7 @@ tasks.shadowJar { minimize { exclude(dependency("com.sksamuel.hoplite:hoplite-.*:.*")) exclude(dependency(libs.sqlite.get())) + exclude(dependency(libs.mariadb.get())) } }