diff options
| author | Michael <[email protected]> | 2017-02-02 09:47:23 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-02 09:47:23 -0500 |
| commit | bbe37edb68f9e7535216bff80ba3e6b16cbca398 (patch) | |
| tree | 4382859eda0c253e17966159890f49208a41367f /ShiftOS_TheReturn/Scripting.cs | |
| parent | d8978b860d950e3ccde3c8beecf8b88bdd4a34a8 (diff) | |
| download | shiftos_thereturn-bbe37edb68f9e7535216bff80ba3e6b16cbca398.tar.gz shiftos_thereturn-bbe37edb68f9e7535216bff80ba3e6b16cbca398.tar.bz2 shiftos_thereturn-bbe37edb68f9e7535216bff80ba3e6b16cbca398.zip | |
Shiftnet, and audio fixes
Diffstat (limited to 'ShiftOS_TheReturn/Scripting.cs')
| -rw-r--r-- | ShiftOS_TheReturn/Scripting.cs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs index 4d5c1a7..1bb48d5 100644 --- a/ShiftOS_TheReturn/Scripting.cs +++ b/ShiftOS_TheReturn/Scripting.cs @@ -34,6 +34,7 @@ using System.Dynamic; using Newtonsoft.Json; using System.Windows.Forms; using System.Threading; +using System.Net; namespace ShiftOS.Engine.Scripting { @@ -125,6 +126,16 @@ namespace ShiftOS.Engine.Scripting t.IsBackground = true; t.Start(); }); + Lua.includeScript = new Action<string>((file) => + { + if (!Utils.FileExists(file)) + throw new ArgumentException("File does not exist."); + + if (!file.EndsWith(".lua")) + throw new ArgumentException("File is not a lua file."); + + Lua(Utils.ReadAllText(file)); + }); } @@ -142,12 +153,31 @@ namespace ShiftOS.Engine.Scripting public void Execute(string lua) { + try + { Console.WriteLine(""); Lua(lua); Console.WriteLine($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + } + catch (Exception e) + { + Infobox.Show("Script error", $@"Script threw {e.GetType().Name}: + +{e.Message}"); + } } } + [Exposed("net")] + public class NetFunctions + { + public string get(string url) + { + return new WebClient().DownloadString(url); + } + + } + [Exposed("console")] public class ConsoleFunctions { @@ -175,7 +205,18 @@ namespace ShiftOS.Engine.Scripting return TerminalBackend.RunClient(cmd, args); } - + public void addCodepoints(int cp) + { + if (cp > 100 || cp <= 0) + { + throw new Exception("Value 'cp' must be at or below 100, and above 0."); + } + else + { + SaveSystem.CurrentSave.Codepoints += cp; + SaveSystem.SaveGame(); + } + } } |
