Exemplo n.º 1
0
        public static void BackupNow(MCServer s, string strAppendName = "")
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\")) Directory.CreateDirectory(s.ServerDirectory + @"\backups\");

            //Force a save
            s.Save();
            s.DisableSaving();

            //Find all the directories that start with "world"
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");

            string[] dirs = Directory.GetDirectories(s.ServerDirectory, "world*");
            foreach (string dir in dirs)
            {
                //Copy world to a temp Dir
                DirectoryInfo thisDir = new DirectoryInfo(dir);
                Util.Copy(dir, s.ServerDirectory + @"\backups\temp\" + thisDir.Name);
            }

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();
            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("D2") + "-" + DateTime.Now.Day.ToString("D2") + "-" + DateTime.Now.Hour.ToString("D2") + "-" + DateTime.Now.Minute.ToString("D2") + strAppendName + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0) s.HasChanged = false;
        }
Exemplo n.º 2
0
        public Player(string strName, MCServer s)
        {
            this.Username = strName;
            this.Server   = s;

            this.Level = Database.GetPlayerLevel(strName, s.ServerID);

            if (this.Level == null)
            {
                //We're letting anyone in these days, so add to the DB
                Database.AddUser(this.Username, this.Server.ServerID);
                this.Level = "guest";
            }

            //check the op list
            if (Util.SearchFile(s.ServerDirectory + "ops.txt", strName))
            {
                this.Level = "op";
            }

            //Emulate MOTD
            if (Database.GetSetting("motd", "MC", this.Server.ServerID) != "")
            {
                this.SendMessage(Database.GetSetting("motd", "MC", this.Server.ServerID));
            }
        }
Exemplo n.º 3
0
        public static void ClearBackups(MCServer s, string strPeriod, int intAmount)
        {
            Database.AddLog("Clearing backups older than " + intAmount.ToString() + " " + strPeriod, "backup", "info", false, s.ServerID);

            string[] files = Directory.GetFiles(s.ServerDirectory + @"\backups\");

            foreach (string file in files)
            {
                FileInfo fi      = new FileInfo(file);
                DateTime endTime = new DateTime();
                switch (strPeriod)
                {
                case "yy":
                    endTime = DateTime.Now.AddYears(-intAmount);
                    break;

                case "mm":
                    endTime = DateTime.Now.AddMonths(-intAmount);
                    break;

                case "dd":
                    endTime = DateTime.Now.AddDays(-intAmount);
                    break;
                }
                if (fi.CreationTime < endTime)
                {
                    fi.Delete();
                }
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            //Start DB Connection
            Database.init();
            Database.AddLog("Starting Up");

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

            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);
                Core.Servers.Add(ServerID, myServer);
            }

            //Start Webserver
            WebServer.Init();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
Exemplo n.º 5
0
        public static void ClearBackups(MCServer s, string strPeriod, int intAmount)
        {
            Database.AddLog("Clearing backups older than " + intAmount.ToString() + " " + strPeriod, "backup", "info", false, s.ServerID);

            string[] files = Directory.GetFiles(s.ServerDirectory + @"\backups\");

            foreach (string file in files)
            {
                FileInfo fi = new FileInfo(file);
                DateTime endTime = new DateTime();
                switch (strPeriod)
                {
                    case "yy":
                        endTime = DateTime.Now.AddYears(-intAmount);
                        break;
                    case "mm":
                        endTime = DateTime.Now.AddMonths(-intAmount);
                        break;
                    case "dd":
                        endTime = DateTime.Now.AddDays(-intAmount);
                        break;
                }
                if (fi.CreationTime < endTime)
                    fi.Delete();
            }
        }
Exemplo n.º 6
0
        public static void BackupNow(MCServer s)
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\")) Directory.CreateDirectory(s.ServerDirectory + @"\backups\");

            //Force a save
            s.Save();
            s.DisableSaving();

            //Copy world to a temp Dir
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\")) Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");
            Util.Copy(s.ServerDirectory + @"\world\", s.ServerDirectory + @"\backups\temp\");

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();
            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0) s.HasChanged = false;
        }
Exemplo n.º 7
0
        static void Main()
        {

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

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

            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();
                Core.Servers.Add(Convert.ToInt32(readerServers["ServerID"]), myServer);
            }

            //Start job engine
            JobEngine.Init();

            //Start Webserver
            WebServer.Init();
        
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());
        }
Exemplo n.º 8
0
 public static void BackupIfNeeded(MCServer s)
 {
     //Only backup if the world has changed since last one
     if (s.HasChanged)
     {
         BackupNow(s);
     }
 }
Exemplo n.º 9
0
 public static void BackupIfNeeded(MCServer s)
 {
     //Only backup if the world has changed since last one
     if (s.HasChanged)
     {
         BackupNow(s);
     }
 }
