login detection

This commit is contained in:
Asecave
2022-03-07 15:38:35 +01:00
parent 91ed88d15d
commit 86d449cba2
3 changed files with 40 additions and 34 deletions

View File

@@ -11,12 +11,16 @@ public class Game {
private String[] words;
private int count;
private int phase;
private String tempLoginName;
static {
databaseConnector = new DatabaseConnector(null, 0, "wordle.db", null, null);
System.err.println(databaseConnector.getErrorMessage());
if (databaseConnector.getErrorMessage() != null) {
System.err.println(databaseConnector.getErrorMessage());
}
}
@@ -37,7 +41,7 @@ public class Game {
if (msg.equals("quit")) {
send("+OK bye");
wordleServer.closeConnection(ip, port);
System.exit(0);
System.exit(0); // TODO remove: Einfacher zum testen
}
switch (phase) {
@@ -64,19 +68,24 @@ public class Game {
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);
if (result != null && result.getData().length > 0) {
tempLoginName = result.getData()[0][0];
send("+OK");
} else {
send("-ERR User not found.");
}
} else if (msg.startsWith("pass ")) {
int pw = args.hashCode();
databaseConnector.executeStatement("SELECT * FROM User WHERE password = '" + pw + "' AND name = '" + tempLoginName + "'");
QueryResult result = databaseConnector.getCurrentQueryResult();
if (result != null && result.getData().length > 0) {
user = new User(tempLoginName);
send("+OK welcome");
} else {
send("-ERR login not valid");
}
} else if (msg.startsWith("wotd ")) {
} else if (msg.startsWith("play ")) {
@@ -92,7 +101,7 @@ public class Game {
String args = msg.substring(5);
//vergleichen von wotd mit
//ja = spiel beendet und ausgabe word 11111
//nein = ausgabe 01102 oder so und prüfen ob man noch ein wort eingebn kann
//nein = ausgabe 01102 oder so und pr<EFBFBD>fen ob man noch ein wort eingebn kann
// ja game continues nein = game lost
} else if (msg.startsWith("info")) {