Made server close when core is destroyed

This commit is contained in:
Anuken
2018-01-13 14:13:04 -05:00
parent d6a9b93f78
commit 4fc2097c62
6 changed files with 23 additions and 1 deletions

View File

@@ -409,6 +409,7 @@ public class Control extends Module{
Timers.run(60, () -> {
ui.restart.show();
netServer.handleGameOver();
});
}

View File

@@ -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

View File

@@ -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;

View File

@@ -135,4 +135,8 @@ public class Packets {
public static class EntityRequestPacket{
public int id;
}
public static class GameOverPacket{
}
}

View File

@@ -38,6 +38,7 @@ public class Registrator {
BlockConfigPacket.class,
EntityRequestPacket.class,
ConnectConfirmPacket.class,
GameOverPacket.class,
Class.class,
byte[].class,

View File

@@ -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(){