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