Beispiel #1
0
        public static void Tick(object t)
        {
            DateTime datNow     = DateTime.Now;
            int      intMinutes = datNow.Minute;
            int      intHour    = datNow.Hour;

            //is it time to phone home?
            if (Database.GetSetting("UsageData", "YAMS") == "true" && intHour == 12 && intMinutes == 0)
            {
                Util.PhoneHome();
            }

            //Get jobs for current minute
            SqlCeDataReader rdJobs = Database.GetJobs(intHour, intMinutes);

            MCServer s;

            while (rdJobs.Read())
            {
                switch (rdJobs["JobAction"].ToString())
                {
                case "overviewer":
                    s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                    AddOns.Overviewer gmap = new AddOns.Overviewer(s, rdJobs["JobParams"].ToString());
                    gmap.Start();
                    break;

                case "biome-extractor":
                    s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                    AddOns.BiomeExtractor extractor = new AddOns.BiomeExtractor(s, rdJobs["JobParams"].ToString());
                    extractor.Start();
                    break;

                default:
                    Database.AddLog("Invalid entry in Job database", "job", "warn");
                    break;
                }
            }
        }
Beispiel #2
0
        public static void Tick(object t)
        {
            DateTime datNow = DateTime.Now;
            int intMinutes = datNow.Minute;
            int intHour = datNow.Hour;

            //is it time to phone home?
            if (Database.GetSetting("UsageData", "YAMS") == "true" && intMinutes == 0) Util.PhoneHome();

            //Should we check DNS?
            if (intMinutes % 5 == 0 && Database.GetSetting("DNSName", "YAMS") != "") Util.UpdateDNS();

            //Get jobs for current minute
            SqlCeDataReader rdJobs = Database.GetJobs(intHour, intMinutes);

            MCServer s;

            while (rdJobs.Read())
            {
                try
                {

                    //Split up the parameters
                    string strParams = rdJobs["JobParams"].ToString();
                    Dictionary<string, string> jobParams = new Dictionary<string, string> { };

                    if (strParams != "")
                    {
                        string[] arrKeys = strParams.Split('&');
                        foreach (string strKey in arrKeys)
                        {
                            string[] arrValues = strKey.Split('=');
                            if (arrValues.Length == 2)
                            {
                                jobParams.Add(arrValues[0], arrValues[1]);
                            }
                            else
                            {
                                Database.AddLog("Params failed on job. String was " + strParams, "job", "warn");
                            }
                        }
                    }

                    switch (rdJobs["JobAction"].ToString())
                    {
                        case "overviewer":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            AddOns.Overviewer gmap = new AddOns.Overviewer(s, rdJobs["JobParams"].ToString());
                            gmap.Start();
                            break;
                        case "c10t":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            AddOns.c10t c10t = new AddOns.c10t(s, rdJobs["JobParams"].ToString());
                            c10t.Start();
                            break;
                        case "biome-extractor":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            AddOns.BiomeExtractor extractor = new AddOns.BiomeExtractor(s, rdJobs["JobParams"].ToString());
                            extractor.Start();
                            break;
                        case "backup":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            Backup.BackupIfNeeded(s);
                            break;
                        case "update":
                            AutoUpdate.CheckUpdates();
                            break;
                        case "delayedrestart":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            s.DelayedRestart(Convert.ToInt32(rdJobs["JobParams"]));
                            break;
                        case "restartwhenfree":
                            s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                            s.RestartIfEmpty();
                            break;
                        case "clearlogs":
                            Database.ClearLogs(jobParams["period"], Convert.ToInt32(jobParams["amount"]));
                            break;
                        case "clearbackups":
                            Backup.ClearBackups(Core.Servers[Convert.ToInt32(rdJobs["JobServer"])], jobParams["period"], Convert.ToInt32(jobParams["amount"]));
                            break;
                        default:
                            Database.AddLog("Invalid entry in Job database", "job", "warn");
                            break;
                    }

                } catch (Exception e) {
                    YAMS.Database.AddLog("Error running job: " + e.Message, "job", "error");
                }
            }
        }
