aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-07-31 19:44:51 +1000
committerRogueAI42 <[email protected]>2017-07-31 19:44:51 +1000
commit23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8 (patch)
treefa5dc08a89014d79565f30b22c94403845239cc3 /ShiftOS_TheReturn
parentd953797369cd72a718b801e0036ce9ebb181f24f (diff)
parent6366721315d8a62febeb5c0c0340f15ab7d35963 (diff)
downloadshiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.tar.gz
shiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.tar.bz2
shiftos_thereturn-23bd15d7cf7522fb05a5f2ea8e0a89d3a80efdc8.zip
Merge remote-tracking branch 'upstream/monogame' into monogame
Diffstat (limited to 'ShiftOS_TheReturn')
-rw-r--r--ShiftOS_TheReturn/CommandParser.cs42
-rw-r--r--ShiftOS_TheReturn/Hacking.cs5
-rw-r--r--ShiftOS_TheReturn/TerminalBackend.cs138
3 files changed, 139 insertions, 46 deletions
diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs
index d56e7bd..7568b98 100644
--- a/ShiftOS_TheReturn/CommandParser.cs
+++ b/ShiftOS_TheReturn/CommandParser.cs
@@ -13,17 +13,6 @@ using System.Windows.Forms;
namespace ShiftOS.Engine
{
/// <summary>
- /// Static abstraction layer for the current command parser
- /// </summary>
- public static class CurrentCommandParser
- {
- /// <summary>
- /// The current parser
- /// </summary>
- public static CommandParser parser;
- }
-
- /// <summary>
/// Provides functionality for parsing a Terminal command string
/// </summary>
public sealed class CommandParser
@@ -119,6 +108,8 @@ namespace ShiftOS.Engine
int i = 0;
string currentArgument = "";
int help = -1;
+ bool id_found = false;
+ string id_text = "";
while (position < text.Length)
{
@@ -131,7 +122,21 @@ namespace ShiftOS.Engine
}
CommandFormat part = parts[i];
- string res = part.CheckValidity(text.Substring(position));
+ string inp = text.Substring(position);
+ string res = part.CheckValidity(inp);
+ if(part is CommandFormatText)
+ {
+ if(res == "+FALSE+")
+ {
+ if(id_found == false)
+ {
+ id_found = true;
+ id_text = inp.Remove(0,1);
+ res = "";
+ arguments.Add("id", id_text);
+ }
+ }
+ }
// ok so:
@@ -148,8 +153,17 @@ namespace ShiftOS.Engine
}
else if (part is CommandFormatArgument)
{
- currentArgument = res;
- help = -1;
+ if (arguments.ContainsKey(res))
+ {
+ Console.WriteLine("Duplicate command-line argument detected: " + res);
+ command = "+FALSE+";
+ position = text.Length;
+ }
+ else
+ {
+ currentArgument = res;
+ help = -1;
+ }
}
else if (part is CommandFormatValue)
{
diff --git a/ShiftOS_TheReturn/Hacking.cs b/ShiftOS_TheReturn/Hacking.cs
index b9149d9..8412203 100644
--- a/ShiftOS_TheReturn/Hacking.cs
+++ b/ShiftOS_TheReturn/Hacking.cs
@@ -111,7 +111,7 @@ namespace ShiftOS.Engine
var amount = data.LootAmount;
for (int i = 0; i < amount; i++)
{
- int idx = rnd.Next(0, loot.Count - 1);
+ int idx = rnd.Next(0, loot.Count); //warning MV1224: Random.Next(min, max) - max is not inclusive, i.e the number will always be less than it and equal to or greater than min.
hsys.ServerFTPLoot.Add(loot[idx]);
loot.RemoveAt(idx);
}
@@ -124,10 +124,13 @@ namespace ShiftOS.Engine
throw new NaughtyDeveloperException("Someone tried to fail a non-existent hack.");
if (CurrentHackable.IsPwn3d)
throw new NaughtyDeveloperException("A developer tried to un-pwn a pwn3d hackable.");
+ Console.WriteLine();
Console.WriteLine("[sploitset] [FAIL] disconnected - connection terminated by remote machine ");
if (!string.IsNullOrWhiteSpace(CurrentHackable.Data.OnHackFailedStoryEvent))
Story.Start(CurrentHackable.Data.OnHackFailedStoryEvent);
CurrentHackable = null;
+ TerminalBackend.SetShellOverride("");
+ TerminalBackend.PrintPrompt();
}
public static void EndHack()
diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs
index 689465f..dcc4625 100644
--- a/ShiftOS_TheReturn/TerminalBackend.cs
+++ b/ShiftOS_TheReturn/TerminalBackend.cs
@@ -40,6 +40,29 @@ namespace ShiftOS.Engine
/// </summary>
public static class TerminalBackend
{
+ private static string _shellOverrideString = "";
+
+
+ /// <summary>
+ /// Gets the current shell prompt override string.
+ /// </summary>
+ public static string ShellOverride
+ {
+ get
+ {
+ return (string.IsNullOrWhiteSpace(_shellOverrideString) || SaveSystem.CurrentSave == null) ? $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ " : _shellOverrideString;
+ }
+ }
+
+ /// <summary>
+ /// Sets the shell override string to the specified value. Empty string or <see cref="null"/> to use the default ShiftOS string.
+ /// </summary>
+ /// <param name="value">The string to use as a shell prompt.</param>
+ public static void SetShellOverride(string value)
+ {
+ _shellOverrideString = value;
+ }
+
/// <summary>
/// Occurs when a command is processed.
/// </summary>
@@ -133,6 +156,17 @@ namespace ShiftOS.Engine
public class TerminalCommand
{
+ public virtual bool MatchShell()
+ {
+ if(ShellMatch != "metacmd")
+ {
+ return (ShellMatch == _shellOverrideString);
+ }
+ return true;
+ }
+
+ public string ShellMatch { get; set; }
+
public override int GetHashCode()
{
int hash = 0;
@@ -178,11 +212,19 @@ namespace ShiftOS.Engine
public virtual void Invoke(Dictionary<string, object> args)
{
List<string> errors = new List<string>();
+ if (ShellMatch != "metacmd")
+ {
+ if (ShellMatch != TerminalBackend._shellOverrideString)
+ {
+ errors.Add("Command not found.");
+ }
+ }
+
if (errors.Count > 0)
{
foreach (var error in errors)
{
- Console.WriteLine("Command error: " + error);
+ Console.WriteLine(error);
}
return;
}
@@ -197,10 +239,28 @@ namespace ShiftOS.Engine
}
}
+ [MetaCommand]
+ [Command("exit")]
+ public static void Exit()
+ {
+ if (_shellOverrideString != "")
+ _shellOverrideString = "";
+ else
+ {
+ Console.WriteLine("error: cannot exit system shell");
+ }
+ }
+
+
public class WinOpenCommand : TerminalCommand
{
public Type ShiftOSWindow { get; set; }
+ public override bool MatchShell()
+ {
+ return (_shellOverrideString == "");
+ }
+
public override void Invoke(Dictionary<string, object> args)
{
@@ -296,6 +356,13 @@ namespace ShiftOS.Engine
var tc = new TerminalCommand();
tc.RequiresElevation = !(type.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null);
+ var shellConstraint = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShellConstraintAttribute) as ShellConstraintAttribute;
+ tc.ShellMatch = (shellConstraint == null) ? "" : shellConstraint.Shell;
+
+ if(mth.GetCustomAttributes(false).FirstOrDefault(x=>x is MetaCommandAttribute) != null)
+ {
+ tc.ShellMatch = "metacmd";
+ }
tc.CommandInfo = cmd as Command;
tc.RequiresElevation = tc.RequiresElevation || !(mth.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null);
@@ -471,42 +538,23 @@ namespace ShiftOS.Engine
return true;
}
+#if DEBUG
+ [Command("setshell", hide = true)]
+ [RequiresArgument("id")]
+ public static void Debug_SetShellOverrideCMD(Dictionary<string, object> args)
+ {
+ SetShellOverride(args["id"].ToString());
+ }
+#endif
+
/// <summary>
/// Prints the user prompt to the terminal.
/// </summary>
public static void PrintPrompt()
{
- if (SaveSystem.CurrentSave != null)
+ if (PrefixEnabled)
{
- ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC;
- ConsoleEx.Italic = false;
- ConsoleEx.Underline = false;
-
- ConsoleEx.ForegroundColor = ConsoleColor.Magenta;
- ConsoleEx.Bold = true;
-
- Console.Write(SaveSystem.CurrentSave.Username);
- ConsoleEx.Bold = false;
- ConsoleEx.ForegroundColor = ConsoleColor.Gray;
- Console.Write("@");
- ConsoleEx.Italic = true;
- ConsoleEx.Bold = true;
- ConsoleEx.ForegroundColor = ConsoleColor.Yellow;
- Console.Write(SaveSystem.CurrentSave.SystemName);
- ConsoleEx.Italic = false;
- ConsoleEx.Bold = false;
- ConsoleEx.ForegroundColor = ConsoleColor.Gray;
- Console.Write(":~");
- Console.ForegroundColor = ConsoleColor.White;
- ConsoleEx.Italic = true;
- if (KernelWatchdog.InKernelMode == true)
- Console.Write("#");
- else
- Console.Write("$");
- ConsoleEx.Italic = false;
- ConsoleEx.Bold = false;
- ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC;
- Console.Write(" ");
+ Console.Write(ShellOverride);
ConsoleEx.Flush();
}
}
@@ -536,4 +584,32 @@ namespace ShiftOS.Engine
}
}
+
+ /// <summary>
+ /// Marks this command so that it can be run in ANY shell.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
+ public class MetaCommandAttribute : Attribute
+ {
+
+ }
+
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
+ public class ShellConstraintAttribute : Attribute
+ {
+ /// <summary>
+ /// Instructs the terminal command interpreter to disallow running of this command unless the user shell override matches up with the value provided here.
+ /// </summary>
+ /// <param name="shell">The required shell string. Null or whitespace to match with the default ShiftOS shell.</param>
+ public ShellConstraintAttribute(string shell)
+ {
+ Shell = shell;
+ }
+
+
+ /// <summary>
+ /// Gets the required shell string for the command.
+ /// </summary>
+ public string Shell { get; private set; }
+ }
}