forked from IF-LK-2020/wordle
Game instance for every connection
This commit is contained in:
@@ -2,7 +2,11 @@ public class Game {
|
||||
// Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
|
||||
WordleServer wordleServer;
|
||||
User user;
|
||||
DatabaseConnector databaseConnector;// Datenbankverbindung aufstellen
|
||||
static DatabaseConnector databaseConnector;// Datenbankverbindung aufstellen
|
||||
|
||||
private String ip;
|
||||
private int port;
|
||||
|
||||
private String wordle;
|
||||
private String[] words;
|
||||
private int count;
|
||||
@@ -11,10 +15,27 @@ public class Game {
|
||||
|
||||
this.wordleServer = wordleServer;
|
||||
|
||||
|
||||
user = new User();
|
||||
}
|
||||
|
||||
public void processMessage(String msg) {
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,23 @@ public class WordleServer extends Server {
|
||||
|
||||
@Override
|
||||
public void processClosingConnection( String pClientIP, int pClientPort ) {
|
||||
System.out.println("Closed connection: " + pClientPort);
|
||||
find(pClientIP, pClientPort);
|
||||
games.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processMessage( String pClientIP, int pClientPort, String pMessage ) {
|
||||
games.toFirst();
|
||||
games.getContent().processMessage(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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user