示例#1
0
        public static int initialize(string mapReferenceFile)
        {
            // Indicates the number of maps loaded successfully
            int loadedMaps=0;

            XmlData doc=new XmlData(mapReferenceFile);

            if(doc.ExistElement("maps")==false)
            {
                Logger.Write(LogLevel.Error, "Item Manager: Error while parsing map database ({0})!", mapReferenceFile);
                return loadedMaps;
            }

            Logger.Write(LogLevel.Information, "Loading map reference: {0}", mapReferenceFile);

            //Für jeden Mapknoten
            List<XmlNode> nodes=doc.GetElements("maps.map");

            foreach(XmlNode node in nodes)
            {
                if(node.Name!="map") continue;

                int id=Convert.ToInt32(node.Attributes["id"].Value);
                string name=node.Attributes["name"].Value;

                if(id>0&&name!="")
                {
                    // Testing if the file is actually in the maps folder
                    string file="maps/"+name+".tmx";
                    bool mapFileExists=ResourceManager.exists(file);

                    if(mapFileExists)
                    {
                        maps[id]=new MapComposite(id, name);
                        ++loadedMaps;
                    }
                }
                else
                {
                    if(name=="")
                    {
                        Logger.Write(LogLevel.Warning, "Invalid unnamed map Id: {0}.", id);
                    }
                    else
                    {
                        Logger.Write(LogLevel.Warning, "Invalid map Id: {0}.", id);
                    }
                }
            }

            if(loadedMaps>0)
            {
                Logger.Write(LogLevel.Information, "{0} valid map file references were loaded.", loadedMaps);
            }

            return loadedMaps;
        }
示例#2
0
        public Highscore(string path)
        {
            highscorePath=path;

            if(FileSystem.ExistsFile(highscorePath))
            {
                XmlData scoreFile=new XmlData(highscorePath);
                List<XmlNode> scoreNodes=scoreFile.GetElements("xml.Score");

                foreach(XmlNode scoreNode in scoreNodes)
                {
                    string name=scoreNode.Attributes["name"]!=null?scoreNode.Attributes["name"].Value:"";
                    int value=scoreNode.Attributes["value"]!=null?Convert.ToInt32(scoreNode.Attributes["value"].Value):0;
                    userHighscore.Add(name, value);
                }
            }
        }
示例#3
0
        public static void Init(string filename)
        {
            if(filename==null||filename=="")
            {
                Filename=DEFAULT_CONFIG_FILE;
            }
            else
            {
                Filename=filename;
            }

            if(!FileSystem.ExistsFile(Filename)) throw new Exception();

            xmlfile=new XmlData(Filename);
            nodes=xmlfile.GetElements("configuration.option");
        }
示例#4
0
        static void Main(string[] args)
        {
            if(args.Length!=1)
            {
                Console.WriteLine("Please set a config file!");
                return;
            }

            //CancelEvent verdrahten
            Console.CancelKeyPress+=new ConsoleCancelEventHandler(Console_CancelKeyPress);

            //Highscore Pfad bauen
            string highscorePath=FileSystem.GetPath(args[0])+"highscore.xml";

            //Config auslesen
            XmlData Options=new XmlData(args[0]);

            string username=Options.GetElementAsString("xml.IRC.UserName");
            string realname=Options.GetElementAsString("xml.IRC.RealName");
            string ident=Options.GetElementAsString("xml.IRC.Ident");
            string server=Options.GetElementAsString("xml.IRC.Server");
            string channel=Options.GetElementAsString("xml.IRC.Channel");
            string userpassword=Options.GetElementAsString("xml.IRC.Password");

            //Bot anlegen
            Arbiter arbiter=new Arbiter(server, username, realname, ident, channel, highscorePath);

            //Jokes einlesen
            List<XmlNode> jokeNodes=Options.GetElements("xml.Jokes.Joke");

            foreach(XmlNode jokeNode in jokeNodes)
            {
                string category=jokeNode.Attributes["category"]!=null?jokeNode.Attributes["category"].Value:"";
                string jokeText=jokeNode.InnerText;
                arbiter.Jokes.Add(new Joke(category, jokeText));
            }

            //Quizfragen einlesen
            List<XmlNode> questionsNodes=Options.GetElements("xml.Quiz.Question");

            foreach(XmlNode questionNode in questionsNodes)
            {
                string category=questionNode.Attributes["category"].Value;
                string question=questionNode.Attributes["question"].Value;
                string success=questionNode.Attributes["success"]!=null?questionNode.Attributes["success"].Value:"";
                int points=Convert.ToInt32(questionNode.Attributes["points"].Value);
                List<string> hints=new List<string>();

                int keywordWeight=1;
                if(questionNode.Attributes.GetNamedItem("keywordWeight")!=null)
                {
                    keywordWeight=Convert.ToInt32(questionNode.Attributes["keywordWeight"].Value);
                }

                List<Keyword> keywords=new List<Keyword>();

                foreach(XmlNode child in questionNode.ChildNodes)
                {
                    if(child.Name=="Keyword")
                    {
                        int weight=1;

                        if(child.Attributes.GetNamedItem("keywordWeight")!=null)
                        {
                            string weightValue=child.Attributes["keywordWeight"].Value;

                            if(weightValue=="MAX")
                                weight=Int32.MaxValue;
                            else
                                weight=Convert.ToInt32(weightValue);
                        }

                        Keyword keyword=new Keyword(child.InnerText, weight);
                        keywords.Add(keyword);
                    }
                    else if(child.Name=="Hint")
                    {
                        hints.Add(child.InnerText);
                    }
                }

                //Frage zum Bot hinzufügen
                arbiter.Quiz.Questions.Add(new Question(category, question, hints, success, points, keywordWeight, keywords));
            }

            //Quotes einlesen
            List<XmlNode> quodeNodes=Options.GetElements("xml.Quotes.Quote");

            foreach(XmlNode quodeNode in quodeNodes)
            {
                string author=quodeNode.Attributes["author"].Value;
                string quoteText=quodeNode.InnerText;
                arbiter.Quotes.Add(new Quote(author, quoteText));
            }

            //Bot starten
            arbiter.Start(userpassword);
        }
