diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Simulation')
-rw-r--r-- | OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | 575 |
1 files changed, 575 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs new file mode 100644 index 0000000..b1b2a30 --- /dev/null +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | |||
@@ -0,0 +1,575 @@ | |||
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.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | using Nini.Config; | ||
43 | |||
44 | namespace OpenSim.Services.Connectors.Simulation | ||
45 | { | ||
46 | public class SimulationServiceConnector : ISimulationService | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | //private GridRegion m_Region; | ||
51 | |||
52 | public SimulationServiceConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public SimulationServiceConnector(IConfigSource config) | ||
57 | { | ||
58 | //m_Region = region; | ||
59 | } | ||
60 | |||
61 | public IScene GetScene(ulong regionHandle) | ||
62 | { | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | #region Agents | ||
67 | |||
68 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) | ||
69 | { | ||
70 | reason = String.Empty; | ||
71 | |||
72 | if (destination == null) | ||
73 | { | ||
74 | reason = "Destination is null"; | ||
75 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); | ||
76 | return false; | ||
77 | } | ||
78 | |||
79 | // Eventually, we want to use a caps url instead of the agentID | ||
80 | string uri = string.Empty; | ||
81 | try | ||
82 | { | ||
83 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + aCircuit.AgentID + "/"; | ||
84 | } | ||
85 | catch (Exception e) | ||
86 | { | ||
87 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); | ||
88 | reason = e.Message; | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
93 | |||
94 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
95 | AgentCreateRequest.Method = "POST"; | ||
96 | AgentCreateRequest.ContentType = "application/json"; | ||
97 | AgentCreateRequest.Timeout = 10000; | ||
98 | //AgentCreateRequest.KeepAlive = false; | ||
99 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
100 | |||
101 | // Fill it in | ||
102 | OSDMap args = null; | ||
103 | try | ||
104 | { | ||
105 | args = aCircuit.PackAgentCircuitData(); | ||
106 | } | ||
107 | catch (Exception e) | ||
108 | { | ||
109 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
110 | } | ||
111 | // Add the input arguments | ||
112 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
113 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
114 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
115 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
116 | args["teleport_flags"] = OSD.FromString(flags.ToString()); | ||
117 | |||
118 | string strBuffer = ""; | ||
119 | byte[] buffer = new byte[1]; | ||
120 | try | ||
121 | { | ||
122 | strBuffer = OSDParser.SerializeJsonString(args); | ||
123 | Encoding str = Util.UTF8; | ||
124 | buffer = str.GetBytes(strBuffer); | ||
125 | |||
126 | } | ||
127 | catch (Exception e) | ||
128 | { | ||
129 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
130 | // ignore. buffer will be empty, caller should check. | ||
131 | } | ||
132 | |||
133 | Stream os = null; | ||
134 | try | ||
135 | { // send the Post | ||
136 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
137 | os = AgentCreateRequest.GetRequestStream(); | ||
138 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
139 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
140 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
141 | } | ||
142 | //catch (WebException ex) | ||
143 | catch | ||
144 | { | ||
145 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
146 | reason = "cannot contact remote region"; | ||
147 | return false; | ||
148 | } | ||
149 | finally | ||
150 | { | ||
151 | if (os != null) | ||
152 | os.Close(); | ||
153 | } | ||
154 | |||
155 | // Let's wait for the response | ||
156 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
157 | |||
158 | WebResponse webResponse = null; | ||
159 | StreamReader sr = null; | ||
160 | try | ||
161 | { | ||
162 | webResponse = AgentCreateRequest.GetResponse(); | ||
163 | if (webResponse == null) | ||
164 | { | ||
165 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | |||
170 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
171 | string response = sr.ReadToEnd().Trim(); | ||
172 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
173 | |||
174 | if (!String.IsNullOrEmpty(response)) | ||
175 | { | ||
176 | try | ||
177 | { | ||
178 | // we assume we got an OSDMap back | ||
179 | OSDMap r = Util.GetOSDMap(response); | ||
180 | bool success = r["success"].AsBoolean(); | ||
181 | reason = r["reason"].AsString(); | ||
182 | return success; | ||
183 | } | ||
184 | catch (NullReferenceException e) | ||
185 | { | ||
186 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
187 | |||
188 | // check for old style response | ||
189 | if (response.ToLower().StartsWith("true")) | ||
190 | return true; | ||
191 | |||
192 | return false; | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | catch (WebException ex) | ||
198 | { | ||
199 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
200 | // ignore, really | ||
201 | } | ||
202 | finally | ||
203 | { | ||
204 | if (sr != null) | ||
205 | sr.Close(); | ||
206 | } | ||
207 | |||
208 | return true; | ||
209 | } | ||
210 | |||
211 | public bool UpdateAgent(GridRegion destination, AgentData data) | ||
212 | { | ||
213 | return UpdateAgent(destination, (IAgentData)data); | ||
214 | } | ||
215 | |||
216 | public bool UpdateAgent(GridRegion destination, AgentPosition data) | ||
217 | { | ||
218 | return UpdateAgent(destination, (IAgentData)data); | ||
219 | } | ||
220 | |||
221 | private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) | ||
222 | { | ||
223 | // Eventually, we want to use a caps url instead of the agentID | ||
224 | string uri = string.Empty; | ||
225 | try | ||
226 | { | ||
227 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + cAgentData.AgentID + "/"; | ||
228 | } | ||
229 | catch (Exception e) | ||
230 | { | ||
231 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent update. Reason: " + e.Message); | ||
232 | return false; | ||
233 | } | ||
234 | //Console.WriteLine(" >>> DoAgentUpdateCall <<< " + uri); | ||
235 | |||
236 | HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
237 | ChildUpdateRequest.Method = "PUT"; | ||
238 | ChildUpdateRequest.ContentType = "application/json"; | ||
239 | ChildUpdateRequest.Timeout = 10000; | ||
240 | //ChildUpdateRequest.KeepAlive = false; | ||
241 | |||
242 | // Fill it in | ||
243 | OSDMap args = null; | ||
244 | try | ||
245 | { | ||
246 | args = cAgentData.Pack(); | ||
247 | } | ||
248 | catch (Exception e) | ||
249 | { | ||
250 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message); | ||
251 | } | ||
252 | // Add the input arguments | ||
253 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
254 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
255 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
256 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
257 | |||
258 | string strBuffer = ""; | ||
259 | byte[] buffer = new byte[1]; | ||
260 | try | ||
261 | { | ||
262 | strBuffer = OSDParser.SerializeJsonString(args); | ||
263 | Encoding str = Util.UTF8; | ||
264 | buffer = str.GetBytes(strBuffer); | ||
265 | |||
266 | } | ||
267 | catch (Exception e) | ||
268 | { | ||
269 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); | ||
270 | // ignore. buffer will be empty, caller should check. | ||
271 | } | ||
272 | |||
273 | Stream os = null; | ||
274 | try | ||
275 | { // send the Post | ||
276 | ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
277 | os = ChildUpdateRequest.GetRequestStream(); | ||
278 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
279 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri); | ||
280 | } | ||
281 | catch (WebException ex) | ||
282 | //catch | ||
283 | { | ||
284 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message); | ||
285 | |||
286 | return false; | ||
287 | } | ||
288 | finally | ||
289 | { | ||
290 | if (os != null) | ||
291 | os.Close(); | ||
292 | } | ||
293 | |||
294 | // Let's wait for the response | ||
295 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate"); | ||
296 | |||
297 | WebResponse webResponse = null; | ||
298 | StreamReader sr = null; | ||
299 | try | ||
300 | { | ||
301 | webResponse = ChildUpdateRequest.GetResponse(); | ||
302 | if (webResponse == null) | ||
303 | { | ||
304 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post"); | ||
305 | } | ||
306 | |||
307 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
308 | //reply = sr.ReadToEnd().Trim(); | ||
309 | sr.ReadToEnd().Trim(); | ||
310 | sr.Close(); | ||
311 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
312 | |||
313 | } | ||
314 | catch (WebException ex) | ||
315 | { | ||
316 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate {0}", ex.Message); | ||
317 | // ignore, really | ||
318 | } | ||
319 | finally | ||
320 | { | ||
321 | if (sr != null) | ||
322 | sr.Close(); | ||
323 | } | ||
324 | |||
325 | return true; | ||
326 | } | ||
327 | |||
328 | public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) | ||
329 | { | ||
330 | agent = null; | ||
331 | // Eventually, we want to use a caps url instead of the agentID | ||
332 | string uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + id + "/" + destination.RegionID.ToString() + "/"; | ||
333 | //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri); | ||
334 | |||
335 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
336 | request.Method = "GET"; | ||
337 | request.Timeout = 10000; | ||
338 | //request.Headers.Add("authorization", ""); // coming soon | ||
339 | |||
340 | HttpWebResponse webResponse = null; | ||
341 | string reply = string.Empty; | ||
342 | StreamReader sr = null; | ||
343 | try | ||
344 | { | ||
345 | webResponse = (HttpWebResponse)request.GetResponse(); | ||
346 | if (webResponse == null) | ||
347 | { | ||
348 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); | ||
349 | } | ||
350 | |||
351 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
352 | reply = sr.ReadToEnd().Trim(); | ||
353 | |||
354 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was " + reply); | ||
355 | |||
356 | } | ||
357 | catch (WebException ex) | ||
358 | { | ||
359 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message); | ||
360 | // ignore, really | ||
361 | return false; | ||
362 | } | ||
363 | finally | ||
364 | { | ||
365 | if (sr != null) | ||
366 | sr.Close(); | ||
367 | } | ||
368 | |||
369 | if (webResponse.StatusCode == HttpStatusCode.OK) | ||
370 | { | ||
371 | // we know it's jason | ||
372 | OSDMap args = Util.GetOSDMap(reply); | ||
373 | if (args == null) | ||
374 | { | ||
375 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: Error getting OSDMap from reply"); | ||
376 | return false; | ||
377 | } | ||
378 | |||
379 | agent = new CompleteAgentData(); | ||
380 | agent.Unpack(args); | ||
381 | return true; | ||
382 | } | ||
383 | |||
384 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode); | ||
385 | return false; | ||
386 | } | ||
387 | |||
388 | public bool ReleaseAgent(UUID origin, UUID id, string uri) | ||
389 | { | ||
390 | WebRequest request = WebRequest.Create(uri); | ||
391 | request.Method = "DELETE"; | ||
392 | request.Timeout = 10000; | ||
393 | |||
394 | StreamReader sr = null; | ||
395 | try | ||
396 | { | ||
397 | WebResponse webResponse = request.GetResponse(); | ||
398 | if (webResponse == null) | ||
399 | { | ||
400 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent"); | ||
401 | } | ||
402 | |||
403 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
404 | //reply = sr.ReadToEnd().Trim(); | ||
405 | sr.ReadToEnd().Trim(); | ||
406 | sr.Close(); | ||
407 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
408 | |||
409 | } | ||
410 | catch (WebException ex) | ||
411 | { | ||
412 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message); | ||
413 | return false; | ||
414 | } | ||
415 | finally | ||
416 | { | ||
417 | if (sr != null) | ||
418 | sr.Close(); | ||
419 | } | ||
420 | |||
421 | return true; | ||
422 | } | ||
423 | |||
424 | public bool CloseAgent(GridRegion destination, UUID id) | ||
425 | { | ||
426 | string uri = string.Empty; | ||
427 | try | ||
428 | { | ||
429 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/agent/" + id + "/" + destination.RegionID.ToString() + "/"; | ||
430 | } | ||
431 | catch (Exception e) | ||
432 | { | ||
433 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent close. Reason: " + e.Message); | ||
434 | return false; | ||
435 | } | ||
436 | |||
437 | //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri); | ||
438 | |||
439 | WebRequest request = WebRequest.Create(uri); | ||
440 | request.Method = "DELETE"; | ||
441 | request.Timeout = 10000; | ||
442 | |||
443 | StreamReader sr = null; | ||
444 | try | ||
445 | { | ||
446 | WebResponse webResponse = request.GetResponse(); | ||
447 | if (webResponse == null) | ||
448 | { | ||
449 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete "); | ||
450 | } | ||
451 | |||
452 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
453 | //reply = sr.ReadToEnd().Trim(); | ||
454 | sr.ReadToEnd().Trim(); | ||
455 | sr.Close(); | ||
456 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
457 | |||
458 | } | ||
459 | catch (WebException ex) | ||
460 | { | ||
461 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete {0}", ex.Message); | ||
462 | return false; | ||
463 | } | ||
464 | finally | ||
465 | { | ||
466 | if (sr != null) | ||
467 | sr.Close(); | ||
468 | } | ||
469 | |||
470 | return true; | ||
471 | } | ||
472 | |||
473 | #endregion Agents | ||
474 | |||
475 | #region Objects | ||
476 | |||
477 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
478 | { | ||
479 | string uri | ||
480 | = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + "/object/" + sog.UUID + "/"; | ||
481 | //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri); | ||
482 | |||
483 | WebRequest ObjectCreateRequest = WebRequest.Create(uri); | ||
484 | ObjectCreateRequest.Method = "POST"; | ||
485 | ObjectCreateRequest.ContentType = "application/json"; | ||
486 | ObjectCreateRequest.Timeout = 10000; | ||
487 | |||
488 | OSDMap args = new OSDMap(2); | ||
489 | args["sog"] = OSD.FromString(sog.ToXml2()); | ||
490 | args["extra"] = OSD.FromString(sog.ExtraToXmlString()); | ||
491 | string state = sog.GetStateSnapshot(); | ||
492 | if (state.Length > 0) | ||
493 | args["state"] = OSD.FromString(state); | ||
494 | // Add the input general arguments | ||
495 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
496 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
497 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
498 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
499 | |||
500 | string strBuffer = ""; | ||
501 | byte[] buffer = new byte[1]; | ||
502 | try | ||
503 | { | ||
504 | strBuffer = OSDParser.SerializeJsonString(args); | ||
505 | Encoding str = Util.UTF8; | ||
506 | buffer = str.GetBytes(strBuffer); | ||
507 | |||
508 | } | ||
509 | catch (Exception e) | ||
510 | { | ||
511 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
512 | // ignore. buffer will be empty, caller should check. | ||
513 | } | ||
514 | |||
515 | Stream os = null; | ||
516 | try | ||
517 | { // send the Post | ||
518 | ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
519 | os = ObjectCreateRequest.GetRequestStream(); | ||
520 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
521 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri); | ||
522 | } | ||
523 | catch (WebException ex) | ||
524 | { | ||
525 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message); | ||
526 | return false; | ||
527 | } | ||
528 | finally | ||
529 | { | ||
530 | if (os != null) | ||
531 | os.Close(); | ||
532 | } | ||
533 | |||
534 | // Let's wait for the response | ||
535 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
536 | |||
537 | StreamReader sr = null; | ||
538 | try | ||
539 | { | ||
540 | WebResponse webResponse = ObjectCreateRequest.GetResponse(); | ||
541 | if (webResponse == null) | ||
542 | { | ||
543 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post"); | ||
544 | return false; | ||
545 | } | ||
546 | |||
547 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
548 | //reply = sr.ReadToEnd().Trim(); | ||
549 | sr.ReadToEnd().Trim(); | ||
550 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); | ||
551 | |||
552 | } | ||
553 | catch (WebException ex) | ||
554 | { | ||
555 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message); | ||
556 | return false; | ||
557 | } | ||
558 | finally | ||
559 | { | ||
560 | if (sr != null) | ||
561 | sr.Close(); | ||
562 | } | ||
563 | |||
564 | return true; | ||
565 | } | ||
566 | |||
567 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
568 | { | ||
569 | // TODO, not that urgent | ||
570 | return false; | ||
571 | } | ||
572 | |||
573 | #endregion Objects | ||
574 | } | ||
575 | } | ||