コード例 #1
0
        public static void Maintenance_OnCommand(CommandEventArgs e)
        {
            try
            {
                if (e.Length == 0)
                {
                    Usage(e);
                }
                else
                {
                    string strParam = e.GetString(0);

                    // default is 5 minutes from now
                    m_When = DateTime.Now + TimeSpan.FromMinutes(5);

                    if (e.Length > 1)
                    {                           // we have a date-time param
                        string sx = null;
                        for (int ix = 1; ix < e.Length; ix++)
                        {
                            sx += e.GetString(ix) + " ";
                        }
                        try { m_When = DateTime.Parse(sx); }
                        catch
                        {
                            e.Mobile.SendMessage("Bad date format.");
                            e.Mobile.SendMessage("Maintenance not initiated.");
                            Usage(e);
                            return;
                        }

                        TimeSpan diff = m_When.Subtract(DateTime.Now);
                        m_Countdown = (int)diff.TotalMinutes;
                    }

                    if (strParam.ToLower().Equals("cancel"))
                    {
                        m_Scheduled = false;
                        if (m_Rebuild)
                        {
                            if (KillRebuild())
                            {
                                e.Mobile.SendMessage("Rebuild.exe canceled succesfully.");
                                Rebuild = false;
                            }
                            else
                            {
                                e.Mobile.SendMessage("Error closeing rebuild.exe!!!");
                            }
                        }
                        AutoSave.SavesEnabled = true;
                        e.Mobile.SendMessage("Maintenance has been canceled.");
                        World.Broadcast(0x482, true, "Server maintenance has been canceled.");
                        m_Maintenance.Stop();
                    }
                    else if (strParam.ToLower().Equals("rebuild"))
                    {
                        if (Rebuild)
                        {
                            e.Mobile.SendMessage("The server is already prepareing for a rebuild.");
                        }
                        else
                        {
                            Rebuild               = true;
                            Shutdown              = true;
                            Scheduled             = true;
                            AutoSave.SavesEnabled = false;
                            e.Mobile.SendMessage("You have initiated a server rebuild.");
                            m_Maintenance.Start();

                            if (!StartRebuild(Misc.TestCenter.Enabled))
                            {
                                e.Mobile.SendMessage("Rebuild.exe failed to start, canceling rebuild.");
                                Rebuild   = false;
                                Scheduled = false;
                            }
                        }
                    }
                    else if (strParam.ToLower().Equals("restart") || strParam.ToLower().Equals("shutdown"))
                    {
                        if (m_Scheduled)
                        {
                            e.Mobile.SendMessage("The server is already restarting.");
                        }
                        else
                        {
                            m_Shutdown            = strParam.ToLower().Equals("shutdown") ? true : false;
                            m_Scheduled           = true;
                            AutoSave.SavesEnabled = false;
                            e.Mobile.SendMessage("You have initiated server {0}.", m_Shutdown ? "shutdown" : "restart");
                            m_Maintenance.Start();
                        }
                    }
                    else
                    {
                        Usage(e);
                    }
                }
            }
            catch (Exception exc)
            {
                LogHelper.LogException(exc);
                e.Mobile.SendMessage("There was a problem with the [Maintenance command!!  See console log");
                System.Console.WriteLine("Error with [Maintenance!");
                System.Console.WriteLine(exc.Message);
                System.Console.WriteLine(exc.StackTrace);
            }
        }
コード例 #2
0
ファイル: Maintenance.cs プロジェクト: zerodowned/angelisland
        public static void Maintenance_OnCommand(CommandEventArgs e)
        {
            try
            {
                if (e.Length == 0)
                {
                    Usage(e);
                }
                else
                {
                    string strParam = e.GetString(0);

                    if (strParam.ToLower().Equals("cancel"))
                    {
                        m_Scheduled = false;
                        if (m_Rebuild)
                        {
                            if (KillRebuild())
                            {
                                e.Mobile.SendMessage("Rebuild.exe canceled succesfully.");
                                Rebuild = false;
                            }
                            else
                            {
                                e.Mobile.SendMessage("Error closeing rebuild.exe!!!");
                            }
                        }
                        m_Countdown           = 5;
                        AutoSave.SavesEnabled = true;
                        e.Mobile.SendMessage("Maintenance has been canceled.");
                        World.Broadcast(0x482, true, "Server maintenance has been canceled.");
                        m_Maintenance.Stop();
                    }
                    else if (strParam.ToLower().Equals("rebuild"))
                    {
                        if (Rebuild)
                        {
                            e.Mobile.SendMessage("The server is already prepareing for a rebuild.");
                        }
                        else
                        {
                            Rebuild               = true;
                            Shutdown              = true;
                            Scheduled             = true;
                            AutoSave.SavesEnabled = false;
                            e.Mobile.SendMessage("You have initiated a server rebuild.");
                            m_Maintenance.Start();

                            if (!StartRebuild(Misc.TestCenter.Enabled))
                            {
                                e.Mobile.SendMessage("Rebuild.exe failed to start, canceling rebuild.");
                                Rebuild   = false;
                                Scheduled = false;
                            }
                        }
                    }
                    else if (strParam.ToLower().Equals("restart") || strParam.ToLower().Equals("shutdown"))
                    {
                        if (m_Scheduled)
                        {
                            e.Mobile.SendMessage("The server is already restarting.");
                        }
                        else
                        {
                            m_Shutdown            = strParam.ToLower().Equals("shutdown") ? true : false;
                            m_Scheduled           = true;
                            m_Countdown           = 5;
                            AutoSave.SavesEnabled = false;
                            e.Mobile.SendMessage("You have initiated server {0}.", m_Shutdown ? "shutdown" : "restart");
                            m_Maintenance.Start();
                        }
                    }
                    else
                    {
                        Usage(e);
                    }
                }
            }
            catch (Exception exc)
            {
                LogHelper.LogException(exc);
                e.Mobile.SendMessage("There was a problem with the [Maintenance command!!  See console log");
                System.Console.WriteLine("Error with [Maintenance!");
                System.Console.WriteLine(exc.Message);
                System.Console.WriteLine(exc.StackTrace);
            }
        }