/// <summary> /// Main login function. /// * This can be pretty much ignored, no changes are needed here. /// </summary> public bool Login(string u, string p) { cookieContainer.SetCookies(new Uri("http://age-of-aincrd.com"), "cookie_check=1;"); string[] loginParams = new string[] { u, p }; string rLoginData = string.Format("login={0}®ister=0&password={1}", loginParams); byte[] bLoginData = Encoding.UTF8.GetBytes(rLoginData); HttpWebRequest loginRequest = (HttpWebRequest)WebRequest.Create("https://age-of-aincrad.com/forum/login/login"); loginRequest.CookieContainer = cookieContainer; loginRequest.Method = "POST"; loginRequest.AllowAutoRedirect = false; loginRequest.ContentType = "application/x-www-form-urlencoded"; loginRequest.ContentLength = (long)bLoginData.Length; loginRequest.Referer = "http://age-of-aincrad.com"; loginRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"; Stream loginRequestStream = loginRequest.GetRequestStream(); loginRequestStream.Write(bLoginData, 0, bLoginData.Length); loginRequestStream.Close(); HttpWebResponse loginResponse = (HttpWebResponse)loginRequest.GetResponse(); loginRequestStream = loginResponse.GetResponseStream(); StreamReader loginRequestReader = new StreamReader(loginRequestStream); string loginRequestData = loginRequestReader.ReadToEnd(); cookieContainer.Add(loginResponse.Cookies); if (loginResponse.StatusCode == HttpStatusCode.SeeOther) { HttpWebRequest tokenRequest = (HttpWebRequest)WebRequest.Create("http://age-of-aincrad.com/forum/"); tokenRequest.CookieContainer = new CookieContainer(); tokenRequest.CookieContainer.Add(loginResponse.Cookies); loginRequestStream = tokenRequest.GetResponse().GetResponseStream(); loginRequestReader = new StreamReader(loginRequestStream); loginRequestData = loginRequestReader.ReadToEnd(); if (loginRequestData.Contains("_xfToken")) { string tokenValue = loginRequestData.Substring(loginRequestData.IndexOf("_xfToken") + 17); tokenValue = tokenValue.Split(new char[] { '"' })[0]; forumData.SetToken(tokenValue); } } loginRequestReader.Close(); loginRequestStream.Close(); loginResponse.Close(); if (forumData.GetToken() != "") { userData.SetLoginState(true); userData.SetUsername(u); userData.SetPassword(p); return(true); } return(false); }