Make the text mode remote console really work. It can now be used to send
multi-word commands with proper quoting, handles arguments with spaces and allows interactive use, e.g. user creation.avinationmerge
parent
74d62901c8
commit
4921d5ac2d
|
@ -29,6 +29,7 @@ using Nini.Config;
|
||||||
using log4net;
|
using log4net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenSim.Server.Base;
|
using OpenSim.Server.Base;
|
||||||
|
@ -73,9 +74,18 @@ namespace OpenSim.ConsoleClient
|
||||||
|
|
||||||
Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/StartSession/", String.Format("USER={0}&PASS={1}", m_User, m_Pass), LoginReply);
|
Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/StartSession/", String.Format("USER={0}&PASS={1}", m_User, m_Pass), LoginReply);
|
||||||
|
|
||||||
int res = m_Server.Run();
|
string pidFile = serverConfig.GetString("PIDFile", String.Empty);
|
||||||
|
|
||||||
Environment.Exit(res);
|
while (m_Server.Running)
|
||||||
|
{
|
||||||
|
System.Threading.Thread.Sleep(500);
|
||||||
|
// MainConsole.Instance.Prompt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pidFile != String.Empty)
|
||||||
|
File.Delete(pidFile);
|
||||||
|
|
||||||
|
Environment.Exit(0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -83,13 +93,14 @@ namespace OpenSim.ConsoleClient
|
||||||
private static void SendCommand(string module, string[] cmd)
|
private static void SendCommand(string module, string[] cmd)
|
||||||
{
|
{
|
||||||
string sendCmd = "";
|
string sendCmd = "";
|
||||||
|
string[] cmdlist = new string[cmd.Length - 1];
|
||||||
|
|
||||||
|
sendCmd = cmd[0];
|
||||||
|
|
||||||
if (cmd.Length > 1)
|
if (cmd.Length > 1)
|
||||||
{
|
{
|
||||||
sendCmd = cmd[0];
|
Array.Copy(cmd, 1, cmdlist, 0, cmd.Length - 1);
|
||||||
|
sendCmd += " \"" + String.Join("\" \"", cmdlist) + "\"";
|
||||||
Array.Copy(cmd, 1, cmd, 0, cmd.Length-1);
|
|
||||||
Array.Resize(ref cmd, cmd.Length-1);
|
|
||||||
sendCmd += "\"" + String.Join("\" \"", cmd) + "\"";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/SessionCommand/", String.Format("ID={0}&COMMAND={1}", m_SessionID, sendCmd), CommandReply);
|
Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/SessionCommand/", String.Format("ID={0}&COMMAND={1}", m_SessionID, sendCmd), CommandReply);
|
||||||
|
@ -183,16 +194,27 @@ namespace OpenSim.ConsoleClient
|
||||||
while (lines.Count > 100)
|
while (lines.Count > 100)
|
||||||
lines.RemoveAt(0);
|
lines.RemoveAt(0);
|
||||||
|
|
||||||
|
string prompt = String.Empty;
|
||||||
|
|
||||||
foreach (string l in lines)
|
foreach (string l in lines)
|
||||||
{
|
{
|
||||||
string[] parts = l.Split(new char[] {':'}, 3);
|
string[] parts = l.Split(new char[] {':'}, 3);
|
||||||
if (parts.Length != 3)
|
if (parts.Length != 3)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MainConsole.Instance.Output(parts[2].Trim(), parts[1]);
|
if (parts[2].StartsWith("+++") || parts[2].StartsWith("-++"))
|
||||||
|
prompt = parts[2];
|
||||||
|
else
|
||||||
|
MainConsole.Instance.Output(parts[2].Trim(), parts[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Requester.MakeRequest(requestUrl, requestData, ReadResponses);
|
Requester.MakeRequest(requestUrl, requestData, ReadResponses);
|
||||||
|
|
||||||
|
if (prompt.StartsWith("+++"))
|
||||||
|
MainConsole.Instance.ReadLine(prompt.Substring(3), true, true);
|
||||||
|
else if (prompt.StartsWith("-++"))
|
||||||
|
SendCommand(String.Empty, new string[] { MainConsole.Instance.ReadLine(prompt.Substring(3), false, true) });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CommandReply(string requestUrl, string requestData, string replyData)
|
public static void CommandReply(string requestUrl, string requestData, string replyData)
|
||||||
|
|
|
@ -106,8 +106,15 @@ namespace OpenSim.Framework.Console
|
||||||
|
|
||||||
public override string ReadLine(string p, bool isCommand, bool e)
|
public override string ReadLine(string p, bool isCommand, bool e)
|
||||||
{
|
{
|
||||||
|
if (isCommand)
|
||||||
|
Output("+++"+p);
|
||||||
|
else
|
||||||
|
Output("-++"+p);
|
||||||
|
|
||||||
m_DataEvent.WaitOne();
|
m_DataEvent.WaitOne();
|
||||||
|
|
||||||
|
string cmdinput;
|
||||||
|
|
||||||
lock (m_InputData)
|
lock (m_InputData)
|
||||||
{
|
{
|
||||||
if (m_InputData.Count == 0)
|
if (m_InputData.Count == 0)
|
||||||
|
@ -116,29 +123,30 @@ namespace OpenSim.Framework.Console
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string cmdinput = m_InputData[0];
|
cmdinput = m_InputData[0];
|
||||||
m_InputData.RemoveAt(0);
|
m_InputData.RemoveAt(0);
|
||||||
if (m_InputData.Count == 0)
|
if (m_InputData.Count == 0)
|
||||||
m_DataEvent.Reset();
|
m_DataEvent.Reset();
|
||||||
|
|
||||||
if (isCommand)
|
|
||||||
{
|
|
||||||
string[] cmd = Commands.Resolve(Parser.Parse(cmdinput));
|
|
||||||
|
|
||||||
if (cmd.Length != 0)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0 ; i < cmd.Length ; i++)
|
|
||||||
{
|
|
||||||
if (cmd[i].Contains(" "))
|
|
||||||
cmd[i] = "\"" + cmd[i] + "\"";
|
|
||||||
}
|
|
||||||
return String.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmdinput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isCommand)
|
||||||
|
{
|
||||||
|
string[] cmd = Commands.Resolve(Parser.Parse(cmdinput));
|
||||||
|
|
||||||
|
if (cmd.Length != 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0 ; i < cmd.Length ; i++)
|
||||||
|
{
|
||||||
|
if (cmd[i].Contains(" "))
|
||||||
|
cmd[i] = "\"" + cmd[i] + "\"";
|
||||||
|
}
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cmdinput;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoExpire()
|
private void DoExpire()
|
||||||
|
@ -308,7 +316,7 @@ namespace OpenSim.Framework.Console
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post["COMMAND"] == null || post["COMMAND"].ToString() == String.Empty)
|
if (post["COMMAND"] == null)
|
||||||
return reply;
|
return reply;
|
||||||
|
|
||||||
lock (m_InputData)
|
lock (m_InputData)
|
||||||
|
|
|
@ -236,6 +236,11 @@ namespace OpenSim.Server.Base
|
||||||
Initialise();
|
Initialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Running
|
||||||
|
{
|
||||||
|
get { return m_Running; }
|
||||||
|
}
|
||||||
|
|
||||||
public virtual int Run()
|
public virtual int Run()
|
||||||
{
|
{
|
||||||
while (m_Running)
|
while (m_Running)
|
||||||
|
|
Loading…
Reference in New Issue