From 078c729d0918b923a4b4076bd927b53cd1bcc9d7 Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Mon, 6 Mar 2017 21:24:34 +0000 Subject: server-side for auto npc generation --- ShiftOS.Server/RandomUserGenerator.cs | 277 ++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 ShiftOS.Server/RandomUserGenerator.cs (limited to 'ShiftOS.Server/RandomUserGenerator.cs') diff --git a/ShiftOS.Server/RandomUserGenerator.cs b/ShiftOS.Server/RandomUserGenerator.cs new file mode 100644 index 0000000..afaee46 --- /dev/null +++ b/ShiftOS.Server/RandomUserGenerator.cs @@ -0,0 +1,277 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Threading; +using System.IO; +using ShiftOS.Objects; +using static ShiftOS.Objects.ShiftFS.Utils; + +namespace ShiftOS.Server +{ + public static class RandomUserGenerator + { + const string USERPREFIXES = "culled;purged;anon;fatal;unaccounted;netban;killed;old"; + const string SYSNAMES = "unknown;error;dead;system;mud"; + const string PASSCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_"; + + public static void StartThread() + { + var t = new Thread(() => + { + var rnd = new Random(); + while (Program.server.IsOnline) + { + if (!Directory.Exists("deadsaves")) + { + Directory.CreateDirectory("deadsaves"); + } + + var sve = new Save(); + + int passLength = 0; + int securityGrade = rnd.Next(1, 5); + switch (securityGrade) + { + default: + passLength = 4; + break; + case 2: + passLength = 6; + break; + case 3: + passLength = 10; + break; + case 4: + passLength = 15; + break; + } + + string pass = ""; + char lastChar = '\0'; + for (int i = 0; i < passLength; i++) + { + char c = PASSCHARS[rnd.Next(0, PASSCHARS.Length)]; + while(c == lastChar) + { + c = PASSCHARS[rnd.Next(0, PASSCHARS.Length)]; + } + pass += c; + lastChar = c; //this ensures no repeated sequences. + } + + sve.Password = pass; + + int id_length = rnd.Next(3, 10); + string id = ""; + + lastChar = '\0'; + for (int i = 0; i < id_length; i++) + { + char c = PASSCHARS[rnd.Next(0, PASSCHARS.Length)]; + while (c == lastChar) + { + c = PASSCHARS[rnd.Next(0, PASSCHARS.Length)]; + } + id += c; + lastChar = c; //this ensures no repeated sequences. + } + + string[] names = USERPREFIXES.Split(';'); + string name = names[rnd.Next(0, names.Length)]; + sve.Username = $"{id}_{name}"; + + names = SYSNAMES.Split(';'); + name = names[rnd.Next(0, names.Length)]; + + sve.SystemName = name; + + //Codepoint generation. + int startCP = 0; + int maxAmt = 0; + + switch (securityGrade) + { + default: + startCP = 1000; + maxAmt = 12500; + break; + case 2: + startCP = 25000; + maxAmt = 50000; + break; + case 3: + startCP = 75000; + maxAmt = 150000; + break; + case 4: + startCP = 500000; + maxAmt = 1500000; + break; + } + + 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; + //json the object and mount + string json = Newtonsoft.Json.JsonConvert.SerializeObject(dir); + //mount it to the MUD + ShiftOS.Objects.ShiftFS.Utils.Mount(json); + //get the mount id + int mountid = ShiftOS.Objects.ShiftFS.Utils.Mounts.Count - 1; + + bool leakShiftnetDataRandomly = (rnd.Next(0, 10) > 5); + + //create home directory + CreateDirectory($"{mountid}:/home"); + //create downloads directory + CreateDirectory($"{mountid}:/home/downloads"); + //if we're leaking shiftnet data... + CreateDirectory($"{mountid}:/home/documents"); + + //alright, let's leak some shop items. + foreach(var shop in Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText("shops.json"))) + { + if(shop != null) + { + try + { + foreach(var item in shop.Items) + { + if(rnd.Next(0,10) > 5) + { + if (sve.Codepoints >= item.Cost) + { + //deduct item's codepoints. + sve.Codepoints -= item.Cost; + + //create a new file in user's downloads folder...with the item's name and binary contents inside. + WriteAllBytes($"{mountid}:/home/downloads/{item.Name}.{GetFileExt(item.FileType)}", item.MUDFile); + } + } + } + } + catch { } + } + } + + //shiftnetData + Dictionary shiftnetData = new Dictionary(); + + if(leakShiftnetDataRandomly == true) + { + //And maybe let's leak some shiftnet sites. + LeakDirectories($"{mountid}:/home/documents", out shiftnetData); + + //Now start saving the directories. + foreach(var kv in shiftnetData) + { + if(!DirectoryExists(kv.Value)) + CreateDirectory(kv.Value); + + foreach(var file in Directory.GetFiles(kv.Key)) + { + 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. + + } + }); + t.IsBackground = true; + t.Start(); + } + + public static void LeakDirectories(string output, out Dictionary targets) + { + var rnd = new Random(); + List dirs = new List(); + foreach(var pth in getDirectories("shiftnet")) + { + if(rnd.Next(0,10) > 5) + { + dirs.Add(pth); + } + } + + targets = new Dictionary(); + foreach(var dir in dirs) + { + string sDir = dir.Replace("\\", "/"); + while (!sDir.StartsWith("shiftnet/")) + { + sDir = sDir.Remove(0, 1); + } + targets.Add(dir, output + "/" + sDir); + } + + } + + private static List getDirectories(string path) + { + List paths = new List(); + foreach(var pth in Directory.GetDirectories(path)) + { + paths.AddRange(getDirectories(pth).ToArray()); + } + paths.Add(path); + return paths; + } + + public static string GetFileExt(int fType) + { + switch((FileType)fType) + { + default: + return "bin"; + case FileType.Executable: + return "sft"; + case FileType.Filesystem: + return "mfs"; + case FileType.Image: + return "pic"; + case FileType.JSON: + return "json"; + case FileType.Lua: + return "lua"; + case FileType.Skin: + return "skn"; + case FileType.TextFile: + return ".txt"; + } + } + + public enum FileType + { + TextFile, + Directory, + Mount, + UpOne, + Image, + Skin, + JSON, + Executable, + Lua, + Python, + Filesystem, + Unknown + } + } +} -- cgit v1.2.3 From bf3dbc26a5579e9c2134435d272aafe857ffd1d1 Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Tue, 7 Mar 2017 01:09:53 +0000 Subject: the mud called me a drunk --- ShiftOS.Server/RandomUserGenerator.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ShiftOS.Server/RandomUserGenerator.cs') diff --git a/ShiftOS.Server/RandomUserGenerator.cs b/ShiftOS.Server/RandomUserGenerator.cs index afaee46..8c1e430 100644 --- a/ShiftOS.Server/RandomUserGenerator.cs +++ b/ShiftOS.Server/RandomUserGenerator.cs @@ -214,12 +214,18 @@ namespace ShiftOS.Server targets = new Dictionary(); 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); } } -- cgit v1.2.3 From 01530d637d790a101ea4dcb0e183664420d98ff9 Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Tue, 7 Mar 2017 13:14:07 +0000 Subject: Fix NPC generation --- ShiftOS.Objects/ShiftFS.cs | 5 ++++- ShiftOS.Server/RandomUserGenerator.cs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'ShiftOS.Server/RandomUserGenerator.cs') diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs index e14c2a8..2c6b28b 100644 --- a/ShiftOS.Objects/ShiftFS.cs +++ b/ShiftOS.Objects/ShiftFS.cs @@ -291,10 +291,13 @@ namespace ShiftOS.Objects.ShiftFS { string[] pathlist = path.Split('/'); int vol = Convert.ToInt32(pathlist[0].Replace(":", "")); + if (Mounts[vol] == null) + Mounts[vol] = new Directory(); var dir = Mounts[vol]; + for (int i = 1; i <= pathlist.Length - 1; i++) { - dir = dir.FindDirectoryByName(pathlist[i]); + dir = dir?.FindDirectoryByName(pathlist[i]); } return dir != null; diff --git a/ShiftOS.Server/RandomUserGenerator.cs b/ShiftOS.Server/RandomUserGenerator.cs index 8c1e430..672f25d 100644 --- a/ShiftOS.Server/RandomUserGenerator.cs +++ b/ShiftOS.Server/RandomUserGenerator.cs @@ -119,6 +119,7 @@ namespace ShiftOS.Server 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 @@ -219,7 +220,7 @@ namespace ShiftOS.Server string sDir = dir.Replace("\\", "/"); if (sDir.Contains("shiftnet")) { - while (!sDir.StartsWith("shiftnet/")) + while (!sDir.StartsWith("shiftnet")) { sDir = sDir.Remove(0, 1); } -- cgit v1.2.3 From 9c143b1249e03fa63492c7aa5283bf60f88c118b Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Tue, 7 Mar 2017 14:17:58 +0000 Subject: auto crash handling --- ShiftOS.Server/Program.cs | 21 +++++++++++++++++++++ ShiftOS.Server/RandomUserGenerator.cs | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'ShiftOS.Server/RandomUserGenerator.cs') 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 672f25d..3a62f9c 100644 --- a/ShiftOS.Server/RandomUserGenerator.cs +++ b/ShiftOS.Server/RandomUserGenerator.cs @@ -114,7 +114,7 @@ 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 @@ -181,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. -- cgit v1.2.3