Skip to content

Commit 92b4021

Browse files
authored
Merge pull request #54 from Erol444/develop
Develop
2 parents 1cbcc08 + 171cc0b commit 92b4021

18 files changed

+200
-91
lines changed

.github/workflows/pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
id: Changelog
3737
run: |
3838
git branch --show-current
39-
changelog=$(git log --no-merges --pretty=format:'- %s' ${{ steps.previoustag.outputs.tag }}..HEAD)
39+
changelog=$(git log --no-merges --pretty=format:'- %s' ${{ steps.previoustag.outputs.tag }}..HEAD --reverse)
4040
changelog="${changelog//'%'/'%25'}"
4141
changelog="${changelog//$'\n'/'%0A'}"
4242
changelog="${changelog//$'\r'/'%0D'}"

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: |
4040
git branch --show-current
4141
last=$(git log --merges --grep='develop' --first-parent master --pretty=format:"%h" | sed -n '2p')
42-
changelog=$(git log --no-merges --pretty=format:'- %s' $last..HEAD)
42+
changelog=$(git log --no-merges --pretty=format:'- %s' $last..HEAD --reverse)
4343
changelog="${changelog//'%'/'%25'}"
4444
changelog="${changelog//$'\n'/'%0A'}"
4545
changelog="${changelog//$'\r'/'%0D'}"
@@ -130,7 +130,7 @@ jobs:
130130
nodetail: retrue
131131
description: |
132132
Version `TBS-${{needs.version.outputs.version}}`
133-
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{steps.tag.outputs.tag}}) to download!
133+
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download!
134134
**Changelog**:
135135
${{needs.version.outputs.changelog}}
136136
Clear:

TbsCore/Core/WebBrowserInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void SetupChromeDriver(Access.Access access, string username, string ser
9191
options.AddArgument("ignore-certificate-errors"); // --ignore-certificate-errors ?
9292
}
9393

94-
options.AddArgument($"--user-agent={access.UserAgent}");
94+
//options.AddArgument($"--user-agent={access.UserAgent}");
9595

9696
//options.AddArguments("--disable-logging");
9797
//options.AddArguments("--disable-metrics");

TbsCore/Helpers/AccountHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static int Delay(Account acc)
5353
{
5454
//Return random delay
5555
Random rnd = new Random();
56-
return acc.Settings.DelayClicking + rnd.Next(-500, 500);
56+
return rnd.Next(acc.Settings.DelayClickingMin, acc.Settings.DelayClickingMax);
5757
}
5858

5959
public static void StartAccountTasks(Account acc)

TbsCore/Helpers/HttpHelper.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using Newtonsoft.Json;
2-
using RestSharp;
1+
using RestSharp;
32
using System;
43
using System.Net;
5-
using TbsCore.Helpers;
64
using TbsCore.Models.Access;
75
using TbsCore.Models.AccModels;
8-
using TbsCore.Models.MapModels;
9-
using TbsCore.Models.VillageModels;
106

