Esempio n. 1
0
        public static void StartUp()
        {
            //Clear out old files if they exist, if it doesn't work we'll just do it on next startup.
            try { if (File.Exists(RootFolder + @"\YAMS-Library.dll.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Library.dll.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.config.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.config.OLD");
                  }
            }
            catch { };

            //Start DB Connection
            Database.init();
            Database.AddLog("Starting Up");

            //Is this the first run?
            if (Database.GetSetting("FirstRun", "YAMS") != "true")
            {
                YAMS.Util.FirstRun();
            }

            StoragePath = Database.GetSetting("StoragePath", "YAMS");

            Database.AddLog("Deleting and killing PIDs", "app", "debug");
            //Are there any PIDs we previously started still running?
            if (File.Exists(Core.RootFolder + "\\pids.txt"))
            {
                try
                {
                    StreamReader trPids = new StreamReader(Core.RootFolder + "\\pids.txt");
                    string       line;
                    while ((line = trPids.ReadLine()) != null)
                    {
                        try
                        {
                            Process.GetProcessById(Convert.ToInt32(line)).Kill();
                        }
                        catch (Exception e)
                        {
                            Database.AddLog("Process " + line + " not killed: " + e.Message);
                        }
                    }

                    trPids.Close();
                }
                catch (Exception e)
                {
                    Database.AddLog("Not all processes killed: " + e.Message);
                }
                try
                {
                    File.Delete(Core.RootFolder + "\\pids.txt");
                }
                catch (Exception e)
                {
                    Database.AddLog("Unable to delete the pids.txt file: " + e.Message);
                }
            }
            ;

            //Load any servers
            Database.AddLog("Reading minecraft servers!", "app", "debug");
            MySqlDataReader readerServers = Database.GetServers();
            ArrayList       ServerIDs     = new ArrayList();

            while (readerServers.Read())
            {
                int ServerID = Convert.ToInt32(readerServers.GetString("ServerID"));
                ServerIDs.Add(ServerID);
            }
            readerServers.Close();

            System.Collections.IEnumerator enu = ServerIDs.GetEnumerator();
            while (enu.MoveNext())
            {
                int      ServerID = Convert.ToInt32(enu.Current);
                MCServer myServer = new MCServer(ServerID);
                Servers.Add(ServerID, myServer);
            }
            Database.AddLog("Starting web server!", "app", "debug");
            //Start Webserver
            WebServer.Init();
        }
Esempio n. 2
0
        public static void StartUp()
        {
            //Clear out old files if they exist, if it doesn't work we'll just do it on next startup.
            try { if (File.Exists(RootFolder + @"\YAMS-Library.dll.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Library.dll.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.OLD");
                  }
            }
            catch { };
            try { if (File.Exists(RootFolder + @"\YAMS-Service.exe.config.OLD"))
                  {
                      File.Delete(RootFolder + @"\YAMS-Service.exe.config.OLD");
                  }
            }
            catch { };

            //Start DB Connection
            Database.init();
            Database.AddLog("Starting Up");

            //Is this the first run?
            if (Database.GetSetting("FirstRun", "YAMS") != "true")
            {
                YAMS.Util.FirstRun();
            }

            //Fill up some vars
            AutoUpdate.bolUpdateAddons = Convert.ToBoolean(Database.GetSetting("UpdateAddons", "YAMS"));
            AutoUpdate.bolUpdateGUI    = Convert.ToBoolean(Database.GetSetting("UpdateGUI", "YAMS"));
            AutoUpdate.bolUpdateJAR    = Convert.ToBoolean(Database.GetSetting("UpdateJAR", "YAMS"));
            AutoUpdate.bolUpdateSVC    = Convert.ToBoolean(Database.GetSetting("UpdateSVC", "YAMS"));
            AutoUpdate.bolUpdateWeb    = Convert.ToBoolean(Database.GetSetting("UpdateWeb", "YAMS"));
            StoragePath = Database.GetSetting("StoragePath", "YAMS");

            //Are there any PIDs we previously started still running?
            if (File.Exists(Core.RootFolder + "\\pids.txt"))
            {
                try
                {
                    StreamReader trPids = new StreamReader(Core.RootFolder + "\\pids.txt");
                    string       line;
                    while ((line = trPids.ReadLine()) != null)
                    {
                        try
                        {
                            Process.GetProcessById(Convert.ToInt32(line)).Kill();
                        }
                        catch (Exception e)
                        {
                            Database.AddLog("Process " + line + " not killed: " + e.Message);
                        }
                    }

                    trPids.Close();
                }
                catch (Exception e)
                {
                    Database.AddLog("Not all processes killed: " + e.Message);
                }
                try
                {
                    File.Delete(Core.RootFolder + "\\pids.txt");
                }
                catch (Exception e)
                {
                    Database.AddLog("Unable to delete the pids.txt file: " + e.Message);
                }
            }
            ;

            //Check for updates
            AutoUpdate.CheckUpdates();

            //Load any servers
            SqlCeDataReader readerServers = YAMS.Database.GetServers();

            while (readerServers.Read())
            {
                Database.AddLog("Starting Server " + readerServers["ServerID"]);
                MCServer myServer = new MCServer(Convert.ToInt32(readerServers["ServerID"]));
                if (Convert.ToBoolean(readerServers["ServerAutostart"]))
                {
                    myServer.Start();
                }
                Servers.Add(Convert.ToInt32(readerServers["ServerID"]), myServer);
            }

            //Start job engine
            JobEngine.Init();

            //Start Webserver
            WebServer.Init();

            //Start Telnet Server
            if (Database.GetSetting("EnableTelnet", "YAMS") == "true")
            {
                TelnetServer.Init();
            }
        }