forked from IF-LK-2020/wordle
(Properly) added push and pull Stats
This commit is contained in:
23
Query.java
23
Query.java
@@ -4,18 +4,35 @@ public class Query {
|
||||
Query() {
|
||||
db = new DatabaseConnector("", 0, "wordle.db", "", "");
|
||||
}
|
||||
|
||||
public void pullStats(User user) {
|
||||
String[][] r;
|
||||
db.executeStatement("SELECT * FROM user WHERE user LIKE" + user.username);
|
||||
r = db.getCurrentQueryResult().getData();
|
||||
user.currentStreak = Integer.parseInt(r[1][0]);
|
||||
user.maxStreak = Integer.parseInt(r[2][0]);
|
||||
user.wins = Integer.parseInt(r[3][0]);
|
||||
user.timesPlayed = Integer.parseInt(r[4][0]);
|
||||
user.wonInTurn[0] = Integer.parseInt(r[5][0]);
|
||||
user.wonInTurn[1] = Integer.parseInt(r[6][0]);
|
||||
user.wonInTurn[2] = Integer.parseInt(r[7][0]);
|
||||
user.wonInTurn[3] = Integer.parseInt(r[8][0]);
|
||||
user.wonInTurn[4] = Integer.parseInt(r[9][0]);
|
||||
user.wonInTurn[5] = Integer.parseInt(r[10][0]);
|
||||
user.lastDayWOTDFinished = Integer.parseInt(r[11][0]);
|
||||
|
||||
}
|
||||
|
||||
public void pushStats(User user) {
|
||||
|
||||
db.executeStatement("UPDATE INTO Stats (current_streak," + " max_streak, " + "wins, " + "times_played, "
|
||||
+ "won_on_1, " + "won_on_2, " + "won_on_3, " + "won_on_4, " + "won_on_5, " + "won_on_6, "
|
||||
+ "last_day_WOTD_finished) " + "VALUES (" + user.currentStreak + user.maxStreak + user.wins
|
||||
+ user.timesPlayed + user.wonInTurn[0] + user.wonInTurn[1] + user.wonInTurn[2] + user.wonInTurn[3]
|
||||
+ user.wonInTurn[4] + user.wonInTurn[5] + user.lastDayWOTDFinished + ")");
|
||||
}
|
||||
|
||||
public void checkLogin(String username, String password){
|
||||
|
||||
public boolean checkLogin(String username, String password) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getWord() {
|
||||
|
||||
@@ -11,13 +11,11 @@ public class WordleServer extends Server {
|
||||
new WordleServer();
|
||||
}
|
||||
|
||||
|
||||
private DatabaseConnector db;
|
||||
|
||||
private HashMap<String, User> users;
|
||||
private Query query;
|
||||
|
||||
|
||||
public WordleServer() {
|
||||
this(DEFAULT_PORT);
|
||||
}
|
||||
@@ -42,7 +40,6 @@ public class WordleServer extends Server {
|
||||
@Override
|
||||
public void processClosingConnection(String pClientIP, int pClientPort) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,9 +61,13 @@ public class WordleServer extends Server {
|
||||
if (m.equalsIgnoreCase("USER")) {
|
||||
m = pMessage.substring(6, pMessage.length() - 1);
|
||||
u.setUsername(m);
|
||||
send(pClientIP, pClientPort, "+OK Bye");
|
||||
} else if (m.equalsIgnoreCase("PASS")) {
|
||||
m = pMessage.substring(6, pMessage.length() - 1);
|
||||
u.setPassword(m);
|
||||
if (u.getPassword() != null && u.getUsername() != null) {
|
||||
query.checkLogin(u.getUsername(), u.getPassword());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -79,5 +80,4 @@ public class WordleServer extends Server {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user