forked from IF-LK-2020/wordle
login detection
This commit is contained in:
parent
91ed88d15d
commit
86d449cba2
|
@ -11,12 +11,16 @@ public class Game {
|
||||||
private String[] words;
|
private String[] words;
|
||||||
private int count;
|
private int count;
|
||||||
private int phase;
|
private int phase;
|
||||||
|
|
||||||
|
private String tempLoginName;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
databaseConnector = new DatabaseConnector(null, 0, "wordle.db", null, null);
|
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")) {
|
if (msg.equals("quit")) {
|
||||||
send("+OK bye");
|
send("+OK bye");
|
||||||
wordleServer.closeConnection(ip, port);
|
wordleServer.closeConnection(ip, port);
|
||||||
System.exit(0);
|
System.exit(0); // TODO remove: Einfacher zum testen
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (phase) {
|
switch (phase) {
|
||||||
|
@ -64,19 +68,24 @@ public class Game {
|
||||||
if (msg.startsWith("user ")) {
|
if (msg.startsWith("user ")) {
|
||||||
|
|
||||||
databaseConnector.executeStatement("SELECT * FROM User WHERE name = '" + args + "'");
|
databaseConnector.executeStatement("SELECT * FROM User WHERE name = '" + args + "'");
|
||||||
System.err.println(databaseConnector.getErrorMessage());
|
|
||||||
QueryResult result = databaseConnector.getCurrentQueryResult();
|
QueryResult result = databaseConnector.getCurrentQueryResult();
|
||||||
|
if (result != null && result.getData().length > 0) {
|
||||||
if (result != null) {
|
tempLoginName = result.getData()[0][0];
|
||||||
String name = result.getData()[0][0];
|
send("+OK");
|
||||||
System.out.println(name);
|
|
||||||
user = new User(name);
|
|
||||||
} else {
|
} else {
|
||||||
send("-ERR User not found.");
|
send("-ERR User not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (msg.startsWith("pass ")) {
|
} 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("wotd ")) {
|
||||||
|
|
||||||
} else if (msg.startsWith("play ")) {
|
} else if (msg.startsWith("play ")) {
|
||||||
|
@ -92,7 +101,7 @@ public class Game {
|
||||||
String args = msg.substring(5);
|
String args = msg.substring(5);
|
||||||
//vergleichen von wotd mit
|
//vergleichen von wotd mit
|
||||||
//ja = spiel beendet und ausgabe word 11111
|
//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
|
// ja game continues nein = game lost
|
||||||
|
|
||||||
} else if (msg.startsWith("info")) {
|
} else if (msg.startsWith("info")) {
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
public class User
|
public class User {
|
||||||
{
|
|
||||||
|
|
||||||
static DatabaseConnector databaseConnector;// Datenbankverbindung aufstellen
|
|
||||||
private String name = "default";
|
private String name = "default";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Konstruktor für Objekte der Klasse User
|
* Konstruktor für Objekte der Klasse User
|
||||||
*/
|
*/
|
||||||
public User(String name)
|
public User(String name)
|
||||||
{
|
{
|
||||||
databaseConnector = new DatabaseConnector("", 0, "wordle.db", "", "");
|
|
||||||
setName(name);
|
setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,14 +14,14 @@ public class User
|
||||||
|
|
||||||
public void setPassword(String password)
|
public void setPassword(String password)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET password = " + password + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET password = " + password + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getPassword()
|
public String getPassword()
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT password FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT password FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +29,7 @@ public class User
|
||||||
|
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET name = " + name + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET name = " + name + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,14 +42,14 @@ public class User
|
||||||
|
|
||||||
public void setWinPercentage(float winPercentage)
|
public void setWinPercentage(float winPercentage)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET winPercentage = " + winPercentage + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET winPercentage = " + winPercentage + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float getWinPercentage()
|
public float getWinPercentage()
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT winPercentage FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT winPercentage FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return Float.parseFloat(result);
|
return Float.parseFloat(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,14 +57,14 @@ public class User
|
||||||
|
|
||||||
public void setTimesPlayed(int timesPlayed)
|
public void setTimesPlayed(int timesPlayed)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET timesPlayed = " + timesPlayed + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET timesPlayed = " + timesPlayed + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getTimesPlayed()
|
public int getTimesPlayed()
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT timesPlayed FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT timesPlayed FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return Integer.parseInt(result);
|
return Integer.parseInt(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,14 +80,14 @@ public class User
|
||||||
|
|
||||||
public void setCurrentStreak(int currentStreak)
|
public void setCurrentStreak(int currentStreak)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET currentStreak = " + currentStreak + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET currentStreak = " + currentStreak + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getCurrentStreak()
|
public int getCurrentStreak()
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT currentStreak FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT currentStreak FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return Integer.parseInt(result);
|
return Integer.parseInt(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,14 +103,14 @@ public class User
|
||||||
|
|
||||||
public void setMaxStreak(int maxStreak)
|
public void setMaxStreak(int maxStreak)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET maxStreak = " + maxStreak + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET maxStreak = " + maxStreak + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getMaxStreak()
|
public int getMaxStreak()
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT maxStreak FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT maxStreak FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return Integer.parseInt(result);
|
return Integer.parseInt(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,14 +126,14 @@ public class User
|
||||||
|
|
||||||
public void setWonInTurn(int row, int value)
|
public void setWonInTurn(int row, int value)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("UPDATE User SET wonInTurn" + row + " = " + value + " Where name = " + this.name);
|
Game.databaseConnector.executeStatement("UPDATE User SET wonInTurn" + row + " = " + value + " Where name = " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getWonInTurn(int row)
|
public int getWonInTurn(int row)
|
||||||
{
|
{
|
||||||
databaseConnector.executeStatement("SELECT wonInTurn" + row + " FROM User Where name =" + this.name);
|
Game.databaseConnector.executeStatement("SELECT wonInTurn" + row + " FROM User Where name =" + this.name);
|
||||||
String result = databaseConnector.getCurrentQueryResult().getData()[0][0];
|
String result = Game.databaseConnector.getCurrentQueryResult().getData()[0][0];
|
||||||
return Integer.parseInt(result);
|
return Integer.parseInt(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue