From 8c941c7165d100dc1952e65fbed254dd0757d8d9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 28 Dec 2019 21:34:20 -0500 Subject: [PATCH] Added update trigger / Server moddability tweaks --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/core/Logic.java | 3 ++- core/src/mindustry/core/NetServer.java | 1 - core/src/mindustry/game/EventType.java | 3 ++- core/src/mindustry/game/Rules.java | 2 ++ core/src/mindustry/net/BeControl.java | 8 +++++-- core/src/mindustry/net/Packets.java | 3 ++- .../src/mindustry/server/ServerControl.java | 24 +++++++++---------- 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 2b2a1aa548..0ee7e3bd4e 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -155,6 +155,7 @@ server.kicked.nameEmpty = Your chosen name is invalid. server.kicked.idInUse = You are already on this server! Connecting with two accounts is not permitted. server.kicked.customClient = This server does not support custom builds. Download an official version. server.kicked.gameover = Game over! +server.kicked.serverRestarting = The server is restarting. server.versions = Your version:[accent] {0}[]\nServer version:[accent] {1}[] host.info = The [accent]host[] button hosts a server on port [scarlet]6567[]. \nAnybody on the same [lightgray]wifi or local network[] should be able to see your server in their server list.\n\nIf you want people to be able to connect from anywhere by IP, [accent]port forwarding[] is required.\n\n[lightgray]Note: If someone is experiencing trouble connecting to your LAN game, make sure you have allowed Mindustry access to your local network in your firewall settings. Note that public networks sometimes do not allow server discovery. join.info = Here, you can enter a [accent]server IP[] to connect to, or discover [accent]local network[] servers to connect to.\nBoth LAN and WAN multiplayer is supported.\n\n[lightgray]Note: There is no automatic global server list; if you want to connect to someone by IP, you would need to ask the host for their IP. diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 17fedab303..12761439b7 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -209,6 +209,7 @@ public class Logic implements ApplicationListener{ @Override public void update(){ + Events.fire(Trigger.update); if(!state.is(State.menu)){ if(!net.client()){ @@ -260,7 +261,7 @@ public class Logic implements ApplicationListener{ } } - if(!net.client() && !world.isInvalidMap() && !state.isEditor()){ + if(!net.client() && !world.isInvalidMap() && !state.isEditor() && !state.rules.canGameOver){ checkGameOver(); } } diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index c74f14211c..a355ecbd76 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -217,7 +217,6 @@ public class NetServer implements ApplicationListener{ //playing in pvp mode automatically assigns players to teams player.setTeam(assignTeam(player, playerGroup.all())); - Log.info("Auto-assigned player {0} to team {1}.", player.name, player.getTeam()); sendWorldData(player); diff --git a/core/src/mindustry/game/EventType.java b/core/src/mindustry/game/EventType.java index 6cbaba5e4b..5a9950b489 100644 --- a/core/src/mindustry/game/EventType.java +++ b/core/src/mindustry/game/EventType.java @@ -29,7 +29,8 @@ public class EventType{ suicideBomb, openWiki, teamCoreDamage, - socketConfigChanged + socketConfigChanged, + update } public static class WinEvent{} diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 93ceaf5cfe..06231e5318 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -70,6 +70,8 @@ public class Rules{ public boolean editor = false; /** Whether the tutorial is enabled. False by default. */ public boolean tutorial = false; + /** Whether a gameover can happen at all. Set this to false to implement custom gameover conditions. */ + public boolean canGameOver = true; /** Starting items put in cores */ public Array loadout = Array.with(ItemStack.with(Items.copper, 100)); /** Blocks that cannot be placed. */ diff --git a/core/src/mindustry/net/BeControl.java b/core/src/mindustry/net/BeControl.java index 76fa81f310..13f645b996 100644 --- a/core/src/mindustry/net/BeControl.java +++ b/core/src/mindustry/net/BeControl.java @@ -11,6 +11,7 @@ import mindustry.core.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.net.Administration.*; +import mindustry.net.Packets.*; import mindustry.ui.*; import mindustry.ui.dialogs.*; @@ -126,13 +127,16 @@ public class BeControl{ len -> Core.app.post(() -> Log.info("&ly| Size: {0} MB.", Strings.fixed((float)len / 1024 / 1024, 2))), progress -> {}, () -> false, - () -> { + () -> Core.app.post(() -> { + netServer.kickAll(KickReason.serverRestarting); + Threads.sleep(32); + Log.info("&lcVersion downloaded, exiting. Note that if you are not using a auto-restart script, the server will not restart automatically."); //replace old file with new dest.copyTo(source); dest.delete(); System.exit(2); //this will cause a restart if using the script - }, + }), Throwable::printStackTrace); }catch(Exception e){ e.printStackTrace(); diff --git a/core/src/mindustry/net/Packets.java b/core/src/mindustry/net/Packets.java index 683983d69b..98a3bad857 100644 --- a/core/src/mindustry/net/Packets.java +++ b/core/src/mindustry/net/Packets.java @@ -15,7 +15,8 @@ public class Packets{ public enum KickReason{ kick, clientOutdated, serverOutdated, banned, gameover(true), recentKick, - nameInUse, idInUse, nameEmpty, customClient, serverClose, vote, typeMismatch, whitelist, playerLimit; + nameInUse, idInUse, nameEmpty, customClient, serverClose, vote, typeMismatch, + whitelist, playerLimit, serverRestarting; public final boolean quiet; diff --git a/server/src/mindustry/server/ServerControl.java b/server/src/mindustry/server/ServerControl.java index df70cf3c0a..094d020e78 100644 --- a/server/src/mindustry/server/ServerControl.java +++ b/server/src/mindustry/server/ServerControl.java @@ -163,6 +163,15 @@ public class ServerControl implements ApplicationListener{ toggleSocket(Config.socketInput.bool()); }); + Events.on(PlayEvent.class, e -> { + try{ + JsonValue value = JsonIO.json().fromJson(null, Core.settings.getString("globalrules")); + JsonIO.json().readFields(state.rules, value); + }catch(Throwable t){ + Log.err("Error applying custom rules, proceeding without them.", t); + } + }); + if(!mods.list().isEmpty()){ info("&lc{0} mods loaded.", mods.list().size); } @@ -238,7 +247,6 @@ public class ServerControl implements ApplicationListener{ try{ world.loadMap(result, result.applyRules(lastMode)); state.rules = result.applyRules(preset); - applyRules(); logic.play(); info("Map loaded."); @@ -390,7 +398,7 @@ public class ServerControl implements ApplicationListener{ base.addChild(arg[1], value); Log.info("Changed rule: &ly{0}", value.toString().replace("\n", " ")); }catch(Throwable e){ - Log.err("Error parsing rule JSON", e); + Log.err("Error parsing rule JSON: {0}", e.getMessage()); } } @@ -777,15 +785,6 @@ public class ServerControl implements ApplicationListener{ mods.eachClass(p -> p.registerClientCommands(netServer.clientCommands)); } - private void applyRules(){ - try{ - JsonValue value = JsonIO.json().fromJson(null, Core.settings.getString("globalrules")); - JsonIO.json().readFields(state.rules, value); - }catch(Throwable t){ - Log.err("Error applying custom rules, proceeding without them.", t); - } - } - private void readCommands(){ Scanner scan = new Scanner(System.in); @@ -836,9 +835,8 @@ public class ServerControl implements ApplicationListener{ Call.onWorldDataBegin(); run.run(); - logic.play(); state.rules = world.getMap().applyRules(lastMode); - applyRules(); + logic.play(); for(Player p : players){ if(p.con == null) continue;