Skip to content

Commit

Permalink
chore: Do some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Oct 5, 2023
1 parent 424b7f1 commit 210c32b
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 23 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ Then you can start the discord bot by running `./gradlew imperium-discord:runImp

> If it's the first time you run it, it will automatically download mindustry assets from GitHub,
> this might take less than 2 minutes. (Or more if you have potato internet `;-;`)

## Limitations

- It will crash if you it as a local steam server.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spotless {
}
}

// TODO Kyori enables javadoc, but we don't want that with a Kotlin project
// Kyori enables javadoc, but we don't want that with a Kotlin project
tasks.javadocJar {
enabled = false
outputs.files()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ data class ImperiumConfig(
val language: Locale = Locale.ENGLISH,
val storage: StorageConfig = StorageConfig.Minio(),
val security: SecurityConfig = SecurityConfig(),
// TODO Warn when the id is 0
val generatorId: Int = 0,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import kotlin.reflect.jvm.jvmName

class RabbitmqMessenger(private val config: ImperiumConfig, private val metadata: ImperiumMetadata) : Messenger, ImperiumApplication.Listener {

// TODO Use json ?
private val kryo = Kryo().apply {
instantiatorStrategy = StdInstantiatorStrategy()
setRegistrationRequired(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class SimpleSnowflakeGenerator(config: ImperiumConfig) : ImperiumSnowflakeGenera
Options(Options.SequenceOverflowStrategy.SPIN_WAIT),
)

init {
if (config.generatorId == 0) {
logger.warn("The generator-id is 0, this config needs an explicit value.")
}
}

override suspend fun generate(): ImperiumSnowflake =
withContext(ImperiumScope.MAIN.coroutineContext) { generator.next() }

Expand All @@ -58,5 +64,6 @@ class SimpleSnowflakeGenerator(config: ImperiumConfig) : ImperiumSnowflakeGenera
// The creation date of the chaotic neutral server
internal val IMPERIUM_EPOCH = Instant.ofEpochMilli(1543879632378L)
internal val IMPERIUM_EPOCH_OFFSET = Duration.between(Instant.EPOCH, IMPERIUM_EPOCH)
private val logger by LoggerDelegate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import java.nio.LongBuffer
import java.util.Base64
import java.util.Locale

// TODO: Cleanup this file ?

fun String.capitalize(locale: Locale = Locale.ROOT, all: Boolean = false): String {
if (all) {
return split(" ").joinToString(" ") { it.capitalize(locale) }
Expand All @@ -44,4 +42,5 @@ fun ByteArray.toBase64(): String =
Base64.getEncoder().encodeToString(this)

fun Long.toBase62(): String = Base62.encode(this)

fun String.toLongFromBase62(): Long = LongBuffer.allocate(1).also { buffer -> Base62.decode(this, buffer) }.get(0)
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ data class Punishment(
enum class Type {
FREEZE, MUTE, KICK, BAN;

// TODO Better name ?
fun isKick() = this == KICK || this == BAN
}
}
1 change: 0 additions & 1 deletion imperium-mindustry/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ tasks.shadowJar {
archiveClassifier.set("plugin")

/*
// TODO KOTLIN RELOCATION IS BUGGY, THIS IS VERY ANNOYING (CAUSE: DOES NOT RELOCATE KOTLIN METADATA)
doFirst {
RelocationUtil.configureRelocation(this@shadowJar, "com.xpdustry.imperium.shadow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.xpdustry.imperium.mindustry.chat.BridgeChatMessageListener
import com.xpdustry.imperium.mindustry.chat.ChatMessageListener
import com.xpdustry.imperium.mindustry.chat.ChatTranslatorListener
import com.xpdustry.imperium.mindustry.command.ImperiumPluginCommandManager
import com.xpdustry.imperium.mindustry.config.ConventionListener
import com.xpdustry.imperium.mindustry.history.HistoryCommand
import com.xpdustry.imperium.mindustry.listener.ConventionListener
import com.xpdustry.imperium.mindustry.security.AdminRequestListener
import com.xpdustry.imperium.mindustry.security.GatekeeperListener
import com.xpdustry.imperium.mindustry.security.LogicImageAnalysisListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.xpdustry.imperium.mindustry.listener
package com.xpdustry.imperium.mindustry.config

import com.xpdustry.imperium.common.application.ImperiumApplication
import com.xpdustry.imperium.common.config.ServerConfig
Expand All @@ -27,7 +27,6 @@ import fr.xpdustry.distributor.api.scheduler.MindustryTimeUnit
import fr.xpdustry.distributor.api.scheduler.TaskHandler
import mindustry.net.Administration

// TODO Move to better package
class ConventionListener(instances: InstanceManager) : ImperiumApplication.Listener {
private val config = instances.get<ServerConfig.Mindustry>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ import java.util.function.Consumer

// TODO
// - Add interactive mode like the "/inspector" command ?
// - Move the rendering logic to a separate class ?
class HistoryCommand(instances: InstanceManager) : ImperiumApplication.Listener {
private val history: BlockHistory = instances.get()
private val clientCommandManager: ImperiumPluginCommandManager = instances.get("client")
private val serverCommandManager: ImperiumPluginCommandManager = instances.get("server")
private val history = instances.get<BlockHistory>()
private val clientCommandManager = instances.get<ImperiumPluginCommandManager>("client")
private val serverCommandManager = instances.get<ImperiumPluginCommandManager>("server")

override fun onImperiumInit() {
withCommandManagers { manager ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class GatekeeperListener(instances: InstanceManager) : ImperiumApplication.Liste
private fun interceptPlayerConnection(con: NetConnection, packet: Packets.ConnectPacket, pipeline: GatekeeperPipeline) {
if (con.kicked) return

// TODO Add steam support
if (con.address.startsWith("steam:")) {
packet.uuid = con.address.substring("steam:".length)
}
Expand Down Expand Up @@ -120,7 +119,6 @@ private fun interceptPlayerConnection(con: NetConnection, packet: Packets.Connec
val mods = packet.mods.copy()
val missing = Vars.mods.getIncompatibility(mods)
if (!mods.isEmpty || !missing.isEmpty) {
// TODO Localize this message
// can't easily be localized since kick reasons can't have formatted text with them
val result = StringBuilder("[accent]Incompatible mods![]\n\n")
if (!missing.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.xpdustry.imperium.common.security.Punishment
import com.xpdustry.imperium.common.security.PunishmentManager
import com.xpdustry.imperium.mindustry.command.ImperiumPluginCommandManager
import com.xpdustry.imperium.mindustry.history.BlockHistory
import com.xpdustry.imperium.mindustry.misc.PlayerMap
import com.xpdustry.imperium.mindustry.misc.runMindustryThread
import fr.xpdustry.distributor.api.event.EventHandler
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -84,8 +85,7 @@ class LogicImageAnalysisListener(instances: InstanceManager) : ImperiumApplicati
// TODO Implement delegate property backed by Core.settings so it persists across restarts
// private var debug = false

// TODO Implement player map
private val debugPlayers = mutableSetOf<Player>()
private val debugPlayers = PlayerMap<Boolean>(instances.get())

override fun onImperiumInit() {
drawerJob = startProcessing(drawerQueue)
Expand All @@ -95,11 +95,12 @@ class LogicImageAnalysisListener(instances: InstanceManager) : ImperiumApplicati
literal("debug")
commandDescription("Show the location of the clusters")
handler {
if (debugPlayers.add(it.sender.player)) {
it.sender.sendMessage("Image analysis debug mode is now enabled")
} else {
if (debugPlayers[it.sender.player] == true) {
debugPlayers.remove(it.sender.player)
it.sender.sendMessage("Image analysis debug mode is now disabled")
} else {
debugPlayers[it.sender.player] = true
it.sender.sendMessage("Image analysis debug mode is now enabled")
}
}
}
Expand All @@ -109,7 +110,7 @@ class LogicImageAnalysisListener(instances: InstanceManager) : ImperiumApplicati
delay(1.seconds)
runMindustryThread {
if (Vars.state.isPlaying) {
for (player in debugPlayers) {
for (player in debugPlayers.entries.filter { it.second }.map { it.first }) {
renderCluster(player, displays, Color.PINK)
renderCluster(player, canvases, Color.YELLOW)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ import kotlin.time.Duration.Companion.minutes

private val VOTEKICK_TARGET = stateKey<Player>("votekick_target")

// TODO Implement Session per team for PVP
// TODO
// - Implement Session per team for PVP
// - Implement rate limit (FIX RATELIMITER)
class VoteKickCommand(instances: InstanceManager) : ImperiumApplication.Listener {
private val clientCommands = instances.get<ImperiumPluginCommandManager>("client")
private val plugin = instances.get<MindustryPlugin>()
Expand Down

0 comments on commit 210c32b

Please sign in to comment.