Beispiel #1
0
        /// <summary>
        /// change player password
        /// </summary>
        ///  <param name="tmpCode"> the code that recieved by email or phone number</param>
        ///  <param name="newPassword"> the new password that want to be changed</param>
        /// <return></return>
        public static async Task <ApiResponse> ChangePassword(string tmpCode, string newPassword)
        {
            Dictionary <string, dynamic> body = new Dictionary <string, dynamic>();

            if (tmpCode != null)
            {
                body.Add("tmpCode", tmpCode);
            }
            if (newPassword != null)
            {
                body.Add("newPassword", GCPolicy.Md5Generator(newPassword));
            }

            ServerResponse req = await PutRequestAsync("players/v2/forgot/changePassword", body);

            var resp = (JObject)JsonConvert.DeserializeObject(req.responseMessage);

            if (req.IsSuccess)
            {
                bool instance = resp["change"].ToObject <bool>();
                return(new ApiResponse(instance, req.responseStatusCode, null));
            }
            else
            {
                if (resp["ecode"].ToObject <int>() == 10074)
                {
                    return(new ApiResponse(false, 10074, null));
                }
            }
            return(new ApiResponse(false, req.responseStatusCode, null));
        }
Beispiel #2
0
        /// <summary>
        /// Create Your Player in your Game
        /// </summary>
        ///  <param name="PlayerSchema"> the Schema of player you want to create </param>
        /// <return></return>
        public async static Task <ApiResponse> CreatePlayer <T>(T PlayerSchema)
        {
            string stringJSON = JsonConvert.SerializeObject(PlayerSchema);
            var    body       = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(stringJSON);

            if (body.ContainsKey("password") == true)
            {
                body["password"] = GCPolicy.Md5Generator(body["password"]);
            }
            else
            {
                return(new ApiResponse(false, -751));
            }
            ServerResponse req = await PostRequestAsync("/players/v2/register", body);

            var resp = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(req.responseMessage);

            if (req.IsSuccess)
            {
                _playerToken = resp["token"];
                resp.Remove("token");
                return(new ApiResponse(true, req.responseStatusCode, resp));
            }
            else if (resp["ecode"] == 10012)
            {
                return(new ApiResponse(false, 10012, null));
            }

            return(new ApiResponse(false, req.responseStatusCode, null));
        }
Beispiel #3
0
        /// <summary>
        /// login your player in game
        /// </summary>
        ///  <param name="playerName"> the username of your player </param>
        ///  <param name="password"> the password of your player </param>
        /// <return></return>
        public static async Task <ApiResponse> Login(string playerName, string password)
        {
            string pass = "";

            if (password == "guest")
            {
                pass = "******";
            }
            else
            {
                pass = GCPolicy.Md5Generator(password);
            }
            ServerResponse req = await GetRequestAsync("/players/v2/login/" + playerName + "/" + pass);

            var resp = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(req.responseMessage);

            if (req.IsSuccess)
            {
                _playerToken = resp["token"];
                resp.Remove("token");
                return(new ApiResponse(true, 200, resp));
            }
            else if (resp["ecode"] == 404)
            {
                return(new ApiResponse(false, 404, null));
            }
            else if (resp["ecode"] == 10090)
            {
                return(new ApiResponse(false, 10090, null));
            }
            else if (resp["ecode"] == 10091)
            {
                return(new ApiResponse(false, 10091, null));
            }
            return(new ApiResponse(false, req.responseStatusCode, null));
        }