Exemplo n.º 10
0
        public static void BackupNow(MCServer s, string strAppendName = "")
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\"))
            {
                Directory.CreateDirectory(s.ServerDirectory + @"\backups\");
            }

            //Force a save
            s.Save();
            s.DisableSaving();

            //Find all the directories that start with "world"
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\"))
            {
                Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            }
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\"))
            {
                Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");
            }

            string[] dirs = Directory.GetDirectories(s.ServerDirectory, "world*");
            foreach (string dir in dirs)
            {
                //Copy world to a temp Dir
                DirectoryInfo thisDir = new DirectoryInfo(dir);
                Util.Copy(dir, s.ServerDirectory + @"\backups\temp\" + thisDir.Name);
            }

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();

            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("D2") + "-" + DateTime.Now.Day.ToString("D2") + "-" + DateTime.Now.Hour.ToString("D2") + "-" + DateTime.Now.Minute.ToString("D2") + strAppendName + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0)
            {
                s.HasChanged = false;
            }
        }
Exemplo n.º 11
0
        public Player(string strName, MCServer s)
        {
            this.Username = strName;
            this.Server = s;

            this.Level = Database.GetPlayerLevel(strName, s.ServerID);

            if (this.Level == null)
            {
                //We're letting anyone in these days, so add to the DB
                Database.AddUser(this.Username, this.Server.ServerID);
                this.Level = "guest";
            }

            //check the op list
            //if (Util.SearchFile(s.ServerDirectory + "ops.txt", strName)) this.Level = "op";

            //Emulate MOTD
            if (Database.GetSetting("motd", "MC", this.Server.ServerID) != "") this.SendMessage(Database.GetSetting("motd", "MC", this.Server.ServerID));
        }
