factor out common HandleShow code for "show uptime"

This commit is contained in:
Justin Clark-Casey (justincc)
2012-11-22 04:05:09 +00:00
parent 74a20a62ee
commit 5c48d7a378
9 changed files with 72 additions and 63 deletions

View File

@@ -26,12 +26,19 @@
*/
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Servers
{
public class ServerBase
{
/// <summary>
/// Console to be used for any command line output. Can be null, in which case there should be no output.
/// </summary>
protected ICommandConsole m_console;
/// <summary>
/// Time at which this server was started
/// </summary>
@@ -42,6 +49,22 @@ namespace OpenSim.Framework.Servers
m_startuptime = DateTime.Now;
}
public virtual void HandleShow(string module, string[] cmd)
{
List<string> args = new List<string>(cmd);
args.RemoveAt(0);
string[] showParams = args.ToArray();
switch (showParams[0])
{
case "uptime":
Notice(GetUptimeReport());
break;
}
}
/// <summary>
/// Return a report about the uptime of this server
/// </summary>
@@ -54,5 +77,32 @@ namespace OpenSim.Framework.Servers
return sb.ToString();
}
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="msg"></param>
protected void Notice(string msg)
{
if (m_console != null)
{
m_console.Output(msg);
}
}
/// <summary>
/// Console output is only possible if a console has been established.
/// That is something that cannot be determined within this class. So
/// all attempts to use the console MUST be verified.
/// </summary>
/// <param name="format"></param>
/// <param name="components"></param>
protected void Notice(string format, params string[] components)
{
if (m_console != null)
m_console.OutputFormat(format, components);
}
}
}