aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Simulation
diff options
context:
space:
mode:
authorMelanie2011-01-06 19:08:15 +0000
committerMelanie2011-01-06 19:08:15 +0000
commitde4eaab5847b6c4c5eb4c8c07191b8c463d0b3ad (patch)
tree7b9865d97acfd441edb97d12ce8286eb48901cee /OpenSim/Services/Connectors/Simulation
parentFix god mode perms adjustment (diff)
parentMerge branch 'master' into cmickeyb (diff)
downloadopensim-SC-de4eaab5847b6c4c5eb4c8c07191b8c463d0b3ad.zip
opensim-SC-de4eaab5847b6c4c5eb4c8c07191b8c463d0b3ad.tar.gz
opensim-SC-de4eaab5847b6c4c5eb4c8c07191b8c463d0b3ad.tar.bz2
opensim-SC-de4eaab5847b6c4c5eb4c8c07191b8c463d0b3ad.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Services/Connectors/Simulation')
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs557
1 files changed, 111 insertions, 446 deletions
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index b877ca5..fbfc2dd 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -75,473 +75,191 @@ namespace OpenSim.Services.Connectors.Simulation
75 return "agent/"; 75 return "agent/";
76 } 76 }
77 77
78 /// <summary>
79 ///
80 /// </summary>
78 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) 81 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
79 { 82 {
80 HttpWebRequest AgentCreateRequest = null; 83 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start");
81 reason = String.Empty; 84
82
83 if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest))
84 {
85 string response = GetResponse(AgentCreateRequest, out reason);
86 bool success = true;
87 UnpackResponse(response, out success, out reason);
88 return success;
89 }
90
91 return false;
92 }
93
94
95 protected bool SendRequest(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason, out HttpWebRequest AgentCreateRequest)
96 {
97 reason = String.Empty; 85 reason = String.Empty;
98 AgentCreateRequest = null;
99
100 if (destination == null) 86 if (destination == null)
101 { 87 {
102 reason = "Destination is null";
103 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); 88 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
104 return false; 89 return false;
105 } 90 }
106 91
107 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/"; 92 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
108 93
109 AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
110 AgentCreateRequest.Method = "POST";
111 AgentCreateRequest.ContentType = "application/json";
112 AgentCreateRequest.Timeout = 10000;
113 //AgentCreateRequest.KeepAlive = false;
114 //AgentCreateRequest.Headers.Add("Authorization", authKey);
115
116 // Fill it in
117 OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags);
118 if (args == null)
119 return false;
120
121 string strBuffer = "";
122 byte[] buffer = new byte[1];
123 try 94 try
124 { 95 {
125 strBuffer = OSDParser.SerializeJsonString(args); 96 OSDMap args = aCircuit.PackAgentCircuitData();
126 Encoding str = Util.UTF8;
127 buffer = str.GetBytes(strBuffer);
128 97
129 } 98 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
130 catch (Exception e) 99 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
131 { 100 args["destination_name"] = OSD.FromString(destination.RegionName);
132 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); 101 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
133 // ignore. buffer will be empty, caller should check. 102 args["teleport_flags"] = OSD.FromString(flags.ToString());
134 }
135 103
136 Stream os = null; 104 OSDMap result = WebUtil.PostToService(uri,args);
137 try 105 if (result["Success"].AsBoolean())
138 { // send the Post 106 return true;
139 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send 107
140 os = AgentCreateRequest.GetRequestStream(); 108 reason = result["Message"] != null ? result["Message"].AsString() : "error";
141 os.Write(buffer, 0, strBuffer.Length); //Send it
142 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}",
143 uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY);
144 }
145 //catch (WebException ex)
146 catch
147 {
148 //m_log.ErrorFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
149 reason = "cannot contact remote region";
150 return false; 109 return false;
151 } 110 }
152 finally
153 {
154 if (os != null)
155 os.Close();
156 }
157
158 return true;
159 }
160
161 protected string GetResponse(HttpWebRequest AgentCreateRequest, out string reason)
162 {
163 // Let's wait for the response
164 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
165 reason = string.Empty;
166
167 WebResponse webResponse = null;
168 StreamReader sr = null;
169 string response = string.Empty;
170 try
171 {
172 webResponse = AgentCreateRequest.GetResponse();
173 if (webResponse == null)
174 {
175 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post");
176 }
177 else
178 {
179
180 sr = new StreamReader(webResponse.GetResponseStream());
181 response = sr.ReadToEnd().Trim();
182 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
183 }
184 }
185 catch (WebException ex)
186 {
187 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
188 reason = "Destination did not reply";
189 return string.Empty;
190 }
191 finally
192 {
193 if (sr != null)
194 sr.Close();
195 }
196
197 return response;
198 }
199
200 protected void UnpackResponse(string response, out bool result, out string reason)
201 {
202 result = true;
203 reason = string.Empty;
204 if (!String.IsNullOrEmpty(response))
205 {
206 try
207 {
208 // we assume we got an OSDMap back
209 OSDMap r = Util.GetOSDMap(response);
210 result = r["success"].AsBoolean();
211 reason = r["reason"].AsString();
212 }
213 catch (NullReferenceException e)
214 {
215 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
216
217 // check for old style response
218 if (response.ToLower().StartsWith("true"))
219 result = true;
220
221 result = false;
222 }
223 }
224 }
225
226 protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags)
227 {
228 OSDMap args = null;
229 try
230 {
231 args = aCircuit.PackAgentCircuitData();
232 }
233 catch (Exception e) 111 catch (Exception e)
234 { 112 {
235 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); 113 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
236 return null; 114 reason = e.Message;
237 } 115 }
238 116
239 // Add the input arguments 117 return false;
240 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
241 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
242 args["destination_name"] = OSD.FromString(destination.RegionName);
243 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
244 args["teleport_flags"] = OSD.FromString(flags.ToString());
245
246 return args;
247 } 118 }
248 119
120 /// <summary>
121 /// Send complete data about an agent in this region to a neighbor
122 /// </summary>
249 public bool UpdateAgent(GridRegion destination, AgentData data) 123 public bool UpdateAgent(GridRegion destination, AgentData data)
250 { 124 {
251 return UpdateAgent(destination, (IAgentData)data); 125 return UpdateAgent(destination, (IAgentData)data);
252 } 126 }
253 127
128 /// <summary>
129 /// Send updated position information about an agent in this region to a neighbor
130 /// This operation may be called very frequently if an avatar is moving about in
131 /// the region.
132 /// </summary>
254 public bool UpdateAgent(GridRegion destination, AgentPosition data) 133 public bool UpdateAgent(GridRegion destination, AgentPosition data)
255 { 134 {
135 // we need a better throttle for these
136 // return false;
137
256 return UpdateAgent(destination, (IAgentData)data); 138 return UpdateAgent(destination, (IAgentData)data);
257 } 139 }
258 140
141 /// <summary>
142 /// This is the worker function to send AgentData to a neighbor region
143 /// </summary>
259 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) 144 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
260 { 145 {
261 // Eventually, we want to use a caps url instead of the agentID 146 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: UpdateAgent start");
262 147
148 // Eventually, we want to use a caps url instead of the agentID
263 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/"; 149 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/";
264 150
265 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
266 ChildUpdateRequest.Method = "PUT";
267 ChildUpdateRequest.ContentType = "application/json";
268 ChildUpdateRequest.Timeout = 30000;
269 //ChildUpdateRequest.KeepAlive = false;
270
271 // Fill it in
272 OSDMap args = null;
273 try
274 {
275 args = cAgentData.Pack();
276 }
277 catch (Exception e)
278 {
279 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message);
280 }
281 // Add the input arguments
282 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
283 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
284 args["destination_name"] = OSD.FromString(destination.RegionName);
285 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
286
287 string strBuffer = "";
288 byte[] buffer = new byte[1];
289 try
290 {
291 strBuffer = OSDParser.SerializeJsonString(args);
292 Encoding str = Util.UTF8;
293 buffer = str.GetBytes(strBuffer);
294
295 }
296 catch (Exception e)
297 {
298 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
299 // ignore. buffer will be empty, caller should check.
300 }
301
302 Stream os = null;
303 try
304 { // send the Post
305 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
306 os = ChildUpdateRequest.GetRequestStream();
307 os.Write(buffer, 0, strBuffer.Length); //Send it
308 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri);
309 }
310 catch (WebException ex)
311 //catch
312 {
313 // m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message);
314
315 return false;
316 }
317 finally
318 {
319 if (os != null)
320 os.Close();
321 }
322
323 // Let's wait for the response
324 //m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate");
325
326 WebResponse webResponse = null;
327 StreamReader sr = null;
328 try 151 try
329 { 152 {
330 webResponse = ChildUpdateRequest.GetResponse(); 153 OSDMap args = cAgentData.Pack();
331 if (webResponse == null)
332 {
333 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post");
334 }
335 154
336 sr = new StreamReader(webResponse.GetResponseStream()); 155 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
337 //reply = sr.ReadToEnd().Trim(); 156 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
338 sr.ReadToEnd().Trim(); 157 args["destination_name"] = OSD.FromString(destination.RegionName);
339 sr.Close(); 158 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
340 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
341 159
160 OSDMap result = WebUtil.PutToService(uri,args);
161 return result["Success"].AsBoolean();
342 } 162 }
343 catch (WebException ex) 163 catch (Exception e)
344 {
345 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate from {0}: {1}", uri, ex.Message);
346 // ignore, really
347 }
348 finally
349 { 164 {
350 if (sr != null) 165 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
351 sr.Close();
352 } 166 }
353 167
354 return true; 168 return false;
355 } 169 }
356 170
171 /// <summary>
172 /// Not sure what sequence causes this function to be invoked. The only calling
173 /// path is through the GET method
174 /// </summary>
357 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) 175 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
358 { 176 {
359 IPEndPoint ext = destination.ExternalEndPoint; 177 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: RetrieveAgent start");
178
360 agent = null; 179 agent = null;
361 if (ext == null) return false; 180
362 // Eventually, we want to use a caps url instead of the agentID 181 // Eventually, we want to use a caps url instead of the agentID
363 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 182 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
364 183
365 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
366 request.Method = "GET";
367 request.Timeout = 10000;
368 //request.Headers.Add("authorization", ""); // coming soon
369
370 HttpWebResponse webResponse = null;
371 string reply = string.Empty;
372 StreamReader sr = null;
373 try 184 try
374 { 185 {
375 webResponse = (HttpWebResponse)request.GetResponse(); 186 OSDMap result = WebUtil.GetFromService(uri);
376 if (webResponse == null) 187 if (result["Success"].AsBoolean())
377 { 188 {
378 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); 189 // OSDMap args = Util.GetOSDMap(result["_RawResult"].AsString());
190 OSDMap args = (OSDMap)result["_Result"];
191 if (args != null)
192 {
193 agent = new CompleteAgentData();
194 agent.Unpack(args);
195 return true;
196 }
379 } 197 }
380
381 sr = new StreamReader(webResponse.GetResponseStream());
382 reply = sr.ReadToEnd().Trim();
383
384
385 } 198 }
386 catch (WebException ex) 199 catch (Exception e)
387 {
388 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message);
389 // ignore, really
390 return false;
391 }
392 finally
393 {
394 if (sr != null)
395 sr.Close();
396 }
397
398 if (webResponse.StatusCode == HttpStatusCode.OK)
399 { 200 {
400 // we know it's jason 201 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
401 OSDMap args = Util.GetOSDMap(reply);
402 if (args == null)
403 {
404 return false;
405 }
406
407 agent = new CompleteAgentData();
408 agent.Unpack(args);
409 return true;
410 } 202 }
411 203
412 return false; 204 return false;
413 } 205 }
414 206
207 /// <summary>
208 /// </summary>
415 public bool QueryAccess(GridRegion destination, UUID id) 209 public bool QueryAccess(GridRegion destination, UUID id)
416 { 210 {
211 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: QueryAccess start");
212
417 IPEndPoint ext = destination.ExternalEndPoint; 213 IPEndPoint ext = destination.ExternalEndPoint;
418 if (ext == null) return false; 214 if (ext == null) return false;
215
419 // Eventually, we want to use a caps url instead of the agentID 216 // Eventually, we want to use a caps url instead of the agentID
420 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 217 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
421 218
422 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
423 request.Method = "QUERYACCESS";
424 request.Timeout = 10000;
425 //request.Headers.Add("authorization", ""); // coming soon
426
427 HttpWebResponse webResponse = null;
428 string reply = string.Empty;
429 StreamReader sr = null;
430 try 219 try
431 { 220 {
432 webResponse = (HttpWebResponse)request.GetResponse(); 221 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"QUERYACCESS",10000);
433 if (webResponse == null) 222 return result["Success"].AsBoolean();
434 {
435 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent query ");
436 }
437
438 sr = new StreamReader(webResponse.GetResponseStream());
439 reply = sr.ReadToEnd().Trim();
440
441
442 } 223 }
443 catch (WebException ex) 224 catch (Exception e)
444 {
445 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent query {0}", ex.Message);
446 // ignore, really
447 return false;
448 }
449 finally
450 { 225 {
451 if (sr != null) 226 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcess failed with exception; {0}",e.ToString());
452 sr.Close();
453 } 227 }
454 228
455 if (webResponse.StatusCode == HttpStatusCode.OK)
456 {
457 try
458 {
459 bool result;
460
461 result = bool.Parse(reply);
462
463 return result;
464 }
465 catch
466 {
467 return false;
468 }
469 }
470
471 return false; 229 return false;
472 } 230 }
473 231
232 /// <summary>
233 /// </summary>
474 public bool ReleaseAgent(UUID origin, UUID id, string uri) 234 public bool ReleaseAgent(UUID origin, UUID id, string uri)
475 { 235 {
476 WebRequest request = WebRequest.Create(uri); 236 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ReleaseAgent start");
477 request.Method = "DELETE";
478 request.Timeout = 10000;
479 237
480 StreamReader sr = null;
481 try 238 try
482 { 239 {
483 WebResponse webResponse = request.GetResponse(); 240 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
484 if (webResponse == null)
485 {
486 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent");
487 }
488
489 sr = new StreamReader(webResponse.GetResponseStream());
490 //reply = sr.ReadToEnd().Trim();
491 sr.ReadToEnd().Trim();
492 sr.Close();
493 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
494
495 }
496 catch (WebException ex)
497 {
498 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message);
499 return false;
500 } 241 }
501 finally 242 catch (Exception e)
502 { 243 {
503 if (sr != null) 244 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] ReleaseAgent failed with exception; {0}",e.ToString());
504 sr.Close();
505 } 245 }
506 246
507 return true; 247 return true;
508 } 248 }
509 249
510 private bool CloseAgent(GridRegion destination, UUID id, bool ChildOnly) 250 private bool CloseAgent(GridRegion destination, UUID id, bool ChildOnly)
511 { 251 {
512 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 252 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CloseAgent start");
513 253
514 WebRequest request = WebRequest.Create(uri); 254 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
515 request.Method = "DELETE";
516 if (ChildOnly)
517 request.Method += "CHILD";
518 request.Timeout = 10000;
519 255
520 StreamReader sr = null;
521 try 256 try
522 { 257 {
523 WebResponse webResponse = request.GetResponse(); 258 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
524 if (webResponse == null)
525 {
526 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete ");
527 }
528
529 sr = new StreamReader(webResponse.GetResponseStream());
530 //reply = sr.ReadToEnd().Trim();
531 sr.ReadToEnd().Trim();
532 sr.Close();
533 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
534
535 }
536 catch (WebException ex)
537 {
538 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete from {0}: {1}", destination.RegionName, ex.Message);
539 return false;
540 } 259 }
541 finally 260 catch (Exception e)
542 { 261 {
543 if (sr != null) 262 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CloseAgent failed with exception; {0}",e.ToString());
544 sr.Close();
545 } 263 }
546 264
547 return true; 265 return true;
@@ -566,99 +284,46 @@ namespace OpenSim.Services.Connectors.Simulation
566 return "object/"; 284 return "object/";
567 } 285 }
568 286
287 /// <summary>
288 ///
289 /// </summary>
569 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) 290 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
570 { 291 {
571 IPEndPoint ext = destination.ExternalEndPoint; 292 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateObject start");
572 if (ext == null) return false;
573 string uri
574 = destination.ServerURI + ObjectPath() + sog.UUID + "/";
575 //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri);
576
577 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
578 ObjectCreateRequest.Method = "POST";
579 ObjectCreateRequest.ContentType = "application/json";
580 ObjectCreateRequest.Timeout = 10000;
581
582 OSDMap args = new OSDMap(2);
583 args["sog"] = OSD.FromString(sog.ToXml2());
584 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
585 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
586 string state = sog.GetStateSnapshot();
587 if (state.Length > 0)
588 args["state"] = OSD.FromString(state);
589 // Add the input general arguments
590 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
591 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
592 args["destination_name"] = OSD.FromString(destination.RegionName);
593 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
594
595 string strBuffer = "";
596 byte[] buffer = new byte[1];
597 try
598 {
599 strBuffer = OSDParser.SerializeJsonString(args);
600 Encoding str = Util.UTF8;
601 buffer = str.GetBytes(strBuffer);
602 293
603 } 294 string uri = destination.ServerURI + ObjectPath() + sog.UUID + "/";
604 catch (Exception e)
605 {
606 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message);
607 // ignore. buffer will be empty, caller should check.
608 }
609 295
610 Stream os = null;
611 try 296 try
612 { // send the Post
613 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
614 os = ObjectCreateRequest.GetRequestStream();
615 os.Write(buffer, 0, strBuffer.Length); //Send it
616 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri);
617 }
618 catch (WebException ex)
619 {
620 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message);
621 return false;
622 }
623 finally
624 { 297 {
625 if (os != null) 298 OSDMap args = new OSDMap(2);
626 os.Close();
627 }
628 299
629 // Let's wait for the response 300 args["sog"] = OSD.FromString(sog.ToXml2());
630 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); 301 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
302 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
631 303
632 StreamReader sr = null; 304 string state = sog.GetStateSnapshot();
633 try 305 if (state.Length > 0)
634 { 306 args["state"] = OSD.FromString(state);
635 WebResponse webResponse = ObjectCreateRequest.GetResponse();
636 if (webResponse == null)
637 {
638 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post");
639 return false;
640 }
641 307
642 sr = new StreamReader(webResponse.GetResponseStream()); 308 // Add the input general arguments
643 //reply = sr.ReadToEnd().Trim(); 309 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
644 sr.ReadToEnd().Trim(); 310 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
645 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); 311 args["destination_name"] = OSD.FromString(destination.RegionName);
312 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
646 313
314 OSDMap result = WebUtil.PostToService(uri,args);
647 } 315 }
648 catch (WebException ex) 316 catch (Exception e)
649 {
650 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message);
651 return false;
652 }
653 finally
654 { 317 {
655 if (sr != null) 318 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CreateObject failed with exception; {0}",e.ToString());
656 sr.Close();
657 } 319 }
658 320
659 return true; 321 return true;
660 } 322 }
661 323
324 /// <summary>
325 ///
326 /// </summary>
662 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) 327 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
663 { 328 {
664 // TODO, not that urgent 329 // TODO, not that urgent