Ejemplo n.º 1
0
        /// <summary>
        /// This method uses a service from Cloudflare to obtain user's country and state.
        /// For more information you can read the summary of the Privacy Policy of this application: https://clemenskoprolin.com/lightparty/legal/
        /// And the Privacy Policy of Cloudflare: https://www.cloudflare.com/privacypolicy/
        /// </summary>
        /// <returns>A array of strings. The fist value is the user's state, the second is the user's country.</returns>
        public static async Task <string[]> GetUserLocation()
        {
            string state   = "";
            string country = "";

            string locationServiceData = await InternetRequests.SendGetRequest(locationServiceURL);

            if (locationServiceData != "null")
            {
                using (System.IO.StringReader reader = new System.IO.StringReader(locationServiceData))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.Contains("colo"))
                        {
                            state = line.Split("=")[1];
                        }

                        if (line.Contains("loc"))
                        {
                            country = line.Split("=")[1];
                        }
                    }
                }
            }

            string[] location = { state, country };
            return(location);
        }