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 count;
|
||||||
private int phase;
|
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) {
|
public Game(WordleServer wordleServer, String pClientIP, int pClientPort) {
|
||||||
|
|
||||||
this.wordleServer = wordleServer;
|
this.wordleServer = wordleServer;
|
||||||
@@ -19,6 +27,7 @@ public class Game {
|
|||||||
this.port = pClientPort;
|
this.port = pClientPort;
|
||||||
|
|
||||||
send("+OK Hello there");
|
send("+OK Hello there");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processMessage(String msg) {
|
public void processMessage(String msg) {
|
||||||
@@ -28,6 +37,7 @@ public class Game {
|
|||||||
if (msg.equals("quit")) {
|
if (msg.equals("quit")) {
|
||||||
send("+OK bye");
|
send("+OK bye");
|
||||||
wordleServer.closeConnection(ip, port);
|
wordleServer.closeConnection(ip, port);
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
@@ -44,14 +54,35 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loginPhase(String msg) {
|
private void loginPhase(String msg) {
|
||||||
|
|
||||||
|
if (msg.length() <= 5) {
|
||||||
|
sendUniversalError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String args = msg.substring(5);
|
||||||
if (msg.startsWith("user ")) {
|
if (msg.startsWith("user ")) {
|
||||||
|
|
||||||
|
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("pass ")) {
|
||||||
|
|
||||||
} else if (msg.startsWith("wotd ")) {
|
} else if (msg.startsWith("wotd ")) {
|
||||||
|
|
||||||
} else if (msg.startsWith("play ")) {
|
} else if (msg.startsWith("play ")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sendUniversalError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +108,10 @@ public class Game {
|
|||||||
wordleServer.send(ip, port, msg);
|
wordleServer.send(ip, port, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendUniversalError() {
|
||||||
|
send("-ERR command not valid in this state");
|
||||||
|
}
|
||||||
|
|
||||||
public String getIp() {
|
public String getIp() {
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user