diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 5d97e00ba2..3db1097c65 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -409,6 +409,7 @@ public class Control extends Module{ Timers.run(60, () -> { ui.restart.show(); + netServer.handleGameOver(); }); } diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index e262f78631..b0416c9ef0 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -33,6 +33,8 @@ import io.anuke.ucore.modules.Module; import java.io.DataInputStream; import java.io.IOException; +import static io.anuke.mindustry.Vars.ui; + public class NetClient extends Module { public static final Color[] colorArray = {Color.ORANGE, Color.SCARLET, Color.LIME, Color.PURPLE, Color.GOLD, Color.PINK, Color.SKY, Color.GOLD, Color.VIOLET, @@ -292,6 +294,11 @@ public class NetClient extends Module { Tile tile = Vars.world.tile(packet.position); if(tile != null) tile.block().configure(tile, packet.data); }); + + Net.handle(GameOverPacket.class, packet -> { + kicked = true; + Gdx.app.postRunnable(ui.restart::show); + }); } @Override diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 7cafb47474..29cafc61da 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -216,6 +216,11 @@ public class NetServer extends Module{ Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(message, null)); } + public void handleGameOver(){ + Net.send(new GameOverPacket(), SendMode.tcp); + Timers.runTask(30f, () -> GameState.set(State.menu)); + } + public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){ BulletPacket packet = new BulletPacket(); packet.x = x; diff --git a/core/src/io/anuke/mindustry/net/Packets.java b/core/src/io/anuke/mindustry/net/Packets.java index 30e17f6d08..0fef24e582 100644 --- a/core/src/io/anuke/mindustry/net/Packets.java +++ b/core/src/io/anuke/mindustry/net/Packets.java @@ -135,4 +135,8 @@ public class Packets { public static class EntityRequestPacket{ public int id; } + + public static class GameOverPacket{ + + } } diff --git a/core/src/io/anuke/mindustry/net/Registrator.java b/core/src/io/anuke/mindustry/net/Registrator.java index a607db7b3f..27904dcc3b 100644 --- a/core/src/io/anuke/mindustry/net/Registrator.java +++ b/core/src/io/anuke/mindustry/net/Registrator.java @@ -38,6 +38,7 @@ public class Registrator { BlockConfigPacket.class, EntityRequestPacket.class, ConnectConfirmPacket.class, + GameOverPacket.class, Class.class, byte[].class, diff --git a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java index e349b0f419..ef53493ec5 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java @@ -64,13 +64,17 @@ public class JoinDialog extends FloatingDialog { } join.hide(); }).disabled(b -> Settings.getString("ip").isEmpty() || Strings.parseInt(Settings.getString("port")) == Integer.MIN_VALUE || Net.active()); + join.shown(() -> { join.getTitleLabel().setText(renaming != null ? "$text.server.edit" : "$text.server.add"); }); setup(); - shown(this::refreshLocal); + shown(() -> { + refreshLocal(); + refreshRemote(); + }); } void setupRemote(){