Beispiel #1
0
        public IEnumerator SendRequest(TeamRequestType type, Action <RequestResult, string> callback, int score = 0, TeamData teamData = null, string name = null, bool flag = false)
        {
            bool requestSuccess    = false;
            int  requestTriesCount = 0;

            while (!requestSuccess)
            {
                if (requestTriesCount > 0)
                {
                    yield return(new WaitForSeconds(RequestFailWaitTime));
//					Debug.Log("Request [" + type + "] failed with result [" + _requestResult + "] retrying #" + requestTriesCount);
                }

                requestTriesCount++;
                if (requestTriesCount == MaxRequestRetries)
                {
                    Debug.Log("Failed to perform request 3 times. Canceling request.");
                    break;
                }

                switch (type)
                {
                case TeamRequestType.AddTeam:
                    yield return(_coroutineFactory.StartCoroutine(() => SendAddTeamRequest(teamData)));

                    break;

                case TeamRequestType.JoinTeam:
                    yield return(_coroutineFactory.StartCoroutine(() => SendJoinTeamRequest(teamData)));

                    break;

                case TeamRequestType.GetTeamsByName:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetTeamsByNameRequest(name)));

                    break;

                case TeamRequestType.GetTeamLeaderboard:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetTopTeamsRequest(teamData, flag)));

                    break;

                case TeamRequestType.GetPlayersLeaderboard:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetTopPlayersRequest(teamData)));

                    break;

                case TeamRequestType.GetTop:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetTopRequest(teamData)));

                    break;

                case TeamRequestType.GetTeam:
                    yield return(_coroutineFactory.StartCoroutine(() => SendGetTeamRequest(teamData)));

                    break;

                case TeamRequestType.UpdateScore:
                    yield return(_coroutineFactory.StartCoroutine(() => SendUpdateScoreRequest(score)));

                    break;
                }

                if (_requestResult != RequestResult.NoInternet && _requestResult != RequestResult.CantReachServer && _requestResult != RequestResult.InternalServerError)
                {
                    requestSuccess = true;
                }
            }

            callback(_requestResult, _requestData);
        }
Beispiel #2
0
 private void BuildGetTeamRequest(TeamData teamInfo)
 {
     _requestUrl = String.Format("{0}{1}/{2}", _url, "teams", teamInfo.id);
 }
Beispiel #3
0
 private void BuildGetTopPlayersRequest(TeamData teamData)
 {
     _requestUrl = String.Format("{0}{1}/{2}/{3}", _url, "teams", teamData.id, "leaderboard");
 }
Beispiel #4
0
 private void BuildGetTopRequest(TeamData teamData)
 {
     _requestUrl = String.Format("{0}{1}/{2}/{3}?{4}={5}", _url, "teams", teamData.id, "top", "country", teamData.teamInfo.countryId);
 }
Beispiel #5
0
 private void BuildGetTopTeamsRequest(TeamData teamData, bool calcRankChanges)
 {
     _requestUrl = String.Format("{0}{1}/{2}?{3}={4}", _url, "teams", "leaderboard", "rankChange", calcRankChanges);
 }