Beispiel #3
0
        public static void Tick(object t)
        {
            DateTime datNow     = DateTime.Now;
            int      intMinutes = datNow.Minute;
            int      intHour    = datNow.Hour;

            //is it time to phone home?
            if (Database.GetSetting("UsageData", "YAMS") == "true" && intMinutes == 0)
            {
                Util.PhoneHome();
            }

            //Should we check DNS?
            if (intMinutes % 5 == 0 && Database.GetSetting("DNSName", "YAMS") != "")
            {
                Util.UpdateDNS();
            }

            //Get jobs for current minute
            SqlCeDataReader rdJobs = Database.GetJobs(intHour, intMinutes);

            MCServer s;

            while (rdJobs.Read())
            {
                try
                {
                    //Split up the parameters
                    string strParams = rdJobs["JobParams"].ToString();
                    Dictionary <string, string> jobParams = new Dictionary <string, string> {
                    };

                    if (strParams != "")
                    {
                        string[] arrKeys = strParams.Split('&');
                        foreach (string strKey in arrKeys)
                        {
                            string[] arrValues = strKey.Split('=');
                            if (arrValues.Length == 2)
                            {
                                jobParams.Add(arrValues[0], arrValues[1]);
                            }
                            else
                            {
                                Database.AddLog("Params failed on job. String was " + strParams, "job", "warn");
                            }
                        }
                    }

                    switch (rdJobs["JobAction"].ToString())
                    {
                    case "overviewer":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        AddOns.Overviewer gmap = new AddOns.Overviewer(s, rdJobs["JobParams"].ToString());
                        gmap.Start();
                        break;

                    case "c10t":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        AddOns.c10t c10t = new AddOns.c10t(s, rdJobs["JobParams"].ToString());
                        c10t.Start();
                        break;

                    case "biome-extractor":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        AddOns.BiomeExtractor extractor = new AddOns.BiomeExtractor(s, rdJobs["JobParams"].ToString());
                        extractor.Start();
                        break;

                    case "backup":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        Backup.BackupIfNeeded(s);
                        break;

                    case "update":
                        AutoUpdate.CheckUpdates();
                        break;

                    case "delayedrestart":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        s.DelayedRestart(Convert.ToInt32(rdJobs["JobParams"]));
                        break;

                    case "restartwhenfree":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        s.RestartIfEmpty();
                        break;

                    case "start":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        s.Start();
                        break;

                    case "stop":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        s.Stop();
                        break;

                    case "clearlogs":
                        Database.ClearLogs(jobParams["period"], Convert.ToInt32(jobParams["amount"]));
                        break;

                    case "clearbackups":
                        Backup.ClearBackups(Core.Servers[Convert.ToInt32(rdJobs["JobServer"])], jobParams["period"], Convert.ToInt32(jobParams["amount"]));
                        break;

                    case "command":
                        s = Core.Servers[Convert.ToInt32(rdJobs["JobServer"])];
                        s.Send(jobParams["command"]);
                        break;

                    default:
                        Database.AddLog("Invalid entry in Job database", "job", "warn");
                        break;
                    }
                } catch (Exception e) {
                    YAMS.Database.AddLog("Error running job: " + e.Message, "job", "error");
                }
            }
        }
