SidePanel system, system status, crapton of other neat things

This commit is contained in:
Michael 2017-07-13 08:40:47 -04:00
parent af01804c0f
commit e92af1bc7f
20 changed files with 225 additions and 1767 deletions

View file

@ -8,6 +8,8 @@ using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.Apps
{
[Launcher("Shiftorium", false, null, "Utilities")]
[DefaultTitle("Shiftorium")]
[WinOpen("shiftorium")]
public class CodeShop : GUI.Control, IShiftOSWindow
{

View file

@ -9,7 +9,7 @@ using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.Apps
{
[Launcher("{TITLE_PONG}", true, "al_pong", "{AL_GAMES}")]
[Launcher("{TITLE_PONG}", false, null, "{AL_GAMES}")]
[WinOpen("{WO_PONG}")]
[DefaultTitle("{TITLE_PONG}")]
[DefaultIcon("iconPong")]

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
using ShiftOS.Frontend.Desktop;
using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.Apps
{
[WinOpen("systemstatus")]
[Launcher("System Status", false, null, "System")]
[DefaultTitle("System Status")]
[SidePanel]
public class SystemStatus : GUI.Control, IShiftOSWindow
{
GUI.TextControl _header = null;
GUI.TextControl _mainstatus = null;
public SystemStatus()
{
Width = 720;
Height = 480;
_header = new GUI.TextControl();
_mainstatus = new GUI.TextControl();
AddControl(_header);
AddControl(_mainstatus);
_header.AutoSize = true;
_header.Text = "System Status";
}
public void OnLoad()
{
}
public void OnSkinLoad()
{
}
public bool OnUnload()
{
return true;
}
public void OnUpgrade()
{
}
protected override void OnLayout()
{
_header.Font = SkinEngine.LoadedSkin.HeaderFont;
_header.X = 20;
_header.Y = 20;
_mainstatus.X = 20;
_mainstatus.Y = _header.Y + _header.Height + 10;
_mainstatus.Width = Width - 40;
_mainstatus.Height = Height - (_header.Y + _header.Height) - 40;
_mainstatus.Text = $@"Codepoints: {SaveSystem.CurrentSave.Codepoints}
Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed, {Shiftorium.GetDefaults().Count} available
Filesystems:
";
foreach(var mount in Objects.ShiftFS.Utils.Mounts)
{
_mainstatus.Text += $" - {Objects.ShiftFS.Utils.Mounts.IndexOf(mount)}:/ ({mount.Name}){Environment.NewLine}";
}
_mainstatus.Text += $@"
Username: {SaveSystem.CurrentSave.Username}
System name: {SaveSystem.CurrentSave.SystemName}
RAM usage: 0MB/0MB <nyi>
Open programs: {AppearanceManager.OpenForms.Count}";
}
protected override void OnPaint(GraphicsContext gfx)
{
base.OnPaint(gfx);
}
}
}

View file

@ -39,12 +39,9 @@ namespace ShiftOS.Frontend.Apps
TerminalBackend.PrintPrompt();
SaveSystem.GameReady += () =>
{
if (Shiftorium.UpgradeInstalled("desktop"))
{
AppearanceManager.Close(this);
}
else
TerminalBackend.PrintPrompt();
Console.WriteLine("[sessionmgr] Starting system UI...");
AppearanceManager.SetupWindow(new SystemStatus());
TerminalBackend.PrintPrompt();
};
}
@ -214,7 +211,7 @@ namespace ShiftOS.Frontend.Apps
{
if (TerminalBackend.PrefixEnabled)
{
text3 = text4.Remove(0, $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
}
TerminalBackend.LastCommand = text3;
TerminalBackend.SendText(text4);
@ -250,7 +247,7 @@ namespace ShiftOS.Frontend.Apps
{
var tostring3 = Lines[Lines.Length - 1];
var tostringlen = tostring3.Length + 1;
var workaround = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var derp = workaround.Length + 1;
if (tostringlen != derp)
{
@ -271,7 +268,7 @@ namespace ShiftOS.Frontend.Apps
{
var getstring = Lines[Lines.Length - 1];
var stringlen = getstring.Length + 1;
var header = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ";
var headerlen = header.Length + 1;
var selstart = Index;
var remstrlen = Text.Length - stringlen;
@ -287,7 +284,7 @@ namespace ShiftOS.Frontend.Apps
else if (a.Key == Keys.Up)
{
var tostring3 = Lines[Lines.Length - 1];
if (tostring3 == $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ")
Console.Write(TerminalBackend.LastCommand);
ConsoleEx.OnFlush?.Invoke();
return;

View file

@ -190,7 +190,10 @@ namespace ShiftOS.Frontend.Desktop
protected override void OnLayout()
{
SendToBack();
if (alOpen)
BringToFront();
else
SendToBack();
X = 0;
Y = 0;
Width = GetSize().Width;

View file

@ -13,8 +13,26 @@ using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Frontend.Desktop
{
public static class ShiftOSWindowExtensions
{
public static bool IsSidePanel(this IWindowBorder border)
{
var win = border.ParentWindow.GetType();
var attr = win.GetCustomAttributes(false).FirstOrDefault(x => x is SidePanel);
return attr != null;
}
}
public class WindowManager : Engine.WindowManager
{
public int DesktopStart
{
get
{
return (LoadedSkin.DesktopPanelPosition == 1) ? 0 : LoadedSkin.DesktopPanelHeight;
}
}
public override void Close(IShiftOSWindow win)
{
var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win);
@ -91,10 +109,15 @@ namespace ShiftOS.Frontend.Desktop
Console.WriteLine("Application not found on system.");
return;
}
while(AppearanceManager.OpenForms.Count >= MaxCount)
while (AppearanceManager.OpenForms.Where(x => !x.IsSidePanel()).Count() >= MaxCount)
{
AppearanceManager.OpenForms[0].Close();
AppearanceManager.OpenForms.RemoveAt(0);
var brdr = AppearanceManager.OpenForms.FirstOrDefault(x => !x.IsSidePanel());
if (brdr != null)
{
brdr.Close();
AppearanceManager.OpenForms.Remove(brdr);
}
}
var wb = new WindowBorder();
wb.Width = (win as GUI.Control).Width + LoadedSkin.LeftBorderWidth + LoadedSkin.RightBorderWidth;
@ -107,22 +130,31 @@ namespace ShiftOS.Frontend.Desktop
win.OnLoad();
win.OnUpgrade();
win.OnSkinLoad();
if (!Shiftorium.UpgradeInstalled("wm_free_placement"))
{
TileWindows();
}
TileWindows();
}
public void TileWindows()
{
if (AppearanceManager.OpenForms.Count == 0)
return;
else if(AppearanceManager.OpenForms.Count == 1)
int start = 0;
var brdr = AppearanceManager.OpenForms.FirstOrDefault(x => x.IsSidePanel()) as WindowBorder;
if (brdr != null)
{
var wb = (WindowBorder)AppearanceManager.OpenForms[0];
wb.X = 0;
wb.Y = 0;
wb.ResizeWindow(UIManager.Viewport.Width, UIManager.Viewport.Height);
brdr.X = 0;
brdr.Y = DesktopStart;
brdr.ResizeWindow(UIManager.Viewport.Width / 4, UIManager.Viewport.Height - LoadedSkin.DesktopPanelHeight);
start = UIManager.Viewport.Width / 4;
}
var wb = (WindowBorder)AppearanceManager.OpenForms.FirstOrDefault(x => !x.IsSidePanel());
if (wb != null)
{
wb.X = start;
wb.Y = DesktopStart;
wb.ResizeWindow(UIManager.Viewport.Width - start, UIManager.Viewport.Height - LoadedSkin.DesktopPanelHeight);
}
}
}
@ -134,10 +166,10 @@ namespace ShiftOS.Frontend.Desktop
public void ResizeWindow(int width, int height)
{
int titleheight = Shiftorium.UpgradeInstalled("wm_titlebar") ? LoadedSkin.TitlebarHeight : 0;
int leftwidth = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.LeftBorderWidth : 0;
int bottomheight = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
int rightwidth = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
int titleheight = LoadedSkin.TitlebarHeight;
int leftwidth = LoadedSkin.LeftBorderWidth;
int bottomheight = LoadedSkin.BottomBorderWidth;
int rightwidth = LoadedSkin.RightBorderWidth;
_hostedwindow.Width = width - leftwidth - rightwidth;
_hostedwindow.Height = height - bottomheight - titleheight;
Width = width;
@ -149,37 +181,8 @@ namespace ShiftOS.Frontend.Desktop
{
X = 720;
Y = 480;
MouseDown += () =>
{
var scnloc = PointToScreen(MouseX, MouseY);
mouseprevx = scnloc.X;
mouseprevy = scnloc.Y;
moving = true;
};
MouseMove += (loc) =>
{
if (moving == true)
{
var scnloc = PointToScreen(MouseX, MouseY);
int differencex = scnloc.X - mouseprevx;
int differencey = scnloc.Y - mouseprevy;
X -= differencex;
Y -= differencey;
mouseprevx = scnloc.X;
mouseprevy = scnloc.Y;
}
};
MouseUp += () =>
{
moving = false;
};
}
private bool moving = false;
private int mouseprevx = 0;
private int mouseprevy = 0;
public IShiftOSWindow ParentWindow
{
get
@ -223,16 +226,10 @@ namespace ShiftOS.Frontend.Desktop
protected override void OnLayout()
{
if (moving)
{
var screenpoint = PointToScreen(MouseX, MouseY);
this.X = lastmousex + screenpoint.X;
this.Y = lastmousey + screenpoint.Y;
}
int titlebarheight = Shiftorium.UpgradeInstalled("wm_titlebar") ? LoadedSkin.TitlebarHeight : 0;
int borderleft = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.LeftBorderWidth : 0;
int borderright = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
int borderbottom = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
int titlebarheight = LoadedSkin.TitlebarHeight;
int borderleft = LoadedSkin.LeftBorderWidth;
int borderright = LoadedSkin.RightBorderWidth;
int borderbottom = LoadedSkin.BottomBorderWidth;
_hostedwindow.X = borderleft;
_hostedwindow.Y = titlebarheight;
Width = _hostedwindow.X + _hostedwindow.Width + LoadedSkin.RightBorderWidth;
@ -248,8 +245,6 @@ namespace ShiftOS.Frontend.Desktop
int rightborderwidth = LoadedSkin.RightBorderWidth;
int bottomborderwidth = LoadedSkin.BottomBorderWidth;
if (Shiftorium.UpgradeInstalled("wm_titlebar"))
{
var titlebarcolor = UIManager.SkinTextures["TitleBackgroundColor"];
var titlefont = LoadedSkin.TitleFont;
var titletextcolor = LoadedSkin.TitleTextColor;
@ -320,8 +315,6 @@ namespace ShiftOS.Frontend.Desktop
var tbuttonpos = LoadedSkin.TitleButtonPosition;
//Draw close button
if(Shiftorium.UpgradeInstalled("close_button"))
{
var closebuttonsize = LoadedSkin.CloseButtonSize;
var closebuttonright = LoadedSkin.CloseButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
@ -334,13 +327,11 @@ namespace ShiftOS.Frontend.Desktop
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["closebutton"]);
}
}
//Draw maximize button
if (Shiftorium.UpgradeInstalled("maximize_button"))
{
var closebuttonsize = LoadedSkin.MaximizeButtonSize;
var closebuttonright = LoadedSkin.MaximizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonsize = LoadedSkin.MaximizeButtonSize;
closebuttonright = LoadedSkin.MaximizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
if (!UIManager.SkinTextures.ContainsKey("maximizebutton"))
@ -351,34 +342,23 @@ namespace ShiftOS.Frontend.Desktop
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["maximizebutton"]);
}
}
//Draw minimize button
if (Shiftorium.UpgradeInstalled("minimize_button"))
{
var closebuttonsize = LoadedSkin.MinimizeButtonSize;
var closebuttonright = LoadedSkin.MinimizeButtonFromSide;
closebuttonsize = LoadedSkin.MinimizeButtonSize;
closebuttonright = LoadedSkin.MinimizeButtonFromSide;
if (LoadedSkin.TitleButtonPosition == 0)
closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
if (!UIManager.SkinTextures.ContainsKey("minimizebutton"))
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["MinimizeButtonColor"]);
}
else
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["minimizebutton"]);
}
}
if (!UIManager.SkinTextures.ContainsKey("minimizebutton"))
{
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["MinimizeButtonColor"]);
}
else
{
//Set the titleheight to 0.
titleheight = 0;
gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["minimizebutton"]);
}
if (Shiftorium.UpgradeInstalled("window_borders"))
{
//Some variables we'll need...
int bottomlocy = Height - LoadedSkin.BottomBorderWidth;
int bottomlocx = leftborderwidth;
@ -433,17 +413,17 @@ namespace ShiftOS.Frontend.Desktop
gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["leftborder"]);
}
//RIGHT
if (!UIManager.SkinTextures.ContainsKey("rightborder"))
{
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, borderrightcolor);
}
else
{
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["rightborder"]);
}
//RIGHT
if (!UIManager.SkinTextures.ContainsKey("rightborder"))
{
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, borderrightcolor);
}
else
{
gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["rightborder"]);
}
gfx.DrawRectangle(leftborderwidth, titleheight, Width - leftborderwidth - rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["ControlColor"]);
//So here's what we're gonna do now.
@ -477,4 +457,10 @@ namespace ShiftOS.Frontend.Desktop
return tex2;
}
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class SidePanel : Attribute
{
}
}

