public Question setQuestionById(string id) { StartCoroutine(processTimer()); currentQuestion = null; GamedoniaData.Search("questions", "{_id:{$oid:'" + id + "'}}", delegate(bool success, IList data){ if (success) { //TODO Your success processing if (data != null && data.Count == 1) { Dictionary <string, object> question = (Dictionary <string, object>)data[0]; currentQuestion = new Question( question["_id"].ToString(), int.Parse(question["cId"].ToString()), question["qT"].ToString(), question["qA"].ToString(), question["qB"].ToString(), question["qC"].ToString(), question["qD"].ToString(), question["qCA"].ToString(), question["sID"].ToString(), int.Parse(question["qAp"].ToString()) ); questionLoaded = true; } questionLoaded = true; } else { questionLoaded = true; //TODO Your fail processing } }); return(currentQuestion); }
void showAllEntities() { printToConsole("Showing all entities...\n"); GamedoniaData.Search("movies", "{}", delegate(bool success, IList list){ if (success) { //TODO Your success processing if (list != null) { foreach (Dictionary <string, object> elem in list) { printToConsole("Name: " + elem["name"] + "\n" + "Director: " + elem["director"] + "\n" + "Duration: " + elem["duration"] + "\n" + "Music: " + elem["music"] + "\n"); } } else { printToConsole("No movies found."); } } else { //TODO Your fail processing printToConsole("The collection doesn't exist. Create one in the Dashboard."); } }); }
public void getAllMatchesOnStartGame() { Debug.Log("get all matches on start game"); // GamedoniaData.Search ("matches", "{'user_ids': {$in:['"+PlayerManager.I.player.playerID+"']}}", delegate (bool success, IList data) { if (matches.Count == 0) { Debug.Log("search matches for user"); Debug.Log("u_ids:'" + PlayerManager.I.player.playerID + "' }"); GamedoniaData.Search("matches", "{u_ids:'" + PlayerManager.I.player.playerID + "' }", delegate(bool success, IList data) { if (success) { if (data != null) { for (int i = 0; i < data.Count; i++) { Debug.Log("Add match for user"); Dictionary <string, object> matchD = (Dictionary <string, object>)data[i]; Match match = new Match(); match.m_ID = matchD["_id"].ToString(); List <string> uids = JsonMapper.ToObject <List <string> > (JsonMapper.ToJson(matchD ["u_ids"])); match.u_ids = uids; List <Turn> turns = new List <Turn> (); List <object> t_turns = new List <object> (); t_turns = (List <object>)matchD ["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn ["t_ID"].ToString()), t_turn ["p_ID"].ToString(), t_turn ["q_ID"].ToString(), int.Parse(t_turn ["c_ID"].ToString()), int.Parse(t_turn ["t_st"].ToString())); turns.Add(turn); } match.m_cp = matchD ["m_cp"].ToString(); match.m_trns = turns; match.m_date = matchD ["m_date"].ToString(); match.m_status = matchD ["m_status"].ToString(); if (!matches.Contains(match)) { AddMatch(match, false, false); } } MatchManager.I.checkUpdates = true; } else { MatchManager.I.checkUpdates = true; } } else { MatchManager.I.checkUpdates = true; } }); } }
public List <Question> getQuestionsByPlayerId() { StartCoroutine(processTimer()); List <Question> questionList = new List <Question>(); GamedoniaData.Search("questions", "{\"sID\":\"" + PlayerManager.I.player.playerID + "\"}", delegate(bool success, IList data){ if (success) { //TODO Your success processing if (data != null && data.Count > 0) { for (int i = 0; i < data.Count; i++) { Dictionary <string, object> questionD = (Dictionary <string, object>)data[i]; Question question = new Question( questionD["_id"].ToString(), int.Parse(questionD["cId"].ToString()), questionD["qT"].ToString(), questionD["qA"].ToString(), questionD["qB"].ToString(), questionD["qC"].ToString(), questionD["qD"].ToString(), questionD["qCA"].ToString(), questionD["sID"].ToString(), int.Parse(questionD["qAp"].ToString()) ); questionList.Add(question); } retrievedQuestions = true; } retrievedQuestions = true; } else { retrievedQuestions = true; } }); return(questionList); }
public List <Question> getNonApprovedQuestions() { List <Question> questionList = new List <Question>(); GamedoniaData.Search("questions", "{\"qAp\":0}", delegate(bool success, IList data){ if (success) { //TODO Your success processing if (data != null && data.Count > 0) { for (int i = 0; i < data.Count; i++) { Dictionary <string, object> questionD = (Dictionary <string, object>)data[i]; Question question = new Question( questionD["_id"].ToString(), int.Parse(questionD["cId"].ToString()), questionD["qT"].ToString(), questionD["qA"].ToString(), questionD["qB"].ToString(), questionD["qC"].ToString(), questionD["qD"].ToString(), questionD["qCA"].ToString(), questionD["sID"].ToString(), int.Parse(questionD["qAp"].ToString()) ); questionList.Add(question); } retrievedQuestions = true; } retrievedQuestions = true; } else { retrievedQuestions = true; } }); return(questionList); }
public void CheckForInvites() { Debug.Log("CHECK FOR INVITES"); GamedoniaData.Search("matches", "{$and: [ { \"m_status\":\"invite\" }, { \"m_cp\":'" + PlayerManager.I.player.playerID + "' }]}", delegate(bool success, IList data) { if (success) { if (data != null) { for (int i = 0; i < data.Count; i++) { Dictionary <string, object> matchD = (Dictionary <string, object>)data[i]; Match match = GetMatch(matchD["_id"].ToString()); if (match == null) { match = new Match(); match.m_ID = matchD["_id"].ToString(); List <string> uids = JsonMapper.ToObject <List <string> > (JsonMapper.ToJson(matchD ["u_ids"])); match.u_ids = uids; List <Turn> turns = new List <Turn> (); List <object> t_turns = new List <object> (); t_turns = (List <object>)matchD ["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn ["t_ID"].ToString()), t_turn ["p_ID"].ToString(), t_turn ["q_ID"].ToString(), int.Parse(t_turn ["c_ID"].ToString()), int.Parse(t_turn ["t_st"].ToString())); turns.Add(turn); } match.m_cp = matchD ["m_cp"].ToString(); match.m_trns = turns; match.m_date = matchD ["m_date"].ToString(); match.m_status = matchD ["m_status"].ToString(); AddMatch(match, false, false); } } } } }); }
/********************************************************PUSH NOTIFICATIONS AREA ****************************************************************************/ // Process incoming notification void OnGameUpdateNotification(Dictionary <string, object> notification) { Scene currentScene = SceneManager.GetActiveScene(); Hashtable payload = notification["payload"] != null ? (Hashtable)notification["payload"] : new Hashtable(); string type = payload.ContainsKey("type") ? payload["type"].ToString() : ""; string matchID = payload.ContainsKey("notif_id") ? payload["notif_id"].ToString() : ""; string oppName = payload.ContainsKey("notif_name") ? payload["notif_name"].ToString() : ""; switch (type) { case "matchInvite": GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool invitesuccess, IList data) { if (invitesuccess) { if (data != null) { Dictionary <string, object> matchD = (Dictionary <string, object>)data[0]; Match match = MatchManager.I.GetMatch(matchID); if (match == null) { match = new Match(); match.m_ID = matchD["_id"].ToString(); List <string> uids = JsonMapper.ToObject <List <string> > (JsonMapper.ToJson(matchD ["u_ids"])); match.u_ids = uids; List <Turn> turns = new List <Turn> (); List <object> t_turns = new List <object> (); t_turns = (List <object>)matchD ["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn ["t_ID"].ToString()), t_turn ["p_ID"].ToString(), t_turn ["q_ID"].ToString(), int.Parse(t_turn ["c_ID"].ToString()), int.Parse(t_turn ["t_st"].ToString())); turns.Add(turn); } match.m_cp = matchD ["m_cp"].ToString(); match.m_trns = turns; match.m_date = matchD ["m_date"].ToString(); match.m_status = matchD ["m_status"].ToString(); MatchManager.I.AddMatch(match, false, false); } if (currentScene.name == "Home") { //GameObject.FindObjectOfType<CurrentMatches>().showInvites(); GameObject.FindObjectOfType <CurrentMatches> ().updateMatches(); GameObject.FindObjectOfType <CurrentMatches> ().updateLives(); } } } }); break; case "matchTurn": //TODO: process the message Match match = MatchManager.I.GetMatch(matchID); if (match != null) { // Update match information // Get match from gamedonia server GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool success, IList data) { if (success) { if (data != null) { // *************** Server side match information ******************** Dictionary <string, object> matchD = (Dictionary <string, object>)data[0]; List <Turn> turns = new List <Turn>(); // Conver incoming turn data to Turn class List <object> t_turns = new List <object>(); t_turns = (List <object>)matchD["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString())); turns.Add(turn); } List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"])); // Add friend to list string oppId = MatchManager.I.GetOppenentId(match); if (!PlayerManager.I.friends.ContainsKey(oppId) && oppId != "") { PlayerManager.I.AddFriend(oppId); } // *************** Update local match ******************** match.u_ids = uids; match.m_cc = 0; match.m_trns = turns; match.m_cp = PlayerManager.I.player.playerID; match.m_date = matchD["m_date"].ToString(); match.m_status = matchD["m_status"].ToString(); if (currentScene.name == "Home") { GameObject.FindObjectOfType <CurrentMatches>().updateMatches(); } } else { } } }); } break; case "matchFinish": Match finishMatch = MatchManager.I.GetMatch(matchID); GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool success, IList data) { if (success) { if (data != null) { // *************** Server side match information ******************** Dictionary <string, object> matchD = (Dictionary <string, object>)data[0]; List <Turn> turns = new List <Turn>(); // Convert incoming turn data to Turn class List <object> t_turns = new List <object>(); t_turns = (List <object>)matchD["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString())); turns.Add(turn); } List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"])); // *************** Update local match ******************** finishMatch.u_ids = uids; finishMatch.m_cc = 0; finishMatch.m_trns = turns; finishMatch.m_cp = PlayerManager.I.player.playerID; finishMatch.m_date = matchD ["m_date"].ToString(); finishMatch.m_status = matchD["m_status"].ToString(); if (matchD["m_won"].ToString() == PlayerManager.I.player.playerID) { // Check if we can earn an attribute of our opponent PlayerManager.I.UnlockNewAttribute(MatchManager.I.GetOppenentId(finishMatch)); } if (currentScene.name == "Home") { Loader.I.showFinishedPopup(oppName, matchD["m_won"].ToString()); } GameObject.FindObjectOfType <CurrentMatches> ().updateLives(); } } }); break; case "matchDeny": GamedoniaData.Delete("matches", matchID); Match matchDeny = MatchManager.I.GetMatch(matchID); MatchManager.I.matches.Remove(matchDeny); MatchManager.I.Save(); GameObject.FindObjectOfType <CurrentMatches> ().showInvites(); GameObject.FindObjectOfType <CurrentMatches> ().deleteRow(matchDeny.m_ID); if (currentScene.name == "Home") { GameObject.FindObjectOfType <CurrentMatches> ().updateLives(); } break; default: // Do nothing break; } }
public void checkForUpdateMatches() { currentMatchID = ""; currentCategory = 0; List <Match> yourTurn = GetPlayingMatches(true, "opponent"); if (yourTurn.Count > 0) { for (int i = 0; i < yourTurn.Count; i++) { string matchID = yourTurn [i].m_ID; checkIfMatchExists(matchID); if (yourTurn [i].m_status != "finished") { GamedoniaData.Search("matches", "{_id: { $oid: '" + matchID + "' } }", delegate(bool success, IList data) { if (success) { if (data != null) { Match match = GetMatch(matchID); Dictionary <string, object> matchD = (Dictionary <string, object>)data [0]; Debug.Log(matchD ["m_status"].ToString()); if (matchD ["m_status"].ToString() == "deny") { RemoveMatch(match, "", true, true); } else { List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"])); // Add friend if it is a new player string oppId = (match.u_ids[0] != PlayerManager.I.player.playerID ? uids[0] : uids[1]); if (!PlayerManager.I.friends.ContainsKey(oppId) && oppId != "") { PlayerManager.I.AddFriend(oppId); } // Update match if we are the currentplayer if (matchD ["m_cp"].ToString() == PlayerManager.I.player.playerID && oppId != "" || matchD ["m_status"].ToString() == "finished") { if (match.u_ids [0] == "") { match.u_ids [0] = uids [0]; } List <Turn> turns = new List <Turn> (); List <object> t_turns = new List <object> (); t_turns = (List <object>)matchD ["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn ["t_ID"].ToString()), t_turn ["p_ID"].ToString(), t_turn ["q_ID"].ToString(), int.Parse(t_turn ["c_ID"].ToString()), int.Parse(t_turn ["t_st"].ToString())); turns.Add(turn); } match.m_cp = matchD ["m_cp"].ToString(); match.m_trns = turns; match.m_date = matchD ["m_date"].ToString(); match.m_status = matchD ["m_status"].ToString(); Save(); checkUpdates = true; } else { checkUpdates = true; } } } } checkUpdates = true; }); } checkUpdates = true; } checkUpdates = true; } else { checkUpdates = true; } }
public void StartRandomMatch() { Loader.I.CheckInternetConnection(); if (!Loader.I.noInternet) { currentMatchID = ""; currentCategory = 0; // Enable Loader Loader.I.enableLoader(); // Search for random fame in random queue tabel GamedoniaData.Search("randomqueue", "{'uid': {$nin:['" + PlayerManager.I.player.playerID + "'" + getPlayingFriendsIds() + "]}}", delegate(bool success, IList data){ if (success) { // If there isnt anyone waiting for a game we start a match then send it as an option to others if (data == null || data.Count == 0) { Debug.Log("not matches available"); Match match = new Match(); // Add empty player since we dont know against we play yet match.AddPlayer(""); // Set match status to playing match.m_status = "waiting"; // Add ourself match.AddPlayer(PlayerManager.I.player.playerID); // We are the current player match.m_cp = PlayerManager.I.player.playerID; // Set current Date match.m_date = RuntimeData.I.getCorrectDateTime(System.DateTime.Now); //Debug.Log(match.m_date); //Debug.Log("random"+DateTime.Parse(match.m_date)); //string myDate = "30-12-2016 07:50:00:AM"; //DateTime dt1 = DateTime.ParseExact(myDate, "dd-MM-yyyy hh:mm:ss:tt", System.Globalization.CultureInfo.InvariantCulture); // Add match to local list and gamedonia server AddMatch(match, true, false, true); } else { // We found a random player, delete entry from randomqueue GamedoniaData.Delete("randomqueue", ((IDictionary)data[0])["_id"].ToString(), null); // Add player to friend list if (!PlayerManager.I.friends.ContainsKey(((IDictionary)data[0])["uid"].ToString()) && ((IDictionary)data[0])["uid"].ToString() != "") { PlayerManager.I.AddFriend(((IDictionary)data[0])["uid"].ToString()); } GamedoniaData.Search("matches", "{_id: { $oid: '" + ((IDictionary)data[0])["m_ID"].ToString() + "' } }", 1, "{m_trns:1}", delegate(bool _success, IList match) { if (success) { if (data != null) { Dictionary <string, object> matchD = (Dictionary <string, object>)match[0]; List <Turn> turns = new List <Turn>(); // Convert incoming turn data to Turn class List <object> t_turns = new List <object>(); t_turns = (List <object>)matchD["m_trns"]; foreach (Dictionary <string, object> t_turn in t_turns) { Turn turn = new Turn(int.Parse(t_turn["t_ID"].ToString()), t_turn["p_ID"].ToString(), t_turn["q_ID"].ToString(), int.Parse(t_turn["c_ID"].ToString()), int.Parse(t_turn["t_st"].ToString())); turns.Add(turn); } List <string> uids = JsonMapper.ToObject <List <string> >(JsonMapper.ToJson(matchD["u_ids"])); uids[0] = PlayerManager.I.player.playerID; Match existingMatch = new Match(matchD ["_id"].ToString(), uids, "", "", matchD ["m_status"].ToString(), 0, matchD ["m_cp"].ToString(), 0, matchD ["m_date"].ToString()); existingMatch.m_trns = turns; existingMatch.m_cp = PlayerManager.I.player.playerID; existingMatch.m_status = "playing"; currentMatchID = existingMatch.m_ID; AddMatch(existingMatch, false, false, true); } } }); } } }); } }