From ab199633f89c017d887bbc1423ec40fa3a5d27ad Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 23 Oct 2019 21:47:08 -0400 Subject: [PATCH] Check version when connecting --- core/src/io/anuke/mindustry/Vars.java | 1 - core/src/io/anuke/mindustry/io/MapIO.java | 2 +- .../io/anuke/mindustry/net/CrashSender.java | 28 +++++++++---------- .../src/io/anuke/mindustry/net/NetworkIO.java | 4 +-- core/src/io/anuke/mindustry/net/Packets.java | 10 +++---- .../mindustry/ui/dialogs/HostDialog.java | 2 +- .../mindustry/ui/dialogs/JoinDialog.java | 24 ++++++++++------ .../ui/dialogs/SettingsMenuDialog.java | 2 +- .../mindustry/ui/fragments/MenuFragment.java | 5 ++-- .../mindustry/desktop/DesktopLauncher.java | 2 +- .../anuke/mindustry/desktop/steam/SNet.java | 2 +- .../anuke/mindustry/server/ServerControl.java | 6 ++-- 12 files changed, 47 insertions(+), 41 deletions(-) diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index 4d1cf2c505..d5c4a980f5 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -10,7 +10,6 @@ import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; import io.anuke.mindustry.ai.*; import io.anuke.mindustry.core.*; -import io.anuke.mindustry.core.Version; import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.effect.*; import io.anuke.mindustry.entities.traits.*; diff --git a/core/src/io/anuke/mindustry/io/MapIO.java b/core/src/io/anuke/mindustry/io/MapIO.java index be198b1f4d..da24c1d8d7 100644 --- a/core/src/io/anuke/mindustry/io/MapIO.java +++ b/core/src/io/anuke/mindustry/io/MapIO.java @@ -6,7 +6,7 @@ import io.anuke.arc.graphics.*; import io.anuke.arc.graphics.Pixmap.*; import io.anuke.arc.util.io.*; import io.anuke.mindustry.content.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.game.*; import io.anuke.mindustry.maps.*; import io.anuke.mindustry.world.*; diff --git a/core/src/io/anuke/mindustry/net/CrashSender.java b/core/src/io/anuke/mindustry/net/CrashSender.java index 804cf9675c..1240c22160 100644 --- a/core/src/io/anuke/mindustry/net/CrashSender.java +++ b/core/src/io/anuke/mindustry/net/CrashSender.java @@ -11,7 +11,7 @@ import io.anuke.arc.util.serialization.*; import io.anuke.arc.util.serialization.JsonValue.*; import io.anuke.arc.util.serialization.JsonWriter.*; import io.anuke.mindustry.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import java.io.*; import java.text.*; @@ -26,23 +26,23 @@ public class CrashSender{ exception.printStackTrace(); //don't create crash logs for custom builds, as it's expected - if(io.anuke.mindustry.core.Version.build == -1 || (System.getProperty("user.name").equals("anuke") && "release".equals(io.anuke.mindustry.core.Version.modifier))) return; + if(Version.build == -1 || (System.getProperty("user.name").equals("anuke") && "release".equals(Version.modifier))) return; //attempt to load version regardless - if(io.anuke.mindustry.core.Version.number == 0){ + if(Version.number == 0){ try{ ObjectMap map = new ObjectMap<>(); PropertiesUtils.load(map, new InputStreamReader(CrashSender.class.getResourceAsStream("/version.properties"))); - io.anuke.mindustry.core.Version.type = map.get("type"); - io.anuke.mindustry.core.Version.number = Integer.parseInt(map.get("number")); - io.anuke.mindustry.core.Version.modifier = map.get("modifier"); + Version.type = map.get("type"); + Version.number = Integer.parseInt(map.get("number")); + Version.modifier = map.get("modifier"); if(map.get("build").contains(".")){ String[] split = map.get("build").split("\\."); - io.anuke.mindustry.core.Version.build = Integer.parseInt(split[0]); - io.anuke.mindustry.core.Version.revision = Integer.parseInt(split[1]); + Version.build = Integer.parseInt(split[0]); + Version.revision = Integer.parseInt(split[1]); }else{ - io.anuke.mindustry.core.Version.build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1; + Version.build = Strings.canParseInt(map.get("build")) ? Integer.parseInt(map.get("build")) : -1; } }catch(Throwable ignored){ ignored.printStackTrace(); @@ -70,7 +70,7 @@ public class CrashSender{ } //do not send exceptions that occur for versions that can't be parsed - if(io.anuke.mindustry.core.Version.number == 0){ + if(Version.number == 0){ return; } @@ -89,10 +89,10 @@ public class CrashSender{ boolean fn = netActive, fs = netServer; //add all relevant info, ignoring exceptions - ex(() -> value.addChild("versionType", new JsonValue(io.anuke.mindustry.core.Version.type))); - ex(() -> value.addChild("versionNumber", new JsonValue(io.anuke.mindustry.core.Version.number))); - ex(() -> value.addChild("versionModifier", new JsonValue(io.anuke.mindustry.core.Version.modifier))); - ex(() -> value.addChild("build", new JsonValue(io.anuke.mindustry.core.Version.build))); + ex(() -> value.addChild("versionType", new JsonValue(Version.type))); + ex(() -> value.addChild("versionNumber", new JsonValue(Version.number))); + ex(() -> value.addChild("versionModifier", new JsonValue(Version.modifier))); + ex(() -> value.addChild("build", new JsonValue(Version.build))); ex(() -> value.addChild("revision", new JsonValue(Version.revision))); ex(() -> value.addChild("net", new JsonValue(fn))); ex(() -> value.addChild("server", new JsonValue(fs))); diff --git a/core/src/io/anuke/mindustry/net/NetworkIO.java b/core/src/io/anuke/mindustry/net/NetworkIO.java index 6555fe0c14..ff61c41f42 100644 --- a/core/src/io/anuke/mindustry/net/NetworkIO.java +++ b/core/src/io/anuke/mindustry/net/NetworkIO.java @@ -2,7 +2,7 @@ package io.anuke.mindustry.net; import io.anuke.arc.*; import io.anuke.arc.util.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.game.*; import io.anuke.mindustry.io.*; @@ -68,7 +68,7 @@ public class NetworkIO{ buffer.putInt(playerGroup.size()); buffer.putInt(state.wave); - buffer.putInt(io.anuke.mindustry.core.Version.build); + buffer.putInt(Version.build); writeString(buffer, Version.type); buffer.put((byte)Gamemode.bestFit(state.rules).ordinal()); diff --git a/core/src/io/anuke/mindustry/net/Packets.java b/core/src/io/anuke/mindustry/net/Packets.java index 240775eefa..0a39de51ef 100644 --- a/core/src/io/anuke/mindustry/net/Packets.java +++ b/core/src/io/anuke/mindustry/net/Packets.java @@ -1,12 +1,12 @@ package io.anuke.mindustry.net; -import io.anuke.arc.Core; +import io.anuke.arc.*; import io.anuke.arc.collection.*; -import io.anuke.arc.util.serialization.Base64Coder; -import io.anuke.mindustry.core.Version; -import io.anuke.mindustry.io.TypeIO; +import io.anuke.arc.util.serialization.*; +import io.anuke.mindustry.core.*; +import io.anuke.mindustry.io.*; -import java.nio.ByteBuffer; +import java.nio.*; /** * Class for storing all packets. diff --git a/core/src/io/anuke/mindustry/ui/dialogs/HostDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/HostDialog.java index 9dc090a303..5ecb7a3e9a 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/HostDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/HostDialog.java @@ -5,7 +5,7 @@ import io.anuke.arc.graphics.*; import io.anuke.arc.scene.ui.*; import io.anuke.arc.util.*; import io.anuke.mindustry.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.ui.*; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java index 6ed444ec1a..b786bc3fe4 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java @@ -10,7 +10,7 @@ import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; import io.anuke.mindustry.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.Packets.*; @@ -105,9 +105,8 @@ public class JoinDialog extends FloatingDialog{ TextButton button = buttons[0] = remote.addButton("[accent]" + server.displayIP(), Styles.cleart, () -> { if(!buttons[0].childrenPressed()){ - if(server.lastHost != null && server.lastHost.version != io.anuke.mindustry.core.Version.build && io.anuke.mindustry.core.Version.build != -1 && server.lastHost.version != -1){ - ui.showInfo("[scarlet]" + (server.lastHost.version > io.anuke.mindustry.core.Version.build ? KickReason.clientOutdated : KickReason.serverOutdated).toString() + "\n[]" + - Core.bundle.format("server.versions", io.anuke.mindustry.core.Version.build, server.lastHost.version)); + if(server.lastHost != null){ + safeConnect(server.ip, server.port, server.lastHost.version); }else{ connect(server.ip, server.port); } @@ -196,13 +195,13 @@ public class JoinDialog extends FloatingDialog{ versionString = Core.bundle.format("server.version", Core.bundle.get("server.custombuild"), ""); }else if(host.version == 0){ versionString = Core.bundle.get("server.outdated"); - }else if(host.version < io.anuke.mindustry.core.Version.build && io.anuke.mindustry.core.Version.build != -1){ + }else if(host.version < Version.build && Version.build != -1){ versionString = Core.bundle.get("server.outdated") + "\n" + Core.bundle.format("server.version", host.version, ""); - }else if(host.version > io.anuke.mindustry.core.Version.build && io.anuke.mindustry.core.Version.build != -1){ + }else if(host.version > Version.build && Version.build != -1){ versionString = Core.bundle.get("server.outdated.client") + "\n" + Core.bundle.format("server.version", host.version, ""); - }else if(host.version == io.anuke.mindustry.core.Version.build && Version.type.equals(host.versionType)){ + }else if(host.version == Version.build && Version.type.equals(host.versionType)){ //not important versionString = ""; }else{ @@ -314,7 +313,7 @@ public class JoinDialog extends FloatingDialog{ local.row(); - TextButton button = local.addButton("", Styles.cleart, () -> connect(host.address, port)) + TextButton button = local.addButton("", Styles.cleart, () -> safeConnect(host.address, port, host.version)) .width(w).pad(5f).get(); button.clearChildren(); buildServer(host, button); @@ -344,6 +343,15 @@ public class JoinDialog extends FloatingDialog{ }); } + void safeConnect(String ip, int port, int version){ + if(version != Version.build && Version.build != -1 && version != -1){ + ui.showInfo("[scarlet]" + (version > Version.build ? KickReason.clientOutdated : KickReason.serverOutdated).toString() + "\n[]" + + Core.bundle.format("server.versions", Version.build, version)); + }else{ + connect(ip, port); + } + } + float targetWidth(){ return Core.graphics.isPortrait() ? 350f : 500f; } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java index 2f5c9d1e4d..fdbf61df9e 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SettingsMenuDialog.java @@ -14,7 +14,7 @@ import io.anuke.arc.scene.ui.TextButton.*; import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; import io.anuke.mindustry.core.GameState.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.graphics.*; diff --git a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java index ca676655a4..9e22cae99b 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java @@ -11,12 +11,11 @@ import io.anuke.arc.scene.style.*; import io.anuke.arc.scene.ui.*; import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; -import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.gen.*; import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.ui.*; -import io.anuke.mindustry.ui.Styles; import static io.anuke.arc.Core.assets; import static io.anuke.mindustry.Vars.*; @@ -65,7 +64,7 @@ public class MenuFragment extends Fragment{ parent.fill(c -> c.bottom().right().addButton("", Styles.discordt, ui.discord::show).size(84, 45)); } - String versionText = "[#ffffffba]" + ((io.anuke.mindustry.core.Version.build == -1) ? "[#fc8140aa]custom build" : (io.anuke.mindustry.core.Version.type.equals("official") ? io.anuke.mindustry.core.Version.modifier : io.anuke.mindustry.core.Version.type) + " build " + io.anuke.mindustry.core.Version.build + (io.anuke.mindustry.core.Version.revision == 0 ? "" : "." + Version.revision)); + String versionText = "[#ffffffba]" + ((Version.build == -1) ? "[#fc8140aa]custom build" : (Version.type.equals("official") ? Version.modifier : Version.type) + " build " + Version.build + (Version.revision == 0 ? "" : "." + Version.revision)); parent.fill((x, y, w, h) -> { Texture logo = Core.assets.get("sprites/logo.png"); diff --git a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java index 837df66b20..27b52d6ad0 100644 --- a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java @@ -19,9 +19,9 @@ import io.anuke.arc.util.io.*; import io.anuke.arc.util.serialization.*; import io.anuke.mindustry.*; import io.anuke.mindustry.core.GameState.*; +import io.anuke.mindustry.core.Version; import io.anuke.mindustry.desktop.steam.*; import io.anuke.mindustry.game.EventType.*; -import io.anuke.mindustry.core.Version; import io.anuke.mindustry.mod.Mods.*; import io.anuke.mindustry.net.*; import io.anuke.mindustry.net.Net.*; diff --git a/desktop/src/io/anuke/mindustry/desktop/steam/SNet.java b/desktop/src/io/anuke/mindustry/desktop/steam/SNet.java index a89ab65c3f..16bb25ff67 100644 --- a/desktop/src/io/anuke/mindustry/desktop/steam/SNet.java +++ b/desktop/src/io/anuke/mindustry/desktop/steam/SNet.java @@ -9,8 +9,8 @@ import io.anuke.arc.collection.*; import io.anuke.arc.function.*; import io.anuke.arc.util.*; import io.anuke.arc.util.pooling.*; -import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.core.Version; +import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.*; import io.anuke.mindustry.net.ArcNetImpl.*; import io.anuke.mindustry.net.*; diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index 550a242199..67dd9c2e96 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -10,7 +10,7 @@ import io.anuke.arc.util.CommandHandler.*; import io.anuke.arc.util.Timer.*; import io.anuke.mindustry.*; import io.anuke.mindustry.core.GameState.*; -import io.anuke.mindustry.core.Version; +import Version; import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.game.*; @@ -134,7 +134,7 @@ public class ServerControl implements ApplicationListener{ thread.setDaemon(true); thread.start(); - if(io.anuke.mindustry.core.Version.build == -1){ + if(Version.build == -1){ warn("&lyYour server is running a custom build, which means that client checking is disabled."); warn("&lyIt is highly advised to specify which version you're using by building with gradle args &lc-Pbuildversion=&lm&ly."); } @@ -194,7 +194,7 @@ public class ServerControl implements ApplicationListener{ }); handler.register("version", "Displays server version info.", arg -> { - info("&lmVersion: &lyMindustry {0}-{1} {2} / build {3}", io.anuke.mindustry.core.Version.number, io.anuke.mindustry.core.Version.modifier, io.anuke.mindustry.core.Version.type, Version.build); + info("&lmVersion: &lyMindustry {0}-{1} {2} / build {3}", Version.number, Version.modifier, Version.type, Version.build); info("&lmJava Version: &ly{0}", System.getProperty("java.version")); });