aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/Inventory/tests
diff options
context:
space:
mode:
authorDr Scofield2008-08-20 10:11:58 +0000
committerDr Scofield2008-08-20 10:11:58 +0000
commit61e6d72cbcdbd362ed8779fc79fbf81ec3481931 (patch)
tree78bc9d697fd7bf4acab057247f1ade64e414d845 /OpenSim/ApplicationPlugins/Rest/Inventory/tests
parentFrom: Alan Webb <alan_webb@us.ibm.com> (diff)
downloadopensim-SC_OLD-61e6d72cbcdbd362ed8779fc79fbf81ec3481931.zip
opensim-SC_OLD-61e6d72cbcdbd362ed8779fc79fbf81ec3481931.tar.gz
opensim-SC_OLD-61e6d72cbcdbd362ed8779fc79fbf81ec3481931.tar.bz2
opensim-SC_OLD-61e6d72cbcdbd362ed8779fc79fbf81ec3481931.tar.xz
oops. forgot.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/Inventory/tests')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs225
1 files changed, 225 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs
new file mode 100644
index 0000000..c50a945
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs
@@ -0,0 +1,225 @@
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 OpenSim 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
29using libsecondlife;
30using Nini.Config;
31using System;
32using System.Collections.Generic;
33using System.IO;
34using System.Threading;
35using System.Xml;
36using OpenSim.Framework;
37using OpenSim.Region.Environment.Scenes;
38using OpenSim.Framework.Servers;
39using OpenSim.Framework.Communications;
40using OpenSim.Framework.Communications.Cache;
41
42namespace OpenSim.ApplicationPlugins.Rest.Inventory.Tests
43{
44
45 public class Remote : ITest
46 {
47
48 private static readonly int PARM_TESTID = 0;
49 private static readonly int PARM_COMMAND = 1;
50
51 private static readonly int PARM_MOVE_AVATAR = 2;
52 private static readonly int PARM_MOVE_X = 3;
53 private static readonly int PARM_MOVE_Y = 4;
54 private static readonly int PARM_MOVE_Z = 5;
55
56 private bool enabled = false;
57
58 // No constructor code is required.
59
60 public Remote()
61 {
62 Rest.Log.InfoFormat("{0} Remote services constructor", MsgId);
63 }
64
65 // Post-construction, pre-enabled initialization opportunity
66 // Not currently exploited.
67
68 public void Initialize()
69 {
70 enabled = true;
71 Rest.Log.InfoFormat("{0} Remote services initialize", MsgId);
72 }
73
74 // Called by the plug-in to halt REST processing. Local processing is
75 // disabled, and control blocks until all current processing has
76 // completed. No new processing will be started
77
78 public void Close()
79 {
80 enabled = false;
81 Rest.Log.InfoFormat("{0} Remote services closing down", MsgId);
82 }
83
84 // Properties
85
86 internal string MsgId
87 {
88 get { return Rest.MsgId; }
89 }
90
91 // Remote Handler
92 // Key information of interest here is the Parameters array, each
93 // entry represents an element of the URI, with element zero being
94 // the
95
96 public void Execute(RequestData rdata)
97 {
98
99 if (!enabled) return;
100
101 // If we can't relate to what's there, leave it for others.
102
103 if (rdata.Parameters.Length == 0 || rdata.Parameters[PARM_TESTID] != "remote")
104 return;
105
106 Rest.Log.DebugFormat("{0} REST Remote handler ENTRY", MsgId);
107
108 // Remove the prefix and what's left are the parameters. If we don't have
109 // the parameters we need, fail the request. Parameters do NOT include
110 // any supplied query values.
111
112 if (rdata.Parameters.Length > 1)
113 {
114 switch (rdata.Parameters[PARM_COMMAND].ToLower())
115 {
116 case "move" :
117 DoMove(rdata);
118 break;
119 default :
120 DoHelp(rdata);
121 break;
122 }
123 }
124 else
125 {
126 DoHelp(rdata);
127 }
128 }
129
130 private void DoHelp(RequestData rdata)
131 {
132 rdata.body = Help;
133 rdata.Complete();
134 rdata.Respond("Help");
135 }
136
137 private void DoMove(RequestData rdata)
138 {
139 if (rdata.Parameters.Length >= 6)
140 {
141
142 string[] names = rdata.Parameters[PARM_MOVE_AVATAR].Split(Rest.CA_SPACE);
143 ScenePresence avatar = null;
144 Scene scene = null;
145
146 if (names.Length != 2)
147 {
148 rdata.Fail(Rest.HttpStatusCodeBadRequest,
149 String.Format("invalid avatar name: <{0}>",rdata.Parameters[PARM_MOVE_AVATAR]));
150 }
151
152 Rest.Log.WarnFormat("{0} '{1}' command received for {2} {3}",
153 MsgId, rdata.Parameters[0], names[0], names[1]);
154
155 // The first parameter should be an avatar name, look for the
156 // avatar in the known regions first.
157
158 foreach (Scene cs in Rest.main.SceneManager.Scenes)
159 {
160 foreach (ScenePresence presence in cs.GetAvatars())
161 {
162 if (presence.Firstname == names[0] &&
163 presence.Lastname == names[1])
164 {
165 scene = cs;
166 avatar = presence;
167 break;
168 }
169 }
170 }
171
172 if (avatar != null)
173 {
174
175 Rest.Log.DebugFormat("{0} Move : Avatar {1} located in region {2}",
176 MsgId, rdata.Parameters[PARM_MOVE_AVATAR], scene.RegionInfo.RegionName);
177
178 try
179 {
180 float x = Convert.ToSingle(rdata.Parameters[PARM_MOVE_X]);
181 float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]);
182 float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]);
183 LLVector3 vector = new LLVector3(x,y,z);
184 avatar.DoAutoPilot(0,vector,avatar.ControllingClient);
185 }
186 catch (Exception e)
187 {
188 rdata.Fail(Rest.HttpStatusCodeBadRequest,
189 String.Format("invalid parameters: {0}", e.Message));
190 }
191
192 }
193 else
194 {
195 rdata.Fail(Rest.HttpStatusCodeBadRequest,
196 String.Format("avatar {0} not present", rdata.Parameters[PARM_MOVE_AVATAR]));
197 }
198
199 rdata.Complete();
200 rdata.Respond("OK");
201
202 }
203 else
204 {
205 Rest.Log.WarnFormat("{0} Move: No movement information provided", MsgId);
206 rdata.Fail(Rest.HttpStatusCodeBadRequest, "no movement information provided");
207 }
208
209 }
210
211 private static readonly string Help =
212 "<html>"
213 + "<head><title>Remote Command Usage</title></head>"
214 + "<body>"
215 + "<p>Supported commands are:</p>"
216 + "<dl>"
217 + "<dt>move/avatar-name/x/y/z</dt>"
218 + "<dd>moves the specified avatar to another location</dd>"
219 + "</dl>"
220 + "</body>"
221 + "</html>"
222 ;
223
224 }
225}