|
|
@@ -475,69 +475,15 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
return this.gameMode;
|
|
|
}
|
|
|
|
|
|
- public void LinkPlayersToLocalGame(List<string> playerNames, int gameId) {
|
|
|
-
|
|
|
- IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
- conn.Open();
|
|
|
- string questionSql = "SELECT id FROM questions order by random() limit 1";
|
|
|
- IDbCommand cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = questionSql;
|
|
|
- IDataReader reader = cmd.ExecuteReader();
|
|
|
- int questionId = -1;
|
|
|
- while (reader.Read()) {
|
|
|
- questionId = reader.GetInt32(0);
|
|
|
- }
|
|
|
- foreach (string player in playerNames) {
|
|
|
- string sql = "SELECT id FROM localUsers WHERE name = '" + player + "'";
|
|
|
- int playerId;
|
|
|
- cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
- reader = cmd.ExecuteReader();
|
|
|
- if (reader.Read()) {
|
|
|
- playerId = reader.GetInt32(0);
|
|
|
- } else {
|
|
|
- reader.Close();
|
|
|
- sql = "INSERT INTO localUsers (name) VALUES ('" + player + "')";
|
|
|
- cmd.CommandText = sql;
|
|
|
- cmd.ExecuteNonQuery();
|
|
|
-
|
|
|
- cmd.CommandText = "SELECT last_insert_rowid()";
|
|
|
- Int64 lastInsert64 = (Int64)cmd.ExecuteScalar();
|
|
|
- playerId = (int)lastInsert64;
|
|
|
- }
|
|
|
- cmd.Dispose();
|
|
|
- reader.Close();
|
|
|
-
|
|
|
- LinkPlayerToGame(playerId, gameId);
|
|
|
- SavePlayersQuestion(questionId.ToString(), player, gameId);
|
|
|
-
|
|
|
- }
|
|
|
- IDbCommand cmd2 = conn.CreateCommand();
|
|
|
- cmd2.CommandText = "UPDATE game SET currentPlayer = '" + playerNames[0] + "' WHERE id = " + gameId;
|
|
|
- cmd2.ExecuteNonQuery();
|
|
|
- cmd2.Dispose();
|
|
|
- conn.Close();
|
|
|
- }
|
|
|
-
|
|
|
- private void LinkPlayerToGame(int playerId, int gameId) {
|
|
|
- string sql = "INSERT INTO localGamePlayers (gameId, playerId) VALUES (" + gameId + ", " + playerId + ")";
|
|
|
- SqliteConnection conn2 = new SqliteConnection(databaseUrl);
|
|
|
- conn2.Open();
|
|
|
- IDbCommand cmd = conn2.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
- cmd.ExecuteNonQuery();
|
|
|
- cmd.Dispose();
|
|
|
- conn2.Close();
|
|
|
- }
|
|
|
-
|
|
|
internal int GetWinCondition(int gameId) {
|
|
|
if (winAmount == -1) {
|
|
|
WWWForm form = new WWWForm();
|
|
|
form.AddField("gameId", gameId);
|
|
|
+ form.AddField("f", "GetWinCondition");
|
|
|
|
|
|
string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
|
|
|
|
|
|
- Int32.TryParse(response, out int winAmount);
|
|
|
+ Int32.TryParse(response, out this.winAmount);
|
|
|
|
|
|
}
|
|
|
return this.winAmount;
|
|
|
@@ -558,24 +504,17 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
return nq;
|
|
|
}
|
|
|
|
|
|
- public void SavePlayersQuestion(string questionId, string playerNameValue, int gameId) {
|
|
|
- string gameMode = PlayerPrefs.GetString("GameMode");
|
|
|
-
|
|
|
- Int32.TryParse(questionId, out int qId);
|
|
|
-
|
|
|
- if (gameMode.Equals("Local")) {
|
|
|
- string sql = "INSERT OR IGNORE INTO usersLockedQuestions (playerName, questionId, gameId) VALUES ('" + playerNameValue + "'," + qId + "," + gameId + ")";
|
|
|
- IDbConnection conn = new SqliteConnection(databaseUrl);
|
|
|
- conn.Open();
|
|
|
- IDbCommand cmd = conn.CreateCommand();
|
|
|
- cmd.CommandText = sql;
|
|
|
+ public void SavePlayersQuestion(List<int> questionsToSave, string playerNameValue, int gameId) {
|
|
|
+ WWWForm form = new WWWForm();
|
|
|
+ form.AddField("f", "SavePlayerQuestions");
|
|
|
+ form.AddField("gameId", gameId);
|
|
|
+ form.AddField("questionsToSave", questionsToSave.ToString());
|
|
|
+ form.AddField("userName", playerNameValue);
|
|
|
|
|
|
- cmd.ExecuteReader();
|
|
|
+ string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
|
|
|
|
|
|
- cmd.Dispose();
|
|
|
- conn.Close();
|
|
|
- } else {
|
|
|
- // TODO Save question to database online;
|
|
|
+ if (!response.Equals("")) {
|
|
|
+ Debug.Log(response);
|
|
|
}
|
|
|
}
|
|
|
|