Exemple #1
0
    protected IEnumerator SendCore(string apicall, Hashtable args, IRequestCallback cb, bool requires_auth_token)
    {
        if (GameKey == "")
        {
            logger.DebugLog("[roar] -- No game key set!--");
            yield break;
        }

        logger.DebugLog("[roar] -- Calling: " + apicall);

        // Encode POST parameters
        WWWForm post = new WWWForm();

        if (args != null)
        {
            foreach (DictionaryEntry param in args)
            {
                //Debug.Log(string.Format("{0} => {1}", param.Key, param.Value));
                post.AddField(param.Key as string, param.Value as string);
            }
        }

        if (requires_auth_token)
        {
            AddAuthToken(args, post);
        }

        // Fire call sending event
        RoarManager.OnRoarNetworkStart();

        //Debug.Log ( "roar_api_url = " + RoarAPIUrl );
        if (Debug.isDebugBuild)
        {
            Debug.Log("Requesting : " + RoarAPIUrl + GameKey + "/" + apicall + "/");
        }

        //NOTE: This is a work-around for unity not supporting zero length body for POST requests
        if (post.data.Length == 0)
        {
            post.AddField("dummy", "x");
        }

        var xhr = new WWW(RoarAPIUrl + GameKey + "/" + apicall + "/", post);

        yield return(xhr);

        OnServerResponse(xhr.text, apicall, cb);
    }