-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
168 lines (137 loc) · 6.14 KB
/
Program.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
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.IO;
using System.Security;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using WhirlpoolCore.Loaders;
namespace WhirlpoolCore
{
class Program
{
private static SecureString TlsCertificatePassword;
private static X509Certificate2 TlsCertificate;
static async Task Main(string[] args)
{
String BlockString = "\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C\u258C";
String Milestone = "Alpha";
String BuildString = "";
byte[] TlsCertificateBytes;
if (File.Exists("BuildNumber.txt"))
{
String[] Lines = File.ReadAllLines("BuildNumber.txt");
String NewLine = "";
if (Lines.Length > 0)
{
String FinalLine = Lines[Lines.Length - 1];
String LastBuild = FinalLine.Split(new char[] { '|' })[0];
String LastBuildNumber = LastBuild.Replace(Milestone, "").Replace("Build", "");
LastBuildNumber.TrimStart();
int BuildNumber = int.Parse(LastBuildNumber) + 1;
String BuildDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + " Central (US & Canada)";
BuildString = "Build " + BuildNumber.ToString();
NewLine = Milestone + " " + BuildString + " | " + BuildDate;
}
StreamWriter Sw = File.AppendText("BuildNumber.txt");
Sw.WriteLine(NewLine);
Sw.Flush();
Sw.Close();
}
Console.Title = "Whirlpool II | " + Milestone + " " + BuildString;
Console.OutputEncoding = Encoding.UTF8;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(@"__ ___ _ _ _ ___ ___ ");
Console.WriteLine(@"\ \ / / |__ (_)_ __| |_ __ ___ ___ | | |_ _|_ _|");
Console.WriteLine(@" \ \ /\ / /| '_ \| | '__| | '_ \ / _ \ / _ \| | | | | | ");
Console.WriteLine(@" \ V V / | | | | | | | | |_) | (_) | (_) | | | | | | ");
Console.WriteLine(@" \_/\_/ |_| |_|_|_| |_| .__/ \___/ \___/|_| |___|___|");
Console.WriteLine(@" |_| ");
Console.WriteLine();
Console.WriteLine(Milestone + " " + BuildString);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(BlockString + BlockString + BlockString);
Console.WriteLine(BlockString + " Under Construction " + BlockString);
Console.WriteLine(BlockString + BlockString + BlockString);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(">> Opening socket...");
if (File.Exists("NodebayCertificate.pfx"))
{
TlsCertificateBytes = File.ReadAllBytes("NodebayCertificate.pfx");
UnlockCertificate();
}
else
{
Console.WriteLine(">> TLS Certificate not found. This build cannot proceed with boot.");
Console.ReadKey();
return;
}
while (TlsCertificate == null)
{
try
{
TlsCertificate = new X509Certificate2(TlsCertificateBytes, TlsCertificatePassword);
}
catch (CryptographicException)
{
Console.Write(">> ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Certificate password invalid. Please retry.");
Console.ForegroundColor = ConsoleColor.White;
UnlockCertificate();
}
}
Console.Write(">> ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Loaded Cert: " + TlsCertificate.Subject);
Console.ForegroundColor = ConsoleColor.White;
String GameAddress = "127.0.0.1";
int GamePort = 8443;
Socket MainSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
MainSocket.Bind(new IPEndPoint(IPAddress.Parse(GameAddress), GamePort));
Console.WriteLine(">> Game socket bound on {0}:{1}", GameAddress, GamePort);
Console.WriteLine("Whirlpool II -> Ready!");
MainSocket.Listen(120);
DataManager.InitializeData();
WorldManager.InitializeWorld();
try
{
await ConnectionManager.InitializeAsync(MainSocket, TlsCertificate);
}
catch (AuthenticationException ae)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(ae);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
static void UnlockCertificate()
{
Console.Write(">> Enter TLS Certificate Password: ");
TlsCertificatePassword = new SecureString();
while (true)
{
ConsoleKeyInfo KeyInfo = Console.ReadKey(true);
if (KeyInfo.Key == ConsoleKey.Enter)
{
Console.WriteLine();
break;
}
if (KeyInfo.Key == ConsoleKey.Backspace && TlsCertificatePassword.Length > 0)
{
TlsCertificatePassword.RemoveAt(TlsCertificatePassword.Length - 1);
}
else if (KeyInfo.Key != ConsoleKey.Backspace)
{
TlsCertificatePassword.AppendChar(KeyInfo.KeyChar);
}
}
}
}
}