29 using System.Collections;
30 using System.Collections.Generic;
34 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Services.Interfaces;
39 using OpenMetaverse.Imaging;
40 using OpenMetaverse.StructuredData;
44 using OpenSim.Services.Connectors.Simulation;
46 namespace OpenSim.Services.Connectors.Hypergrid
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52 private static UUID m_HGMapImage =
new UUID(
"00000000-0000-1111-9999-000000000013");
63 m_AssetService = assService;
68 return "foreignagent/";
73 return "foreignobject/";
76 public bool LinkRegion(
GridRegion info, out UUID regionID, out ulong realHandle, out
string externalName, out
string imageURL, out
string reason)
79 imageURL = string.Empty;
81 externalName = string.Empty;
82 reason = string.Empty;
84 Hashtable hash =
new Hashtable();
85 hash[
"region_name"] = info.RegionName;
87 IList paramList =
new ArrayList();
90 XmlRpcRequest request =
new XmlRpcRequest(
"link_region", paramList);
91 m_log.Debug(
"[GATEKEEPER SERVICE CONNECTOR]: Linking to " + info.ServerURI);
92 XmlRpcResponse response = null;
95 response = request.Send(info.ServerURI, 10000);
99 m_log.Debug(
"[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message);
100 reason =
"Error contacting remote server";
104 if (response.IsFault)
106 reason = response.FaultString;
107 m_log.ErrorFormat(
"[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString);
111 hash = (Hashtable)response.Value;
116 bool success =
false;
117 Boolean.TryParse((
string)hash[
"result"], out success);
120 UUID.TryParse((string)hash[
"uuid"], out regionID);
122 if ((
string)hash[
"handle"] != null)
124 realHandle = Convert.ToUInt64((string)hash[
"handle"]);
127 if (hash[
"region_image"] != null)
129 imageURL = (string)hash[
"region_image"];
132 if (hash[
"external_name"] != null)
134 externalName = (string)hash[
"external_name"];
142 reason =
"Error parsing return arguments";
143 m_log.Error(
"[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace);
150 public UUID
GetMapImage(UUID regionID,
string imageURL,
string storagePath)
152 if (m_AssetService == null)
154 m_log.DebugFormat(
"[GATEKEEPER SERVICE CONNECTOR]: No AssetService defined. Map tile not retrieved.");
158 UUID mapTile = m_HGMapImage;
159 string filename = string.Empty;
163 WebClient c =
new WebClient();
165 string name = regionID.ToString();
166 filename = Path.Combine(storagePath, name +
".jpg");
167 m_log.DebugFormat(
"[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename);
168 if (!
File.Exists(filename))
170 m_log.DebugFormat(
"[GATEKEEPER SERVICE CONNECTOR]: downloading...");
171 c.DownloadFile(imageURL, filename);
175 m_log.DebugFormat(
"[GATEKEEPER SERVICE CONNECTOR]: using cached image");
178 byte[] imageData = null;
180 using (Bitmap bitmap =
new Bitmap(filename))
183 imageData = OpenJPEG.EncodeFromImage(bitmap,
true);
186 AssetBase ass =
new AssetBase(UUID.Random(),
"region " + name, (sbyte)AssetType.Texture, regionID.ToString());
191 ass.Data = imageData;
193 m_AssetService.Store(ass);
196 mapTile = ass.FullID;
200 m_log.Info(
"[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache");
207 Hashtable hash =
new Hashtable();
208 hash[
"region_uuid"] = regionID.ToString();
209 if (agentID != UUID.Zero)
211 hash[
"agent_id"] = agentID.ToString();
212 if (agentHomeURI != null)
213 hash[
"agent_home_uri"] = agentHomeURI;
216 IList paramList =
new ArrayList();
219 XmlRpcRequest request =
new XmlRpcRequest(
"get_region", paramList);
220 m_log.Debug(
"[GATEKEEPER SERVICE CONNECTOR]: contacting " + gatekeeper.ServerURI);
221 XmlRpcResponse response = null;
224 response = request.Send(gatekeeper.ServerURI, 10000);
228 message =
"Error contacting grid.";
229 m_log.Debug(
"[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message);
233 if (response.IsFault)
235 message =
"Error contacting grid.";
236 m_log.ErrorFormat(
"[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString);
240 hash = (Hashtable)response.Value;
245 bool success =
false;
246 Boolean.TryParse((
string)hash[
"result"], out success);
248 if (hash[
"message"] != null)
249 message = (string)hash[
"message"];
253 message =
"The teleport destination could not be found.";
259 UUID.TryParse((string)hash[
"uuid"], out region.
RegionID);
262 if (hash[
"x"] != null)
264 Int32.TryParse((string)hash[
"x"], out n);
265 region.RegionLocX = n;
268 if (hash[
"y"] != null)
270 Int32.TryParse((string)hash[
"y"], out n);
271 region.RegionLocY = n;
274 if (hash[
"size_x"] != null)
276 Int32.TryParse((string)hash[
"size_x"], out n);
277 region.RegionSizeX = n;
280 if (hash[
"size_y"] != null)
282 Int32.TryParse((string)hash[
"size_y"], out n);
283 region.RegionSizeY = n;
286 if (hash[
"region_name"] != null)
288 region.RegionName = (string)hash[
"region_name"];
291 if (hash[
"hostname"] != null)
293 region.ExternalHostName = (string)hash[
"hostname"];
296 if (hash[
"http_port"] != null)
299 UInt32.TryParse((string)hash[
"http_port"], out p);
303 if (hash[
"internal_port"] != null)
306 Int32.TryParse((string)hash[
"internal_port"], out p);
307 region.InternalEndPoint =
new IPEndPoint(IPAddress.Parse(
"0.0.0.0"), p);
311 if (hash[
"server_uri"] != null)
313 region.ServerURI = (string)hash[
"server_uri"];
324 message =
"Error parsing response from grid.";
325 m_log.Error(
"[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace);
GatekeeperServiceConnector(IAssetService assService)
UUID GetMapImage(UUID regionID, string imageURL, string storagePath)
OpenSim.Services.Interfaces.GridRegion GridRegion
Asset class. All Assets are reference by this class or a class derived from this class ...
override string AgentPath()
GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID, UUID agentID, string agentHomeURI, out string message)
override string ObjectPath()
bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string externalName, out string imageURL, out string reason)
Interactive OpenSim region server
GatekeeperServiceConnector()