aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ConsoleClient
diff options
context:
space:
mode:
authorDiva Canto2009-08-17 05:55:38 -0700
committerDiva Canto2009-08-17 05:55:38 -0700
commitfa8a94577a2f38145da0c8a1f6d1c72c4f339ed9 (patch)
tree7bee741b06e6732fae848bef3c6b7f808ab3349a /OpenSim/ConsoleClient
parentBumped up grid services interface number. (diff)
parentAdd System.Xml reference to the console project (diff)
downloadopensim-SC_OLD-fa8a94577a2f38145da0c8a1f6d1c72c4f339ed9.zip
opensim-SC_OLD-fa8a94577a2f38145da0c8a1f6d1c72c4f339ed9.tar.gz
opensim-SC_OLD-fa8a94577a2f38145da0c8a1f6d1c72c4f339ed9.tar.bz2
opensim-SC_OLD-fa8a94577a2f38145da0c8a1f6d1c72c4f339ed9.tar.xz
Merge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/ConsoleClient')
-rw-r--r--OpenSim/ConsoleClient/ConsoleClient.cs198
-rw-r--r--OpenSim/ConsoleClient/Requester.cs86
2 files changed, 284 insertions, 0 deletions
diff --git a/OpenSim/ConsoleClient/ConsoleClient.cs b/OpenSim/ConsoleClient/ConsoleClient.cs
new file mode 100644
index 0000000..319584f
--- /dev/null
+++ b/OpenSim/ConsoleClient/ConsoleClient.cs
@@ -0,0 +1,198 @@
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
28using Nini.Config;
29using log4net;
30using System.Reflection;
31using System;
32using System.Xml;
33using System.Collections.Generic;
34using OpenSim.Server.Base;
35using OpenSim.Framework.Console;
36using OpenMetaverse;
37
38namespace 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 List<string> lines = new List<string>();
167
168 foreach (XmlNode part in rootNodeL[0].ChildNodes)
169 {
170 if (part.Name != "Line")
171 continue;
172
173 lines.Add(part.InnerText);
174 }
175
176 // Cut down scrollback to 100 lines (4 screens)
177 // for the command line client
178 //
179 while (lines.Count > 100)
180 lines.RemoveAt(0);
181
182 foreach (string l in lines)
183 {
184 string[] parts = l.Split(new char[] {':'}, 3);
185 if (parts.Length != 3)
186 continue;
187
188 MainConsole.Instance.Output(parts[2].Trim(), parts[1]);
189 }
190
191 Requester.MakeRequest(requestUrl, requestData, ReadResponses);
192 }
193
194 public static void CommandReply(string requestUrl, string requestData, string replyData)
195 {
196 }
197 }
198}
diff --git a/OpenSim/ConsoleClient/Requester.cs b/OpenSim/ConsoleClient/Requester.cs
new file mode 100644
index 0000000..af7860d
--- /dev/null
+++ b/OpenSim/ConsoleClient/Requester.cs
@@ -0,0 +1,86 @@
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
28using System;
29using System.IO;
30using System.Net;
31using System.Reflection;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35using log4net;
36
37namespace OpenSim.ConsoleClient
38{
39 public delegate void ReplyDelegate(string requestUrl, string requestData, string replyData);
40
41 public class Requester
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 public static void MakeRequest(string requestUrl, string data,
46 ReplyDelegate action)
47 {
48 WebRequest request = WebRequest.Create(requestUrl);
49 WebResponse response = null;
50
51 request.Method = "POST";
52
53 request.ContentType = "application/x-www-form-urlencoded";
54
55 byte[] buffer = new System.Text.ASCIIEncoding().GetBytes(data);
56 int length = (int) buffer.Length;
57 request.ContentLength = length;
58
59 request.BeginGetRequestStream(delegate(IAsyncResult res)
60 {
61 Stream requestStream = request.EndGetRequestStream(res);
62
63 requestStream.Write(buffer, 0, length);
64
65 request.BeginGetResponse(delegate(IAsyncResult ar)
66 {
67 string reply = String.Empty;
68
69 response = request.EndGetResponse(ar);
70
71 try
72 {
73 StreamReader r = new StreamReader(response.GetResponseStream());
74 reply = r.ReadToEnd();
75
76 }
77 catch (System.InvalidOperationException)
78 {
79 }
80
81 action(requestUrl, data, reply);
82 }, null);
83 }, null);
84 }
85 }
86}