aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-05-01 16:06:50 -0400
committerMichael <[email protected]>2017-05-01 16:06:50 -0400
commit367e2dd6418de7d1944077588c228e80220996af (patch)
treef08391cba339a91aa78fe23901ee7c805eaa5972
parent7532df70757ecbcaf735a5fc50eee282f555741a (diff)
downloadshiftos_thereturn-367e2dd6418de7d1944077588c228e80220996af.tar.gz
shiftos_thereturn-367e2dd6418de7d1944077588c228e80220996af.tar.bz2
shiftos_thereturn-367e2dd6418de7d1944077588c228e80220996af.zip
User management commands.
-rw-r--r--ShiftOS_TheReturn/ShiftOS.Engine.csproj1
-rw-r--r--ShiftOS_TheReturn/UserManagementCommands.cs88
2 files changed, 89 insertions, 0 deletions
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/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;
+ }
+ }
+}