From 505073b6938fc8be8b91807a69bd67e45ed4382f Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Mon, 29 May 2017 16:41:49 +0000 Subject: [PATCH] Fix server-side crash when kiading revoked api keys --- ShiftOS.Objects/Save.cs | 23 +++++++++++++---------- ShiftOS.Server/Program.cs | 13 +++++++++---- ShiftOS.Server/SaveManager.cs | 26 +++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index f4e1e09..8675a35 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -47,24 +47,27 @@ namespace ShiftOS.Objects { get { - if (!string.IsNullOrWhiteSpace(UniteAuthToken)) + try { var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); return uc.GetCodepoints(); } - else + catch + { return _cp; + } } set { - if (!string.IsNullOrWhiteSpace(UniteAuthToken)) - { - var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); - uc.SetCodepoints(value); - } - else - _cp = value; - + try + { + var uc = new ShiftOS.Unite.UniteClient("", UniteAuthToken); + uc.SetCodepoints(value); + } + catch + { + _cp = value; + } } } diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index c880321..e1dcdf2 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -98,11 +98,16 @@ namespace ShiftOS.Server { if (server.IsOnline) { - server.DispatchAll(new NetObject("heartbeat", new ServerMessage + + try { - Name = "heartbeat", - GUID = "server" - })); + server.DispatchAll(new NetObject("heartbeat", new ServerMessage + { + Name = "heartbeat", + GUID = "server" + })); + } + catch { } } }; if (!Directory.Exists("saves")) diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs index d81a1a7..bb71c71 100644 --- a/ShiftOS.Server/SaveManager.cs +++ b/ShiftOS.Server/SaveManager.cs @@ -207,7 +207,6 @@ namespace ShiftOS.Server { var save = JsonConvert.DeserializeObject(ReadEncFile(savefile)); - if (save.UniteAuthToken==token) { if (save.ID == new Guid()) @@ -216,6 +215,31 @@ namespace ShiftOS.Server WriteEncFile(savefile, JsonConvert.SerializeObject(save)); } + var wr = HttpWebRequest.Create(UserConfig.Get().UniteUrl + "/API/GetCodepoints"); + wr.Headers.Add("Authentication: Token " + save.UniteAuthToken); + try + { + using(var resp = wr.GetResponse()) + { + using(var str = resp.GetResponseStream()) + { + using(var reader = new StreamReader(str)) + { + Console.WriteLine("This user has " + reader.ReadToEnd() + " Codepoint(s)."); + } + } + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + Program.server.DispatchTo(new Guid(guid), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_login_denied", + GUID = "server" + })); + return; + } Program.server.DispatchTo(new Guid(guid), new NetObject("mud_savefile", new ServerMessage {