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.");
         }
     });
 }
Beispiel #2
0
 public void AddMatch(Match match, bool addToServer = true, bool queueObject = false, bool sq = false)
 {
     if (addToServer)
     {
         GamedoniaData.Create("matches", getDictionaryMatch(match), delegate(bool success, IDictionary data){
             if (success)
             {
                 match.m_ID     = data["_id"].ToString();
                 currentMatchID = match.m_ID;
                 Save();
                 if (queueObject)
                 {
                     Debug.Log("create game queue object");
                     createGameQueueObject();
                 }
             }
             else
             {
             }
         });
     }
     if (!matches.Contains(match))
     {
         matches.Add(match);
         Save();
         if (sq)
         {
             Loader.I.LoadScene("Category");
         }
     }
 }
Beispiel #3
0
 public void RemoveMatch(Match match = null, string matchID = "", bool completely = false, bool deleteInScene = false)
 {
     if (match == null)
     {
         if (matchID != "")
         {
             match = GetMatch(matchID);
         }
     }
     Debug.Log("Removing match");
     currentMatchID  = "";
     currentCategory = 0;
     matches.Remove(match);
     if (completely)
     {
         Debug.Log("Removing match completely");
         GamedoniaData.Delete("matches", match.m_ID, delegate(bool success){
             if (success)
             {
                 Debug.Log("Removed match!!");
             }
             else
             {
             }
         });
     }
     if (deleteInScene)
     {
         GameObject.FindObjectOfType <CurrentMatches> ().deleteRow(match.m_ID);
     }
     Save();
 }
Beispiel #4
0
 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 createEntity()
    {
        //printToConsole("Creating Entity...");

        // Store all the information you want inside a dictionary
        Dictionary <string, object> movie = new Dictionary <string, object>();

        movie ["name"]    = name;
        movie["director"] = director;
        movie["duration"] = duration;
        movie["music"]    = music;

        // Make the request to store the entity inside the desired collection
        GamedoniaData.Create("movies", movie, delegate(bool success, IDictionary data){
            if (success)
            {
                //TODO Your success processing
                Application.LoadLevel("DataScene");
            }
            else
            {
                //TODO Your success processing
                //printToConsole("Failed to create entity.");
                errorMsg = Gamedonia.getLastError().ToString();
                Debug.Log(errorMsg);
            }
        });
    }
Beispiel #6
0
    public void setWinner(Match match, string winner)
    {
        match.m_status = "finished";
        match.m_cp     = winner;
        Dictionary <string, object> matchUpdate = MatchManager.I.getDictionaryMatch(match, null, true, winner);

        GamedoniaData.Update("matches", matchUpdate);
        Save();
    }
Beispiel #7
0
    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;
                }
            });
        }
    }
Beispiel #8
0
    // *********************** GAMEDONIA SERVER FUNCTIONS*******************************************
    private void createGameQueueObject()
    {
        Dictionary <string, object> randomGame = new Dictionary <string, object>();

        randomGame.Add("uid", PlayerManager.I.player.playerID);
        randomGame.Add("nickname", PlayerManager.I.player.profile.name);
        randomGame.Add("p_ID", PlayerManager.I.player.playerID);
        randomGame.Add("m_ID", currentMatchID);

        GamedoniaData.Create("randomqueue", randomGame);
    }
Beispiel #9
0
    }//end update

    public void verificationCheck()
    {
        Loader.I.enableLoader();
        if (verificationCode.text == "")
        {
            lockImg.DOColor(eColor, 1);
            wrongLogin.SetActive(true);
            wrongLogin.GetComponent <Text>().text = "Je hebt niks ingevoerd!";
            Loader.I.disableLoader();
        }


        //if internet connection, start verificaiton
        if (i_access)
        {
            if (verificationCode.text != "")
            {
                string code = verificationCode.text;

                GamedoniaData.Count("staticdata", "{\"playCode\":\"" + code + "\"}", delegate(bool success, int count)
                {
                    if (success)
                    {
                        if (count == 1)
                        {
                            //TODO Your success processing
                            // setting bool
                            PlayerManager.I.player.verificationComplete = true;
                            //loading login screen
                            SceneManager.LoadScene("Login");
                            //saving player files
                            PlayerManager.I.Save();
                            lockImg.DOColor(dColor, 1);
                        }
                        else
                        {
                            //when password is wrong
                            lockImg.DOColor(eColor, 1);
                            wrongLogin.SetActive(true);
                            wrongLogin.GetComponent <Text>().text = "Wachtwoord onjuist";
                            Loader.I.disableLoader();
                        }
                    }
                });
            }
        }
        else
        {
            //start waiting for connection void
            StartCoroutine(waitForConnection(waitForConnectionTime));
        }
    }
 void removeEntity()
 {
     GamedoniaData.Delete("movies", "54d39884e4b0b94e5d240e3f", delegate(bool success){
         if (success)
         {
             printToConsole("Movie deleted successfully.");
         }
         else
         {
             printToConsole("Failed to delete the movie.");
         }
     });
 }
