aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs215
1 files changed, 215 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index a8d9292..ae0a0b6 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -1,13 +1,18 @@
1using System; 1using System;
2using System.Collections; 2using System.Collections;
3using System.Collections.Generic; 3using System.Collections.Generic;
4using System.Drawing;
4using System.Net; 5using System.Net;
6using System.Reflection;
5 7
8using OpenSim.Framework;
6using OpenSim.Services.Interfaces; 9using OpenSim.Services.Interfaces;
7using GridRegion = OpenSim.Services.Interfaces.GridRegion; 10using GridRegion = OpenSim.Services.Interfaces.GridRegion;
8 11
9using OpenMetaverse; 12using OpenMetaverse;
13using OpenMetaverse.Imaging;
10using Nwc.XmlRpc; 14using Nwc.XmlRpc;
15using log4net;
11 16
12using OpenSim.Services.Connectors.Simulation; 17using OpenSim.Services.Connectors.Simulation;
13 18
@@ -15,6 +20,21 @@ namespace OpenSim.Services.Connectors.Hypergrid
15{ 20{
16 public class GatekeeperServiceConnector : SimulationServiceConnector 21 public class GatekeeperServiceConnector : SimulationServiceConnector
17 { 22 {
23 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
24
25 private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013");
26
27 private IAssetService m_AssetService;
28
29 public GatekeeperServiceConnector() : base()
30 {
31 }
32
33 public GatekeeperServiceConnector(IAssetService assService)
34 {
35 m_AssetService = assService;
36 }
37
18 protected override string AgentPath() 38 protected override string AgentPath()
19 { 39 {
20 return "/foreignagent/"; 40 return "/foreignagent/";
@@ -25,6 +45,201 @@ namespace OpenSim.Services.Connectors.Hypergrid
25 return "/foreignobject/"; 45 return "/foreignobject/";
26 } 46 }
27 47
48 public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string imageURL, out string reason)
49 {
50 regionID = UUID.Zero;
51 imageURL = string.Empty;
52 realHandle = 0;
53 reason = string.Empty;
54
55 Hashtable hash = new Hashtable();
56 hash["region_name"] = info.RegionName;
57
58 IList paramList = new ArrayList();
59 paramList.Add(hash);
60
61 XmlRpcRequest request = new XmlRpcRequest("link_region", paramList);
62 string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/";
63 //m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Linking to " + uri);
64 XmlRpcResponse response = null;
65 try
66 {
67 response = request.Send(uri, 10000);
68 }
69 catch (Exception e)
70 {
71 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message);
72 reason = "Error contacting remote server";
73 return false;
74 }
75
76 if (response.IsFault)
77 {
78 reason = response.FaultString;
79 m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString);
80 return false;
81 }
82
83 hash = (Hashtable)response.Value;
84 //foreach (Object o in hash)
85 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
86 try
87 {
88 bool success = false;
89 Boolean.TryParse((string)hash["result"], out success);
90 if (success)
91 {
92 UUID.TryParse((string)hash["uuid"], out regionID);
93 //m_log.Debug(">> HERE, uuid: " + uuid);
94 if ((string)hash["handle"] != null)
95 {
96 realHandle = Convert.ToUInt64((string)hash["handle"]);
97 //m_log.Debug(">> HERE, realHandle: " + realHandle);
98 }
99 if (hash["region_image"] != null)
100 {
101 imageURL = (string)hash["region_image"];
102 }
103 }
104
105 }
106 catch (Exception e)
107 {
108 reason = "Error parsing return arguments";
109 m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace);
110 return false;
111 }
112
113 return true;
114 }
115
116 UUID m_MissingTexture = new UUID("5748decc-f629-461c-9a36-a35a221fe21f");
117
118 public UUID GetMapImage(UUID regionID, string imageURL)
119 {
120 if (m_AssetService == null)
121 return m_MissingTexture;
122
123 try
124 {
125
126 WebClient c = new WebClient();
127 //m_log.Debug("JPEG: " + imageURL);
128 string filename = regionID.ToString();
129 c.DownloadFile(imageURL, filename + ".jpg");
130 Bitmap m = new Bitmap(filename + ".jpg");
131 //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
132 byte[] imageData = OpenJPEG.EncodeFromImage(m, true);
133 AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture);
134
135 // !!! for now
136 //info.RegionSettings.TerrainImageID = ass.FullID;
137
138 ass.Temporary = true;
139 ass.Local = true;
140 ass.Data = imageData;
141
142 m_AssetService.Store(ass);
143
144 // finally
145 return ass.FullID;
146
147 }
148 catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
149 {
150 m_log.Warn("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache");
151 }
152 return UUID.Zero;
153 }
154
155 public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID)
156 {
157 Hashtable hash = new Hashtable();
158 hash["region_uuid"] = regionID.ToString();
159
160 IList paramList = new ArrayList();
161 paramList.Add(hash);
162
163 XmlRpcRequest request = new XmlRpcRequest("get_region", paramList);
164 string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/";
165 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: contacting " + uri);
166 XmlRpcResponse response = null;
167 try
168 {
169 response = request.Send(uri, 10000);
170 }
171 catch (Exception e)
172 {
173 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message);
174 return null;
175 }
176
177 if (response.IsFault)
178 {
179 m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString);
180 return null;
181 }
182
183 hash = (Hashtable)response.Value;
184 //foreach (Object o in hash)
185 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
186 try
187 {
188 bool success = false;
189 Boolean.TryParse((string)hash["result"], out success);
190 if (success)
191 {
192 GridRegion region = new GridRegion();
193
194 UUID.TryParse((string)hash["uuid"], out region.RegionID);
195 //m_log.Debug(">> HERE, uuid: " + region.RegionID);
196 int n = 0;
197 if (hash["x"] != null)
198 {
199 Int32.TryParse((string)hash["x"], out n);
200 region.RegionLocX = n;
201 //m_log.Debug(">> HERE, x: " + region.RegionLocX);
202 }
203 if (hash["y"] != null)
204 {
205 Int32.TryParse((string)hash["y"], out n);
206 region.RegionLocY = n;
207 //m_log.Debug(">> HERE, y: " + region.RegionLocY);
208 }
209 if (hash["region_name"] != null)
210 {
211 region.RegionName = (string)hash["region_name"];
212 //m_log.Debug(">> HERE, name: " + region.RegionName);
213 }
214 if (hash["hostname"] != null)
215 region.ExternalHostName = (string)hash["hostname"];
216 if (hash["http_port"] != null)
217 {
218 uint p = 0;
219 UInt32.TryParse((string)hash["http_port"], out p);
220 region.HttpPort = p;
221 }
222 if (hash["internal_port"] != null)
223 {
224 int p = 0;
225 Int32.TryParse((string)hash["internal_port"], out p);
226 region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p);
227 }
228
229 // Successful return
230 return region;
231 }
232
233 }
234 catch (Exception e)
235 {
236 m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace);
237 return null;
238 }
239
240 return null;
241 }
242
28 public GridRegion GetHomeRegion(GridRegion gatekeeper, UUID userID, out Vector3 position, out Vector3 lookAt) 243 public GridRegion GetHomeRegion(GridRegion gatekeeper, UUID userID, out Vector3 position, out Vector3 lookAt)
29 { 244 {
30 position = Vector3.UnitY; lookAt = Vector3.UnitY; 245 position = Vector3.UnitY; lookAt = Vector3.UnitY;