Skip to content

Commit

Permalink
Merge branch 'xpdustry:master' into christmas-event
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonP01 authored Dec 27, 2024
2 parents 7286fbd + 09101e1 commit 4f6c46f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down
40 changes: 40 additions & 0 deletions imperium-build-logic/src/main/kotlin/GenerateImperiumChangelog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.util.regex.Pattern
import net.kyori.indra.git.IndraGitExtension
import org.eclipse.jgit.lib.Constants
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.getByType

@CacheableTask
open class GenerateImperiumChangelog : DefaultTask() {

@OutputFile
val target: RegularFileProperty = project.objects.fileProperty()

@TaskAction
fun generate() {
val git = project.rootProject.extensions.getByType<IndraGitExtension>().git()!!
val latest = git.repository.resolve("v" + project.rootProject.file("VERSION.txt").readText().trim())!!
val head = git.repository.resolve(Constants.HEAD)!!
target.get().asFile.writer().buffered().use { writer ->
git.log().addRange(latest, head).call().forEach { commit ->
val message = commit.shortMessage ?: return@forEach
val matcher = ACCEPTED_SUFFIX.matcher(message)
if (!matcher.find()) return@forEach
writer.write(matcher.group("verb").lowercase())
writer.write("/")
writer.write(matcher.group("scope")?.lowercase() ?: "common")
writer.write("/")
writer.write(message.split(':', limit = 2)[1].trim())
writer.newLine()
}
}
}

companion object {
private val ACCEPTED_SUFFIX = Pattern.compile("^(?<verb>feat|fix)(\\((?<scope>mindustry|discord)\\))?:", Pattern.CASE_INSENSITIVE)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id("net.kyori.indra.git")
}

tasks.register("incrementVersionFile") {
doLast { file("VERSION.txt").writeText(project.version.toString()) }
}
Expand Down
6 changes: 5 additions & 1 deletion imperium-mindustry/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ val generateResources by tasks.registering {
}
}

val generateChangelog by tasks.registering(GenerateImperiumChangelog::class) {
target = temporaryDir.resolve("imperium-changelog.txt")
}

