예제 #1
0
    public void GetAddressQRCode(string address, GrdEventHandler callback)
    {
        Dictionary <string, string> dic = new Dictionary <string, string>();

        dic.Add("address", address);
        StartCoroutine(Get((responseText) => {
            responseText = responseText.Replace("data:image/image/png;base64,", "");
            byte[] array = System.Convert.FromBase64String(responseText);
            int width, height;
            int error         = 0;
            Texture2D texture = null;
            try
            {
                GetImageSize(array, out width, out height);
                texture            = new Texture2D(width, height, TextureFormat.ARGB32, false, true);
                texture.hideFlags  = HideFlags.HideAndDontSave;
                texture.filterMode = FilterMode.Point;
                texture.LoadImage(array);
            }
            catch
            {
                error = 1;
            }
            if (callback != null)
            {
                callback(error, texture);
            }
        }, "qrcodeaddress", dic));
    }
예제 #2
0
    /// <summary>
    /// Transfer user money to another wallet
    /// </summary>
    /// <param name="toAddress">Address of the wallet to transfer to</param>
    /// <param name="money">The amount of money to tranfer</param>
    /// <param name="callback">Call when the transfer finished!</param>
    public void Transfer(string toAddress, decimal money, string otp, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("to", toAddress);
        pars.Add("value", FormatNumber(money));
        pars.Add("otp", otp);
        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            if (result["error"].ToString() == "0")
            {
                if (!result.ContainsKey("balance"))
                {
                    User.balance -= money;
                }
                else
                {
                    User.balance = decimal.Parse(result["balance"].ToString());
                }
            }
            if (callback != null)
            {
                callback(int.Parse(result["error"].ToString()), result["message"].ToString());
            }
        }, "transfer", pars));
    }
예제 #3
0
        /// <summary>
        /// Request for buy an item.
        /// </summary>
        /// <param name="callback"></param>
        public static void RequestBuyItem(string itemid, int quantity, GrdEventHandler <GrdPurchaseRequest> callback)
        {
            Dictionary <string, string> pars = new Dictionary <string, string>();

            pars["itemid"]   = itemid;
            pars["quantity"] = quantity.ToString();
            handler.Post((data) =>
            {
                Dictionary <string, object> result = GetObjectData(data);
                if (callback != null)
                {
                    int error = int.Parse(result["error"].ToString());
                    GrdEventArgs <GrdPurchaseRequest> args = null;
                    if (error == 0)
                    {
                        GrdPurchaseRequest request = new GrdPurchaseRequest();
                        request.RequestId          = result["requestid"].ToString();
                        args = new GrdEventArgs <GrdPurchaseRequest>(error, "", data, request);
                    }
                    else
                    {
                        args = new GrdEventArgs <GrdPurchaseRequest>(error, result["message"].ToString(), data, null);
                    }
                    callback(error, args);
                }
            }, "requestpurchase", pars);
        }
예제 #4
0
    /// <summary>
    /// This method use for user login to system. Server response the result is success or failed.
    /// </summary>
    /// <param name="username">Username user use to login</param>
    /// <param name="password">Password user use to login</param>
    /// <param name="callback">Call when completed.</param>
    public void Login(string username, string password, string otp, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("username", username);
        pars.Add("password", Md5Sum(password));
        pars.Add("otp", otp);
        StartCoroutine(Post((data) =>
        {
            object r = null;
            Dictionary <string, object> result = GetObjectData((string)data);
            if (result["error"].ToString() == "0")
            {
                user               = new GrdUser();
                user.username      = username;
                user.address       = result["address"].ToString();
                user.email         = result["email"].ToString();
                user.balance       = decimal.Parse(result["balance"].ToString());
                user.isRequiredOtp = result["isRequiredOtp"].ToString() == "1";
                token              = result["token"].ToString();
                r = user;
            }
            else
            {
                r = result["message"];
            }
            if (callback != null)
            {
                callback(int.Parse(result["error"].ToString()), r);
            }
        }, "login", pars));
    }
