Exemplo n.º 1
0
        private static void ProcessLevels(PResponse response, Hashtable data, out List<PlayerLevel> levels, out int numlevels)
        {
            levels = new List<PlayerLevel> ();
            numlevels = 0;

            if (!response.success)
                return;

            numlevels = (int)(double)data["numlevels"];
            var levelarr = (ArrayList)data["levels"];
            levels.AddRange(from object t in levelarr select new PlayerLevel((Hashtable) t));
        }
Exemplo n.º 2
0
        private static void ProcessScores(PResponse response, IDictionary data, out List<PlayerScore> scores, out int numitems)
        {
            scores = new List<PlayerScore>();
            numitems = 0;

            if (!response.success)
                return;

            numitems = (int)(double)data["numscores"];
            var scorearr = (ArrayList) data["scores"];

            scores.AddRange(from object t in scorearr select new PlayerScore((Hashtable) t));
        }
Exemplo n.º 3
0
        private static void ProcessLevels(PResponse response, Hashtable data, out List <PlayerLevel> levels, out int numlevels)
        {
            levels    = new List <PlayerLevel> ();
            numlevels = 0;

            if (!response.success)
            {
                return;
            }

            numlevels = (int)(double)data["numlevels"];
            var levelarr = (ArrayList)data["levels"];

            levels.AddRange(from object t in levelarr select new PlayerLevel((Hashtable)t));
        }
Exemplo n.º 4
0
        private static void ProcessScores(PResponse response, IDictionary data, out List <PlayerScore> scores, out int numitems)
        {
            scores   = new List <PlayerScore>();
            numitems = 0;

            if (!response.success)
            {
                return;
            }

            numitems = (int)(double)data["numscores"];
            var scorearr = (ArrayList)data["scores"];

            scores.AddRange(from object t in scorearr select new PlayerScore((Hashtable)t));
        }
Exemplo n.º 5
0
        /**
         * Rates a level
         * @param	levelid	String	The level id
         * @param	rating	Int		Rating from 1 - 10
         * @param	callback	Action<PResponse> Your callback function
         */
        public static void Rate(string levelid, int rating, Action <PResponse> callback)
        {
            if (rating < 1 || rating > 10)
            {
                callback(PResponse.Error(401));
                return;
            }

            var postdata = new Hashtable
            {
                { "levelid", levelid },
                { "rating", rating }
            };

            PRequest.GetResponse(SECTION, RATE, postdata, callback);
        }
Exemplo n.º 6
0
        public static void GetResponse(string section, string action, Hashtable postdata, Action <PResponse> callback)
        {
            if (postdata == null)
            {
                postdata = new Hashtable();
            }
            else
            {
                postdata.Remove("publickey");
                postdata.Remove("section");
                postdata.Remove("action");
            }

            postdata.Add("publickey", PUBLICKEY);
            postdata.Add("section", section);
            postdata.Add("action", action);

            var json   = JSON.JsonEncode(postdata);
            var buffer = Encoding.UTF8.GetBytes("data=" + Encode.Base64(json) + "&hash=" + Encode.Md5(json + PRIVATEKEY));
            var task   = MakeAsyncRequest(buffer);

            if (string.IsNullOrEmpty(task.Result) || task.Exception != null || task.IsCanceled || task.IsFaulted)
            {
                callback(PResponse.GeneralError(1));
                return;
            }

            var results = (Hashtable)JSON.JsonDecode(task.Result);

            if (!results.ContainsKey("success") || !results.ContainsKey("errorcode"))
            {
                callback(PResponse.GeneralError(1));
                return;
            }

            callback(new PResponse
            {
                success   = (bool)results["success"],
                errorcode = (int)(double)results["errorcode"],
                json      = results
            });
        }