aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/AgentHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs244
1 files changed, 243 insertions, 1 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 3da72c7..4966f66 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Net; 32using System.Net;
@@ -45,6 +46,247 @@ using log4net;
45 46
46namespace OpenSim.Server.Handlers.Simulation 47namespace OpenSim.Server.Handlers.Simulation
47{ 48{
49 public class AgentHandler
50 {
51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private ISimulationService m_SimulationService;
53
54 public AgentHandler(ISimulationService sim)
55 {
56 m_SimulationService = sim;
57 }
58
59 public Hashtable Handler(Hashtable request)
60 {
61 //m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler 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 responsedata["keepalive"] = false;
72
73
74 UUID agentID;
75 string action;
76 ulong regionHandle;
77 if (!Utils.GetParams((string)request["uri"], out agentID, out regionHandle, out action))
78 {
79 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
80 responsedata["int_response_code"] = 404;
81 responsedata["str_response_string"] = "false";
82
83 return responsedata;
84 }
85
86 // Next, let's parse the verb
87 string method = (string)request["http-method"];
88 if (method.Equals("PUT"))
89 {
90 DoAgentPut(request, responsedata);
91 return responsedata;
92 }
93 else if (method.Equals("POST"))
94 {
95 DoAgentPost(request, responsedata, agentID);
96 return responsedata;
97 }
98 else if (method.Equals("GET"))
99 {
100 DoAgentGet(request, responsedata, agentID, regionHandle);
101 return responsedata;
102 }
103 else if (method.Equals("DELETE"))
104 {
105 DoAgentDelete(request, responsedata, agentID, action, regionHandle);
106 return responsedata;
107 }
108 else
109 {
110 m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method);
111 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
112 responsedata["str_response_string"] = "Method not allowed";
113
114 return responsedata;
115 }
116
117 }
118
119 protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
120 {
121 OSDMap args = Utils.GetOSDMap((string)request["body"]);
122 if (args == null)
123 {
124 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
125 responsedata["str_response_string"] = "Bad request";
126 return;
127 }
128
129 // retrieve the regionhandle
130 ulong regionhandle = 0;
131 if (args["destination_handle"] != null)
132 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
133
134 AgentCircuitData aCircuit = new AgentCircuitData();
135 try
136 {
137 aCircuit.UnpackAgentCircuitData(args);
138 }
139 catch (Exception ex)
140 {
141 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
142 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
143 responsedata["str_response_string"] = "Bad request";
144 return;
145 }
146
147 OSDMap resp = new OSDMap(2);
148 string reason = String.Empty;
149 uint teleportFlags = 0;
150 if (args.ContainsKey("teleport_flags"))
151 {
152 teleportFlags = args["teleport_flags"].AsUInteger();
153 }
154
155 // This is the meaning of POST agent
156 //m_regionClient.AdjustUserInformation(aCircuit);
157 bool result = m_SimulationService.CreateAgent(regionhandle, aCircuit, teleportFlags, out reason);
158
159 resp["reason"] = OSD.FromString(reason);
160 resp["success"] = OSD.FromBoolean(result);
161
162 // TODO: add reason if not String.Empty?
163 responsedata["int_response_code"] = HttpStatusCode.OK;
164 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
165 }
166
167 protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata)
168 {
169 OSDMap args = Utils.GetOSDMap((string)request["body"]);
170 if (args == null)
171 {
172 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
173 responsedata["str_response_string"] = "Bad request";
174 return;
175 }
176
177 // retrieve the regionhandle
178 ulong regionhandle = 0;
179 if (args["destination_handle"] != null)
180 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
181
182 string messageType;
183 if (args["message_type"] != null)
184 messageType = args["message_type"].AsString();
185 else
186 {
187 m_log.Warn("[AGENT HANDLER]: Agent Put Message Type not found. ");
188 messageType = "AgentData";
189 }
190
191 bool result = true;
192 if ("AgentData".Equals(messageType))
193 {
194 AgentData agent = new AgentData();
195 try
196 {
197 agent.Unpack(args);
198 }
199 catch (Exception ex)
200 {
201 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
202 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
203 responsedata["str_response_string"] = "Bad request";
204 return;
205 }
206
207 //agent.Dump();
208 // This is one of the meanings of PUT agent
209 result = m_SimulationService.UpdateAgent(regionhandle, agent);
210
211 }
212 else if ("AgentPosition".Equals(messageType))
213 {
214 AgentPosition agent = new AgentPosition();
215 try
216 {
217 agent.Unpack(args);
218 }
219 catch (Exception ex)
220 {
221 m_log.InfoFormat("[AGENT HANDLER]: exception on unpacking ChildAgentUpdate message {0}", ex.Message);
222 return;
223 }
224 //agent.Dump();
225 // This is one of the meanings of PUT agent
226 result = m_SimulationService.UpdateAgent(regionhandle, agent);
227
228 }
229
230 responsedata["int_response_code"] = HttpStatusCode.OK;
231 responsedata["str_response_string"] = result.ToString();
232 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
233 }
234
235 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, ulong regionHandle)
236 {
237 IAgentData agent = null;
238 bool result = m_SimulationService.RetrieveAgent(regionHandle, id, out agent);
239 OSDMap map = null;
240 if (result)
241 {
242 if (agent != null) // just to make sure
243 {
244 map = agent.Pack();
245 string strBuffer = "";
246 try
247 {
248 strBuffer = OSDParser.SerializeJsonString(map);
249 }
250 catch (Exception e)
251 {
252 m_log.WarnFormat("[AGENT HANDLER]: Exception thrown on serialization of DoAgentGet: {0}", e.Message);
253 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
254 // ignore. buffer will be empty, caller should check.
255 }
256
257 responsedata["content_type"] = "application/json";
258 responsedata["int_response_code"] = HttpStatusCode.OK;
259 responsedata["str_response_string"] = strBuffer;
260 }
261 else
262 {
263 responsedata["int_response_code"] = HttpStatusCode.InternalServerError;
264 responsedata["str_response_string"] = "Internal error";
265 }
266 }
267 else
268 {
269 responsedata["int_response_code"] = HttpStatusCode.NotFound;
270 responsedata["str_response_string"] = "Not Found";
271 }
272 }
273
274 protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle)
275 {
276 //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle);
277
278 if (action.Equals("release"))
279 m_SimulationService.ReleaseAgent(regionHandle, id, "");
280 else
281 m_SimulationService.CloseAgent(regionHandle, id);
282
283 responsedata["int_response_code"] = HttpStatusCode.OK;
284 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
285
286 m_log.Debug("[AGENT HANDLER]: Agent Deleted.");
287 }
288 }
289
48 public class AgentGetHandler : BaseStreamHandler 290 public class AgentGetHandler : BaseStreamHandler
49 { 291 {
50 // TODO: unused: private ISimulationService m_SimulationService; 292 // TODO: unused: private ISimulationService m_SimulationService;
@@ -153,7 +395,7 @@ namespace OpenSim.Server.Handlers.Simulation
153 // m_regionClient.AdjustUserInformation(aCircuit); 395 // m_regionClient.AdjustUserInformation(aCircuit);
154 396
155 // Finally! 397 // Finally!
156 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason); 398 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, /*!!!*/0, out reason);
157 399
158 OSDMap resp = new OSDMap(1); 400 OSDMap resp = new OSDMap(1);
159 401