30 using System.Reflection;
34 using System.Collections.Generic;
35 using OpenSim.Server.Base;
36 using OpenSim.Framework;
37 using OpenSim.Framework.Console;
45 private static string m_Host;
46 private static int m_Port;
47 private static string m_User;
48 private static string m_Pass;
49 private static UUID m_SessionID;
51 static int Main(
string[] args)
55 IConfig serverConfig = m_Server.Config.Configs[
"Startup"];
56 if (serverConfig == null)
58 System.Console.WriteLine(
"Startup config section missing in .ini file");
59 throw new Exception(
"Configuration error");
62 ArgvConfigSource argvConfig =
new ArgvConfigSource(args);
64 argvConfig.AddSwitch(
"Startup",
"host",
"h");
65 argvConfig.AddSwitch(
"Startup",
"port",
"p");
66 argvConfig.AddSwitch(
"Startup",
"user",
"u");
67 argvConfig.AddSwitch(
"Startup",
"pass",
"P");
69 m_Server.Config.Merge(argvConfig);
71 m_User = serverConfig.GetString(
"user",
"Test");
72 m_Host = serverConfig.GetString(
"host",
"localhost");
73 m_Port = serverConfig.GetInt(
"port", 8003);
74 m_Pass = serverConfig.GetString(
"pass",
"secret");
76 Requester.MakeRequest(
"http://"+m_Host+
":"+m_Port.ToString()+
"/StartSession/", String.Format(
"USER={0}&PASS={1}", m_User, m_Pass), LoginReply);
78 string pidFile = serverConfig.GetString(
"PIDFile", String.Empty);
80 while (m_Server.Running)
82 System.Threading.Thread.Sleep(500);
86 if (pidFile != String.Empty)
94 private static void SendCommand(
string module,
string[] cmd)
97 string[] cmdlist =
new string[cmd.Length - 1];
103 Array.Copy(cmd, 1, cmdlist, 0, cmd.Length - 1);
104 sendCmd +=
" \"" + String.Join(
"\" \"", cmdlist) +
"\"";
107 Requester.MakeRequest(
"http://"+m_Host+
":"+m_Port.ToString()+
"/SessionCommand/", String.Format(
"ID={0}&COMMAND={1}", m_SessionID, sendCmd), CommandReply);
110 public static void LoginReply(
string requestUrl,
string requestData,
string replyData)
112 XmlDocument doc =
new XmlDocument();
114 doc.LoadXml(replyData);
116 XmlNodeList rootL = doc.GetElementsByTagName(
"ConsoleSession");
117 if (rootL.Count != 1)
119 MainConsole.Instance.Output(
"Connection data info was not valid");
122 XmlElement rootNode = (XmlElement)rootL[0];
124 if (rootNode == null)
126 MainConsole.Instance.Output(
"Connection data info was not valid");
130 XmlNodeList helpNodeL = rootNode.GetElementsByTagName(
"HelpTree");
131 if (helpNodeL.Count != 1)
133 MainConsole.Instance.Output(
"Connection data info was not valid");
137 XmlElement helpNode = (XmlElement)helpNodeL[0];
138 if (helpNode == null)
140 MainConsole.Instance.Output(
"Connection data info was not valid");
144 XmlNodeList sessionL = rootNode.GetElementsByTagName(
"SessionID");
145 if (sessionL.Count != 1)
147 MainConsole.Instance.Output(
"Connection data info was not valid");
151 XmlElement sessionNode = (XmlElement)sessionL[0];
152 if (sessionNode == null)
154 MainConsole.Instance.Output(
"Connection data info was not valid");
158 if (!UUID.TryParse(sessionNode.InnerText, out m_SessionID))
160 MainConsole.Instance.Output(
"Connection data info was not valid");
164 MainConsole.Instance.Commands.FromXml(helpNode, SendCommand);
166 Requester.MakeRequest(
"http://"+m_Host+
":"+m_Port.ToString()+
"/ReadResponses/"+m_SessionID.ToString()+
"/", String.Empty, ReadResponses);
169 public static void ReadResponses(
string requestUrl,
string requestData,
string replyData)
171 XmlDocument doc =
new XmlDocument();
173 doc.LoadXml(replyData);
175 XmlNodeList rootNodeL = doc.GetElementsByTagName(
"ConsoleSession");
176 if (rootNodeL.Count != 1 || rootNodeL[0] == null)
178 Requester.MakeRequest(requestUrl, requestData, ReadResponses);
182 List<string> lines =
new List<string>();
184 foreach (XmlNode part
in rootNodeL[0].ChildNodes)
186 if (part.Name !=
"Line")
189 lines.Add(part.InnerText);
195 while (lines.Count > 100)
198 string prompt = String.Empty;
200 foreach (
string l
in lines)
202 string[] parts = l.Split(
new char[] {
':'}, 3);
203 if (parts.Length != 3)
206 if (parts[2].StartsWith(
"+++") || parts[2].StartsWith(
"-++"))
209 MainConsole.Instance.Output(parts[2].Trim(), parts[1]);
213 Requester.MakeRequest(requestUrl, requestData, ReadResponses);
215 if (prompt.StartsWith(
"+++"))
217 else if (prompt.StartsWith(
"-++"))
221 public static void CommandReply(
string requestUrl,
string requestData,
string replyData)
static void ReadResponses(string requestUrl, string requestData, string replyData)
static ICommandConsole Instance
Interactive OpenSim region server
static void LoginReply(string requestUrl, string requestData, string replyData)
static void CommandReply(string requestUrl, string requestData, string replyData)
string ReadLine(string p, bool isCommand, bool e)