· 6 years ago · Nov 16, 2019, 10:32 AM
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10using System.Collections;
11using System.Net;
12using System.IO;
13using System.Diagnostics;
14using Microsoft.VisualBasic;
15using Reborn4ReviveDLL2._0;
16using sb2New;
17
18namespace Reborn4Revive
19{
20 public partial class Form1 : Form
21 {
22 /// public static DBconnector dbquery = new DBconnector();
23 ///
24 ///
25 ///
26 ///
27 ///
28 public static ArrayList filesToDownload = new ArrayList();
29 public static ArrayList missingFiles = new ArrayList();
30 public static ArrayList existingFiles = new ArrayList();
31 public static ArrayList bytesOfFiles = new ArrayList();
32 public static ArrayList needToDownload = new ArrayList();
33 public static ArrayList folderPath = new ArrayList();
34 public static ArrayList missingFolders = new ArrayList();
35 public static string fileName;
36 public static int fileCounter = 0;
37 public static int downloadedFileCounter = 0;
38 public static int count = 5;
39
40 public static WebClient wclient = new WebClient();
41
42
43 public Form1()
44 {
45 InitializeComponent();
46 }
47
48 private void button1_Click(object sender, EventArgs e)
49 {
50
51 if (button1.Text == "Continue")
52 {
53 var text = DBconnector.resetPW(textBox1.Text, textBox2.Text);
54 MessageBox.Show(text);
55 Application.Exit();
56 Process.Start(Application.StartupPath + "\\Reborn4Revive.exe");
57 return;
58 }
59
60
61 //DBconnector.sender("login " + textBox1.Text + "+" + textBox2.Text);
62
63 string result = DBconnector.login(textBox1.Text, textBox2.Text);
64
65 if (result == "1")
66 {
67 //string klasse = DBconnector.getClass(textBox1.Text);
68 //if (Convert.ToInt32(klasse) >= 5)
69 //{
70 // MessageBox.Show("Something went wrong with your class! \n Please click ok to get redirected to our website \n and change your class");
71 // Process.Start("https://reborn4revive.net/");
72 // return;
73 //}
74 //else
75 //{
76 string verify = DBconnector.getCertified(textBox1.Text);
77
78 if (verify == "")
79 {
80 MessageBox.Show("This account is not verified! Please go in our Discord and type in bot command channel /verify [ingameName]");
81 return;
82 }
83 else
84
85 {
86
87 if (DBconnector.Check2(textBox1.Text) == "" || DBconnector.getSessionId(textBox1.Text) == "")
88 {
89 MessageBox.Show("This account is inavlid! Please create a new one!");
90 DBconnector.removeIt(textBox1.Text);
91 return;
92 }
93 else
94 {
95 if (DBconnector.checkBan(textBox1.Text) == textBox1.Text)
96 {
97 MessageBox.Show("You are banned!");
98 Application.Exit();
99 return;
100 }
101 else
102 {
103 // DBconnector.RegisterMyProtocol(Application.StartupPath + "\\bfp4f.exe", textBox1.Text);
104 Reborn4Revive.Properties.Settings.Default.username = textBox1.Text;
105 Reborn4Revive.Properties.Settings.Default.password = textBox2.Text;
106 Reborn4Revive.Properties.Settings.Default.Save();
107 MessageBox.Show("Login succsessfully!");
108 textBox1.Visible = false;
109 textBox2.Visible = false;
110 button1.Visible = false;
111 progressBar1.Visible = true;
112 label5.Visible = true;
113 label2.Visible = true;
114 label3.Visible = true;
115 label4.Visible = true;
116
117 pictureBox2.Visible = false;
118 label1.Visible = false;
119 linkLabel1.Visible = false;
120 pictureBox5.Visible = false;
121
122 button1.Enabled = false;
123
124
125
126 gettingsFiles();
127 }
128 // }
129 }
130 }
131 }
132 else
133 {
134 MessageBox.Show("Login error. Are you sure that you typed in the correct data? Try it again");
135 }
136 }
137
138 private void gettingsFiles()
139 {
140
141 timer3.Start();
142 timer3.Enabled = true;
143 radioButton1.Checked = true;
144
145 pictureBox6.Visible = true;
146 radioButton1.Visible = true;
147 radioButton2.Visible = true;
148 radioButton3.Visible = true;
149 radioButton4.Visible = true;
150 radioButton5.Visible = true;
151
152 label2.Text = "Status: Getting file list...";
153 wclient.DownloadFile("http://thd1.de/~jonas/GameFiles/files.txt", Application.StartupPath + "\\files.txt");
154 var table = File.ReadAllLines(Application.StartupPath + "\\files.txt");
155 foreach (string fileName2 in table)
156 {
157 if (fileName2 != "")
158 {
159 filesToDownload.Add(fileName2);
160 }
161 }
162 getFolders();
163 }
164
165 //step 1.5 get the folders and create the missing ones
166
167 private void getFolders()
168 {
169 label2.Text = "Status: Getting folder list...";
170 wclient.DownloadFile("http://thd1.de/~jonas/GameFiles/folders.xml", Application.StartupPath + "\\folders.xml");
171 var folder = File.ReadAllLines(Application.StartupPath + "\\folders.xml");
172 foreach (string folderName in folder)
173 {
174 if (folderName != "")
175 {
176 folderPath.Add(folderName);
177 }
178 }
179 getMissingFolder();
180 }
181
182 private void getMissingFolder()
183 {
184
185 label2.Text = "Status: Check missing folders...";
186 foreach (string folderName in folderPath)
187 {
188 if (folderName != "")
189 {
190 if (!Directory.Exists(Application.StartupPath + "\\" + folderName))
191 {
192 missingFolders.Add(folderName);
193 }
194 }
195 }
196 createMissingFolders();
197 }
198
199 private void createMissingFolders()
200 {
201
202 label2.Text = "Status: Create missing folders...";
203 foreach (string missingFolderName in missingFolders)
204 {
205 if (missingFolderName != "")
206 {
207 Directory.CreateDirectory(Application.StartupPath + "\\" + missingFolderName);
208 }
209 }
210 checkNotExistsFiles();
211 }
212
213 //step 2 check if already some file exists and add the not existing files to a new array
214
215 private void checkNotExistsFiles()
216 {
217
218 label2.Text = "Status: Check missing files...";
219 foreach (string file in filesToDownload)
220 {
221 // MessageBox.Show(Application.StartupPath + "/" + file);
222 if (file != "")
223 {
224 // MessageBox.Show(Application.StartupPath + "\\" + file);
225 if (!File.Exists(Application.StartupPath + "\\" + file))
226 {
227 // MessageBox.Show(file);
228 missingFiles.Add(file);
229 }
230 }
231 }
232 FileBytes();
233 }
234
235
236
237 //step 3 getting file bytes
238
239 private void FileBytes()
240 {
241
242 label2.Text = "Status: Getting file bytes...";
243 wclient.DownloadFile("http://thd1.de/~jonas/GameFiles/bytes.xml", Application.StartupPath + "\\bytes.xml");
244 var table = File.ReadAllLines(Application.StartupPath + "\\bytes.xml");
245 foreach (string byteS in table)
246 {
247 if (byteS != "")
248 {
249 bytesOfFiles.Add(byteS);
250 }
251 }
252 byteChecker();
253 }
254
255 //step 4 check the bytes of the existing files
256
257
258 private void byteChecker()
259 {
260
261 label2.Text = "Status: Check bytes of existing files...";
262 foreach (string fileBytes in filesToDownload)
263 {
264 if (File.Exists(Application.StartupPath + "\\" + fileBytes))
265 {
266 if (FileSystem.FileLen(fileBytes).ToString() != bytesOfFiles[0].ToString())
267 {
268 needToDownload.Add(fileBytes);
269 bytesOfFiles.RemoveAt(0);
270 }
271 else
272 {
273 bytesOfFiles.RemoveAt(0);
274 }
275 }
276 else
277 {
278 needToDownload.Add(fileBytes);
279 bytesOfFiles.RemoveAt(0);
280 }
281 }
282 fileCount();
283 }
284
285 //step 4.5 counting files
286
287 private void fileCount()
288 {
289
290 foreach (string file in needToDownload)
291 {
292 fileCounter++;
293 downloadedFileCounter++;
294 }
295 downloader();
296 }
297
298 //step 5 Download the missing Files
299
300 private void downloader()
301 {
302
303 if (fileCounter > 0 )
304 {
305 label2.Text = "Status: Downloading missing files...";
306 using (WebClient wc = new WebClient())
307 {
308 label4.Text = "Files: " + fileCounter + " / " + downloadedFileCounter;
309 wc.DownloadProgressChanged += wc_DownloadProgressChanged;
310 wc.DownloadFileCompleted += wc_DownloadFileCompleted;
311 // MessageBox.Show(needToDownload[0].ToString());
312 label5.Text = needToDownload[0].ToString();
313 wc.DownloadFileAsync(new Uri("http://thd1.de/~jonas/GameFiles/" + needToDownload[0].ToString()), Application.StartupPath + "\\" + needToDownload[0].ToString());
314 }
315 }
316 else if (fileCounter <= 0)
317 {
318 label5.Text = "Download Finished!";
319 label5.Location = new Point(353,411);
320 label3.Text = "";
321 label2.Text = "";
322 label4.Text = "";
323 progressBar1.Value = 100;
324 button2.Visible = true;
325 // GameStarter();
326
327 }
328 }
329
330
331
332
333 private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
334 {
335 progressBar1.Value = e.ProgressPercentage;
336 long totalbytes = e.TotalBytesToReceive / 1024 / 1024;
337 long totalbytesKB = e.TotalBytesToReceive / 1024;
338 long bytes = e.BytesReceived / 1024 / 1024;
339 long bytesKB = e.BytesReceived / 1024;
340 if (e.BytesReceived >= 999)
341 {
342 label3.Text = bytes.ToString() + " / " + totalbytes.ToString() + " MB ";
343 }
344 else
345 {
346 label3.Text = bytesKB.ToString() + " / " + totalbytesKB.ToString() + " KB ";
347 }
348 }
349
350 private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
351 {
352
353
354 needToDownload.RemoveAt(0);
355 fileCounter --;
356
357 if (fileCounter > 0)
358 {
359 downloader();
360 }
361 else
362 {
363 label3.Visible = false;
364 label4.Visible = false;
365 label2.Visible = false;
366 label5.Text = "Download finished!";
367 label5.Location = new Point(353, 411);
368 progressBar1.Value = 100;
369 button2.Visible = true;
370
371 }
372 }
373
374 private void ctrlClick(object sender, System.EventArgs e)
375 {
376 textBox1.SelectAll();
377 }
378
379 private void ctrlClick2(object sender, System.EventArgs e)
380 {
381 textBox2.SelectAll();
382 }
383
384 private void Form1_Load(object sender, EventArgs e)
385 {
386
387 //start discord api
388 DiscordClientLauncher discordpi = new DiscordClientLauncher();
389 discordpi.Start("launcher", Reborn4Revive.Properties.Settings.Default.launcherVersionClient);
390 //
391 //check for updates
392 string serverVersion = DBconnector.updateCheck();
393 string clientVersion = Reborn4Revive.Properties.Settings.Default.launcherVersionClient;
394
395 if (clientVersion != serverVersion)
396 {
397 MessageBox.Show("New update found click ok to download the update!");
398 Process.Start(Application.StartupPath + "\\updater.exe");
399 Application.Exit();
400 return;
401 }
402
403 //
404
405 textBox1.Multiline = true;
406 textBox1.MinimumSize = new Size(173, 24);
407 textBox1.Size = new Size(173, 24);
408 textBox1.Multiline = false;
409
410 textBox2.Multiline = true;
411 textBox2.MinimumSize = new Size(173, 24);
412 textBox2.Size = new Size(173, 24);
413 textBox2.Multiline = false;
414
415 //
416
417
418
419 //
420
421
422 if (Reborn4Revive.Properties.Settings.Default.username != "")
423 {
424 textBox1.Text = Reborn4Revive.Properties.Settings.Default.username;
425 textBox2.Text = Reborn4Revive.Properties.Settings.Default.password;
426 }
427 }
428
429
430 //private void pictureBox2_Click(object sender, EventArgs e)
431 //{
432 // string args = Reborn4Revive.Properties.Settings.Default.args;
433 // string sessionID = DBconnector.getSessionId(textBox1.Text);
434
435 // args = args.Replace("#SESSION#", sessionID);
436 // args = args.Replace("#PLAYER#", textBox1.Text);
437 // args = args.Replace("#IP#", "185.249.198.123");
438
439 // Process.Start(Application.StartupPath + "\\bfp4f.exe", args);
440
441 // // Process.Start(Application.StartupPath + "\\serverBrowser.exe", textBox1.Text);
442 // Application.Exit();
443 //}
444
445 //private void pictureBox3_Click(object sender, EventArgs e)
446 //{
447 // //settings
448 // timer1.Start();
449 // timer1.Enabled = true;
450 // pictureBox3.Visible = false;
451 //}
452
453 //private void timer1_Tick(object sender, EventArgs e)
454 //{
455 // var loc = panel1.Location;
456 // panel1.Location = new Point(loc.X - 5, loc.Y);
457
458 // if (loc.X <= 570)
459 // {
460 // timer1.Stop();
461 // timer1.Enabled = false;
462 // return;
463 // }
464 //}
465
466 private void pictureBox4_Click(object sender, EventArgs e)
467 {
468 timer2.Start();
469 timer2.Enabled = true;
470 }
471
472 private void GameStarter()
473 {
474 var ip = DBconnector.getSelectedServer(textBox1.Text);
475 string sessionID = DBconnector.getSessionId(textBox1.Text);
476
477 if (ip == "")
478 {
479 MessageBox.Show("Please select a server!");
480 Process.Start("https://reborn4revive.net/serverList/serverList.php");
481 Application.Exit();
482 return;
483 }
484 else if (ip != "")
485 {
486 //MessageBox.Show(ip + "nice");
487 string args = Reborn4Revive.Properties.Settings.Default.args;
488 args = args.Replace("#SESSION#", sessionID);
489 args = args.Replace("#PLAYER#", textBox1.Text);
490 args = args.Replace("#IP#", ip);
491 Process.Start(Application.StartupPath + "\\bfp4f.exe", args);
492 Application.Exit();
493 }
494 }
495
496 private void radioButton1_CheckedChanged(object sender, EventArgs e)
497 {
498 pictureBox6.Image = Reborn4Revive.Properties.Resources.bgT1;
499 }
500
501 private void radioButton2_CheckedChanged(object sender, EventArgs e)
502 {
503 pictureBox6.Image = Reborn4Revive.Properties.Resources.bgT2;
504 }
505
506 private void radioButton3_CheckedChanged(object sender, EventArgs e)
507 {
508 pictureBox6.Image = Reborn4Revive.Properties.Resources.bgT3;
509 }
510
511 private void radioButton4_CheckedChanged(object sender, EventArgs e)
512 {
513 pictureBox6.Image = Reborn4Revive.Properties.Resources.bgT4;
514 }
515
516 private void radioButton5_CheckedChanged(object sender, EventArgs e)
517 {
518 pictureBox6.Image = Reborn4Revive.Properties.Resources.bgT5;
519 }
520
521 private void timer3_Tick(object sender, EventArgs e)
522 {
523 count++;
524
525
526
527 if (count == 5)
528 {
529 radioButton1.Checked = true;
530 }
531 else if(count == 10)
532 {
533 radioButton2.Checked = true;
534 }
535 else if (count == 15)
536 {
537 radioButton3.Checked = true;
538 }
539 else if (count == 20)
540 {
541 radioButton4.Checked = true;
542 }
543 else if (count == 25)
544 {
545 radioButton5.Checked = true;
546 count = 0;
547 }
548 }
549
550 private void button2_Click(object sender, EventArgs e)
551 {
552
553 //Form2 form2 = new Form2();
554 //form2.Visible = true;
555 Form3 form3 = new Form3();
556 form3.Visible = true;
557 this.Visible = false;
558
559 }
560
561 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
562 {
563 if (linkLabel1.Text == "What is my auth id?")
564 {
565 Process.Start("https://reborn4revive.net/help/");
566 }
567 else
568 {
569 textBox1.Text = "Enter your auth ID";
570 textBox2.UseSystemPasswordChar = false;
571 textBox2.Text = "New Password";
572
573 button1.Visible = true;
574 button1.Text = "Continue";
575 linkLabel1.Text = "What is my auth id?";
576 }
577 }
578
579 private void toolTip1_Popup(object sender, PopupEventArgs e)
580 {
581
582 }
583
584 private void textBox2_TextChanged(object sender, EventArgs e)
585 {
586 if (linkLabel1.Text == "What is my auth id?")
587 {
588 textBox2.UseSystemPasswordChar = true;
589 }
590 }
591
592 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
593 {
594 Process.Start("https://reborn4revive.net/serverList/serverList.php");
595 }
596 }
597}