Esempio n. 1
0
 public InpScriptEvent(InpScript voParent, string vsEventName, List<string> vcsCommands)
 {
     moParent = voParent;
     int lPos = vsEventName.IndexOf("/");
     if (lPos > 0 ) {
         msEventName = vsEventName.Substring(0, lPos).Trim();
         msEventCondition = vsEventName.Substring(lPos+1).Trim();
         ParseCondition (msEventCondition );
     } else {
         msEventName = vsEventName;
     }
     msCommands = vcsCommands.ToArray();
 }
Esempio n. 2
0
        public static InpScript TryParse(string vsFilename)
        {
            InpScript oRet = new InpScript();

            StreamReader oSR = File.OpenText(vsFilename);
            bool started = false;
            string sEvent = "";
            List<string> csBuf = new  List<string>();
            int num = 0;

            Console.WriteLine("Reading Script " + vsFilename);
            while (!oSR.EndOfStream) {
                string line = oSR.ReadLine().Trim();
                num++;
                if (line.Length > 0 && !line.StartsWith("//")) {
                    if (started) {
                        if (line.StartsWith("!")) {
                            if (sEvent.Length != 0) {
                                InpScriptEvent oEvent = new InpScriptEvent(oRet, sEvent, csBuf);
                                oRet.mcoEvents.Add(sEvent, oEvent);
                                csBuf.Clear();
                            }
                            sEvent = line.Substring(1);
                        } else {
                            if (sEvent.Length == 0) {
                                Console.WriteLine ("expected event at line " + num + ", ignoring line");
                            } else {
                                csBuf.Add(line);
                            }
                        }
                    } else {
                        if (line.Equals("itsnotpython"))
                            started = true;
                    }
                }
            }
            if (sEvent.Length > 0) {
                InpScriptEvent oEvent = new InpScriptEvent(oRet, sEvent, csBuf);
                oRet.mcoEvents.Add(sEvent, oEvent);
            }

            Console.WriteLine("Checking...");
            foreach (InpScriptEvent oEvent in oRet.mcoEvents.Values) {
                Console.WriteLine ("got event: " + oEvent.Name);
            }

            return oRet;
        }
Esempio n. 3
0
 public void RegisterBot(InpScript voScript, Connection voConn)
 {
     foreach (InpScriptEvent oSE in voScript.Events.Values) {
         InpEvent e = InpEvent.GetEvent(oSE.Name);
         if (e != null) {
             InpScriptEventRunner oRunner = new InpScriptEventRunner(oSE, voConn);
             e.FireEvent += oRunner.ConsumeEvent;
             mcoRunners.Add(oRunner);
             Console.WriteLine("Event " + oSE.Name + " registered");
         } else {
             Console.WriteLine("Event " + oSE.Name + " not found");
         }
     }
 }