aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server
diff options
context:
space:
mode:
authorpfg <[email protected]>2017-03-07 17:33:44 -0800
committerpfg <[email protected]>2017-03-07 17:33:44 -0800
commitb20d77edd1227b2ce53b65b0752972bd65a36e84 (patch)
treeb15615591e009c9aa472ba5d95374a064c50e8b1 /ShiftOS.Server
parent4989356d6797335b44060ae94c9af34404773506 (diff)
parent449d43d22c1d12ce6aa0243fbb4ea94481ff8f4c (diff)
downloadshiftos_thereturn-b20d77edd1227b2ce53b65b0752972bd65a36e84.tar.gz
shiftos_thereturn-b20d77edd1227b2ce53b65b0752972bd65a36e84.tar.bz2
shiftos_thereturn-b20d77edd1227b2ce53b65b0752972bd65a36e84.zip
Merge branch 'master' of https://github.com/shiftos-game/ShiftOS
Diffstat (limited to 'ShiftOS.Server')
-rw-r--r--ShiftOS.Server/Core.cs86
-rw-r--r--ShiftOS.Server/Program.cs21
-rw-r--r--ShiftOS.Server/RandomUserGenerator.cs22
3 files changed, 123 insertions, 6 deletions
diff --git a/ShiftOS.Server/Core.cs b/ShiftOS.Server/Core.cs
index 42a9127..4ec421d 100644
--- a/ShiftOS.Server/Core.cs
+++ b/ShiftOS.Server/Core.cs
@@ -125,5 +125,91 @@ namespace ShiftOS.Server
}
}
+
+ [MudRequest("getusers", typeof(string))]
+ public static void GetAllUsers(string guid, string contents)
+ {
+ List<string> accs = new List<string>();
+ if(contents == "dead")
+ {
+ foreach(var sve in Directory.GetFiles("deadsaves"))
+ {
+ if (sve.EndsWith(".save"))
+ {
+ var save = JsonConvert.DeserializeObject<Save>(File.ReadAllText(sve));
+ accs.Add($"{save.Username}@{save.SystemName}");
+ }
+
+ }
+ }
+ server.DispatchTo(new Guid(guid), new NetObject("h4xx0r", new ServerMessage
+ {
+ Name = "allusers",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(accs)
+ }));
+ }
+
+ [MudRequest("mud_save_allow_dead", typeof(Save))]
+ public static void SaveDead(string guid, Save sve)
+ {
+ if(File.Exists("saves/" + sve.Username + ".save"))
+ {
+ WriteEncFile("saves/" + sve.Username + ".save", JsonConvert.SerializeObject(sve));
+ }
+ else if(File.Exists("deadsaves/" + sve.Username + ".save"))
+ {
+ File.WriteAllText("deadsaves/" + sve.Username + ".save", JsonConvert.SerializeObject(sve));
+ }
+ }
+
+ [MudRequest("get_user_data", typeof(Dictionary<string, string>))]
+ public static void GetUserData(string guid, Dictionary<string, string> contents)
+ {
+ string usr = contents["user"];
+ string sys = contents["sysname"];
+
+ foreach(var sve in Directory.GetFiles("deadsaves"))
+ {
+ if (sve.EndsWith(".save"))
+ {
+ var saveFile = JsonConvert.DeserializeObject<Save>(File.ReadAllText(sve));
+ if(saveFile.Username == usr && saveFile.SystemName == sys)
+ {
+ server.DispatchTo(new Guid(guid), new NetObject("1337", new ServerMessage
+ {
+ Name = "user_data",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(saveFile)
+ }));
+ }
+ return;
+ }
+ }
+ foreach (var sve in Directory.GetFiles("saves"))
+ {
+ if (sve.EndsWith(".save"))
+ {
+ var saveFile = JsonConvert.DeserializeObject<Save>(ReadEncFile(sve));
+ if (saveFile.Username == usr && saveFile.SystemName == sys)
+ {
+ server.DispatchTo(new Guid(guid), new NetObject("1337", new ServerMessage
+ {
+ Name = "user_data",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(saveFile)
+ }));
+ }
+ return;
+ }
+ }
+
+ server.DispatchTo(new Guid(guid), new NetObject("n07_50_1337", new ServerMessage
+ {
+ Name = "user_data_not_found",
+ GUID = "server"
+ }));
+
+ }
}
}
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs
index 7e5a517..9093c35 100644
--- a/ShiftOS.Server/Program.cs
+++ b/ShiftOS.Server/Program.cs
@@ -123,6 +123,27 @@ namespace ShiftOS.Server
Console.WriteLine("Client connected.");
server.DispatchTo(a.Guid, new NetObject("welcome", new ServerMessage { Name = "Welcome", Contents = a.Guid.ToString(), GUID = "Server" }));
};
+
+ server.OnClientDisconnected += (o, a) =>
+ {
+ Console.WriteLine("Client disconnected.");
+ };
+
+ server.OnClientRejected += (o, a) =>
+ {
+ Console.WriteLine("FUCK. Something HORRIBLE JUST HAPPENED.");
+ };
+
+ AppDomain.CurrentDomain.UnhandledException += (o, a) =>
+ {
+ ChatBackend.Broadcast("**Automatic Broadcast:** The multi-user domain is restarting because of a crash.");
+#if DEBUG
+ ChatBackend.Broadcast("Crash summary: " + a.ExceptionObject.ToString());
+#endif
+ if(server.IsOnline == true)
+ server.Stop();
+ System.Diagnostics.Process.Start("ShiftOS.Server.exe");
+ };
server.OnReceived += (o, a) =>
{
diff --git a/ShiftOS.Server/RandomUserGenerator.cs b/ShiftOS.Server/RandomUserGenerator.cs
index afaee46..3a62f9c 100644
--- a/ShiftOS.Server/RandomUserGenerator.cs
+++ b/ShiftOS.Server/RandomUserGenerator.cs
@@ -114,11 +114,12 @@ namespace ShiftOS.Server
sve.Codepoints = rnd.Next(startCP, maxAmt);
//FS treasure generation.
-
+ /*
//create a ramdisk dir
var dir = new ShiftOS.Objects.ShiftFS.Directory();
//name the directory after the user
dir.Name = sve.Username;
+ dir.permissions = Objects.ShiftFS.Permissions.All;
//json the object and mount
string json = Newtonsoft.Json.JsonConvert.SerializeObject(dir);
//mount it to the MUD
@@ -180,16 +181,19 @@ namespace ShiftOS.Server
WriteAllBytes(kv.Value, File.ReadAllBytes(file));
}
}
- }
+ }*/
//save the save file to disk.
File.WriteAllText("deadsaves/" + sve.Username + ".save", Newtonsoft.Json.JsonConvert.SerializeObject(sve, Newtonsoft.Json.Formatting.Indented));
//We don't care about the encryption algorithm because these saves can't be logged into as regular users.
+ /*
//Now we export the mount.
string exportedMount = ExportMount(mountid);
//And save it to disk.
File.WriteAllText("deadsaves/" + sve.Username + ".mfs", exportedMount);
+ */
+
Thread.Sleep((60 * 60) * 1000); //approx. 1 hour.
@@ -214,12 +218,18 @@ namespace ShiftOS.Server
targets = new Dictionary<string, string>();
foreach(var dir in dirs)
{
- string sDir = dir.Replace("\\", "/");
- while (!sDir.StartsWith("shiftnet/"))
+ if (!string.IsNullOrWhiteSpace(dir))
{
- sDir = sDir.Remove(0, 1);
+ string sDir = dir.Replace("\\", "/");
+ if (sDir.Contains("shiftnet"))
+ {
+ while (!sDir.StartsWith("shiftnet"))
+ {
+ sDir = sDir.Remove(0, 1);
+ }
+ targets.Add(dir, output + "/" + sDir);
+ }
}
- targets.Add(dir, output + "/" + sDir);
}
}