mirror of
https://github.com/opensim/opensim.git
synced 2026-08-04 16:22:50 +08:00
Add the OpenSim.ConsoleClient app.
Usage: OpenSim.ConsoleClient -h <host> -p <port> -u <user> -P <pass> host defaults to localhost, port defaults to 8003.
This commit is contained in:
@@ -373,10 +373,28 @@ namespace OpenSim.Framework.Console
|
||||
|
||||
public XmlElement GetXml(XmlDocument doc)
|
||||
{
|
||||
CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
|
||||
((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
|
||||
if (((Dictionary<string, object>)tree["help"]).Count == 0)
|
||||
tree.Remove("help");
|
||||
|
||||
CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
|
||||
((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
|
||||
if (((Dictionary<string, object>)tree["quit"]).Count == 0)
|
||||
tree.Remove("quit");
|
||||
|
||||
XmlElement root = doc.CreateElement("", "HelpTree", "");
|
||||
|
||||
ProcessTreeLevel(tree, root, doc);
|
||||
|
||||
if (!tree.ContainsKey("help"))
|
||||
tree["help"] = (object) new Dictionary<string, object>();
|
||||
((Dictionary<string, object>)tree["help"])[String.Empty] = help;
|
||||
|
||||
if (!tree.ContainsKey("quit"))
|
||||
tree["quit"] = (object) new Dictionary<string, object>();
|
||||
((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -426,8 +444,80 @@ namespace OpenSim.Framework.Console
|
||||
}
|
||||
}
|
||||
|
||||
public void FromXml(XmlElement root)
|
||||
public void FromXml(XmlElement root, CommandDelegate fn)
|
||||
{
|
||||
CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
|
||||
((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
|
||||
if (((Dictionary<string, object>)tree["help"]).Count == 0)
|
||||
tree.Remove("help");
|
||||
|
||||
CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
|
||||
((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
|
||||
if (((Dictionary<string, object>)tree["quit"]).Count == 0)
|
||||
tree.Remove("quit");
|
||||
|
||||
tree.Clear();
|
||||
|
||||
ReadTreeLevel(tree, root, fn);
|
||||
|
||||
if (!tree.ContainsKey("help"))
|
||||
tree["help"] = (object) new Dictionary<string, object>();
|
||||
((Dictionary<string, object>)tree["help"])[String.Empty] = help;
|
||||
|
||||
if (!tree.ContainsKey("quit"))
|
||||
tree["quit"] = (object) new Dictionary<string, object>();
|
||||
((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
|
||||
}
|
||||
|
||||
private void ReadTreeLevel(Dictionary<string, object> level, XmlNode node, CommandDelegate fn)
|
||||
{
|
||||
Dictionary<string, object> next;
|
||||
string name;
|
||||
|
||||
XmlNodeList nodeL = node.ChildNodes;
|
||||
XmlNodeList cmdL;
|
||||
CommandInfo c;
|
||||
|
||||
foreach (XmlNode part in nodeL)
|
||||
{
|
||||
switch (part.Name)
|
||||
{
|
||||
case "Level":
|
||||
name = ((XmlElement)part).GetAttribute("Name");
|
||||
next = new Dictionary<string, object>();
|
||||
level[name] = next;
|
||||
ReadTreeLevel(next, part, fn);
|
||||
break;
|
||||
case "Command":
|
||||
cmdL = part.ChildNodes;
|
||||
c = new CommandInfo();
|
||||
foreach (XmlNode cmdPart in cmdL)
|
||||
{
|
||||
switch (cmdPart.Name)
|
||||
{
|
||||
case "Module":
|
||||
c.module = cmdPart.InnerText;
|
||||
break;
|
||||
case "Shared":
|
||||
c.shared = Convert.ToBoolean(cmdPart.InnerText);
|
||||
break;
|
||||
case "HelpText":
|
||||
c.help_text = cmdPart.InnerText;
|
||||
break;
|
||||
case "LongHelp":
|
||||
c.long_help = cmdPart.InnerText;
|
||||
break;
|
||||
case "Description":
|
||||
c.descriptive_help = cmdPart.InnerText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
c.fn = new List<CommandDelegate>();
|
||||
c.fn.Add(fn);
|
||||
level[String.Empty] = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,12 @@ namespace OpenSim.Framework.Console
|
||||
m_LineNumber++;
|
||||
m_Scrollback.Add(String.Format("{0}", m_LineNumber)+":"+level+":"+text);
|
||||
}
|
||||
System.Console.Write(text);
|
||||
System.Console.WriteLine(text.Trim());
|
||||
}
|
||||
|
||||
public override void Output(string text)
|
||||
{
|
||||
Output(text, "normal");
|
||||
}
|
||||
|
||||
public override string ReadLine(string p, bool isCommand, bool e)
|
||||
@@ -152,9 +157,8 @@ namespace OpenSim.Framework.Console
|
||||
|
||||
foreach (UUID id in expired)
|
||||
{
|
||||
System.Console.WriteLine("Expired {0}", id.ToString());
|
||||
CloseConnection(id);
|
||||
m_Connections.Remove(id);
|
||||
CloseConnection(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,8 +248,8 @@ namespace OpenSim.Framework.Console
|
||||
{
|
||||
if (m_Connections.ContainsKey(id))
|
||||
{
|
||||
CloseConnection(id);
|
||||
m_Connections.Remove(id);
|
||||
CloseConnection(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,9 +350,15 @@ namespace OpenSim.Framework.Console
|
||||
|
||||
public void CloseConnection(UUID id)
|
||||
{
|
||||
string uri = "/ReadResponses/" + id.ToString() + "/";
|
||||
try
|
||||
{
|
||||
string uri = "/ReadResponses/" + id.ToString() + "/";
|
||||
|
||||
m_Server.RemovePollServiceHTTPHandler("", uri);
|
||||
m_Server.RemovePollServiceHTTPHandler("", uri);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasEvents(UUID sessionID)
|
||||
@@ -394,8 +404,11 @@ namespace OpenSim.Framework.Console
|
||||
lock (m_Scrollback)
|
||||
{
|
||||
long startLine = m_LineNumber - m_Scrollback.Count;
|
||||
long sendStart = startLine;
|
||||
if (sendStart < c.lastLineSeen)
|
||||
sendStart = c.lastLineSeen;
|
||||
|
||||
for (long i = startLine ; i < m_LineNumber ; i++)
|
||||
for (long i = sendStart ; i < m_LineNumber ; i++)
|
||||
{
|
||||
XmlElement res = xmldoc.CreateElement("", "Line", "");
|
||||
long line = i + 1;
|
||||
@@ -422,12 +435,21 @@ namespace OpenSim.Framework.Console
|
||||
{
|
||||
Hashtable result = new Hashtable();
|
||||
|
||||
result["int_response_code"] = 502;
|
||||
result["content_type"] = "text/plain";
|
||||
XmlDocument xmldoc = new XmlDocument();
|
||||
XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
|
||||
"", "");
|
||||
|
||||
xmldoc.AppendChild(xmlnode);
|
||||
XmlElement rootElement = xmldoc.CreateElement("", "ConsoleSession",
|
||||
"");
|
||||
|
||||
xmldoc.AppendChild(rootElement);
|
||||
|
||||
result["str_response_string"] = xmldoc.InnerXml;
|
||||
result["int_response_code"] = 200;
|
||||
result["content_type"] = "text/xml";
|
||||
result["keepalive"] = false;
|
||||
result["reusecontext"] = false;
|
||||
result["str_response_string"] = "Upstream error: ";
|
||||
result["error_status_text"] = "Upstream error:";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user