Beispiel #11
0
    public void ChangeLastTurn(Turn turn, bool finish, bool directlyNinth = false)
    {
        Debug.Log("In last turn");
        Dictionary <string, object> matchUpdate = null;
        Match  match  = GetMatch(currentMatchID);
        string winner = "";

        if (directlyNinth)
        {
            Debug.Log("added last turn");
            AddTurn(turn);
        }
        else
        {
            for (int i = 0; i < match.m_trns.Count; i++)
            {
                if (match.m_trns [i].p_ID == PlayerManager.I.player.playerID && match.m_trns [i].t_ID == turn.t_ID)
                {
                    match.m_trns [i] = turn;
                }
            }
        }

        if (finish)
        {
            match.m_status = "finished";
            Debug.Log("Set status to finished");
            match.m_cp = GetOppenentId(match);
            winner     = getWinner(match);
            // Gamedonia server script handles opponent push message
        }
        if (turn.t_st == 0)
        {
            match.m_cp = GetOppenentId(match);
        }
        if (finish)
        {
            matchUpdate = MatchManager.I.getDictionaryMatch(match, null, true, winner);
        }
        else
        {
            matchUpdate = MatchManager.I.getDictionaryMatch(match, null, true);
        }

        GamedoniaData.Update("matches", matchUpdate);
        Save();
    }
Beispiel #12
0
    public void AddTurn(Turn turn, string match_ID = "")
    {
        if (match_ID == "")
        {
            match_ID = currentMatchID;
        }
        Match match = GetMatch(match_ID);

        if (match.m_trns == null)
        {
            match.m_trns = new List <Turn> ();

            if (match.m_trns.Count == 0 && match.m_status != "inviteStart")
            {
                createGameQueueObject();
            }
        }
        if (!match.m_trns.Contains(turn))
        {
            match.AddTurn(turn);
            if (turn.t_st == 0)
            {
                if (match.m_status != "waiting")
                {
                    match.m_cp = GetOppenentId(match);
                }
                else
                {
                    match.m_cp = "";
                }
                // Update match to gamedonia
                if (match.m_status == "inviteStart")
                {
                    match.m_status = "invite";
                }
                match.m_date = RuntimeData.I.getCorrectDateTime(System.DateTime.Now);
                Dictionary <string, object> matchUpdate = MatchManager.I.getDictionaryMatch(match, null, true);
                GamedoniaData.Update("matches", matchUpdate);
            }
            else
            {
            }
        }

        // Save locally
        Save();
    }
Beispiel #13
0
 private void checkIfMatchExists(string matchId)
 {
     GamedoniaData.Count("matches", "{_id:{$oid:'" + matchId + "'}}", delegate(bool success, int count){
         if (success)
         {
             Debug.Log("matches" + count);
             if (count == 0)
             {
                 RemoveMatch(null, matchId);
             }
         }
         else
         {
             //TODO Your fail processing
         }
     });
 }
Beispiel #14
0
    public void SetQuestionState(string questionID, int stateId)
    {
        Dictionary <string, object> question = new Dictionary <string, object>();

        question["_id"] = questionID;
        question["qAp"] = stateId;
        GamedoniaData.Update("questions", question, delegate(bool success, IDictionary data){
            if (success)
            {
                //TODO Your success processing
            }
            else
            {
                //TODO Your fail processing
            }
        });
    }
Beispiel #15
0
    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);
    }
Beispiel #16
0
    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);
    }