View file

@ -38,6 +38,19 @@ namespace ShiftOS.Frontend.GUI
private int _mouseY = 0;
private bool _captureMouse = false;
public void BringToFront()
{
if(_parent != null)
{
_parent._children.Remove(this);
_parent.AddControl(this);
}
else
{
UIManager.BringToFront(this);
}
}
public bool RequiresPaint
{
get

View file

@ -135,13 +135,13 @@ namespace ShiftOS.Frontend.GUI
if(i == selectedIndex)
{
//draw the string as selected
gfx.DrawRectangle(x, y, width, height, UIManager.SkinTextures["ControlTextColor"]);
gfx.DrawString(items[i].ToString(), x, y, LoadedSkin.ControlColor.ToMonoColor(), LoadedSkin.MainFont);
gfx.DrawRectangle(x, y+2, width, height, UIManager.SkinTextures["ControlTextColor"]);
gfx.DrawString(items[i].ToString(), x, y+2, LoadedSkin.ControlColor.ToMonoColor(), LoadedSkin.MainFont);
}
else
{
gfx.DrawRectangle(x, y, width, height, UIManager.SkinTextures["ControlColor"]);
gfx.DrawString(items[i].ToString(), x, y, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.MainFont);
gfx.DrawRectangle(x, y+2, width, height, UIManager.SkinTextures["ControlColor"]);
gfx.DrawString(items[i].ToString(), x, y+2, LoadedSkin.ControlTextColor.ToMonoColor(), LoadedSkin.MainFont);
}
}

