コード例 #1
0
ファイル: UnitService.cs プロジェクト: Zexuz/TribalWarsBot
        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));
        }
コード例 #2
0
ファイル: ReportService.cs プロジェクト: Zexuz/TribalWarsBot
        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);
        }
コード例 #3
0
ファイル: ReportService.cs プロジェクト: Zexuz/TribalWarsBot
        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);
        }
コード例 #4
0
        private CQ GetHtmlForPage()
        {
            var req  = _requestManager.GenerateGETRequest(Url, null, null, false);
            var res  = _requestManager.GetResponse(req);
            CQ  html = RequestManager.GetResponseStringFromResponse(res);

            return(html);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: UnitService.cs プロジェクト: Zexuz/TribalWarsBot
        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"));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: UnitService.cs プロジェクト: Zexuz/TribalWarsBot
        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());
        }
コード例 #9
0
ファイル: PlayerService.cs プロジェクト: Zexuz/TribalWarsBot
        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);
        }
コード例 #10
0
        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"));
        }
コード例 #11
0
        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"));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
ファイル: UnitService.cs プロジェクト: Zexuz/TribalWarsBot
        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"));
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: AttackService.cs プロジェクト: Zexuz/TribalWarsBot
        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);
        }
コード例 #16
0
ファイル: AttackService.cs プロジェクト: Zexuz/TribalWarsBot
 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);
 }