diff options
author | Melanie | 2009-08-17 08:45:20 +0100 |
---|---|---|
committer | Melanie | 2009-08-17 08:45:20 +0100 |
commit | cef16bec6dabc90fdccf82f755d24683d834208b (patch) | |
tree | 3265dbc64721f17eef82b06c7e16a7b4c6e0f657 /OpenSim/ConsoleClient/ConsoleClient.cs | |
parent | Merge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-cef16bec6dabc90fdccf82f755d24683d834208b.zip opensim-SC-cef16bec6dabc90fdccf82f755d24683d834208b.tar.gz opensim-SC-cef16bec6dabc90fdccf82f755d24683d834208b.tar.bz2 opensim-SC-cef16bec6dabc90fdccf82f755d24683d834208b.tar.xz |
Add the OpenSim.ConsoleClient app.
Usage: OpenSim.ConsoleClient -h <host> -p <port> -u <user> -P <pass>
host defaults to localhost, port defaults to 8003.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/ConsoleClient/ConsoleClient.cs | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/OpenSim/ConsoleClient/ConsoleClient.cs b/OpenSim/ConsoleClient/ConsoleClient.cs new file mode 100644 index 0000000..0d4f3cf --- /dev/null +++ b/OpenSim/ConsoleClient/ConsoleClient.cs | |||
@@ -0,0 +1,185 @@ | |||
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 OpenSimulator 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 | |||
28 | using Nini.Config; | ||
29 | using log4net; | ||
30 | using System.Reflection; | ||
31 | using System; | ||
32 | using System.Xml; | ||
33 | using System.Collections.Generic; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenMetaverse; | ||
37 | |||
38 | namespace OpenSim.ConsoleClient | ||
39 | { | ||
40 | public class OpenSimConsoleClient | ||
41 | { | ||
42 | private static readonly ILog m_log = | ||
43 | LogManager.GetLogger( | ||
44 | MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | protected static ServicesServerBase m_Server = null; | ||
47 | private static string m_Host; | ||
48 | private static int m_Port; | ||
49 | private static string m_User; | ||
50 | private static string m_Pass; | ||
51 | private static UUID m_SessionID; | ||
52 | |||
53 | static int Main(string[] args) | ||
54 | { | ||
55 | m_Server = new ServicesServerBase("Client", args); | ||
56 | |||
57 | IConfig serverConfig = m_Server.Config.Configs["Startup"]; | ||
58 | if (serverConfig == null) | ||
59 | { | ||
60 | System.Console.WriteLine("Startup config section missing in .ini file"); | ||
61 | throw new Exception("Configuration error"); | ||
62 | } | ||
63 | |||
64 | ArgvConfigSource argvConfig = new ArgvConfigSource(args); | ||
65 | |||
66 | argvConfig.AddSwitch("Startup", "host", "h"); | ||
67 | argvConfig.AddSwitch("Startup", "port", "p"); | ||
68 | argvConfig.AddSwitch("Startup", "user", "u"); | ||
69 | argvConfig.AddSwitch("Startup", "pass", "P"); | ||
70 | |||
71 | m_Server.Config.Merge(argvConfig); | ||
72 | |||
73 | m_User = serverConfig.GetString("user", "Test"); | ||
74 | m_Host = serverConfig.GetString("host", "localhost"); | ||
75 | m_Port = serverConfig.GetInt("port", 8003); | ||
76 | m_Pass = serverConfig.GetString("pass", "secret"); | ||
77 | |||
78 | Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/StartSession/", String.Format("USER={0}&PASS={1}", m_User, m_Pass), LoginReply); | ||
79 | |||
80 | int res = m_Server.Run(); | ||
81 | |||
82 | Environment.Exit(res); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | private static void SendCommand(string module, string[] cmd) | ||
88 | { | ||
89 | string sendCmd = String.Join(" ", cmd); | ||
90 | |||
91 | Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/SessionCommand/", String.Format("ID={0}&COMMAND={1}", m_SessionID, sendCmd), CommandReply); | ||
92 | } | ||
93 | |||
94 | public static void LoginReply(string requestUrl, string requestData, string replyData) | ||
95 | { | ||
96 | XmlDocument doc = new XmlDocument(); | ||
97 | |||
98 | doc.LoadXml(replyData); | ||
99 | |||
100 | XmlNodeList rootL = doc.GetElementsByTagName("ConsoleSession"); | ||
101 | if (rootL.Count != 1) | ||
102 | { | ||
103 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
104 | Environment.Exit(1); | ||
105 | } | ||
106 | XmlElement rootNode = (XmlElement)rootL[0]; | ||
107 | |||
108 | if (rootNode == null) | ||
109 | { | ||
110 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
111 | Environment.Exit(1); | ||
112 | } | ||
113 | |||
114 | XmlNodeList helpNodeL = rootNode.GetElementsByTagName("HelpTree"); | ||
115 | if (helpNodeL.Count != 1) | ||
116 | { | ||
117 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
118 | Environment.Exit(1); | ||
119 | } | ||
120 | |||
121 | XmlElement helpNode = (XmlElement)helpNodeL[0]; | ||
122 | if (helpNode == null) | ||
123 | { | ||
124 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
125 | Environment.Exit(1); | ||
126 | } | ||
127 | |||
128 | XmlNodeList sessionL = rootNode.GetElementsByTagName("SessionID"); | ||
129 | if (sessionL.Count != 1) | ||
130 | { | ||
131 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
132 | Environment.Exit(1); | ||
133 | } | ||
134 | |||
135 | XmlElement sessionNode = (XmlElement)sessionL[0]; | ||
136 | if (sessionNode == null) | ||
137 | { | ||
138 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
139 | Environment.Exit(1); | ||
140 | } | ||
141 | |||
142 | if (!UUID.TryParse(sessionNode.InnerText, out m_SessionID)) | ||
143 | { | ||
144 | MainConsole.Instance.Output("Connection data info was not valid"); | ||
145 | Environment.Exit(1); | ||
146 | } | ||
147 | |||
148 | MainConsole.Instance.Commands.FromXml(helpNode, SendCommand); | ||
149 | |||
150 | Requester.MakeRequest("http://"+m_Host+":"+m_Port.ToString()+"/ReadResponses/"+m_SessionID.ToString()+"/", String.Empty, ReadResponses); | ||
151 | } | ||
152 | |||
153 | public static void ReadResponses(string requestUrl, string requestData, string replyData) | ||
154 | { | ||
155 | XmlDocument doc = new XmlDocument(); | ||
156 | |||
157 | doc.LoadXml(replyData); | ||
158 | |||
159 | XmlNodeList rootNodeL = doc.GetElementsByTagName("ConsoleSession"); | ||
160 | if (rootNodeL.Count != 1 || rootNodeL[0] == null) | ||
161 | { | ||
162 | Requester.MakeRequest(requestUrl, requestData, ReadResponses); | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | foreach (XmlNode part in rootNodeL[0].ChildNodes) | ||
167 | { | ||
168 | if (part.Name != "Line") | ||
169 | continue; | ||
170 | |||
171 | string[] parts = part.InnerText.Split(new char[] {':'}, 3); | ||
172 | if (parts.Length != 3) | ||
173 | continue; | ||
174 | |||
175 | MainConsole.Instance.Output(parts[2], parts[1]); | ||
176 | } | ||
177 | |||
178 | Requester.MakeRequest(requestUrl, requestData, ReadResponses); | ||
179 | } | ||
180 | |||
181 | public static void CommandReply(string requestUrl, string requestData, string replyData) | ||
182 | { | ||
183 | } | ||
184 | } | ||
185 | } | ||