Extended Protocol implementation

This commit is contained in:
Maxim Derksen 2022-03-03 11:30:40 +01:00
parent 4636051237
commit a1b47bf828
1 changed files with 12 additions and 6 deletions

View File

@ -44,14 +44,13 @@ public class WordleServer extends Server {
@Override
public void processMessage(String pClientIP, int pClientPort, String pMessage) {
String conectionID = pClientIP + ":" + Integer.toString(pClientPort);
User u = users.get(conectionID);
String connectionID = pClientIP + ":" + Integer.toString(pClientPort);
User u = users.get(connectionID);
u.setConnectionID(connectionID);
if (pMessage.equals("QUIT")) {
send(pClientIP, pClientPort, "+OK Bye");
close();
} else {
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
}
switch (u.getState()) {
@ -61,13 +60,20 @@ public class WordleServer extends Server {
if (m.equalsIgnoreCase("USER")) {
m = pMessage.substring(6, pMessage.length() - 1);
u.setUsername(m);
send(pClientIP, pClientPort, "+OK Bye");
send(pClientIP, pClientPort, "+OK");
} else if (m.equalsIgnoreCase("PASS")) {
m = pMessage.substring(6, pMessage.length() - 1);
u.setPassword(m);
if (u.getPassword() != null && u.getUsername() != null) {
query.checkLogin(u.getUsername(), u.getPassword());
if (query.checkLogin(u.getUsername(), u.getPassword())) {
send(pClientIP, pClientPort, "+OK welcome");
u.setState(3);
} else {
send(pClientIP, pClientPort, "+ERR login not valid");
}
}
} else {
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
}
break;
case 2: