Пример #1
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            var dims   = new[] { "TestDimenValue1", "TestDimenValue2" };
            var names  = new[] { "TestName1", "TestName2" };
            var nss    = new[] { "TestNameSpace1", "TestNameSpace2" };
            var units  = new[] { "Kilobytes", "Megabytes", "Gigabytes" };
            var random = new Random();


            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (int i = 0; i < nTicks; i++)
            {
                //log.Info("A tick! Value: 2, Unit: Bytes, Unit: Kilobytes");

                if (random.Next(2) == 0)
                {
                    log.InfoFormat("A tick! Namespace: {1} MetricCOMMENTName: {2} Dimension: TestDim: {3} Value: {0} {4}",
                                   random.NextDouble() * (1e5 - 1e2) + 1e2,
                                   nss[random.Next(2)], names[random.Next(2)], dims[random.Next(2)], units[random.Next(3)]);
                }
                else
                {
                    var metricDatum = new MetricDatum("A tick!");
                    metricDatum.NameSpace = nss[random.Next(2)];
                    metricDatum.Dimensions.Add(new Dimension {
                        Name = "TestDim", Value = dims[random.Next(2)]
                    });
                    metricDatum.Unit                        = units[random.Next(3)];
                    metricDatum.StatisticValues             = new StatisticSet();
                    metricDatum.StatisticValues.Minimum     = random.NextDouble() * (3e3 - 1e2) + 1e2;
                    metricDatum.StatisticValues.Maximum     = random.NextDouble() * (1.1e5 - .9e4) + .9e4;
                    metricDatum.StatisticValues.Sum         = (random.NextDouble() * (6e4 - 4e4) + 4e4) * 100;
                    metricDatum.StatisticValues.SampleCount = 100;
                    log.Info(metricDatum);
                }

                Thread.Sleep(10);
            }

            ILoggerRepository rep = LogManager.GetRepository();

            foreach (IAppender appender in rep.GetAppenders())
            {
                var buffered = appender as BufferingAppenderSkeleton;
                if (buffered != null)
                {
                    buffered.Flush();
                }
            }

            stopWatch.Stop();
            Console.WriteLine("All {0} ticks in {1} ms.\nWaiting for requests to complete.", nTicks, stopWatch.ElapsedMilliseconds);

            stopWatch.Start();
            ServiceTasks.WaitForPendingRequests();

            stopWatch.Stop();
            Console.WriteLine("Requests completed in {0} ms.", stopWatch.ElapsedMilliseconds);
        }
Пример #2
0
        public void RegisterCommonAppenders(IConfig startupConfig)
        {
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                }
                else if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = (FileAppender)appender;
                }
                else if (appender.Name == "StatsLogFileAppender")
                {
                    m_statsLogFileAppender = (FileAppender)appender;
                }
            }

            if (null == m_consoleAppender)
            {
                Notice("No appender named Console found (see the log4net config file for this executable)!");
            }
            else
            {
                // FIXME: This should be done through an interface rather than casting.
                m_consoleAppender.Console = (ConsoleBase)m_console;

                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }

                Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
            }

            if (m_logFileAppender != null && startupConfig != null)
            {
                string cfgFileName = startupConfig.GetString("LogFile", null);
                if (cfgFileName != null)
                {
                    m_logFileAppender.File = cfgFileName;
                    m_logFileAppender.ActivateOptions();
                }

                m_log.InfoFormat("[SERVER BASE]: Logging started to file {0}", m_logFileAppender.File);
            }

            if (m_statsLogFileAppender != null && startupConfig != null)
            {
                string cfgStatsFileName = startupConfig.GetString("StatsLogFile", null);
                if (cfgStatsFileName != null)
                {
                    m_statsLogFileAppender.File = cfgStatsFileName;
                    m_statsLogFileAppender.ActivateOptions();
                }

                m_log.InfoFormat("[SERVER BASE]: Stats Logging started to file {0}", m_statsLogFileAppender.File);
            }
        }
Пример #3
0
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[]       appenders  = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;

                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                    {
                        m_consoleAppender.Threshold = Level.All;
                    }

                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }

                m_console.Commands.AddCommand("base", false, "quit",
                                              "quit",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "shutdown",
                                              "shutdown",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "forcegc",
                                              "forcegc [ 0|1|2|*|now ]",
                                              "Forces an immediate full garbage collection (testing/dev only)", HandleForceGC);

                m_console.Commands.AddCommand("base", false, "set log level",
                                              "set log level <level>",
                                              "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("base", false, "show info",
                                              "show info",
                                              "Show general information", HandleShow);

                m_console.Commands.AddCommand("base", false, "show stats",
                                              "show stats",
                                              "Show statistics", HandleShow);

                m_console.Commands.AddCommand("base", false, "show threads",
                                              "show threads",
                                              "Show thread status", HandleShow);

                m_console.Commands.AddCommand("base", false, "show uptime",
                                              "show uptime",
                                              "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("base", false, "show version",
                                              "show version",
                                              "Show server version", HandleShow);
            }
        }
Пример #4
0
        private void SetUpConsole(IConfigSource config, IRegistryCore registry)
        {
            List <ICommandConsole> Plugins = AuroraModuleLoader.PickupModules <ICommandConsole>();

            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize(config, registry.RequestModuleInterface <ISimulationBase>());
            }

            List <INotificationService> NotificationPlugins = AuroraModuleLoader.PickupModules <INotificationService>();

            foreach (INotificationService plugin in NotificationPlugins)
            {
                plugin.Init(config, registry);
            }

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = MainConsole.Instance;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }
                repository.Threshold = m_consoleAppender.Threshold;
                foreach (ILogger log in repository.GetCurrentLoggers())
                {
                    log.Level = m_consoleAppender.Threshold;
                }
            }
            IAppender logFileAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    logFileAppender = appender;
                }
            }

            if (logFileAppender != null)
            {
                if (logFileAppender is FileAppender)
                {
                    FileAppender appender      = (FileAppender)logFileAppender;
                    IConfig      startupConfig = config.Configs["Startup"];
                    string       fileName      = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }
            if (MainConsole.Instance == null)
            {
                m_log.Info("[Console]: No Console located");
                return;
            }

            MainConsole.Instance.MaxLogLevel = m_consoleAppender.Threshold;
            if (m_consoleAppender != null)
            {
                MainConsole.Instance.Fatal(String.Format("[Console]: Console log level is {0}", m_consoleAppender.Threshold));
            }

            MainConsole.Instance.Commands.AddCommand("set log level", "set log level [level]", "Set the console logging level", HandleLogLevel);

            MainConsole.Instance.Commands.AddCommand("get log level", "get log level", "Returns the current console logging level", HandleGetLogLevel);
        }
Пример #5
0
        // Handle all the automagical stuff
        //
        public ServicesServerBase(string prompt, string[] args)
        {
            m_startuptime = DateTime.Now;

            // Save raw arguments
            //
            m_Arguments = args;

            // Read command line
            //
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");
            argvConfig.AddSwitch("Startup", "prompt", "p");
            argvConfig.AddSwitch("Startup", "logconfig", "g");

            // Automagically create the ini file name
            //
            string fileName  = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            string iniFile   = fileName + ".ini";
            string logConfig = null;

            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                // Check if a file name was given on the command line
                //
                iniFile = startupConfig.GetString("inifile", iniFile);
                //
                // Check if a prompt was given on the command line
                prompt = startupConfig.GetString("prompt", prompt);
                //
                // Check for a Log4Net config file on the command line
                logConfig = startupConfig.GetString("logconfig", logConfig);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            //
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
                    configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error reading from config source.  {0}", e.Message);
                Environment.Exit(1);
            }

            // Merge the configuration from the command line into the
            // loaded file
            //
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            //
            if (m_Config.Configs["Startup"] != null)
            {
                startupConfig = m_Config.Configs["Startup"];
            }

            prompt = startupConfig.GetString("Prompt", prompt);

            // Allow derived classes to load config before the console is
            // opened.
            //
            ReadConfig();

            // Create main console
            //
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else if (consoleType == "rest")
            {
                MainConsole.Instance = new RemoteConsole(prompt);
                ((RemoteConsole)MainConsole.Instance).ReadConfig(Config);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            //
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            if (logConfig != null)
            {
                FileInfo cfg = new FileInfo(logConfig);
                XmlConfigurator.Configure(cfg);
            }
            else
            {
                XmlConfigurator.Configure();
            }

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }
                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = (ConsoleBase)MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            //
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    string cfgFileName = startupConfig.GetString("logfile", null);
                    if (cfgFileName != null)
                    {
                        fileAppender.File = cfgFileName;
                        fileAppender.ActivateOptions();
                    }
                }
            }

            if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
            {
                CreatePIDFile(startupConfig.GetString("PIDFile"));
            }

            // Register the quit command
            //
            MainConsole.Instance.Commands.AddCommand("General", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
                                                     "shutdown",
                                                     "Quit the application", HandleQuit);

            // Register a command to read other commands from a file
            MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
                                                     "command-script <script>",
                                                     "Run a command script from file", HandleScript);

            MainConsole.Instance.Commands.AddCommand("General", false, "show uptime",
                                                     "show uptime",
                                                     "Show server uptime", HandleShow);


            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            //
            Initialise();
        }
Пример #6
0
        private static void SendMailError(AdvException currError)
        {
            if (HttpContext.Current != null && HttpContext.Current.Request.Url.AbsoluteUri.Contains("localhost"))
            {
                return;
            }

            lock (Sync)
            {
                var data = LogTempDataService.GetLogTempData();
                if (data.MailErrorLastSend.DayOfYear < DateTime.Now.DayOfYear)
                {
                    data.MailErrorCurrentCount = 0;
                }
                if (data.MailErrorCurrentCount < MaxMailsSendPerDay)
                {
                    if (File.Exists(EmailNotificationTemplate))
                    {
                        var template = new StringBuilder(File.ReadAllText(EmailNotificationTemplate));

                        template.Replace("CommonInfo_Header", Resource.Admin_MasterPageAdmin_BugTracker_CommonInfo);
                        var outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        outHtml.Append("<table>");
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "Message", currError.ExceptionData.ManualMessage.IsNullOrEmpty() ? "none" : currError.ExceptionData.ManualMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionMessage", currError.ExceptionData.ExceptionMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "ExceptionStackTrace", currError.ExceptionData.ExceptionStackTrace.IsNullOrEmpty() ? "none" : currError.ExceptionData.ExceptionStackTrace);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionMessage", currError.ExceptionData.InnerExceptionMessage.IsNullOrEmpty() ? "none" : currError.ExceptionData.InnerExceptionMessage);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", "InnerExceptionStackTrace", currError.ExceptionData.InnerExceptionStackTrace.IsNullOrEmpty() ? "none" : currError.ExceptionData.InnerExceptionStackTrace);
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");
                        foreach (var key in currError.ExceptionData.Parameters.Keys)
                        {
                            outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.ExceptionData.Parameters[key]);
                        }
                        outHtml.Append("<tr><td colspan='2'><hr/></td></td></tr>");

                        outHtml.Append("</table>");
                        outHtml.Append("</div>");
                        template.Replace("CommonInfo_Body", outHtml.ToString());


                        template.Replace("Request_Header", Resource.Admin_MasterPageAdmin_BugTracker_Request);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.RequestData != null)
                        {
                            outHtml.Append("<table>");

                            foreach (var key in currError.RequestData.ColectionData.Keys)
                            {
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.RequestData.ColectionData[key]);
                            }
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Request_Body", outHtml.ToString());


                        template.Replace("Browser_Header", Resource.Admin_MasterPageAdmin_BugTracker_Browser);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.BrowserData != null)
                        {
                            outHtml.Append("<table>");
                            foreach (var key in currError.BrowserData.ColectionData.Keys)
                            {
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.BrowserData.ColectionData[key]);
                            }
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Browser_Body", outHtml.ToString());


                        template.Replace("Session_Header", Resource.Admin_MasterPageAdmin_BugTracker_Session);
                        outHtml = new StringBuilder();
                        outHtml.Append("<div class=\'tab-content\'>");
                        if (currError.SessionData != null)
                        {
                            outHtml.Append("<table>");
                            foreach (var key in currError.SessionData.ColectionData.Keys)
                            {
                                outHtml.AppendFormat("<tr><td><b>{0}</b></td><td>{1}</td></tr>", key, currError.SessionData.ColectionData[key]);
                            }
                            outHtml.Append("</table>");
                        }
                        outHtml.Append("</div>");
                        template.Replace("Session_Body", outHtml.ToString());

                        ILoggerRepository rep = LogManager.GetRepository();
                        foreach (IAppender appender in rep.GetAppenders())
                        {
                            if (appender is SmtpAppender)
                            {
                                // Loop exception here. SettingsMain.SiteUrl - Лезет в базу.
                                // ((SmtpAppender)appender).Subject = SettingsMain.SiteUrl + " " + SettingsGeneral.SiteVersion;

                                ((SmtpAppender)appender).Subject = SettingsGeneral.AbsoluteUrl + " " + SettingsGeneral.SiteVersion;
                                var emailLog1 = LogManager.GetLogger("EmailErr");
                                emailLog1.Error(template.ToString());
                            }
                        }
                    }

                    data.MailErrorCurrentCount++;
                    data.MailErrorLastSend = DateTime.Now;
                }
                LogTempDataService.UpdateLogTempData(data);
            }
        }
