public static bool SendGump(TriggerObject trigObject, Mobile target, string GumpFile, bool closeGump) { if (GumpFile == null || target == null) { return(false); } string path; GumpFileMap.TryGetValue(GumpFile.ToLower(), out path); if (path == null) { //path = Path.GetFullPath(ScriptFile); path = Path.Combine(Core.BaseDirectory, "UberScripts", GumpFile); if (!File.Exists(path)) { throw new UberScriptException("Script file did not exist at " + path); } GumpFileMap.Add(GumpFile.ToLower(), path); } UberGumpBase parsedGump; XmlDocument parsedXml; if (!Gumps.ContainsKey(path)) { parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) { return(false); } parsedGump = new UberGumpBase(parsedXml.FirstChild); Gumps.Add(path, parsedGump); } else { parsedGump = Gumps[path]; } if (closeGump && target.HasGump(typeof(UberScriptGump))) { target.CloseGump(typeof(UberScriptGump)); } target.SendGump(new UberScriptGump(target, trigObject, parsedGump, GumpFile)); return(true); }
public static void AddGump(string GumpFile) { //only add if it hasn't already been added try { string path; GumpFileMap.TryGetValue(GumpFile.ToLower(), out path); if (path == null) { path = Path.Combine(Core.BaseDirectory, "UberScripts", GumpFile); if (!File.Exists(path)) { throw new UberScriptException("Script file did not exist at " + path); } GumpFileMap.Add(GumpFile.ToLower(), path); } if (!Gumps.ContainsKey(path)) { XmlDocument parsedXml = new XmlDocument(); //* create an xml document object. parsedXml.Load(path); //* load the XML document from the specified file. if (parsedXml == null) { throw new Exception("Xml Document parsed to null!"); } UberGumpBase parsedGump = new UberGumpBase(parsedXml); Gumps.Add(path, parsedGump); } } catch (Exception general) { Console.WriteLine("Error Parsing Gump Xml file: " + GumpFile); Console.WriteLine(general.Message); Console.WriteLine(general.StackTrace); } }
public static string TestValidUberScript(string fileChars, out bool result) { //Console.WriteLine("Testing file with " + fileChars.Length + " bytes"); //Console.WriteLine(fileChars); string[] lines = fileChars.Split('\n'); try { RootNode parsed = UberTreeParser.ParseFileContents(lines, null); if (parsed == null) { throw new Exception(); // try xml parse } } catch (Exception e) { // now try parsing it as XML to see if it's an XML gump if (fileChars.Contains("<Gump") || fileChars.Contains("<gump") || fileChars.Contains("<GUMP")) { try { XmlDocument parsedXml; parsedXml = new XmlDocument(); parsedXml.LoadXml(fileChars); UberGumpBase parsedGump = new UberGumpBase(parsedXml.FirstChild); } catch (Exception e2) { result = false; string output = "Gump XML Parsing Error encountered (Send the xml of the file to Alan at [email protected] if you REALLY can't figure it out from the following message):\n\n" + e2.Message; while (e2.InnerException != null) { output += "\n\t" + e2.InnerException.Message; e2 = e2.InnerException; } return(output); } result = true; return(@"======================== XML SUCCESS ====================== XML file was processed successfully! Your UberScripts can now send that gump by using SENDGUMP(mobile, gumpFileName) If you are a GM on the test server, you can now do the following: [addatt xmlscript fileName and then target the Item or Mobile you would like to attach the script to. e.g. if you just uploaded 'test.us' then you would do [addatt xmlscript test.us If you are testing something in the onCreate trigger, and already have that script on the object you are testing it on, be sure to [delatt xmlscript on the Mobile or Item and then [addatt that script again (onCreate trigger only executes when the script is first attached) "); } else { result = false; return("UberScript Parsing Error encountered (Send the text of the file to Alan at [email protected] if you REALLY can't figure it out from the following message):\n\n" + e.Message); } } result = true; return(@"======================== SUCCESS ========================== UberScript was processed successfully! If you are a GM on the test server, you can now do the following: [addatt xmlscript fileName and then target the Item or Mobile you would like to attach the script to. e.g. if you just uploaded 'test.us' then you would do [addatt xmlscript test.us If you are testing something in the onCreate trigger, and already have that script on the object you are testing it on, be sure to [delatt xmlscript on the Mobile or Item and then [addatt that script again (onCreate trigger only executes when the script is first attached)"); }