Beispiel #17
0
    public void DenyMatch(Match match)
    {
        match.m_status = "deny";
        match.m_cp     = GetOppenentId(match);
        currentMatchID = match.m_ID;
        Dictionary <string, object> matchUpdate = MatchManager.I.getDictionaryMatch(match, "", true);

        GamedoniaData.Update("matches", matchUpdate, delegate(bool success, IDictionary data){
            if (success)
            {
                matches.Remove(match);
                Save();
                GameObject.FindObjectOfType <CurrentMatches> ().showInvites();
                GameObject.FindObjectOfType <CurrentMatches> ().deleteRow(match.m_ID);
                GameObject.FindObjectOfType <CurrentMatches> ().checkMatchCount();
            }
            else
            {
                //TODO Your fail processing
            }
        });
    }
Beispiel #18
0
    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);
                        }
                    }
                }
            }
        });
    }
Beispiel #19
0
    private void UpdateHoursRemaining(string LastTurnDate, GameObject row, string type, Match match)
    {
        if (LastTurnDate != "" && match != null)
        {
            float  timeLeft = getHoursRemaining(LastTurnDate);
            string oppId    = MatchManager.I.GetOppenentId(match);
            if (timeLeft <= 0)
            {
                if (type == "yourTurn")
                {
                    MatchManager.I.setWinner(match, oppId);
                }
                else if (type == "hisTurn")
                {
                    if (oppId != "")
                    {
                        MatchManager.I.setWinner(match, PlayerManager.I.player.playerID);
                        PlayerManager.I.UnlockNewAttribute(oppId);
                        Loader.I.showFinishedPopup("", PlayerManager.I.player.playerID, oppId);
                    }
                    else
                    {
                        MatchManager.I.RemoveMatch(match, "", true, true);
                        GamedoniaData.Delete("randomqueue", match.m_ID, null);
                    }
                }
                else if (type == "inviteTurn")
                {
                    MatchManager.I.DenyMatch(match);
                }
            }
            row.transform.GetChild(3).GetComponent <Text>().text = "nog " + timeLeft + " uur om te reageren";

            SetHourGlassImage(timeLeft, row.transform.GetChild(6).gameObject);
        }
    }
Beispiel #20
0
 private void setChildInformation(string oppId, string matchId, GameObject parent, string listname, int i = 0)
 {
     if (oppId != "")
     {
         float timeLeft = 0;
         Match match    = MatchManager.I.GetMatch(matchId);
         GamedoniaUsers.GetUser(oppId, delegate(bool success, GDUserProfile data) {
             if (success)
             {
                 Dictionary <string, object> oppProfile = new Dictionary <string, object> ();
                 oppProfile = data.profile;
                 foreach (Transform child in parent.transform)
                 {
                     if (child.name == "playerName")
                     {
                         if (oppId != "")
                         {
                             string extraText = "";
                             if (match.m_status == "invite" && match.m_cp == oppId)
                             {
                                 extraText = " (wachten op acceptatie)";
                             }
                             child.GetComponent <Text> ().text = oppProfile ["name"].ToString() + extraText;
                         }
                     }
                     if (child.name == "Score")
                     {
                         if (listname != "inviteTurn")
                         {
                             string _score = MatchManager.I.getMatchScore(matchId, oppId);
                             child.GetComponent <Text> ().text = MatchManager.I.getMatchScore(matchId, oppId);
                         }
                     }
                     if (child.name == "line")
                     {
                         if (listname == "yourTurn")
                         {
                             if (yourTurn.Count == 1 || (yourTurn.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                         else if (listname == "hisTurn")
                         {
                             if (hisTurn.Count == 1 || (hisTurn.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                         else if (listname == "finished")
                         {
                             if (finishedMatches.Count == 1 || (finishedMatches.Count - 1) == i)
                             {
                                 child.gameObject.SetActive(false);
                             }
                         }
                     }
                     if (child.name == "rankImg")
                     {
                         if (oppId != "")
                         {
                             child.GetComponent <Image> ().sprite = PlayerManager.I.GetRankSprite(int.Parse(oppProfile ["lvl"].ToString()));
                         }
                     }
                     if (child.name == "TimeRemaining")
                     {
                         timeLeft = getHoursRemaining(match.m_date);
                         if (listname == "finished")
                         {
                             child.GetComponent <Text>().text = Mathf.Abs(timeLeft) + " uur geleden beëindigd";
                         }
                         else if (listname == "inviteTurn")
                         {
                             child.GetComponent <Text>().text = "nog " + timeLeft + " uur";
                         }
                         else if (listname == "yourTurn")
                         {
                             child.GetComponent <Text>().text = "nog " + timeLeft + " uur om te reageren";
                         }
                         else if (listname == "hisTurn")
                         {
                             child.GetComponent <Text>().text = "heeft nog " + timeLeft + " uur om te reageren";
                         }
                         if (timeLeft <= 0)
                         {
                             if (listname == "yourTurn")
                             {
                                 MatchManager.I.setWinner(match, oppId);
                                 StartCoroutine(waitBeforeUpdateMatches(1f));
                             }
                             else if (listname == "hisTurn")
                             {
                                 if (oppId != "")
                                 {
                                     MatchManager.I.setWinner(match, PlayerManager.I.player.playerID);
                                     PlayerManager.I.UnlockNewAttribute(oppId);
                                     Loader.I.showFinishedPopup(oppProfile ["name"].ToString(), PlayerManager.I.player.playerID);
                                 }
                                 else
                                 {
                                     MatchManager.I.RemoveMatch(match, "", true, true);
                                     GamedoniaData.Delete("randomqueue", match.m_ID, null);
                                 }
                             }
                             else if (listname == "inviteTurn")
                             {
                                 MatchManager.I.DenyMatch(match);
                             }
                         }
                     }
                     if (child.name == "HourGlass")
                     {
                         SetHourGlassImage(timeLeft, child.gameObject);
                     }
                 }
                 parent.SetActive(true);
             }
         });
     }
     else
     {
         foreach (Transform child in parent.transform)
         {
             if (child.name == "Score")
             {
                 if (listname != "inviteTurn")
                 {
                     string _score = MatchManager.I.getMatchScore(matchId, oppId);
                     child.GetComponent <Text> ().text = (_score == "" ? "0-0" : _score);
                 }
             }
         }
         parent.SetActive(true);
     }
 }
Beispiel #21
0
    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);
                                }
                            }
                        });
                    }
                }
            });
        }
    }
