private static string GetPlaceHtml(RequestManager reqManager, int village) { string url = $"https://sv36.tribalwars.se/game.php?village={village}&screen=place"; var res = reqManager.SendGETRequest(url, null, null, false); return(RequestManager.GetResponseStringFromResponse(res)); }
private static CQ GetHtml(RequestManager requestManager, int from, int village) { var url = $"https://sv36.tribalwars.se/game.php?village={village}&screen=report&mode=attack&from={from}"; var res = requestManager.SendGETRequest(url, null, null, false); var html = RequestManager.GetResponseStringFromResponse(res); return(html); }
private CQ GetReportHtml(RequestManager requestManager, int village, int reportItemId) { var url = $"{Constants.BaseUrl}village={village}&screen=report&mode=all&group_id=-1&view={reportItemId}"; var res = requestManager.SendGETRequest(url, null, null, false); var resStr = RequestManager.GetResponseStringFromResponse(res); return(resStr); }
private CQ GetHtmlForPage() { var req = _requestManager.GenerateGETRequest(Url, null, null, false); var res = _requestManager.GetResponse(req); CQ html = RequestManager.GetResponseStringFromResponse(res); return(html); }
private CQ GetHeadQScreenHtml() { var url = "https://sv36.tribalwars.se/game.php?village=2145&screen=main"; var req = _reqManager.GenerateGETRequest(url, null, null, true); var res = _reqManager.GetResponse(req); return(RequestManager.GetResponseStringFromResponse(res)); }
public bool CancelOrderFromActiveQueue(RequestManager reqManager, int orderNr, string token, int village) { var url = $"https://sv36.tribalwars.se/game.php?village={village}&screen=train&ajaxaction=cancel&h={token}"; var postData = $"id={orderNr}"; var res = reqManager.SendPOSTRequest(url, postData, null, null, true); var jsonRes = RequestManager.GetResponseStringFromResponse(res); return(jsonRes.Contains("success:true")); }
private CQ SetFilters(string token) { var url = "https://sv36.tribalwars.se/game.php?village=2145&screen=event_crest&action=set_filters&h=" + token; var postData = "filter%5Bhide_friends%5D=on&filter%5Bhide_crestless%5D=on"; var req = _requestManager.GeneratePOSTRequest(url, postData, null, null, true); var res = _requestManager.GetResponse(req); CQ html = RequestManager.GetResponseStringFromResponse(res); return(html); }
private static List <UnitQueueItem> GetActiveQueue(RequestManager reqManager, int village, BuildingTypes building) { var typeStr = BuildingHelper.GetNameForType(building); var url = $"https://sv36.tribalwars.se/game.php?village={village}&screen={typeStr}"; var res = reqManager.SendGETRequest(url, null, null, true); CQ htmlString = RequestManager.GetResponseStringFromResponse(res); var list = htmlString .Select($"#trainqueue_wrap_{typeStr} tbody tr") .Where(ele => ele.ClassName.Length > 0) .Select(ele => GetUnitQueueItem(ele, typeStr)); return(list.ToList()); }
public RootObject GetPlayerAndCurrentVillageInfo(RequestCache requestCache) { string url = $"{Constants.BaseUrl}screen=overview"; var res = requestCache.Manager.SendGETRequest(url, null, null, true); var htmlString = RequestManager.GetResponseStringFromResponse(res); var indexStart = htmlString.IndexOf("TribalWars.updateGameData({", StringComparison.Ordinal); var indexEnd = htmlString.IndexOf("});", indexStart, StringComparison.Ordinal); var jsonText = htmlString.SubstringBetween(indexStart + "TribalWars.updateGameData(".Length, indexEnd + 1); var rootObject = JsonConvert.DeserializeObject <RootObject>(jsonText); return(rootObject); }
public bool AddBuildingUppgradeToActiveQeueu(BuildingTypes building, string csrfToken, int currentVillage) { var uppgradeUrl = UpgradeBuildingUrl .Replace("__village__", currentVillage.ToString()) .Replace("__type__", "main") .Replace("__csrfToken__", csrfToken); var url = $"{BaseUrl}{uppgradeUrl}"; var postData = $"id={BuildingHelper.GetNameForType(building)}&force=1&destroy=0&source={currentVillage}"; var resNotParsed = _reqManager.GeneratePOSTRequest(url, postData, null, null, true); var res = _reqManager.GetResponse(resNotParsed); var htmlStr = RequestManager.GetResponseStringFromResponse(res); return(htmlStr.Contains("Byggnationen har beordrats")); }
public bool CancelBuildingUpgradeFromActiveQueue(string id, string csrfToken, int currentVillage) { var cancelOrderUrl = CancelOrderUrl .Replace("__village__", currentVillage.ToString()) .Replace("__type__", "main") .Replace("__csrfToken__", csrfToken); var url = $"{BaseUrl}{cancelOrderUrl}"; var postData = $"id={id}&destroy=0"; var resNotParsed = _reqManager.GeneratePOSTRequest(url, postData, null, null, true); var res = _reqManager.GetResponse(resNotParsed); var html = RequestManager.GetResponseStringFromResponse(res); return(html.Contains("success\":true")); }
private bool LoginToTw() { string postData = $"user={_user.Name}&password={_user.Password}&cookie=true&clear=true"; const string url = "https://www.tribalwars.se/index.php?action=login&show_server_selection=1"; var loginReq = Manager.GeneratePOSTRequest(url, postData, null, null, true); var loginRes = Manager.GetResponse(loginReq); var responseStr = RequestManager.GetResponseStringFromResponse(loginRes); if (responseStr.Contains("error")) { throw new Exception($"error login to tw {responseStr}"); } return(loginRes.StatusCode == HttpStatusCode.OK); }
public bool AddOrderToActiveQueue(RequestManager reqManager, Dictionary <Units, int> units, string token, int village) { var url = $"https://sv36.tribalwars.se/game.php?village={village}&screen=train&ajaxaction=train&mode=train&h={token}"; var postData = ""; foreach (var unitKeyPair in units) { var unitName = UnitHelper.GetNameForType(unitKeyPair.Key); postData += $"units%5B{unitName}%5D={unitKeyPair.Value}&"; } var res = reqManager.SendPOSTRequest(url, postData, null, null, true); var jsonRes = RequestManager.GetResponseStringFromResponse(res); return(jsonRes.Contains("success:true")); }
public void GetMapForGrid(int x, int y) { var url = $"https://sv36.tribalwars.se/map.php?v=2&{x}_{y}=1"; var req = _requestManager.GenerateGETRequest(url, null, null, false); var res = _requestManager.GetResponse(req); var json = RequestManager.GetResponseStringFromResponse(res); json = json.SubstringBetween(1, json.Length - 1); dynamic dynamicJsonTest = JObject.Parse(json); string str = dynamicJsonTest.data.villages.ToString(); var jsondata = JObject.Parse(str); var listOfVillages = new List <MapVillage>(); foreach (JProperty jsonElement in jsondata.Properties()) { Console.WriteLine("Json key " + jsonElement.Name + " artist: "); Console.WriteLine(jsonElement.Name); foreach (var nested in JObject.Parse(jsonElement.Value.ToString()).Properties()) { var village = new MapVillage { VillageId = (int)nested.Value[0], DontKnow = (int)nested.Value[1], VillageName = (string)nested.Value[2], VillagePoints = (string)nested.Value[3], DontKnow2 = (int)nested.Value[4], NullObject = null, Something = (string)nested.Value[6], StirngThatIsZero = (string)nested.Value[7] }; listOfVillages.Add(village); } } Console.WriteLine(listOfVillages); Environment.Exit(0); }
private string SendAttackInit(RequestManager requestManager, PlanedAttack planedAttack, int villageNr) { var url = $"https://sv36.tribalwars.se/game.php?village={villageNr}&screen=place&try=confirm"; var postData = "22c2d931d74cd8a06d92b4=e6c57ef722c2d9" + "&template_id=" + $"&source_village={villageNr}" + $"&{UnitHelper.GetUnitQueryStringFromUnitDict(planedAttack.Units)}" + $"&x={planedAttack.EnemyVillageXCord}" + $"&y={planedAttack.EnemyVillageYCord}" + "&target_type=coord" + "&input=&attack=Attack"; var req = requestManager.GeneratePOSTRequest(url, postData, null, null, true); var res = requestManager.GetResponse(req); var str = RequestManager.GetResponseStringFromResponse(res); CQ html = str; var formElement = html.Select("#command-data-form"); var inputs = formElement.Children("input").Where(ele => ele.Type == "hidden").ToList(); var queryString = inputs.Aggregate("", (current, input) => current + $"{input.Name}={input.Value}&"); return(queryString); }
private void SendAttackConfirm(RequestManager requestManager, string postData, string token, int village) { var url = $"https://sv36.tribalwars.se/game.php?village={village}&screen=place&action=command&h={token}"; var res = requestManager.SendPOSTRequest(url, postData, null, null, true); var htmlResponse = RequestManager.GetResponseStringFromResponse(res); }