diff --git a/RCRPlanner/FetchData.cs b/RCRPlanner/FetchData.cs index b7bbe90..397cac7 100644 --- a/RCRPlanner/FetchData.cs +++ b/RCRPlanner/FetchData.cs @@ -41,6 +41,8 @@ class FetchData //string iracingSeriesImages = "https://images-static.iracing.com/img/logos/series/"; + readonly string partnerLink = "https://api.npoint.io/6cef9bfd30441a01c8c9"; + private CookieContainer cookie = new CookieContainer(); public HttpClientHandler handler = new HttpClientHandler(); public static HttpClient client = new HttpClient(); @@ -63,9 +65,15 @@ public async Task Login_API(byte[] Email, byte[] Password, bool forcelogin) { HttpResponseMessage response; + List cookies = new List(); foreach (Cookie cookie in cookie.GetCookies(new Uri("https://iracing.com"))) { - if (cookie.Name == "authtoken_members" && cookie.Expires > DateTime.Now.AddMinutes(10) && forcelogin == false) + cookies.Add(cookie); + } + int theCookie = cookies.FindIndex(c => c.Name == "authtoken_members"); + if (theCookie != -1) + { + if (cookies[theCookie].Expires > (DateTime.Now.AddMinutes(10)) && forcelogin == false) { try { @@ -82,34 +90,37 @@ public async Task Login_API(byte[] Email, byte[] Password, bool forcelogin) } } } - if (handler.CookieContainer.Count == 0 || forcelogin) + else { - try - { - handler = new HttpClientHandler +// if (handler.CookieContainer.Count == 0 || forcelogin) +// { + try { - CookieContainer = cookie - }; - client = new HttpClient(handler); - string loginHash = EncryptPW(Email, Password); - string postBody = "{\"email\": \"" + Encoding.Default.GetString(Email) + "\",\"password\": \"" + loginHash + "\"}"; - var content = new StringContent(postBody, Encoding.UTF8, "application/json"); - - response = await client.PostAsync(iracingAuthUrl, content); - response = await client.GetAsync(iracingDataDoc); - return Convert.ToInt32(response.StatusCode); - } - catch (Exception ex) - { - if (ex.InnerException != null) + handler = new HttpClientHandler + { + CookieContainer = cookie + }; + client = new HttpClient(handler); + string loginHash = EncryptPW(Email, Password); + string postBody = "{\"email\": \"" + Encoding.Default.GetString(Email) + "\",\"password\": \"" + loginHash + "\"}"; + var content = new StringContent(postBody, Encoding.UTF8, "application/json"); + + response = await client.PostAsync(iracingAuthUrl, content); + response = await client.GetAsync(iracingDataDoc); + return Convert.ToInt32(response.StatusCode); + } + catch (Exception ex) { - MessageBox.Show("Connection:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error); + if (ex.InnerException != null) + { + MessageBox.Show("Connection:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error); + } } } - } +// } return 0; - } + public async Task getLink(string url) { var response = await client.GetAsync(url); @@ -470,5 +481,30 @@ public bool EnsureVersionCompatibility() var responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject(contents, settings); return responseObject; } + + public async Task> getPartner() + { + var response = await client.GetAsync(partnerLink); + + response.EnsureSuccessStatusCode(); + var contents = await response.Content.ReadAsStringAsync(); + var responseObject = new List(); + try + { + responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject>(contents, settings); + } + catch (Exception ex) + { + if (ex.InnerException != null) + { + MessageBox.Show("Partner download:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error); + } + else + { + MessageBox.Show("Partner download:" + ex.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error); + } + } + return responseObject; + } } } diff --git a/RCRPlanner/MainWindow.xaml b/RCRPlanner/MainWindow.xaml index fab3714..e70e81f 100644 --- a/RCRPlanner/MainWindow.xaml +++ b/RCRPlanner/MainWindow.xaml @@ -18,17 +18,17 @@ SizeChanged="Window_SizeChanged" Background="Transparent"> - - - - - - - - - - - + + + + + + + + + + + @@ -40,7 +40,6 @@ -