Skip to content

Commit

Permalink
Latest v7
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Oct 30, 2024
2 parents df9952e + f0af61e commit 1ddb950
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 199 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@ core/assets/logicids.dat
jdks/

# Kotlin
.kotlin/
.kotlin/
fooKotlinScriptSupport.jar
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript{
arcModule = { String name ->
//skip to last submodule
name = name.substring(name.lastIndexOf(':') + 1)
return "com.github.mindustry-antigrief${localArc ? "" : ".Arc"}:$name:$arcHash"
return "com.github.mindustry-antigrief${localArc ? "" : ".arc"}:$name:$arcHash"
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
dependencies {
val arcHash = Properties(20).apply { load(file("../gradle.properties").inputStream()) }["archash"]
val localArc = File(rootDir.parentFile.parent, "Arc").exists() && !project.hasProperty("noLocalArc")
implementation("com.github.mindustry-antigrief${if (localArc) "" else ".Arc"}:arc-core:$arcHash")
implementation("com.github.mindustry-antigrief${if (localArc) "" else ".arc"}:arc-core:$arcHash")
}

// I swear gradle is the worst
Expand Down
3 changes: 3 additions & 0 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,16 @@ client.autotransfer = Auto Transfer
# CLaJ related
client.claj.join = Join via CLaJ
client.claj.info = Copy Link and Join allows you to join friend's games without steam or port forwarding. See https://mindustry.dev/CLaJ for more info.
client.claj.joinvalid = CLaJ link valid!
client.claj.manage = Manage CLaJ Invites
client.claj.generate = Create CLaJ Link
client.claj.link = Input CLaJ Link:
client.claj.portnotfound = CLaJ link missing port
client.claj.colonnotfound = CLaJ link missing colon
client.claj.wrongkeylength = CLaJ link is wrong length
client.claj.missingprefix = CLaJ link missing prefix
client.claj.ping.error = Error contacting server.
client.claj.ping.pending = Not yet contacted.

# Editor
client.editor.autosaved = Autosaved!
Expand Down
4 changes: 4 additions & 0 deletions core/assets/bundles/bundle_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ client.autotransfer = 自動転送
# CLaJ related
client.claj.join = CLaJ 経由で参加
client.claj.info = Copy Link and Join を使用すると、Steam やポート転送なしに友達のゲームに参加できます。詳細については https://mindustry.dev/CLaJ を参照してください。
client.claj.joinvalid = 有効なCLaJリンク!
client.claj.manage = CLaJ 招待を管理
client.claj.generate = CLaJ リンクを作成
client.claj.link = CLaJ リンクを入力してください:
client.claj.portnotfound = CLaJ リンクにポートがありません
client.claj.colonnotfound = CLaJ リンクにコロンがありません
client.claj.wrongkeylength = CLaJ リンクの長さが正しくありません
client.claj.missingprefix = CLaJ リンクに接頭辞がありません
client.claj.ping.error = サーバーへの接続エラー
client.claj.ping.pending = まだ接続されていません

# Editor
client.editor.autosaved = 自動保存されました!
client.editor.mapautosave = 自動保存を保持する:[lightgray]x[] 回
Expand Down
1 change: 1 addition & 0 deletions core/assets/bundles/bundle_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ client.autotransfer = 自动传输资源
# CLaJ related
client.claj.join = 通过CLaJ加入
client.claj.info = 复制链接并允许你无需Steam或端口映射来加入朋友的游戏. 详见https://mindustry.dev/CLaJ.
client.claj.joinvalid = 无效的CLaJ链接!
client.claj.manage = 管理CLaJ邀请
client.claj.generate = 创建CLaJ链接
client.claj.link = 导入CLaJ链接:
Expand Down
1 change: 0 additions & 1 deletion core/assets/scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ importPackage(Packages.arc)
importPackage(Packages.arc.audio)
importPackage(Packages.arc.files)
importPackage(Packages.arc.flabel)
importPackage(Packages.arc.flabel.effects)
importPackage(Packages.arc.func)
importPackage(Packages.arc.graphics)
importPackage(Packages.arc.graphics.g2d)
Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/Vars.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public static void init(){
bases = new BaseRegistry();
logicVars = new GlobalVars();
javaPath =
new Fi(OS.prop("java.home")).child("bin/java").exists() ? new Fi(OS.prop("java.home")).child("bin/java").absolutePath() :
new Fi(OS.prop("java.home")).child("bin/java").exists() ? new Fi(OS.prop("java.home")).child("bin/java").absolutePath() : // Unix
new Fi(OS.prop("java.home")).child("bin/java.exe").exists() ? new Fi(OS.prop("java.home")).child("bin/java.exe").absolutePath() : // Windows
Core.files.local("jre/bin/java").exists() ? Core.files.local("jre/bin/java").absolutePath() : // Unix
Core.files.local("jre/bin/java.exe").exists() ? Core.files.local("jre/bin/java.exe").absolutePath() : // Windows
"java"; // Fallback
Expand Down
15 changes: 3 additions & 12 deletions core/src/mindustry/client/ClientLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import arc.util.*
import mindustry.Vars.*
import mindustry.client.ClientVars.*
import mindustry.client.antigrief.*
import mindustry.client.communication.*
import mindustry.client.navigation.*
import mindustry.client.navigation.Navigation.stopFollowing
import mindustry.client.ui.*
Expand Down Expand Up @@ -129,7 +128,7 @@ class ClientLogic {
}

if (settings.getBool("discordrpc")) platform.startDiscord()
if (settings.getBool("mobileui")) mobile = !mobile
if (settings.getBool("mobileui") && !OS.hasProp("nomobileui")) mobile = !mobile
if (settings.getBool("viruswarnings")) LExecutor.virusWarnings = true
UnitType.drawAllItems = settings.getBool("drawallitems")
UnitType.formationAlpha = settings.getInt("formationopacity") / 100f
Expand All @@ -141,14 +140,6 @@ class ClientLogic {
Navigation.navigator.init()

Migrations().runMigrations()

if (isDeveloper()) {
register("update <name/id...>") { args, _ ->
val name = args.joinToString(" ")
val player = Groups.player.find { it.id == Strings.parseInt(name) } ?: Groups.player.minByOrNull { biasedLevenshtein(Strings.stripColors(it.name), name) }!!
Main.send(CommandTransmission(CommandTransmission.Commands.UPDATE, Main.keyStorage.cert() ?: return@register, player))
}
}
}

Events.on(PlayerJoin::class.java) { e -> // Run when a player joins the server
Expand All @@ -172,7 +163,7 @@ class ClientLogic {
Events.on(GameOverEventClient::class.java) {
if (net.client()) {
// Afk players will start mining at the end of a game (kind of annoying but worth it)
if ((Navigation.currentlyFollowing as? BuildPath)?.mineItems == null) Navigation.follow(MinePath(args = "copper lead beryllium graphite", newGame = true))
if ((Navigation.currentlyFollowing as? BuildPath)?.mineItems == null && !CustomMode.defense()) Navigation.follow(MinePath(args = "copper lead beryllium graphite", newGame = true))

// Save maps on game over if the setting is enabled
if (settings.getBool("savemaponend")) control.saves.addSave(state.map.name())
Expand All @@ -196,7 +187,7 @@ class ClientLogic {
// Warn about turrets that are built with an enemy void in range
Events.on(BlockBuildBeginEventBefore::class.java) { event ->
val block = event.newBlock
if (block !is Turret) return@on
if (!((block as? Turret)?.targetGround ?: false)) return@on
if (event.unit?.player == null) return@on
if (state.rules.infiniteResources) return@on

Expand Down
3 changes: 2 additions & 1 deletion core/src/mindustry/client/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fun setupCommands() {
}
}

player.sendMessage("client.command.count.success"[type.localizedName, total, cap, free, freeFlagged, flagged, unflagged, players, command, logic, logicFlagged])
player.sendMessage("client.command.count.success".bundle(type.localizedName, total, cap, free, freeFlagged, flagged, unflagged, players, command, logic, logicFlagged))
}

// FINISHME: Add unit control/select command(s)
Expand Down Expand Up @@ -410,6 +410,7 @@ fun setupCommands() {
Build Cost (Refund): ${rules.buildCostMultiplier}x (${rules.deconstructRefundMultiplier}x)
Block Health (Damage): ${rules.blockHealth(team)}x (${rules.blockDamage(team)}x)
Unit Damage: ${rules.unitDamage(team)}x
Unit Health: ${rules.unitHealth(team)}x
Core Capture: ${rules.coreCapture}
Core Incinerates: ${rules.coreIncinerates}
Core Modifies Unit Cap: ${rules.unitCapVariable}
Expand Down
4 changes: 2 additions & 2 deletions core/src/mindustry/client/claj/ClajJoinDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import mindustry.ui.*
import mindustry.ui.dialogs.*

class ClajJoinDialog : BaseDialog("@client.claj.join") {
var lastLink = "CLaJLink#ip:port"
var lastLink = ""
var valid = false
var output: String? = null

init {
cont.add("@client.claj.link").padRight(5f).right()
cont.field(lastLink) { link -> setLink(link) }.size(550f, 54f).maxTextLength(100).valid { link -> setLink(link) }.left() // FINISHME: Cursed
cont.field(lastLink) { link -> setLink(link) }.size(550f, 54f).maxTextLength(100).valid { link -> setLink(link) }.left().get().messageText = "CLaJLink#ip:port" // FINISHME: Cursed
cont.row().label { if (lastLink.isBlank()) "[grey]${Core.bundle["client.claj.info"]}" else output }.fillX().wrap().center().colspan(2).get().clicked { Menus.openURI("https://mindustry.dev/CLaJ") }
addCloseButton()
buttons.button("@ok") {
Expand Down
14 changes: 10 additions & 4 deletions core/src/mindustry/client/claj/ClajManagerDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import arc.scene.ui.layout.*
import arc.util.*
import mindustry.*
import mindustry.client.claj.ClajSupport.createRoom
import mindustry.client.utils.*
import mindustry.gen.*
import mindustry.ui.*
import mindustry.ui.dialogs.*

class ClajManagerDialog : BaseDialog("@client.claj.manage") {
var serverIP = "claj.phoenix-network.dev"
var serverPort = 4000
var serverIP = "claj.mindustry.dev"
var serverPort = 9000
var lastPing = -1
var lastPingAt = Time.millis() // Prevents ping during init block
private var room: Room? = null

init { // FINISHME: Clean up this mess. Also implement proper claj banning and such since that's currently impossible
Expand All @@ -24,9 +27,11 @@ class ClajManagerDialog : BaseDialog("@client.claj.manage") {
list.update { list.cells.retainAll { cell -> cell.get() != null } } // Awful.
list.defaults().width(750F).padBottom(8f)
rooms.add(list).row()
rooms.field("claj.phoenix-network.dev:4000") { address: String ->
rooms.field("$serverIP:$serverPort") { address: String ->
serverIP = address.substringBefore(':')
serverPort = Strings.parseInt(address.substringAfter(':'))
lastPing = -1
lastPingAt = Time.millis() // Delay any pings by a second to prevent spam pinging while typing
}.maxTextLength(100).valid { address -> address.contains(':') }.row()
rooms.button("@client.claj.generate") {
try {
Expand All @@ -35,7 +40,8 @@ class ClajManagerDialog : BaseDialog("@client.claj.manage") {
} catch (ignored: Throwable) {
Vars.ui.showErrorMessage(ignored.message)
}
}.disabled { list.children.size >= 4 }.padTop(8f)
}.disabled { list.children.size >= 4 }.padTop(8f).row()
rooms.label { if (Time.timeSinceMillis(lastPingAt) > 1000) { lastPingAt = Time.millis(); Vars.net.pingHost(serverIP, serverPort, { lastPing = it.ping }) { lastPing = -2 } }; if (lastPing == -2) "[scarlet]" + "client.claj.ping.error".bundle() else if (lastPing == -1) "[orange]" + "client.claj.ping.pending".bundle() else "ping".bundle(lastPing) }
}.height(550f).row()
val l = cont.labelWrap("@client.claj.info").labelAlign(2, 8).padTop(16f).width(400f).get()
l.style.fontColor = Color.lightGray
Expand Down
6 changes: 0 additions & 6 deletions core/src/mindustry/client/claj/ClajSupport.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package mindustry.client.claj

import arc.*
import arc.func.*
import arc.net.*
import arc.net.Server
import arc.scene.*
import arc.scene.ui.*
import arc.struct.*
import arc.util.*
import arc.util.serialization.*
import arc.util.serialization.Json.*
import mindustry.*
import mindustry.client.claj.ClajManagerDialog.*
import mindustry.client.utils.*
import mindustry.game.*
import mindustry.game.EventType.*
import mindustry.gen.*
import mindustry.io.*
Expand Down
18 changes: 16 additions & 2 deletions core/src/mindustry/client/crypto/KeyStorage.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package mindustry.client.crypto

import arc.*
import arc.util.*
import arc.util.serialization.*
import mindustry.*
import mindustry.client.*
import mindustry.client.communication.*
import mindustry.client.utils.*
import mindustry.gen.*
import java.io.*
import java.math.*
import java.security.*
Expand Down Expand Up @@ -36,7 +40,7 @@ open class KeyStorage(val directory: File) {
}

init {
Vars.mainExecutor.execute {
Vars.mainExecutor.submit {
val file = directory.resolve("keys")
val aliasFile = directory.resolve("aliases")
if (file.exists()) {
Expand Down Expand Up @@ -66,6 +70,16 @@ open class KeyStorage(val directory: File) {
}
}
loaded = true

Core.app.post {
if (isDeveloper()) {
register("update <name/id...>") { args, _ ->
val name = args.joinToString(" ")
val player = Groups.player.find { it.id == Strings.parseInt(name) } ?: Groups.player.minByOrNull { biasedLevenshtein(Strings.stripColors(it.name), name) }!!
Main.send(CommandTransmission(CommandTransmission.Commands.UPDATE, Main.keyStorage.cert() ?: return@register, player))
}
}
}
}
}

Expand Down Expand Up @@ -109,7 +123,7 @@ open class KeyStorage(val directory: File) {
}

fun cert(): X509Certificate? {
return store.getCertificate("cert") as? X509Certificate
return if (!loaded) null else store.getCertificate("cert") as? X509Certificate
}

fun chain(): List<X509Certificate>? {
Expand Down
12 changes: 6 additions & 6 deletions core/src/mindustry/client/navigation/AStarNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ object AStarNavigator : Navigator() {
tileWidth = ceil(width / tilesize).toInt()
tileHeight = ceil(height / tilesize).toInt()

start.clamp(0f, 0f, width, height)
end.clamp(0f, 0f, width, height)
start.clamp(0f, 0f, width, height - 1f)
end.clamp(0f, 0f, width, height - 1f)

//Reset
startX = World.toTile(start.x).coerceIn(0, tileWidth)
startY = World.toTile(start.y).coerceIn(0, tileHeight)
endX = World.toTile(end.x).coerceIn(0, tileWidth)
endY = World.toTile(end.y).coerceIn(0, tileHeight)
startX = World.toTile(start.x).coerceIn(0, tileWidth - 1)
startY = World.toTile(start.y).coerceIn(0, tileHeight - 1)
endX = World.toTile(end.x).coerceIn(0, tileWidth - 1)
endY = World.toTile(end.y).coerceIn(0, tileHeight - 1)

if (!gridSize.equals(tileWidth, tileHeight)) {
grid = Array(tileWidth * tileHeight) { Cell(it % tileWidth, it / tileWidth) }
Expand Down
14 changes: 7 additions & 7 deletions core/src/mindustry/client/navigation/AStarNavigatorOptimised.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object AStarNavigatorOptimised : Navigator() {
private val pool = Pools.get(PositionWaypoint::class.java, ::PositionWaypoint)
private var grid: Array<Cell> = emptyArray()
private var gridSize = Point2()
private var open = BinaryHeap<Cell>(65_536, false)
private var open = BinaryHeap<Cell>(1024, false)
private var startX = -1
private var startY = -1
private var endX = 0
Expand Down Expand Up @@ -242,14 +242,14 @@ object AStarNavigatorOptimised : Navigator() {
tileWidth = ceil(width / tilesize).toInt()
tileHeight = ceil(height / tilesize).toInt()

start.clamp(0f, 0f, width, height)
end.clamp(0f, 0f, width, height)
start.clamp(0f, 0f, width - 1f, height - 1f)
end.clamp(0f, 0f, width - 1f, height - 1f)

//Reset
startX = World.toTile(start.x).coerceIn(0, tileWidth)
startY = World.toTile(start.y).coerceIn(0, tileHeight)
endX = World.toTile(end.x).coerceIn(0, tileWidth)
endY = World.toTile(end.y).coerceIn(0, tileHeight)
startX = World.toTile(start.x).coerceIn(0, tileWidth - 1)
startY = World.toTile(start.y).coerceIn(0, tileHeight - 1)
endX = World.toTile(end.x).coerceIn(0, tileWidth - 1)
endY = World.toTile(end.y).coerceIn(0, tileHeight - 1)

if (!gridSize.equals(tileWidth, tileHeight)) {
grid = Array(tileWidth * tileHeight) { Cell(it % tileWidth, it / tileWidth) }
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/client/utils/ClientUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fun <T> Iterable<T>.unescape(escapement: T, vararg escape: T): List<T> {
}

fun String.bundle(): String = Core.bundle[removePrefix("@")]
operator fun String.get(vararg args: Any?): String = Core.bundle.formatKt(removePrefix("@"), args)
fun String.bundle(vararg args: Any?): String = Core.bundle.formatKt(removePrefix("@"), args)

val X509Certificate.readableName: String
get() = subjectX500Principal.name.removePrefix("CN=")
Expand Down
Loading

0 comments on commit 1ddb950

Please sign in to comment.