aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Server')
-rw-r--r--ShiftOS.Server/Program.cs24
-rw-r--r--ShiftOS.Server/SaveManager.cs58
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))]