aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ShiftOS.WinForms/Applications/Shifter.cs7
-rw-r--r--ShiftOS.WinForms/Tools/ControlManager.cs33
-rw-r--r--ShiftOS_TheReturn/UserManagementCommands.cs238
3 files changed, 265 insertions, 13 deletions
diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs
index edc3703..acb64a5 100644
--- a/ShiftOS.WinForms/Applications/Shifter.cs
+++ b/ShiftOS.WinForms/Applications/Shifter.cs
@@ -814,15 +814,12 @@ namespace ShiftOS.WinForms.Applications
ControlManager.SetupControl(color);
color.BackColor = ((Color)c.Field.GetValue(LoadedSkin));
- color.BackColorChanged += (o, a) =>
- {
- c.Field.SetValue(LoadedSkin, color.BackColor);
- };
color.Click += (o, a) =>
{
- AppearanceManager.SetupDialog(new ColorPicker(color.BackColor, c.Name, new Action<Color>((col) =>
+ AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action<Color>((col) =>
{
color.BackColor = col;
+ c.Field.SetValue(LoadedSkin, col);
CodepointValue += 300;
InvokeSetup(cat);
diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs
index 4f888ab..fc9567d 100644
--- a/ShiftOS.WinForms/Tools/ControlManager.cs
+++ b/ShiftOS.WinForms/Tools/ControlManager.cs
@@ -220,13 +220,22 @@ namespace ShiftOS.WinForms.Tools
Desktop.InvokeOnWorkerThread(() =>
{
Button b = ctrl as Button;
- b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor;
- b.BackgroundImage = SkinEngine.GetImage("buttonidle");
- b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle");
+ if (!b.Tag.ToString().ToLower().Contains("keepbg"))
+ {
+ b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor;
+ b.BackgroundImage = SkinEngine.GetImage("buttonidle");
+ b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle");
+ }
b.FlatAppearance.BorderSize = SkinEngine.LoadedSkin.ButtonBorderWidth;
- b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor;
- b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor;
- b.Font = SkinEngine.LoadedSkin.ButtonTextFont;
+ if (!b.Tag.ToString().ToLower().Contains("keepfg"))
+ {
+ b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor;
+ b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor;
+ }
+ if(!b.Tag.ToString().ToLower().Contains("keepfont"))
+ b.Font = SkinEngine.LoadedSkin.ButtonTextFont;
+
+ Color orig_bg = b.BackColor;
b.MouseEnter += (o, a) =>
{
@@ -236,13 +245,13 @@ namespace ShiftOS.WinForms.Tools
};
b.MouseLeave += (o, a) =>
{
- b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor;
+ b.BackColor = orig_bg;
b.BackgroundImage = SkinEngine.GetImage("buttonidle");
b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle");
};
b.MouseUp += (o, a) =>
{
- b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor;
+ b.BackColor = orig_bg;
b.BackgroundImage = SkinEngine.GetImage("buttonidle");
b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle");
};
@@ -257,6 +266,14 @@ namespace ShiftOS.WinForms.Tools
});
}
+ if(ctrl is TextBox)
+ {
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ (ctrl as TextBox).BorderStyle = BorderStyle.FixedSingle;
+ });
+ }
+
ctrl.KeyDown += (o, a) =>
{
if (a.Control && a.KeyCode == Keys.T)
diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs
new file mode 100644
index 0000000..a64c99c
--- /dev/null
+++ b/ShiftOS_TheReturn/UserManagementCommands.cs
@@ -0,0 +1,238 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+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)
+ {
+ 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;
+ }
+
+ /// <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)
+ {
+ 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);
+ 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")]
+ 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;
+ }
+
+ /// <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")]
+ 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;
+ }
+ }
+}