diff options
author | Diva Canto | 2009-12-31 09:25:16 -0800 |
---|---|---|
committer | Diva Canto | 2009-12-31 09:25:16 -0800 |
commit | a8901a40f4526720f68049706cabd34cf9717172 (patch) | |
tree | f64b2d8eed119e8080e3d696e4e822b55f0f5882 /OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | |
parent | No-op. (diff) | |
download | opensim-SC-a8901a40f4526720f68049706cabd34cf9717172.zip opensim-SC-a8901a40f4526720f68049706cabd34cf9717172.tar.gz opensim-SC-a8901a40f4526720f68049706cabd34cf9717172.tar.bz2 opensim-SC-a8901a40f4526720f68049706cabd34cf9717172.tar.xz |
Simulation handlers (agents & objects) completed.
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | 191 |
1 files changed, 191 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..8c3af72 --- /dev/null +++ b/OpenSim/Server/Handlers/Simulation/ObjectHandlers.cs | |||
@@ -0,0 +1,191 @@ | |||
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 OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | |||
41 | using OpenMetaverse; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | using Nini.Config; | ||
44 | using log4net; | ||
45 | |||
46 | |||
47 | namespace OpenSim.Server.Handlers.Simulation | ||
48 | { | ||
49 | public class ObjectHandler | ||
50 | { | ||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | private ISimulationService m_SimulationService; | ||
53 | |||
54 | public ObjectHandler(ISimulationService sim) | ||
55 | { | ||
56 | m_SimulationService = sim; | ||
57 | } | ||
58 | |||
59 | public Hashtable Handler(Hashtable request) | ||
60 | { | ||
61 | m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); | ||
62 | |||
63 | m_log.Debug("---------------------------"); | ||
64 | m_log.Debug(" >> uri=" + request["uri"]); | ||
65 | m_log.Debug(" >> content-type=" + request["content-type"]); | ||
66 | m_log.Debug(" >> http-method=" + request["http-method"]); | ||
67 | m_log.Debug("---------------------------\n"); | ||
68 | |||
69 | Hashtable responsedata = new Hashtable(); | ||
70 | responsedata["content_type"] = "text/html"; | ||
71 | |||
72 | UUID objectID; | ||
73 | string action; | ||
74 | ulong regionHandle; | ||
75 | if (!Utils.GetParams((string)request["uri"], out objectID, out regionHandle, out action)) | ||
76 | { | ||
77 | m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]); | ||
78 | responsedata["int_response_code"] = 404; | ||
79 | responsedata["str_response_string"] = "false"; | ||
80 | |||
81 | return responsedata; | ||
82 | } | ||
83 | |||
84 | // Next, let's parse the verb | ||
85 | string method = (string)request["http-method"]; | ||
86 | if (method.Equals("POST")) | ||
87 | { | ||
88 | DoObjectPost(request, responsedata, regionHandle); | ||
89 | return responsedata; | ||
90 | } | ||
91 | else if (method.Equals("PUT")) | ||
92 | { | ||
93 | DoObjectPut(request, responsedata, regionHandle); | ||
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("[REST COMMS]: method {0} not supported in object message", method); | ||
104 | responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; | ||
105 | responsedata["str_response_string"] = "Mthod not allowed"; | ||
106 | |||
107 | return responsedata; | ||
108 | } | ||
109 | |||
110 | } | ||
111 | |||
112 | protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) | ||
113 | { | ||
114 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
115 | if (args == null) | ||
116 | { | ||
117 | responsedata["int_response_code"] = 400; | ||
118 | responsedata["str_response_string"] = "false"; | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | string sogXmlStr = "", extraStr = "", stateXmlStr = ""; | ||
123 | if (args["sog"] != null) | ||
124 | sogXmlStr = args["sog"].AsString(); | ||
125 | if (args["extra"] != null) | ||
126 | extraStr = args["extra"].AsString(); | ||
127 | |||
128 | IScene s = m_SimulationService.GetScene(regionhandle); | ||
129 | ISceneObject sog = null; | ||
130 | try | ||
131 | { | ||
132 | //sog = SceneObjectSerializer.FromXml2Format(sogXmlStr); | ||
133 | sog = s.DeserializeObject(sogXmlStr); | ||
134 | sog.ExtraFromXmlString(extraStr); | ||
135 | } | ||
136 | catch (Exception ex) | ||
137 | { | ||
138 | m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message); | ||
139 | responsedata["int_response_code"] = HttpStatusCode.BadRequest; | ||
140 | responsedata["str_response_string"] = "Bad request"; | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | if ((args["state"] != null) && s.AllowScriptCrossings) | ||
145 | { | ||
146 | stateXmlStr = args["state"].AsString(); | ||
147 | if (stateXmlStr != "") | ||
148 | { | ||
149 | try | ||
150 | { | ||
151 | sog.SetState(stateXmlStr, s); | ||
152 | } | ||
153 | catch (Exception ex) | ||
154 | { | ||
155 | m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message); | ||
156 | // ignore and continue | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | // This is the meaning of POST object | ||
161 | bool result = m_SimulationService.CreateObject(regionhandle, sog, false); | ||
162 | |||
163 | responsedata["int_response_code"] = HttpStatusCode.OK; | ||
164 | responsedata["str_response_string"] = result.ToString(); | ||
165 | } | ||
166 | |||
167 | protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, ulong regionhandle) | ||
168 | { | ||
169 | OSDMap args = Utils.GetOSDMap((string)request["body"]); | ||
170 | if (args == null) | ||
171 | { | ||
172 | responsedata["int_response_code"] = 400; | ||
173 | responsedata["str_response_string"] = "false"; | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | UUID userID = UUID.Zero, itemID = UUID.Zero; | ||
178 | if (args["userid"] != null) | ||
179 | userID = args["userid"].AsUUID(); | ||
180 | if (args["itemid"] != null) | ||
181 | itemID = args["itemid"].AsUUID(); | ||
182 | |||
183 | // This is the meaning of PUT object | ||
184 | bool result = m_SimulationService.CreateObject(regionhandle, userID, itemID); | ||
185 | |||
186 | responsedata["int_response_code"] = 200; | ||
187 | responsedata["str_response_string"] = result.ToString(); | ||
188 | } | ||
189 | |||
190 | } | ||
191 | } \ No newline at end of file | ||