opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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() { }
56  
57 public ObjectHandler(ISimulationService sim)
58 {
59 m_SimulationService = sim;
60 }
61  
62 public Hashtable Handler(Hashtable request)
63 {
64 //m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called");
65  
66 //m_log.Debug("---------------------------");
67 //m_log.Debug(" >> uri=" + request["uri"]);
68 //m_log.Debug(" >> content-type=" + request["content-type"]);
69 //m_log.Debug(" >> http-method=" + request["http-method"]);
70 //m_log.Debug("---------------------------\n");
71  
72 Hashtable responsedata = new Hashtable();
73 responsedata["content_type"] = "text/html";
74  
75 UUID objectID;
76 UUID regionID;
77 string action;
78 if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action))
79 {
80 m_log.InfoFormat("[OBJECT HANDLER]: Invalid parameters for object message {0}", request["uri"]);
81 responsedata["int_response_code"] = 404;
82 responsedata["str_response_string"] = "false";
83  
84 return responsedata;
85 }
86  
87 try
88 {
89 // Next, let's parse the verb
90 string method = (string)request["http-method"];
91 if (method.Equals("POST"))
92 {
93 DoObjectPost(request, responsedata, regionID);
94 return responsedata;
95 }
96 //else if (method.Equals("DELETE"))
97 //{
98 // DoObjectDelete(request, responsedata, agentID, action, regionHandle);
99 // return responsedata;
100 //}
101 else
102 {
103 m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method);
104 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
105 responsedata["str_response_string"] = "Method not allowed";
106  
107 return responsedata;
108 }
109 }
110 catch (Exception e)
111 {
112 m_log.WarnFormat("[OBJECT HANDLER]: Caught exception {0}", e.StackTrace);
113 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
114 responsedata["str_response_string"] = "Internal server error";
115  
116 return responsedata;
117  
118 }
119 }
120  
121 protected void DoObjectPost(Hashtable request, Hashtable responsedata, UUID regionID)
122 {
123 OSDMap args = Utils.GetOSDMap((string)request["body"]);
124 if (args == null)
125 {
126 responsedata["int_response_code"] = 400;
127 responsedata["str_response_string"] = "false";
128 return;
129 }
130 // retrieve the input arguments
131 int x = 0, y = 0;
132 UUID uuid = UUID.Zero;
133 string regionname = string.Empty;
134 Vector3 newPosition = Vector3.Zero;
135  
136 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
137 Int32.TryParse(args["destination_x"].AsString(), out x);
138 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
139 Int32.TryParse(args["destination_y"].AsString(), out y);
140 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
141 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
142 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
143 regionname = args["destination_name"].ToString();
144 if (args.ContainsKey("new_position") && args["new_position"] != null)
145 Vector3.TryParse(args["new_position"], out newPosition);
146  
147 GridRegion destination = new GridRegion();
148 destination.RegionID = uuid;
149 destination.RegionLocX = x;
150 destination.RegionLocY = y;
151 destination.RegionName = regionname;
152  
153 string sogXmlStr = "", extraStr = "", stateXmlStr = "";
154 if (args.ContainsKey("sog") && args["sog"] != null)
155 sogXmlStr = args["sog"].AsString();
156 if (args.ContainsKey("extra") && args["extra"] != null)
157 extraStr = args["extra"].AsString();
158  
159 IScene s = m_SimulationService.GetScene(destination.RegionID);
160 ISceneObject sog = null;
161 try
162 {
163 //m_log.DebugFormat("[OBJECT HANDLER]: received {0}", sogXmlStr);
164 sog = s.DeserializeObject(sogXmlStr);
165 sog.ExtraFromXmlString(extraStr);
166 }
167 catch (Exception ex)
168 {
169 m_log.InfoFormat("[OBJECT HANDLER]: exception on deserializing scene object {0}", ex.Message);
170 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
171 responsedata["str_response_string"] = "Bad request";
172 return;
173 }
174  
175 if (args.ContainsKey("modified"))
176 sog.HasGroupChanged = args["modified"].AsBoolean();
177 else
178 sog.HasGroupChanged = false;
179  
180 if ((args["state"] != null) && s.AllowScriptCrossings)
181 {
182 stateXmlStr = args["state"].AsString();
183 if (stateXmlStr != "")
184 {
185 try
186 {
187 sog.SetState(stateXmlStr, s);
188 }
189 catch (Exception ex)
190 {
191 m_log.InfoFormat("[OBJECT HANDLER]: exception on setting state for scene object {0}", ex.Message);
192 // ignore and continue
193 }
194 }
195 }
196  
197 bool result = false;
198 try
199 {
200 // This is the meaning of POST object
201 result = CreateObject(destination, newPosition, sog);
202 }
203 catch (Exception e)
204 {
205 m_log.DebugFormat("[OBJECT HANDLER]: Exception in CreateObject: {0}", e.StackTrace);
206 }
207  
208 responsedata["int_response_code"] = HttpStatusCode.OK;
209 responsedata["str_response_string"] = result.ToString();
210 }
211  
212 // subclasses can override this
213 protected virtual bool CreateObject(GridRegion destination, Vector3 newPosition, ISceneObject sog)
214 {
215 return m_SimulationService.CreateObject(destination, newPosition, sog, false);
216 }
217 }
218 }