public static UnovaSession Create(string username, string password) { var us = new UnovaSession(); //initialize cookies //_web.DownloadString(Urls.UrlBase); us.Web.DownloadString(Urls.UrlLogin); //submit login request byte[] resp = us.Web.UploadValues(Urls.UrlLoginAction, new NameValueCollection { { "unovarpg", us.CSRFToken }, { "username", username }, { "password", password } }); string respS = Encoding.UTF8.GetString(resp); return(!respS.Contains("validateLogin") ? us : null); }
internal static UnovaBattle FromHtml(UnovaSession sess, string html, int?pokeId = null, int?level = null, int?mapId = null, long?tid = null) { var ub = new UnovaBattle(); ub._sess = sess; ub.PokeId = pokeId; ub.Level = level; ub._mapId = mapId; if (tid != null) { ub._tid = tid; } //get tokens string fParams = RegexToken.Match(html).Groups[1].Value; ub._type = fParams.Split(',')[2].Trim('\'', ' '); ub._token = fParams.Split(',').Last().Trim('\'', ' '); ub._runToken = RegexRunToken.Match(html).Groups[1].Value; return(ub); }