Skip to content

Commit

Permalink
+ Server now shuts down properly
Browse files Browse the repository at this point in the history
+ Caps lock no longer crashes linux games
  • Loading branch information
defaultsamson committed Sep 2, 2016
1 parent 7be7454 commit d29dd4a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ca/afroman/assets/AudioClip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
1 change: 1 addition & 0 deletions src/ca/afroman/client/ClientGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/ca/afroman/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
22 changes: 18 additions & 4 deletions src/ca/afroman/input/LockKey.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
package ca.afroman.input;

import java.awt.Toolkit;
import java.util.List;

public class LockKey extends Key
{
private boolean isToggled;

public LockKey(List<Key> container, int... keyEvents)
{
super(container, keyEvents);

isToggled = false;
}

/**
* @return if this lock key is currently in a toggled state or not.
*/
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;
}
}
13 changes: 13 additions & 0 deletions src/ca/afroman/server/ServerGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions src/ca/afroman/util/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d29dd4a

Please sign in to comment.