CreateMD5Hash() public method

Encodes the input as a MD5 hash
public CreateMD5Hash ( string input ) : string
input string /// The input we want encoded ///
return string
Beispiel #1
0
    private static WWW GetEventWWW(GA_Submit.CategoryType category, Hashtable parameters)
    {
        string url  = GA_Submit.GetURL(GA_Submit.Categories[category], _publicTestKey);
        string json = GA_Submit.DictToJson(new List <Hashtable>()
        {
            parameters
        });
        string jsonHash = GA_Submit.CreateMD5Hash(json + _privateTestKey);

        return(GA_Submit.CreateSubmitWWW(url, json, jsonHash));
    }
Beispiel #2
0
    public WWW RequestGameInfo(SubmitSuccessHandler successEvent, SubmitErrorHandler errorEvent)
    {
        if (string.IsNullOrEmpty(GA.SettingsGA.GameKey))
        {
            GA.LogWarning("Game key not set - please setup your Game key in GA_Settings, under the Basic tab");
            return(null);
        }
        if (string.IsNullOrEmpty(GA.SettingsGA.ApiKey))
        {
            GA.LogWarning("API key not set - please setup your API key in GA_Settings, under the Advanced tab");
            return(null);
        }

        string game_key = GA.SettingsGA.GameKey;

        string requestInfo = "game_key=" + game_key + "&keys=area%7Cevent_id%7Cbuild";

        requestInfo = requestInfo.Replace(" ", "%20");

        //Get the url with the request type
        string url = GetURL(Requests[RequestType.GA_GetHeatmapGameInfo]);

        url += "/?" + requestInfo;

        WWW www = null;

                #if UNITY_FLASH
        //Set the authorization header to contain an MD5 hash of the JSON array string + the private key
        Hashtable headers = new Hashtable();
        headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey));

        //Try to send the data
        www = new WWW(url, new byte[] { 0 }, headers);
                #else
        //Set the authorization header to contain an MD5 hash of the JSON array string + the private key
                #if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0
        Hashtable headers = new Hashtable();
                #else
        Dictionary <string, string> headers = new Dictionary <string, string>();
                #endif
        headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey));

        //Try to send the data
        www = new WWW(url, new byte[] { 0 }, headers);
                #endif

        GA.RunCoroutine(Request(www, RequestType.GA_GetHeatmapGameInfo, successEvent, errorEvent), () => www.isDone);

        return(www);
    }
