Exemplo n.º 1
0
    // leaderboards

    /*IEnumerator SaveScore()
     * {
     *      var score = new Playtomic_PlayerScore();
     *      score.Name = "Ben";
     *      score.Points = 1000000;
     *
     *      yield return StartCoroutine(Playtomic.Leaderboards.Save("highscores", score, true, true, false));
     *      var response = Playtomic.PlayerLevels.GetResponse("Save");
     *
     *      if(response.Success)
     *      {
     *              Debug.Log("Score saved!");
     *      }
     *      else
     *      {
     *              Debug.Log("Score failed to save because of " + response.ErrorCode + ": " + response.ErrorDescription);
     *      }
     * }
     *
     * IEnumerator ListScores()
     * {
     *      yield return StartCoroutine(Playtomic.Leaderboards.List("highscores", true, "alltime", 1, 20, false));
     *      var response = Playtomic.Leaderboards.GetResponse("List");
     *
     *      if(response.Success)
     *      {
     *              Debug.Log("Scores listed successfully: " + response.NumItems + " in total, " + response.Scores.Count + " returned");
     *
     *              for(var i=0; i<response.Scores.Count; i++)
     *                      Debug.Log(response.Scores[i].Name + ": " + response.Scores[i].Points);
     *      }
     *      else
     *      {
     *              Debug.Log("Score list failed to load because of " + response.ErrorCode + ": " + response.ErrorDescription);
     *      }
     * }*/

    // tony's test
    IEnumerator SaveScore()
    {
        var score = new Playtomic_PlayerScore();

        score.Name   = "TonyP";
        score.Points = 1000000;

        yield return(StartCoroutine(Playtomic.Leaderboards.Save("highscores", score, true)));

        var response = Playtomic.PlayerLevels.GetResponse("Save");

        if (response.Success)
        {
            Debug.Log("Score saved!");
        }
        else
        {
            Debug.Log("Score failed to save because of " + response.ErrorCode + ": " + response.ErrorDescription);
        }
    }
    public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest, bool allowduplicates, bool facebook)
    {
        var postdata = new Dictionary <String, String>();

        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("name", score.Name);
        postdata.Add("points", score.Points.ToString());
        postdata.Add("allowduplicates", allowduplicates ? "y" : "n");
        postdata.Add("auth", Playtomic_Encode.MD5(Playtomic.SourceUrl + score.Points));
        postdata.Add("customfields", score.CustomData.Count.ToString());
        postdata.Add("fbuserid", string.IsNullOrEmpty(score.FBUserId) ? "" : score.FBUserId);
        postdata.Add("fb", facebook ? "y" : "n");
        postdata.Add("url", Playtomic.SourceUrl);

        var n = 0;

        foreach (var key in score.CustomData.Keys)
        {
            postdata.Add("ckey" + n, key);
            postdata.Add("cdata" + n, score.CustomData[key]);
            n++;
        }

        string  url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, SAVE, postdata, out url, out post);

        WWW www = new WWW(url, post);

        yield return(www);

        var response = Playtomic_Request.Process(www);

        SetResponse(response, "Save");
    }
    public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal, bool allowduplicates, bool facebook, Dictionary<String, String> customfilters)
    {
        var postdata = new Dictionary<String, String>();

        // common data
        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("fb", facebook ? "y" : "n");

        // save data
        postdata.Add("name", score.Name);
        postdata.Add("points", score.Points.ToString());
        postdata.Add("allowduplicates", allowduplicates ? "y" : "n");
        postdata.Add("auth", Playtomic_Encode.MD5(Playtomic.SourceUrl + score.Points));
        postdata.Add("numfields", score.CustomData.Count.ToString());
        postdata.Add("fbuserid", string.IsNullOrEmpty(score.FBUserId) ? "" : score.FBUserId);
        postdata.Add("url", Playtomic.SourceUrl);

        var n = 0;

        foreach(var key in score.CustomData.Keys)
        {
            postdata.Add("ckey" + n, key);
            postdata.Add("cdata" + n, score.CustomData[key]);
            n++;
        }

        // list data
        var numfilters = customfilters == null ? 0 : customfilters.Count;

        postdata.Add("global", isglobal ? "y" : "n");
        postdata.Add("perpage", perpage.ToString());
        postdata.Add("mode", mode);
        postdata.Add("numfilters", numfilters.ToString());

        var fieldnumber = 0;

        if(numfilters > 0)
        {
            foreach(var key in customfilters.Keys)
            {
                postdata.Add("lkey" + fieldnumber, key);
                postdata.Add("ldata" + fieldnumber, customfilters[key]);
                fieldnumber++;
            }
        }

        string url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, SAVEANDLIST, postdata, out url, out post);

        WWW www = new WWW(url, post);
        yield return www;

        var response = Playtomic_Request.Process(www);

        if (response.Success)
        {
            var data = (Hashtable)response.JSON;
            var scores = (ArrayList)data["Scores"];
            var len = scores.Count;

            response.NumItems = (int)(double)data["NumScores"];
            response.Scores = new List<Playtomic_PlayerScore>();

            for(var i=0; i<len; i++)
            {
                Hashtable item = (Hashtable)scores[i];

                var sscore = new Playtomic_PlayerScore();
                sscore.Name = WWW.UnEscapeURL((string)item["Name"]);
                sscore.Points = (int)(double)item["Points"];
                sscore.SDate = DateTime.Parse((string)item["SDate"]);
                sscore.RDate = WWW.UnEscapeURL((string)item["RDate"]);
                sscore.Rank = (long)(double)item["Rank"];

                if(item.ContainsKey("SubmittedOrBest"))
                    sscore.SubmittedOrBest = item["SubmittedOrBest"].ToString() == "true";

                if(item.ContainsKey("CustomData"))
                {
                    Hashtable customdata = (Hashtable)item["CustomData"];

                    foreach(var key in customdata.Keys)
                        sscore.CustomData.Add((string)key, WWW.UnEscapeURL((string)customdata[key]));
                }

                response.Scores.Add(sscore);
            }
        }

        SetResponse(response, "SaveAndList");
    }
 public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal, bool allowduplicates)
 {
     return SaveAndList(table, score, highest, mode, perpage, isglobal, allowduplicates, false, null);
 }
    public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest, bool allowduplicates, bool facebook)
    {
        var postdata = new Dictionary<String, String>();
        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("name", score.Name);
        postdata.Add("points", score.Points.ToString());
        postdata.Add("allowduplicates", allowduplicates ? "y" : "n");
        postdata.Add("auth", Playtomic_Encode.MD5(Playtomic.SourceUrl + score.Points));
        postdata.Add("customfields", score.CustomData.Count.ToString());
        postdata.Add("fbuserid", string.IsNullOrEmpty(score.FBUserId) ? "" : score.FBUserId);
        postdata.Add("fb", facebook ? "y" : "n");
        postdata.Add("url", Playtomic.SourceUrl);

        var n = 0;

        foreach(var key in score.CustomData.Keys)
        {
            postdata.Add("ckey" + n, key);
            postdata.Add("cdata" + n, score.CustomData[key]);
            n++;
        }

        string url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, SAVE, postdata, out url, out post);

        WWW www = new WWW(url, post);
        yield return www;

        var response = Playtomic_Request.Process(www);
        SetResponse(response, "Save");
    }
 public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest, bool allowduplicates)
 {
     return Save(table, score, highest, allowduplicates, false);
 }
 public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest)
 {
     return Save(table, score, highest, false, false);
 }
    public IEnumerator List(string table, bool highest, string mode, int page, int perpage, bool facebook, Dictionary<String, String> customfilters, string[] friendslist)
    {
        var numfilters = customfilters == null ? 0 : customfilters.Count;
        var postdata = new Dictionary<String, String>();
        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("mode", mode);
        postdata.Add("page", page.ToString());
        postdata.Add("perpage", perpage.ToString());
        postdata.Add("filters", numfilters.ToString());
        postdata.Add("url", "global");

        if(numfilters > 0)
        {
            var fieldnumber = 0;

            foreach(var key in customfilters.Keys)
            {
                postdata.Add("ckey" + fieldnumber, key);
                postdata.Add("cdata" + fieldnumber, customfilters[key]);
                fieldnumber++;
            }
        }

        if(facebook)
        {
            postdata.Add("fb", "y");

            if(friendslist != null && friendslist.Length > 0)
            {
                postdata.Add("friendslist", string.Join(",", friendslist));
            }
        }
        else
        {
            postdata.Add("fb", "n");
        }

        string url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, LIST, postdata, out url, out post);

        WWW www = new WWW(url, post);
        yield return www;

        var response = Playtomic_Request.Process(www);

        if (response.Success)
        {
            var data = (Hashtable)response.JSON;
            var scores = (ArrayList)data["Scores"];
            var len = scores.Count;

            response.NumItems = (int)(double)data["NumScores"];
            response.Scores = new List<Playtomic_PlayerScore>();

            for(var i=0; i<len; i++)
            {
                Hashtable item = (Hashtable)scores[i];

                var sscore = new Playtomic_PlayerScore();
                sscore.Name = WWW.UnEscapeURL((string)item["Name"]);
                sscore.Points = (int)(double)item["Points"];
                sscore.SDate = DateTime.Parse((string)item["SDate"]);
                sscore.RDate = WWW.UnEscapeURL((string)item["RDate"]);
                sscore.Rank = (long)(double)item["Rank"];

                if(item.ContainsKey("CustomData"))
                {
                    Hashtable customdata = (Hashtable)item["CustomData"];

                    foreach(var key in customdata.Keys)
                        sscore.CustomData.Add((string)key, WWW.UnEscapeURL((string)customdata[key]));
                }

                response.Scores.Add(sscore);
            }
        }

        SetResponse(response, "List");
    }
    public IEnumerator List(string table, bool highest, string mode, int page, int perpage, bool facebook, Dictionary <String, String> customfilters, string[] friendslist)
    {
        var numfilters = customfilters == null ? 0 : customfilters.Count;
        var postdata   = new Dictionary <String, String>();

        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("mode", mode);
        postdata.Add("page", page.ToString());
        postdata.Add("perpage", perpage.ToString());
        postdata.Add("filters", numfilters.ToString());
        postdata.Add("url", "global");

        if (numfilters > 0)
        {
            var fieldnumber = 0;

            foreach (var key in customfilters.Keys)
            {
                postdata.Add("ckey" + fieldnumber, key);
                postdata.Add("cdata" + fieldnumber, customfilters[key]);
                fieldnumber++;
            }
        }

        if (facebook)
        {
            postdata.Add("fb", "y");

            if (friendslist != null && friendslist.Length > 0)
            {
                postdata.Add("friendslist", string.Join(",", friendslist));
            }
        }
        else
        {
            postdata.Add("fb", "n");
        }


        string  url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, LIST, postdata, out url, out post);

        WWW www = new WWW(url, post);

        yield return(www);

        var response = Playtomic_Request.Process(www);

        if (response.Success)
        {
            var data   = (Hashtable)response.JSON;
            var scores = (ArrayList)data["Scores"];
            var len    = scores.Count;

            response.NumItems = (int)(double)data["NumScores"];
            response.Scores   = new List <Playtomic_PlayerScore>();

            for (var i = 0; i < len; i++)
            {
                Hashtable item = (Hashtable)scores[i];

                var sscore = new Playtomic_PlayerScore();
                sscore.Name   = WWW.UnEscapeURL((string)item["Name"]);
                sscore.Points = (int)(double)item["Points"];
                sscore.SDate  = DateTime.Parse((string)item["SDate"]);
                sscore.RDate  = WWW.UnEscapeURL((string)item["RDate"]);
                sscore.Rank   = (long)(double)item["Rank"];

                if (item.ContainsKey("CustomData"))
                {
                    Hashtable customdata = (Hashtable)item["CustomData"];

                    foreach (var key in customdata.Keys)
                    {
                        sscore.CustomData.Add((string)key, WWW.UnEscapeURL((string)customdata[key]));
                    }
                }

                response.Scores.Add(sscore);
            }
        }

        SetResponse(response, "List");
    }
    public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal, bool allowduplicates, bool facebook, Dictionary <String, String> customfilters)
    {
        var postdata = new Dictionary <String, String>();

        // common data
        postdata.Add("table", table);
        postdata.Add("highest", highest ? "y" : "n");
        postdata.Add("fb", facebook ? "y" : "n");

        // save data
        postdata.Add("name", score.Name);
        postdata.Add("points", score.Points.ToString());
        postdata.Add("allowduplicates", allowduplicates ? "y" : "n");
        postdata.Add("auth", Playtomic_Encode.MD5(Playtomic.SourceUrl + score.Points));
        postdata.Add("numfields", score.CustomData.Count.ToString());
        postdata.Add("fbuserid", string.IsNullOrEmpty(score.FBUserId) ? "" : score.FBUserId);
        postdata.Add("url", Playtomic.SourceUrl);

        var n = 0;

        foreach (var key in score.CustomData.Keys)
        {
            postdata.Add("ckey" + n, key);
            postdata.Add("cdata" + n, score.CustomData[key]);
            n++;
        }

        // list data
        var numfilters = customfilters == null ? 0 : customfilters.Count;

        postdata.Add("global", isglobal ? "y" : "n");
        postdata.Add("perpage", perpage.ToString());
        postdata.Add("mode", mode);
        postdata.Add("numfilters", numfilters.ToString());

        var fieldnumber = 0;

        if (numfilters > 0)
        {
            foreach (var key in customfilters.Keys)
            {
                postdata.Add("lkey" + fieldnumber, key);
                postdata.Add("ldata" + fieldnumber, customfilters[key]);
                fieldnumber++;
            }
        }

        string  url;
        WWWForm post;

        Playtomic_Request.Prepare(SECTION, SAVEANDLIST, postdata, out url, out post);

        WWW www = new WWW(url, post);

        yield return(www);

        var response = Playtomic_Request.Process(www);

        if (response.Success)
        {
            var data   = (Hashtable)response.JSON;
            var scores = (ArrayList)data["Scores"];
            var len    = scores.Count;

            response.NumItems = (int)(double)data["NumScores"];
            response.Scores   = new List <Playtomic_PlayerScore>();

            for (var i = 0; i < len; i++)
            {
                Hashtable item = (Hashtable)scores[i];

                var sscore = new Playtomic_PlayerScore();
                sscore.Name   = WWW.UnEscapeURL((string)item["Name"]);
                sscore.Points = (int)(double)item["Points"];
                sscore.SDate  = DateTime.Parse((string)item["SDate"]);
                sscore.RDate  = WWW.UnEscapeURL((string)item["RDate"]);
                sscore.Rank   = (long)(double)item["Rank"];

                if (item.ContainsKey("SubmittedOrBest"))
                {
                    sscore.SubmittedOrBest = item["SubmittedOrBest"].ToString() == "true";
                }

                if (item.ContainsKey("CustomData"))
                {
                    Hashtable customdata = (Hashtable)item["CustomData"];

                    foreach (var key in customdata.Keys)
                    {
                        sscore.CustomData.Add((string)key, WWW.UnEscapeURL((string)customdata[key]));
                    }
                }

                response.Scores.Add(sscore);
            }
        }

        SetResponse(response, "SaveAndList");
    }
 public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal, bool allowduplicates)
 {
     return(SaveAndList(table, score, highest, mode, perpage, isglobal, allowduplicates, false, null));
 }
 public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest, bool allowduplicates)
 {
     return(Save(table, score, highest, allowduplicates, false));
 }
 public IEnumerator Save(string table, Playtomic_PlayerScore score, bool highest)
 {
     return(Save(table, score, highest, false, false));
 }