예제 #5
0
        public static void CheckItemStatus(string requestid, GrdEventHandler <GrdPurchaseStatus> callback)
        {
            Dictionary <string, string> pars = new Dictionary <string, string>();

            pars["requestid"] = requestid;
            handler.Post((data) =>
            {
                Dictionary <string, object> result = GetObjectData(data);
                if (callback != null)
                {
                    int error  = int.Parse(result["error"].ToString());
                    string msg = "";
                    GrdPurchaseStatus status = GrdPurchaseStatus.NewRequest;
                    if (error != 0)
                    {
                        msg = result["message"].ToString();
                    }
                    else
                    {
                        status = (GrdPurchaseStatus)int.Parse(result["status"].ToString());
                    }
                    GrdEventArgs <GrdPurchaseStatus> args = new GrdEventArgs <GrdPurchaseStatus>(error, msg, data, status);
                    callback(error, args);
                }
            }, "checkpurchasestatus", pars);
        }
예제 #6
0
 /// <summary>
 /// LogOut user from system.
 /// </summary>
 /// <param name="callback"></param>
 public void LogOut(GrdEventHandler callback)
 {
     StartCoroutine(Post((data) =>
     {
         Dictionary <string, object> result = GetObjectData((string)data);
         if (callback != null)
         {
             callback(int.Parse(result["error"].ToString()), result["message"]);
         }
     }, "logout", null));
 }
예제 #7
0
    /// <summary>
    /// Use when user want to turn on the 2 steps verification.
    ///
    /// </summary>
    /// <param name="callback">Call when the request is completed and return the result</param>
    public void RequestEnableOtp(GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            if (callback != null)
            {
                callback(int.Parse(result["error"].ToString()), result["message"].ToString());
            }
        }, "requestotp", pars));
    }
예제 #8
0
    /// <summary>
    /// This method use to reset password for user. System will send an email change password for user
    /// </summary>
    /// <param name="username">Username user use to login</param>
    /// <param name="password">Password user use to login</param>
    /// <param name="callback">Call when completed.</param>
    public void ResetPassword(string usernameOrEmail, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("email", usernameOrEmail);
        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            if (callback != null)
            {
                callback(int.Parse(result["error"].ToString()), result["message"]);
            }
        }, "requestresetpassword", pars));
    }
예제 #9
0
    /// <summary>
    /// Allow user enable or disable the 2 steps verification security options
    /// </summary>
    /// <param name="otp"></param>
    /// <param name="enabled"></param>
    /// <param name="callback"></param>
    public void EnableOtp(string otp, bool enabled, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("otp", otp);
        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            int error = int.Parse(result["error"].ToString());
            if (error == 0)
            {
                User.isRequiredOtp = enabled;
            }
            if (callback != null)
            {
                callback(error, result["message"].ToString());
            }
        }, "enableotp", pars));
    }
예제 #10
0
        /// <summary>
        /// Get the qrcode from text
        /// </summary>
        /// <param name="text">The text to encode to QR code</param>
        /// <param name="callback">Call when server response QR code.</param>
        public static void GetQRCode(string text, GrdEventHandler <Texture2D> callback)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("text", text);
            dic.Add("type", "1");
            handler.Post((data) =>
            {
                if (callback != null)
                {
                    Dictionary <string, object> result = GetObjectData((string)data);
                    Texture2D texture = null;
                    int error         = int.Parse(result["error"].ToString());
                    string message    = text;
                    if (error == 0)
                    {
                        string qrcode = result["qrcode"].ToString();
                        if (qrcode.Length > 0)
                        {
                            qrcode = qrcode.Substring("data:image/image/png;base64,".Length);
                        }
                        try
                        {
                            texture = GetTexture(qrcode);
                        }
                        catch
                        {
                            error = 1;
                        }
                    }
                    else
                    {
                        text = result["message"].ToString();
                    }
                    GrdEventArgs <Texture2D> args = new GrdEventArgs <Texture2D>(error, data, text, texture);
                    callback(error, args);
                }
            }, "qrcode", dic);
        }
