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, 58 insertions, 186 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
index 4966f66..f4f3eea 100644
--- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -35,6 +35,7 @@ using System.Text;
35using OpenSim.Server.Base; 35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base; 36using OpenSim.Server.Handlers.Base;
37using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using OpenSim.Framework; 39using OpenSim.Framework;
39using OpenSim.Framework.Servers.HttpServer; 40using OpenSim.Framework.Servers.HttpServer;
40 41
@@ -72,9 +73,9 @@ namespace OpenSim.Server.Handlers.Simulation
72 73
73 74
74 UUID agentID; 75 UUID agentID;
76 UUID regionID;
75 string action; 77 string action;
76 ulong regionHandle; 78 if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
77 if (!Utils.GetParams((string)request["uri"], out agentID, out regionHandle, out action))
78 { 79 {
79 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); 80 m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
80 responsedata["int_response_code"] = 404; 81 responsedata["int_response_code"] = 404;
@@ -97,12 +98,12 @@ namespace OpenSim.Server.Handlers.Simulation
97 } 98 }
98 else if (method.Equals("GET")) 99 else if (method.Equals("GET"))
99 { 100 {
100 DoAgentGet(request, responsedata, agentID, regionHandle); 101 DoAgentGet(request, responsedata, agentID, regionID);
101 return responsedata; 102 return responsedata;
102 } 103 }
103 else if (method.Equals("DELETE")) 104 else if (method.Equals("DELETE"))
104 { 105 {
105 DoAgentDelete(request, responsedata, agentID, action, regionHandle); 106 DoAgentDelete(request, responsedata, agentID, action, regionID);
106 return responsedata; 107 return responsedata;
107 } 108 }
108 else 109 else
@@ -126,10 +127,27 @@ namespace OpenSim.Server.Handlers.Simulation
126 return; 127 return;
127 } 128 }
128 129
129 // retrieve the regionhandle 130 // retrieve the input arguments
130 ulong regionhandle = 0; 131 int x = 0, y = 0;
131 if (args["destination_handle"] != null) 132 UUID uuid = UUID.Zero;
132 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); 133 string regionname = string.Empty;
134 uint teleportFlags = 0;
135 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
136 Int32.TryParse(args["destination_x"].AsString(), out x);
137 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
138 Int32.TryParse(args["destination_y"].AsString(), out y);
139 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
140 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
141 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
142 regionname = args["destination_name"].ToString();
143 if (args.ContainsKey("teleport_flags") && args["teleport_flags"] != null)
144 teleportFlags = args["teleport_flags"].AsUInteger();
145
146 GridRegion destination = new GridRegion();
147 destination.RegionID = uuid;
148 destination.RegionLocX = x;
149 destination.RegionLocY = y;
150 destination.RegionName = regionname;
133 151
134 AgentCircuitData aCircuit = new AgentCircuitData(); 152 AgentCircuitData aCircuit = new AgentCircuitData();
135 try 153 try
@@ -146,15 +164,10 @@ namespace OpenSim.Server.Handlers.Simulation
146 164
147 OSDMap resp = new OSDMap(2); 165 OSDMap resp = new OSDMap(2);
148 string reason = String.Empty; 166 string reason = String.Empty;
149 uint teleportFlags = 0;
150 if (args.ContainsKey("teleport_flags"))
151 {
152 teleportFlags = args["teleport_flags"].AsUInteger();
153 }
154 167
155 // This is the meaning of POST agent 168 // This is the meaning of POST agent
156 //m_regionClient.AdjustUserInformation(aCircuit); 169 //m_regionClient.AdjustUserInformation(aCircuit);
157 bool result = m_SimulationService.CreateAgent(regionhandle, aCircuit, teleportFlags, out reason); 170 bool result = m_SimulationService.CreateAgent(destination, aCircuit, teleportFlags, out reason);
158 171
159 resp["reason"] = OSD.FromString(reason); 172 resp["reason"] = OSD.FromString(reason);
160 resp["success"] = OSD.FromBoolean(result); 173 resp["success"] = OSD.FromBoolean(result);
@@ -174,10 +187,24 @@ namespace OpenSim.Server.Handlers.Simulation
174 return; 187 return;
175 } 188 }
176 189
177 // retrieve the regionhandle 190 // retrieve the input arguments
178 ulong regionhandle = 0; 191 int x = 0, y = 0;
179 if (args["destination_handle"] != null) 192 UUID uuid = UUID.Zero;
180 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); 193 string regionname = string.Empty;
194 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
195 Int32.TryParse(args["destination_x"].AsString(), out x);
196 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
197 Int32.TryParse(args["destination_y"].AsString(), out y);
198 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
199 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
200 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
201 regionname = args["destination_name"].ToString();
202
203 GridRegion destination = new GridRegion();
204 destination.RegionID = uuid;
205 destination.RegionLocX = x;
206 destination.RegionLocY = y;
207 destination.RegionName = regionname;
181 208
182 string messageType; 209 string messageType;
183 if (args["message_type"] != null) 210 if (args["message_type"] != null)
@@ -206,7 +233,7 @@ namespace OpenSim.Server.Handlers.Simulation
206 233
207 //agent.Dump(); 234 //agent.Dump();
208 // This is one of the meanings of PUT agent 235 // This is one of the meanings of PUT agent
209 result = m_SimulationService.UpdateAgent(regionhandle, agent); 236 result = m_SimulationService.UpdateAgent(destination, agent);
210 237
211 } 238 }
212 else if ("AgentPosition".Equals(messageType)) 239 else if ("AgentPosition".Equals(messageType))
@@ -223,7 +250,7 @@ namespace OpenSim.Server.Handlers.Simulation
223 } 250 }
224 //agent.Dump(); 251 //agent.Dump();
225 // This is one of the meanings of PUT agent 252 // This is one of the meanings of PUT agent
226 result = m_SimulationService.UpdateAgent(regionhandle, agent); 253 result = m_SimulationService.UpdateAgent(destination, agent);
227 254
228 } 255 }
229 256
@@ -232,10 +259,13 @@ namespace OpenSim.Server.Handlers.Simulation
232 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead 259 //responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); ??? instead
233 } 260 }
234 261
235 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, ulong regionHandle) 262 protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, UUID regionID)
236 { 263 {
264 GridRegion destination = new GridRegion();
265 destination.RegionID = regionID;
266
237 IAgentData agent = null; 267 IAgentData agent = null;
238 bool result = m_SimulationService.RetrieveAgent(regionHandle, id, out agent); 268 bool result = m_SimulationService.RetrieveAgent(destination, id, out agent);
239 OSDMap map = null; 269 OSDMap map = null;
240 if (result) 270 if (result)
241 { 271 {
@@ -271,14 +301,17 @@ namespace OpenSim.Server.Handlers.Simulation
271 } 301 }
272 } 302 }
273 303
274 protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle) 304 protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, UUID regionID)
275 { 305 {
276 //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle); 306 //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle);
277 307
308 GridRegion destination = new GridRegion();
309 destination.RegionID = regionID;
310
278 if (action.Equals("release")) 311 if (action.Equals("release"))
279 m_SimulationService.ReleaseAgent(regionHandle, id, ""); 312 m_SimulationService.ReleaseAgent(destination, id, "");
280 else 313 else
281 m_SimulationService.CloseAgent(regionHandle, id); 314 m_SimulationService.CloseAgent(destination, id);
282 315
283 responsedata["int_response_code"] = HttpStatusCode.OK; 316 responsedata["int_response_code"] = HttpStatusCode.OK;
284 responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); 317 responsedata["str_response_string"] = "OpenSim agent " + id.ToString();
@@ -287,165 +320,4 @@ namespace OpenSim.Server.Handlers.Simulation
287 } 320 }
288 } 321 }
289 322
290 public class AgentGetHandler : BaseStreamHandler
291 {
292 // TODO: unused: private ISimulationService m_SimulationService;
293 // TODO: unused: private IAuthenticationService m_AuthenticationService;
294
295 public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) :
296 base("GET", "/agent")
297 {
298 // TODO: unused: m_SimulationService = service;
299 // TODO: unused: m_AuthenticationService = authentication;
300 }
301
302 public override byte[] Handle(string path, Stream request,
303 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
304 {
305 // Not implemented yet
306 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
307 return new byte[] { };
308 }
309 }
310
311 public class AgentPostHandler : BaseStreamHandler
312 {
313 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
314 private ISimulationService m_SimulationService;
315 private IAuthenticationService m_AuthenticationService;
316 // TODO: unused: private bool m_AllowForeignGuests;
317
318 public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) :
319 base("POST", "/agent")
320 {
321 m_SimulationService = service;
322 m_AuthenticationService = authentication;
323 // TODO: unused: m_AllowForeignGuests = foreignGuests;
324 }
325
326 public override byte[] Handle(string path, Stream request,
327 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
328 {
329 byte[] result = new byte[0];
330
331 UUID agentID;
332 string action;
333 ulong regionHandle;
334 if (!RestHandlerUtils.GetParams(path, out agentID, out regionHandle, out action))
335 {
336 m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path);
337 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
338 httpResponse.StatusDescription = "Invalid parameters for agent message " + path;
339
340 return result;
341 }
342
343 if (m_AuthenticationService != null)
344 {
345 // Authentication
346 string authority = string.Empty;
347 string authToken = string.Empty;
348 if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken))
349 {
350 m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
351 httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
352 return result;
353 }
354 // TODO: Rethink this
355 //if (!m_AuthenticationService.VerifyKey(agentID, authToken))
356 //{
357 // m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
358 // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
359 // return result;
360 //}
361 m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID);
362 }
363
364 OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength);
365 if (args == null)
366 {
367 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
368 httpResponse.StatusDescription = "Unable to retrieve data";
369 m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path);
370 return result;
371 }
372
373 // retrieve the regionhandle
374 ulong regionhandle = 0;
375 if (args["destination_handle"] != null)
376 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
377
378 AgentCircuitData aCircuit = new AgentCircuitData();
379 try
380 {
381 aCircuit.UnpackAgentCircuitData(args);
382 }
383 catch (Exception ex)
384 {
385 m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message);
386 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
387 httpResponse.StatusDescription = "Problems with data deserialization";
388 return result;
389 }
390
391 string reason = string.Empty;
392
393 // We need to clean up a few things in the user service before I can do this
394 //if (m_AllowForeignGuests)
395 // m_regionClient.AdjustUserInformation(aCircuit);
396
397 // Finally!
398 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, /*!!!*/0, out reason);
399
400 OSDMap resp = new OSDMap(1);
401
402 resp["success"] = OSD.FromBoolean(success);
403
404 httpResponse.StatusCode = (int)HttpStatusCode.OK;
405
406 return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp));
407 }
408 }
409
410 public class AgentPutHandler : BaseStreamHandler
411 {
412 // TODO: unused: private ISimulationService m_SimulationService;
413 // TODO: unused: private IAuthenticationService m_AuthenticationService;
414
415 public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) :
416 base("PUT", "/agent")
417 {
418 // TODO: unused: m_SimulationService = service;
419 // TODO: unused: m_AuthenticationService = authentication;
420 }
421
422 public override byte[] Handle(string path, Stream request,
423 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
424 {
425 // Not implemented yet
426 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
427 return new byte[] { };
428 }
429 }
430
431 public class AgentDeleteHandler : BaseStreamHandler
432 {
433 // TODO: unused: private ISimulationService m_SimulationService;
434 // TODO: unused: private IAuthenticationService m_AuthenticationService;
435
436 public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) :
437 base("DELETE", "/agent")
438 {
439 // TODO: unused: m_SimulationService = service;
440 // TODO: unused: m_AuthenticationService = authentication;
441 }
442
443 public override byte[] Handle(string path, Stream request,
444 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
445 {
446 // Not implemented yet
447 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
448 return new byte[] { };
449 }
450 }
451} 323}