using System; using System.IO; using System.Net; using System.Text; namespace WOCBOT_3 { public static class Web { private static CookieContainer loginCookies; private static CookieCollection cookie; private static string loginURL; static Web() { Web.loginCookies = new CookieContainer(); Web.cookie = new CookieCollection(); Web.loginURL = "http://www.warofclicks.com/User/Login"; } public static void downloadFile(string url, string path) { try { (new WebClient()).DownloadFile(url, path); } catch (Exception exception) { App.writeLog(string.Concat("(ERROR) Unable to download file : ", exception.ToString())); } } public static void getCookies(string url = "https://www.warofclicks.com") { try { HttpWebRequest cookieContainer = (HttpWebRequest)WebRequest.Create(url); cookieContainer.CookieContainer = new CookieContainer(); cookieContainer.CookieContainer.Add(Web.cookie); Web.cookie = ((HttpWebResponse)cookieContainer.GetResponse()).Cookies; Web.loginCookies.Add(Web.cookie); } catch (Exception exception1) { Exception exception = exception1; App.writeLog(string.Concat("(ERROR) Unable to get cookies from ", url, " : ", exception.ToString())); } } public static string getPage(string url) { string end; try { HttpWebRequest cookieContainer = (HttpWebRequest)WebRequest.Create(url); cookieContainer.CookieContainer = new CookieContainer(); cookieContainer.CookieContainer = Web.loginCookies; HttpWebResponse response = (HttpWebResponse)cookieContainer.GetResponse(); Web.loginCookies.Add(response.Cookies); using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { end = streamReader.ReadToEnd(); } } catch (Exception exception1) { Exception exception = exception1; App.writeLog(string.Concat("(ERROR) Unable to get page ", url, " : ", exception.ToString())); end = null; } return end; } public static string login(string email, string password) { string end; Web.getCookies("https://www.warofclicks.com"); try { string str = string.Format("ReturnUrl=%2F&Email={0}&Password={1}&RememberMe=true&RememberMe=false", email, password); HttpWebRequest cookieContainer = (HttpWebRequest)WebRequest.Create(Web.loginURL); cookieContainer.CookieContainer = new CookieContainer(); cookieContainer.CookieContainer.Add(Web.cookie); cookieContainer.Method = "POST"; cookieContainer.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; cookieContainer.AllowWriteStreamBuffering = true; cookieContainer.KeepAlive = true; cookieContainer.Host = "www.warofclicks.com"; cookieContainer.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; cookieContainer.Referer = "http://www.warofclicks.com/"; cookieContainer.ProtocolVersion = HttpVersion.Version11; cookieContainer.AllowAutoRedirect = true; cookieContainer.ContentType = "application/x-www-form-urlencoded"; byte[] bytes = Encoding.ASCII.GetBytes(str); cookieContainer.ContentLength = (long)((int)bytes.Length); Stream requestStream = cookieContainer.GetRequestStream(); requestStream.Write(bytes, 0, (int)bytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)cookieContainer.GetResponse(); Web.loginCookies = cookieContainer.CookieContainer; using (StreamReader streamReader = new StreamReader(response.GetResponseStream())) { end = streamReader.ReadToEnd(); } } catch (Exception exception) { App.writeLog(string.Concat("(ERROR) Unable to login : ", exception.ToString())); end = null; } return end; } public static string postCaptcha(string currentLink, string captchaID, string ADV) { string end; try { byte[] bytes = Encoding.UTF8.GetBytes(string.Concat(new string[] { "{\"img\":\"", captchaID, "\",\"adv\":\"", ADV, "\"}" })); HttpWebRequest length = (HttpWebRequest)WebRequest.Create("http://www.warofclicks.com/Security/CheckSecurityImage"); length.CookieContainer = Web.loginCookies; length.Method = "POST"; length.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; length.AllowWriteStreamBuffering = true; length.KeepAlive = true; length.Host = "www.warofclicks.com"; length.Accept = "application/json, text/javascript, */*; q=0.01"; length.Referer = currentLink; length.ContentType = "application/json; charset=UTF-8"; length.ContentLength = (long)((int)bytes.Length); Stream requestStream = length.GetRequestStream(); requestStream.Write(bytes, 0, (int)bytes.Length); requestStream.Close(); using (StreamReader streamReader = new StreamReader(((HttpWebResponse)length.GetResponse()).GetResponseStream())) { end = streamReader.ReadToEnd(); } } catch (Exception exception) { App.writeLog(string.Concat("(ERROR) Unable to post captcha : ", exception.ToString())); end = Web.postCaptcha(currentLink, captchaID, ADV); } return end; } public static string postData(string url, string data, params object[] args) { string end; try { string str = string.Format(data, args); HttpWebRequest version11 = (HttpWebRequest)WebRequest.Create(url); version11.CookieContainer = Web.loginCookies; version11.Method = "POST"; version11.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; version11.AllowWriteStreamBuffering = true; version11.KeepAlive = true; version11.Host = "www.warofclicks.com"; version11.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; version11.Referer = url; version11.ProtocolVersion = HttpVersion.Version11; version11.AllowAutoRedirect = true; version11.ContentType = "application/x-www-form-urlencoded"; byte[] bytes = Encoding.ASCII.GetBytes(str); version11.ContentLength = (long)((int)bytes.Length); Stream requestStream = version11.GetRequestStream(); requestStream.Write(bytes, 0, (int)bytes.Length); requestStream.Close(); using (StreamReader streamReader = new StreamReader(((HttpWebResponse)version11.GetResponse()).GetResponseStream())) { end = streamReader.ReadToEnd(); } } catch (Exception exception1) { Exception exception = exception1; App.writeLog(string.Concat("(ERROR) Can't connect to ", url, " : ", exception.ToString())); end = null; } return end; } } }