diff options
| author | Michael <[email protected]> | 2017-07-17 14:34:59 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-07-17 14:34:59 -0400 |
| commit | a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db (patch) | |
| tree | d974220621e6cfcfe745c2825149ca370e3a7aab /ShiftOS_TheReturn | |
| parent | e929a9f5105c00b0a3a2b4e75a876bbb95bbfa7b (diff) | |
| download | shiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.tar.gz shiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.tar.bz2 shiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.zip | |
Hacking, barebones fskimmer, double clicking
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/FileSkimmerBackend.cs | 12 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Hacking.cs | 98 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Paths.cs | 9 |
3 files changed, 104 insertions, 15 deletions
diff --git a/ShiftOS_TheReturn/FileSkimmerBackend.cs b/ShiftOS_TheReturn/FileSkimmerBackend.cs index ac20d34..b14733f 100644 --- a/ShiftOS_TheReturn/FileSkimmerBackend.cs +++ b/ShiftOS_TheReturn/FileSkimmerBackend.cs @@ -44,7 +44,8 @@ namespace ShiftOS.Engine /// Opens a file from the specified ShiftFS path. /// </summary> /// <param name="path">The path to open.</param> - public static void OpenFile(string path) + /// <returns>Whether or not the file could be opened.</returns> + public static bool OpenFile(string path) { if (!Objects.ShiftFS.Utils.FileExists(path)) throw new System.IO.FileNotFoundException("ShiftFS could not find the file specified.", path); @@ -56,9 +57,11 @@ namespace ShiftOS.Engine { var obj = (IFileHandler)Activator.CreateInstance(type); obj.OpenFile(path); + return true; } } } + return false; } public static FileType GetFileType(string path) { @@ -137,11 +140,6 @@ namespace ShiftOS.Engine _fs = fs; } - public static System.Drawing.Image GetImage(string filepath) - { - return _fs.GetImage(filepath); - } - public static string GetFileExtension(FileType fileType) { return _fs.GetFileExtension(fileType); @@ -153,10 +151,8 @@ namespace ShiftOS.Engine /// </summary> public interface IFileSkimmer { - void OpenFile(string filepath); void GetPath(string[] filetypes, FileOpenerStyle style, Action<string> callback); void OpenDirectory(string path); - Image GetImage(string path); string GetFileExtension(FileType fileType); } diff --git a/ShiftOS_TheReturn/Hacking.cs b/ShiftOS_TheReturn/Hacking.cs index db47f66..ea2d89b 100644 --- a/ShiftOS_TheReturn/Hacking.cs +++ b/ShiftOS_TheReturn/Hacking.cs @@ -10,6 +10,9 @@ namespace ShiftOS.Engine { private static List<HackableSystem> _activeConnections = new List<HackableSystem>(); private static List<Objects.Hackable> Hackables = new List<Objects.Hackable>(); + private static List<Objects.Loot> Loot = new List<Objects.Loot>(); + + public static HackableSystem CurrentHackable { get; private set; } public static Objects.Hackable[] AvailableToHack { @@ -44,13 +47,84 @@ namespace ShiftOS.Engine } } + public static void InitHack(Objects.Hackable data) + { + var hsys = new HackableSystem(); + hsys.Data = data; + hsys.IsPwn3d = false; + var fs = new Objects.ShiftFS.Directory(); + fs.Name = data.FriendlyName; + Objects.ShiftFS.Utils.Mounts.Add(fs); + var mountid = Objects.ShiftFS.Utils.Mounts.IndexOf(fs); + Objects.ShiftFS.Utils.Mounts.Remove(fs); + hsys.Filesystem = fs; + hsys.FirewallCracked = (data.FirewallStrength == 0); + hsys.DoConnectionTimeout = (data.ConnectionTimeoutLevel > 0); + if (hsys.DoConnectionTimeout) + { + hsys.MillisecondsCountdown = 1000 * (240 / data.ConnectionTimeoutLevel); + } + else + { + hsys.MillisecondsCountdown = 0; + } + hsys.PortsToUnlock = new List<Port>(); + if (data.SystemType.HasFlag(Objects.SystemType.EmailServer)) + hsys.PortsToUnlock.Add(new Port + { + Value = 25, + Name = "SMTP mailserver (unencrypted)", + }); + if (data.SystemType.HasFlag(Objects.SystemType.FileServer)) + hsys.PortsToUnlock.Add(new Port + { + Value = 22, + Name = "File Transfer Protocol", + }); + if (data.SystemType.HasFlag(Objects.SystemType.SSHServer)) + hsys.PortsToUnlock.Add(new Port + { + Value = 21, + Name = "ShiftSSH server", + }); + if (data.SystemType.HasFlag(Objects.SystemType.Database)) + hsys.PortsToUnlock.Add(new Port + { + Value = 3306, + Name = "MySQL database", + }); + + CurrentHackable = hsys; + } + + public static void FailHack() + { + if (CurrentHackable == null) + 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."); + if (!string.IsNullOrWhiteSpace(CurrentHackable.Data.OnHackFailedStoryEvent)) + Story.Start(CurrentHackable.Data.OnHackFailedStoryEvent); + if (Objects.ShiftFS.Utils.Mounts.Contains(CurrentHackable.Filesystem)) + Objects.ShiftFS.Utils.Mounts.Remove(CurrentHackable.Filesystem); + CurrentHackable = null; + } + public static void Initiate() { foreach(var type in ReflectMan.Types.Where(x => x.GetInterfaces().Contains(typeof(IHackableProvider)))) { var @interface = (IHackableProvider)Activator.CreateInstance(type, null); Hackables.AddRange(@interface.GetHackables()); - + var lootinfo = @interface.GetLootInfo(); + foreach(var loot in lootinfo) + { + var existing = Loot.FirstOrDefault(x => x.Info.Filename == loot.Filename); + if (existing != null) + throw new DataConflictException("Data conflict encountered while reading loot data. Two or more loot resources with the filename \"" + loot.Filename + "\" were found. This can cause major bugs and confusion in the game."); + var @new = new Objects.Loot(loot, @interface.GetLootFromResource(loot.ResourceId)); + Loot.Add(@new); + } } var hackable = Hackables.FirstOrDefault(x => Hackables.Where(y => x.SystemName == y.SystemName).Count() > 1); @@ -61,6 +135,21 @@ namespace ShiftOS.Engine } } + /// <summary> + /// An exception which is thrown when a developer deliberately tries to cause a bug. + /// </summary> + public class NaughtyDeveloperException : Exception + { + /// <summary> + /// Create a new instance of the <see cref="NaughtyDeveloperException"/>, with the specified message, which will cause Visual Studio to call the person who caused the exception a scrotem. + /// </summary> + /// <param name="message">The message you want to yell at the user.</param> + public NaughtyDeveloperException(string message) : base(message + " - FIX IT, YOU SCROTEM") + { + + } + } + public class DataConflictException : Exception { public DataConflictException(string message) : base(message) @@ -72,6 +161,8 @@ namespace ShiftOS.Engine public interface IHackableProvider { Objects.Hackable[] GetHackables(); + Objects.LootInfo[] GetLootInfo(); + byte[] GetLootFromResource(string resId); } public class HackableSystem @@ -80,7 +171,8 @@ namespace ShiftOS.Engine public List<Port> PortsToUnlock { get; set; } public bool FirewallCracked { get; set; } public Objects.ShiftFS.Directory Filesystem { get; set; } - public int MillisecondsCountdown { get; set; } + public double MillisecondsCountdown { get; set; } + public bool DoConnectionTimeout { get; set; } public bool IsPwn3d { get; set; } } @@ -88,7 +180,5 @@ namespace ShiftOS.Engine { public string Name { get; set; } public int Value { get; set; } - public int Difficulty { get; set; } - public bool Cracked { get; set; } } } diff --git a/ShiftOS_TheReturn/Paths.cs b/ShiftOS_TheReturn/Paths.cs index 5827af2..0b00915 100644 --- a/ShiftOS_TheReturn/Paths.cs +++ b/ShiftOS_TheReturn/Paths.cs @@ -45,8 +45,8 @@ namespace ShiftOS.Engine /// </summary> public static void Init() { - Locations = new Dictionary<string, string>(); - Locations.Add("root", "0:"); + Locations = new Dictionary<string, string>(); + Locations.Add("root", "0:"); AddPath("root", "system"); @@ -76,7 +76,10 @@ namespace ShiftOS.Engine CheckPathExistence(); - CreateAndMountSharedFolder(); + if (Mounts.Count < 2) + { + CreateAndMountSharedFolder(); + } } /// <summary> |
