-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
459 lines (379 loc) · 14.8 KB
/
Form1.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using DEBoarded;
using Newtonsoft.Json;
namespace DEBoard
{
public partial class Form1 : KryptonForm
{
public int _lgtimeOUT = 5000;
public bool netCHECK = true;
public Form1()
{
InitializeComponent();
this.Size = new Size((this.Width - kryptonDataGridView1.Width) + kryptonDataGridView1.Width, this.Height);
timer1.Start();
timer2.Start();
}
public int pageBEGIN = 1;
public async Task<string> DownloadStringAsync(Uri uri, int timeOut = 60000)
{
string output = null;
bool cancelledOrError = false;
using (var client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
client.Proxy = null;
client.DownloadStringCompleted += (sender, e) =>
{
if (e.Error != null || e.Cancelled)
{
cancelledOrError = true;
}
else
{
output = e.Result;
}
};
client.DownloadStringAsync(uri);
var n = DateTime.Now;
while (output == null && !cancelledOrError && DateTime.Now.Subtract(n).TotalMilliseconds < timeOut)
{
await Task.Delay(100); // wait for respsonse
}
}
return await Task.FromResult(output);
}
public static bool CheckForInternetConnection()
{
try
{
using (var client = new WebClient())
using (client.OpenRead("http://google.com/generate_204"))
return true;
}
catch
{
return false;
}
}
public static string GetTypeLadder(string num)
{
switch (num)
{
case "0":
return "Random Map";
case "1":
return "Regicide";
case "2":
return "Deathmatch";
case "13":
return "Empire Wars";
default:
return "Custom";
}
}
public string _playerPROFILES(DEBoarded.Player[] list)
{
foreach (var pl in list)
{
if (pl != null)
{
return pl.Name;
}
}
return "";
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.BackColor = ColorTranslator.FromHtml("#717171");
richTextBox1.SelectedRtf = DEBoarded.Properties.Resources.Readme;
}
private void kryptonDataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void kryptonDataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
}
private void kryptonDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (kryptonDataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null && kryptonDataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Join")
{
//MessageBox.Show(kryptonDataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString());
Process.Start("explorer.exe", kryptonDataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString());
}
}
private void Lobbies_ParentChanged(object sender, EventArgs e)
{
}
private void Lobbies_Click(object sender, EventArgs e)
{
this.Size = new Size((this.Width - kryptonDataGridView1.Width) + kryptonDataGridView1.Width, this.Height);
}
private void Lobbies_Initialized(object sender, EventArgs e)
{
this.Size = new Size((this.Width - kryptonDataGridView1.Width) + kryptonDataGridView1.Width, this.Height);
}
private void kryptonPage2_Click(object sender, EventArgs e)
{
}
private void kryptonPage2_Load(object sender, EventArgs e)
{
}
private void kryptonPage2_Enter(object sender, EventArgs e)
{
}
public static string streaker(long streak)
{
if (streak > 0)
return @"+" + streak;
else
return streak.ToString();
}
public async Task FetchLeaderboard(int page)
{
kryptonDataGridView2.Rows.Clear();
Uri apiLOB = new Uri(@"https://aoe2.net/api/leaderboard?game=aoe2de&leaderboard_id=3&start=" + page + "&count=10");
string jsonLOBBIES = await DownloadStringAsync(apiLOB);
//MessageBox.Show(jsonLOBBIES.Substring(0, 8));
var ldb = LeaderBoard.FromJson(jsonLOBBIES);
int i = 1;
foreach (var l in ldb.Leaderboard)
{
i++;
LinkLabel ln = new LinkLabel();
Button btn = new Button();
ln.Text = "View";
ln.Name = "view" + i.ToString();
btn.Name = "btn" + i.ToString();
btn.Text = "Join";
kryptonDataGridView2.Rows.Add(l.Rank, l.Rating, l.Name, l.Games, streaker(l.Streak), l.Wins, l.Drops + @"%", "View", @"https://www.ageofempires.com/stats/?profileId=" + l.ProfileId + @"&game=age2");
}
}
private async void kryptonPage2_EnabledChanged(object sender, EventArgs e)
{
await FetchLeaderboard(1);
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
}
private async void trackBar1_ValueChanged(object sender, EventArgs e)
{
try
{
kryptonDataGridView2.DataSource = null;
await Task.Delay(1000);
//await FetchLeaderboard(trackBar1.Value * 10);
}
catch (SystemException)
{
}
}
private string filterPage = String.Empty;
private async void kryptonTextBox1_TextChanged(object sender, EventArgs e)
{
await Task.Delay(200);
if(filterPage != kryptonTextBox1.Text)
{
filterPage = kryptonTextBox1.Text;
int n;
if (int.TryParse(kryptonTextBox1.Text, out n))
{
await FetchLeaderboard(Int32.Parse(kryptonTextBox1.Text));
}
else
{
MessageBox.Show("Please Enter a number!");
}
}
}
private async void nextPAGE_Click(object sender, EventArgs e)
{
await Task.Delay(100);
int n;
if (int.TryParse(kryptonTextBox1.Text, out n))
if (Int32.Parse(kryptonTextBox1.Text) >= 10)
{
kryptonDataGridView2.Rows.Clear();
kryptonTextBox1.Text = (Int32.Parse(kryptonTextBox1.Text) + 10).ToString();
}
}
private async void prevPAGE_Click(object sender, EventArgs e)
{
await Task.Delay(100);
int n;
if (int.TryParse(kryptonTextBox1.Text, out n))
if (Int32.Parse(kryptonTextBox1.Text) >= 10)
{
kryptonDataGridView2.Rows.Clear();
kryptonTextBox1.Text = (Int32.Parse(kryptonTextBox1.Text) - 10).ToString();
}
}
private void kryptonDataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex == 7)//if ur link columnIndex (complain_no ColumnIndex) is zero
{
Process.Start(kryptonDataGridView2.SelectedCells[8].Value.ToString());
}
}
catch (SystemException)
{
}
}
private string filterText = String.Empty;
private async void kryptonTextBox2_TextChanged(object sender, EventArgs e)
{
kryptonDataGridView3.Rows.Clear();
await Task.Delay(500);
if (filterText != kryptonTextBox2.Text)
{
filterText = kryptonTextBox2.Text;
Uri apiLOB = new Uri(@"https://aoe2.net/api/leaderboard?game=aoe2de&leaderboard_id=3&start=1&search=" + kryptonTextBox2.Text);
string jsonLOBBIES = await DownloadStringAsync(apiLOB);
//MessageBox.Show(jsonLOBBIES.Substring(0, 8));
var ldb = QueryPlayer.FromJson(jsonLOBBIES);
int i = 1;
foreach (var l in ldb.Leaderboard)
{
i++;
LinkLabel ln = new LinkLabel();
Button btn = new Button();
ln.Text = "View";
ln.Name = "view" + i.ToString();
btn.Name = "btn" + i.ToString();
btn.Text = "Join";
kryptonDataGridView3.Rows.Add(l.Rank, l.Name, l.Rating, l.Games, "View", "View", @"https://www.ageofempires.com/stats/?profileId=" + l.ProfileId + @"&game=age2", @"http://steamcommunity.com/profiles/" + l.SteamId);
}
RemoveDuplicate(kryptonDataGridView3);
}
if(kryptonTextBox2.Text == null)
{
kryptonDataGridView3.Rows.Clear();
}
}
public void RemoveDuplicate(DataGridView grv)
{
for (int currentRow = 0; currentRow < grv.Rows.Count - 1; currentRow++)
{
DataGridViewRow rowToCompare = grv.Rows[currentRow];
for (int otherRow = currentRow + 1; otherRow < grv.Rows.Count; otherRow++)
{
DataGridViewRow row = grv.Rows[otherRow];
bool duplicateRow = true;
for (int cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++)
{
if (!rowToCompare.Cells[cellIndex].Value.Equals(row.Cells[cellIndex].Value))
{
duplicateRow = false;
break;
}
}
if (duplicateRow)
{
grv.Rows.Remove(row);
otherRow--;
}
}
}
}
private void kryptonDataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex == 4)//if ur link columnIndex (complain_no ColumnIndex) is zero
{
Process.Start(kryptonDataGridView3.SelectedCells[6].Value.ToString());
}
if (e.ColumnIndex == 5)//if ur link columnIndex (complain_no ColumnIndex) is zero
{
Process.Start(kryptonDataGridView3.SelectedCells[7].Value.ToString());
}
}
catch (SystemException)
{
}
}
private async void timer1_Tick(object sender, EventArgs e)
{
//Customize timeout
timer1.Interval = _lgtimeOUT;
Uri apiLOB = new Uri(@"https://aoe2.net/api/lobbies?game=aoe2de");
string jsonLOBBIES = await DownloadStringAsync(apiLOB);
if(jsonLOBBIES != null)
{
var lobBrowser = LobBrowser.FromJson(jsonLOBBIES);
kryptonDataGridView1.Rows.Clear();
int i = 1;
foreach (var l in lobBrowser)
{
i++;
Button btn = new Button();
btn.Name = "btn" + i.ToString();
btn.Text = "Join";
kryptonDataGridView1.Rows.Add(btn, GetTypeLadder(l.GameType.ToString()), l.Name, l.AverageRating, "steam://joinlobby/813780/" + l.LobbyId + "/" + l.LeaderboardId, l.NumPlayers + "/" + l.NumSlots, _playerPROFILES(l.Players));
}
pictureBox1.Visible = false;
if (kryptonPage2.Enabled == false)
kryptonPage2.Enabled = true;
//Connect Status
if (CheckForInternetConnection())
{
kryptonHeader1.Values.Image = DEBoarded.Properties.Resources.online;
kryptonHeader1.Values.Description = "(Online)";
}
}
else
{
kryptonHeader1.Values.Image = DEBoarded.Properties.Resources.offline;
kryptonHeader1.Values.Description = "(Offline)";
}
}
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Interval = 60000;
if (CheckForInternetConnection())
{
kryptonHeader1.Values.Image = DEBoarded.Properties.Resources.online;
kryptonHeader1.Values.Description = "(Online)";
}
else
{
kryptonHeader1.Values.Image = DEBoarded.Properties.Resources.offline;
kryptonHeader1.Values.Description = "(Offline)";
}
}
private void LRinterval_SelectedItemChanged(object sender, EventArgs e)
{
}
private void LRinterval_Scroll(object sender, ScrollEventArgs e)
{
}
private void cbINTER_SelectedIndexChanged(object sender, EventArgs e)
{
_lgtimeOUT = int.Parse(cbINTER.Text) * 1000;
}
private void intCHECK_SelectedIndexChanged(object sender, EventArgs e)
{
if (intCHECK.Text == "Yes")
netCHECK = false;
else
netCHECK = true;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}