Skip to content

Commit

Permalink
chore: Misc improvements and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Dec 2, 2023
1 parent 2a18556 commit d2dd3a9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class SimpleAccountManager(
it[AccountAchievementTable.account] = account
it[AccountAchievementTable.achievement] = achievement
it[AccountAchievementTable.completed] = completed
it[progress] = progress.plus(value)
}

AccountResult.Success to completed
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import java.nio.file.Path
import java.sql.DriverManager
import java.sql.SQLException
import kotlin.io.path.absolutePathString
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.runBlocking
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
Expand All @@ -40,6 +43,8 @@ interface SQLProvider {
class SimpleSQLProvider(private val config: DatabaseConfig.SQL, private val directory: Path) :
SQLProvider, ImperiumApplication.Listener {

private val parent = SupervisorJob()
private val scope = CoroutineScope(ImperiumScope.IO.coroutineContext + parent)
private lateinit var database: Database
private lateinit var source: HikariDataSource

Expand Down Expand Up @@ -72,13 +77,15 @@ class SimpleSQLProvider(private val config: DatabaseConfig.SQL, private val dire
}

override fun onImperiumExit() {
parent.complete()
runBlocking { parent.join() }
source.close()
}

override fun <T> newTransaction(block: () -> T): T = transaction { block() }

override suspend fun <T> newSuspendTransaction(block: suspend () -> T): T =
newSuspendedTransaction(ImperiumScope.IO.coroutineContext, database) { block() }
newSuspendedTransaction(scope.coroutineContext, database) { block() }

private fun unregisterDriver(name: String) {
// Calling Class.forName("com.mysql.cj.jdbc.Driver") is enough to call the static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.xpdustry.imperium.common.account.RankChangeEvent
import com.xpdustry.imperium.common.application.ImperiumApplication
import com.xpdustry.imperium.common.async.ImperiumScope
import com.xpdustry.imperium.common.command.Command
import com.xpdustry.imperium.common.config.ServerConfig
import com.xpdustry.imperium.common.inject.InstanceManager
import com.xpdustry.imperium.common.inject.get
import com.xpdustry.imperium.common.message.Messenger
Expand All @@ -36,7 +35,6 @@ class RoleSyncListener(instances: InstanceManager) : ImperiumApplication.Listene
private val discord = instances.get<DiscordService>()
private val accounts = instances.get<AccountManager>()
private val messenger = instances.get<Messenger>()
private val config = instances.get<ServerConfig.Discord>()

override fun onImperiumInit() {
discord.getMainServer().addServerMemberJoinListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.xpdustry.imperium.common.user.UserManager
import com.xpdustry.imperium.discord.command.InteractionSender
import com.xpdustry.imperium.discord.command.annotation.NonEphemeral
import com.xpdustry.imperium.discord.service.DiscordService
import java.net.InetAddress
import org.javacord.api.entity.message.embed.EmbedBuilder

class PlayerCommand(instances: InstanceManager) : ImperiumApplication.Listener {
Expand Down Expand Up @@ -61,10 +60,10 @@ class PlayerCommand(instances: InstanceManager) : ImperiumApplication.Listener {
.apply {
if (discord.isAllowed(actor.user, Rank.ADMIN)) {
addField("Uuid", "`${user.uuid}`", true)
addField("Last Address", user.lastAddress.hostAddress, true)
addField("Last Address", "`${user.lastAddress.hostAddress}`", true)
addField(
"Addresses",
details.addresses.joinToString(transform = InetAddress::getHostAddress),
details.addresses.joinToString(transform = { "`${it.hostAddress}`" }),
true)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.xpdustry.imperium.common.config.ServerConfig
import com.xpdustry.imperium.common.content.MindustryGamemode
import com.xpdustry.imperium.common.inject.get
import com.xpdustry.imperium.common.version.MindustryVersion
import com.xpdustry.imperium.common.webhook.WebhookMessage
import com.xpdustry.imperium.common.webhook.WebhookMessageSender
import com.xpdustry.imperium.mindustry.account.AccountCommand
import com.xpdustry.imperium.mindustry.account.AccountListener
import com.xpdustry.imperium.mindustry.account.UserSettingsCommand
Expand Down Expand Up @@ -63,6 +65,7 @@ import fr.xpdustry.distributor.api.localization.LocalizationSourceRegistry
import fr.xpdustry.distributor.api.plugin.AbstractMindustryPlugin
import java.util.Locale
import kotlin.system.exitProcess
import kotlinx.coroutines.runBlocking

class ImperiumPlugin : AbstractMindustryPlugin() {
private val application = MindustryImperiumApplication(this)
Expand Down Expand Up @@ -137,6 +140,13 @@ class ImperiumPlugin : AbstractMindustryPlugin() {
}
}
}

// TODO This is not clean, find a better way
runBlocking {
application.instances
.get<WebhookMessageSender>()
.send(WebhookMessage(content = "The server has started."))
}
}

override fun onExit() {
Expand All @@ -152,6 +162,11 @@ private class MindustryImperiumApplication(private val plugin: ImperiumPlugin) :
if (exited) return
exited = true
super.exit(status)
runBlocking {
instances
.get<WebhookMessageSender>()
.send(WebhookMessage(content = "The server has exit with $status code."))
}
when (status) {
ExitStatus.EXIT,
ExitStatus.INIT_FAILURE -> Core.app.exit()
Expand Down

0 comments on commit d2dd3a9

Please sign in to comment.