-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginInfo.cs
190 lines (165 loc) · 7.43 KB
/
PluginInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using GeniePlugin.Interfaces;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
namespace SimuCoins
{
public class PluginInfo : IPlugin
{
private static IHost? coin;
private MainForm? form;
private NoGUI? noForm;
private static readonly HttpClient httpClient = new();
private static readonly HttpClientHandler httpClientHandler = new() { CookieContainer = new() };
private static string _pagecontent = string.Empty;
private static string _token = string.Empty;
internal const string BalanceUrl = "https://store.play.net/store/purchase/dr";
internal const string ClaimUrl = "https://store.play.net/Store/ClaimReward";
internal const string LoginUrl = "https://store.play.net/Account/SignIn?returnURL=%2FAccount%2FSignIn";
internal const string SignOutUrl = "https://store.play.net/Account/SignOut";
internal const string StoreUrl = "https://store.play.net/";
internal const string BalancePattern = "<h1 class=\"balance centered sans_serif\">You Have <span class=\"blue\">(\\d+)</span><img src=\"https://www.play.net/images/layout/store/icons/sc_icon_28_w.png\">!</h1>";
internal const string ClaimPattern = "<h1 class=\"RewardMessage centered sans_serif\">Subscription Reward: (\\d+) Free SimuCoins</h1>";
internal const string NamePattern = "<div\\s+class=\"login\\s+sans_serif\">\\s*(\\S+)\\s+|\\s+<a\\s+href=\"/Account/SignOut\">SIGN OUT</a>\\s*</div>";
internal const string TimePattern = "<h1 class=\"RewardMessage centered sans_serif\">(.*?)</h1>";
public bool Enabled { get; set; } = true;
public static IHost? Coin { get => coin; set => coin = value; }
public string Name => "SimuCoins";
public string Version => "2.1.2";
public string Description => "Log into SimuCoins store to check current coins, time left and auto claim coins when available";
public string Author => "Thires <Thiresdr@gmail.com>";
public async void Initialize(IHost host)
{
coin = host;
noForm = new NoGUI();
await InitializeAsync();
}
private static async Task InitializeAsync()
{
await LoadPage();
}
internal static string PageContent
{
get => _pagecontent;
set => _pagecontent = value;
}
internal static string Token
{
get => _token;
set => _token = value;
}
private async static Task LoadPage()
{
try
{
HttpResponseMessage response = await httpClient.GetAsync(LoginUrl);
PageContent = await response.Content.ReadAsStringAsync();
Token = Regex.Match(PageContent, "<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"(.*?)\" />").Groups[1].Value;
}
catch (HttpRequestException ex)
{
// Handle HTTP request exception
Coin?.EchoText($"HTTP request failed: {ex.Message}");
}
catch (TaskCanceledException ex) when (ex.InnerException is TimeoutException)
{
// Handle timeout exception
PluginInfo.Coin?.EchoText($"The request timed out: {ex.Message}");
}
catch (SocketException ex) when (ex.ErrorCode == 995)
{
// Handle the specific "SocketException (995)" error
Coin?.EchoText($"SocketException (995): The I/O operation was aborted: {ex.Message}");
}
catch (Exception ex)
{
// Handle other exceptions
Coin?.EchoText($"An error occurred with store.play.net: {ex.Message}");
}
}
public void Show()
{
if (form == null || form.IsDisposed)
{
form = new MainForm();
}
form.Show();
}
public void VariableChanged(string variable)
{
}
public string ParseText(string text, string window)
{
return text;
}
public string? ParseInput(string text)
{
if (Regex.IsMatch(text, @"^/(sct|sctext|sc|simucoins|scall|sca)(\shelp)$|^/simucoins($|\s)|^/sc($|\s)|^/sct($|\s)|^/sctext($|\s)|^/scall($|\s)|^/sca($|\s)", RegexOptions.IgnoreCase))
{
_ = ParseInputAsync(text);
return "";
}
return text;
}
public async Task ParseInputAsync(string text)
{
if (Regex.IsMatch(text, @"^/(sct|sctext|sc|simucoins|scall|sca)(\shelp)$", RegexOptions.IgnoreCase))
{
Coin?.EchoText("\r\nUse the GUI to enter accounts that will be saved with successful logins.\r\nAll methods will claim coins if they are available.\r\nCommands for Simucoins:\r\n/sc or /simucoins will open the GUI.\r\n/sc or /simucoins <username> <password> logs in using the GUI.\r\n/sct or /sctext <username> <password> displays text version.\r\n/sca or /scall will display text and log into each account that is saved within the xml.\r\n\r\n#trigger {^Welcome to DragonRealms \\(\\w+\\) v\\d+\\.\\d+$} {#put /sca}\r\n#trigger save\r\n");
}
else if (Regex.IsMatch(text, @"^/sct($|\s)|^/sctext($|\s)", RegexOptions.IgnoreCase))
{
var arguments = text.Split(' ');
if (arguments.Length == 3)
noForm?.NoGUILogin(arguments[1], arguments[2]);
else
Coin?.EchoText("Usage: /sct <username> <password> or /sctext <username> <password>");
}
else if (Regex.IsMatch(text, @"^/simucoins($|\s)|^/sc($|\s)", RegexOptions.IgnoreCase))
{
Show();
var arguments = text.Split(' ');
if (arguments.Length == 1) { }
else if (arguments.Length == 3)
{
if (form != null)
{
form.UserName = arguments[1];
form.Password = arguments[2];
await form.GUILogin();
}
}
else
{
Coin?.EchoText("Usage: /simucoins or /sc <username> <password>");
}
}
else if (Regex.IsMatch(text, @"^/scall($|\s)|^/sca($|\s)", RegexOptions.IgnoreCase))
{
noForm?.DoAll();
}
}
internal static async Task SignOut()
{
string url = PluginInfo.SignOutUrl;
try
{
using var httpClient = new HttpClient(new HttpClientHandler { CookieContainer = new CookieContainer() });
var response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
httpClientHandler.Dispose();
}
catch (HttpRequestException ex)
{
Coin?.EchoText($"SignOut: {ex.Message}");
}
}
public void ParseXML(string xml)
{
}
public void ParentClosing()
{
}
}
}