mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 07:07:03 +07:00
Check version when connecting
This commit is contained in:
parent
80ccc0eee0
commit
ab199633f8
@ -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.*;
|
||||
|
@ -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.*;
|
||||
|
@ -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<String, String> 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)));
|
||||
|
@ -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());
|
||||
|
@ -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.
|
||||
|
@ -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.*;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.*;
|
||||
|
@ -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");
|
||||
|
@ -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.*;
|
||||
|
@ -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.*;
|
||||
|
@ -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<build>&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"));
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user