View file

@ -19,6 +19,12 @@ namespace ShiftOS.Frontend.GraphicsSubsystem
public static System.Drawing.Size Viewport { get; set; }
public static GUI.Control FocusedControl = null;
public static void BringToFront(GUI.Control ctrl)
{
topLevels.Remove(ctrl);
topLevels.Add(ctrl);
}
public static void LayoutUpdate()
{
foreach (var toplevel in topLevels.ToArray())

View file

@ -182,6 +182,16 @@ namespace ShiftOS.Frontend
this.Layout();
}
protected override void OnLayout()
{
try
{
btnok.Y = this.Height - btnok.Height - 10;
flyesno.Y = this.Height - flyesno.Height - 10;
}
catch { }
}
private Control panel1;
private TextControl lbmessage;

File diff suppressed because it is too large Load diff

View file

@ -44,6 +44,7 @@
<ItemGroup>
<Compile Include="Apps\CodeShop.cs" />
<Compile Include="Apps\Pong.cs" />
<Compile Include="Apps\SystemStatus.cs" />
<Compile Include="Apps\Terminal.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Desktop\Desktop.cs" />

View file

@ -39,8 +39,7 @@ namespace ShiftOS.Objects
public bool SoundEnabled = true;
public int MusicVolume = 100;
[Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")]
public string Username { get; set; }
public string Username = "user";
public bool IsSandbox = false;
@ -49,48 +48,9 @@ namespace ShiftOS.Objects
public Dictionary<string, bool> Upgrades { get; set; }
public int StoryPosition { get; set; }
public string Language { get; set; }
public string MyShop { get; set; }
public List<string> CurrentLegions { get; set; }
public int MajorVersion { get; set; }
public int MinorVersion { get; set; }
public int Revision { get; set; }
public string UniteAuthToken { get; set; }
public bool IsPatreon { get; set; }
public UserClass Class { get; set; }
public double RawReputation { get; set; }
public Reputation Reputation
{
get
{
return (Reputation)((int)Math.Round(RawReputation));
}
}
public string Password { get; set; }
public bool PasswordHashed { get; set; }
public string SystemName { get; set; }
private dynamic _settings = new SettingsObject();
public int ShiftnetSubscription { get; set; }
public Guid ID { get; set; }
public bool IsMUDAdmin { get; set; }
public dynamic Settings
{
get
{
return _settings;
}
}
public int LastMonthPaid { get; set; }
public List<string> StoriesExperienced { get; set; }
public int CountUpgrades()
@ -104,8 +64,6 @@ namespace ShiftOS.Objects
return count;
}
public List<ClientSave> Users { get; set; }
/// <summary>
/// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job.
/// </summary>

