forked from IF-LK-2020/wordle
Extended Protocol implementation
This commit is contained in:
@@ -44,14 +44,13 @@ public class WordleServer extends Server {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMessage(String pClientIP, int pClientPort, String pMessage) {
|
public void processMessage(String pClientIP, int pClientPort, String pMessage) {
|
||||||
String conectionID = pClientIP + ":" + Integer.toString(pClientPort);
|
String connectionID = pClientIP + ":" + Integer.toString(pClientPort);
|
||||||
User u = users.get(conectionID);
|
User u = users.get(connectionID);
|
||||||
|
u.setConnectionID(connectionID);
|
||||||
|
|
||||||
if (pMessage.equals("QUIT")) {
|
if (pMessage.equals("QUIT")) {
|
||||||
send(pClientIP, pClientPort, "+OK Bye");
|
send(pClientIP, pClientPort, "+OK Bye");
|
||||||
close();
|
close();
|
||||||
} else {
|
|
||||||
send(pClientIP, pClientPort, "-ERR Command not valid in this state");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (u.getState()) {
|
switch (u.getState()) {
|
||||||
@@ -61,14 +60,21 @@ public class WordleServer extends Server {
|
|||||||
if (m.equalsIgnoreCase("USER")) {
|
if (m.equalsIgnoreCase("USER")) {
|
||||||
m = pMessage.substring(6, pMessage.length() - 1);
|
m = pMessage.substring(6, pMessage.length() - 1);
|
||||||
u.setUsername(m);
|
u.setUsername(m);
|
||||||
send(pClientIP, pClientPort, "+OK Bye");
|
send(pClientIP, pClientPort, "+OK");
|
||||||
} else if (m.equalsIgnoreCase("PASS")) {
|
} else if (m.equalsIgnoreCase("PASS")) {
|
||||||
m = pMessage.substring(6, pMessage.length() - 1);
|
m = pMessage.substring(6, pMessage.length() - 1);
|
||||||
u.setPassword(m);
|
u.setPassword(m);
|
||||||
if (u.getPassword() != null && u.getUsername() != null) {
|
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;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Spielphase
|
// Spielphase
|
||||||
|
|||||||
Reference in New Issue
Block a user