-
Notifications
You must be signed in to change notification settings - Fork 131
/
MainScreen.cs
3394 lines (2967 loc) · 159 KB
/
MainScreen.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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using GameLauncher.App.Classes.Auth;
using GameLauncher.App.Classes.Hash;
using GameLauncher.App.Classes.InsiderKit;
using GameLauncher.App.Classes.LauncherCore.APICheckers;
using GameLauncher.App.Classes.LauncherCore.Client;
using GameLauncher.App.Classes.LauncherCore.Client.Auth;
using GameLauncher.App.Classes.LauncherCore.Client.Web;
using GameLauncher.App.Classes.LauncherCore.Downloader;
using GameLauncher.App.Classes.LauncherCore.FileReadWrite;
using GameLauncher.App.Classes.LauncherCore.Global;
using GameLauncher.App.Classes.LauncherCore.Languages.Visual_Forms;
using GameLauncher.App.Classes.LauncherCore.LauncherUpdater;
using GameLauncher.App.Classes.LauncherCore.Lists;
using GameLauncher.App.Classes.LauncherCore.Lists.JSON;
using GameLauncher.App.Classes.LauncherCore.Logger;
using GameLauncher.App.Classes.LauncherCore.ModNet;
using GameLauncher.App.Classes.LauncherCore.ModNet.JSON;
using GameLauncher.App.Classes.LauncherCore.Proxy;
using GameLauncher.App.Classes.LauncherCore.RPC;
using GameLauncher.App.Classes.LauncherCore.Support;
using GameLauncher.App.Classes.LauncherCore.Validator.Email;
using GameLauncher.App.Classes.LauncherCore.Validator.JSON;
using GameLauncher.App.Classes.LauncherCore.Visuals;
using GameLauncher.App.Classes.SystemPlatform;
using GameLauncher.App.Classes.SystemPlatform.Unix;
using GameLauncher.App.Classes.SystemPlatform.Windows;
using GameLauncher.App.UI_Forms.About_Screen;
using GameLauncher.App.UI_Forms.SecurityCenter_Screen;
using GameLauncher.App.UI_Forms.SelectServer_Screen;
using GameLauncher.App.UI_Forms.Settings_Screen;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace GameLauncher.App.UI_Forms.Main_Screen
{
public partial class MainScreen : Form
{
private Point _mouseDownPoint = Point.Empty;
private bool _loginEnabled;
private bool _serverEnabled;
private bool _builtinserver;
private bool _skipServerTrigger;
private bool _playenabled;
private bool _isDownloading = true;
private bool _disableLogout = false;
private bool _restartLauncher = false;
public static String getTempNa = Path.GetTempFileName();
private static int _lastSelectedServerId;
private static int _nfswPid;
private static Thread _nfswstarted;
private static bool StillCheckingLastServer = false;
private static bool ServerChangeTriggered = false;
private static int ProcessID = 0;
private static int ProcessWID = 0;
private static DateTime _downloadStartTime;
private static Downloader _downloader;
private static string JsonGSI;
private static MemoryStream _serverRawBanner = null;
private string _loginWelcomeTime = string.Empty;
private string _loginToken = string.Empty;
private string _userId = string.Empty;
private static int serverSecondsToShutDown;
public static String ModNetFileNameInUse = String.Empty;
public static readonly Queue<Uri> modFilesDownloadUrls = new Queue<Uri>();
public static bool isDownloadingModNetFiles = false;
public static int CurrentModFileCount = 0;
public static int TotalModFileCount = 0;
public static readonly String filename_pack = Strings.Encode(Path.Combine(Locations.LauncherFolder, "GameFiles.sbrwpack"));
private void MoveWindow_MouseDown(object sender, MouseEventArgs e)
{
if (e.Y <= 90) _mouseDownPoint = new Point(e.X, e.Y);
}
private void MoveWindow_MouseUp(object sender, MouseEventArgs e)
{
_mouseDownPoint = Point.Empty;
Opacity = 1;
}
private void MoveWindow_MouseMove(object sender, MouseEventArgs e)
{
if (_mouseDownPoint.IsEmpty) { return; }
var f = this as Form;
f.Location = new Point(f.Location.X + (e.X - _mouseDownPoint.X), f.Location.Y + (e.Y - _mouseDownPoint.Y));
InformationCache.ParentScreenLocation = new Point(f.Location.X + (e.X - _mouseDownPoint.X), f.Location.Y + (e.Y - _mouseDownPoint.Y));
Opacity = 0.9;
}
private void MainScreen_Load(object sender, EventArgs e)
{
Log.Visuals("CORE: Loading Main Screen");
FunctionStatus.CenterScreen(this);
Application.OpenForms[this.Name].Activate();
Log.Core("CORE: Setting Parent Window location");
InformationCache.ParentScreenLocation = Location;
if (!string.IsNullOrWhiteSpace(InsiderInfo.BuildNumber()))
{
if (EnableInsiderDeveloper.Allowed() || EnableInsiderBetaTester.Allowed())
{
InsiderBuildNumberText.Visible = true;
InsiderBuildNumberText.Text = InsiderInfo.BuildNumber();
}
else
{
InsiderBuildNumberText.Visible = translatedBy.Visible = false;
}
}
Log.Core("LAUNCHER: NFSW Download Source is now: " + FileSettingsSave.CDN);
MainEmail.Text = FileAccountSave.UserRawEmail;
MainPassword.Text = FileAccountSave.UserRawPassword;
Log.Core("LAUNCHER: Checking for password");
if (!string.IsNullOrWhiteSpace(FileAccountSave.UserHashedPassword))
{
_loginEnabled = true;
_serverEnabled = true;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.FivithTextForeColor;
}
else
{
_loginEnabled = false;
_serverEnabled = false;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.SixTextForeColor;
}
if (!string.IsNullOrWhiteSpace(FileAccountSave.UserRawEmail) &&
(!string.IsNullOrWhiteSpace(FileAccountSave.UserHashedPassword) || !string.IsNullOrWhiteSpace(FileAccountSave.UserRawPassword)))
{
Log.Core("LAUNCHER: Restoring last saved email and password");
RememberMe.Checked = true;
FileAccountSave.SaveLoginInformation = true;
}
/* Server Display List */
ServerPick.DisplayMember = "Name";
Log.Core("LAUNCHER: Setting server list");
ServerPick.DataSource = ServerListUpdater.CleanList;
/* Display Server List Dialog if Server IP Doesn't Exist */
if (string.IsNullOrWhiteSpace(FileAccountSave.ChoosenGameServer))
{
SelectServer.OpenScreen(false);
if (SelectedServer.Data != null)
{
FileAccountSave.ChoosenGameServer = SelectedServer.Data.IPAddress;
FileAccountSave.SaveAccount();
}
else
{
FunctionStatus.LauncherForceClose = true;
}
}
if (FunctionStatus.LauncherForceClose)
{
FunctionStatus.ErrorCloseLauncher("Closing From SelectServer Dialog", false);
}
else
{
Log.Core("SERVERLIST: Checking...");
Log.Core("SERVERLIST: Setting first server in list");
Log.Core("SERVERLIST: Checking if server is set on INI File");
try
{
if (string.IsNullOrWhiteSpace(FileAccountSave.ChoosenGameServer))
{
Log.Warning("SERVERLIST: Failed to find anything... assuming " + ((ServerList)ServerPick.SelectedItem).IPAddress);
FileAccountSave.ChoosenGameServer = ((ServerList)ServerPick.SelectedItem).IPAddress;
FileAccountSave.SaveAccount();
}
}
catch
{
Log.Error("SERVERLIST: Failed to write anything...");
FileAccountSave.ChoosenGameServer = string.Empty;
FileAccountSave.SaveAccount();
}
Log.Core("SERVERLIST: Re-Checking if server is set on INI File");
if (!string.IsNullOrWhiteSpace(FileAccountSave.ChoosenGameServer))
{
Log.Core("SERVERLIST: Found something!");
_skipServerTrigger = true;
Log.Core("SERVERLIST: Checking if server exists on our database");
try
{
if (ServerListUpdater.CleanList.Count != 0)
{
if (ServerListUpdater.CleanList.FindIndex(i => string.Equals(i.IPAddress, FileAccountSave.ChoosenGameServer)) != 0)
{
Log.Core("SERVERLIST: Server found! Checking ID");
var index = ServerListUpdater.CleanList.FindIndex(i => string.Equals(i.IPAddress, FileAccountSave.ChoosenGameServer));
Log.Core("SERVERLIST: ID is " + index);
if (index >= 0)
{
Log.Core("SERVERLIST: ID set correctly");
ServerPick.SelectedIndex = index;
}
else
{
ServerPick.SelectedIndex = 1;
}
}
else
{
Log.Warning("SERVERLIST: Unable to find anything, assuming default");
ServerPick.SelectedIndex = 1;
Log.Warning("SERVERLIST: Deleting unknown entry");
FileAccountSave.ChoosenGameServer = string.Empty;
FileAccountSave.SaveAccount();
}
Log.Core("SERVERLIST: Triggering server change");
if (ServerPick.SelectedIndex == 1)
{
ServerPick_SelectedIndexChanged(sender, e);
}
Log.Completed("SERVERLIST: All done");
}
else { ServerPick_SelectedIndexChanged(sender, e); Log.Completed("SERVERLIST: Empty List. Not Setting Index"); }
}
catch (Exception Error)
{
LogToFileAddons.OpenLog("Serverlist", null, Error, null, true);
}
}
Log.Core("LAUNCHER: Re-checking InstallationDirectory: " + FileSettingsSave.GameInstallation);
string Drive = Strings.Encode(Path.GetPathRoot(FileSettingsSave.GameInstallation));
if (!Directory.Exists(Drive))
{
if (!string.IsNullOrWhiteSpace(Drive))
{
FileSettingsSave.GameInstallation = Locations.GameFilesFailSafePath;
FileSettingsSave.SaveSettings();
string Display_Message = Translations.Database("MainScreen_TextBox_GameFiles_Invalid_Location");
Log.Error(string.Format("LAUNCHER: Drive {0} was not found. Your actual installation directory is set to {1} now.",
Drive, Locations.GameFilesFailSafePath));
string TempEmailCache = string.Empty;
if (!string.IsNullOrWhiteSpace(MainEmail.Text))
{
TempEmailCache = MainEmail.Text;
MainEmail.Text = "EMAIL IS HIDDEN";
}
MessageBox.Show(null, string.Format("Drive {0} was not found. Your actual installation directory is set to {1} now.",
Drive, Locations.GameFilesFailSafePath),
"GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (!string.IsNullOrWhiteSpace(TempEmailCache))
{
MainEmail.Text = TempEmailCache;
}
}
}
this.SafeEndInvokeAsyncCatch(this.SafeBeginInvokeActionAsync(Launcher_X_Form =>
{
Log.Core("CORE: 'GetServerInformation' from all Servers in Server List and Download Selected Server Banners");
LaunchNfsw();
}));
this.BringToFront();
try
{
new LauncherUpdateCheck(LauncherIconStatus, LauncherStatusText, LauncherStatusDesc).ChangeVisualStatus();
}
catch
{
if (UnixOS.Detected())
{
LauncherIconStatus.BackgroundImage = Theming.UpdateIconSuccess;
LauncherStatusText.ForeColor = Theming.Sucess;
LauncherStatusText.Text = "Launcher Status:\n - Linux Build";
LauncherStatusDesc.Text = "Version: v" + Application.ProductVersion;
}
}
PingServerListAPIStatus();
Log.Visuals("CORE: Applyinng ContextMenu");
ContextMenu = new ContextMenu();
ContextMenu.MenuItems.Add(new MenuItem("About", (O, K) => { About.OpenScreen(); }));
if (LauncherUpdateCheck.UpgradeAvailable)
{
ContextMenu.MenuItems.Add("-");
ContextMenu.MenuItems.Add(new MenuItem("Obsolete", (N, O) => { Process.Start("https://www.youtube.com/watch?v=LutDfASARmE"); }));
}
ContextMenu.MenuItems.Add("-");
ContextMenu.MenuItems.Add(new MenuItem("Close Launcher", CloseBTN_Click));
Notification.ContextMenu = ContextMenu;
Notification.Icon = new Icon(Icon, Icon.Width, Icon.Height);
Notification.Text = "SBRW Launcher";
Notification.Visible = true;
ContextMenu = null;
/* Remove TracksHigh Folder and Files */
RemoveTracksHighFiles();
}
}
private void ClosingTasks()
{
FileSettingsSave.SaveSettings();
FileAccountSave.SaveAccount();
try
{ _downloader.Stop(); }
catch (Exception Error)
{
LogToFileAddons.OpenLog("CDN DOWNLOADER", null, Error, null, true);
}
try
{
if (FunctionStatus.LauncherBattlePass)
{
Process.GetProcessById(_nfswPid).Kill();
}
else
{
Process[] allOfThem = Process.GetProcessesByName("nfsw");
if (allOfThem != null && allOfThem.Any())
{
foreach (var oneProcess in allOfThem)
{
Process.GetProcessById(oneProcess.Id).Kill();
}
}
}
}
catch { }
if (DiscordLauncherPresence.Running())
{
DiscordLauncherPresence.Stop("Close");
}
if (ServerProxy.Running())
{
ServerProxy.Instance.Stop("Main Screen");
}
try { Notification.Dispose(); } catch { }
if (File.Exists(Locations.GameLinksFile) && !FunctionStatus.LauncherBattlePass)
{
ModNetHandler.CleanLinks(Locations.GameLinksFile, FileSettingsSave.GameInstallation);
}
}
private void CloseBTN_Click(object sender, EventArgs e)
{
ClosingTasks();
/* Leave this here. Its to properly close the launcher from Visual Studio (And Close the Launcher a well)
* If the Boolen is true it will restart the Application
*/
if (_restartLauncher)
{
Application.Restart();
}
else
{
try { this.Close(); } catch { }
}
}
private void ButtonClose_MouseDown(object sender, EventArgs e)
{
CloseBTN.BackgroundImage = Theming.CloseButtonClick;
}
private void ButtonClose_MouseEnter(object sender, EventArgs e)
{
CloseBTN.BackgroundImage = Theming.CloseButtonHover;
}
private void ButtonClose_MouseLeaveANDMouseUp(object sender, EventArgs e)
{
CloseBTN.BackgroundImage = Theming.CloseButton;
}
private void ButtonSecurityCenter_MouseDown(object sender, EventArgs e)
{
ButtonSecurityCenter.BackgroundImage = SecurityCenter.SecurityCenterIcon(1);
}
private void ButtonSecurityCenter_MouseEnter(object sender, EventArgs e)
{
ButtonSecurityCenter.BackgroundImage = SecurityCenter.SecurityCenterIcon(2);
}
private void ButtonSecurityCenter_MouseLeaveANDMouseUp(object sender, EventArgs e)
{
ButtonSecurityCenter.BackgroundImage = SecurityCenter.SecurityCenterIcon(0);
}
private void ButtonSettings_MouseDown(object sender, EventArgs e)
{
SettingsButton.BackgroundImage = (FileSettingsSave.GameIntegrity == "Bad") ? Theming.GearButtonWarningClick : Theming.GearButtonClick;
}
private void ButtonSettings_MouseEnter(object sender, EventArgs e)
{
SettingsButton.BackgroundImage = (FileSettingsSave.GameIntegrity == "Bad") ? Theming.GearButtonWarningHover : Theming.GearButtonHover;
}
private void ButtonSettings_MouseLeaveANDMouseUp(object sender, EventArgs e)
{
SettingsButton.BackgroundImage = (FileSettingsSave.GameIntegrity == "Bad") ? Theming.GearButtonWarning : Theming.GearButton;
}
private void LoginEnter(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return && _loginEnabled)
{
LoginButton_Click(null, null);
e.SuppressKeyPress = true;
}
}
private void Loginbuttonenabler(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(MainEmail.Text) || string.IsNullOrWhiteSpace(MainPassword.Text))
{
_loginEnabled = false;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.SixTextForeColor;
}
else
{
_loginEnabled = true;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.FivithTextForeColor;
}
}
private void LoginButton_MouseUp(object sender, EventArgs e)
{
if (_loginEnabled || _builtinserver)
{
LoginButton.BackgroundImage = Theming.GrayButtonHover;
}
else
{
LoginButton.BackgroundImage = Theming.GrayButton;
}
}
private void LoginButton_MouseDown(object sender, EventArgs e)
{
if (_loginEnabled || _builtinserver)
{
LoginButton.BackgroundImage = Theming.GrayButtonClick;
}
else
{
LoginButton.BackgroundImage = Theming.GrayButton;
}
}
private void LoginButton_Click(object sender, EventArgs e)
{
if ((_loginEnabled == false || _serverEnabled == false) && _builtinserver == false)
{
return;
}
if (_isDownloading)
{
string TempEmailCache = string.Empty;
if (!string.IsNullOrWhiteSpace(MainEmail.Text))
{
TempEmailCache = MainEmail.Text;
MainEmail.Text = "EMAIL IS HIDDEN";
}
MessageBox.Show(null, "Please wait while the GameLauncher is still downloading the game files.", "GameLauncher", MessageBoxButtons.OK);
if (!string.IsNullOrWhiteSpace(TempEmailCache))
{
MainEmail.Text = TempEmailCache;
}
return;
}
Tokens.Clear();
String Email;
String Password;
Tokens.IPAddress = InformationCache.SelectedServerData.IPAddress;
Tokens.ServerName = ServerListUpdater.ServerName("Login");
switch (Authentication.HashType(InformationCache.SelectedServerJSON.authHash ?? string.Empty))
{
case AuthHash.H10:
Email = MainEmail.Text.ToString();
Password = MainPassword.Text.ToString();
break;
case AuthHash.H11:
Email = MainEmail.Text.ToString();
Password = MDFive.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H12:
Email = MainEmail.Text.ToString();
Password = SHA.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H13:
Email = MainEmail.Text.ToString();
Password = SHATwoFiveSix.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H20:
Email = MDFive.Hashes(MainEmail.Text.ToString()).ToLower();
Password = MDFive.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H21:
Email = SHA.Hashes(MainEmail.Text.ToString()).ToLower();
Password = SHA.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H22:
Email = SHATwoFiveSix.Hashes(MainEmail.Text.ToString()).ToLower();
Password = SHATwoFiveSix.Hashes(MainPassword.Text.ToString()).ToLower();
break;
default:
Log.Error("HASH TYPE: Unknown Hash Standard was Provided");
return;
}
Authentication.Client("Login", InformationCache.SelectedServerJSON.modernAuthSupport, Email, Password, null);
if (String.IsNullOrWhiteSpace(Tokens.Error))
{
try
{
if (!(ServerPick.SelectedItem is ServerList server)) return;
FileAccountSave.ChoosenGameServer = server.IPAddress;
}
catch { }
_userId = Tokens.UserId;
_loginToken = Tokens.LoginToken;
InformationCache.SelectedServerData.IPAddress = Tokens.IPAddress;
/* Tells the FileAccountSave to Actually Save the Information or Not */
FileAccountSave.SaveLoginInformation = RememberMe.Checked;
FileAccountSave.UserRawEmail = MainEmail.Text.ToString();
FileAccountSave.UserRawPassword = MainPassword.Text.ToString();
switch (Authentication.HashType(InformationCache.SelectedServerJSON.authHash ?? string.Empty))
{
case AuthHash.H10:
FileAccountSave.SavedGameServerHash = "1.0";
FileAccountSave.UserHashedEmail = string.Empty;
FileAccountSave.UserHashedPassword = string.Empty;
break;
case AuthHash.H11:
FileAccountSave.SavedGameServerHash = "1.1";
FileAccountSave.UserHashedEmail = string.Empty;
FileAccountSave.UserHashedPassword = MDFive.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H12:
FileAccountSave.SavedGameServerHash = "1.2";
FileAccountSave.UserHashedEmail = string.Empty;
FileAccountSave.UserHashedPassword = SHA.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H13:
FileAccountSave.SavedGameServerHash = "1.3";
FileAccountSave.UserHashedEmail = string.Empty;
FileAccountSave.UserHashedPassword = SHATwoFiveSix.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H20:
FileAccountSave.SavedGameServerHash = "2.0";
FileAccountSave.UserHashedEmail = MDFive.Hashes(MainEmail.Text.ToString()).ToLower();
FileAccountSave.UserHashedPassword = MDFive.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H21:
FileAccountSave.SavedGameServerHash = "2.1";
FileAccountSave.UserHashedEmail = SHA.Hashes(MainEmail.Text.ToString()).ToLower();
FileAccountSave.UserHashedPassword = SHA.Hashes(MainPassword.Text.ToString()).ToLower();
break;
case AuthHash.H22:
FileAccountSave.SavedGameServerHash = "2.2";
FileAccountSave.UserHashedEmail = SHATwoFiveSix.Hashes(MainEmail.Text.ToString()).ToLower();
FileAccountSave.UserHashedPassword = SHATwoFiveSix.Hashes(MainPassword.Text.ToString()).ToLower();
break;
default:
FileAccountSave.SavedGameServerHash = "Unknown";
FileAccountSave.UserHashedEmail = string.Empty;
FileAccountSave.UserHashedPassword = string.Empty;
Log.Error("HASH TYPE: Unknown Hash Standard was Provided");
return;
}
FileAccountSave.SaveAccount();
if (!String.IsNullOrWhiteSpace(Tokens.Warning))
{
MainEmail.Text = "EMAIL IS HIDDEN";
MessageBox.Show(null, Tokens.Warning, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MainEmail.Text = Email;
}
LoginFormElements(false);
LoggedInFormElements(true);
}
else
{
/* Main Screen Login */
MainEmailBorder.Image = Theming.BorderEmailError;
MainPasswordBorder.Image = Theming.BorderPasswordError;
MainEmail.Text = "EMAIL IS HIDDEN";
MessageBox.Show(null, Tokens.Error, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
MainEmail.Text = Email;
}
}
private void LoginButton_MouseEnter(object sender, EventArgs e)
{
if (_loginEnabled || _builtinserver)
{
LoginButton.BackgroundImage = Theming.GrayButtonHover;
LoginButton.ForeColor = Theming.FivithTextForeColor;
}
else
{
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.SixTextForeColor;
}
}
private void LoginButton_MouseLeave(object sender, EventArgs e)
{
if (_loginEnabled || _builtinserver)
{
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.FivithTextForeColor;
}
else
{
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.ForeColor = Theming.SixTextForeColor;
}
}
private void ServerPick_SelectedIndexChanged(object sender, EventArgs e)
{
GC.Collect();
MainEmailBorder.Image = Theming.BorderEmail;
MainPasswordBorder.Image = Theming.BorderPassword;
/* Disable Certain Functions */
_loginEnabled = false;
_serverEnabled = false;
FunctionStatus.AllowRegistration = false;
InformationCache.SelectedServerJSON = null;
/* Disable Login & Register Button */
LoginButton.Enabled = false;
RegisterText.Enabled = false;
/* Disable Social Panel when switching */
DisableSocialPanelandClearIt();
/* Stops any actions for a Server */
ServerChangeTriggered = true;
if (!ServerListUpdater.LoadedList && InformationCache.SelectedServerData == null)
{
ServerStatusText.Text = "Launcher Offline:\n - Unknown";
ServerStatusText.ForeColor = Theming.ThirdTextForeColor;
ServerStatusDesc.Text = string.Empty;
ServerStatusIcon.BackgroundImage = Theming.ServerIconUnkown;
return;
}
InformationCache.SelectedServerData = (ServerList)ServerPick.SelectedItem;
if (InformationCache.SelectedServerData.IsSpecial)
{
ServerPick.SelectedIndex = _lastSelectedServerId;
return;
}
if (!_skipServerTrigger) { return; }
_lastSelectedServerId = ServerPick.SelectedIndex;
ServerStatusText.Text = "Server Status:\n - Pinging";
ServerStatusText.ForeColor = Theming.SecondaryTextForeColor;
ServerStatusDesc.Text = string.Empty;
ServerStatusIcon.BackgroundImage = Theming.ServerIconChecking;
LoginButton.ForeColor = Theming.SixTextForeColor;
string BannerCache = Strings.Encode(
Path.Combine(".BannerCache", SHA.Hashes(InformationCache.SelectedServerData.IPAddress) + ".bin"));
Banner.Image = Banners.Grayscale(BannerCache);
Banner.BackColor = Color.Transparent;
string ImageUrl = string.Empty;
string numPlayers = string.Empty;
string numRegistered = string.Empty;
if (ServerPick.GetItemText(ServerPick.SelectedItem) == "Offline Built-In Server")
{
_builtinserver = true;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.Text = "Launch".ToUpper();
LoginButton.ForeColor = Theming.FivithTextForeColor;
ServerInfoPanel.Visible = false;
}
else
{
_builtinserver = false;
LoginButton.BackgroundImage = Theming.GrayButton;
LoginButton.Text = "Login".ToUpper();
LoginButton.ForeColor = Theming.SixTextForeColor;
ServerInfoPanel.Visible = false;
}
Uri ServerURI = new Uri(InformationCache.SelectedServerData.IPAddress + "/GetServerInformation");
ServicePointManager.FindServicePoint(ServerURI).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
var Client = new WebClient
{
Encoding = Encoding.UTF8
};
if (!WebCalls.Alternative()) { Client = new WebClientWithTimeout { Encoding = Encoding.UTF8 }; }
else
{
Client.Headers.Add("user-agent", "SBRW Launcher " +
Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
}
Client.DownloadStringAsync(ServerURI);
System.Timers.Timer aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += (x, y) => { Client.CancelAsync(); try { aTimer.Dispose(); } catch { } };
aTimer.AutoReset = false;
aTimer.Enabled = true;
Client.DownloadStringCompleted += (sender2, e2) =>
{
aTimer.Enabled = false;
try { aTimer.Dispose(); } catch { }
bool GSIErrorFree = true;
if (e2.Cancelled || e2.Error != null)
{
InformationCache.SelectedServerJSON = null;
ServerStatusIcon.BackgroundImage = Theming.ServerIconOffline;
ServerStatusText.Text = "Server Status:\n - Offline ( OFF )";
ServerStatusText.ForeColor = Theming.Error;
ServerStatusDesc.Text = (e2.Error != null) ?
Strings.Truncate(e2.Error.Message ?? "Server Seems to be Offline", 36) : "Failed to Connect to Server";
if (!InformationCache.ServerStatusBook.ContainsKey(InformationCache.SelectedServerData.ID))
{
InformationCache.ServerStatusBook.Add(
InformationCache.SelectedServerData.ID, (e2.Error != null) ? 0 : 3);
}
else
{
InformationCache.ServerStatusBook
[InformationCache.SelectedServerData.ID] = (e2.Error != null) ? 0 : 3;
}
if (e2.Error != null)
{
LogToFileAddons.OpenLog("JSON GSI", null, e2.Error, null, true);
}
if (Client != null)
{
Client.Dispose();
}
}
else
{
if (ServerListUpdater.ServerName("Ping") == "Offline Built-In Server")
{
numPlayers = "∞";
numRegistered = "∞";
}
else
{
try
{
InformationCache.SelectedServerJSON = JsonConvert.DeserializeObject<GetServerInformation>(e2.Result);
}
catch (Exception Error)
{
if (EnableInsiderBetaTester.Allowed() || EnableInsiderDeveloper.Allowed())
{
try { Log.Error("JSON GSI (Received): " + e2.Result); }
catch { Log.Error("JSON GSI (Received): Unable to Get Result"); }
}
else
{
Log.Error("JSON GSI: Invalid");
}
LogToFileAddons.OpenLog("JSON GSI", null, Error, null, true);
GSIErrorFree = false;
InformationCache.SelectedServerJSON = null;
}
if (!InformationCache.ServerStatusBook.ContainsKey(InformationCache.SelectedServerData.ID))
{
InformationCache.ServerStatusBook.Add(
InformationCache.SelectedServerData.ID, (!GSIErrorFree) ? 3 : 1);
}
else
{
InformationCache.ServerStatusBook
[InformationCache.SelectedServerData.ID] = (!GSIErrorFree) ? 3 : 1;
}
if (GSIErrorFree)
{
try
{
if (!string.IsNullOrWhiteSpace(InformationCache.SelectedServerJSON.bannerUrl))
{
bool ServerBannerResult;
try
{
ServerBannerResult = Uri.TryCreate(InformationCache.SelectedServerJSON.bannerUrl, UriKind.Absolute, out Uri uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
catch { ServerBannerResult = false; }
ImageUrl = ServerBannerResult ? InformationCache.SelectedServerJSON.bannerUrl : string.Empty;
}
else
{
ImageUrl = string.Empty;
}
}
catch { }
/* Social Panel Core */
/* Discord Invite Display */
try
{
bool ServerDiscordLink;
try
{
ServerDiscordLink = Uri.TryCreate(InformationCache.SelectedServerJSON.discordUrl, UriKind.Absolute, out Uri uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
catch { ServerDiscordLink = false; }
DiscordIcon.BackgroundImage = ServerDiscordLink ? Theming.DiscordIcon : Theming.DiscordIconDisabled;
DiscordInviteLink.Enabled = ServerDiscordLink;
DiscordInviteLink.Text = ServerDiscordLink ? "Discord Invite" : string.Empty;
}
catch { }
/* Homepage Display */
try
{
bool ServerWebsiteLink;
try
{
ServerWebsiteLink = Uri.TryCreate(InformationCache.SelectedServerJSON.homePageUrl, UriKind.Absolute, out Uri uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
catch { ServerWebsiteLink = false; }
HomePageIcon.BackgroundImage = ServerWebsiteLink ? Theming.HomeIcon : Theming.HomeIconDisabled;
HomePageLink.Enabled = ServerWebsiteLink;
HomePageLink.Text = ServerWebsiteLink ? "Home Page" : string.Empty;
}
catch { }
/* Facebook Group Display */
try
{
bool ServerFacebookLink;
try
{
ServerFacebookLink = Uri.TryCreate(InformationCache.SelectedServerJSON.facebookUrl, UriKind.Absolute, out Uri uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
catch { ServerFacebookLink = false; }
FacebookIcon.BackgroundImage = ServerFacebookLink ? Theming.FacebookIcon : Theming.FacebookIconDisabled;
FacebookGroupLink.Enabled = ServerFacebookLink;
FacebookGroupLink.Text = ServerFacebookLink ? "Facebook Page" : string.Empty;
}
catch { }
/* Twitter Account Display */
try
{
bool ServerTwitterLink = Uri.TryCreate(InformationCache.SelectedServerJSON.twitterUrl, UriKind.Absolute, out Uri uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
TwitterIcon.BackgroundImage = ServerTwitterLink ? Theming.TwitterIcon : Theming.TwitterIconDisabled;
TwitterAccountLink.Enabled = ServerTwitterLink;
TwitterAccountLink.Text = ServerTwitterLink ? "Twitter Feed" : string.Empty;
}
catch { }
/* Server Set Speedbug Timer Display */
try
{
serverSecondsToShutDown =
(InformationCache.SelectedServerJSON.secondsToShutDown != 0) ? InformationCache.SelectedServerJSON.secondsToShutDown : 7200;
ServerShutDown.Text = string.Format(Translations.Database("MainScreen_Text_ServerShutDown") +
" " + TimeConversions.RelativeTime(serverSecondsToShutDown));
}
catch { }
try
{
/* Scenery Group Display */
string SceneryStatus;
switch (String.Join("", InformationCache.SelectedServerJSON.activatedHolidaySceneryGroups))
{
case "SCENERY_GROUP_NEWYEARS":
SceneryStatus = "Scenery: New Years";
break;
case "SCENERY_GROUP_VALENTINES":
SceneryStatus = "Scenery: Valentines";
break;
case "SCENERY_GROUP_OKTOBERFEST":
SceneryStatus = "Scenery: Oktoberfest";
break;
case "SCENERY_GROUP_HALLOWEEN":
SceneryStatus = "Scenery: Halloween";
break;
case "SCENERY_GROUP_CHRISTMAS":
SceneryStatus = "Scenery: Christmas";
break;
default:
SceneryStatus = "Scenery: Normal";
break;
}
SceneryGroupText.Text = SceneryStatus;
}
catch { }
/* Check Selected Server Address for since nfsw currently requires being proxied for https */
if (InformationCache.SelectedServerData.IPAddress.StartsWith("https"))
{
/* This is in case it is not listed in GSI at all || is present in GSI and is set to true */
if ((!InformationCache.SelectedServerJSON.enforceLauncherProxy) || (InformationCache.SelectedServerJSON.enforceLauncherProxy != false))
{ /* So we can force the Proxy On even if a User has Disabled it */
InformationCache.SelectedServerEnforceProxy = true;
}
/* but still allow that nfsw might get patched to do https raw? */
else if (InformationCache.SelectedServerJSON.enforceLauncherProxy == false)
{ /* In which case, respect the GSI set value */
InformationCache.SelectedServerEnforceProxy = false;
}
}
/* If it's an HTTP Server, check if Proxy is being requested as Enforced On */
else if ((!InformationCache.SelectedServerJSON.enforceLauncherProxy) || (InformationCache.SelectedServerJSON.enforceLauncherProxy != true))
{ /* This is set so that it doesn't try to enforce Proxy On if user switches
* to a server that doesn't have enforceLauncherProxy set or true */
InformationCache.SelectedServerEnforceProxy = false;
}
if (InformationCache.SelectedServerJSON.maxOnlinePlayers != 0)
{
numPlayers = string.Format("{0} / {1}", InformationCache.SelectedServerJSON.onlineNumber, InformationCache.SelectedServerJSON.maxOnlinePlayers.ToString());
numRegistered = string.Format("{0}", InformationCache.SelectedServerJSON.numberOfRegistered);
}