diff options
| author | AShifter <[email protected]> | 2017-05-02 19:43:15 -0600 |
|---|---|---|
| committer | AShifter <[email protected]> | 2017-05-02 19:43:15 -0600 |
| commit | b06801028acc3b3da80ef5077abe8f0baaa82dac (patch) | |
| tree | 5c65cccdd17f8d89125841663749cbaf970ed52a /ShiftOS_TheReturn | |
| parent | bbb21a1b32ff2642eb3f9804ef653e57a8be7e41 (diff) | |
| parent | 8381c825b1c6d4d47af23e9461ece4f4a1f88cc5 (diff) | |
| download | shiftos_thereturn-b06801028acc3b3da80ef5077abe8f0baaa82dac.tar.gz shiftos_thereturn-b06801028acc3b3da80ef5077abe8f0baaa82dac.tar.bz2 shiftos_thereturn-b06801028acc3b3da80ef5077abe8f0baaa82dac.zip | |
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/KernelWatchdog.cs | 25 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/SaveSystem.cs | 11 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/TerminalBackend.cs | 56 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/UniteClient.cs | 20 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/UniteTestCommands.cs | 10 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/UserManagementCommands.cs | 88 |
7 files changed, 192 insertions, 19 deletions
diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs index cc03f5a..430d36a 100644 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -66,41 +66,54 @@ namespace ShiftOS.Engine public static bool IsSafe(Type type) { - if (InKernelMode == true) + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) return true; foreach (var attrib in type.GetCustomAttributes(false)) { if (attrib is KernelModeAttribute) + { + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) + return true; return false; + } } return true; } public static bool IsSafe(MethodInfo type) { - if (InKernelMode == true) + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) return true; foreach (var attrib in type.GetCustomAttributes(false)) { if (attrib is KernelModeAttribute) + { + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) + return true; return false; + } } return true; } + static string regularUsername = ""; + public static void EnterKernelMode() { - InKernelMode = true; - Console.WriteLine("<kernel> Watchdog deactivated, system-level access granted."); + regularUsername = SaveSystem.CurrentUser.Username; + SaveSystem.CurrentUser = SaveSystem.Users.FirstOrDefault(x => x.Username == "root"); + } public static void LeaveKernelMode() { - InKernelMode = false; - Console.WriteLine("<kernel> Kernel mode disabled."); + var user = SaveSystem.Users.FirstOrDefault(x => x.Username == regularUsername); + if (user == null) + throw new Exception("User not in root mode."); + SaveSystem.CurrentUser = user; } internal static bool CanRunOffline(Type method) diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index a27b04f..945869b 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -198,7 +198,10 @@ namespace ShiftOS.Engine Thread.Sleep(50); Console.WriteLine("{SYSTEM_INITIATED}"); - + + if (CurrentSave.Users == null) + CurrentSave.Users = new List<ClientSave>(); + if(CurrentSave.Users.Count == 0) { @@ -294,8 +297,10 @@ namespace ShiftOS.Engine public static List<ClientSave> Users { - get; - private set; + get + { + return CurrentSave.Users; + } } public static event EmptyEventHandler GameReady; diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 5cd6c68..fb33dc5 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -133,6 +133,7 @@ <Compile Include="TutorialManager.cs" /> <Compile Include="UniteClient.cs" /> <Compile Include="UniteTestCommands.cs" /> + <Compile Include="UserManagementCommands.cs" /> <Compile Include="VirusEngine.cs" /> <Compile Include="WinOpenAttribute.cs" /> <EmbeddedResource Include="Infobox.resx"> diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 6911feb..9c57aa8 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -323,6 +323,23 @@ namespace ShiftOS.Engine } else { + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin) + { + Infobox.PromptText("Elevate to root mode", "This command cannot be run as a regular user. To run this command, please enter your password to elevate to root mode temporarily.", (pass) => + { + if (pass == SaveSystem.CurrentUser.Password) + { + KernelWatchdog.EnterKernelMode(); + RunClient(text, args, isRemote); + KernelWatchdog.LeaveKernelMode(); + } + else + { + Infobox.Show("Access denied.", "You did not type in the correct password."); + } + }, true); + return true; + } Console.Write("<"); ConsoleEx.Bold = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; @@ -332,25 +349,27 @@ namespace ShiftOS.Engine Console.Write(">"); ConsoleEx.Italic = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command."); + Console.WriteLine(" You cannot run this command. You do not have permission. Incident reported."); KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); return true; } } + } - } } } - else - { - Console.WriteLine(text + " cannot be ran in a remote session"); - return true; - } } - + else + { + Console.WriteLine(text + " cannot be ran in a remote session"); + return true; + } } + } + + else { Console.Write("<"); @@ -366,10 +385,27 @@ namespace ShiftOS.Engine return true; } + } else { - + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin) + { + Infobox.PromptText("Elevate to root mode", "This command cannot be run as a regular user. To run this command, please enter your password to elevate to root mode temporarily.", (pass) => + { + if (pass == SaveSystem.CurrentUser.Password) + { + KernelWatchdog.EnterKernelMode(); + RunClient(text, args, isRemote); + KernelWatchdog.LeaveKernelMode(); + } + else + { + Infobox.Show("Access denied.", "You did not type in the correct password."); + } + }, true); + return true; + } Console.Write("<"); ConsoleEx.Bold = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; @@ -379,7 +415,7 @@ namespace ShiftOS.Engine Console.Write(">"); ConsoleEx.Italic = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command."); + Console.WriteLine(" You cannot run this command. You do not have permission. Incident reported."); KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); return true; } diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs index 88e44af..cb08382 100644 --- a/ShiftOS_TheReturn/UniteClient.cs +++ b/ShiftOS_TheReturn/UniteClient.cs @@ -34,6 +34,26 @@ namespace ShiftOS.Unite } } + public int GetPongCP() + { + return Convert.ToInt32(MakeCall("/API/GetPongCP")); + } + + public int GetPongLevel() + { + return Convert.ToInt32(MakeCall("/API/GetPongLevel")); + } + + public void SetPongLevel(int value) + { + MakeCall("/API/SetPongLevel/" + value.ToString()); + } + + public void SetPongCP(int value) + { + MakeCall("/API/SetPongCP/" + value.ToString()); + } + public string GetEmail() { return MakeCall("/API/GetEmail"); diff --git a/ShiftOS_TheReturn/UniteTestCommands.cs b/ShiftOS_TheReturn/UniteTestCommands.cs index 37ab1ee..7a83e44 100644 --- a/ShiftOS_TheReturn/UniteTestCommands.cs +++ b/ShiftOS_TheReturn/UniteTestCommands.cs @@ -10,6 +10,16 @@ namespace ShiftOS.Engine [Namespace("unite")] public static class UniteTestCommands { + [Command("setdisplayname")] + [RequiresArgument("name")] + public static bool SetDisplayName(Dictionary<string, object> args) + { + string dname = args["name"].ToString(); + var unite = new ShiftOS.Unite.UniteClient("http://getshiftos.ml", SaveSystem.CurrentSave.UniteAuthToken); + unite.SetDisplayName(dname); + return true; + } + [Command("login")] [RequiresArgument("username")] [RequiresArgument("password")] diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs new file mode 100644 index 0000000..62735a3 --- /dev/null +++ b/ShiftOS_TheReturn/UserManagementCommands.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; + +namespace ShiftOS.Engine +{ + [Namespace("admin")] + [KernelMode] + [RequiresUpgrade("mud_fundamentals")] + public static class AdminUserManagementCommands + { + [Command("add", description = "Add a user to the system.", usage ="name:")] + [RequiresArgument("name")] + public static bool AddUser(Dictionary<string, object> args) + { + string name = args["name"].ToString(); + if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==name) != null) + { + Console.WriteLine("Error: User already exists."); + return true; + } + + var user = new ClientSave + { + Username = name, + Password = "", + Permissions = UserPermissions.User + }; + SaveSystem.CurrentSave.Users.Add(user); + Console.WriteLine($"Creating new user \"{name}\" with no password and User permissions."); + SaveSystem.SaveGame(); + return true; + } + + [Command("remove", description = "Remove a user from the system.", usage = "name:")] + [RequiresArgument("name")] + public static bool RemoveUser(Dictionary<string, object> args) + { + string name = args["name"].ToString(); + if (SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name) == null) + { + Console.WriteLine("Error: User doesn't exist."); + return true; + } + + var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name); + SaveSystem.CurrentSave.Users.Remove(user); + Console.WriteLine($"Removing user \"{name}\" from system..."); + SaveSystem.SaveGame(); + return true; + } + + + + } + + [Namespace("user")] + [RequiresUpgrade("mud_fundamentals")] + public static class UserManagementCommands + { + + + [Command("setpass", description ="Allows you to set your password to a new value.", usage ="old:,new:")] + [RequiresArgument("old")] + [RequiresArgument("new")] + public static bool SetPassword(Dictionary<string, object> args) + { + string old = args["old"].ToString(); + string newpass = args["new"].ToString(); + + if(old == SaveSystem.CurrentUser.Password) + { + SaveSystem.CurrentUser.Password = newpass; + SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == SaveSystem.CurrentUser.Username).Password = newpass; + Console.WriteLine("Password set successfully."); + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Passwords do not match."); + } + return true; + } + } +} |
