forked from IF-LK-2020/wordle
Extended Protocol implementation
This commit is contained in:
parent
4636051237
commit
a1b47bf828
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue