aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors
diff options
context:
space:
mode:
authorDiva Canto2010-01-16 21:42:44 -0800
committerDiva Canto2010-01-16 21:42:44 -0800
commit04e29c1bacbc1e2df980ae15896a847ce7535da2 (patch)
treee799d2837af1a41bc2c3b2d571201e9a8a6d7ae7 /OpenSim/Services/Connectors
parentFinished moving object crossings into EntityTransferModule (diff)
downloadopensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.zip
opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.gz
opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.bz2
opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.xz
Beginning of rewriting HG. Compiles, and runs, but HG functions not restored yet.
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r--OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs8
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs245
2 files changed, 253 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
index 7098b07..8b39171 100644
--- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs
@@ -55,6 +55,14 @@ namespace OpenSim.Services.Connectors.Grid
55 m_AssetService = assService; 55 m_AssetService = assService;
56 } 56 }
57 57
58 public bool LinkRegion(GridRegion info, out UUID regionID, out ulong regionHandle, out string reason)
59 {
60 regionID = LinkRegion(info, out regionHandle);
61 // reason...
62 reason = string.Empty;
63 return true;
64 }
65
58 public UUID LinkRegion(GridRegion info, out ulong realHandle) 66 public UUID LinkRegion(GridRegion info, out ulong realHandle)
59 { 67 {
60 UUID uuid = UUID.Zero; 68 UUID uuid = UUID.Zero;
diff --git a/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
new file mode 100644
index 0000000..460acae
--- /dev/null
+++ b/OpenSim/Services/Connectors/Hypergrid/HypergridServiceConnector.cs
@@ -0,0 +1,245 @@
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;
44
45namespace OpenSim.Services.Connectors.Hypergrid
46{
47 public class HypergridServiceConnector
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IAssetService m_AssetService;
52
53 public HypergridServiceConnector(IAssetService assService)
54 {
55 m_AssetService = assService;
56 }
57
58 public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string imageURL, out string reason)
59 {
60 regionID = UUID.Zero;
61 imageURL = string.Empty;
62 realHandle = 0;
63 reason = string.Empty;
64
65 Hashtable hash = new Hashtable();
66 hash["region_name"] = info.RegionName;
67
68 IList paramList = new ArrayList();
69 paramList.Add(hash);
70
71 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
72 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
73 m_log.Debug("[HGrid]: Linking to " + uri);
74 XmlRpcResponse response = null;
75 try
76 {
77 response = request.Send(uri, 10000);
78 }
79 catch (Exception e)
80 {
81 m_log.Debug("[HGrid]: Exception " + e.Message);
82 reason = "Error contacting remote server";
83 return false;
84 }
85
86 if (response.IsFault)
87 {
88 reason = response.FaultString;
89 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
90 return false;
91 }
92
93 hash = (Hashtable)response.Value;
94 //foreach (Object o in hash)
95 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
96 try
97 {
98 bool success = false;
99 Boolean.TryParse((string)hash["result"], out success);
100 if (success)
101 {
102 UUID.TryParse((string)hash["uuid"], out regionID);
103 //m_log.Debug(">> HERE, uuid: " + uuid);
104 if ((string)hash["handle"] != null)
105 {
106 realHandle = Convert.ToUInt64((string)hash["handle"]);
107 //m_log.Debug(">> HERE, realHandle: " + realHandle);
108 }
109 if (hash["region_image"] != null)
110 {
111 imageURL = (string)hash["region_image"];
112 }
113 }
114
115 }
116 catch (Exception e)
117 {
118 reason = "Error parsing return arguments";
119 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
120 return false;
121 }
122
123 return true;
124 }
125
126 public UUID GetMapImage(UUID regionID, string imageURL)
127 {
128 try
129 {
130
131 WebClient c = new WebClient();
132 //m_log.Debug("JPEG: " + uri);
133 string filename = regionID.ToString();
134 c.DownloadFile(imageURL, filename + ".jpg");
135 Bitmap m = new Bitmap(filename + ".jpg");
136 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
137 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
138 AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture);
139
140 // !!! for now
141 //info.RegionSettings.TerrainImageID = ass.FullID;
142
143 ass.Temporary = true;
144 ass.Local = true;
145 ass.Data = imageData;
146
147 m_AssetService.Store(ass);
148
149 // finally
150 return ass.FullID;
151
152 }
153 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
154 {
155 m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache");
156 }
157 return UUID.Zero;
158 }
159
160 public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID)
161 {
162 Hashtable hash = new Hashtable();
163 hash["region_uuid"] = regionID.ToString();
164
165 IList paramList = new ArrayList();
166 paramList.Add(hash);
167
168 XmlRpcRequest request = new XmlRpcRequest("get_region", paramList);
169 string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/";
170 m_log.Debug("[HGrid]: contacting " + uri);
171 XmlRpcResponse response = null;
172 try
173 {
174 response = request.Send(uri, 10000);
175 }
176 catch (Exception e)
177 {
178 m_log.Debug("[HGrid]: Exception " + e.Message);
179 return null;
180 }
181
182 if (response.IsFault)
183 {
184 m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString);
185 return null;
186 }
187
188 hash = (Hashtable)response.Value;
189 //foreach (Object o in hash)
190 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
191 try
192 {
193 bool success = false;
194 Boolean.TryParse((string)hash["result"], out success);
195 if (success)
196 {
197 GridRegion region = new GridRegion();
198
199 UUID.TryParse((string)hash["uuid"], out region.RegionID);
200 //m_log.Debug(">> HERE, uuid: " + uuid);
201 int n = 0;
202 if (hash["x"] != null)
203 {
204 Int32.TryParse((string)hash["x"], out n);
205 region.RegionLocX = n;
206 }
207 if (hash["y"] != null)
208 {
209 Int32.TryParse((string)hash["y"], out n);
210 region.RegionLocY = n;
211 }
212 if (hash["region_name"] != null)
213 {
214 region.RegionName = (string)hash["region_name"];
215 }
216 if (hash["hostname"] != null)
217 region.ExternalHostName = (string)hash["hostname"];
218 if (hash["http_port"] != null)
219 {
220 uint p = 0;
221 UInt32.TryParse((string)hash["http_port"], out p);
222 region.HttpPort = p;
223 }
224 if (hash["internal_port"] != null)
225 {
226 int p = 0;
227 Int32.TryParse((string)hash["internal_port"], out p);
228 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
229 }
230
231 // Successful return
232 return region;
233 }
234
235 }
236 catch (Exception e)
237 {
238 m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace);
239 return null;
240 }
241
242 return null;
243 }
244 }
245}