OnlineDatabase.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mono.Data.Sqlite;
  5. using System.Data;
  6. using System;
  7. using UnityEngine.Networking;
  8. using System.IO;
  9. using System.Text;
  10. public class OnlineDatabase : MonoBehaviour {
  11. private const string onlineQuestionsUrl = "narkampen.nordh.xyz/narKampen/dbFiles/Question.php";
  12. private const string serverUrl = "narkampen.nordh.xyz/narKampen/dbFiles/";
  13. string gameMode;
  14. int winAmount = -1;
  15. public GameObject questionCardPrefab;
  16. private static OnlineDatabase instance;
  17. public static OnlineDatabase Instance { get { return instance; } }
  18. private void Awake() {
  19. if (instance == null) {
  20. instance = this;
  21. }
  22. }
  23. internal List<CategoryPanel.Category> GetCategories(List<CategoryPanel.Category> list, int gameId) {
  24. WWWForm form = new WWWForm();
  25. form.AddField("gameId", gameId);
  26. string response = CallOnlineDatabaseWithResponse("Categories.php", form);
  27. response = "{\"categoryList\" : " + response + " }";
  28. Categories categories = new Categories();
  29. JsonUtility.FromJsonOverwrite(response, categories);
  30. foreach (Category c in categories.categoryList) {
  31. CategoryPanel.Category cat = new CategoryPanel.Category();
  32. cat.color = new Color32((byte)c.r, (byte)c.g, (byte)c.b, (byte)c.a);
  33. cat.name = c.name;
  34. cat.id = c.id;
  35. cat.questionCount = c.count;
  36. list.Add(cat);
  37. }
  38. return list;
  39. }
  40. internal int SetupNewOnlineGame(int limitPerQuestion, int limitPerPlayer, int toWin, List<InviteSearchResult> inviteUsers, List<int> selectedCategories) {
  41. List<int> playerIds = new List<int>();
  42. inviteUsers.ForEach(i => playerIds.Add(i.GetId()));
  43. int currentUser = Database.Instance.GetSignedInUser().Key;
  44. playerIds.Add(currentUser);
  45. var form = new WWWForm();
  46. form.AddField("currentUser", currentUser);
  47. form.AddField("winNumber", toWin);
  48. form.AddField("limitPerQuestion", limitPerQuestion);
  49. form.AddField("limitPerPlayer", limitPerPlayer);
  50. form.AddField("playerIds", String.Join(",", playerIds));
  51. form.AddField("categoryIds", String.Join(",", selectedCategories));
  52. string response = CallOnlineDatabaseWithResponse("NewOnlineGame.php", form);
  53. if (response.Equals("")) {
  54. Debug.Log("Expected gameId in response for creating new game but did not get one");
  55. }
  56. if (Int32.TryParse(response, out int newGameId)) {
  57. return newGameId;
  58. } else {
  59. Debug.Log("Failed to get new game id with response " + response);
  60. return -1;
  61. }
  62. }
  63. [Serializable]
  64. public class Question {
  65. public string question;
  66. public string answer;
  67. public string id;
  68. public string category;
  69. public string categoryName;
  70. public int r;
  71. public int g;
  72. public int b;
  73. public int a;
  74. }
  75. [Serializable]
  76. public class Questions {
  77. public List<Question> questionsList = new List<Question>();
  78. }
  79. [Serializable]
  80. public class PlayerInfo {
  81. public string username;
  82. public string status;
  83. }
  84. [Serializable]
  85. public class PlayerInfos {
  86. public List<PlayerInfo> playerInfoList = new List<PlayerInfo>();
  87. }
  88. [Serializable]
  89. public class GamePlayerInfo {
  90. public string username;
  91. public string userLockedQuestions;
  92. }
  93. [Serializable]
  94. public class GamePlayerInfos {
  95. public List<GamePlayerInfo> gamePlayerInfoList = new List<GamePlayerInfo>();
  96. }
  97. [Serializable]
  98. public class Category {
  99. public int r;
  100. public int g;
  101. public int b;
  102. public int a;
  103. public int id;
  104. public string name;
  105. public int count;
  106. }
  107. [Serializable]
  108. public class Categories {
  109. public List<Category> categoryList = new List<Category>();
  110. }
  111. [Serializable]
  112. public class OnlineGame {
  113. public string id;
  114. public string winNumber;
  115. public string answerTimer;
  116. public string roundTimeLimit;
  117. public string currentPlayer;
  118. public string round;
  119. public string startDate;
  120. public string lastPlayedDate;
  121. public string finishedDate;
  122. public string status;
  123. public int userId;
  124. public string username;
  125. public int userLockedQuestions;
  126. }
  127. [Serializable]
  128. public class OnlineGames {
  129. public List<OnlineGame> onlineGamesList = new List<OnlineGame>();
  130. }
  131. [Serializable]
  132. public class UserName {
  133. public string id;
  134. public string username;
  135. }
  136. [Serializable]
  137. public class UserNames {
  138. public List<UserName> usernamesList = new List<UserName>();
  139. }
  140. private void CallDatabase(string filename, WWWForm formData) {
  141. string postUrl = serverUrl + filename;
  142. UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
  143. www.SendWebRequest();
  144. if (www.isNetworkError || www.isHttpError) {
  145. Debug.Log(www.error);
  146. } else {
  147. while (!www.isDone) {
  148. }
  149. }
  150. }
  151. private string CallOnlineDatabaseWithResponse(string filename, WWWForm formData) {
  152. string postUrl = serverUrl + filename;
  153. UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
  154. www.SendWebRequest();
  155. if (www.isNetworkError || www.isHttpError) {
  156. Debug.Log(www.error);
  157. } else {
  158. while (!www.isDone) {
  159. }
  160. }
  161. return www.downloadHandler.text;
  162. }
  163. string questionString = "";
  164. string answerString = "";
  165. string idString = "";
  166. string categoryString = "";
  167. public string QuestionString { get => questionString; set => questionString = value; }
  168. internal void SendGameOverMessage(int gameId, List<KeyValuePair<string, int>> players, string currentPlayer)
  169. {
  170. string message = "Den som van var " + currentPlayer + "!"; //TODO
  171. string title = "Spelet slut!"; //TODO
  172. WWWForm form = new WWWForm();
  173. form.AddField("gameId", gameId);
  174. form.AddField("message", message);
  175. form.AddField("title", title);
  176. form.AddField("winningPlayer", currentPlayer);
  177. form.AddField("messageType", "gameFinishedMessage");
  178. int index = 0;
  179. foreach (KeyValuePair<String, int> player in players) {
  180. form.AddField("player" + index++, player.Key);
  181. }
  182. CallDatabase("FCMMessageing.php", form);
  183. }
  184. private void Start() {
  185. if (instance == null) {
  186. instance = this;
  187. }
  188. }
  189. internal void SetLastPlayedDate(int gameId) {
  190. WWWForm form = new WWWForm();
  191. form.AddField("gameId", gameId);
  192. form.AddField("f", "SetLastPlayed");
  193. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  194. if (!response.Equals("")) {
  195. Debug.Log(response);
  196. }
  197. }
  198. internal void SetGameFinished(int gameId, string gameMode)
  199. {
  200. WWWForm formData = new WWWForm();
  201. formData.AddField("gameId", gameId);
  202. formData.AddField("f", "GameFinished");
  203. CallDatabase("OnlineGames.php", formData);
  204. }
  205. internal void DeclineOnlineGame(string userName, int gameId) {
  206. WWWForm formData = new WWWForm();
  207. formData.AddField("userId", -1);
  208. formData.AddField("f", "decline");
  209. formData.AddField("gameId", gameId);
  210. formData.AddField("userName", userName);
  211. CallDatabase("OnlineGames.php", formData);
  212. }
  213. internal void AcceptOnlineGame(string userName, int gameId) {
  214. WWWForm formData = new WWWForm();
  215. formData.AddField("userId", -1);
  216. formData.AddField("f", "accept");
  217. formData.AddField("gameId", gameId);
  218. formData.AddField("userName", userName);
  219. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
  220. if (!response.Equals("")) {
  221. Debug.Log(response);
  222. }
  223. }
  224. //TODO Försök att ta bort alla utom 1 databas anrop i denna
  225. internal List<OnlineGameScript> GetOnlineGames(int userId, string userName, GameObject prefab) {
  226. WWWForm formData = new WWWForm();
  227. formData.AddField("userId", userId);
  228. formData.AddField("f", "list");
  229. formData.AddField("gameId", -1);
  230. formData.AddField("userName", userName);
  231. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
  232. if (response.Equals("No games found for user") || response.Equals("")) {
  233. return null;
  234. }
  235. response = "{\"onlineGamesList\" : " + response + " }";
  236. OnlineGames og = new OnlineGames();
  237. JsonUtility.FromJsonOverwrite(response, og);
  238. GameObject onlineGameObject;
  239. OnlineGameScript ogs = null;
  240. List<OnlineGameScript> games = new List<OnlineGameScript>();
  241. foreach (OnlineGame game in og.onlineGamesList) {
  242. onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  243. ogs = onlineGameObject.GetComponent<OnlineGameScript>();
  244. ogs.CurrentPlayer = game.currentPlayer;
  245. ogs.SetGameStatus(game.status);
  246. Int32.TryParse(game.id, out int gameId);
  247. List<KeyValuePair<string, string>> playerInfos = GetGameInfo(gameId);
  248. if (game.status.Equals("PENDING")) {
  249. string extraInfo = "";
  250. foreach (KeyValuePair<string, string> s in playerInfos) {
  251. if (s.Value.Equals("WAITING") && s.Key.Equals(userName, StringComparison.InvariantCultureIgnoreCase)) {
  252. ogs.SetGameStatus("INVITED");
  253. extraInfo += s.Key + ",";
  254. } else if (s.Value.EndsWith("WAITING")) {
  255. extraInfo += s.Key + ",";
  256. }
  257. }
  258. extraInfo = extraInfo.TrimEnd(',');
  259. ogs.SetGameStatusText(extraInfo);
  260. } else if (game.status.Equals("OTHERS_TURN")) {
  261. ogs.SetGameStatusText(game.playerToAct);
  262. } else if (game.status.Equals("ACTIVE")) {
  263. ogs.SetGameStatusText(game.playerToAct);
  264. } else {
  265. ogs.SetGameStatusText();
  266. }
  267. ogs.SetId(game.id);
  268. ogs.SetWinNumber(game.winNumber);
  269. ogs.SetAnswerTimer(game.answerTimer);
  270. ogs.SetRoundTimeLimit(game.roundTimeLimit);
  271. ogs.SetRound(game.round);
  272. ogs.StartDate = game.startDate;
  273. ogs.LastPlayedDate = game.lastPlayedDate;
  274. games.Add(ogs);
  275. ogs.PlayerInfos = playerInfos;
  276. }
  277. return games;
  278. }
  279. internal List<KeyValuePair<string, string>> GetGameInfo(int gameId) {
  280. List<KeyValuePair<string, string>> returnList = new List<KeyValuePair<string, string>>();
  281. WWWForm form = new WWWForm();
  282. form.AddField("f", "GetGameInfo");
  283. form.AddField("gameId", gameId);
  284. string response = CallOnlineDatabaseWithResponse("OnlineGameInfo.php", form);
  285. response = "{\"playerInfoList\" : " + response + " }";
  286. PlayerInfos pi = new PlayerInfos();
  287. JsonUtility.FromJsonOverwrite(response, pi);
  288. foreach (PlayerInfo p in pi.playerInfoList) {
  289. KeyValuePair<string, string> player = new KeyValuePair<string, string>(p.username, p.status);
  290. returnList.Add(player);
  291. }
  292. return returnList;
  293. }
  294. internal void SetQuestionsLost(int gameId, string playerName, int questionsLost) {
  295. WWWForm form = new WWWForm();
  296. form.AddField("f", "SetQuestionsLost");
  297. form.AddField("questionsLost", questionsLost);
  298. form.AddField("userName", playerName);
  299. form.AddField("gameId", gameId);
  300. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  301. if (!response.Equals("")) {
  302. Debug.Log(response);
  303. }
  304. }
  305. internal void RemoveGame(int gameId) {
  306. WWWForm form = new WWWForm();
  307. form.AddField("f", "DeleteGame");
  308. form.AddField("gameId", gameId);
  309. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  310. if (!response.Equals("")) {
  311. Debug.Log(response);
  312. }
  313. }
  314. public string GetCurrentPlayer(int gameId) {
  315. WWWForm form = new WWWForm();
  316. form.AddField("f", "CurrentPlayer");
  317. form.AddField("gameId", gameId);
  318. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  319. if (response.Equals("")) {
  320. Debug.Log("Something wrong with current player for game with id: " + gameId);
  321. }
  322. return response;
  323. }
  324. public void SetCurrentPlayer(int gameId, string currentPlayer) {
  325. WWWForm form = new WWWForm();
  326. form.AddField("f", "SetCurrentPlayer");
  327. form.AddField("gameId", gameId);
  328. form.AddField("userName", currentPlayer);
  329. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  330. if (!response.Equals("")) {
  331. Debug.Log(response);
  332. }
  333. }
  334. internal int GetPlayerPoints(int gameId, string playerName) {
  335. WWWForm form = new WWWForm();
  336. form.AddField("f", "GetPlayerPoints");
  337. form.AddField("gameId", gameId);
  338. form.AddField("userName", playerName);
  339. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  340. if (response.Equals("")) {
  341. Debug.Log("Something wrong with current player for game with id: " + gameId);
  342. }
  343. Int32.TryParse(response, out int playerPoints);
  344. return playerPoints;
  345. }
  346. internal void SetFinishedDate(int gameId, string finishedDate) {
  347. WWWForm form = new WWWForm();
  348. form.AddField("f", "SetFinishedDate");
  349. form.AddField("gameId", gameId);
  350. form.AddField("finishedDate", finishedDate);
  351. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  352. if (!response.Equals("")) {
  353. Debug.Log(response);
  354. }
  355. }
  356. internal void SetRoundValue(int gameId, int round) {
  357. WWWForm form = new WWWForm();
  358. form.AddField("f", "SetRound");
  359. form.AddField("gameId", gameId);
  360. form.AddField("round", round);
  361. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  362. if (!response.Equals("")) {
  363. Debug.Log(response);
  364. }
  365. }
  366. internal int GetRoundValue(int gameId) {
  367. WWWForm form = new WWWForm();
  368. form.AddField("f", "GetRound");
  369. form.AddField("gameId", gameId);
  370. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  371. if (response.Equals("")) {
  372. Debug.Log("Something wrong with getting round for game with id: " + gameId);
  373. }
  374. Int32.TryParse(response, out int round);
  375. return round;
  376. }
  377. internal List<KeyValuePair<string, int>> GetPlayersForGame(int gameId) {
  378. WWWForm form = new WWWForm();
  379. form.AddField("f", "GetPlayers");
  380. form.AddField("gameId", gameId);
  381. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  382. if (response.Equals("")) {
  383. Debug.Log("Something wrong with getting players from game with id: " + gameId);
  384. }
  385. response = response = "{\"gamePlayerInfoList\" : " + response + " }";
  386. GamePlayerInfos gpi = new GamePlayerInfos();
  387. JsonUtility.FromJsonOverwrite(response, gpi);
  388. List<KeyValuePair<string, int>> returnList = new List<KeyValuePair<string, int>>();
  389. foreach (GamePlayerInfo p in gpi.gamePlayerInfoList) {
  390. Int32.TryParse(p.userLockedQuestions, out int points);
  391. KeyValuePair<string, int> player = new KeyValuePair<string, int>(p.username, points);
  392. returnList.Add(player);
  393. }
  394. return returnList;
  395. }
  396. public string AnswerString { get => answerString; set => answerString = value; }
  397. public string IdString { get => idString; set => idString = value; }
  398. public string CategoryString { get => categoryString; set => categoryString = value; }
  399. internal int GetQuestionsLost(int gameId, string playerName) {
  400. WWWForm form = new WWWForm();
  401. form.AddField("f", "GetQuestionsLost");
  402. form.AddField("userName", playerName);
  403. form.AddField("gameId", gameId);
  404. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  405. if (response.Equals("")) {
  406. Debug.Log("Something wrong with getting questions lost from game with id: " + gameId + " and playername " + playerName);
  407. }
  408. Int32.TryParse(response, out int questionsLost);
  409. return questionsLost;
  410. }
  411. internal int GetWinCondition(int gameId) {
  412. if (winAmount == -1) {
  413. WWWForm form = new WWWForm();
  414. form.AddField("gameId", gameId);
  415. form.AddField("f", "GetWinCondition");
  416. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  417. Int32.TryParse(response, out this.winAmount);
  418. }
  419. return this.winAmount;
  420. }
  421. public NewQuestionData newQuestionData;
  422. public NewQuestionData GetNewQuestion(List<int> userAnsweredQuestions, int userId) {
  423. int gameId = GameObject.Find("GameManager").GetComponent<GameManagerScript>().GameId;
  424. Question q = GetQuestionData(gameId, userId);
  425. Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  426. // Color32 questionCategoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  427. Int32.TryParse(q.category, out int categoryId);
  428. Int32.TryParse(q.id, out int questionId);
  429. NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
  430. return questionData;
  431. }
  432. public void SavePlayersQuestion(List<int> questionsToSave, string playerNameValue, int gameId) {
  433. WWWForm form = new WWWForm();
  434. form.AddField("f", "SavePlayerQuestions");
  435. form.AddField("gameId", gameId);
  436. form.AddField("questionsToSave", String.Join(",",questionsToSave));
  437. form.AddField("userName", playerNameValue);
  438. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  439. if (!response.Equals("")) {
  440. Debug.Log(response);
  441. }
  442. }
  443. public List<NewQuestionData> GetPlayerQuestions(int gameId, string playerName) {
  444. List<NewQuestionData> questions = new List<NewQuestionData>();
  445. WWWForm form = new WWWForm();
  446. form.AddField("f", "PlayerQuestions");
  447. form.AddField("gameId", gameId);
  448. form.AddField("userName", playerName);
  449. string response = CallOnlineDatabaseWithResponse("OnlineGameInfo.php", form);
  450. response = "{\"questionsList\" : " + response + "}";
  451. Questions ql = new Questions();
  452. JsonUtility.FromJsonOverwrite(response, ql);
  453. foreach (Question q in ql.questionsList) {
  454. /*GameObject question = Instantiate(questionCardPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  455. NewQuestionData qc = question.GetComponent<NewQuestionData>();
  456. */
  457. Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  458. Int32.TryParse(q.category, out int categoryId);
  459. Int32.TryParse(q.id, out int questionId);
  460. NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
  461. questions.Add(questionData);
  462. }
  463. return questions;
  464. }
  465. private Question GetQuestionData(int gameId, int playerId) {
  466. WWWForm form = new WWWForm();
  467. form.AddField("gameId", gameId);
  468. form.AddField("playerId", playerId);
  469. string response = CallOnlineDatabaseWithResponse("Question.php", form);
  470. // Show result
  471. response = "{\"questionsList\" : [ " + response + " ]}";
  472. Questions qe = new Questions();
  473. JsonUtility.FromJsonOverwrite(response, qe);
  474. return qe.questionsList[0];
  475. }
  476. public List<UserName> GetUsersToInvite(string searchString) {
  477. string postUrl = "narkampen.nordh.xyz/narKampen/dbFiles/PlayerSearch.php?";
  478. postUrl += "search=" + UnityWebRequest.EscapeURL(searchString);
  479. UserNames uNames = new UserNames();
  480. UnityWebRequest www = UnityWebRequest.Get(postUrl);
  481. www.SendWebRequest();
  482. if (www.isNetworkError || www.isHttpError) {
  483. Debug.Log(www.error);
  484. } else {
  485. while (!www.isDone) {
  486. }
  487. // Show result
  488. string jsonData = www.downloadHandler.text;
  489. if (!jsonData.Equals("")) {
  490. jsonData = "{\"usernamesList\" : " + jsonData + " }";
  491. JsonUtility.FromJsonOverwrite(jsonData, uNames);
  492. }
  493. }
  494. // TODO handle empty
  495. return uNames.usernamesList;
  496. }
  497. internal void SendNextPlayerMessage(int gameId, String nextPlayer)
  498. {
  499. WWWForm form = new WWWForm();
  500. form.AddField("gameId", gameId);
  501. form.AddField("playerName", nextPlayer);
  502. form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_TITLE"));
  503. List<KeyValuePair<string, int>> players = OnlineDatabase.Instance.GetPlayersForGame(gameId);
  504. StringBuilder sb = new StringBuilder();
  505. foreach (KeyValuePair<String, int> player in players)
  506. {
  507. sb.AppendLine(player.Key + " (" + player.Value + ")");
  508. }
  509. String message = String.Format(LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_MESSAGE"),sb.ToString());
  510. form.AddField("message", message);
  511. form.AddField("type", "FCMNextPlayer");
  512. //string response = CallOnlineDatabaseWithResponse("FCMNextPlayer.php", form);
  513. CallDatabase("FCMMessageing.php", form);
  514. }
  515. internal void SendInviteForNewGame(int gameId, List<String> Players, String inviter) {
  516. WWWForm form = new WWWForm();
  517. form.AddField("gameId", gameId);
  518. int index = 0;
  519. foreach(String player in Players) {
  520. form.AddField("player" + index++, player);
  521. }
  522. form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEW_GAME_TITLE"));
  523. form.AddField("message", String.Format(LocalizationManager.Instance.GetText("FCM_NEW_GAME_MESSAGE"), inviter));
  524. form.AddField("type", "InviteMessage");
  525. CallDatabase("FCMMessageing.php", form);
  526. }
  527. internal void UpdatePlayerToken(int userId, string myToken)
  528. {
  529. WWWForm form = new WWWForm();
  530. form.AddField("userId", userId);
  531. form.AddField("token", myToken);
  532. form.AddField("f", "UpdatePlayerToken");
  533. CallDatabase("OnlineGames.php", form);
  534. }
  535. internal List<string> FindRandomPlayer() {
  536. List<string> returnValue = new List<string>();
  537. WWWForm form = new WWWForm();
  538. form.AddField("f", "FindRandomPlayer");
  539. String response = CallOnlineDatabaseWithResponse("", form);
  540. //TODO FIX ME
  541. return returnValue;
  542. }
  543. }