117
namespace TbsCore.Helpers
128
{
@@ -62,7 +58,7 @@ public static HtmlAgilityPack.HtmlDocument SendGetReq(Account acc, string url)
6258
public static void InitRestClient(Access access, RestClient client)
6359
{
6460
client.Timeout = 5000;
65-
client.UserAgent = access.UserAgent;
61+
//client.UserAgent = access.UserAgent;
6662

6763
// Set proxy
6864
if (!string.IsNullOrEmpty(access.Proxy))

TbsCore/Helpers/UpdateAccountObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class UpdateAccountObject
1414
{
1515
public static bool UpdateVillages(HtmlAgilityPack.HtmlDocument htmlDoc, Account acc)
1616
{
17-
List<VillageChecked> foundVills = RightBarParser.GetVillages(htmlDoc);
17+
List<VillageChecked> foundVills = RightBarParser.GetVillages(htmlDoc, acc.AccInfo.ServerVersion);
1818
if (foundVills.Count == 0) return false; //some problem in GetVillages function!
1919

2020
for (int i = 0; i < acc.Villages.Count; i++)

TbsCore/Helpers/VillageHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static async Task SwitchVillage(Account acc, int id)
8686
// Parse village list again and find correct href
8787
Uri uri = new Uri(acc.Wb.CurrentUrl);
8888

89-
var vills = RightBarParser.GetVillages(acc.Wb.Html);
89+
var vills = RightBarParser.GetVillages(acc.Wb.Html, acc.AccInfo.ServerVersion);
9090
var href = vills.FirstOrDefault(x => x.Id == id)?.Href;
9191

9292
if (string.IsNullOrEmpty(href)) // Login screen, server messages etc.

TbsCore/Models/Settings/GeneralSettings.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public void Init()
2626
DonateAbove = 95;
2727
DonateExcessOf = 65;
2828
DiscordWebhook = false;
29-
DelayClicking = 3000;
29+
DelayClickingMin = 2500;
30+
DelayClickingMax = 3800;
3031
}
3132

3233
public bool AutoActivateProductionBoost { get; set; }
@@ -134,9 +135,14 @@ public void Init()
134135
public bool DiscordOnlineAnnouncement { get; set; }
135136

136137
/// <summary>
137-
/// How long should bot click between 2 click ( bot will +- 500ms for random )
138+
/// Minimum time between 2 click
138139
/// </summary>
139-
public int DelayClicking { get; set; }
140+
public int DelayClickingMin { get; set; }
141+
142+
/// <summary>
143+
/// Maximum time between 2 click
144+
/// </summary>
145+
public int DelayClickingMax { get; set; }
140146
}
141147

142148
/// <summary>

TbsCore/Parsers/RightBarParser.cs

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using TbsCore.Models.MapModels;
55
using TbsCore.Models.SideBarModels;
66
using TbsCore.Helpers;
7+
using static TbsCore.Helpers.Classificator;
78

89
namespace TbsCore.Parsers
910
{
@@ -37,48 +38,71 @@ public static CulturePoints GetCulturePoints(HtmlAgilityPack.HtmlDocument htmlDo
3738
};
3839
}
3940

40-
public static List<VillageChecked> GetVillages(HtmlAgilityPack.HtmlDocument htmlDoc)
41+
public static List<VillageChecked> GetVillages(HtmlAgilityPack.HtmlDocument htmlDoc, ServerVersionEnum serverVersion)
4142
{
4243
List<VillageChecked> ret = new List<VillageChecked>();
4344

44-
try
45+
var villsNode = htmlDoc.GetElementbyId("sidebarBoxVillagelist");
46+
if (villsNode == null) return ret;
47+
List<HtmlAgilityPack.HtmlNode> vills = null;
48+
switch (serverVersion)
4549
{
46-
var villsNode = htmlDoc.GetElementbyId("sidebarBoxVillagelist");
47-
if (villsNode == null) return ret;
48-
49-
var vills = villsNode.Descendants("li").ToList();
50-
foreach (var node in vills)
51-
{
52-
bool underAttack = false, active = false;
50+
case ServerVersionEnum.T4_4:
51+
{
52+
vills = villsNode.Descendants("li").ToList();
53+
break;
54+
}
55+
case ServerVersionEnum.T4_5:
56+
{
57+
vills = villsNode.Descendants("div").Where(x => x.HasClass("listEntry")).ToList();
58+
break;
59+
}
60+
}
5361

54-
if (node.HasClass("attack"))
55-
underAttack = true;
56-
if (node.HasClass("active"))
57-
active = true;
62+
if (vills == null) return ret;
5863

59-
var href = System.Net.WebUtility.HtmlDecode(node.ChildNodes.First(x => x.Name == "a").GetAttributeValue("href", ""));
64+
foreach (var node in vills)
65+
{
66+
bool underAttack = false, active = false;
6067

61-
var villId = Convert.ToInt32(href.Split('=')[1].Split('&')[0]);
68+
if (node.HasClass("attack"))
69+
underAttack = true;
70+
if (node.HasClass("active"))
71+
active = true;
6272

63-
var villName = node.Descendants().FirstOrDefault(x => x.HasClass("name")).InnerText;
64-
var coords = new Coordinates()
65-
{
66-
x = (int)Parser.ParseNum(node.Descendants("span").FirstOrDefault(x => x.HasClass("coordinateX")).InnerText.Replace("(", "")),
67-
y = (int)Parser.ParseNum(node.Descendants("span").FirstOrDefault(x => x.HasClass("coordinateY")).InnerText.Replace(")", ""))
68-
};
73+
var href = System.Net.WebUtility.HtmlDecode(node.ChildNodes.FirstOrDefault(x => x.Name == "a").GetAttributeValue("href", ""));
74+
var villId = Convert.ToInt32(href.Split('=')[1].Split('&')[0]);
75+
var villName = node.Descendants("a").FirstOrDefault().InnerText.Replace(" ", "").Replace("\r\n", "");
6976

70-
ret.Add(new VillageChecked()
71-
{
72-
Id = villId,
73-
UnderAttack = underAttack,
74-
Name = villName,
75-
Coordinates = coords,
76-
Active = active,
77-
Href = href,
78-
});
77+
var x_node = node.Descendants("span").FirstOrDefault(x => x.HasClass("coordinateX"));
78+
int x_coord = 0;
79+
if (x_node != null)
80+
{
81+
x_coord = (int)Parser.ParseNum(x_node.InnerText.Replace("(", ""));
82+
}
83+
var y_node = node.Descendants("span").FirstOrDefault(x => x.HasClass("coordinateY"));
84+
int y_coord = 0;
85+
if (y_node != null)
86+
{
87+
y_coord = (int)Parser.ParseNum(y_node.InnerText.Replace(")", ""));
7988
}
89+
var coords = new Coordinates()
90+
{
91+
x = x_coord,
92+
y = y_coord,
93+
};
94+
95+
ret.Add(new VillageChecked()
96+
{
97+
Id = villId,
98+
UnderAttack = underAttack,
99+
Name = villName,
100+
Coordinates = coords,
101+
Active = active,
102+
Href = href,
103+
});
80104
}
81-
catch (Exception e) { Console.WriteLine("error " + e.Message); }
105+
82106
return ret;
83107
}
84108

TbsCore/TbsCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageReference Include="RandomUserAgent" Version="1.1.2" />
2424
<PackageReference Include="RestSharp" Version="106.12.0" />
2525
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
26-
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="91.0.4472.10100" />
26+
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="95.0.4638.1700" />
2727
<PackageReference Include="Serilog" Version="2.10.0" />
2828
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
2929
<PackageReference Include="Serilog.Sinks.Map" Version="1.0.2" />

0 commit comments

Comments
 (0)