From bbe37edb68f9e7535216bff80ba3e6b16cbca398 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Feb 2017 09:47:23 -0500 Subject: Shiftnet, and audio fixes --- ShiftOS_TheReturn/Scripting.cs | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'ShiftOS_TheReturn/Scripting.cs') 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((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(); + } + } } -- cgit v1.2.3