diff options
| author | william341 <[email protected]> | 2017-05-28 12:37:00 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-28 12:37:00 -0700 |
| commit | 771c20cfb3a703e0f1550fdcf9eb07b78298c944 (patch) | |
| tree | 59cb532e15ebff313fdba2be264d78ec0033f407 /ShiftOS.Server/Program.cs | |
| parent | 496b0cbf8659c99203f48210fd39c572400ae623 (diff) | |
| parent | c7ba7d733c756d196f98dd4533289a1ef4db715f (diff) | |
| download | shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.gz shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.bz2 shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.zip | |
Merge pull request #1 from shiftos-game/master
welp, no longer a dev.
Diffstat (limited to 'ShiftOS.Server/Program.cs')
| -rw-r--r-- | ShiftOS.Server/Program.cs | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 04d7b2e..c880321 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -86,7 +86,25 @@ namespace ShiftOS.Server /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { - + Thread.Sleep(2000); + AppDomain.CurrentDomain.UnhandledException += (o, a) => + { + System.Diagnostics.Process.Start("ShiftOS.Server.exe"); + Environment.Exit(0); + }; + UserConfig.Get(); + System.Timers.Timer tmr = new System.Timers.Timer(5000); + tmr.Elapsed += (o, a) => + { + if (server.IsOnline) + { + server.DispatchAll(new NetObject("heartbeat", new ServerMessage + { + Name = "heartbeat", + GUID = "server" + })); + } + }; if (!Directory.Exists("saves")) { Directory.CreateDirectory("saves"); @@ -106,11 +124,13 @@ namespace ShiftOS.Server { Console.WriteLine($"Server started on address {server.Address}, port {server.Port}."); ServerStarted?.Invoke(server.Address.ToString()); - }; + tmr.Start(); + }; server.OnStopped += (o, a) => { Console.WriteLine("WARNING! Server stopped."); + tmr.Stop(); }; server.OnError += (o, a) => @@ -121,8 +141,32 @@ namespace ShiftOS.Server server.OnClientAccepted += (o, a) => { Console.WriteLine("Client connected."); - server.DispatchTo(a.Guid, new NetObject("welcome", new ServerMessage { Name = "Welcome", Contents = a.Guid.ToString(), GUID = "Server" })); - }; + try + { + server.DispatchTo(a.Guid, new NetObject("welcome", new ServerMessage { Name = "Welcome", Contents = a.Guid.ToString(), GUID = "Server" })); + } + catch + { + Console.WriteLine("Oh, you don't have time to finish the handshake? Fine. Get off."); + } + }; + + server.OnClientDisconnected += (o, a) => + { + Console.WriteLine("Client disconnected."); + }; + + server.OnClientRejected += (o, a) => + { + Console.WriteLine("FUCK. Something HORRIBLE JUST HAPPENED."); + }; + + AppDomain.CurrentDomain.UnhandledException += (o, a) => + { + if(server.IsOnline == true) + server.Stop(); + System.Diagnostics.Process.Start("ShiftOS.Server.exe"); + }; server.OnReceived += (o, a) => { @@ -164,8 +208,13 @@ namespace ShiftOS.Server Console.WriteLine("Server stopping."); }; + + /* var task = ChatBackend.StartDiscordBots(); task.Wait(); + */ + + RandomUserGenerator.StartThread(); while (server.IsOnline) { @@ -254,8 +303,6 @@ namespace ShiftOS.Server /// <param name="msg">Message.</param> public static void Interpret(ServerMessage msg) { - Dictionary<string, object> args = null; - try { Console.WriteLine($@"[{DateTime.Now}] Message received from {msg.GUID}: {msg.Name}"); @@ -283,8 +330,7 @@ namespace ShiftOS.Server try { object contents = null; - bool throwOnNull = false; - + if (mAttrib.ExpectedType == typeof(int)) { @@ -312,7 +358,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == typeof(bool)) { - throwOnNull = true; if (msg.Contents.ToLower() == "true") { contents = true; @@ -329,7 +374,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == null) { - throwOnNull = false; } else if(mAttrib.ExpectedType == typeof(string)) { |
