Example #1
0
        /*
         * Sends the user to log in to coachdata app and receives data from
         * the server
         * Function redone from the conection.js of Mateo
         *
         * This function is a coroutine and must be used with startCoroutine instead of called directly
         *
         *@param user: the user string
         *@param loggedSuccesfully: function called if the user manages to log in (can be null)
         *@param error: function called if the user fails to log in (can be null)
         */
        public static IEnumerator loginCoachData(string user, loggedFunction loggedSuccesfully, errorFunction error)
        {
            float evaluation = 0;
            WWW   request;
            Dictionary <string, string> args = new Dictionary <string, string>();
            IEnumerator auxRet;

            do
            {
                auxRet = setBaseUrl();
                if (auxRet != null)
                {
                    yield return(auxRet);
                }
            } while (auxRet != null);

            args.Add("user", user);
            request = new WWW(BASE_URL + GAME_LOGIN + GetParameters(args));
            while (!request.isDone)
            {
                yield return(request);
            }

            /*Debug.LogError ("REQUEST:"+BASE_URL + GAME_LOGIN+GetParameters(args));
             *          Debug.LogError ("TEXT:"+request.text);*/
            if (request.error == null)
            {
                loginCoachDataResponse aux = JsonConvert.DeserializeObject <loginCoachDataResponse>(request.text);
                if (aux.response == "OK")
                {
                    if (aux.evaluated)
                    {
                        foreach (KeyValuePair <string, JToken> pair in aux.evaluations)
                        {
                            evaluation += pair.Value.ToObject <int>();
                        }
                        evaluation /= (float)(aux.evaluations.Count * aux.max_mark);
                    }
                    if (loggedSuccesfully != null)
                    {
                        loggedSuccesfully(evaluation);
                    }
                }
                else
                {
                    if (error != null)
                    {
                        error();
                    }
                }
            }
            else if (error != null)
            {
                error();
            }
        }
Example #2
0
        /******************************************************************************************************************/
        public static IEnumerator sendVideoGameStatistics(string user, int levelReached, float yards, int acquiredSpeed,
                                                          int acquiredJumps, int acquiredLifes, float timePlayedInSeconds, successFunction success, errorFunction error)
        {
            WWW request;
            Dictionary <string, string> args = new Dictionary <string, string>();
            IEnumerator auxRet;

            do
            {
                auxRet = setBaseUrl();
                if (auxRet != null)
                {
                    yield return(auxRet);
                }
            } while (auxRet != null);
            args.Add("user", user);
            args.Add("levelReached", levelReached.ToString());
            args.Add("yards", yards.ToString());
            args.Add("acquiredSpeed", acquiredSpeed.ToString());
            args.Add("acquiredJumps", acquiredJumps.ToString());
            args.Add("acquiredLifes", acquiredLifes.ToString());
            args.Add("timePlayedInSeconds", timePlayedInSeconds.ToString());
            args.Add("timePlayedInMinutes", (timePlayedInSeconds / 60).ToString());
            request = new WWW(BASE_URL + SAVE_STATISTICS + GetParameters(args));
            yield return(request);

            if (request.error == null)
            {
                loginCoachDataResponse aux = JsonConvert.DeserializeObject <loginCoachDataResponse>(request.text);
                if (aux.response != "OK")
                {
                    if (error != null)
                    {
                        error();
                    }
                }
                else
                {
                    if (success != null)
                    {
                        success();
                    }
                }
            }
            else
            if (error != null)
            {
                error();
            }
        }
Example #3
0
        /******************************************************************************************************************/
        public static IEnumerator sendVideoGameValues(string user, int level, int points, int velocity, int numJumps, int lifes,
                                                      successFunction success, errorFunction error)
        {
            WWW request;
            Dictionary <string, string> args = new Dictionary <string, string>();
            IEnumerator auxRet;

            do
            {
                auxRet = setBaseUrl();
                if (auxRet != null)
                {
                    yield return(auxRet);
                }
            } while (auxRet != null);
            args.Add("user", user);
            args.Add("level", level.ToString());
            args.Add("points", points.ToString());
            args.Add("velocity", velocity.ToString());
            args.Add("numJumps", numJumps.ToString());
            args.Add("lifes", lifes.ToString());
            request = new WWW(BASE_URL + SAVE_VALUES + GetParameters(args));
            yield return(request);

            if (request.error == null)
            {
                loginCoachDataResponse aux = JsonConvert.DeserializeObject <loginCoachDataResponse>(request.text);
                if (aux.response != "OK")
                {
                    if (error != null)
                    {
                        error();
                    }
                }
                else
                {
                    if (success != null)
                    {
                        success();
                    }
                }
            }
            else
            if (error != null)
            {
                error();
            }
        }