aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Clients
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Clients')
-rw-r--r--OpenSim/Framework/Communications/Clients/AuthClient.cs151
-rw-r--r--OpenSim/Framework/Communications/Clients/GridClient.cs392
-rw-r--r--OpenSim/Framework/Communications/Clients/InventoryClient.cs79
-rw-r--r--OpenSim/Framework/Communications/Clients/RegionClient.cs755
4 files changed, 0 insertions, 1377 deletions
diff --git a/OpenSim/Framework/Communications/Clients/AuthClient.cs b/OpenSim/Framework/Communications/Clients/AuthClient.cs
deleted file mode 100644
index adae637..0000000
--- a/OpenSim/Framework/Communications/Clients/AuthClient.cs
+++ /dev/null
@@ -1,151 +0,0 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using Nwc.XmlRpc;
32using OpenMetaverse;
33
34namespace OpenSim.Framework.Communications.Clients
35{
36 public class AuthClient
37 {
38 public static string GetNewKey(string authurl, UUID userID, UUID authToken)
39 {
40 //Hashtable keyParams = new Hashtable();
41 //keyParams["user_id"] = userID;
42 //keyParams["auth_token"] = authKey;
43
44 List<string> SendParams = new List<string>();
45 SendParams.Add(userID.ToString());
46 SendParams.Add(authToken.ToString());
47
48 XmlRpcRequest request = new XmlRpcRequest("hg_new_auth_key", SendParams);
49 XmlRpcResponse reply;
50 try
51 {
52 reply = request.Send(authurl, 6000);
53 }
54 catch (Exception e)
55 {
56 System.Console.WriteLine("[HGrid]: Failed to get new key. Reason: " + e.Message);
57 return string.Empty;
58 }
59
60 if (!reply.IsFault)
61 {
62 string newKey = string.Empty;
63 if (reply.Value != null)
64 newKey = (string)reply.Value;
65
66 return newKey;
67 }
68 else
69 {
70 System.Console.WriteLine("[HGrid]: XmlRpc request to get auth key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
71 return string.Empty;
72 }
73
74 }
75
76 public static bool VerifyKey(string authurl, UUID userID, string authKey)
77 {
78 List<string> SendParams = new List<string>();
79 SendParams.Add(userID.ToString());
80 SendParams.Add(authKey);
81
82 System.Console.WriteLine("[HGrid]: Verifying user key with authority " + authurl);
83
84 XmlRpcRequest request = new XmlRpcRequest("hg_verify_auth_key", SendParams);
85 XmlRpcResponse reply;
86 try
87 {
88 reply = request.Send(authurl, 10000);
89 }
90 catch (Exception e)
91 {
92 System.Console.WriteLine("[HGrid]: Failed to verify key. Reason: " + e.Message);
93 return false;
94 }
95
96 if (reply != null)
97 {
98 if (!reply.IsFault)
99 {
100 bool success = false;
101 if (reply.Value != null)
102 success = (bool)reply.Value;
103
104 return success;
105 }
106 else
107 {
108 System.Console.WriteLine("[HGrid]: XmlRpc request to verify key failed with message {0}" + reply.FaultString + ", code " + reply.FaultCode);
109 return false;
110 }
111 }
112 else
113 {
114 System.Console.WriteLine("[HGrid]: XmlRpc request to verify key returned null reply");
115 return false;
116 }
117 }
118
119 public static bool VerifySession(string authurl, UUID userID, UUID sessionID)
120 {
121 Hashtable requestData = new Hashtable();
122 requestData["avatar_uuid"] = userID.ToString();
123 requestData["session_id"] = sessionID.ToString();
124 ArrayList SendParams = new ArrayList();
125 SendParams.Add(requestData);
126 XmlRpcRequest UserReq = new XmlRpcRequest("check_auth_session", SendParams);
127 XmlRpcResponse UserResp = null;
128 try
129 {
130 UserResp = UserReq.Send(authurl, 3000);
131 }
132 catch (Exception e)
133 {
134 System.Console.WriteLine("[Session Auth]: VerifySession XmlRpc: " + e.Message);
135 return false;
136 }
137
138 Hashtable responseData = (Hashtable)UserResp.Value;
139 if (responseData != null && responseData.ContainsKey("auth_session") && responseData["auth_session"] != null && responseData["auth_session"].ToString() == "TRUE")
140 {
141 //System.Console.WriteLine("[Authorization]: userserver reported authorized session for user " + userID);
142 return true;
143 }
144 else
145 {
146 //System.Console.WriteLine("[Authorization]: userserver reported unauthorized session for user " + userID);
147 return false;
148 }
149 }
150 }
151}
diff --git a/OpenSim/Framework/Communications/Clients/GridClient.cs b/OpenSim/Framework/Communications/Clients/GridClient.cs
deleted file mode 100644
index 4836556..0000000
--- a/OpenSim/Framework/Communications/Clients/GridClient.cs
+++ /dev/null
@@ -1,392 +0,0 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33
34using log4net;
35using OpenMetaverse;
36using Nwc.XmlRpc;
37
38namespace OpenSim.Framework.Communications.Clients
39{
40 public class GridClient
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 public bool RegisterRegion(
45 string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out bool forcefulBanLines)
46 {
47 m_log.InfoFormat(
48 "[GRID CLIENT]: Registering region {0} with grid at {1}", regionInfo.RegionName, gridServerURL);
49
50 forcefulBanLines = true;
51
52 Hashtable GridParams = new Hashtable();
53 // Login / Authentication
54
55 GridParams["authkey"] = sendKey;
56 GridParams["recvkey"] = receiveKey;
57 GridParams["UUID"] = regionInfo.RegionID.ToString();
58 GridParams["sim_ip"] = regionInfo.ExternalHostName;
59 GridParams["sim_port"] = regionInfo.InternalEndPoint.Port.ToString();
60 GridParams["region_locx"] = regionInfo.RegionLocX.ToString();
61 GridParams["region_locy"] = regionInfo.RegionLocY.ToString();
62 GridParams["sim_name"] = regionInfo.RegionName;
63 GridParams["http_port"] = regionInfo.HttpPort.ToString();
64 GridParams["remoting_port"] = ConfigSettings.DefaultRegionRemotingPort.ToString();
65 GridParams["map-image-id"] = regionInfo.RegionSettings.TerrainImageID.ToString();
66 GridParams["originUUID"] = regionInfo.originRegionID.ToString();
67 GridParams["server_uri"] = regionInfo.ServerURI;
68 GridParams["region_secret"] = regionInfo.regionSecret;
69 GridParams["major_interface_version"] = VersionInfo.MajorInterfaceVersion.ToString();
70
71 if (regionInfo.MasterAvatarAssignedUUID != UUID.Zero)
72 GridParams["master_avatar_uuid"] = regionInfo.MasterAvatarAssignedUUID.ToString();
73 else
74 GridParams["master_avatar_uuid"] = regionInfo.EstateSettings.EstateOwner.ToString();
75
76 // Package into an XMLRPC Request
77 ArrayList SendParams = new ArrayList();
78 SendParams.Add(GridParams);
79
80 // Send Request
81 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
82 XmlRpcResponse GridResp;
83
84 try
85 {
86 // The timeout should always be significantly larger than the timeout for the grid server to request
87 // the initial status of the region before confirming registration.
88 GridResp = GridReq.Send(gridServerURL, 90000);
89 }
90 catch (Exception e)
91 {
92 Exception e2
93 = new Exception(
94 String.Format(
95 "Unable to register region with grid at {0}. Grid service not running?",
96 gridServerURL),
97 e);
98
99 throw e2;
100 }
101
102 Hashtable GridRespData = (Hashtable)GridResp.Value;
103 // Hashtable griddatahash = GridRespData;
104
105 // Process Response
106 if (GridRespData.ContainsKey("error"))
107 {
108 string errorstring = (string)GridRespData["error"];
109
110 Exception e = new Exception(
111 String.Format("Unable to connect to grid at {0}: {1}", gridServerURL, errorstring));
112
113 throw e;
114 }
115 else
116 {
117 // m_knownRegions = RequestNeighbours(regionInfo.RegionLocX, regionInfo.RegionLocY);
118 if (GridRespData.ContainsKey("allow_forceful_banlines"))
119 {
120 if ((string)GridRespData["allow_forceful_banlines"] != "TRUE")
121 {
122 forcefulBanLines = false;
123 }
124 }
125
126 }
127 return true;
128 }
129
130 public bool DeregisterRegion(string gridServerURL, string sendKey, string receiveKey, RegionInfo regionInfo, out string errorMsg)
131 {
132 errorMsg = "";
133 Hashtable GridParams = new Hashtable();
134
135 GridParams["UUID"] = regionInfo.RegionID.ToString();
136
137 // Package into an XMLRPC Request
138 ArrayList SendParams = new ArrayList();
139 SendParams.Add(GridParams);
140
141 // Send Request
142 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_after_region_moved", SendParams);
143 XmlRpcResponse GridResp = null;
144
145 try
146 {
147 GridResp = GridReq.Send(gridServerURL, 10000);
148 }
149 catch (Exception e)
150 {
151 Exception e2
152 = new Exception(
153 String.Format(
154 "Unable to deregister region with grid at {0}. Grid service not running?",
155 gridServerURL),
156 e);
157
158 throw e2;
159 }
160
161 Hashtable GridRespData = (Hashtable)GridResp.Value;
162
163 // Hashtable griddatahash = GridRespData;
164
165 // Process Response
166 if (GridRespData != null && GridRespData.ContainsKey("error"))
167 {
168 errorMsg = (string)GridRespData["error"];
169 return false;
170 }
171
172 return true;
173 }
174
175 public bool RequestNeighborInfo(
176 string gridServerURL, string sendKey, string receiveKey, UUID regionUUID,
177 out RegionInfo regionInfo, out string errorMsg)
178 {
179 // didn't find it so far, we have to go the long way
180 regionInfo = null;
181 errorMsg = string.Empty;
182 Hashtable requestData = new Hashtable();
183 requestData["region_UUID"] = regionUUID.ToString();
184 requestData["authkey"] = sendKey;
185 ArrayList SendParams = new ArrayList();
186 SendParams.Add(requestData);
187 XmlRpcRequest gridReq = new XmlRpcRequest("simulator_data_request", SendParams);
188 XmlRpcResponse gridResp = null;
189
190 try
191 {
192 gridResp = gridReq.Send(gridServerURL, 3000);
193 }
194 catch (Exception e)
195 {
196 errorMsg = e.Message;
197 return false;
198 }
199
200 Hashtable responseData = (Hashtable)gridResp.Value;
201
202 if (responseData.ContainsKey("error"))
203 {
204 errorMsg = (string)responseData["error"];
205 return false; ;
206 }
207
208 regionInfo = BuildRegionInfo(responseData, String.Empty);
209
210 return true;
211 }
212
213 public bool RequestNeighborInfo(
214 string gridServerURL, string sendKey, string receiveKey, ulong regionHandle,
215 out RegionInfo regionInfo, out string errorMsg)
216 {
217 // didn't find it so far, we have to go the long way
218 regionInfo = null;
219 errorMsg = string.Empty;
220
221 try
222 {
223 Hashtable requestData = new Hashtable();
224 requestData["region_handle"] = regionHandle.ToString();
225 requestData["authkey"] = sendKey;
226 ArrayList SendParams = new ArrayList();
227 SendParams.Add(requestData);
228 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
229 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
230
231 Hashtable responseData = (Hashtable)GridResp.Value;
232
233 if (responseData.ContainsKey("error"))
234 {
235 errorMsg = (string)responseData["error"];
236 return false;
237 }
238
239 uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
240 uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
241 string externalHostName = (string)responseData["sim_ip"];
242 uint simPort = Convert.ToUInt32(responseData["sim_port"]);
243 string regionName = (string)responseData["region_name"];
244 UUID regionID = new UUID((string)responseData["region_UUID"]);
245 uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
246
247 uint httpPort = 9000;
248 if (responseData.ContainsKey("http_port"))
249 {
250 httpPort = Convert.ToUInt32((string)responseData["http_port"]);
251 }
252
253 // Ok, so this is definitively the wrong place to do this, way too hard coded, but it doesn't seem we GET this info?
254
255 string simURI = "http://" + externalHostName + ":" + simPort;
256
257 // string externalUri = (string) responseData["sim_uri"];
258
259 //IPEndPoint neighbourInternalEndPoint = new IPEndPoint(IPAddress.Parse(internalIpStr), (int) port);
260 regionInfo = RegionInfo.Create(regionID, regionName, regX, regY, externalHostName, httpPort, simPort, remotingPort, simURI);
261 }
262 catch (Exception e)
263 {
264 errorMsg = e.Message;
265 return false;
266 }
267
268 return true;
269 }
270
271 public bool RequestClosestRegion(
272 string gridServerURL, string sendKey, string receiveKey, string regionName,
273 out RegionInfo regionInfo, out string errorMsg)
274 {
275 regionInfo = null;
276 errorMsg = string.Empty;
277 try
278 {
279 Hashtable requestData = new Hashtable();
280 requestData["region_name_search"] = regionName;
281 requestData["authkey"] = sendKey;
282 ArrayList SendParams = new ArrayList();
283 SendParams.Add(requestData);
284 XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
285 XmlRpcResponse GridResp = GridReq.Send(gridServerURL, 3000);
286
287 Hashtable responseData = (Hashtable)GridResp.Value;
288
289 if (responseData.ContainsKey("error"))
290 {
291 errorMsg = (string)responseData["error"];
292 return false;
293 }
294
295 regionInfo = BuildRegionInfo(responseData, "");
296
297 }
298 catch (Exception e)
299 {
300 errorMsg = e.Message;
301 return false;
302 }
303 return true;
304 }
305
306 /// <summary>
307 /// Performs a XML-RPC query against the grid server returning mapblock information in the specified coordinates
308 /// </summary>
309 /// <remarks>REDUNDANT - OGS1 is to be phased out in favour of OGS2</remarks>
310 /// <param name="minX">Minimum X value</param>
311 /// <param name="minY">Minimum Y value</param>
312 /// <param name="maxX">Maximum X value</param>
313 /// <param name="maxY">Maximum Y value</param>
314 /// <returns>Hashtable of hashtables containing map data elements</returns>
315 public bool MapBlockQuery(
316 string gridServerURL, int minX, int minY, int maxX, int maxY, out Hashtable respData, out string errorMsg)
317 {
318 respData = new Hashtable();
319 errorMsg = string.Empty;
320
321 Hashtable param = new Hashtable();
322 param["xmin"] = minX;
323 param["ymin"] = minY;
324 param["xmax"] = maxX;
325 param["ymax"] = maxY;
326 IList parameters = new ArrayList();
327 parameters.Add(param);
328
329 try
330 {
331 XmlRpcRequest req = new XmlRpcRequest("map_block", parameters);
332 XmlRpcResponse resp = req.Send(gridServerURL, 10000);
333 respData = (Hashtable)resp.Value;
334 return true;
335 }
336 catch (Exception e)
337 {
338 errorMsg = e.Message;
339 return false;
340 }
341 }
342
343 public bool SearchRegionByName(string gridServerURL, IList parameters, out Hashtable respData, out string errorMsg)
344 {
345 respData = null;
346 errorMsg = string.Empty;
347 try
348 {
349 XmlRpcRequest request = new XmlRpcRequest("search_for_region_by_name", parameters);
350 XmlRpcResponse resp = request.Send(gridServerURL, 10000);
351 respData = (Hashtable)resp.Value;
352 if (respData != null && respData.Contains("faultCode"))
353 {
354 errorMsg = (string)respData["faultString"];
355 return false;
356 }
357
358 return true;
359 }
360 catch (Exception e)
361 {
362 errorMsg = e.Message;
363 return false;
364 }
365 }
366
367 public RegionInfo BuildRegionInfo(Hashtable responseData, string prefix)
368 {
369 uint regX = Convert.ToUInt32((string)responseData[prefix + "region_locx"]);
370 uint regY = Convert.ToUInt32((string)responseData[prefix + "region_locy"]);
371 string internalIpStr = (string)responseData[prefix + "sim_ip"];
372 uint port = Convert.ToUInt32(responseData[prefix + "sim_port"]);
373
374 IPEndPoint neighbourInternalEndPoint = new IPEndPoint(Util.GetHostFromDNS(internalIpStr), (int)port);
375
376 RegionInfo regionInfo = new RegionInfo(regX, regY, neighbourInternalEndPoint, internalIpStr);
377 regionInfo.RemotingPort = Convert.ToUInt32((string)responseData[prefix + "remoting_port"]);
378 regionInfo.RemotingAddress = internalIpStr;
379
380 if (responseData.ContainsKey(prefix + "http_port"))
381 {
382 regionInfo.HttpPort = Convert.ToUInt32((string)responseData[prefix + "http_port"]);
383 }
384
385 regionInfo.RegionID = new UUID((string)responseData[prefix + "region_UUID"]);
386 regionInfo.RegionName = (string)responseData[prefix + "region_name"];
387
388 regionInfo.RegionSettings.TerrainImageID = new UUID((string)responseData[prefix + "map_UUID"]);
389 return regionInfo;
390 }
391 }
392}
diff --git a/OpenSim/Framework/Communications/Clients/InventoryClient.cs b/OpenSim/Framework/Communications/Clients/InventoryClient.cs
deleted file mode 100644
index e4f5e2a..0000000
--- a/OpenSim/Framework/Communications/Clients/InventoryClient.cs
+++ /dev/null
@@ -1,79 +0,0 @@
1/**
2 * Copyright (c), Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29using System;
30using OpenSim.Framework.Servers;
31using OpenSim.Framework.Servers.HttpServer;
32
33using OpenMetaverse;
34
35namespace OpenSim.Framework.Communications.Clients
36{
37 public class InventoryClient
38 {
39 private string ServerURL;
40
41 public InventoryClient(string url)
42 {
43 ServerURL = url;
44 }
45
46 public void GetInventoryItemAsync(InventoryItemBase item, ReturnResponse<InventoryItemBase> callBack)
47 {
48 System.Console.WriteLine("[HGrid] GetInventory from " + ServerURL);
49 try
50 {
51 RestSessionObjectPosterResponse<InventoryItemBase, InventoryItemBase> requester
52 = new RestSessionObjectPosterResponse<InventoryItemBase, InventoryItemBase>();
53 requester.ResponseCallback = callBack;
54
55 requester.BeginPostObject(ServerURL + "/GetItem/", item, string.Empty, string.Empty);
56 }
57 catch (Exception e)
58 {
59 System.Console.WriteLine("[HGrid]: Exception posting to inventory: " + e);
60 }
61 }
62
63 public InventoryItemBase GetInventoryItem(InventoryItemBase item)
64 {
65 System.Console.WriteLine("[HGrid] GetInventory " + item.ID + " from " + ServerURL);
66 try
67 {
68 item = SynchronousRestSessionObjectPoster<Guid, InventoryItemBase>.BeginPostObject("POST", ServerURL + "/GetItem/", item.ID.Guid, "", "");
69 return item;
70 }
71 catch (Exception e)
72 {
73 System.Console.WriteLine("[HGrid]: Exception posting to inventory: " + e);
74 }
75 return null;
76 }
77
78 }
79}
diff --git a/OpenSim/Framework/Communications/Clients/RegionClient.cs b/OpenSim/Framework/Communications/Clients/RegionClient.cs
deleted file mode 100644
index ee7dec8..0000000
--- a/OpenSim/Framework/Communications/Clients/RegionClient.cs
+++ /dev/null
@@ -1,755 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34
35using OpenMetaverse;
36using OpenMetaverse.StructuredData;
37
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39
40using log4net;
41
42namespace OpenSim.Framework.Communications.Clients
43{
44 public class RegionClient
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 public bool DoCreateChildAgentCall(GridRegion region, AgentCircuitData aCircuit, string authKey, uint teleportFlags, out string reason)
49 {
50 reason = String.Empty;
51
52 // Eventually, we want to use a caps url instead of the agentID
53 string uri = string.Empty;
54 try
55 {
56 uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
57 }
58 catch (Exception e)
59 {
60 m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent create. Reason: " + e.Message);
61 reason = e.Message;
62 return false;
63 }
64
65 //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
66
67 HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
68 AgentCreateRequest.Method = "POST";
69 AgentCreateRequest.ContentType = "application/json";
70 AgentCreateRequest.Timeout = 10000;
71 //AgentCreateRequest.KeepAlive = false;
72 AgentCreateRequest.Headers.Add("Authorization", authKey);
73
74 // Fill it in
75 OSDMap args = null;
76 try
77 {
78 args = aCircuit.PackAgentCircuitData();
79 }
80 catch (Exception e)
81 {
82 m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
83 }
84 // Add the regionhandle of the destination region
85 ulong regionHandle = GetRegionHandle(region.RegionHandle);
86 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
87 args["teleport_flags"] = OSD.FromString(teleportFlags.ToString());
88
89 string strBuffer = "";
90 byte[] buffer = new byte[1];
91 try
92 {
93 strBuffer = OSDParser.SerializeJsonString(args);
94 Encoding str = Util.UTF8;
95 buffer = str.GetBytes(strBuffer);
96
97 }
98 catch (Exception e)
99 {
100 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
101 // ignore. buffer will be empty, caller should check.
102 }
103
104 Stream os = null;
105 try
106 { // send the Post
107 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
108 os = AgentCreateRequest.GetRequestStream();
109 os.Write(buffer, 0, strBuffer.Length); //Send it
110 //m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
111 }
112 //catch (WebException ex)
113 catch
114 {
115 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
116 reason = "cannot contact remote region";
117 return false;
118 }
119 finally
120 {
121 if (os != null)
122 os.Close();
123 }
124
125 // Let's wait for the response
126 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
127
128 WebResponse webResponse = null;
129 StreamReader sr = null;
130 try
131 {
132 webResponse = AgentCreateRequest.GetResponse();
133 if (webResponse == null)
134 {
135 m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
136 }
137 else
138 {
139
140 sr = new StreamReader(webResponse.GetResponseStream());
141 string response = sr.ReadToEnd().Trim();
142 m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
143
144 if (!String.IsNullOrEmpty(response))
145 {
146 try
147 {
148 // we assume we got an OSDMap back
149 OSDMap r = GetOSDMap(response);
150 bool success = r["success"].AsBoolean();
151 reason = r["reason"].AsString();
152 return success;
153 }
154 catch (NullReferenceException e)
155 {
156 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
157
158 // check for old style response
159 if (response.ToLower().StartsWith("true"))
160 return true;
161
162 return false;
163 }
164 }
165 }
166 }
167 catch (WebException ex)
168 {
169 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
170 // ignore, really
171 }
172 finally
173 {
174 if (sr != null)
175 sr.Close();
176 }
177
178 return true;
179
180 }
181
182 public bool DoChildAgentUpdateCall(GridRegion region, IAgentData cAgentData)
183 {
184 // Eventually, we want to use a caps url instead of the agentID
185 string uri = string.Empty;
186 try
187 {
188 uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/";
189 }
190 catch (Exception e)
191 {
192 m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent update. Reason: " + e.Message);
193 return false;
194 }
195 //Console.WriteLine(" >>> DoChildAgentUpdateCall <<< " + uri);
196
197 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
198 ChildUpdateRequest.Method = "PUT";
199 ChildUpdateRequest.ContentType = "application/json";
200 ChildUpdateRequest.Timeout = 10000;
201 //ChildUpdateRequest.KeepAlive = false;
202
203 // Fill it in
204 OSDMap args = null;
205 try
206 {
207 args = cAgentData.Pack();
208 }
209 catch (Exception e)
210 {
211 m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
212 }
213 // Add the regionhandle of the destination region
214 ulong regionHandle = GetRegionHandle(region.RegionHandle);
215 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
216
217 string strBuffer = "";
218 byte[] buffer = new byte[1];
219 try
220 {
221 strBuffer = OSDParser.SerializeJsonString(args);
222 Encoding str = Util.UTF8;
223 buffer = str.GetBytes(strBuffer);
224
225 }
226 catch (Exception e)
227 {
228 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
229 // ignore. buffer will be empty, caller should check.
230 }
231
232 Stream os = null;
233 try
234 { // send the Post
235 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
236 os = ChildUpdateRequest.GetRequestStream();
237 os.Write(buffer, 0, strBuffer.Length); //Send it
238 //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
239 }
240 //catch (WebException ex)
241 catch
242 {
243 //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
244
245 return false;
246 }
247 finally
248 {
249 if (os != null)
250 os.Close();
251 }
252
253 // Let's wait for the response
254 //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");
255
256 WebResponse webResponse = null;
257 StreamReader sr = null;
258 try
259 {
260 webResponse = ChildUpdateRequest.GetResponse();
261 if (webResponse == null)
262 {
263 m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post");
264 }
265
266 sr = new StreamReader(webResponse.GetResponseStream());
267 //reply = sr.ReadToEnd().Trim();
268 sr.ReadToEnd().Trim();
269 sr.Close();
270 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
271
272 }
273 catch (WebException ex)
274 {
275 m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message);
276 // ignore, really
277 }
278 finally
279 {
280 if (sr != null)
281 sr.Close();
282 }
283
284 return true;
285 }
286
287 public bool DoRetrieveRootAgentCall(GridRegion region, UUID id, out IAgentData agent)
288 {
289 agent = null;
290 // Eventually, we want to use a caps url instead of the agentID
291 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/";
292 //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri);
293
294 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
295 request.Method = "GET";
296 request.Timeout = 10000;
297 //request.Headers.Add("authorization", ""); // coming soon
298
299 HttpWebResponse webResponse = null;
300 string reply = string.Empty;
301 StreamReader sr = null;
302 try
303 {
304 webResponse = (HttpWebResponse)request.GetResponse();
305 if (webResponse == null)
306 {
307 m_log.Info("[REST COMMS]: Null reply on agent get ");
308 }
309
310 sr = new StreamReader(webResponse.GetResponseStream());
311 reply = sr.ReadToEnd().Trim();
312
313 //Console.WriteLine("[REST COMMS]: ChilAgentUpdate reply was " + reply);
314
315 }
316 catch (WebException ex)
317 {
318 m_log.InfoFormat("[REST COMMS]: exception on reply of agent get {0}", ex.Message);
319 // ignore, really
320 return false;
321 }
322 finally
323 {
324 if (sr != null)
325 sr.Close();
326 }
327
328 if (webResponse.StatusCode == HttpStatusCode.OK)
329 {
330 // we know it's jason
331 OSDMap args = GetOSDMap(reply);
332 if (args == null)
333 {
334 //Console.WriteLine("[REST COMMS]: Error getting OSDMap from reply");
335 return false;
336 }
337
338 agent = new CompleteAgentData();
339 agent.Unpack(args);
340 return true;
341 }
342
343 //Console.WriteLine("[REST COMMS]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode);
344 return false;
345 }
346
347 public bool DoReleaseAgentCall(ulong regionHandle, UUID id, string uri)
348 {
349 //m_log.Debug(" >>> DoReleaseAgentCall <<< " + uri);
350
351 WebRequest request = WebRequest.Create(uri);
352 request.Method = "DELETE";
353 request.Timeout = 10000;
354
355 StreamReader sr = null;
356 try
357 {
358 WebResponse webResponse = request.GetResponse();
359 if (webResponse == null)
360 {
361 m_log.Info("[REST COMMS]: Null reply on agent delete ");
362 }
363
364 sr = new StreamReader(webResponse.GetResponseStream());
365 //reply = sr.ReadToEnd().Trim();
366 sr.ReadToEnd().Trim();
367 sr.Close();
368 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
369
370 }
371 catch (WebException ex)
372 {
373 m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
374 // ignore, really
375 }
376 finally
377 {
378 if (sr != null)
379 sr.Close();
380 }
381
382 return true;
383 }
384
385
386 public bool DoCloseAgentCall(GridRegion region, UUID id)
387 {
388 string uri = string.Empty;
389 try
390 {
391 uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + id + "/" + region.RegionHandle.ToString() + "/";
392 }
393 catch (Exception e)
394 {
395 m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent close. Reason: " + e.Message);
396 return false;
397 }
398
399 //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri);
400
401 WebRequest request = WebRequest.Create(uri);
402 request.Method = "DELETE";
403 request.Timeout = 10000;
404
405 StreamReader sr = null;
406 try
407 {
408 WebResponse webResponse = request.GetResponse();
409 if (webResponse == null)
410 {
411 m_log.Info("[REST COMMS]: Null reply on agent delete ");
412 }
413
414 sr = new StreamReader(webResponse.GetResponseStream());
415 //reply = sr.ReadToEnd().Trim();
416 sr.ReadToEnd().Trim();
417 sr.Close();
418 //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);
419
420 }
421 catch (WebException ex)
422 {
423 m_log.InfoFormat("[REST COMMS]: exception on reply of agent delete {0}", ex.Message);
424 // ignore, really
425 }
426 finally
427 {
428 if (sr != null)
429 sr.Close();
430 }
431
432 return true;
433 }
434
435 public bool DoCreateObjectCall(GridRegion region, ISceneObject sog, string sogXml2, bool allowScriptCrossing)
436 {
437 ulong regionHandle = GetRegionHandle(region.RegionHandle);
438 string uri
439 = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort
440 + "/object/" + sog.UUID + "/" + regionHandle.ToString() + "/";
441 //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri);
442
443 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
444 ObjectCreateRequest.Method = "POST";
445 ObjectCreateRequest.ContentType = "application/json";
446 ObjectCreateRequest.Timeout = 10000;
447
448 OSDMap args = new OSDMap(2);
449 args["sog"] = OSD.FromString(sogXml2);
450 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
451 if (allowScriptCrossing)
452 {
453 string state = sog.GetStateSnapshot();
454 if (state.Length > 0)
455 args["state"] = OSD.FromString(state);
456 }
457
458 string strBuffer = "";
459 byte[] buffer = new byte[1];
460 try
461 {
462 strBuffer = OSDParser.SerializeJsonString(args);
463 Encoding str = Util.UTF8;
464 buffer = str.GetBytes(strBuffer);
465
466 }
467 catch (Exception e)
468 {
469 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message);
470 // ignore. buffer will be empty, caller should check.
471 }
472
473 Stream os = null;
474 try
475 { // send the Post
476 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
477 os = ObjectCreateRequest.GetRequestStream();
478 os.Write(buffer, 0, strBuffer.Length); //Send it
479 m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
480 }
481 //catch (WebException ex)
482 catch
483 {
484 // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message);
485
486 return false;
487 }
488 finally
489 {
490 if (os != null)
491 os.Close();
492 }
493
494 // Let's wait for the response
495 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
496
497 StreamReader sr = null;
498 try
499 {
500 WebResponse webResponse = ObjectCreateRequest.GetResponse();
501 if (webResponse == null)
502 {
503 m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post");
504 }
505
506 sr = new StreamReader(webResponse.GetResponseStream());
507 //reply = sr.ReadToEnd().Trim();
508 sr.ReadToEnd().Trim();
509 //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
510
511 }
512 catch (WebException ex)
513 {
514 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message);
515 // ignore, really
516 }
517 finally
518 {
519 if (sr != null)
520 sr.Close();
521 }
522
523 return true;
524
525 }
526
527 public bool DoCreateObjectCall(GridRegion region, UUID userID, UUID itemID)
528 {
529 ulong regionHandle = GetRegionHandle(region.RegionHandle);
530 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/object/" + UUID.Zero + "/" + regionHandle.ToString() + "/";
531 //m_log.Debug(" >>> DoCreateChildAgentCall <<< " + uri);
532
533 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
534 ObjectCreateRequest.Method = "PUT";
535 ObjectCreateRequest.ContentType = "application/json";
536 ObjectCreateRequest.Timeout = 10000;
537
538 OSDMap args = new OSDMap(2);
539 args["userid"] = OSD.FromUUID(userID);
540 args["itemid"] = OSD.FromUUID(itemID);
541
542 string strBuffer = "";
543 byte[] buffer = new byte[1];
544 try
545 {
546 strBuffer = OSDParser.SerializeJsonString(args);
547 Encoding str = Util.UTF8;
548 buffer = str.GetBytes(strBuffer);
549
550 }
551 catch (Exception e)
552 {
553 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message);
554 // ignore. buffer will be empty, caller should check.
555 }
556
557 Stream os = null;
558 try
559 { // send the Post
560 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
561 os = ObjectCreateRequest.GetRequestStream();
562 os.Write(buffer, 0, strBuffer.Length); //Send it
563 //m_log.InfoFormat("[REST COMMS]: Posted CreateObject request to remote sim {0}", uri);
564 }
565 //catch (WebException ex)
566 catch
567 {
568 // m_log.InfoFormat("[REST COMMS]: Bad send on CreateObject {0}", ex.Message);
569
570 return false;
571 }
572 finally
573 {
574 if (os != null)
575 os.Close();
576 }
577
578 // Let's wait for the response
579 //m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
580
581 StreamReader sr = null;
582 try
583 {
584 WebResponse webResponse = ObjectCreateRequest.GetResponse();
585 if (webResponse == null)
586 {
587 m_log.Info("[REST COMMS]: Null reply on DoCreateObjectCall post");
588 }
589
590 sr = new StreamReader(webResponse.GetResponseStream());
591 sr.ReadToEnd().Trim();
592 sr.ReadToEnd().Trim();
593
594 //m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", reply);
595
596 }
597 catch (WebException ex)
598 {
599 m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateObjectCall {0}", ex.Message);
600 // ignore, really
601 }
602 finally
603 {
604 if (sr != null)
605 sr.Close();
606 }
607
608 return true;
609
610 }
611
612 public bool DoHelloNeighbourCall(RegionInfo region, RegionInfo thisRegion)
613 {
614 string uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/region/" + thisRegion.RegionID + "/";
615 //m_log.Debug(" >>> DoHelloNeighbourCall <<< " + uri);
616
617 WebRequest HelloNeighbourRequest = WebRequest.Create(uri);
618 HelloNeighbourRequest.Method = "POST";
619 HelloNeighbourRequest.ContentType = "application/json";
620 HelloNeighbourRequest.Timeout = 10000;
621
622 // Fill it in
623 OSDMap args = null;
624 try
625 {
626 args = thisRegion.PackRegionInfoData();
627 }
628 catch (Exception e)
629 {
630 m_log.Debug("[REST COMMS]: PackRegionInfoData failed with exception: " + e.Message);
631 }
632 // Add the regionhandle of the destination region
633 ulong regionHandle = GetRegionHandle(region.RegionHandle);
634 args["destination_handle"] = OSD.FromString(regionHandle.ToString());
635
636 string strBuffer = "";
637 byte[] buffer = new byte[1];
638 try
639 {
640 strBuffer = OSDParser.SerializeJsonString(args);
641 Encoding str = Util.UTF8;
642 buffer = str.GetBytes(strBuffer);
643
644 }
645 catch (Exception e)
646 {
647 m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of HelloNeighbour: {0}", e.Message);
648 // ignore. buffer will be empty, caller should check.
649 }
650
651 Stream os = null;
652 try
653 { // send the Post
654 HelloNeighbourRequest.ContentLength = buffer.Length; //Count bytes to send
655 os = HelloNeighbourRequest.GetRequestStream();
656 os.Write(buffer, 0, strBuffer.Length); //Send it
657 //m_log.InfoFormat("[REST COMMS]: Posted HelloNeighbour request to remote sim {0}", uri);
658 }
659 //catch (WebException ex)
660 catch
661 {
662 //m_log.InfoFormat("[REST COMMS]: Bad send on HelloNeighbour {0}", ex.Message);
663
664 return false;
665 }
666 finally
667 {
668 if (os != null)
669 os.Close();
670 }
671 // Let's wait for the response
672 //m_log.Info("[REST COMMS]: Waiting for a reply after DoHelloNeighbourCall");
673
674 StreamReader sr = null;
675 try
676 {
677 WebResponse webResponse = HelloNeighbourRequest.GetResponse();
678 if (webResponse == null)
679 {
680 m_log.Info("[REST COMMS]: Null reply on DoHelloNeighbourCall post");
681 }
682
683 sr = new StreamReader(webResponse.GetResponseStream());
684 //reply = sr.ReadToEnd().Trim();
685 sr.ReadToEnd().Trim();
686 //m_log.InfoFormat("[REST COMMS]: DoHelloNeighbourCall reply was {0} ", reply);
687
688 }
689 catch (WebException ex)
690 {
691 m_log.InfoFormat("[REST COMMS]: exception on reply of DoHelloNeighbourCall {0}", ex.Message);
692 // ignore, really
693 }
694 finally
695 {
696 if (sr != null)
697 sr.Close();
698 }
699
700 return true;
701
702 }
703
704 #region Hyperlinks
705
706 public virtual ulong GetRegionHandle(ulong handle)
707 {
708 return handle;
709 }
710
711 public virtual bool IsHyperlink(ulong handle)
712 {
713 return false;
714 }
715
716 public virtual void SendUserInformation(GridRegion regInfo, AgentCircuitData aCircuit)
717 {
718 }
719
720 public virtual void AdjustUserInformation(AgentCircuitData aCircuit)
721 {
722 }
723
724 #endregion /* Hyperlinks */
725
726 public static OSDMap GetOSDMap(string data)
727 {
728 OSDMap args = null;
729 try
730 {
731 OSD buffer;
732 // We should pay attention to the content-type, but let's assume we know it's Json
733 buffer = OSDParser.DeserializeJson(data);
734 if (buffer.Type == OSDType.Map)
735 {
736 args = (OSDMap)buffer;
737 return args;
738 }
739 else
740 {
741 // uh?
742 System.Console.WriteLine("[REST COMMS]: Got OSD of type " + buffer.Type.ToString());
743 return null;
744 }
745 }
746 catch (Exception ex)
747 {
748 System.Console.WriteLine("[REST COMMS]: exception on parse of REST message " + ex.Message);
749 return null;
750 }
751 }
752
753
754 }
755}