Пример #7
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            // We set this to avoid issues with bots running out of HTTP connections if many are run from a single machine
            // to multiple regions.
            Settings.MAX_HTTP_CONNECTIONS = int.MaxValue;

//            System.Threading.ThreadPool.SetMaxThreads(600, 240);
//
//            int workerThreads, iocpThreads;
//            System.Threading.ThreadPool.GetMaxThreads(out workerThreads, out iocpThreads);
//            Console.WriteLine("ThreadPool.GetMaxThreads {0} {1}", workerThreads, iocpThreads);

            InitBotSendAgentUpdates      = true;
            InitBotRequestObjectTextures = true;

            LoginDelay = DefaultLoginDelay;

            Rng            = new Random(Environment.TickCount);
            AssetsReceived = new Dictionary <UUID, bool>();
            RegionsKnown   = new Dictionary <ulong, GridRegion>();

            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand(
                "Bots", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "connect", "connect [<n>]", "Connect bots",
                "If an <n> is given, then the first <n> disconnected bots by postfix number are connected.\n"
                + "If no <n> is given, then all currently disconnected bots are connected.",
                HandleConnect);

            m_console.Commands.AddCommand(
                "Bots", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
                "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
                + "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
                + "If no <n> is given, then all currently connected bots are disconnected.",
                HandleDisconnect);

            m_console.Commands.AddCommand(
                "Bots", false, "add behaviour", "add behaviour <abbreviated-name> [<bot-number>]",
                "Add a behaviour to a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleAddBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "remove behaviour", "remove behaviour <abbreviated-name> [<bot-number>]",
                "Remove a behaviour from a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleRemoveBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "sit", "sit", "Sit all bots on the ground.",
                HandleSit);

            m_console.Commands.AddCommand(
                "Bots", false, "stand", "stand", "Stand all bots.",
                HandleStand);

            m_console.Commands.AddCommand(
                "Bots", false, "set bots", "set bots <key> <value>", "Set a setting for all bots.", HandleSetBots);

            m_console.Commands.AddCommand(
                "Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);

            m_console.Commands.AddCommand(
                "Bots", false, "show bots", "show bots", "Shows the status of all bots.", HandleShowBotsStatus);

            m_console.Commands.AddCommand(
                "Bots", false, "show bot", "show bot <bot-number>",
                "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);

            m_console.Commands.AddCommand(
                "Debug",
                false,
                "debug lludp packet",
                "debug lludp packet <level> <avatar-first-name> <avatar-last-name>",
                "Turn on received packet logging.",
                "If level >  0 then all received packets that are not duplicates are logged.\n"
                + "If level <= 0 then no received packets are logged.",
                HandleDebugLludpPacketCommand);

            m_console.Commands.AddCommand(
                "Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus);

            m_bots = new List <Bot>();

            Watchdog.Enabled = true;
            StatsManager.RegisterConsoleCommands(m_console);

            m_serverStatsCollector = new ServerStatsCollector();
            m_serverStatsCollector.Initialise(null);
            m_serverStatsCollector.Enabled = true;
            m_serverStatsCollector.Start();

            BotConnectingState = BotManagerBotConnectingState.Ready;
        }
Пример #8
0
        /// <summary>
        /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
        /// </summary>
        public BotManager()
        {
            InitBotSendAgentUpdates      = true;
            InitBotRequestObjectTextures = true;

            LoginDelay = DefaultLoginDelay;

            Rng            = new Random(Environment.TickCount);
            AssetsReceived = new Dictionary <UUID, bool>();
            RegionsKnown   = new Dictionary <ulong, GridRegion>();

            m_console            = CreateConsole();
            MainConsole.Instance = m_console;

            // Make log4net see the console
            //
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[]     appenders       = repository.GetAppenders();
            OpenSimAppender consoleAppender = null;

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender         = (OpenSimAppender)appender;
                    consoleAppender.Console = m_console;
                    break;
                }
            }

            m_console.Commands.AddCommand(
                "Bots", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);

            m_console.Commands.AddCommand(
                "Bots", false, "connect", "connect [<n>]", "Connect bots",
                "If an <n> is given, then the first <n> disconnected bots by postfix number are connected.\n"
                + "If no <n> is given, then all currently disconnected bots are connected.",
                HandleConnect);

            m_console.Commands.AddCommand(
                "Bots", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
                "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
                + "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
                + "If no <n> is given, then all currently connected bots are disconnected.",
                HandleDisconnect);

            m_console.Commands.AddCommand(
                "Bots", false, "add behaviour", "add behaviour <abbreviated-name> [<bot-number>]",
                "Add a behaviour to a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleAddBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "remove behaviour", "remove behaviour <abbreviated-name> [<bot-number>]",
                "Remove a behaviour from a bot",
                "If no bot number is specified then behaviour is added to all bots.\n"
                + "Can be performed on connected or disconnected bots.",
                HandleRemoveBehaviour);

            m_console.Commands.AddCommand(
                "Bots", false, "sit", "sit", "Sit all bots on the ground.",
                HandleSit);

            m_console.Commands.AddCommand(
                "Bots", false, "stand", "stand", "Stand all bots.",
                HandleStand);

            m_console.Commands.AddCommand(
                "Bots", false, "set bots", "set bots <key> <value>", "Set a setting for all bots.", HandleSetBots);

            m_console.Commands.AddCommand(
                "Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);

            m_console.Commands.AddCommand(
                "Bots", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus);

            m_console.Commands.AddCommand(
                "Bots", false, "show bot", "show bot <bot-number>",
                "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);

            m_bots = new List <Bot>();
        }
Пример #9
0
        /// <summary>
        /// Find the console plugin and initialize the logger for it
        /// </summary>
        public virtual void SetUpConsole()
        {
            List <ICommandConsole> Plugins = AuroraModuleLoader.PickupModules <ICommandConsole>();

            foreach (ICommandConsole plugin in Plugins)
            {
                plugin.Initialize("Region", ConfigSource, this);
            }

            m_console = m_applicationRegistry.RequestModuleInterface <ICommandConsole>();
            if (m_console == null)
            {
                m_console = new LocalConsole();
            }
            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();
            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    m_consoleAppender = (OpenSimAppender)appender;
                    break;
                }
            }

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "LogFileAppender")
                {
                    m_logFileAppender = appender;
                }
            }

            if (null != m_consoleAppender)
            {
                m_consoleAppender.Console = m_console;
                // If there is no threshold set then the threshold is effectively everything.
                if (null == m_consoleAppender.Threshold)
                {
                    m_consoleAppender.Threshold = Level.All;
                }
                repository.Threshold = m_consoleAppender.Threshold;
                foreach (ILogger log in repository.GetCurrentLoggers())
                {
                    log.Level = m_consoleAppender.Threshold;
                }
                m_log.Fatal(String.Format("[Console]: Console log level is {0}", m_consoleAppender.Threshold));
            }

            IConfig startupConfig = m_config.Configs["Startup"];

            if (m_logFileAppender != null)
            {
                if (m_logFileAppender is log4net.Appender.FileAppender)
                {
                    log4net.Appender.FileAppender appender = (log4net.Appender.FileAppender)m_logFileAppender;
                    string fileName = startupConfig.GetString("LogFile", String.Empty);
                    if (fileName != String.Empty)
                    {
                        appender.File = fileName;
                        appender.ActivateOptions();
                    }
                }
            }

            MainConsole.Instance = m_console;
        }
        /// <summary>
        /// Must be overriden by child classes for their own server specific startup behaviour.
        /// </summary>
        protected virtual void StartupSpecific()
        {
            if (m_console != null)
            {
                ILoggerRepository repository = LogManager.GetRepository();
                IAppender[]       appenders  = repository.GetAppenders();

                foreach (IAppender appender in appenders)
                {
                    if (appender.Name == "Console")
                    {
                        m_consoleAppender = (OpenSimAppender)appender;
                        break;
                    }
                }

                if (null == m_consoleAppender)
                {
                    Notice("No appender named Console found (see the log4net config file for this executable)!");
                }
                else
                {
                    m_consoleAppender.Console = m_console;

                    // If there is no threshold set then the threshold is effectively everything.
                    if (null == m_consoleAppender.Threshold)
                    {
                        m_consoleAppender.Threshold = Level.All;
                    }

                    Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
                }

                m_console.Commands.AddCommand("base", false, "quit",
                                              "quit",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "shutdown",
                                              "shutdown",
                                              "Quit the application", HandleQuit);

                m_console.Commands.AddCommand("base", false, "set log level",
                                              "set log level <level>",
                                              "Set the console logging level", HandleLogLevel);

                m_console.Commands.AddCommand("base", false, "show info",
                                              "show info",
                                              "Show general information about the server", HandleShow);

                m_console.Commands.AddCommand("base", false, "show stats",
                                              "show stats",
                                              "Show statistics", HandleShow);

                m_console.Commands.AddCommand("base", false, "show threads",
                                              "show threads",
                                              "Show thread status", HandleShow);

                m_console.Commands.AddCommand("base", false, "show uptime",
                                              "show uptime",
                                              "Show server uptime", HandleShow);

                m_console.Commands.AddCommand("base", false, "show version",
                                              "show version",
                                              "Show server version", HandleShow);

                m_console.Commands.AddCommand("base", false, "threads abort",
                                              "threads abort <thread-id>",
                                              "Abort a managed thread.  Use \"show threads\" to find possible threads.", HandleThreadsAbort);

                m_console.Commands.AddCommand("base", false, "threads show",
                                              "threads show",
                                              "Show thread status.  Synonym for \"show threads\"",
                                              (string module, string[] args) => Notice(GetThreadsReport()));
            }
        }
