Exemple #1
0
    internal IEnumerator SendRequest <T>(string section, string action, Action <Dictionary <string, T>, PResponse> callback) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, null);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        Dictionary <string, T> gameVars = new Dictionary <string, T>();

        if (data != null)
        {
            if (data is IDictionary)
            {
                foreach (string key in data.Keys)
                {
                    if (data[key] is IDictionary)
                    {
                        gameVars.Add(key, (T)Activator.CreateInstance(typeof(T), new object[] { data[key] }));
                    }
                }
            }
        }

        callback(gameVars, response);
    }
Exemple #2
0
    internal IEnumerator SendRequest <T>(string name, string section, string action, Action <T, PResponse> callback, Dictionary <string, object> postdata = null) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        T gameVar = new T();

        if (data != null)
        {
            if (data is IDictionary)
            {
                if (data.ContainsKey(name))
                {
                    gameVar = (T)Activator.CreateInstance(typeof(T), new object[] { data[name] });
                }
            }
        }

        callback(gameVar, response);
    }
    private IEnumerator SendListRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerScore
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.json;

        List <T> scores = new List <T>();

        int numscores = 0;

        if (response.success)
        {
            if (data.ContainsKey("numscores"))
            {
                int.TryParse(data["numscores"].ToString(), out numscores);
            }

            if (data.ContainsKey("scores"))
            {
                if (data["scores"] is IList)
                {
                    foreach (IDictionary score in (IList)data["scores"])
                    {
                        scores.Add((T)Activator.CreateInstance(typeof(T), new object[] { score }));
                    }
                }
            }
        }

        callback(scores, numscores, response);
    }
    private IEnumerator SendListRequest <T>(Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerLevel, new()
    {
        var www = PRequest.Prepare(SECTION, LIST, postdata);

        yield return(www);

        var      response  = PRequest.Process(www);
        List <T> levels    = null;
        int      numlevels = 0;

        if (response.success)
        {
            var data = response.json;
            levels    = new List <T>();
            numlevels = (int)(double)data["numlevels"];

            var levelarr = (List <object>)data["levels"];

            for (var i = 0; i < levelarr.Count; i++)
            {
                levels.Add((T) new PlayerLevel((Dictionary <string, object>)levelarr[i]));
            }
        }

        callback(levels, numlevels, response);
    }
    private IEnumerator SendRateRequest(Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        var www = PRequest.Prepare(SECTION, RATE, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
    private IEnumerator SendSaveRequest(string section, string action, Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        PResponse response = PRequest.Process(www);

        callback(response);
    }
Exemple #7
0
    private IEnumerator SendRequest(string section, string action, Action <PResponse> callback, PNewsletterOptions options)
    {
        var www = PRequest.Prepare(section, action, options);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
Exemple #8
0
    internal IEnumerator SendSaveRequest(string section, string action, Action <PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
Exemple #9
0
    private IEnumerator SendListRequest <T>(Dictionary <string, object> postdata,
                                            Action <List <T>, int, PResponse> callback) where T : PlayerChallenge, new()
    {
        var www = PRequest.Prepare(SECTION, LIST, postdata);

        yield return(www);

        List <T> challenges    = null;
        int      numchallenges = 0;
        var      response      = default(QuickResponse <ListChallengeResponse <T> >);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <ListChallengeResponse <T> >(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <ListChallengeResponse <T> > {
                success = false, errorcode = 1
            };
        }

        if (response.success)
        {
            var challengeArray = response.ResponseObject.challenges;

            challenges = new List <T>();

            for (int i = 0; i < challengeArray.Length; i++)
            {
                challenges.Add(challengeArray[i]);
            }

            numchallenges = challenges.Count;
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(challenges, numchallenges, resp);
    }
Exemple #10
0
    private IEnumerator sendReplay(Dictionary <string, object> postdata, Action <bool> callback)
    {
        var www = PRequest.Prepare(SECTION, POSTRESULT, postdata);

        yield return(www);

        // no point threading this one due to tiny ammount of data
        var response = PRequest.FastProcess <ReplaySentResponse>(www);

        callback(response.success);
    }
Exemple #11
0
    private IEnumerator SendRequest(string section, string action, Action <PlayerCountry, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        callback(new PlayerCountry(data), response);
    }
Exemple #12
0
    private IEnumerator SendSaveLoadRequest(string section, string action, Dictionary <string, object> postdata, Action <PlayerLevel, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var         response = PRequest.Process(www);
        PlayerLevel level    = null;

        if (response.success)
        {
            level = new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
    private IEnumerator SendSaveLoadRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <T, PResponse> callback) where T : PlayerLevel
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        T   level    = default(T);

        if (response.success)
        {
            level = (T) new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
Exemple #14
0
    private IEnumerator SendSaveLoadRequest <T>(string action,
                                                Dictionary <string, object> postdata,
                                                Action <T, PResponse> callback) where T : PlayerChallenge
    {
        var www = PRequest.Prepare(SECTION, action, postdata);

        yield return(www);

        var response  = default(QuickResponse <UpdateChallengeResponse <T> >);
        var challenge = default(T);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <UpdateChallengeResponse <T> >(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <UpdateChallengeResponse <T> > {
                success = false, errorcode = 1
            };
        }

        if (response.success)
        {
            challenge = response.ResponseObject.challenge;
        }

        var resp = new PResponse {
            success = response.success, errorcode = response.errorcode
        };

        callback(challenge, resp);
    }
Exemple #15
0
    private IEnumerator getReplay <T>(string section, string action, Dictionary <string, object> postdata, Action <T, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var replay   = default(T);
        var response = new QuickResponse <GetReplayResponse <T> >();

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            // spool deserialization off to another thread, allows UI to continue updating in the meantime
            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <GetReplayResponse <T> >(data);
            });
            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }

            if (response.success)
            {
                replay = response.ResponseObject.challenge["replay"];
            }
        }
        else
        {
            response = new QuickResponse <GetReplayResponse <T> > {
                success = false, errorcode = 1
            };
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(replay, resp);
    }
Exemple #16
0
    private IEnumerator SendPing(Dictionary <string, object> postdata, int attempts)
    {
        while (attempts > 0)
        {
            var www = PRequest.Prepare(SECTION, PING, postdata);
            yield return(www);

            // no point threading this one due to tiny size of response
            var response = PRequest.FastProcess <ResponseBase>(www);

            // if successful exit
            if (response.success)
            {
                break;
            }

            attempts--;
        }
    }
Exemple #17
0
    internal IEnumerator SendListRequest <T>(string section, string action, Action <List <T>, PResponse> callback, Dictionary <string, object> postdata = null) where T : PlayerAchievement
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        List <T> achievements = new List <T>();

        if (response.success)
        {
            foreach (IDictionary achievment in (IList)data["achievements"])
            {
                achievements.Add((T)Activator.CreateInstance(typeof(T), new object[] { achievment }));
            }
        }

        callback(achievements, response);
    }
Exemple #18
0
    private IEnumerator SendUpdate <T>(string section,
                                       string action,
                                       Dictionary <string, object> postdata,
                                       Action <bool, PResponse> callback) where T : PlayerChallenge, new()
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = default(QuickResponse <ReplaySentResponse>);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;
            Thread t    = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <ReplaySentResponse>(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <ReplaySentResponse> {
                success = false, errorcode = 1
            };
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(response.success, resp);
    }
Exemple #19
0
    internal IEnumerator SendStreamRequest(string section, string action, Action <List <PlayerAward>, int, PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        int numachievements = 0;

        int.TryParse(data["numachievements"].ToString(), out numachievements);

        var achievements = new List <PlayerAward>();

        if (response.success)
        {
            var acharray = (List <object>)data["achievements"];
            achievements.AddRange(from object t in acharray select new PlayerAward((Dictionary <string, object>)t));
        }

        callback(achievements, numachievements, response);
    }