Example #1
0
 private static string   UrlEncode(string str)
 {
     if (str == null)
     {
         return(null);
     }
     return(PublisherAPI.UrlEncode(str, Encoding.UTF8));
 }
Example #2
0
 private static string   UrlEncode(string str, Encoding e)
 {
     if (str == null)
     {
         return(null);
     }
     return(Encoding.ASCII.GetString(PublisherAPI.UrlEncodeToBytes(str, e)));
 }
Example #3
0
        private static byte[]   UrlEncodeToBytes(string str, Encoding e)
        {
            if (str == null)
            {
                return(null);
            }

            byte[] bytes = e.GetBytes(str);
            return(PublisherAPI.UrlEncodeBytesToBytesInternal(bytes, 0, bytes.Length, false));
        }
Example #4
0
        public void             Connect(string username, string password, Action <HttpWebResponse, string> onCompleted)
        {
            string         endpoint = "https://kharma.unity3d.com/login";
            HttpWebRequest request  = this.CreateRequest(endpoint);
            StringBuilder  buffer   = Utility.GetBuffer();

            buffer.Append("user="******"&pass="******"&unityversion=");
            buffer.Append(PublisherAPI.UrlEncode(Application.unityVersion));
            buffer.Append("&toolversion=");
            buffer.Append(PublisherAPI.UrlEncode("V4.1.0"));
            buffer.Append("&license_hash=");
            buffer.Append(PublisherAPI.UrlEncode(this.GetLicenseHash()));
            buffer.Append("&hardware_hash=");
            buffer.Append(PublisherAPI.UrlEncode(this.GetHardwareHash()));

            byte[] content = Encoding.UTF8.GetBytes(Utility.ReturnBuffer(buffer));

            request.Headers         = new WebHeaderCollection();
            request.Method          = "POST";
            request.ContentType     = "application/x-www-form-urlencoded";
            request.ContentLength   = content.Length;
            request.Accept          = "application/json";
            request.KeepAlive       = true;
            request.Host            = "kharma.unity3d.com";
            request.CookieContainer = new CookieContainer();

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(content, 0, content.Length);
            }

            this.HandleRequest(request, endpoint.GetHashCode(), (r, s) =>
            {
                if (r == null)
                {
                }
                else
                {
                    if (Conf.DebugMode == Conf.DebugState.Verbose)
                    {
                        Debug.Log(s);
                    }
                    this.session = JsonUtility.FromJson <Session>(s);
                }

                onCompleted(r, s);
            });
        }
Example #5
0
        private static byte[]   UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
        {
            int num  = 0;
            int num2 = 0;

            for (int i = 0; i < count; i++)
            {
                char c = (char)bytes[offset + i];
                if (c == ' ')
                {
                    num++;
                }
                else if (!PublisherAPI.IsSafe(c))
                {
                    num2++;
                }
            }

            if (!alwaysCreateReturnValue && num == 0 && num2 == 0)
            {
                return(bytes);
            }

            byte[] array = new byte[count + num2 * 2];
            int    num3  = 0;

            for (int j = 0; j < count; j++)
            {
                byte b  = bytes[offset + j];
                char c2 = (char)b;

                if (PublisherAPI.IsSafe(c2))
                {
                    array[num3++] = b;
                }
                else if (c2 == ' ')
                {
                    array[num3++] = 43;
                }
                else
                {
                    array[num3++] = 37;
                    array[num3++] = (byte)PublisherAPI.IntToHex(b >> 4 & 15);
                    array[num3++] = (byte)PublisherAPI.IntToHex((int)(b & 15));
                }
            }

            return(array);
        }