Пример #11
0
        // Handle all the automagical stuff
        public ServicesServerBase(string prompt, string[] args)
        {
            // Save raw arguments
            m_Arguments = args;

            // Read command line
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");

            // Automagically create the ini file name
            string       fullName     = Assembly.GetEntryAssembly().FullName;
            AssemblyName assemblyName = new AssemblyName(fullName);

            string iniFile = assemblyName.Name + ".ini";

            // Check if a file name was given on the command line
            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                iniFile = startupConfig.GetString("inifile", iniFile);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception)
            {
                System.Console.WriteLine("Error reading from config source {0}", iniFile);
                Thread.CurrentThread.Abort();
            }

            // Merge the configuration from the command line into the
            // loaded file
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            startupConfig = argvConfig.Configs["Startup"];

            // Allow derived classes to load config before the console is
            // opened.
            ReadConfig();

            // Create main console
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            XmlConfigurator.Configure();

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }

                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    fileAppender.File = startupConfig.GetString("logfile", assemblyName.Name + ".log");
                }
            }

            // Register the quit command
            MainConsole.Instance.Commands.AddCommand("base", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            Initialise();
        }
        private static void configure_info_logging_colors()
        {
            try
            {
                // configure INFO on same as current background color and foreground colors
                var bgColor = Console.BackgroundColor;
                var fgColor = Console.ForegroundColor;
                ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetCallingAssembly().UnderlyingType);
                foreach (var append in logRepository.GetAppenders().Where(a => a.Name.is_equal_to(NORMAL_LOGGING_COLORED_APPENDER)).or_empty_list_if_null())
                {
                    var appender = append as ManagedColoredConsoleAppender;
                    if (appender != null)
                    {
                        var infoMapping = new ManagedColoredConsoleAppender.LevelColors
                        {
                            Level     = Level.Info,
                            BackColor = bgColor,
                            ForeColor = fgColor,
                        };
                        appender.AddMapping(infoMapping);

                        // make sure warnings can be clearly seen
                        if (bgColor == ConsoleColor.White ||
                            bgColor == ConsoleColor.Gray ||
                            bgColor == ConsoleColor.Yellow ||
                            bgColor == ConsoleColor.DarkYellow ||
                            bgColor == ConsoleColor.DarkCyan
                            )
                        {
                            var warnMapping = new ManagedColoredConsoleAppender.LevelColors
                            {
                                Level     = Level.Warn,
                                BackColor = ConsoleColor.Black,
                                ForeColor = ConsoleColor.Yellow,
                            };
                            appender.AddMapping(warnMapping);
                        }

                        // make sure errors can be clearly seen
                        if (bgColor == ConsoleColor.Red ||
                            bgColor == ConsoleColor.DarkRed ||
                            bgColor == ConsoleColor.Yellow ||
                            bgColor == ConsoleColor.DarkYellow ||
                            bgColor == ConsoleColor.DarkCyan ||
                            bgColor == ConsoleColor.DarkGray ||
                            bgColor == ConsoleColor.DarkGreen ||
                            bgColor == ConsoleColor.Blue
                            )
                        {
                            var errorMapping = new ManagedColoredConsoleAppender.LevelColors
                            {
                                Level     = Level.Error,
                                BackColor = ConsoleColor.Black,
                                ForeColor = ConsoleColor.Red,
                            };
                            appender.AddMapping(errorMapping);
                        }

                        appender.ActivateOptions();
                    }
                }

                foreach (var append in logRepository.GetAppenders().Where(a => a.Name.is_equal_to(IMPORTANT_LOGGING_COLORED_APPENDER)).or_empty_list_if_null())
                {
                    var appender = append as ManagedColoredConsoleAppender;
                    if (appender != null)
                    {
                        // add black based on current background color
                        if (bgColor == ConsoleColor.White ||
                            bgColor == ConsoleColor.Gray ||
                            bgColor == ConsoleColor.Yellow ||
                            bgColor == ConsoleColor.DarkYellow ||
                            bgColor == ConsoleColor.DarkCyan ||
                            bgColor == ConsoleColor.DarkGray ||
                            bgColor == ConsoleColor.DarkGreen ||
                            bgColor == ConsoleColor.Green ||
                            bgColor == ConsoleColor.Cyan ||
                            bgColor == ConsoleColor.Magenta
                            )
                        {
                            var infoMapping = new ManagedColoredConsoleAppender.LevelColors
                            {
                                Level     = Level.Info,
                                BackColor = ConsoleColor.Black,
                                ForeColor = ConsoleColor.Green,
                            };
                            appender.AddMapping(infoMapping);

                            var warnMapping = new ManagedColoredConsoleAppender.LevelColors
                            {
                                Level     = Level.Warn,
                                BackColor = ConsoleColor.Black,
                                ForeColor = ConsoleColor.Magenta,
                            };
                            appender.AddMapping(warnMapping);

                            appender.ActivateOptions();
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignore this and move on
            }
        }