示例#5
0
        public static void Main(string[] args)
        {
            //Console
            Console.WriteLine("Initializing sensor...");

            //Load config
            XmlData config;

            try
            {
                config=new XmlData("sensor.xml");
            }
            catch(Exception e)
            {
                Console.WriteLine("Konfiguration konnte nicht gelesen werden.");
                Console.WriteLine(e.ToString());
                return;
            }

            bool miscCheckCertificates=Convert.ToBoolean(config.GetElementAsString("xml.misc.checkcertificates"));

            if(miscCheckCertificates==false)
            {
                //Disable certificate check
                ServicePointManager.ServerCertificateValidationCallback=delegate
                {
                    return true;
                };
            }

            bool verbose=Convert.ToBoolean(config.GetElementAsString("xml.misc.verbose"));

            string apiToken=config.GetElementAsString("xml.api.token");
            string apiUrl=config.GetElementAsString("xml.api.url");

            //EAPI Setup
            EAPI eAPI=new EAPI(apiUrl, apiToken);

            #region Network scan
            Console.WriteLine("Scan network...");

            //Scan network
            Dictionary<string, List<NetworkEntry>> networkScans=new Dictionary<string, List<NetworkEntry>>();
            List<XmlNode> networkSegments=config.GetElements("xml.network.segment");

            foreach(XmlNode node in networkSegments)
            {
                bool active=Convert.ToBoolean(node["active"].InnerText);
                if(!active) continue;

                string key=node.Attributes["key"].Value;
                Console.WriteLine("Scan network segment {0}...", key);

                //IP Ranges
                List<string> segmentIPRanges=new List<string>();
                foreach(XmlNode childNode in node.ChildNodes)
                {
                    if(childNode.LocalName=="iprange") segmentIPRanges.Add(childNode.InnerText);
                }

                //Scan ranges
                List<NetworkEntry> entries=new List<NetworkEntry>();

                foreach(string segmentIPRange in segmentIPRanges)
                {
                    NetworkScanner scanner=new NetworkScanner();

                    List<NetworkEntry> segmentEntries=scanner.GetNetworkInformation(segmentIPRange);
                    Console.WriteLine("Detected network devices in segment {0}/{1}: {2}", key, segmentIPRange, segmentEntries.Count);

                    if(verbose)
                    {
                        foreach(NetworkEntry networkEntry in segmentEntries)
                        {
                            Console.WriteLine("Detected network device: {0} / {1} ({2}, {3} ms)", networkEntry.IP, networkEntry.Hostname, networkEntry.Up?"online":"offline", networkEntry.RoundtripTime);
                        }
                    }

                    entries.AddRange(segmentEntries);
                }

                networkScans.Add(key, entries);
            }
            #endregion

            #region Detection
            Console.WriteLine("Start detection...");

            //Entity Detection
            int countEntities=0;

            bool entityDetection=Convert.ToBoolean(config.GetElementAsString("xml.detection.entity.active"));

            if(entityDetection)
            {
                Console.WriteLine("Start entity detection...");

                string sensorType=config.GetElementAsString("xml.detection.entity.sensortype");
                string networkSegment=config.GetElementAsString("xml.detection.entity.networksegment");
                int minimumCount=Convert.ToInt32(config.GetElementAsString("xml.detection.entity.minimumcount"));
                TimeSpan minimumTime=new TimeSpan(0, 0, Convert.ToInt32(config.GetElementAsString("xml.detection.entity.minimumtime")));

                long significantTimeAsLong=Convert.ToInt64(config.GetElementAsString("xml.detection.entity.significanttime"));
                DateTime significantTime=new DateTime(significantTimeAsLong);

                if(sensorType=="network")
                {
                    Console.WriteLine("Start entity detection with sensor type network...");

                    if(networkScans.ContainsKey(networkSegment))
                    {
                        List<NetworkEntry> segmentEntries=networkScans[networkSegment];

                        //Check if minimum count is reached
                        if(segmentEntries.Count>minimumCount)
                        {
                            if(significantTimeAsLong==0)
                            {
                                significantTime=DateTime.Now;
                                config.WriteElement("xml.detection.entity.significanttime", significantTime.Ticks.ToString());
                            }

                            //Check if minimum time is reached
                            if(DateTime.Now>significantTime+minimumTime)
                            {
                                countEntities=segmentEntries.Count;
                            }
                        }
                        else
                        {
                            config.WriteElement("xml.detection.entity.significanttime", "0");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Network segment for detection not found.");
                    }
                }
            }
            #endregion

            #region API
            Console.WriteLine("Transfer sensor data to API...");

            //Write Network informations into API Database
            int countDevices=0;

            foreach(KeyValuePair<string, List<NetworkEntry>> pair in networkScans)
            {
                countDevices+=pair.Value.Count;
                eAPI.SetStatus(pair.Key, pair.Value.Count);
            }

            eAPI.SetStatus("devices", countDevices);

            //Write Entites
            eAPI.SetStatus("entities", countEntities);
            #endregion

            //set last run
            config.WriteElement("xml.misc.lastrun", DateTime.Now.Ticks.ToString());
            config.Save();
        }