forked from IF-LK-2020/wordle
login angefangen
This commit is contained in:
@@ -12,6 +12,14 @@ public class Game {
|
||||
private int count;
|
||||
private int phase;
|
||||
|
||||
static {
|
||||
|
||||
databaseConnector = new DatabaseConnector(null, 0, "wordle.db", null, null);
|
||||
|
||||
System.err.println(databaseConnector.getErrorMessage());
|
||||
|
||||
}
|
||||
|
||||
public Game(WordleServer wordleServer, String pClientIP, int pClientPort) {
|
||||
|
||||
this.wordleServer = wordleServer;
|
||||
@@ -19,6 +27,7 @@ public class Game {
|
||||
this.port = pClientPort;
|
||||
|
||||
send("+OK Hello there");
|
||||
|
||||
}
|
||||
|
||||
public void processMessage(String msg) {
|
||||
@@ -28,6 +37,7 @@ public class Game {
|
||||
if (msg.equals("quit")) {
|
||||
send("+OK bye");
|
||||
wordleServer.closeConnection(ip, port);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
switch (phase) {
|
||||
@@ -44,14 +54,35 @@ public class Game {
|
||||
}
|
||||
|
||||
private void loginPhase(String msg) {
|
||||
if (msg.startsWith("user")) {
|
||||
|
||||
} else if (msg.startsWith("pass")) {
|
||||
if (msg.length() <= 5) {
|
||||
sendUniversalError();
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (msg.startsWith("wotd")) {
|
||||
String args = msg.substring(5);
|
||||
if (msg.startsWith("user ")) {
|
||||
|
||||
} else if (msg.startsWith("play")) {
|
||||
databaseConnector.executeStatement("SELECT * FROM User WHERE name = '" + args + "'");
|
||||
System.err.println(databaseConnector.getErrorMessage());
|
||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||
|
||||
if (result != null) {
|
||||
String name = result.getData()[0][0];
|
||||
System.out.println(name);
|
||||
user = new User(name);
|
||||
} else {
|
||||
send("-ERR User not found.");
|
||||
}
|
||||
|
||||
} else if (msg.startsWith("pass ")) {
|
||||
|
||||
} else if (msg.startsWith("wotd ")) {
|
||||
|
||||
} else if (msg.startsWith("play ")) {
|
||||
|
||||
} else {
|
||||
sendUniversalError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +108,10 @@ public class Game {
|
||||
wordleServer.send(ip, port, msg);
|
||||
}
|
||||
|
||||
private void sendUniversalError() {
|
||||
send("-ERR command not valid in this state");
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user