diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs new file mode 100644 index 0000000..b6eabe3 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | |||
@@ -0,0 +1,238 @@ | |||
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 System; | ||
29 | using System.Collections; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Net; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Server.Handlers.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | |||
42 | using OpenMetaverse; | ||
43 | using OpenMetaverse.StructuredData; | ||
44 | using Nini.Config; | ||
45 | using log4net; | ||
46 | |||
47 | |||
48 | namespace OpenSim.Server.Handlers.Simulation | ||
49 | { | ||
50 | public class ObjectHandler | ||
51 | { | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | private ISimulationService m_SimulationService; | ||
54 | |||
55 | public ObjectHandler(ISimulationService sim) | ||
56 | { | ||
57 | m_SimulationService = sim; | ||
58 | } | ||
59 | |||
60 | public Hashtable Handler(Hashtable request) | ||
61 | { | ||
62 | //m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); | ||
63 | |||
64 | //m_log.Debug("---------------------------"); | ||
65 | //m_log.Debug(" >> uri=" + request["uri"]); | ||
66 | //m_log.Debug(" >> content-type=" + request["content-type"]); | ||
67 | //m_log.Debug(" >> http-method=" + request["http-method"]); | ||
68 | //m_log.Debug("---------------------------\n"); | ||
69 | |||
70 | Hashtable responsedata = new Hashtable(); | ||
71 | responsedata["content_type"] = "text/html"; | ||
72 | |||
73 | UUID objectID; | ||
74 | UUID regionID; | ||
75 | string action; | ||
76 | if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action)) | ||
77 | { | ||
78 | m_log.InfoFormat("[OBJECT HANDLER]: Invalid parameters for object message {0}", request["uri"]); | ||
79 | responsedata["int_response_code"] = 404; | ||
80 | responsedata["str_response_string"] = "false"; | ||
81 | |||
82 | return responsedata; | ||
83 | } | ||
84 | |||
85 | // Next, let's parse the verb | ||
86 | string method = (string)request["http-method"]; | ||
87 | if (method.Equals("POST")) | ||
88 | { | ||
89 | DoObjectPost(request, responsedata, regionID); | ||
90 | return responsedata; | ||
91 | } | ||
92 | else if (method.Equals("PUT")) | ||
93 | { | ||
94 | DoObjectPut(request, responsedata, regionID); | ||
95 | return responsedata; | ||
96 | } | ||
97 | //else if (method.Equals("DELETE")) | ||
98 | //{ | ||
99 | // DoObjectDelete(request, responsedata, agentID, action, regionHandle); | ||
100 | // return responsedata; | ||
101 | //} | ||
102 | else | ||
103 | { | ||
104 | m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method); | ||
105 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
106 | responsedata["str_response_string"] = "Mthod not allowed"; | ||
107 | |||
108 | return responsedata; | ||
109 | } | ||
110 | |||
111 | } | ||
112 | |||
113 | protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID) | ||
114 | { | ||
115 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
116 | if (args == null) | ||
117 | { | ||
118 | responsedata["int_response_code"] = 400; | ||
119 | responsedata["str_response_string"] = "false"; | ||
120 | return; | ||
121 | } | ||
122 | // retrieve the input arguments | ||
123 | int x = 0, y = 0; | ||
124 | UUID uuid = UUID.Zero; | ||
125 | string regionname = string.Empty; | ||
126 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
127 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
128 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
129 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
130 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
131 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
132 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
133 | regionname = args["destination_name"].ToString(); | ||
134 | |||
135 | GridRegion destination = new GridRegion(); | ||
136 | destination.RegionID = uuid; | ||
137 | destination.RegionLocX = x; | ||
138 | destination.RegionLocY = y; | ||
139 | destination.RegionName = regionname; | ||
140 | |||
141 | string sogXmlStr = "", extraStr = "", stateXmlStr = ""; | ||
142 | if (args.ContainsKey("sog") && args["sog"] != null) | ||
143 | sogXmlStr = args["sog"].AsString(); | ||
144 | if (args.ContainsKey("extra") && args["extra"] != null) | ||
145 | extraStr = args["extra"].AsString(); | ||
146 | |||
147 | IScene s = m_SimulationService.GetScene(destination.RegionHandle); | ||
148 | ISceneObject sog = null; | ||
149 | try | ||
150 | { | ||
151 | //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr); | ||
152 | sog = s.DeserializeObject(sogXmlStr); | ||
153 | sog.ExtraFromXmlString(extraStr); | ||
154 | } | ||
155 | catch (Exception ex) | ||
156 | { | ||
157 | m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message); | ||
158 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
159 | responsedata["str_response_string"] = "Bad request"; | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | if ((args["state"] != null) && s.AllowScriptCrossings) | ||
164 | { | ||
165 | stateXmlStr = args["state"].AsString(); | ||
166 | if (stateXmlStr != "") | ||
167 | { | ||
168 | try | ||
169 | { | ||
170 | sog.SetState(stateXmlStr, s); | ||
171 | } | ||
172 | catch (Exception ex) | ||
173 | { | ||
174 | m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message); | ||
175 | // ignore and continue | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | bool result = false; | ||
181 | try | ||
182 | { | ||
183 | // This is the meaning of POST object | ||
184 | result = m_SimulationService.CreateObject(destination, sog, false); | ||
185 | } | ||
186 | catch (Exception e) | ||
187 | { | ||
188 | m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace); | ||
189 | } | ||
190 | |||
191 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
192 | responsedata["str_response_string"] = result.ToString(); | ||
193 | } | ||
194 | |||
195 | protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, UUID regionID) | ||
196 | { | ||
197 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
198 | if (args == null) | ||
199 | { | ||
200 | responsedata["int_response_code"] = 400; | ||
201 | responsedata["str_response_string"] = "false"; | ||
202 | return; | ||
203 | } | ||
204 | |||
205 | // retrieve the input arguments | ||
206 | int x = 0, y = 0; | ||
207 | UUID uuid = UUID.Zero; | ||
208 | string regionname = string.Empty; | ||
209 | if (args.ContainsKey("destination_x") && args["destination_x"] != null) | ||
210 | Int32.TryParse(args["destination_x"].AsString(), out x); | ||
211 | if (args.ContainsKey("destination_y") && args["destination_y"] != null) | ||
212 | Int32.TryParse(args["destination_y"].AsString(), out y); | ||
213 | if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null) | ||
214 | UUID.TryParse(args["destination_uuid"].AsString(), out uuid); | ||
215 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | ||
216 | regionname = args["destination_name"].ToString(); | ||
217 | |||
218 | GridRegion destination = new GridRegion(); | ||
219 | destination.RegionID = uuid; | ||
220 | destination.RegionLocX = x; | ||
221 | destination.RegionLocY = y; | ||
222 | destination.RegionName = regionname; | ||
223 | |||
224 | UUID userID = UUID.Zero, itemID = UUID.Zero; | ||
225 | if (args.ContainsKey("userid") && args["userid"] != null) | ||
226 | userID = args["userid"].AsUUID(); | ||
227 | if (args.ContainsKey("itemid") && args["itemid"] != null) | ||
228 | itemID = args["itemid"].AsUUID(); | ||
229 | |||
230 | // This is the meaning of PUT object | ||
231 | bool result = m_SimulationService.CreateObject(destination, userID, itemID); | ||
232 | |||
233 | responsedata["int_response_code"] = 200; | ||
234 | responsedata["str_response_string"] = result.ToString(); | ||
235 | } | ||
236 | |||
237 | } | ||
238 | } \ No newline at end of file | ||