Exemplo n.º 12
0
        public static void BackupNow(MCServer s)
        {
            Database.AddLog("Backing up " + s.ServerTitle, "backup");

            //Check for a backup dir and create if not
            if (!Directory.Exists(s.ServerDirectory + @"\backups\"))
            {
                Directory.CreateDirectory(s.ServerDirectory + @"\backups\");
            }

            //Force a save
            s.Save();
            s.DisableSaving();

            //Copy world to a temp Dir
            if (Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\"))
            {
                Directory.Delete(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\", true);
            }
            if (!Directory.Exists(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\"))
            {
                Directory.CreateDirectory(Core.StoragePath + s.ServerID.ToString() + @"\backups\temp\");
            }
            Util.Copy(s.ServerDirectory + @"\world\", s.ServerDirectory + @"\backups\temp\");

            //Re-enable saving then force another save
            s.EnableSaving();
            s.Save();

            //Now zip up temp dir and move to backups
            FastZip z = new FastZip();

            z.CreateEmptyDirectories = true;
            z.CreateZip(s.ServerDirectory + @"\backups\" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + ".zip", s.ServerDirectory + @"\backups\temp\", true, "");

            //If the server is empty, reset the HasChanged
            if (s.Players.Count == 0)
            {
                s.HasChanged = false;
            }
        }
Exemplo n.º 13
0
 //Set this class's server
 public App(MCServer s, string strBaseName, string strMainExe, string strName, bool bolRequiresClient, string strParams)
 {
     //set up runtime actions
     this.BaseName = strBaseName;
     this.MainExe = strMainExe;
     this.Name = strName;
     this.RequiresClient = bolRequiresClient;
     this.FullFolderPath = Core.RootFolder + @"\apps\" + this.BaseName;
     this.FullExePath = this.FullFolderPath + @"\" + this.MainExe;
     //have we had any options set?
     if (strParams != "")
     {
         string[] arrKeys = strParams.Split('&');
         foreach (string strKey in arrKeys)
         {
             string[] arrValues = strKey.Split('=');
             if (arrValues.Length == 2)
             {
                 this.jobParams.Add(arrValues[0], arrValues[1]);
             }
             else
             {
                 Database.AddLog("Params failed on " + this.Name + ". String was " + strParams, this.BaseName, "warn");
             }
         }
     }
     //Is it installed?
     if (File.Exists(this.FullExePath))
     {
         this.IsInstalled = true;
         this.Server = s;
     }
     else
     {
         Database.AddLog(this.Name + " is not installed", "addons", "error");
     }
 }
Exemplo n.º 14
0
 public Tectonicus(MCServer s, string strParams = "")
     : base(s, "tectonicus", @"tectonicus.jar", "Tectonicus", true, strParams)
 {
 }
Exemplo n.º 15
0
        public static int NewServerWeb(List <KeyValuePair <string, string> > listServer, string strServerTitle, int intServerMemory = 1024)
        {
            lock (_lock)
            {
                if (!conn.Ping())
                {
                    conn.Close();
                    init();
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                //Create the server and get an ID
                cmd.CommandText = "INSERT INTO MCServers (ServerTitle, ServerWrapperMode, ServerAssignedMemory, ServerAutostart) VALUES (@title, 0, @mem, 0)";
                cmd.Parameters.AddWithValue("@title", strServerTitle);
                cmd.Parameters.AddWithValue("@mem", intServerMemory);
                cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT ServerID FROM MCServers WHERE ServerTitle = @title";
                cmd.Parameters.AddWithValue("@title", strServerTitle);
                MySqlDataReader r        = cmd.ExecuteReader();
                int             intNewID = 0;
                if (r.HasRows)
                {
                    r.Read();
                    intNewID = r.GetInt32("ServerID");
                    r.Close();
                }

                //Set up Files + Folders
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString()))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString());
                }
                //if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\config\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\config\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\world\"))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\world\");
                }
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\backups\"))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\backups\");
                }
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\"))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\");
                }
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\"))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\");
                }
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\"))
                {
                    Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\");
                }
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt"))
                {
                    File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt");
                }
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt"))
                {
                    File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt");
                }
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\ops.txt"))
                {
                    File.Create(Core.StoragePath + intNewID.ToString() + @"\ops.txt");
                }
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\white-list.txt"))
                {
                    File.Create(Core.StoragePath + intNewID.ToString() + @"\white-list.txt");
                }

                //Insert the settings into the DB for this server
                foreach (var element in listServer)
                {
                    cmd.Parameters.Clear();
                    cmd.CommandText = "INSERT INTO MCSettings (ServerID, SettingName, SettingValue) VALUES (@id, @name, @value);";
                    cmd.Parameters.AddWithValue("@id", intNewID);
                    cmd.Parameters.AddWithValue("@name", element.Key);
                    cmd.Parameters.AddWithValue("@value", element.Value);
                    cmd.ExecuteNonQuery();
                }

                //Create default config files
                BuildServerProperties(intNewID);

                //Add the server to the collection
                MCServer myServer = new MCServer(intNewID);
                Core.Servers.Add(intNewID, myServer);

                return(intNewID);
            }
        }
Exemplo n.º 16
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();
        }
Exemplo n.º 17
0
        public static int NewServerWeb(List<KeyValuePair<string, string>> listServer, string strServerTitle, int intServerMemory = 1024)
        {
            SqlCeCommand cmd = new SqlCeCommand();
            cmd.Connection = connLocal;

            //Create the server and get an ID
            cmd.CommandText = "INSERT INTO MCServers (ServerTitle, ServerWrapperMode, ServerAssignedMemory, ServerAutostart) VALUES (@title, 0, @mem, 0)";
            cmd.Parameters.Add("@title", strServerTitle);
            cmd.Parameters.Add("@mem", intServerMemory);
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            cmd.CommandText = "SELECT @@IDENTITY";
            int intNewID = Convert.ToInt32(cmd.ExecuteScalar());

            //Set up Files + Folders
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString())) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString());
            //if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\config\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\config\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\world\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\world\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\backups\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\backups\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\");
            if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt");
            if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt");
            if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\ops.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\ops.txt");
            if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\white-list.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\white-list.txt");

            //Insert the settings into the DB for this server
            foreach (var element in listServer)
            {
                cmd.Parameters.Clear();
                cmd.CommandText = "INSERT INTO MCSettings (ServerID, SettingName, SettingValue) VALUES (@id, @name, @value);";
                cmd.Parameters.Add("@id", intNewID);
                cmd.Parameters.Add("@name", element.Key);
                cmd.Parameters.Add("@value", element.Value);
                cmd.ExecuteNonQuery();
            }

            //Create default config files
            BuildServerProperties(intNewID);

            //Add the server to the collection
            MCServer myServer = new MCServer(intNewID);
            Core.Servers.Add(intNewID, myServer);

            return intNewID;
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
0
 public Overviewer(MCServer s, string strParams = "rendermodes=normal,lighting,night")
     : base(s, "overviewer", @"overviewer.exe", "Overviewer", true, strParams)
 {
 }
Exemplo n.º 20
0
 public BiomeExtractor(MCServer s, string strParams = "")
     : base(s, "biome-extractor", @"MinecraftBiomeExtractor.jar", "Biome Extractor", true, strParams)
 {
 }
Exemplo n.º 21
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();
        }
Exemplo n.º 22
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 and start a timer to do it automatically
            //AutoUpdate.CheckUpdates();
            int UpdateTick = (60 * 60 * 1000);

            if (Database.GetSetting("UpdateBranch", "YAMS") == "dev")
            {
                UpdateTick = (15 * 60 * 1000);
            }
            timUpdate = new Timer(new TimerCallback(timUpdate_Tick), null, 0, UpdateTick);

            //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);
            }

            //Schedule a backup for all servers (temporarily here before going in job engine)
            int BackupTick = (60 * 60 * 1000);

            timBackup = new Timer(new TimerCallback(timBackup_Tick), null, 5 * 60 * 1000, BackupTick);

            //Start job engine
            JobEngine.Init();

            //Start Webserver
            WebServer.Init();
        }
