BaseOpenSimServer.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using OpenSim.Framework.Console;
  29. using OpenSim.Framework.Statistics;
  30. namespace OpenSim.Framework.Servers
  31. {
  32. /// <summary>
  33. /// Common base for the main OpenSimServers (user, grid, inventory, region, etc)
  34. /// </summary>
  35. public abstract class BaseOpenSimServer
  36. {
  37. protected ConsoleBase m_console;
  38. protected DateTime m_startuptime;
  39. protected BaseHttpServer m_httpServer;
  40. public BaseHttpServer HttpServer
  41. {
  42. get { return m_httpServer; }
  43. }
  44. /// <summary>
  45. /// Holds the non-viewer statistics collection object for this service/server
  46. /// </summary>
  47. protected IStatsCollector m_stats;
  48. public BaseOpenSimServer()
  49. {
  50. m_startuptime = DateTime.Now;
  51. }
  52. /// <summary>
  53. /// Should be overriden by descendents if they need to perform extra shutdown processing
  54. /// </summary>
  55. public virtual void Shutdown()
  56. {
  57. if (m_console != null)
  58. {
  59. m_console.Close();
  60. }
  61. Environment.Exit(0);
  62. }
  63. /// <summary>
  64. /// Runs commands issued by the server console from the operator
  65. /// </summary>
  66. /// <param name="command">The first argument of the parameter (the command)</param>
  67. /// <param name="cmdparams">Additional arguments passed to the command</param>
  68. public virtual void RunCmd(string command, string[] cmdparams)
  69. {
  70. switch (command)
  71. {
  72. case "help":
  73. Notice("quit - equivalent to shutdown.");
  74. if (m_stats != null)
  75. Notice("show stats - statistical information for this server");
  76. Notice("show uptime - show server startup and uptime.");
  77. Notice("shutdown - shutdown the server.\n");
  78. break;
  79. case "show":
  80. if (cmdparams.Length > 0)
  81. {
  82. Show(cmdparams[0]);
  83. }
  84. break;
  85. case "quit":
  86. case "shutdown":
  87. Shutdown();
  88. break;
  89. }
  90. }
  91. /// <summary>
  92. /// Outputs to the console information about the region
  93. /// </summary>
  94. /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param>
  95. public virtual void Show(string ShowWhat)
  96. {
  97. switch (ShowWhat)
  98. {
  99. case "stats":
  100. if (m_stats != null)
  101. {
  102. Notice(m_stats.Report());
  103. }
  104. break;
  105. case "uptime":
  106. Notice("Server has been running since " + m_startuptime.DayOfWeek + ", " + m_startuptime.ToString());
  107. Notice("That is an elapsed time of " + (DateTime.Now - m_startuptime).ToString());
  108. break;
  109. }
  110. }
  111. /// <summary>
  112. /// Console output is only possible if a console has been established.
  113. /// That is something that cannot be determined within this class. So
  114. /// all attempts to use the console MUST be verified.
  115. /// </summary>
  116. private void Notice(string msg)
  117. {
  118. if (m_console != null)
  119. {
  120. m_console.Notice(msg);
  121. }
  122. }
  123. }
  124. }