View file

@ -66,38 +66,10 @@ namespace ShiftOS.Engine
}
}
public static bool IsSafe(TerminalBackend.TerminalCommand cmd)
{
if (!cmd.RequiresElevation)
return true;
else
{
if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root)
return true;
else
return false;
}
}
static string regularUsername = ""; //put regular username in here later
public static void EnterKernelMode()
{
regularUsername = SaveSystem.CurrentUser.Username; // k for now put user's username in here for the time being
SaveSystem.CurrentUser = SaveSystem.Users.FirstOrDefault(x => x.Username == "root"); // now their username is root
}
public static void LeaveKernelMode()
{
var user = SaveSystem.Users.FirstOrDefault(x => x.Username == regularUsername); //finds username
if (user == null)
throw new Exception("User not in root mode."); // fuck this means the user isnt root quick throw error
SaveSystem.CurrentUser = user;
}
//determines if you can disconnect from mud if there are no applications that currently need to
internal static bool CanRunOffline(Type method)
{

View file

@ -128,7 +128,7 @@ namespace ShiftOS.Engine
{
try
{
usernameReplace = SaveSystem.CurrentUser.Username;
usernameReplace = SaveSystem.CurrentSave.Username;
}
catch
{

View file

@ -58,11 +58,6 @@ namespace ShiftOS.Engine
/// </summary>
public static bool ShuttingDown = false;
/// <summary>
/// Gets or sets the current logged in client-side user.
/// </summary>
public static ClientSave CurrentUser { get; set; }
/// <summary>
/// Boolean representing whether the save system is ready to be used.
/// </summary>
@ -206,44 +201,21 @@ namespace ShiftOS.Engine
CurrentSave = new Save
{
IsSandbox = true,
Username = "sandbox",
Password = "sandbox",
Username = "user",
SystemName = "shiftos",
Users = new List<ClientSave>
{
new ClientSave
{
Username = "user",
Password = "",
Permissions = 0
}
},
Class = 0,
ID = new Guid(),
Upgrades = new Dictionary<string, bool>(),
CurrentLegions = null,
IsMUDAdmin = false,
IsPatreon = false,
Language = "english",
LastMonthPaid = 0,
MajorVersion = 1,
MinorVersion = 0,
MusicEnabled = false,
MusicVolume = 100,
MyShop = "",
PasswordHashed = false,
PickupPoint = "",
RawReputation = 0.0f,
Revision = 0,
ShiftnetSubscription = 0,
SoundEnabled = true,
StoriesExperienced = null,
StoryPosition = 0,
UniteAuthToken = "",
};
CurrentUser = CurrentSave.Users.First();
Localization.SetupTHETRUEDefaultLocals();
Shiftorium.Init();
@ -358,8 +330,6 @@ namespace ShiftOS.Engine
goto Sysname;
}
if (CurrentSave.Users == null)
CurrentSave.Users = new List<ClientSave>();
Console.WriteLine($@"
`-:/++++::.`
@ -376,7 +346,7 @@ namespace ShiftOS.Engine
oMM+ sMMMMMMMMMN+` `-/smMMMMMMMMMMM: hMM:
sMM+ sMMMMMMMMMMMMds/-` .sMMMMMMMMM/ yMM/
+MMs +MMMMMMMMMMMMMMMMMmhs:` +MMMMMMMM- dMM- {{GEN_SYSTEMNAME}}: {CurrentSave.SystemName.ToUpper()}
.MMm `NMMMMMMMMMMMMMMMMMMMMMo `NMMMMMMd .MMN {{GEN_USERS}}: {Users.Count()}.
.MMm `NMMMMMMMMMMMMMMMMMMMMMo `NMMMMMMd .MMN
hMM+ +MMMMMMmsdNMMMMMMMMMMN/ -MMMMMMN- yMM+
`NMN- oMMMMMd `-/+osso+- .mMMMMMN: +MMd
-NMN: /NMMMm` :yMMMMMMm- oMMd`
@ -388,118 +358,7 @@ namespace ShiftOS.Engine
`:+yhmNNMMMMNNdhs+-
```` ");
if (CurrentSave.Users.Count == 0)
{
CurrentSave.Users.Add(new ClientSave
{
Username = "root",
Password = "",
Permissions = UserPermissions.Root
});
Console.WriteLine("{MISC_NOUSERS}");
}
TerminalBackend.InStory = false;
TerminalBackend.PrefixEnabled = false;
if (LoginManager.ShouldUseGUILogin)
{
Action<ClientSave> Completed = null;
Completed += (user) =>
{
CurrentUser = user;
LoginManager.LoginComplete -= Completed;
};
LoginManager.LoginComplete += Completed;
Desktop.InvokeOnWorkerThread(() =>
{
LoginManager.PromptForLogin();
});
while (CurrentUser == null)
{
Thread.Sleep(10);
}
}
else
{
Login:
string username = "";
int progress = 0;
bool goback = false;
TextSentEventHandler ev = null;
string loginstr = Localization.Parse("{GEN_LPROMPT}", new Dictionary<string, string>
{
["%sysname"] = CurrentSave.SystemName
});
ev = (text) =>
{
if (progress == 0)
{
string getuser = text.Remove(0, loginstr.Length);
if (!string.IsNullOrWhiteSpace(getuser))
{
if (CurrentSave.Users.FirstOrDefault(x => x.Username == getuser) == null)
{
Console.WriteLine();
Console.WriteLine("{ERR_NOUSER}");
goback = true;
progress++;
TerminalBackend.TextSent -= ev;
return;
}
username = getuser;
progress++;
}
else
{
Console.WriteLine();
Console.WriteLine("{ERR_NOUSER}");
TerminalBackend.TextSent -= ev;
goback = true;
progress++;
}
}
else if (progress == 1)
{
string passwordstr = Localization.Parse("{GEN_PASSWORD}: ");
string getpass = text.Remove(0, passwordstr.Length);
var user = CurrentSave.Users.FirstOrDefault(x => x.Username == username);
if (user.Password == getpass)
{
Console.WriteLine();
Console.WriteLine("{GEN_WELCOME}");
CurrentUser = user;
progress++;
}
else
{
Console.WriteLine();
Console.WriteLine("{RES_DENIED}");
goback = true;
progress++;
}
TerminalBackend.TextSent -= ev;
}
};
TerminalBackend.TextSent += ev;
Console.WriteLine();
Console.Write(loginstr);
ConsoleEx.Flush();
while (progress == 0)
{
Thread.Sleep(10);
}
if (goback)
goto Login;
Console.WriteLine();
Console.Write("{GEN_PASSWORD}: ");
ConsoleEx.Flush();
while (progress == 1)
Thread.Sleep(10);
if (goback)
goto Login;
}
TerminalBackend.PrefixEnabled = true;
Shiftorium.LogOrphanedUpgrades = true;
Desktop.InvokeOnWorkerThread(new Action(() =>
@ -529,17 +388,6 @@ namespace ShiftOS.Engine
/// </summary>
public delegate void EmptyEventHandler();
/// <summary>
/// Gets a list of all client-side users.
/// </summary>
public static List<ClientSave> Users
{
get
{
return CurrentSave.Users;
}
}
/// <summary>
/// Occurs when the engine is loaded and the game can take over.
/// </summary>

View file

@ -271,7 +271,7 @@ end");
{
Console.WriteLine("");
Lua(lua);
Console.WriteLine($"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
Console.WriteLine($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
}
catch (Exception e)
{
@ -447,7 +447,7 @@ end");
/// <returns>The user's username.</returns>
public string getUsername()
{
return SaveSystem.CurrentUser.Username;
return SaveSystem.CurrentSave.Username;
}
/// <summary>

View file

@ -161,7 +161,7 @@ Ping: {ServerManager.DigitalSocietyPing} ms
switch(msg.Name)
{
case "getguid_fromserver":
if(SaveSystem.CurrentUser.Username == msg.Contents)
if(SaveSystem.CurrentSave.Username == msg.Contents)
{
client.Send(new NetObject("yes_i_am", new ServerMessage
{
@ -258,7 +258,7 @@ Ping: {ServerManager.DigitalSocietyPing} ms
else if(msg.Name == "update_your_cp")
{
var args = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
if(args["username"] as string == SaveSystem.CurrentUser.Username)
if(args["username"] as string == SaveSystem.CurrentSave.Username)
{
SaveSystem.CurrentSave.Codepoints += (ulong)args["amount"];
Desktop.InvokeOnWorkerThread(new Action(() =>

View file

@ -178,14 +178,6 @@ namespace ShiftOS.Engine
public virtual void Invoke(Dictionary<string, object> args)
{
List<string> errors = new List<string>();
bool requiresAuth = false;
if (!KernelWatchdog.IsSafe(this))
{
if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin)
requiresAuth = true;
else
errors.Add("You can't run this command - you do not have permission.");
}
if (errors.Count > 0)
{
foreach (var error in errors)
@ -194,33 +186,6 @@ namespace ShiftOS.Engine
}
return;
}
if (requiresAuth)
{
Infobox.PromptText("Enter your password.", "This command requires you to have elevated permissions. Please enter your password to confirm this action.", (pass) =>
{
if (pass == SaveSystem.CurrentUser.Password)
{
var uname = SaveSystem.CurrentUser.Username;
SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == "root");
try
{
var h = CommandHandler;
h.Invoke(null, new[] { args });
}
catch
{
var h = CommandHandler;
h.Invoke(null, null);
}
SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == uname);
}
else
{
Infobox.Show("Access denied.", "Incorrect password provided. The command will not run.");
}
}, true);
}
try
{
CommandHandler.Invoke(null, new[] { args });
@ -512,7 +477,7 @@ namespace ShiftOS.Engine
public static void PrintPrompt()
{
Console.WriteLine();
if (SaveSystem.CurrentSave != null && CurrentUser != null)
if (SaveSystem.CurrentSave != null)
{
ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC;
ConsoleEx.Italic = false;
@ -521,7 +486,7 @@ namespace ShiftOS.Engine
ConsoleEx.ForegroundColor = ConsoleColor.Magenta;
ConsoleEx.Bold = true;
Console.Write(SaveSystem.CurrentUser.Username);
Console.Write(SaveSystem.CurrentSave.Username);
ConsoleEx.Bold = false;
ConsoleEx.ForegroundColor = ConsoleColor.Gray;
Console.Write("@");
@ -547,63 +512,6 @@ namespace ShiftOS.Engine
}
}
/// <summary>
/// Static constructor for <see cref="TerminalBackend"/>.
/// </summary>
static TerminalBackend()
{
ServerMessageReceived onMessageReceived = (msg) =>
{
if (msg.Name == "trm_invokecommand")
{
string text3 = "";
string text4 = msg.Contents;
if (TerminalBackend.PrefixEnabled)
{
text3 = text4.Remove(0, $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length);
}
IsForwardingConsoleWrites = true;
if (TerminalBackend.InStory == false)
{
TerminalBackend.InvokeCommand(text3, true);
}
if (TerminalBackend.PrefixEnabled)
{
Console.Write($"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
}
IsForwardingConsoleWrites = false;
}
else if (msg.Name == "pleasewrite")
{
Console.Write(msg.Contents);
}
else if (msg.Name == "handshake_from")
{
var a = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
string uName = a["username"] as string;
string pass = a["password"] as string;
string sys = a["sysname"] as string;
string guid = msg.GUID;
if (SaveSystem.CurrentUser.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys)
{
ForwardGUID = guid;
ServerManager.SendMessage("trm_handshake_accept", $@"{{
guid: ""{ServerManager.thisGuid}"",
target: ""{guid}""
}}");
IsForwardingConsoleWrites = true;
InvokeCommand("sos.status");
Console.Write($"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
IsForwardingConsoleWrites = false;
}
}
};
ServerManager.MessageReceived += onMessageReceived;
}
/// <summary>
/// Gets whether the terminal backend is forwarding console write requests through RTS to a remote client.
/// </summary>

View file

@ -1,242 +1 @@
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>
[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("adduser", description = "{DESC_ADDUSER}")]
[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("{ERR_USERFOUND}");
return true;
}
var user = new ClientSave
{
Username = name,
Password = "",
Permissions = UserPermissions.User
};
SaveSystem.CurrentSave.Users.Add(user);
Console.WriteLine(Localization.Parse("{RES_CREATINGUSER}", new Dictionary<string, string>
{
{ "%name", name }
}));
SaveSystem.SaveGame();
return true;
}
/// <summary>
/// Remove a user from the system.
/// </summary>
/// <param name="args">Command arguments.</param>
/// <returns>Command result.</returns>
[Command("removeuser", description = "{DESC_REMOVEUSER}")]
[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("{ERR_NOUSER}");
return true;
}
var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name);
if (user.Username != SaveSystem.CurrentUser.Username)
{
Console.WriteLine("{ERR_REMOVEYOU}");
return true;
}
SaveSystem.CurrentSave.Users.Remove(user);
Console.WriteLine(Localization.Parse("{RES_REMOVINGUSER}", new Dictionary<string, string>
{
["%name"] = name
}));
SaveSystem.SaveGame();
return true;
}
/// <summary>
/// Set access control level for a user.
/// </summary>
/// <param name="args">Command arguments.</param>
/// <returns>Command result.</returns>
[Command("setuserpermissions", description = "{DESC_SETUSERPERMISSIONS}")]
[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("{ERR_BADACL}");
return true;
}
if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==username) == null)
{
Console.WriteLine("{ERR_NOUSER}");
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("{ERR_BADACL}");
return true;
}
//Permissions are backwards... oops...
if(uperm < SaveSystem.CurrentUser.Permissions)
{
Console.WriteLine("{ERR_ACLHIGHERVALUE}");
return true;
}
var oldperm = SaveSystem.Users.FirstOrDefault(x => x.Username == username).Permissions;
if (SaveSystem.CurrentUser.Permissions > oldperm)
{
Console.WriteLine("{ERR_HIGHERPERMS}");
return true;
}
SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == username).Permissions = uperm;
Console.WriteLine("{RES_ACLUPDATED}");
return true;
}
/// <summary>
/// List all users in the system.
/// </summary>
/// <param name="args">Command arguments.</param>
/// <returns>Command result.</returns>
[Command("users", description = "{DESC_USERS}")]
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>
[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("su", description = "{DESC_SU}")]
[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("{ERR_NOUSER}");
return true;
}
if (usr.Password != pass)
{
Console.WriteLine("{RES_DENIED}");
return true;
}
SaveSystem.CurrentUser = usr;
Console.WriteLine("{RES_GRANTED}");
return true;
}
/// <summary>
/// Set the password for the current user.
/// </summary>
/// <param name="args">Command arguments.</param>
/// <returns>Command result.</returns>
[Command("passwd", description ="{DESC_PASSWD}", 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("{RES_PASSWD_SET}");
SaveSystem.SaveGame();
}
else
{
Console.WriteLine("{ERR_PASSWD_MISMATCH}");
}
return true;
}
}
}