aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs303
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs811
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs16
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs19
4 files changed, 34 insertions, 1115 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
deleted file mode 100644
index 0974372..0000000
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
+++ /dev/null
@@ -1,303 +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.Reflection;
31using System.Xml;
32using log4net;
33using Nini.Config;
34using OpenSim.Framework;
35//using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Region.Framework;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.Framework.Scenes.Hypergrid;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
43{
44 public class HGCommands
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private HGGridConnector m_HGGridConnector;
48 private Scene m_scene;
49
50 private static uint m_autoMappingX = 0;
51 private static uint m_autoMappingY = 0;
52 private static bool m_enableAutoMapping = false;
53
54 public HGCommands(HGGridConnector hgConnector, Scene scene)
55 {
56 m_HGGridConnector = hgConnector;
57 m_scene = scene;
58 }
59
60 //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager,
61 // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version)
62 //{
63 // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices);
64
65 // return
66 // new HGScene(
67 // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
68 // m_moduleLoader, false, m_configSettings.PhysicalPrim,
69 // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
70 //}
71
72 public void RunCommand(string module, string[] cmdparams)
73 {
74 List<string> args = new List<string>(cmdparams);
75 if (args.Count < 1)
76 return;
77
78 string command = args[0];
79 args.RemoveAt(0);
80
81 cmdparams = args.ToArray();
82
83 RunHGCommand(command, cmdparams);
84
85 }
86
87 private void RunHGCommand(string command, string[] cmdparams)
88 {
89 if (command.Equals("link-mapping"))
90 {
91 if (cmdparams.Length == 2)
92 {
93 try
94 {
95 m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
96 m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
97 m_enableAutoMapping = true;
98 }
99 catch (Exception)
100 {
101 m_autoMappingX = 0;
102 m_autoMappingY = 0;
103 m_enableAutoMapping = false;
104 }
105 }
106 }
107 else if (command.Equals("link-region"))
108 {
109 if (cmdparams.Length < 3)
110 {
111 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
112 {
113 LoadXmlLinkFile(cmdparams);
114 }
115 else
116 {
117 LinkRegionCmdUsage();
118 }
119 return;
120 }
121
122 if (cmdparams[2].Contains(":"))
123 {
124 // New format
125 int xloc, yloc;
126 string mapName;
127 try
128 {
129 xloc = Convert.ToInt32(cmdparams[0]);
130 yloc = Convert.ToInt32(cmdparams[1]);
131 mapName = cmdparams[2];
132 if (cmdparams.Length > 3)
133 for (int i = 3; i < cmdparams.Length; i++)
134 mapName += " " + cmdparams[i];
135
136 m_log.Info(">> MapName: " + mapName);
137 //internalPort = Convert.ToUInt32(cmdparams[4]);
138 //remotingPort = Convert.ToUInt32(cmdparams[5]);
139 }
140 catch (Exception e)
141 {
142 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
143 LinkRegionCmdUsage();
144 return;
145 }
146
147 // Convert cell coordinates given by the user to meters
148 xloc = xloc * (int)Constants.RegionSize;
149 yloc = yloc * (int)Constants.RegionSize;
150 m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc);
151 }
152 else
153 {
154 // old format
155 GridRegion regInfo;
156 int xloc, yloc;
157 uint externalPort;
158 string externalHostName;
159 try
160 {
161 xloc = Convert.ToInt32(cmdparams[0]);
162 yloc = Convert.ToInt32(cmdparams[1]);
163 externalPort = Convert.ToUInt32(cmdparams[3]);
164 externalHostName = cmdparams[2];
165 //internalPort = Convert.ToUInt32(cmdparams[4]);
166 //remotingPort = Convert.ToUInt32(cmdparams[5]);
167 }
168 catch (Exception e)
169 {
170 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
171 LinkRegionCmdUsage();
172 return;
173 }
174
175 // Convert cell coordinates given by the user to meters
176 xloc = xloc * (int)Constants.RegionSize;
177 yloc = yloc * (int)Constants.RegionSize;
178 if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
179 {
180 if (cmdparams.Length >= 5)
181 {
182 regInfo.RegionName = "";
183 for (int i = 4; i < cmdparams.Length; i++)
184 regInfo.RegionName += cmdparams[i] + " ";
185 }
186 }
187 }
188 return;
189 }
190 else if (command.Equals("unlink-region"))
191 {
192 if (cmdparams.Length < 1)
193 {
194 UnlinkRegionCmdUsage();
195 return;
196 }
197 if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0]))
198 m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]);
199 else
200 m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]);
201 }
202 }
203
204 private void LoadXmlLinkFile(string[] cmdparams)
205 {
206 //use http://www.hgurl.com/hypergrid.xml for test
207 try
208 {
209 XmlReader r = XmlReader.Create(cmdparams[0]);
210 XmlConfigSource cs = new XmlConfigSource(r);
211 string[] excludeSections = null;
212
213 if (cmdparams.Length == 2)
214 {
215 if (cmdparams[1].ToLower().StartsWith("excludelist:"))
216 {
217 string excludeString = cmdparams[1].ToLower();
218 excludeString = excludeString.Remove(0, 12);
219 char[] splitter = { ';' };
220
221 excludeSections = excludeString.Split(splitter);
222 }
223 }
224
225 for (int i = 0; i < cs.Configs.Count; i++)
226 {
227 bool skip = false;
228 if ((excludeSections != null) && (excludeSections.Length > 0))
229 {
230 for (int n = 0; n < excludeSections.Length; n++)
231 {
232 if (excludeSections[n] == cs.Configs[i].Name.ToLower())
233 {
234 skip = true;
235 break;
236 }
237 }
238 }
239 if (!skip)
240 {
241 ReadLinkFromConfig(cs.Configs[i]);
242 }
243 }
244 }
245 catch (Exception e)
246 {
247 m_log.Error(e.ToString());
248 }
249 }
250
251
252 private void ReadLinkFromConfig(IConfig config)
253 {
254 GridRegion regInfo;
255 int xloc, yloc;
256 uint externalPort;
257 string externalHostName;
258 uint realXLoc, realYLoc;
259
260 xloc = Convert.ToInt32(config.GetString("xloc", "0"));
261 yloc = Convert.ToInt32(config.GetString("yloc", "0"));
262 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
263 externalHostName = config.GetString("externalHostName", "");
264 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
265 realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
266
267 if (m_enableAutoMapping)
268 {
269 xloc = (int)((xloc % 100) + m_autoMappingX);
270 yloc = (int)((yloc % 100) + m_autoMappingY);
271 }
272
273 if (((realXLoc == 0) && (realYLoc == 0)) ||
274 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
275 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
276 {
277 xloc = xloc * (int)Constants.RegionSize;
278 yloc = yloc * (int)Constants.RegionSize;
279 if (
280 m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort,
281 externalHostName, out regInfo))
282 {
283 regInfo.RegionName = config.GetString("localName", "");
284 }
285 }
286 }
287
288
289 private void LinkRegionCmdUsage()
290 {
291 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
292 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
293 m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]");
294 }
295
296 private void UnlinkRegionCmdUsage()
297 {
298 m_log.Info("Usage: unlink-region <HostName>:<HttpPort>");
299 m_log.Info("Usage: unlink-region <LocalName>");
300 }
301
302 }
303}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
deleted file mode 100644
index 131febd..0000000
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGGridConnector.cs
+++ /dev/null
@@ -1,811 +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.Net;
31using System.Reflection;
32using System.Xml;
33
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Region.Framework.Scenes.Hypergrid;
39using OpenSim.Services.Interfaces;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41using OpenSim.Server.Base;
42using OpenSim.Services.Connectors.Grid;
43using OpenSim.Framework.Console;
44
45using OpenMetaverse;
46using log4net;
47using Nini.Config;
48
49namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
50{
51 public class HGGridConnector : ISharedRegionModule, IGridService, IHyperlinkService
52 {
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56 private static string LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI;
57
58 private bool m_Enabled = false;
59 private bool m_Initialized = false;
60
61 private Scene m_aScene;
62 private Dictionary<ulong, Scene> m_LocalScenes = new Dictionary<ulong, Scene>();
63
64 private IGridService m_GridServiceConnector;
65 private HypergridServiceConnector m_HypergridServiceConnector;
66
67 // Hyperlink regions are hyperlinks on the map
68 protected Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>();
69
70 // Known regions are home regions of visiting foreign users.
71 // They are not on the map as static hyperlinks. They are dynamic hyperlinks, they go away when
72 // the visitor goes away. They are mapped to X=0 on the map.
73 // This is key-ed on agent ID
74 protected Dictionary<UUID, GridRegion> m_knownRegions = new Dictionary<UUID, GridRegion>();
75
76 protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>();
77
78 #region ISharedRegionModule
79
80 public Type ReplaceableInterface
81 {
82 get { return null; }
83 }
84
85 public string Name
86 {
87 get { return "HGGridServicesConnector"; }
88 }
89
90 public void Initialise(IConfigSource source)
91 {
92 IConfig moduleConfig = source.Configs["Modules"];
93 if (moduleConfig != null)
94 {
95 string name = moduleConfig.GetString("GridServices", "");
96 if (name == Name)
97 {
98 IConfig gridConfig = source.Configs["GridService"];
99 if (gridConfig == null)
100 {
101 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
102 return;
103 }
104
105
106 InitialiseConnectorModule(source);
107
108 m_Enabled = true;
109 m_log.Info("[HGGRID CONNECTOR]: HG grid enabled");
110 }
111 }
112 }
113
114 private void InitialiseConnectorModule(IConfigSource source)
115 {
116 IConfig gridConfig = source.Configs["GridService"];
117 if (gridConfig == null)
118 {
119 m_log.Error("[HGGRID CONNECTOR]: GridService missing from OpenSim.ini");
120 throw new Exception("Grid connector init error");
121 }
122
123 string module = gridConfig.GetString("GridServiceConnectorModule", String.Empty);
124 if (module == String.Empty)
125 {
126 m_log.Error("[HGGRID CONNECTOR]: No GridServiceConnectorModule named in section GridService");
127 //return;
128 throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
129 }
130
131 Object[] args = new Object[] { source };
132 m_GridServiceConnector = ServerUtils.LoadPlugin<IGridService>(module, args);
133
134 }
135
136 public void PostInitialise()
137 {
138 if (m_Enabled)
139 ((ISharedRegionModule)m_GridServiceConnector).PostInitialise();
140 }
141
142 public void Close()
143 {
144 }
145
146 public void AddRegion(Scene scene)
147 {
148 if (!m_Enabled)
149 return;
150
151 m_LocalScenes[scene.RegionInfo.RegionHandle] = scene;
152 scene.RegisterModuleInterface<IGridService>(this);
153 scene.RegisterModuleInterface<IHyperlinkService>(this);
154
155 ((ISharedRegionModule)m_GridServiceConnector).AddRegion(scene);
156
157 // Yikes!! Remove this as soon as user services get refactored
158 LocalAssetServerURI = scene.CommsManager.NetworkServersInfo.AssetURL;
159 LocalInventoryServerURI = scene.CommsManager.NetworkServersInfo.InventoryURL;
160 LocalUserServerURI = scene.CommsManager.NetworkServersInfo.UserURL;
161 HGNetworkServersInfo.Init(LocalAssetServerURI, LocalInventoryServerURI, LocalUserServerURI);
162
163 }
164
165 public void RemoveRegion(Scene scene)
166 {
167 if (m_Enabled)
168 {
169 m_LocalScenes.Remove(scene.RegionInfo.RegionHandle);
170 ((ISharedRegionModule)m_GridServiceConnector).RemoveRegion(scene);
171 }
172 }
173
174 public void RegionLoaded(Scene scene)
175 {
176 if (!m_Enabled)
177 return;
178
179 if (!m_Initialized)
180 {
181 m_aScene = scene;
182
183 m_HypergridServiceConnector = new HypergridServiceConnector(scene.AssetService);
184
185 HGCommands hgCommands = new HGCommands(this, scene);
186 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-region",
187 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
188 "Link a hypergrid region", hgCommands.RunCommand);
189 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "unlink-region",
190 "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
191 "Unlink a hypergrid region", hgCommands.RunCommand);
192 MainConsole.Instance.Commands.AddCommand("HGGridServicesConnector", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
193 "Set local coordinate to map HG regions to", hgCommands.RunCommand);
194
195 m_Initialized = true;
196 }
197 }
198
199 #endregion
200
201 #region IGridService
202
203 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
204 {
205 // Region doesn't exist here. Trying to link remote region
206 if (regionInfo.RegionID.Equals(UUID.Zero))
207 {
208 m_log.Info("[HGrid]: Linking remote region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort);
209 ulong regionHandle = 0;
210 regionInfo.RegionID = m_HypergridServiceConnector.LinkRegion(regionInfo, out regionHandle);
211 if (!regionInfo.RegionID.Equals(UUID.Zero))
212 {
213 AddHyperlinkRegion(regionInfo, regionHandle);
214 m_log.Info("[HGrid]: Successfully linked to region_uuid " + regionInfo.RegionID);
215
216 // Try get the map image
217 m_HypergridServiceConnector.GetMapImage(regionInfo);
218 return String.Empty;
219 }
220 else
221 {
222 m_log.Info("[HGrid]: No such region " + regionInfo.ExternalHostName + ":" + regionInfo.HttpPort + "(" + regionInfo.InternalEndPoint.Port + ")");
223 return "No such region";
224 }
225 // Note that these remote regions aren't registered in localBackend, so return null, no local listeners
226 }
227 else // normal grid
228 return m_GridServiceConnector.RegisterRegion(scopeID, regionInfo);
229 }
230
231 public bool DeregisterRegion(UUID regionID)
232 {
233 // Try the hyperlink collection
234 if (m_HyperlinkRegions.ContainsKey(regionID))
235 {
236 RemoveHyperlinkRegion(regionID);
237 return true;
238 }
239 // Try the foreign users home collection
240
241 foreach (GridRegion r in m_knownRegions.Values)
242 if (r.RegionID == regionID)
243 {
244 RemoveHyperlinkHomeRegion(regionID);
245 return true;
246 }
247
248 // Finally, try the normal route
249 return m_GridServiceConnector.DeregisterRegion(regionID);
250 }
251
252 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
253 {
254 // No serving neighbours on hyperliked regions.
255 // Just the regular regions.
256 return m_GridServiceConnector.GetNeighbours(scopeID, regionID);
257 }
258
259 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
260 {
261 // Try the hyperlink collection
262 if (m_HyperlinkRegions.ContainsKey(regionID))
263 return m_HyperlinkRegions[regionID];
264
265 // Try the foreign users home collection
266 foreach (GridRegion r in m_knownRegions.Values)
267 if (r.RegionID == regionID)
268 return r;
269
270 // Finally, try the normal route
271 return m_GridServiceConnector.GetRegionByUUID(scopeID, regionID);
272 }
273
274 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
275 {
276 int snapX = (int) (x / Constants.RegionSize) * (int)Constants.RegionSize;
277 int snapY = (int) (y / Constants.RegionSize) * (int)Constants.RegionSize;
278 // Try the hyperlink collection
279 foreach (GridRegion r in m_HyperlinkRegions.Values)
280 {
281 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
282 return r;
283 }
284
285 // Try the foreign users home collection
286 foreach (GridRegion r in m_knownRegions.Values)
287 {
288 if ((r.RegionLocX == snapX) && (r.RegionLocY == snapY))
289 {
290 return r;
291 }
292 }
293
294 // Finally, try the normal route
295 return m_GridServiceConnector.GetRegionByPosition(scopeID, x, y);
296 }
297
298 public GridRegion GetRegionByName(UUID scopeID, string regionName)
299 {
300 // Try normal grid first
301 GridRegion region = m_GridServiceConnector.GetRegionByName(scopeID, regionName);
302 if (region != null)
303 return region;
304
305 // Try the hyperlink collection
306 foreach (GridRegion r in m_HyperlinkRegions.Values)
307 {
308 if (r.RegionName == regionName)
309 return r;
310 }
311
312 // Try the foreign users home collection
313 foreach (GridRegion r in m_knownRegions.Values)
314 {
315 if (r.RegionName == regionName)
316 return r;
317 }
318 return null;
319 }
320
321 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
322 {
323 List<GridRegion> rinfos = new List<GridRegion>();
324
325 if (name == string.Empty)
326 return rinfos;
327
328 foreach (GridRegion r in m_HyperlinkRegions.Values)
329 if ((r.RegionName != null) && r.RegionName.ToLower().StartsWith(name.ToLower()))
330 rinfos.Add(r);
331
332 rinfos.AddRange(m_GridServiceConnector.GetRegionsByName(scopeID, name, maxNumber));
333 return rinfos;
334 }
335
336 public List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax)
337 {
338 int snapXmin = (int)(xmin / Constants.RegionSize) * (int)Constants.RegionSize;
339// int snapXmax = (int)(xmax / Constants.RegionSize) * (int)Constants.RegionSize;
340 int snapYmin = (int)(ymin / Constants.RegionSize) * (int)Constants.RegionSize;
341 int snapYmax = (int)(ymax / Constants.RegionSize) * (int)Constants.RegionSize;
342
343 List<GridRegion> rinfos = new List<GridRegion>();
344 foreach (GridRegion r in m_HyperlinkRegions.Values)
345 if ((r.RegionLocX > snapXmin) && (r.RegionLocX < snapYmax) &&
346 (r.RegionLocY > snapYmin) && (r.RegionLocY < snapYmax))
347 rinfos.Add(r);
348
349 rinfos.AddRange(m_GridServiceConnector.GetRegionRange(scopeID, xmin, xmax, ymin, ymax));
350
351 return rinfos;
352 }
353
354 #endregion
355
356 #region Auxiliary
357
358 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
359 {
360 m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
361 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
362 }
363
364 private void RemoveHyperlinkRegion(UUID regionID)
365 {
366 m_HyperlinkRegions.Remove(regionID);
367 m_HyperlinkHandles.Remove(regionID);
368 }
369
370 private void AddHyperlinkHomeRegion(UUID userID, GridRegion regionInfo, ulong regionHandle)
371 {
372 m_knownRegions[userID] = regionInfo;
373 m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
374 }
375
376 private void RemoveHyperlinkHomeRegion(UUID regionID)
377 {
378 foreach (KeyValuePair<UUID, GridRegion> kvp in m_knownRegions)
379 {
380 if (kvp.Value.RegionID == regionID)
381 {
382 m_knownRegions.Remove(kvp.Key);
383 }
384 }
385 m_HyperlinkHandles.Remove(regionID);
386 }
387 #endregion
388
389 #region IHyperlinkService
390
391 private static Random random = new Random();
392
393
394 public GridRegion TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, int xloc, int yloc)
395 {
396 string host = "127.0.0.1";
397 string portstr;
398 string regionName = "";
399 uint port = 9000;
400 string[] parts = mapName.Split(new char[] { ':' });
401 if (parts.Length >= 1)
402 {
403 host = parts[0];
404 }
405 if (parts.Length >= 2)
406 {
407 portstr = parts[1];
408 //m_log.Debug("-- port = " + portstr);
409 if (!UInt32.TryParse(portstr, out port))
410 regionName = parts[1];
411 }
412 // always take the last one
413 if (parts.Length >= 3)
414 {
415 regionName = parts[2];
416 }
417
418 // Sanity check. Don't ever link to this sim.
419 IPAddress ipaddr = null;
420 try
421 {
422 ipaddr = Util.GetHostFromDNS(host);
423 }
424 catch { }
425
426 if ((ipaddr != null) &&
427 !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port)))
428 {
429 GridRegion regInfo;
430 bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo);
431 if (success)
432 {
433 regInfo.RegionName = mapName;
434 return regInfo;
435 }
436 }
437
438 return null;
439 }
440
441
442 // From the map search and secondlife://blah
443 public GridRegion TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
444 {
445 int xloc = random.Next(0, Int16.MaxValue) * (int) Constants.RegionSize;
446 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
447 }
448
449 public bool TryCreateLink(Scene m_scene, IClientAPI client, int xloc, int yloc,
450 string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo)
451 {
452 m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc);
453
454 regInfo = new GridRegion();
455 regInfo.RegionName = externalRegionName;
456 regInfo.HttpPort = externalPort;
457 regInfo.ExternalHostName = externalHostName;
458 regInfo.RegionLocX = xloc;
459 regInfo.RegionLocY = yloc;
460
461 try
462 {
463 regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
464 }
465 catch (Exception e)
466 {
467 m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message);
468 return false;
469 }
470
471 // Finally, link it
472 if (RegisterRegion(UUID.Zero, regInfo) != String.Empty)
473 {
474 m_log.Warn("[HGrid]: Unable to link region");
475 return false;
476 }
477
478 int x, y;
479 if (!Check4096(m_scene, regInfo, out x, out y))
480 {
481 DeregisterRegion(regInfo.RegionID);
482 if (client != null)
483 client.SendAlertMessage("Region is too far (" + x + ", " + y + ")");
484 m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")");
485 return false;
486 }
487
488 if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y))
489 {
490 DeregisterRegion(regInfo.RegionID);
491 if (client != null)
492 client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")");
493 m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")");
494 return false;
495 }
496
497 m_log.Debug("[HGrid]: link region succeeded");
498 return true;
499 }
500
501 public bool TryUnlinkRegion(Scene m_scene, string mapName)
502 {
503 GridRegion regInfo = null;
504 if (mapName.Contains(":"))
505 {
506 string host = "127.0.0.1";
507 //string portstr;
508 //string regionName = "";
509 uint port = 9000;
510 string[] parts = mapName.Split(new char[] { ':' });
511 if (parts.Length >= 1)
512 {
513 host = parts[0];
514 }
515 // if (parts.Length >= 2)
516 // {
517 // portstr = parts[1];
518 // if (!UInt32.TryParse(portstr, out port))
519 // regionName = parts[1];
520 // }
521 // always take the last one
522 // if (parts.Length >= 3)
523 // {
524 // regionName = parts[2];
525 // }
526 foreach (GridRegion r in m_HyperlinkRegions.Values)
527 if (host.Equals(r.ExternalHostName) && (port == r.HttpPort))
528 regInfo = r;
529 }
530 else
531 {
532 foreach (GridRegion r in m_HyperlinkRegions.Values)
533 if (r.RegionName.Equals(mapName))
534 regInfo = r;
535 }
536 if (regInfo != null)
537 {
538 return DeregisterRegion(regInfo.RegionID);
539 }
540 else
541 {
542 m_log.InfoFormat("[HGrid]: Region {0} not found", mapName);
543 return false;
544 }
545 }
546
547 /// <summary>
548 /// Cope with this viewer limitation.
549 /// </summary>
550 /// <param name="regInfo"></param>
551 /// <returns></returns>
552 public bool Check4096(Scene m_scene, GridRegion regInfo, out int x, out int y)
553 {
554 ulong realHandle = m_HyperlinkHandles[regInfo.RegionID];
555 uint ux = 0, uy = 0;
556 Utils.LongToUInts(realHandle, out ux, out uy);
557 x = (int)(ux / Constants.RegionSize);
558 y = (int)(uy / Constants.RegionSize);
559
560 if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - x) >= 4096) ||
561 (Math.Abs((int)m_scene.RegionInfo.RegionLocY - y) >= 4096))
562 {
563 return false;
564 }
565 return true;
566 }
567
568 public bool CheckCoords(uint thisx, uint thisy, int x, int y)
569 {
570 if ((thisx == x) && (thisy == y))
571 return false;
572 return true;
573 }
574
575 public GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor)
576 {
577 return TryLinkRegion((Scene)client.Scene, client, regionDescriptor);
578 }
579
580 public GridRegion GetHyperlinkRegion(ulong handle)
581 {
582 foreach (GridRegion r in m_HyperlinkRegions.Values)
583 if (r.RegionHandle == handle)
584 return r;
585 foreach (GridRegion r in m_knownRegions.Values)
586 if (r.RegionHandle == handle)
587 return r;
588 return null;
589 }
590
591 public ulong FindRegionHandle(ulong handle)
592 {
593 foreach (GridRegion r in m_HyperlinkRegions.Values)
594 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
595 return m_HyperlinkHandles[r.RegionID];
596
597 foreach (GridRegion r in m_knownRegions.Values)
598 if ((r.RegionHandle == handle) && (m_HyperlinkHandles.ContainsKey(r.RegionID)))
599 return m_HyperlinkHandles[r.RegionID];
600
601 return handle;
602 }
603
604 public bool SendUserInformation(GridRegion regInfo, AgentCircuitData agentData)
605 {
606 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
607
608 if (uinfo == null)
609 return false;
610
611 if ((IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null)) ||
612 (!IsLocalUser(uinfo) && !IsGoingHome(uinfo, regInfo)))
613 {
614 m_log.Info("[HGrid]: Local user is going to foreign region or foreign user is going elsewhere");
615
616 // Set the position of the region on the remote grid
617// ulong realHandle = FindRegionHandle(regInfo.RegionHandle);
618 uint x = 0, y = 0;
619 Utils.LongToUInts(regInfo.RegionHandle, out x, out y);
620 GridRegion clonedRegion = new GridRegion(regInfo);
621 clonedRegion.RegionLocX = (int)x;
622 clonedRegion.RegionLocY = (int)y;
623
624 // Get the user's home region information and adapt the region handle
625 GridRegion home = GetRegionByUUID(m_aScene.RegionInfo.ScopeID, uinfo.UserProfile.HomeRegionID);
626 if (m_HyperlinkHandles.ContainsKey(uinfo.UserProfile.HomeRegionID))
627 {
628 ulong realHandle = m_HyperlinkHandles[uinfo.UserProfile.HomeRegionID];
629 Utils.LongToUInts(realHandle, out x, out y);
630 m_log.DebugFormat("[HGrid]: Foreign user is going elsewhere. Adjusting home handle from {0}-{1} to {2}-{3}", home.RegionLocX, home.RegionLocY, x, y);
631 home.RegionLocX = (int)x;
632 home.RegionLocY = (int)y;
633 }
634
635 // Get the user's service URLs
636 string serverURI = "";
637 if (uinfo.UserProfile is ForeignUserProfileData)
638 serverURI = Util.ServerURI(((ForeignUserProfileData)uinfo.UserProfile).UserServerURI);
639 string userServer = (serverURI == "") || (serverURI == null) ? LocalUserServerURI : serverURI;
640
641 string assetServer = Util.ServerURI(uinfo.UserProfile.UserAssetURI);
642 if ((assetServer == null) || (assetServer == ""))
643 assetServer = LocalAssetServerURI;
644
645 string inventoryServer = Util.ServerURI(uinfo.UserProfile.UserInventoryURI);
646 if ((inventoryServer == null) || (inventoryServer == ""))
647 inventoryServer = LocalInventoryServerURI;
648
649 if (!m_HypergridServiceConnector.InformRegionOfUser(clonedRegion, agentData, home, userServer, assetServer, inventoryServer))
650 {
651 m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
652 return false;
653 }
654 }
655 //if ((uinfo == null) || !IsGoingHome(uinfo, regInfo))
656 //{
657 // m_log.Info("[HGrid]: User seems to be going to foreign region.");
658 // if (!InformRegionOfUser(regInfo, agentData))
659 // {
660 // m_log.Warn("[HGrid]: Could not inform remote region of transferring user.");
661 // return false;
662 // }
663 //}
664 //else
665 // m_log.Info("[HGrid]: User seems to be going home " + uinfo.UserProfile.FirstName + " " + uinfo.UserProfile.SurName);
666
667 // May need to change agent's name
668 if (IsLocalUser(uinfo) && (GetHyperlinkRegion(regInfo.RegionHandle) != null))
669 {
670 agentData.firstname = agentData.firstname + "." + agentData.lastname;
671 agentData.lastname = "@" + LocalUserServerURI.Replace("http://", ""); ; //HGNetworkServersInfo.Singleton.LocalUserServerURI;
672 }
673
674 return true;
675 }
676
677 public void AdjustUserInformation(AgentCircuitData agentData)
678 {
679 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(agentData.AgentID);
680 if ((uinfo != null) && (uinfo.UserProfile != null) &&
681 (IsLocalUser(uinfo) || !(uinfo.UserProfile is ForeignUserProfileData)))
682 {
683 //m_log.Debug("---------------> Local User!");
684 string[] parts = agentData.firstname.Split(new char[] { '.' });
685 if (parts.Length == 2)
686 {
687 agentData.firstname = parts[0];
688 agentData.lastname = parts[1];
689 }
690 }
691 //else
692 // m_log.Debug("---------------> Foreign User!");
693 }
694
695 // Check if a local user exists with the same UUID as the incoming foreign user
696 public bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome)
697 {
698 comingHome = false;
699
700 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
701 if (uinfo != null)
702 {
703 // uh-oh we have a potential intruder
704 if (uinfo.SessionID != sessionID)
705 // can't have a foreigner with a local UUID
706 return false;
707 else
708 // oh, so it's you! welcome back
709 comingHome = true;
710 }
711
712 // OK, user can come in
713 return true;
714 }
715
716 public void AcceptUser(ForeignUserProfileData user, GridRegion home)
717 {
718 m_aScene.CommsManager.UserProfileCacheService.PreloadUserCache(user);
719 ulong realHandle = home.RegionHandle;
720 // Change the local coordinates
721 // X=0 on the map
722 home.RegionLocX = 0;
723 home.RegionLocY = random.Next(0, 10000) * (int)Constants.RegionSize;
724
725 AddHyperlinkHomeRegion(user.ID, home, realHandle);
726
727 DumpUserData(user);
728 DumpRegionData(home);
729
730 }
731
732 public bool IsLocalUser(UUID userID)
733 {
734 CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID);
735 return IsLocalUser(uinfo);
736 }
737
738 #endregion
739
740 #region IHyperlink Misc
741
742 protected bool IsComingHome(ForeignUserProfileData userData)
743 {
744 return (userData.UserServerURI == LocalUserServerURI);
745 }
746
747 // Is the user going back to the home region or the home grid?
748 protected bool IsGoingHome(CachedUserInfo uinfo, GridRegion rinfo)
749 {
750 if (uinfo == null)
751 return false;
752
753 if (uinfo.UserProfile == null)
754 return false;
755
756 if (!(uinfo.UserProfile is ForeignUserProfileData))
757 // it's a home user, can't be outside to return home
758 return false;
759
760 // OK, it's a foreign user with a ForeignUserProfileData
761 // and is going back to exactly the home region.
762 // We can't check if it's going back to a non-home region
763 // of the home grid. That will be dealt with in the
764 // receiving end
765 return (uinfo.UserProfile.HomeRegionID == rinfo.RegionID);
766 }
767
768 protected bool IsLocalUser(CachedUserInfo uinfo)
769 {
770 if (uinfo == null)
771 return false;
772
773 return !(uinfo.UserProfile is ForeignUserProfileData);
774
775 }
776
777
778 protected bool IsLocalRegion(ulong handle)
779 {
780 return m_LocalScenes.ContainsKey(handle);
781 }
782
783 private void DumpUserData(ForeignUserProfileData userData)
784 {
785 m_log.Info(" ------------ User Data Dump ----------");
786 m_log.Info(" >> Name: " + userData.FirstName + " " + userData.SurName);
787 m_log.Info(" >> HomeID: " + userData.HomeRegionID);
788 m_log.Info(" >> UserServer: " + userData.UserServerURI);
789 m_log.Info(" >> InvServer: " + userData.UserInventoryURI);
790 m_log.Info(" >> AssetServer: " + userData.UserAssetURI);
791 m_log.Info(" ------------ -------------- ----------");
792 }
793
794 private void DumpRegionData(GridRegion rinfo)
795 {
796 m_log.Info(" ------------ Region Data Dump ----------");
797 m_log.Info(" >> handle: " + rinfo.RegionHandle);
798 m_log.Info(" >> coords: " + rinfo.RegionLocX + ", " + rinfo.RegionLocY);
799 m_log.Info(" >> external host name: " + rinfo.ExternalHostName);
800 m_log.Info(" >> http port: " + rinfo.HttpPort);
801 m_log.Info(" >> external EP address: " + rinfo.ExternalEndPoint.Address);
802 m_log.Info(" >> external EP port: " + rinfo.ExternalEndPoint.Port);
803 m_log.Info(" ------------ -------------- ----------");
804 }
805
806
807 #endregion
808
809
810 }
811}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 144b5a4..1b00c8a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -238,6 +238,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
238 return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax); 238 return m_GridService.GetRegionRange(scopeID, xmin, xmax, ymin, ymax);
239 } 239 }
240 240
241 public List<GridRegion> GetDefaultRegions(UUID scopeID)
242 {
243 return m_GridService.GetDefaultRegions(scopeID);
244 }
245
246 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
247 {
248 return m_GridService.GetFallbackRegions(scopeID, x, y);
249 }
250
251 public int GetRegionFlags(UUID scopeID, UUID regionID)
252 {
253 return m_GridService.GetRegionFlags(scopeID, regionID);
254 }
255
241 #endregion 256 #endregion
242 257
243 public void NeighboursCommand(string module, string[] cmdparams) 258 public void NeighboursCommand(string module, string[] cmdparams)
@@ -250,5 +265,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
250 m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); 265 m_log.InfoFormat(" {0} @ {1}={2}", r.RegionName, r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
251 } 266 }
252 } 267 }
268
253 } 269 }
254} 270}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
index 391e7c8..2c234d2 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
@@ -188,9 +188,26 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
188 return rinfo; 188 return rinfo;
189 } 189 }
190 190
191 // Let's not override GetRegionsByName -- let's get them all from the grid server 191 public override List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
192 {
193 List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber);
194 List<GridRegion> grinfo = base.GetRegionsByName(scopeID, name, maxNumber);
195
196 if (grinfo != null)
197 rinfo.AddRange(grinfo);
198 return rinfo;
199 }
200
192 // Let's not override GetRegionRange -- let's get them all from the grid server 201 // Let's not override GetRegionRange -- let's get them all from the grid server
193 202
203 public override int GetRegionFlags(UUID scopeID, UUID regionID)
204 {
205 int flags = m_LocalGridService.GetRegionFlags(scopeID, regionID);
206 if (flags == -1)
207 flags = base.GetRegionFlags(scopeID, regionID);
208
209 return flags;
210 }
194 #endregion 211 #endregion
195 } 212 }
196} 213}