Exemplo n.º 14
0
    // leaderboards
    private IEnumerator SaveScore()
    {
        var score = new Playtomic_PlayerScore();
        score.Name = "Ben";
        score.Points = 1000000;

        yield return StartCoroutine(Playtomic.Leaderboards.Save("highscores", score, true, true, false));
        var response = Playtomic.PlayerLevels.GetResponse("Save");

        if(response.Success)
        {
            Debug.Log("Score saved!");
        }
        else
        {
            Debug.Log("Score failed to save because of " + response.ErrorCode + ": " + response.ErrorDescription);
        }
    }
Exemplo n.º 15
0
    public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal, bool allowduplicates, bool facebook, Hashtable customdatahashtable)
    {
        var dict = new Dictionary<String, String>();

        foreach(var key in customdatahashtable.Keys)
        {
            dict.Add(key.ToString(), customdatahashtable[key].ToString());
        }

        return SaveAndList(table, score, highest, mode, perpage, isglobal, allowduplicates, facebook, dict);
    }
Exemplo n.º 16
0
 public IEnumerator SaveAndList(string table, Playtomic_PlayerScore score, bool highest, string mode, int perpage, bool isglobal)
 {
     return SaveAndList(table, score, highest, mode, perpage, isglobal, false, false, new Dictionary<string, string>());
 }