diff options
| author | AShifter <[email protected]> | 2017-06-05 09:49:46 -0600 |
|---|---|---|
| committer | AShifter <[email protected]> | 2017-06-05 09:49:46 -0600 |
| commit | 61c906e596145bbedd60725c6dcee68c34a27907 (patch) | |
| tree | cd7a00d501affe96028bfb21a8dec90c2ee63f2c /ShiftOS_TheReturn/UserManagementCommands.cs | |
| parent | 66ea2cf2fdeeaa025bd22961a0400423233c505d (diff) | |
| parent | 3e11eca70481841b6e2f2253d667944779cfd5fb (diff) | |
| download | shiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.tar.gz shiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.tar.bz2 shiftos_thereturn-61c906e596145bbedd60725c6dcee68c34a27907.zip | |
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS_TheReturn/UserManagementCommands.cs')
| -rw-r--r-- | ShiftOS_TheReturn/UserManagementCommands.cs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs index 1c3c0ed..a64c99c 100644 --- a/ShiftOS_TheReturn/UserManagementCommands.cs +++ b/ShiftOS_TheReturn/UserManagementCommands.cs @@ -7,11 +7,19 @@ using ShiftOS.Objects; namespace ShiftOS.Engine { + /// <summary> + /// Administrative user management terminal commands. + /// </summary> [Namespace("admin")] [KernelMode] [RequiresUpgrade("mud_fundamentals")] public static class AdminUserManagementCommands { + /// <summary> + /// Add a user to the system. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> [Command("add", description = "Add a user to the system.", usage ="name:")] [RequiresArgument("name")] public static bool AddUser(Dictionary<string, object> args) @@ -35,6 +43,12 @@ namespace ShiftOS.Engine return true; } + /// <summary> + /// Remove a user from the system. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> + [Command("remove", description = "Remove a user from the system.", usage = "name:")] [RequiresArgument("name")] public static bool RemoveUser(Dictionary<string, object> args) @@ -47,12 +61,25 @@ namespace ShiftOS.Engine } var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name); + if(user.Username != SaveSystem.CurrentUser.Username) + { + Console.WriteLine("Error: Cannot remove yourself."); + return true; + } SaveSystem.CurrentSave.Users.Remove(user); Console.WriteLine($"Removing user \"{name}\" from system..."); SaveSystem.SaveGame(); return true; } + + + /// <summary> + /// Set access control level for a user. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> + [Command("set_acl")] [RequiresArgument("user")] [RequiresArgument("val")] @@ -116,14 +143,76 @@ namespace ShiftOS.Engine return true; } + /// <summary> + /// List all users in the system. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> + + [Command("users", description = "Get a list of all users on the system.")] + public static bool GetUsers() + { + foreach (var u in SaveSystem.CurrentSave.Users) + { + if (u.Username == SaveSystem.CurrentUser.Username) + { + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + } + else + { + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + ConsoleEx.Bold = false; + } + Console.WriteLine(u.Username); + } + return true; + } } + /// <summary> + /// Non-administrative user management terminal commands. + /// </summary> [Namespace("user")] [RequiresUpgrade("mud_fundamentals")] public static class UserManagementCommands { + /// <summary> + /// Log in as another user. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> + [Command("login", description = "Log in as another user.")] + [RequiresArgument("user")] + [RequiresArgument("pass")] + public static bool Login(Dictionary<string, object> args) + { + string user = args["user"].ToString(); + string pass = args["pass"].ToString(); + + var usr = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == user); + if(usr==null) + { + Console.WriteLine("Error: No such user."); + return true; + } + if (usr.Password != pass) + { + Console.WriteLine("Access denied."); + return true; + } + + SaveSystem.CurrentUser = usr; + Console.WriteLine("Access granted."); + return true; + } + /// <summary> + /// Set the password for the current user. + /// </summary> + /// <param name="args">Command arguments.</param> + /// <returns>Command result.</returns> [Command("setpass", description ="Allows you to set your password to a new value.", usage ="old:,new:")] [RequiresArgument("old")] [RequiresArgument("new")] |
