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); }
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); }
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); }
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); }