Example #1
0
        /// <summary>
        /// Wipes the world for this server and optionally resets the seed in the server.properties
        /// </summary>
        /// <param name="bolRandomSeed">Boolean indicating if a new seed is required</param>
        public void ClearWorld(bool bolRandomSeed)
        {
            bool bolWasRunning = false;

            if (this.Running)
            {
                bolWasRunning = true;
                this.Stop();
            }
            Backup.BackupNow(this);

            Directory.Delete(this.ServerDirectory + "\\world", true);
            Database.AddLog(DateTime.Now, "World Deleted", "server", "info", false, this.ServerID);
            Directory.CreateDirectory(this.ServerDirectory + "\\world");

            if (bolRandomSeed)
            {
                Random random        = new Random();
                string strRandomSeed = random.Next(-2147483648, 2147483647).ToString();  //These are the upper and lower limits for a seed number in Minecraft
                this.SaveProperty("level-seed", strRandomSeed);
                Database.AddLog(DateTime.Now, "Seed Changed to " + strRandomSeed, "server", "info", false, this.ServerID);
            }

            if (bolWasRunning)
            {
                this.Start();
            }
        }
Example #2
0
        public MCServer(int intServerID)
        {
            this.ServerID = intServerID;

            //Set this first so that we can use it right away
            this.ServerDirectory = Core.StoragePath + this.ServerID.ToString() + @"\";

            //Set this here to catch any old references to it.
            this.strWorkingDir = this.ServerDirectory;

            this.bolEnableJavaOptimisations = Convert.ToBoolean(Database.GetSetting(this.ServerID, "ServerEnableOptimisations"));
            this.intAssignedMem             = Convert.ToInt32(Database.GetSetting(this.ServerID, "ServerAssignedMemory"));
            this.ServerTitle = Convert.ToString(Database.GetSetting(this.ServerID, "ServerTitle"));
            this.ServerType  = Convert.ToString(Database.GetSetting(this.ServerID, "ServerType"));
            this.LogonMode   = Convert.ToString(Database.GetSetting(this.ServerID, "ServerLogonMode"));
            this.ListenIP    = this.GetProperty("server-ip");
            this.Port        = Convert.ToInt32(this.GetProperty("server-port"));

            if (this.Port == null)
            {
                this.Port = 25565;
            }
            if (this.ListenIP == null)
            {
                this.ListenIP = "*";
            }

            //There is a bug in <0.3.2 that causes double worlds, detect and correct
            if (this.GetProperty("level-name") == @"..\\world")
            {
                try
                {
                    this.SaveProperty("level-name", "world");
                    //Backup the dupe world, just in case
                    Backup.BackupNow(this, "_dupeworld");

                    //Delete the world dir and replace with the duped one
                    Directory.Move(this.ServerDirectory + @"\world\", this.ServerDirectory + @"\world_duped\");
                    Directory.Move(Core.RootFolder + @"\servers\world\", this.ServerDirectory + @"\world\");

                    //Backup again
                    Backup.BackupNow(this, "_afterdedupe");

                    YAMS.Database.AddLog("Your world needed a de-duplication, the folder world_duped can be deleted if everything seems ok now", "app", "warn");
                }
                catch (Exception e)
                {
                    YAMS.Database.AddLog("Your world needs a de-duplication, but it couldn't be done automatically. Please report this issue: " + e.Data, "app", "error");
                }
            }
        }