Beispiel #3
0
    public WWW RequestHeatmapData(List <string> events, string area, string build, DateTime?startDate, DateTime?endDate, SubmitSuccessHandler successEvent, SubmitErrorHandler errorEvent)
    {
        string game_key  = GA.SettingsGA.GameKey;
        string event_ids = "";

        for (int i = 0; i < events.Count; i++)
        {
            if (i == events.Count - 1)
            {
                event_ids += events[i];
            }
            else
            {
                event_ids += events[i] + "|";
            }
        }

        string requestInfo = "game_key=" + game_key + "&event_ids=" + event_ids + "&area=" + area;

        if (!build.Equals(""))
        {
            requestInfo += "&build=" + build;
        }

        requestInfo = requestInfo.Replace(" ", "%20");

        if (startDate.HasValue && endDate.HasValue)
        {
            DateTime startDT = new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, 0, 0, 0);
            DateTime endDT   = new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 0, 0, 0);

            requestInfo += "&start_ts=" + DateTimeToUnixTimestamp(startDT) + "&end_ts=" + DateTimeToUnixTimestamp(endDT);
        }

        //Get the url with the request type
        string url = GetURL(Requests[RequestType.GA_GetHeatmapData]);

        url += "/?" + requestInfo;

        WWW www = null;

                #if UNITY_FLASH
        //Set the authorization header to contain an MD5 hash of the JSON array string + the private key
        Hashtable headers = new Hashtable();
        headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey));

        //Try to send the data
        www = new WWW(url, new byte[] { 0 }, headers);
                #else
        //Set the authorization header to contain an MD5 hash of the JSON array string + the private key
                #if UNITY_4_3 || UNITY_4_2 || UNITY_4_1 || UNITY_4_0_1 || UNITY_4_0
        Hashtable headers = new Hashtable();
                #else
        Dictionary <string, string> headers = new Dictionary <string, string>();
                #endif
        headers.Add("Authorization", GA_Submit.CreateMD5Hash(requestInfo + GA.SettingsGA.ApiKey));

        //Try to send the data
        www = new WWW(url, new byte[] { 0 }, headers);
                #endif

        GA.RunCoroutine(Request(www, RequestType.GA_GetHeatmapData, successEvent, errorEvent), () => www.isDone);

        return(www);
    }
    private void DeleteMeshes()
    {
        _loaded = false;

        if (meshSelected == null)
        {
            return;
        }

        for (int i = 0; i < meshSelected.Length; i++)
        {
            if (meshSelected[i])
            {
                WWWForm form = new WWWForm();

                form.AddField("gamekey", GA.SettingsGA.GameKey);
                form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + meshNames[i] + ".unity3d" + GA.SettingsGA.SecretKey));
                form.AddField("meshname", meshNames[i] + ".unity3d");

                WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/mesh/delete", form);

                while (!w.isDone)
                {
                }

                if (w.error != null)
                {
                    Debug.LogWarning("Failed to delete mesh: " + meshNames[i]);
                }
                else
                {
                    Hashtable data = (Hashtable)GA_MiniJSON.JsonDecode(w.text);

                    ArrayList errorArray = data["errors"] as ArrayList;

                    if (errorArray.Count > 0)
                    {
                        foreach (Hashtable ht in errorArray)
                        {
                            string msg = (string)ht["message"];
                            if (msg.Equals("404"))
                            {
                                Debug.LogWarning("Game key or mesh not found! Have you input the correct game key in GA_Settings?");
                            }
                            else if (msg.Equals("401"))
                            {
                                Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?");
                            }
                            else if (msg.Equals("400"))
                            {
                                Debug.LogWarning("Failed to delete mesh.");
                            }
                            else if (msg.Equals("503"))
                            {
                                Debug.LogWarning("Service unavailable, please try again later!");
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Deleted mesh: " + meshNames[i]);
                    }
                }
            }
        }
        UpdateMeshList();
    }
    public void UpdateMeshList()
    {
        WWWForm form = new WWWForm();

        form.AddField("gamekey", GA.SettingsGA.GameKey);
        form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + GA.SettingsGA.SecretKey));

        WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/meshes", form);

        while (!w.isDone)
        {
        }

        if (w.error != null)
        {
            Debug.LogWarning("Failed to load mesh names " + w.error);
        }
        else
        {
            try
            {
                Hashtable data = (Hashtable)GA_MiniJSON.JsonDecode(w.text);

                ArrayList errorArray = data["errors"] as ArrayList;
                ArrayList meshArray  = data["results"] as ArrayList;

                if (errorArray.Count > 0 || meshArray.Count == 0)
                {
                    foreach (Hashtable ht in errorArray)
                    {
                        string msg = (string)ht["message"];
                        if (msg.Equals("404"))
                        {
                            Debug.LogWarning("Game key not found! Have you input the correct game key in GA_Settings?");
                        }
                        else if (msg.Equals("401"))
                        {
                            Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?");
                        }
                        else if (msg.Equals("400"))
                        {
                            Debug.LogWarning("Failed to load meshes.");
                        }
                        else if (msg.Equals("503"))
                        {
                            Debug.LogWarning("Service unavailable, please try again later!");
                        }
                    }

                    _error = true;
                }
                else
                {
                    meshNames = new List <string>();
                    meshSizes = new List <string>();
                    foreach (Hashtable ht in meshArray)
                    {
                        meshNames.Add(((string)ht["name"]).Replace(".unity3d", ""));
                        meshSizes.Add(((string)ht["size"]));
                    }

                    meshSelected = new bool[meshNames.Count];
                }
            }
            catch
            {
                _error = true;
            }

            _loaded = true;
        }
    }
    static void UploadAssetBunble(string path, string fileName)
    {
        byte[] meshData = File.ReadAllBytes(path);

        if (!fileName.EndsWith(".unity3d"))
        {
            fileName = fileName + ".unity3d";
        }

        WWWForm form = new WWWForm();

        form.AddField("gamekey", GA.SettingsGA.GameKey);
        form.AddField("authorization", GA_Submit.CreateMD5Hash(GA.SettingsGA.GameKey + fileName + GA.SettingsGA.SecretKey));
        form.AddBinaryData("mesh", meshData, fileName, "application/vnd.unity");

        WWW w = new WWW("https://go.gameanalytics.com/api/heatmap/mesh/upload", form);

        while (!w.isDone)
        {
            EditorUtility.DisplayProgressBar("Uploading static mesh. Please wait...", "Might take a while", w.progress);
        }

        if (w.error != null)
        {
            Debug.LogWarning("Mesh Upload Error: " + w.error);
        }
        else
        {
            Hashtable data       = (Hashtable)GA_MiniJSON.JsonDecode(w.text);
            ArrayList errorArray = data["errors"] as ArrayList;

            if (errorArray.Count > 0)
            {
                foreach (Hashtable ht in errorArray)
                {
                    string msg = (string)ht["message"];
                    if (msg.Equals("404"))
                    {
                        Debug.LogWarning("Game not found! Have you input the correct game key in GA_Settings?");
                    }
                    else if (msg.Equals("401"))
                    {
                        Debug.LogWarning("Authorization failed! Have you input the correct secret key in GA_Settings?");
                    }
                    else if (msg.Equals("400"))
                    {
                        Debug.LogWarning("Failed to upload mesh.");
                    }
                    else if (msg.Equals("503"))
                    {
                        Debug.LogWarning("Service unavailable, please try again later!");
                    }
                    else if (msg.Equals("409"))
                    {
                        Debug.LogWarning("Mesh already exists! please try with a different name, or delete the existing mesh through the GameAnalytics > Delete AssetBundle Menu.");
                    }
                }
            }
            else
            {
                Debug.Log("Mesh Upload: Completed with no errors.");
            }
        }

        if (File.Exists(path))
        {
            Debug.Log("Deleting local asset bundle file after upload");
            File.Delete(path);
        }
    }