Exemplo n.º 23
0
 public c10t(MCServer s, string strParams = "night=false&mode=normal")
     : base(s, "c10t", @"c10t.exe", "c10t", true, strParams)
 {
 }
Exemplo n.º 24
0
        public static int NewServerWeb(List <KeyValuePair <string, string> > listServer, string strServerTitle, int intServerMemory = 1024)
        {
            SqlCeCommand cmd = new SqlCeCommand();

            cmd.Connection = connLocal;

            //Create the server and get an ID
            cmd.CommandText = "INSERT INTO MCServers (ServerTitle, ServerWrapperMode, ServerAssignedMemory, ServerAutostart) VALUES (@title, 0, @mem, 0)";
            cmd.Parameters.Add("@title", strServerTitle);
            cmd.Parameters.Add("@mem", intServerMemory);
            cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            cmd.CommandText = "SELECT @@IDENTITY";
            int intNewID = Convert.ToInt32(cmd.ExecuteScalar());

            //Set up Files + Folders
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString()))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString());
            }
            //if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\config\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\config\");
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\world\"))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\world\");
            }
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\backups\"))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\backups\");
            }
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\"))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\");
            }
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\"))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\");
            }
            if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\"))
            {
                Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\");
            }
            //if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt");
            //if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt");
            //if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\ops.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\ops.txt");
            //if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\white-list.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\white-list.txt");

            //Insert the settings into the DB for this server
            foreach (var element in listServer)
            {
                cmd.Parameters.Clear();
                cmd.CommandText = "INSERT INTO MCSettings (ServerID, SettingName, SettingValue) VALUES (@id, @name, @value);";
                cmd.Parameters.Add("@id", intNewID);
                cmd.Parameters.Add("@name", element.Key);
                cmd.Parameters.Add("@value", element.Value);
                cmd.ExecuteNonQuery();
            }

            //Create default config files
            BuildServerProperties(intNewID);

            //Add the server to the collection
            MCServer myServer = new MCServer(intNewID);

            Core.Servers.Add(intNewID, myServer);

            return(intNewID);
        }
Exemplo n.º 25
0
        public static int NewServerWeb(List<KeyValuePair<string, string>> listServer, string strServerTitle, int intServerMemory = 1024)
        {
            lock (_lock)
            {
                if (!conn.Ping())
                {
                    conn.Close();
                    init();
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                //Create the server and get an ID
                cmd.CommandText = "INSERT INTO MCServers (ServerTitle, ServerWrapperMode, ServerAssignedMemory, ServerAutostart) VALUES (@title, 0, @mem, 0)";
                cmd.Parameters.AddWithValue("@title", strServerTitle);
                cmd.Parameters.AddWithValue("@mem", intServerMemory);
                cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                cmd.CommandText = "SELECT ServerID FROM MCServers WHERE ServerTitle = @title";
                cmd.Parameters.AddWithValue("@title", strServerTitle);
                MySqlDataReader r = cmd.ExecuteReader();
                int intNewID = 0;
                if (r.HasRows)
                {
                    r.Read();
                    intNewID = r.GetInt32("ServerID");
                    r.Close();
                }

                //Set up Files + Folders
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString())) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString());
                //if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\config\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\config\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\world\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\world\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\backups\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\backups\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\");
                if (!Directory.Exists(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\")) Directory.CreateDirectory(Core.StoragePath + intNewID.ToString() + @"\renders\overviewer\output\");
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-ips.txt");
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\banned-players.txt");
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\ops.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\ops.txt");
                if (!File.Exists(Core.StoragePath + intNewID.ToString() + @"\white-list.txt")) File.Create(Core.StoragePath + intNewID.ToString() + @"\white-list.txt");

                //Insert the settings into the DB for this server
                foreach (var element in listServer)
                {
                    cmd.Parameters.Clear();
                    cmd.CommandText = "INSERT INTO MCSettings (ServerID, SettingName, SettingValue) VALUES (@id, @name, @value);";
                    cmd.Parameters.AddWithValue("@id", intNewID);
                    cmd.Parameters.AddWithValue("@name", element.Key);
                    cmd.Parameters.AddWithValue("@value", element.Value);
                    cmd.ExecuteNonQuery();
                }

                //Create default config files
                BuildServerProperties(intNewID);

                //Add the server to the collection
                MCServer myServer = new MCServer(intNewID);
                Core.Servers.Add(intNewID, myServer);

                return intNewID;
            }
        }