@@ -0,0 +1,1393 @@
+package ServerMainPackage;%0A%0Aimport java.io.IOException;%0Aimport java.net.ServerSocket;%0Aimport java.net.Socket;%0Aimport java.util.Collections;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Timer;%0Aimport java.util.TimerTask;%0A%0Aimport Constants.ServerConstants;%0A%0Apublic class ServerDispatcher implements Runnable %7B%0A%09%0A%09private static ServerDispatcher serverDispatcher = new ServerDispatcher();%0A%09private static List%3CMatchConnection%3E activeConnections =%0A%09%09%09Collections.synchronizedList(new LinkedList%3CMatchConnection%3E());%0A%09%0A%09private ServerDispatcher() %7B%7D%0A%09%0A%09public ServerDispatcher getInstance() %7B%0A%09%09return serverDispatcher;%0A%09%7D%0A%09%0A%09@Override%0A%09public void run() %7B%0A%09%09Timer connectionCleaner = new Timer();%0A%09%09TimerTask removeInactiveConnections = new TimerTask() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09for (int i = 0; i %3C activeConnections.size(); i++)%0A%09%09%09%09%09if (!activeConnections.get(i).isActive()) %7B%0A%09%09%09%09%09%09activeConnections.remove(i);%0A%09%09%09%09%09%09i--;%0A%09%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D;%0A%09%09connectionCleaner.scheduleAtFixedRate(removeInactiveConnections, 0,%0A%09%09%09%09ServerConstants.PACKET_DELAY * 2);%0A%09%09%0A%09%09try (ServerSocket serverSocket = new ServerSocket(ServerConstants.PORT)) %7B%0A%09%09%09Socket clientSocket = serverSocket.accept();%0A%09%09%09MatchConnection clientConnection = new MatchConnection(clientSocket);%0A%09%09%09activeConnections.add(clientConnection);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add ServerDispatcher class