tasks.shadowJar {
archiveFileName.set("imperium-mindustry.jar")
archiveClassifier.set("plugin")

from(generateResources)
from(generateResources, generateChangelog)

from(rootProject.file("LICENSE.md")) {
into("META-INF")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.xpdustry.imperium.mindustry.control.ControlListener
import com.xpdustry.imperium.mindustry.event.EventListener
import com.xpdustry.imperium.mindustry.game.AlertListener
import com.xpdustry.imperium.mindustry.game.AntiGriefListener
import com.xpdustry.imperium.mindustry.game.ChangelogCommand
import com.xpdustry.imperium.mindustry.game.GameListener
import com.xpdustry.imperium.mindustry.game.ImperiumLogicListener
import com.xpdustry.imperium.mindustry.game.LogicListener
Expand Down Expand Up @@ -190,7 +191,8 @@ class ImperiumPlugin : AbstractMindustryPlugin() {
SaveCommand::class,
AntiGriefListener::class,
FlexListener::class,
MetricsListener::class)
MetricsListener::class,
ChangelogCommand::class)
.forEach(application::register)

val gamemode = application.instances.get<ImperiumConfig>().mindustry.gamemode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ class CommandAnnotationScanner(
annotation: ImperiumCommand
) {
var names = annotation.name.toNameWithAliases()
val base = mutableListOf(names.first)

val path = mutableListOf(names.first)
var builder =
manager
.commandBuilder(names.first, createLiteralDescription(base), *names.second)
.commandBuilder(names.first, createLiteralDescription(path), *names.second)
.permission(createPermission(function, annotation))
.commandDescription(createLiteralDescription(base))

for (rest in annotation.path.drop(1)) {
names = rest.toNameWithAliases()
base += names.first
builder = builder.literal(names.first, createLiteralDescription(base), *names.second)
path += names.first
builder = builder.literal(names.first, createLiteralDescription(path), *names.second)
}

builder = builder.commandDescription(createLiteralDescription(path))

for (parameter in function.parameters.drop(1)) {
if (parameter.type.classifier == CommandSender::class) continue
val flag = parameter.findAnnotation<Flag>()
builder =
if (flag == null) {
builder.argument(createCommandComponent<Any>(manager, parameter, base))
builder.argument(createCommandComponent<Any>(manager, parameter, path))
} else {
builder.flag(createFlagComponent<Any>(manager, parameter, base, flag))
builder.flag(createFlagComponent<Any>(manager, parameter, path, flag))
}
}

Expand Down Expand Up @@ -178,7 +178,7 @@ class CommandAnnotationScanner(
private fun <T : Any> createCommandComponent(
manager: MindustryCommandManager<CommandSender>,
parameter: KParameter,
base: List<String>
path: List<String>
): TypedCommandComponent<CommandSender, T> {
val token = TypeToken.get(parameter.type.javaType) as TypeToken<T>
val parameters = manager.parserRegistry().parseAnnotations(token, parameter.annotations)
Expand All @@ -189,7 +189,7 @@ class CommandAnnotationScanner(
?: error("No parser found for type: ${parameter.type.javaType}"))
.valueType(token)
.required(!parameter.isOptional)
.description(createArgumentDescription(base, parameter.name!!))
.description(createArgumentDescription(path, parameter.name!!))
.commandManager(manager)
.build()
}
Expand All @@ -198,7 +198,7 @@ class CommandAnnotationScanner(
private fun <T : Any> createFlagComponent(
manager: MindustryCommandManager<CommandSender>,
parameter: KParameter,
base: List<String>,
path: List<String>,
flag: Flag
): CommandFlag<T> {
if (parameter.type.classifier != Boolean::class && !parameter.isOptional) {
Expand All @@ -207,11 +207,11 @@ class CommandAnnotationScanner(
val builder =
CommandFlag.builder<CommandSender>(parameter.name!!)
.withAliases(if (flag.alias.isNotBlank()) listOf(flag.alias) else emptyList())
.withDescription(createArgumentDescription(base, parameter.name!!))
.withDescription(createArgumentDescription(path, parameter.name!!))
return if (parameter.type.classifier == Boolean::class && !parameter.isOptional) {
builder.build() as CommandFlag<T>
} else {
builder.withComponent(createCommandComponent<T>(manager, parameter, base)).build()
builder.withComponent(createCommandComponent<T>(manager, parameter, path)).build()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Imperium, the software collection powering the Chaotic Neutral network.
* Copyright (C) 2024 Xpdustry
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.game

import com.xpdustry.distributor.api.command.CommandSender
import com.xpdustry.distributor.api.component.Component
import com.xpdustry.distributor.api.component.ListComponent.components
import com.xpdustry.distributor.api.component.TextComponent.newline
import com.xpdustry.distributor.api.component.TextComponent.text
import com.xpdustry.distributor.api.component.style.ComponentColor
import com.xpdustry.imperium.common.application.ImperiumApplication
import com.xpdustry.imperium.common.command.ImperiumCommand
import com.xpdustry.imperium.mindustry.command.annotation.ClientSide
import com.xpdustry.imperium.mindustry.command.annotation.ServerSide
import com.xpdustry.imperium.mindustry.translation.GRAY
import java.io.Reader

class ChangelogCommand : ImperiumApplication.Listener {

private val changelog: Component

init {
val features = ArrayList<String>()
val bugfixes = ArrayList<String>()
javaClass.classLoader
.getResourceAsStream("imperium-changelog.txt")!!
.reader()
.use(Reader::readLines)
.forEach { entry ->
val (verb, scope, message) = entry.split('/', limit = 3)
if (scope == "common" || scope == "mindustry") {
when (verb) {
"feat" -> features += message
"fix" -> bugfixes += message
}
}
}

val builder = components()
val none = text("None", GRAY)
builder.append(newline())
builder.append(text("Features and Changes", ComponentColor.ACCENT))
builder.append(newline())
if (features.isNotEmpty()) {
features.forEach { feature -> builder.append(text(" - "), text(feature), newline()) }
} else {
builder.append(none)
}
builder.append(text("Bugfixes", ComponentColor.ACCENT))
builder.append(newline())
if (bugfixes.isNotEmpty()) {
bugfixes.forEach { fix -> builder.append(text(" - "), text(fix), newline()) }
} else {
builder.append(none)
}
changelog = builder.build()
}

@ImperiumCommand(["changelog"])
@ClientSide
@ServerSide
fun onChangelogCommand(sender: CommandSender) {
if (sender.isPlayer) {
sender.audience.sendAnnouncement(changelog)
} else {
sender.audience.sendMessage(changelog)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import arc.util.Time
import arc.util.io.Writes
import com.google.common.net.InetAddresses
import com.xpdustry.distributor.api.Distributor
import com.xpdustry.distributor.api.component.TextComponent.text
import com.xpdustry.distributor.api.component.style.ComponentColor
import com.xpdustry.distributor.api.player.MUUID
import com.xpdustry.distributor.api.util.Priority
import com.xpdustry.imperium.common.application.ImperiumApplication
import com.xpdustry.imperium.common.async.ImperiumScope
Expand Down Expand Up @@ -129,6 +132,16 @@ private fun interceptPlayerConnection(
return
}

if (packet.uuid == null || packet.usid == null) {
audience.kick(KickReason.idInUse, Duration.ZERO, false)
return
}

if (!MUUID.isUuid(packet.uuid) || !MUUID.isUsid(packet.usid)) {
audience.kick(text("Invalid uuid or usid", ComponentColor.RED), Duration.ZERO, false)
return
}

// We do not want to save the data of DDOSers, so we postpone the saving of the player info
val info =
Vars.netServer.admins.getInfoOptional(packet.uuid)
Expand All @@ -137,11 +150,6 @@ private fun interceptPlayerConnection(
con.hasBegunConnecting = true
con.mobile = packet.mobile

if (packet.uuid == null || packet.usid == null) {
audience.kick(KickReason.idInUse, Duration.ZERO, false)
return
}

if (Vars.netServer.admins.isIDBanned(packet.uuid)) {
con.kick(KickReason.banned)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ imperium.command.[ws.cancel].description=Cancels a wave skip vote
imperium.command.[ws.n].description=Vote to not skip waves
imperium.command.[ws.y].description=Vote to skip waves
imperium.command.[ws].description=Participate in the wave skip vote
imperium.command.[changelog].description=Shows the recent changes of Imperium
imperium.gui.close=Close
imperium.gui.back=Back
imperium.gui.submit=Submit
Expand Down

0 comments on commit 4f6c46f

Please sign in to comment.