Beispiel #4
0
        public override void DoWork()
        {
            //Force a server save and turn off level saving
            this.Server.Save();
            this.Server.DisableSaving();

            //If we have Biome Extractor installed, we should run it
            BiomeExtractor BE = new BiomeExtractor(this.Server);
            if (BE.IsInstalled)
            {
                BE.Start();
                while (!BE.Complete) Thread.Sleep(5000);
            }

            string ServerRoot = this.Server.ServerDirectory;
            //Check the proper folders exist
            if (!Directory.Exists(ServerRoot + @"\renders\overviewer\")) Directory.CreateDirectory(ServerRoot + @"\renders\overviewer\");
            if (!Directory.Exists(ServerRoot + @"\renders\overviewer\output\")) Directory.CreateDirectory(ServerRoot + @"\renders\overviewer\output\");
            string strArgs = "";

            if (this.jobParams.ContainsKey("rendermodes"))
            {
                strArgs += " --rendermodes=" + jobParams["rendermodes"];
            }

            strArgs += " \"" + ServerRoot + "\\world\" \"" + ServerRoot + "renders\\overviewer\\output\"";

            Process prcOverviewer = new Process();
            prcOverviewer.StartInfo.UseShellExecute = false;
            prcOverviewer.StartInfo.FileName = this.FullExePath;
            prcOverviewer.StartInfo.Arguments = strArgs;
            prcOverviewer.StartInfo.CreateNoWindow = true;
            prcOverviewer.StartInfo.RedirectStandardError = true;
            prcOverviewer.StartInfo.RedirectStandardInput = true;
            prcOverviewer.StartInfo.RedirectStandardOutput = true;
            prcOverviewer.StartInfo.WorkingDirectory = this.FullFolderPath;

            //Set up events
            prcOverviewer.OutputDataReceived += new DataReceivedEventHandler(OverviewerOutput);
            prcOverviewer.ErrorDataReceived += new DataReceivedEventHandler(OverviewerError);
            prcOverviewer.EnableRaisingEvents = true;

            //Finally start the thing
            prcOverviewer.Start();
            prcOverviewer.BeginOutputReadLine();
            prcOverviewer.BeginErrorReadLine();

            Database.AddLog("Overviewer Path: " + strArgs, this.BaseName);
            Database.AddLog("Overviewer Started", this.BaseName);

            while (!prcOverviewer.WaitForExit(1000)) ;

            if (prcOverviewer.ExitCode == 0)
            {
                Database.AddLog("Overviewer Completed", this.BaseName);
                this.Complete = true;
                this.Result = true;
            }
            else
            {
                Database.AddLog("Overviewer Failed: " + prcOverviewer.ExitCode, this.BaseName, "error");
                this.Complete = true;
                this.Result = false;
            }
            Thread.Sleep(10000);

            //Re-enable server saving and updating
            this.Server.EnableSaving();

            //Must always call this to let base class know we're done
            this.Finish();
        }
Beispiel #5
0
        public override void DoWork()
        {
            //Force a server save and turn off level saving
            this.Server.Save();
            this.Server.DisableSaving();

            //If we have Biome Extractor installed, we should run it
            BiomeExtractor BE = new BiomeExtractor(this.Server);

            if (BE.IsInstalled)
            {
                BE.Start();
                while (!BE.Complete)
                {
                    Thread.Sleep(5000);
                }
            }

            string ServerRoot = this.Server.ServerDirectory;

            //Check the proper folders exist
            if (!Directory.Exists(ServerRoot + @"\renders\overviewer\"))
            {
                Directory.CreateDirectory(ServerRoot + @"\renders\overviewer\");
            }
            if (!Directory.Exists(ServerRoot + @"\renders\overviewer\output\"))
            {
                Directory.CreateDirectory(ServerRoot + @"\renders\overviewer\output\");
            }
            string strArgs = "";

            if (this.jobParams.ContainsKey("rendermodes"))
            {
                strArgs += " --rendermodes=" + jobParams["rendermodes"];
            }

            strArgs += " \"" + ServerRoot + "\\world\" \"" + ServerRoot + "renders\\overviewer\\output\"";

            Process prcOverviewer = new Process();

            prcOverviewer.StartInfo.UseShellExecute        = false;
            prcOverviewer.StartInfo.FileName               = this.FullExePath;
            prcOverviewer.StartInfo.Arguments              = strArgs;
            prcOverviewer.StartInfo.CreateNoWindow         = true;
            prcOverviewer.StartInfo.RedirectStandardError  = true;
            prcOverviewer.StartInfo.RedirectStandardInput  = true;
            prcOverviewer.StartInfo.RedirectStandardOutput = true;
            prcOverviewer.StartInfo.WorkingDirectory       = this.FullFolderPath;

            //Set up events
            prcOverviewer.OutputDataReceived += new DataReceivedEventHandler(OverviewerOutput);
            prcOverviewer.ErrorDataReceived  += new DataReceivedEventHandler(OverviewerError);
            prcOverviewer.EnableRaisingEvents = true;

            //Finally start the thing
            prcOverviewer.Start();
            prcOverviewer.BeginOutputReadLine();
            prcOverviewer.BeginErrorReadLine();

            Database.AddLog("Overviewer Path: " + strArgs, this.BaseName);
            Database.AddLog("Overviewer Started", this.BaseName);

            while (!prcOverviewer.WaitForExit(1000))
            {
                ;
            }

            if (prcOverviewer.ExitCode == 0)
            {
                Database.AddLog("Overviewer Completed", this.BaseName);
                this.Complete = true;
                this.Result   = true;
            }
            else
            {
                Database.AddLog("Overviewer Failed: " + prcOverviewer.ExitCode, this.BaseName, "error");
                this.Complete = true;
                this.Result   = false;
            }
            Thread.Sleep(10000);

            //Re-enable server saving and updating
            this.Server.EnableSaving();

            //Must always call this to let base class know we're done
            this.Finish();
        }