diff options
| author | AShifter <[email protected]> | 2017-05-01 13:37:48 -0600 |
|---|---|---|
| committer | AShifter <[email protected]> | 2017-05-01 13:37:48 -0600 |
| commit | d30eb35c9755cf430efa124a9a2576ab6b74c8da (patch) | |
| tree | bbf4c161697b390a96af01a36277c8dc4e52e1a0 /ShiftOS.Server | |
| parent | b842c73b04fb92d9ecaf3d8fcc2df6157c2e8652 (diff) | |
| parent | 7532df70757ecbcaf735a5fc50eee282f555741a (diff) | |
| download | shiftos_thereturn-d30eb35c9755cf430efa124a9a2576ab6b74c8da.tar.gz shiftos_thereturn-d30eb35c9755cf430efa124a9a2576ab6b74c8da.tar.bz2 shiftos_thereturn-d30eb35c9755cf430efa124a9a2576ab6b74c8da.zip | |
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS.Server')
| -rw-r--r-- | ShiftOS.Server/Program.cs | 24 | ||||
| -rw-r--r-- | ShiftOS.Server/SaveManager.cs | 58 |
2 files changed, 74 insertions, 8 deletions
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index afc2541..97c8a66 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -86,7 +86,18 @@ namespace ShiftOS.Server /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { - + 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 +117,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) => @@ -283,8 +296,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}"); @@ -312,8 +323,7 @@ namespace ShiftOS.Server try { object contents = null; - bool throwOnNull = false; - + if (mAttrib.ExpectedType == typeof(int)) { @@ -341,7 +351,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == typeof(bool)) { - throwOnNull = true; if (msg.Contents.ToLower() == "true") { contents = true; @@ -358,7 +367,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == null) { - throwOnNull = false; } else if(mAttrib.ExpectedType == typeof(string)) { diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs index 52d665b..63aa2bf 100644 --- a/ShiftOS.Server/SaveManager.cs +++ b/ShiftOS.Server/SaveManager.cs @@ -32,6 +32,7 @@ using System.IO; using Newtonsoft.Json; using NetSockets; using static ShiftOS.Server.Program; +using System.Net; namespace ShiftOS.Server { @@ -172,6 +173,9 @@ namespace ShiftOS.Server try { + + + Program.server.DispatchTo(new Guid(guid), new NetObject("auth_failed", new ServerMessage { Name = "mud_saved", @@ -179,6 +183,60 @@ namespace ShiftOS.Server })); } catch { } + + try + { + //Update the shiftos website with the user's codepoints. + if (!string.IsNullOrWhiteSpace(sav.UniteAuthToken)) + { + var wreq = WebRequest.Create("http://getshiftos.ml/API/SetCodepoints/" + sav.Codepoints.ToString()); + wreq.Headers.Add("Authentication: Token " + sav.UniteAuthToken); + wreq.GetResponse(); + } + } + catch { } + + } + + [MudRequest("mud_token_login", typeof(string))] + public static void TokenLogin(string guid, string token) + { + foreach (var savefile in Directory.GetFiles("saves")) + { + try + { + var save = JsonConvert.DeserializeObject<Save>(ReadEncFile(savefile)); + + + if (save.UniteAuthToken==token) + { + if (save.ID == new Guid()) + { + save.ID = Guid.NewGuid(); + WriteEncFile(savefile, JsonConvert.SerializeObject(save)); + } + + + Program.server.DispatchTo(new Guid(guid), new NetObject("mud_savefile", new ServerMessage + { + Name = "mud_savefile", + GUID = "server", + Contents = JsonConvert.SerializeObject(save) + })); + return; + } + } + catch { } + } + try + { + Program.server.DispatchTo(new Guid(guid), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_login_denied", + GUID = "server" + })); + } + catch { } } [MudRequest("delete_save", typeof(ClientSave))] |
