not Valid Command und Willkommens und schlussnachricht hinzugefügt

This commit is contained in:
2022-03-02 14:29:37 +01:00
parent 59f55d3249
commit 29bfa66d09
2 changed files with 19 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
public class User { public class User {
int connectionID; String connectionID;
String username; String username;
String password; String password;
int timesPlayed; int timesPlayed;
@@ -11,7 +11,7 @@ public class User {
int [] wonInTurn; int [] wonInTurn;
Game game; Game game;
public User (int pConnectionID){ public User (String pConnectionID){
connectionID =pConnectionID; connectionID =pConnectionID;
game = new Game(); game = new Game();
} }
@@ -20,7 +20,7 @@ public class User {
return game; return game;
} }
public int getConnectionID() { public String getConnectionID() {
return connectionID; return connectionID;
} }
@@ -60,7 +60,7 @@ public class User {
return username; return username;
} }
public void setConnectionID(int connectionID) { public void setConnectionID(String connectionID) {
this.connectionID = connectionID; this.connectionID = connectionID;
} }

View File

@@ -13,6 +13,9 @@ public class WordleServer extends Server {
private DatabaseConnector db; private DatabaseConnector db;
private List<User> userList;
private Query query;
public WordleServer() { public WordleServer() {
this(DEFAULT_PORT); this(DEFAULT_PORT);
@@ -20,23 +23,33 @@ public class WordleServer extends Server {
public WordleServer( int pPort ) { public WordleServer( int pPort ) {
super(pPort); super(pPort);
query = new Query();
db = new DatabaseConnector("", 0, "wordle.db", "", ""); db = new DatabaseConnector("", 0, "wordle.db", "", "");
userList = new List<User>();
} }
@Override @Override
public void processNewConnection( String pClientIP, int pClientPort ) { public void processNewConnection( String pClientIP, int pClientPort ) {
String connectionID= pClientIP +":"+ Integer.toString(pClientPort);
User u = new User(connectionID);
userList.append(u);
send(pClientIP,pClientPort,"+OK Verbindung zum Wordle Server erfolgreich aufgebaut");
} }
@Override @Override
public void processClosingConnection( String pClientIP, int pClientPort ) { public void processClosingConnection( String pClientIP, int pClientPort ) {
} }
@Override @Override
public void processMessage( String pClientIP, int pClientPort, String pMessage ) { public void processMessage( String pClientIP, int pClientPort, String pMessage ) {
if(pMessage.equals("QUIT")){
send(pClientIP,pClientPort,"+OK Bye");
} else {
send(pClientIP,pClientPort,"-ERR Command not valid in this state");
}
} }
} }