mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-13 19:39:04 +07:00
Added support for server pausing
This commit is contained in:
parent
c980e72f52
commit
88608b3f88
@ -16,7 +16,7 @@ public class GameState{
|
||||
/** Wave countdown in ticks. */
|
||||
public float wavetime;
|
||||
/** Whether the game is in game over state. */
|
||||
public boolean gameOver = false, launched = false;
|
||||
public boolean gameOver = false, launched = false, serverPaused = false;
|
||||
/** Map that is currently being played on. */
|
||||
public @NonNull Map map = emptyMap;
|
||||
/** The current game rules. */
|
||||
@ -59,7 +59,7 @@ public class GameState{
|
||||
}
|
||||
|
||||
public boolean isPaused(){
|
||||
return (is(State.paused) && !net.active()) || (gameOver && !net.active());
|
||||
return (is(State.paused) && !net.active()) || (gameOver && !net.active()) || (serverPaused && !isMenu());
|
||||
}
|
||||
|
||||
public boolean isPlaying(){
|
||||
|
@ -437,7 +437,7 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
||||
public static void onStateSnapshot(float waveTime, int wave, int enemies, short coreDataLen, byte[] coreData){
|
||||
public static void onStateSnapshot(float waveTime, int wave, int enemies, boolean paused, short coreDataLen, byte[] coreData){
|
||||
try{
|
||||
if(wave > state.wave){
|
||||
state.wave = wave;
|
||||
@ -447,6 +447,7 @@ public class NetClient implements ApplicationListener{
|
||||
state.wavetime = waveTime;
|
||||
state.wave = wave;
|
||||
state.enemies = enemies;
|
||||
state.serverPaused = paused;
|
||||
|
||||
netClient.byteStream.setBytes(net.decompressSnapshot(coreData, coreDataLen));
|
||||
DataInputStream input = netClient.dataStream;
|
||||
|
@ -783,7 +783,7 @@ public class NetServer implements ApplicationListener{
|
||||
byte[] stateBytes = syncStream.toByteArray();
|
||||
|
||||
//write basic state data.
|
||||
Call.onStateSnapshot(player.con(), state.wavetime, state.wave, state.enemies, (short)stateBytes.length, net.compressSnapshot(stateBytes));
|
||||
Call.onStateSnapshot(player.con(), state.wavetime, state.wave, state.enemies, state.serverPaused, (short)stateBytes.length, net.compressSnapshot(stateBytes));
|
||||
|
||||
viewport.setSize(player.con().viewWidth, player.con().viewHeight).setCenter(player.con().viewX, player.con().viewY);
|
||||
|
||||
|
@ -340,6 +340,13 @@ public class ServerControl implements ApplicationListener{
|
||||
info("&lyServer: &lb@", arg[0]);
|
||||
});
|
||||
|
||||
|
||||
handler.register("pause", "<on/off>", "Pause or unpause the game.", arg -> {
|
||||
boolean pause = arg[0].equals("on");
|
||||
state.serverPaused = pause;
|
||||
info(pause ? "Game paused." : "Game unpaused.");
|
||||
});
|
||||
|
||||
handler.register("rules", "[remove/add] [name] [value...]", "List, remove or add global rules. These will apply regardless of map.", arg -> {
|
||||
String rules = Core.settings.getString("globalrules");
|
||||
JsonValue base = JsonIO.json().fromJson(null, rules);
|
||||
|
Loading…
Reference in New Issue
Block a user