Beispiel #22
0
    /********************************************************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;
        }
    }
Beispiel #23
0
    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;
        }
    }
Beispiel #24
0
    public void SubmitQuestion()
    {
        Loader.I.enableLoader();
        string correctAnswer = "";

        if (correctAnswerId.value == 0)
        {
            correctAnswer = "A";
        }
        else if (correctAnswerId.value == 1)
        {
            correctAnswer = "B";
        }
        else if (correctAnswerId.value == 2)
        {
            correctAnswer = "C";
        }
        else if (correctAnswerId.value == 3)
        {
            correctAnswer = "D";
        }
        Dictionary <string, object> question = new Dictionary <string, object>();

        if (QuestionBackend.I.changeQuestion)
        {
            question["_id"] = QuestionBackend.I.currentQuestion.q_Id;
        }
        question["cId"] = (categoryId.value + 1);
        question["qT"]  = QuestionTitleText.text;
        question["qA"]  = AnswerAText.text;
        question["qB"]  = AnswerBText.text;
        question["qC"]  = AnswerCText.text;
        question["qD"]  = AnswerDText.text;
        question["qCA"] = correctAnswer;
        question["sID"] = PlayerManager.I.player.playerID;
        question["qAp"] = 0;

        // Add 50 exp to the player
        if (!QuestionBackend.I.changeQuestion)
        {
            PlayerManager.I.player.playerXP = PlayerManager.I.player.playerXP += 50;
        }

        // Make the request to store the entity inside the desired collection
        if (!QuestionBackend.I.changeQuestion)
        {
            GamedoniaData.Create("questions", question, delegate(bool success, IDictionary data){
                if (success)
                {
                    Loader.I.LoadScene("QuestionAddedSuccess");
                    //TODO Your success processing
                }
                else
                {
                    //TODO Your fail processing
                }
            });
        }
        else
        {
            QuestionBackend.I.changeQuestion  = false;
            QuestionBackend.I.currentQuestion = null;
            GamedoniaData.Update("questions", question, delegate(bool success, IDictionary data){
                if (success)
                {
                    Loader.I.LoadScene("MyQuestions");
                }
                else
                {
                    //TODO Your fail processing
                }
            });
        }
    }