Fix server-side crash when kiading revoked api keys

This commit is contained in:
Michael VanOverbeek 2017-05-29 16:41:49 +00:00
parent 58c9152351
commit 505073b693
3 changed files with 47 additions and 15 deletions

View file

@ -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;
}
}
}

View file

@ -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"))

View file

@ -207,7 +207,6 @@ namespace ShiftOS.Server
{
var save = JsonConvert.DeserializeObject<Save>(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
{