aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
diff options
context:
space:
mode:
authorDiva Canto2010-01-24 14:30:48 -0800
committerDiva Canto2010-01-24 14:30:48 -0800
commit48b03c2c61a422c3ac9843892a2ae93b29a9f7b8 (patch)
treece3aae8c5bb0ee0c1748e4355cd616ea84b5b344 /OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
parentChange a member of the friendslist module to better reflect the client side (diff)
downloadopensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.zip
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.gz
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.bz2
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.xz
Integrated the hyperlinking with the GridService.
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs354
1 files changed, 0 insertions, 354 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
deleted file mode 100644
index 1786d38..0000000
--- a/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
+++ /dev/null
@@ -1,354 +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.Text;
32using System.Drawing;
33using System.Net;
34using System.Reflection;
35using OpenSim.Services.Interfaces;
36using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37
38using OpenSim.Framework;
39
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using log4net;
43using Nwc.XmlRpc;
44using Nini.Config;
45
46namespace OpenSim.Services.Connectors.Hypergrid
47{
48 public class HypergridServiceConnector : IHypergridService
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private IAssetService m_AssetService;
53 private string m_ServerURL;
54
55 public HypergridServiceConnector() { }
56
57 public HypergridServiceConnector(IAssetService assService)
58 {
59 m_AssetService = assService;
60 }
61
62 public HypergridServiceConnector(IConfigSource source)
63 {
64 Initialise(source);
65 }
66
67 public virtual void Initialise(IConfigSource source)
68 {
69 IConfig hgConfig = source.Configs["HypergridService"];
70 if (hgConfig == null)
71 {
72 m_log.Error("[HYPERGRID CONNECTOR]: HypergridService missing from OpenSim.ini");
73 throw new Exception("Hypergrid connector init error");
74 }
75
76 string serviceURI = hgConfig.GetString("HypergridServerURI",
77 String.Empty);
78
79 if (serviceURI == String.Empty)
80 {
81 m_log.Error("[HYPERGRID CONNECTOR]: No Server URI named in section HypergridService");
82 throw new Exception("Hypergrid connector init error");
83 }
84 m_ServerURL = serviceURI;
85 }
86
87 public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string imageURL, out string reason)
88 {
89 regionID = UUID.Zero;
90 imageURL = string.Empty;
91 realHandle = 0;
92 reason = string.Empty;
93
94 Hashtable hash = new Hashtable();
95 hash["region_name"] = info.RegionName;
96
97 IList paramList = new ArrayList();
98 paramList.Add(hash);
99
100 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
101 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
102 //m_log.Debug("[HGrid]: Linking to " + uri);
103 XmlRpcResponse response = null;
104 try
105 {
106 response = request.Send(uri, 10000);
107 }
108 catch (Exception e)
109 {
110 m_log.Debug("[HGrid]: Exception " + e.Message);
111 reason = "Error contacting remote server";
112 return false;
113 }
114
115 if (response.IsFault)
116 {
117 reason = response.FaultString;
118 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
119 return false;
120 }
121
122 hash = (Hashtable)response.Value;
123 //foreach (Object o in hash)
124 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
125 try
126 {
127 bool success = false;
128 Boolean.TryParse((string)hash["result"], out success);
129 if (success)
130 {
131 UUID.TryParse((string)hash["uuid"], out regionID);
132 //m_log.Debug(">> HERE, uuid: " + uuid);
133 if ((string)hash["handle"] != null)
134 {
135 realHandle = Convert.ToUInt64((string)hash["handle"]);
136 //m_log.Debug(">> HERE, realHandle: " + realHandle);
137 }
138 if (hash["region_image"] != null)
139 {
140 imageURL = (string)hash["region_image"];
141 }
142 }
143
144 }
145 catch (Exception e)
146 {
147 reason = "Error parsing return arguments";
148 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
149 return false;
150 }
151
152 return true;
153 }
154
155 public UUID GetMapImage(UUID regionID, string imageURL)
156 {
157 try
158 {
159
160 WebClient c = new WebClient();
161 //m_log.Debug("JPEG: " + uri);
162 string filename = regionID.ToString();
163 c.DownloadFile(imageURL, filename + ".jpg");
164 Bitmap m = new Bitmap(filename + ".jpg");
165 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
166 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
167 AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture);
168
169 // !!! for now
170 //info.RegionSettings.TerrainImageID = ass.FullID;
171
172 ass.Temporary = true;
173 ass.Local = true;
174 ass.Data = imageData;
175
176 m_AssetService.Store(ass);
177
178 // finally
179 return ass.FullID;
180
181 }
182 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
183 {
184 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
185 }
186 return UUID.Zero;
187 }
188
189 public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID)
190 {
191 Hashtable hash = new Hashtable();
192 hash["region_uuid"] = regionID.ToString();
193
194 IList paramList = new ArrayList();
195 paramList.Add(hash);
196
197 XmlRpcRequest request = new XmlRpcRequest("get_region", paramList);
198 string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/";
199 m_log.Debug("[HGrid]: contacting " + uri);
200 XmlRpcResponse response = null;
201 try
202 {
203 response = request.Send(uri, 10000);
204 }
205 catch (Exception e)
206 {
207 m_log.Debug("[HGrid]: Exception " + e.Message);
208 return null;
209 }
210
211 if (response.IsFault)
212 {
213 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
214 return null;
215 }
216
217 hash = (Hashtable)response.Value;
218 //foreach (Object o in hash)
219 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
220 try
221 {
222 bool success = false;
223 Boolean.TryParse((string)hash["result"], out success);
224 if (success)
225 {
226 GridRegion region = new GridRegion();
227
228 UUID.TryParse((string)hash["uuid"], out region.RegionID);
229 //m_log.Debug(">> HERE, uuid: " + region.RegionID);
230 int n = 0;
231 if (hash["x"] != null)
232 {
233 Int32.TryParse((string)hash["x"], out n);
234 region.RegionLocX = n;
235 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
236 }
237 if (hash["y"] != null)
238 {
239 Int32.TryParse((string)hash["y"], out n);
240 region.RegionLocY = n;
241 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
242 }
243 if (hash["region_name"] != null)
244 {
245 region.RegionName = (string)hash["region_name"];
246 //m_log.Debug(">> HERE, name: " + region.RegionName);
247 }
248 if (hash["hostname"] != null)
249 region.ExternalHostName = (string)hash["hostname"];
250 if (hash["http_port"] != null)
251 {
252 uint p = 0;
253 UInt32.TryParse((string)hash["http_port"], out p);
254 region.HttpPort = p;
255 }
256 if (hash["internal_port"] != null)
257 {
258 int p = 0;
259 Int32.TryParse((string)hash["internal_port"], out p);
260 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
261 }
262
263 // Successful return
264 return region;
265 }
266
267 }
268 catch (Exception e)
269 {
270 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
271 return null;
272 }
273
274 return null;
275 }
276
277 #region From local regions to grid-wide hypergrid service
278
279 public bool LinkRegion(string regionDescriptor, out UUID regionID, out ulong realHandle, out string imageURL, out string reason)
280 {
281 regionID = UUID.Zero;
282 imageURL = string.Empty;
283 realHandle = 0;
284 reason = string.Empty;
285
286 Hashtable hash = new Hashtable();
287 hash["region_desc"] = regionDescriptor;
288
289 IList paramList = new ArrayList();
290 paramList.Add(hash);
291
292 XmlRpcRequest request = new XmlRpcRequest("link_region_by_desc", paramList);
293 XmlRpcResponse response = null;
294 try
295 {
296 response = request.Send(m_ServerURL, 10000);
297 }
298 catch (Exception e)
299 {
300 m_log.Debug("[HGrid]: Exception " + e.Message);
301 reason = "Error contacting remote server";
302 return false;
303 }
304
305 if (response.IsFault)
306 {
307 reason = response.FaultString;
308 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
309 return false;
310 }
311
312 hash = (Hashtable)response.Value;
313 //foreach (Object o in hash)
314 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
315 try
316 {
317 bool success = false;
318 Boolean.TryParse((string)hash["result"], out success);
319 if (success)
320 {
321 UUID.TryParse((string)hash["uuid"], out regionID);
322 //m_log.Debug(">> HERE, uuid: " + uuid);
323 if ((string)hash["handle"] != null)
324 {
325 realHandle = Convert.ToUInt64((string)hash["handle"]);
326 //m_log.Debug(">> HERE, realHandle: " + realHandle);
327 }
328 if (hash["region_image"] != null)
329 {
330 imageURL = (string)hash["region_image"];
331 }
332 }
333
334 }
335 catch (Exception e)
336 {
337 reason = "Error parsing return arguments";
338 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
339 return false;
340 }
341
342 return true;
343 }
344
345 // TODO !!!
346 public GridRegion GetRegionByUUID(UUID regionID) { return null; }
347 public GridRegion GetRegionByPosition(int x, int y) { return null; }
348 public GridRegion GetRegionByName(string name) { return null; }
349 public List<GridRegion> GetRegionsByName(string name) { return null; }
350 public List<GridRegion> GetRegionRange(int xmin, int xmax, int ymin, int ymax) { return null; }
351
352 #endregion
353 }
354}