Просмотр исходного кода

Ytterligare en funktion uppdaterad

Axel Nordh 6 лет назад
Родитель
Сommit
95bed32298
2 измененных файлов с 20 добавлено и 17 удалено
  1. 11 15
      Assets/Scripts/Database/OnlineDatabase.cs
  2. 9 2
      dbFiles/OnlineGames.php

+ 11 - 15
Assets/Scripts/Database/OnlineDatabase.cs

@@ -404,7 +404,7 @@ public class OnlineDatabase : MonoBehaviour {
 
         string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
         if (response.Equals("")) {
-            Debug.Log("Something wrong with getting current player for game with id: " + gameId);
+            Debug.Log("Something wrong with getting round for game with id: " + gameId);
         }
         Int32.TryParse(response, out int round);
         return round;
@@ -420,6 +420,7 @@ public class OnlineDatabase : MonoBehaviour {
             Debug.Log("Something wrong with getting players from game with id: " + gameId);
         }
 
+        response = response = "{\"playerInfoList\" : " + response + " }";
         GamePlayerInfos gpi = new GamePlayerInfos();
         JsonUtility.FromJsonOverwrite(response, gpi);
 
@@ -438,21 +439,16 @@ public class OnlineDatabase : MonoBehaviour {
     public string CategoryString { get => categoryString; set => categoryString = value; }
 
     internal int GetQuestionsLost(int gameId, string playerName) {
-        string sql = "SELECT questionsLost FROM localGamePlayers WHERE gameId = " + gameId + " AND playerId = (SELECT id from localUsers WHERE name = '" + playerName + "')";
-        IDbConnection conn = new SqliteConnection(databaseUrl);
-        conn.Open();
-        IDbCommand cmd = conn.CreateCommand();
-        cmd.CommandText = sql;
-        IDataReader reader = cmd.ExecuteReader();
-        int returnValue = 0;
-        while (reader.Read()) {
-            returnValue = reader.GetInt32(0);
-        }
-        reader.Close();
-        cmd.Dispose();
-        conn.Close();
+        WWWForm form = new WWWForm();
+        form.AddField("f", "GetQuestionsLost");
+        form.AddField("userName", playerName);
 
-        return returnValue;
+        string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
+        if (response.Equals("")) {
+            Debug.Log("Something wrong with getting questions lost from game with id: " + gameId + " and playername " + playerName);
+        }
+        Int32.TryParse(response, out int questionsLost);
+        return questionsLost;
     }
 
     public string GetGameMode(int gameId) {

+ 9 - 2
dbFiles/OnlineGames.php

@@ -128,7 +128,7 @@
 		$result = $conn->query($sql);
 		$data = $result->fetch_assoc();
 		
-		return $data['userLockedQuestions'];
+		echo $data['userLockedQuestions'];
 	} else if ($callFunction === "SetFinishedDate") {
 		$finishedDate = $_POST['finishedDate'];
 		$sql = "UPDATE game SET finishedDate = '$finishedDate' WHERE id = $gameId";
@@ -148,7 +148,7 @@
 		$result = $conn->query($sql);
 		$data = $result->fetch_assoc();
 		
-		return $data['round'];
+		echo $data['round'];
 	} else if ($callFunction === "GetPlayers") {
 		$sql = "SELECT username, userLockedQuestions FROM gamePlayers INNER JOIN users ON users.id = gamePlayers.playerId WHERE gameId = $gameId";
 		$result = $conn->query($sql);
@@ -161,6 +161,13 @@
 			$i++;
 		}
 		echo json_encode($returnArray);
+	} else if ($callFunction === "GetQuestionsLost") {
+		$userName = $_POST['userName'];
+		$sql = "SELECT questionsLost FROM gamePlayers WHERE gameId = $gameId AND playerId = (SELECT id from users WHERE username = '$userName')";
+		$result = $conn->query($sql);
+		$data = $result->fetch_assoc();
+		
+		echo $data['questionsLost'];
 	}