From d29dd4aafd8e9b04d47c9647784614f256f7b86f Mon Sep 17 00:00:00 2001 From: qwertysam Date: Thu, 1 Sep 2016 23:19:58 -0400 Subject: [PATCH] + Server now shuts down properly + Caps lock no longer crashes linux games --- src/ca/afroman/assets/AudioClip.java | 2 +- src/ca/afroman/client/ClientGame.java | 1 + src/ca/afroman/game/Game.java | 6 ++++++ src/ca/afroman/input/LockKey.java | 22 ++++++++++++++++++---- src/ca/afroman/server/ServerGame.java | 13 +++++++++++++ src/ca/afroman/util/VersionUtil.java | 4 ++-- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/ca/afroman/assets/AudioClip.java b/src/ca/afroman/assets/AudioClip.java index 7ebdec5..835fba1 100644 --- a/src/ca/afroman/assets/AudioClip.java +++ b/src/ca/afroman/assets/AudioClip.java @@ -15,7 +15,7 @@ public class AudioClip extends Asset { - private static final boolean ENABLE_AUDIO = false; + private static final boolean ENABLE_AUDIO = true; private static boolean initUseMp3 = true; private static boolean USE_MP3; private static final String AUDIO_DIR = "/audio/"; diff --git a/src/ca/afroman/client/ClientGame.java b/src/ca/afroman/client/ClientGame.java index 463d947..6c47543 100644 --- a/src/ca/afroman/client/ClientGame.java +++ b/src/ca/afroman/client/ClientGame.java @@ -156,6 +156,7 @@ public void exitFromGame(ExitGameReason reason) { // TODO let the server know that the client has disconnected // sockets().sender().sendPacket(new PacketPlayerDisconnect()); + stopSocket(); receivedPackets.clear(); getLevels().clear(); diff --git a/src/ca/afroman/game/Game.java b/src/ca/afroman/game/Game.java index 3054b33..7c9e8bd 100644 --- a/src/ca/afroman/game/Game.java +++ b/src/ca/afroman/game/Game.java @@ -140,6 +140,12 @@ public void startSocket(String serverIpAddress, int port) socketManager.setServerConnection(serverIpAddress, SocketManager.validatedPort(port)); } + public void stopSocket() + { + if (socketManager != null) socketManager.stopThis(); + socketManager = null; + } + @Override public void tick() { diff --git a/src/ca/afroman/input/LockKey.java b/src/ca/afroman/input/LockKey.java index c746d7b..2531619 100644 --- a/src/ca/afroman/input/LockKey.java +++ b/src/ca/afroman/input/LockKey.java @@ -1,13 +1,16 @@ package ca.afroman.input; -import java.awt.Toolkit; import java.util.List; public class LockKey extends Key { + private boolean isToggled; + public LockKey(List container, int... keyEvents) { super(container, keyEvents); + + isToggled = false; } /** @@ -15,10 +18,21 @@ public LockKey(List container, int... keyEvents) */ public boolean isToggled() { - for (int event : keyEvents) + // for (int event : keyEvents) + // { + // if (Toolkit.getDefaultToolkit().getLockingKeyState(event)) return true; + // } + return isToggled; + } + + @Override + public void update(int keyCode, boolean isPressed) + { + super.update(keyCode, isPressed); + + if (isPressedFiltered()) { - if (Toolkit.getDefaultToolkit().getLockingKeyState(event)) return true; + isToggled = !isToggled; } - return false; } } diff --git a/src/ca/afroman/server/ServerGame.java b/src/ca/afroman/server/ServerGame.java index a3d8d1d..050fa19 100644 --- a/src/ca/afroman/server/ServerGame.java +++ b/src/ca/afroman/server/ServerGame.java @@ -36,6 +36,7 @@ import ca.afroman.packet.PacketEditTrigger; import ca.afroman.packet.PacketRemoveLevelObject; import ca.afroman.packet.PacketSendLevels; +import ca.afroman.packet.PacketStopServer; import ca.afroman.packet.PacketType; import ca.afroman.resource.IDCounter; import ca.afroman.resource.Vector2DDouble; @@ -184,6 +185,18 @@ public void onStart() @Override public void onStop() { + sockets().sender().sendPacketToAllClients(new PacketStopServer()); + + // TODO make a more surefire way to ensure that all clients got the message + try + { + Thread.sleep(1500); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + super.onStop(); // TODO save levels? diff --git a/src/ca/afroman/util/VersionUtil.java b/src/ca/afroman/util/VersionUtil.java index 36864f1..332f23e 100644 --- a/src/ca/afroman/util/VersionUtil.java +++ b/src/ca/afroman/util/VersionUtil.java @@ -5,8 +5,8 @@ public class VersionUtil // Sub versions are backwards compatible with each other public static final int SUB_VERSION = 0; - public static final byte DAY = 27; - public static final byte MONTH = 8; + public static final byte DAY = 1; + public static final byte MONTH = 9; public static final short YEAR = 2016; private static final byte[] YEAR_SPLIT = ByteUtil.shortAsBytes(YEAR);