OnlineDatabase.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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 = "nordh.xyz/narKampen/dbFiles/Question.php";
  12. private const string serverUrl = "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 string userId;
  124. public string username;
  125. public string userLockedQuestions;
  126. public string playerStatus;
  127. }
  128. [Serializable]
  129. public class OnlineGames {
  130. public List<OnlineGame> onlineGamesList = new List<OnlineGame>();
  131. }
  132. [Serializable]
  133. public class UserName {
  134. public string id;
  135. public string username;
  136. }
  137. [Serializable]
  138. public class UserNames {
  139. public List<UserName> usernamesList = new List<UserName>();
  140. }
  141. private void CallDatabase(string filename, WWWForm formData) {
  142. string postUrl = serverUrl + filename;
  143. UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
  144. www.SendWebRequest();
  145. if (www.isNetworkError || www.isHttpError) {
  146. Debug.Log(www.error);
  147. } else {
  148. while (!www.isDone) {
  149. }
  150. }
  151. }
  152. private string CallOnlineDatabaseWithResponse(string filename, WWWForm formData) {
  153. string postUrl = serverUrl + filename;
  154. UnityWebRequest www = UnityWebRequest.Post(postUrl, formData);
  155. www.SendWebRequest();
  156. if (www.isNetworkError || www.isHttpError) {
  157. Debug.Log(www.error);
  158. } else {
  159. while (!www.isDone) {
  160. }
  161. }
  162. return www.downloadHandler.text;
  163. }
  164. string questionString = "";
  165. string answerString = "";
  166. string idString = "";
  167. string categoryString = "";
  168. public string QuestionString { get => questionString; set => questionString = value; }
  169. internal void SendGameOverMessage(int gameId, List<KeyValuePair<string, int>> players, string currentPlayer)
  170. {
  171. string message = "Den som van var " + currentPlayer + "!"; //TODO
  172. string title = "Spelet slut!"; //TODO
  173. WWWForm form = new WWWForm();
  174. form.AddField("gameId", gameId);
  175. form.AddField("message", message);
  176. form.AddField("title", title);
  177. form.AddField("winningPlayer", currentPlayer);
  178. form.AddField("messageType", "gameFinishedMessage");
  179. int index = 0;
  180. foreach (KeyValuePair<String, int> player in players) {
  181. form.AddField("player" + index++, player.Key);
  182. }
  183. CallDatabase("FCMMessageing.php", form);
  184. }
  185. private void Start() {
  186. if (instance == null) {
  187. instance = this;
  188. }
  189. }
  190. internal void SetLastPlayedDate(int gameId) {
  191. WWWForm form = new WWWForm();
  192. form.AddField("gameId", gameId);
  193. form.AddField("f", "SetLastPlayed");
  194. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  195. if (!response.Equals("")) {
  196. Debug.Log(response);
  197. }
  198. }
  199. internal void SetGameFinished(int gameId, string gameMode)
  200. {
  201. WWWForm formData = new WWWForm();
  202. formData.AddField("gameId", gameId);
  203. formData.AddField("f", "GameFinished");
  204. CallDatabase("OnlineGames.php", formData);
  205. }
  206. internal void DeclineOnlineGame(string userName, int gameId) {
  207. WWWForm formData = new WWWForm();
  208. formData.AddField("userId", -1);
  209. formData.AddField("f", "decline");
  210. formData.AddField("gameId", gameId);
  211. formData.AddField("userName", userName);
  212. CallDatabase("OnlineGames.php", formData);
  213. }
  214. internal void AcceptOnlineGame(string userName, int gameId) {
  215. WWWForm formData = new WWWForm();
  216. formData.AddField("userId", -1);
  217. formData.AddField("f", "accept");
  218. formData.AddField("gameId", gameId);
  219. formData.AddField("userName", userName);
  220. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
  221. if (!response.Equals("")) {
  222. Debug.Log(response);
  223. }
  224. }
  225. //TODO Försök att ta bort alla utom 1 databas anrop i denna
  226. internal List<OnlineGameScript> GetOnlineGames(int userId, string userName, GameObject prefab) {
  227. WWWForm formData = new WWWForm();
  228. formData.AddField("userId", userId);
  229. formData.AddField("f", "list");
  230. formData.AddField("gameId", -1);
  231. formData.AddField("userName", userName);
  232. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", formData);
  233. if (response.Equals("No games found for user") || response.Equals("")) {
  234. return null;
  235. }
  236. response = "{\"onlineGamesList\" : " + response + " }";
  237. OnlineGames og = new OnlineGames();
  238. JsonUtility.FromJsonOverwrite(response, og);
  239. GameObject onlineGameObject;
  240. OnlineGameScript ogs = null;
  241. List<OnlineGameScript> games = new List<OnlineGameScript>();
  242. int gameId = -1;
  243. foreach (OnlineGame game in og.onlineGamesList) {
  244. Int32.TryParse(game.id, out int currentGameId);
  245. if (gameId != currentGameId) { // Spel ej i listan
  246. if (ogs != null) { // lägg till spel i listan, inte första gången
  247. SetGlobalGameInfo(userName, ogs, gameId, game);
  248. if (game.currentPlayer.Equals(Database.Instance.GetSignedInUser().Value, StringComparison.InvariantCultureIgnoreCase)) {
  249. ogs.SetGameStatus("YOUR_TURN");
  250. }
  251. games.Add(ogs);
  252. }
  253. onlineGameObject = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  254. ogs = onlineGameObject.GetComponent<OnlineGameScript>();
  255. gameId = currentGameId;
  256. if (game.currentPlayer.Equals(game.userId)) { // om första raden i spelinfo är annan spelare och det är dennes tur att agera
  257. ogs.CurrentPlayer = game.username;
  258. ogs.addPlayer(game.username);
  259. ogs.addPlayerInfo(game.username, game.playerStatus);
  260. }
  261. } else { // Spel redan i listan, fyll på med info
  262. ogs.addPlayer(game.username);
  263. ogs.addPlayerInfo(game.username, game.playerStatus);
  264. if (game.currentPlayer.Equals(game.userId)) {
  265. ogs.CurrentPlayer = game.username;
  266. }
  267. }
  268. }
  269. SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
  270. games.Add(ogs);
  271. return games;
  272. }
  273. private void SetGlobalGameInfo(string userName, OnlineGameScript ogs, int gameId, OnlineGame game) {
  274. ogs.SetGameStatus(game.status);
  275. ogs.SetId(game.id);
  276. ogs.SetWinNumber(game.winNumber);
  277. ogs.SetAnswerTimer(game.answerTimer);
  278. ogs.SetRoundTimeLimit(game.roundTimeLimit);
  279. ogs.SetRound(game.round);
  280. ogs.StartDate = game.startDate;
  281. ogs.LastPlayedDate = game.lastPlayedDate;
  282. }
  283. internal List<KeyValuePair<string, string>> GetGameInfo(int gameId) {
  284. List<KeyValuePair<string, string>> returnList = new List<KeyValuePair<string, string>>();
  285. WWWForm form = new WWWForm();
  286. form.AddField("f", "GetGameInfo");
  287. form.AddField("gameId", gameId);
  288. string response = CallOnlineDatabaseWithResponse("OnlineGameInfo.php", form);
  289. response = "{\"playerInfoList\" : " + response + " }";
  290. PlayerInfos pi = new PlayerInfos();
  291. JsonUtility.FromJsonOverwrite(response, pi);
  292. foreach (PlayerInfo p in pi.playerInfoList) {
  293. KeyValuePair<string, string> player = new KeyValuePair<string, string>(p.username, p.status);
  294. returnList.Add(player);
  295. }
  296. return returnList;
  297. }
  298. internal void SetQuestionsLost(int gameId, string playerName, int questionsLost) {
  299. WWWForm form = new WWWForm();
  300. form.AddField("f", "SetQuestionsLost");
  301. form.AddField("questionsLost", questionsLost);
  302. form.AddField("userName", playerName);
  303. form.AddField("gameId", gameId);
  304. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  305. if (!response.Equals("")) {
  306. Debug.Log(response);
  307. }
  308. }
  309. internal void RemoveGame(int gameId) {
  310. WWWForm form = new WWWForm();
  311. form.AddField("f", "DeleteGame");
  312. form.AddField("gameId", gameId);
  313. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  314. if (!response.Equals("")) {
  315. Debug.Log(response);
  316. }
  317. }
  318. public string GetCurrentPlayer(int gameId) {
  319. WWWForm form = new WWWForm();
  320. form.AddField("f", "CurrentPlayer");
  321. form.AddField("gameId", gameId);
  322. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  323. if (response.Equals("")) {
  324. Debug.Log("Something wrong with current player for game with id: " + gameId);
  325. }
  326. return response;
  327. }
  328. public void SetCurrentPlayer(int gameId, string currentPlayer) {
  329. WWWForm form = new WWWForm();
  330. form.AddField("f", "SetCurrentPlayer");
  331. form.AddField("gameId", gameId);
  332. form.AddField("userName", currentPlayer);
  333. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  334. if (!response.Equals("")) {
  335. Debug.Log(response);
  336. }
  337. }
  338. internal int GetPlayerPoints(int gameId, string playerName) {
  339. WWWForm form = new WWWForm();
  340. form.AddField("f", "GetPlayerPoints");
  341. form.AddField("gameId", gameId);
  342. form.AddField("userName", playerName);
  343. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  344. if (response.Equals("")) {
  345. Debug.Log("Something wrong with current player for game with id: " + gameId);
  346. }
  347. Int32.TryParse(response, out int playerPoints);
  348. return playerPoints;
  349. }
  350. internal void SetFinishedDate(int gameId, string finishedDate) {
  351. WWWForm form = new WWWForm();
  352. form.AddField("f", "SetFinishedDate");
  353. form.AddField("gameId", gameId);
  354. form.AddField("finishedDate", finishedDate);
  355. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  356. if (!response.Equals("")) {
  357. Debug.Log(response);
  358. }
  359. }
  360. internal void SetRoundValue(int gameId, int round) {
  361. WWWForm form = new WWWForm();
  362. form.AddField("f", "SetRound");
  363. form.AddField("gameId", gameId);
  364. form.AddField("round", round);
  365. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  366. if (!response.Equals("")) {
  367. Debug.Log(response);
  368. }
  369. }
  370. internal int GetRoundValue(int gameId) {
  371. WWWForm form = new WWWForm();
  372. form.AddField("f", "GetRound");
  373. form.AddField("gameId", gameId);
  374. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  375. if (response.Equals("")) {
  376. Debug.Log("Something wrong with getting round for game with id: " + gameId);
  377. }
  378. Int32.TryParse(response, out int round);
  379. return round;
  380. }
  381. internal List<KeyValuePair<string, int>> GetPlayersForGame(int gameId) {
  382. WWWForm form = new WWWForm();
  383. form.AddField("f", "GetPlayers");
  384. form.AddField("gameId", gameId);
  385. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  386. if (response.Equals("")) {
  387. Debug.Log("Something wrong with getting players from game with id: " + gameId);
  388. }
  389. response = response = "{\"gamePlayerInfoList\" : " + response + " }";
  390. GamePlayerInfos gpi = new GamePlayerInfos();
  391. JsonUtility.FromJsonOverwrite(response, gpi);
  392. List<KeyValuePair<string, int>> returnList = new List<KeyValuePair<string, int>>();
  393. foreach (GamePlayerInfo p in gpi.gamePlayerInfoList) {
  394. Int32.TryParse(p.userLockedQuestions, out int points);
  395. KeyValuePair<string, int> player = new KeyValuePair<string, int>(p.username, points);
  396. returnList.Add(player);
  397. }
  398. return returnList;
  399. }
  400. public string AnswerString { get => answerString; set => answerString = value; }
  401. public string IdString { get => idString; set => idString = value; }
  402. public string CategoryString { get => categoryString; set => categoryString = value; }
  403. internal int GetQuestionsLost(int gameId, string playerName) {
  404. WWWForm form = new WWWForm();
  405. form.AddField("f", "GetQuestionsLost");
  406. form.AddField("userName", playerName);
  407. form.AddField("gameId", gameId);
  408. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  409. if (response.Equals("")) {
  410. Debug.Log("Something wrong with getting questions lost from game with id: " + gameId + " and playername " + playerName);
  411. }
  412. Int32.TryParse(response, out int questionsLost);
  413. return questionsLost;
  414. }
  415. internal int GetWinCondition(int gameId) {
  416. if (winAmount == -1) {
  417. WWWForm form = new WWWForm();
  418. form.AddField("gameId", gameId);
  419. form.AddField("f", "GetWinCondition");
  420. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  421. Int32.TryParse(response, out this.winAmount);
  422. }
  423. return this.winAmount;
  424. }
  425. public NewQuestionData newQuestionData;
  426. public NewQuestionData GetNewQuestion(List<int> userAnsweredQuestions, int userId) {
  427. int gameId = GameObject.Find("GameManager").GetComponent<GameManagerScript>().GameId;
  428. Question q = GetQuestionData(gameId, userId);
  429. Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  430. // Color32 questionCategoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  431. Int32.TryParse(q.category, out int categoryId);
  432. Int32.TryParse(q.id, out int questionId);
  433. NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
  434. return questionData;
  435. }
  436. public void SavePlayersQuestion(List<int> questionsToSave, string playerNameValue, int gameId) {
  437. WWWForm form = new WWWForm();
  438. form.AddField("f", "SavePlayerQuestions");
  439. form.AddField("gameId", gameId);
  440. form.AddField("questionsToSave", String.Join(",",questionsToSave));
  441. form.AddField("userName", playerNameValue);
  442. string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
  443. if (!response.Equals("")) {
  444. Debug.Log(response);
  445. }
  446. }
  447. public List<NewQuestionData> GetPlayerQuestions(int gameId, string playerName) {
  448. List<NewQuestionData> questions = new List<NewQuestionData>();
  449. WWWForm form = new WWWForm();
  450. form.AddField("f", "PlayerQuestions");
  451. form.AddField("gameId", gameId);
  452. form.AddField("userName", playerName);
  453. string response = CallOnlineDatabaseWithResponse("OnlineGameInfo.php", form);
  454. response = "{\"questionsList\" : " + response + "}";
  455. Questions ql = new Questions();
  456. JsonUtility.FromJsonOverwrite(response, ql);
  457. foreach (Question q in ql.questionsList) {
  458. /*GameObject question = Instantiate(questionCardPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  459. NewQuestionData qc = question.GetComponent<NewQuestionData>();
  460. */
  461. Color32 categoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
  462. Int32.TryParse(q.category, out int categoryId);
  463. Int32.TryParse(q.id, out int questionId);
  464. NewQuestionData questionData = new NewQuestionData(q.answer, q.question, q.categoryName, categoryId, questionId, categoryColor);
  465. questions.Add(questionData);
  466. }
  467. return questions;
  468. }
  469. private Question GetQuestionData(int gameId, int playerId) {
  470. WWWForm form = new WWWForm();
  471. form.AddField("gameId", gameId);
  472. form.AddField("playerId", playerId);
  473. string response = CallOnlineDatabaseWithResponse("Question.php", form);
  474. // Show result
  475. response = "{\"questionsList\" : [ " + response + " ]}";
  476. Questions qe = new Questions();
  477. JsonUtility.FromJsonOverwrite(response, qe);
  478. return qe.questionsList[0];
  479. }
  480. public List<UserName> GetUsersToInvite(string searchString) {
  481. WWWForm form = new WWWForm();
  482. form.AddField("SearchString", UnityWebRequest.EscapeURL(searchString));
  483. form.AddField("f", "PlayerSearch");
  484. String response = CallOnlineDatabaseWithResponse("PlayerSearch.php", form);
  485. response = "{\"usernamesList\" : " + response + " }";
  486. UserNames uNames = new UserNames();
  487. JsonUtility.FromJsonOverwrite(response, uNames);
  488. return uNames.usernamesList;
  489. }
  490. internal void SendNextPlayerMessage(int gameId, String nextPlayer)
  491. {
  492. WWWForm form = new WWWForm();
  493. form.AddField("gameId", gameId);
  494. form.AddField("playerName", nextPlayer);
  495. form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_TITLE"));
  496. List<KeyValuePair<string, int>> players = OnlineDatabase.Instance.GetPlayersForGame(gameId);
  497. StringBuilder sb = new StringBuilder();
  498. foreach (KeyValuePair<String, int> player in players)
  499. {
  500. sb.AppendLine(player.Key + " (" + player.Value + ")");
  501. }
  502. String message = String.Format(LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_MESSAGE"),sb.ToString());
  503. form.AddField("message", message);
  504. form.AddField("type", "FCMNextPlayer");
  505. //string response = CallOnlineDatabaseWithResponse("FCMNextPlayer.php", form);
  506. CallDatabase("FCMMessageing.php", form);
  507. }
  508. internal void SendInviteForNewGame(int gameId, List<String> Players, String inviter) {
  509. WWWForm form = new WWWForm();
  510. form.AddField("gameId", gameId);
  511. int index = 0;
  512. foreach(String player in Players) {
  513. form.AddField("player" + index++, player);
  514. }
  515. form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEW_GAME_TITLE"));
  516. form.AddField("message", String.Format(LocalizationManager.Instance.GetText("FCM_NEW_GAME_MESSAGE"), inviter));
  517. form.AddField("type", "InviteMessage");
  518. CallDatabase("FCMMessageing.php", form);
  519. }
  520. internal void UpdatePlayerToken(int userId, string myToken)
  521. {
  522. WWWForm form = new WWWForm();
  523. form.AddField("userId", userId);
  524. form.AddField("token", myToken);
  525. form.AddField("f", "UpdatePlayerToken");
  526. CallDatabase("OnlineGames.php", form);
  527. }
  528. internal List<UserName> FindRandomPlayer(int playerId) {
  529. List<string> returnValue = new List<string>();
  530. WWWForm form = new WWWForm();
  531. form.AddField("playerId", playerId);
  532. form.AddField("f", "FindRandomPlayers");
  533. String response = CallOnlineDatabaseWithResponse("PlayerSearch.php", form);
  534. response = "{\"usernamesList\" : " + response + " }";
  535. UserNames uNames = new UserNames();
  536. JsonUtility.FromJsonOverwrite(response, uNames);
  537. return uNames.usernamesList;
  538. }
  539. }