aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/UserManagementCommands.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-05-05 11:34:17 -0400
committerMichael <[email protected]>2017-05-05 11:34:17 -0400
commit39b3b4c62c88cb94ce7a5ecefe38754aac4dc3f7 (patch)
treef70da64c0fb4b4850e87253cae05d6f234e06e5e /ShiftOS_TheReturn/UserManagementCommands.cs
parenta57b5855f5a2b7e5f89e411a5cbe66dd0dcb50d6 (diff)
downloadshiftos_thereturn-39b3b4c62c88cb94ce7a5ecefe38754aac4dc3f7.tar.gz
shiftos_thereturn-39b3b4c62c88cb94ce7a5ecefe38754aac4dc3f7.tar.bz2
shiftos_thereturn-39b3b4c62c88cb94ce7a5ecefe38754aac4dc3f7.zip
admin.set_acl and other things
Diffstat (limited to 'ShiftOS_TheReturn/UserManagementCommands.cs')
-rw-r--r--ShiftOS_TheReturn/UserManagementCommands.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs
index 62735a3..1c3c0ed 100644
--- a/ShiftOS_TheReturn/UserManagementCommands.cs
+++ b/ShiftOS_TheReturn/UserManagementCommands.cs
@@ -53,7 +53,68 @@ namespace ShiftOS.Engine
return true;
}
+ [Command("set_acl")]
+ [RequiresArgument("user")]
+ [RequiresArgument("val")]
+ public static bool SetUserPermission(Dictionary<string, object> args)
+ {
+ int permission = 0;
+ string username = args["user"].ToString();
+ try
+ {
+ permission = Convert.ToInt32(args["val"].ToString());
+ }
+ catch
+ {
+ Console.WriteLine("Error: Permission value must be an integer.");
+ return true;
+ }
+
+ if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==username) == null)
+ {
+ Console.WriteLine("Error: User not found.");
+ return true;
+ }
+
+ UserPermissions uperm = UserPermissions.Guest;
+
+ switch (permission)
+ {
+ case 0:
+ uperm = UserPermissions.Guest;
+ break;
+ case 1:
+ uperm = UserPermissions.User;
+ break;
+ case 2:
+ uperm = UserPermissions.Admin;
+ break;
+ case 3:
+ uperm = UserPermissions.Root;
+ break;
+ default:
+ Console.WriteLine("Permission value must be between 0 and 4.");
+ return true;
+ }
+
+ //Permissions are backwards... oops...
+ if(uperm < SaveSystem.CurrentUser.Permissions)
+ {
+ Console.WriteLine("Error: Cannot set user permissions to values greater than your own!");
+ return true;
+ }
+ var oldperm = SaveSystem.Users.FirstOrDefault(x => x.Username == username).Permissions;
+ if (SaveSystem.CurrentUser.Permissions > oldperm)
+ {
+ Console.WriteLine("Error: Can't set the permission of this user. They have more rights than you.");
+ return true;
+ }
+
+ SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == username).Permissions = uperm;
+ Console.WriteLine("User permissions updated.");
+ return true;
+ }
}