예제 #11
0
 /// <summary>
 /// Get the newest user balance from server update to user object.
 /// </summary>
 /// <param name="callback"></param>
 public void UpdateBalance(GrdEventHandler callback)
 {
     StartCoroutine(Get((data) =>
     {
         Dictionary <string, object> result = GetObjectData((string)data);
         object r = null;
         if (result["error"].ToString() == "0")
         {
             if (result.ContainsKey("balance"))
             {
                 User.balance = decimal.Parse(result["balance"].ToString());
             }
             r = data;
         }
         else
         {
             r = result["message"].ToString();
         }
         if (callback != null)
         {
             callback(int.Parse(result["error"].ToString()), r);
         }
     }, "accountbalance"));
 }
예제 #12
0
        public static void GetItemsInfo(string[] itemCodes, GrdEventHandler <GrdItem[]> callback)
        {
            Dictionary <string, string> pars = new Dictionary <string, string>();

            pars["items"] = string.Join(",", itemCodes);
            handler.Post((data) =>
            {
                Dictionary <string, object> result = GetObjectData(data);
                if (callback != null)
                {
                    int error            = int.Parse(result["error"].ToString());
                    string msg           = "";
                    List <GrdItem> items = new List <GrdItem>();
                    if (error == 0)
                    {
                        List <object> ls = (List <object>)result["items"];
                        for (int i = 0; i < ls.Count; i++)
                        {
                            Dictionary <string, object> dic = (Dictionary <string, object>)ls[i];
                            GrdItem item  = new GrdItem();
                            item.itemcode = dic["itemcode"].ToString();
                            item.itemname = dic["itemname"].ToString();
                            item.price    = decimal.Parse(dic["price"].ToString());
                            item.itemicon = dic["itemicon"].ToString();
                            items.Add(item);
                        }
                    }
                    else
                    {
                        msg = result["message"].ToString();
                    }
                    GrdEventArgs <GrdItem[]> args = new GrdEventArgs <GrdItem[]>(error, msg, data, items.ToArray());
                    callback(error, args);
                }
            }, "getappitems", pars);
        }
예제 #13
0
    /// <summary>
    /// Call the server script to do logic game on server
    /// </summary>
    /// <param name="scriptName">The name of the script defined on server</param>
    /// <param name="functionName">The name of function you want to call. If the script have return statement in global scope, the functionName can be empty</param>
    /// <param name="parameters">The parameters to pass to the function</param>
    /// <param name="callback">Call when server response result.</param>
    public void CallServerScript(string scriptName, string functionName, object[] parameters, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("vars", MiniJSON.Json.Serialize(parameters));
        pars.Add("fn", functionName);
        pars.Add("script", scriptName);
        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            int error    = int.Parse(result["error"].ToString());
            object rdata = null;
            if (error != 0)
            {
                rdata = result["message"];
            }
            else
            {
                rdata = result["result"];
            }
            if (callback != null)
            {
                callback(error, rdata);
            }
        }, "callserverscript", pars));
    }
예제 #14
0
    /// <summary>
    /// This function use to register a new user
    /// </summary>
    /// <param name="username">Username use to login</param>
    /// <param name="password">Password of the account</param>
    /// <param name="email">Email use for reseting password or receiving the message from app.</param>
    /// <param name="userdata">Any data in string</param>
    /// <param name="callback">Call when finish.</param>
    public void Register(string username, string password, string email, string userdata, GrdEventHandler callback)
    {
        Dictionary <string, string> pars = new Dictionary <string, string>();

        pars.Add("username", username);
        pars.Add("password", Md5Sum(password));
        pars.Add("email", email);
        pars.Add("userdata", userdata);
        StartCoroutine(Post((data) =>
        {
            Dictionary <string, object> result = GetObjectData((string)data);
            if (callback != null)
            {
                callback(int.Parse(result["error"].ToString()), result["message"]);
            }
        }, "createaccount", pars));
    }
예제 #15
0
 /// <summary>
 /// Get the qrcode from text
 /// </summary>
 /// <param name="text">The text to encode to QR code</param>
 /// <param name="callback">Call when server response QR code.</param>
 public static void GetRequestPurchaseQRCode(string requestid, GrdEventHandler <Texture2D> callback)
 {
     GetQRCode("pay:" + requestid, callback);
 }