package ethanjones.cubes.networking.server;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Net.Protocol;
import com.badlogic.gdx.net.ServerSocket;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.utils.Disposable;

import ethanjones.cubes.core.logging.Log;
import ethanjones.cubes.networking.Networking;
import ethanjones.cubes.side.Side;
import ethanjones.cubes.side.Sided;

public class ServerSocketMonitor implements Runnable, Disposable {

  public boolean running;
  private ServerSocket serverSocket;
  private Thread thread;
  private int port;
  private final ServerNetworking serverNetworking;

  public ServerSocketMonitor(int port, ServerNetworking serverNetworking) {
    this.port = port;
    this.serverNetworking = serverNetworking;
    serverSocket = Gdx.net.newServerSocket(Protocol.TCP, port, Networking.serverSocketHints);
    running = true;
  }

  @Override
  public void run() {
    Sided.setSide(Side.Server);
    while (running) {
      try {
        Socket accept = serverSocket.accept(Networking.socketHints);
        ServerConnectionInitializer.check(accept);
      } catch (Exception e) {
        if (running) Log.error(e);
      }
    }
    dispose();
  }

  @Override
  public void dispose() {
    running = false;
    serverSocket.dispose();
    getThread().interrupt();
  }

  protected Thread getThread() {
    return thread;
  }

  public Thread start() {
    if (thread != null) return thread;
    thread = new Thread(this);
    thread.setDaemon(true);
    thread.setName("Server Socket Monitor: " + port);
    thread.start();
    return thread;
  }
}

@@ -224,16 +224,66 @@
 posable;
+%0Aimport java.util.concurrent.atomic.AtomicBoolean;
 %0A%0Aimport
@@ -512,15 +512,30 @@
 %0A  p
-ublic b
+rotected final AtomicB
 oole
@@ -932,20 +932,39 @@
 nning = 
+new AtomicBoolean(
 true
+)
 ;%0A  %7D%0A%0A 
@@ -1046,16 +1046,22 @@
 (running
+.get()
 ) %7B%0A    
@@ -1237,16 +1237,22 @@
 (running
+.get()
 ) Log.er
@@ -1346,16 +1346,19 @@
 ning
- = 
+.set(
 false
+)
 ;%0A  

Change running boolean in ServerSocketMonitor to an AtomicBoolean