|
|
@@ -81,6 +81,24 @@ public class Database : MonoBehaviour {
|
|
|
public List<Question> questionsList = new List<Question>();
|
|
|
}
|
|
|
|
|
|
+ [Serializable]
|
|
|
+ public class OnlineGame {
|
|
|
+ public string id;
|
|
|
+ public string winNumber;
|
|
|
+ public string answerTimer;
|
|
|
+ public string roundTimeLimit;
|
|
|
+ public string currentPlayer;
|
|
|
+ public string round;
|
|
|
+ public string startDate;
|
|
|
+ public string LastPlayedDate;
|
|
|
+ public string finishedDate;
|
|
|
+ }
|
|
|
+
|
|
|
+ [Serializable]
|
|
|
+ public class OnlineGames {
|
|
|
+ public List<OnlineGame> onlineGamesList = new List<OnlineGame>();
|
|
|
+ }
|
|
|
+
|
|
|
[Serializable]
|
|
|
public class UserName {
|
|
|
public string id;
|
|
|
@@ -92,8 +110,8 @@ public class Database : MonoBehaviour {
|
|
|
public List<UserName> usernamesList = new List<UserName>();
|
|
|
}
|
|
|
|
|
|
- private void CallDatabase(string fileName, WWWForm formData) {
|
|
|
- string postUrl = serverUrl + fileName;
|
|
|
+ private void CallDatabase(string filename, WWWForm formData) {
|
|
|
+ string postUrl = serverUrl + filename;
|
|
|
|
|
|
UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
|
|
|
www.SendWebRequest();
|
|
|
@@ -106,6 +124,22 @@ public class Database : MonoBehaviour {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private string CallOnlineDatabaseWithResponse(string filename, WWWForm formData) {
|
|
|
+ string postUrl = serverUrl + filename;
|
|
|
+
|
|
|
+ UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
|
|
|
+ www.SendWebRequest();
|
|
|
+
|
|
|
+ if (www.isNetworkError || www.isHttpError) {
|
|
|
+ Debug.Log(www.error);
|
|
|
+ } else {
|
|
|
+ while (!www.isDone) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return www.downloadHandler.text;
|
|
|
+ }
|
|
|
+
|
|
|
internal void SetLastPlayedDate(int gameId) {
|
|
|
string sql = "UPDATE game SET lastPlayedDate = DATE() WHERE id = " + gameId;
|
|
|
IDbCommand cmd = GetConnection();
|
|
|
@@ -224,7 +258,19 @@ public class Database : MonoBehaviour {
|
|
|
}
|
|
|
|
|
|
internal void GetOnlineGames(int userId) {
|
|
|
- string sql = "SELECT * FROM games WHERE userId = " + userId;
|
|
|
+
|
|
|
+ WWWForm formData = new WWWForm();
|
|
|
+ formData.AddField("userId", userId);
|
|
|
+
|
|
|
+ string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
|
|
|
+
|
|
|
+ response = "{\"onlineGameList\" : [ " + response + " ]}";
|
|
|
+
|
|
|
+ OnlineGames og = new OnlineGames();
|
|
|
+ JsonUtility.FromJsonOverwrite(response, og);
|
|
|
+
|
|
|
+
|
|
|
+ //TODO Continue development here
|
|
|
}
|
|
|
|
|
|
internal List<LocalGameScript> GetLocalGames(GameObject prefab) {
|