wordle/src/WordleServer.java

51 lines
1.1 KiB
Java

/**
* Server für das WORDLE Spiel.
*/
public class WordleServer extends Server {
public static final int DEFAULT_PORT = 1000;
List<Game> games;
public static void main( String[] args ) {
new WordleServer();
}
public WordleServer() {
this(DEFAULT_PORT);
}
public WordleServer( int pPort ) {
super(pPort);
games = new List<>();
}
@Override
public void processNewConnection( String pClientIP, int pClientPort ) {
games.append(new Game(this, pClientIP, pClientPort));
}
@Override
public void processClosingConnection( String pClientIP, int pClientPort ) {
find(pClientIP, pClientPort);
games.remove();
}
@Override
public void processMessage( String pClientIP, int pClientPort, String pMessage ) {
find(pClientIP, pClientPort).processMessage(pMessage);
}
private Game find(String ip, int port) {
games.toFirst();
while (games.hasAccess()) {
Game g = games.getContent();
if (g.getIp().equals(ip) && g.getPort() == port) {
return g;
}
}
return null;
}
}