aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authordiva2009-02-07 16:10:23 +0000
committerdiva2009-02-07 16:10:23 +0000
commitff0fa1290397d96dbf49477a2668fa62e9be22dc (patch)
treee7be5308f5379f5a6d2c0f663ebe0b8aa6bf87f4 /OpenSim/Region/Environment/Modules
parentFix a .NET issue where changing a locked reference would cause a crash (diff)
downloadopensim-SC_OLD-ff0fa1290397d96dbf49477a2668fa62e9be22dc.zip
opensim-SC_OLD-ff0fa1290397d96dbf49477a2668fa62e9be22dc.tar.gz
opensim-SC_OLD-ff0fa1290397d96dbf49477a2668fa62e9be22dc.tar.bz2
opensim-SC_OLD-ff0fa1290397d96dbf49477a2668fa62e9be22dc.tar.xz
Adds support for HG linking to specific regions within an instance. The format is Host:Port:Region. Refactored the linking code from MapSearchModule to HGHyperlink, so that it can be used both by the MapSearchModule and the Console command.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs123
1 files changed, 13 insertions, 110 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
index fcac7e1..43ed1e4 100644
--- a/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
44 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 45
46 Scene m_scene = null; // only need one for communication with GridService 46 Scene m_scene = null; // only need one for communication with GridService
47 private Random random; 47 List<Scene> m_scenes = new List<Scene>();
48 48
49 #region IRegionModule Members 49 #region IRegionModule Members
50 public void Initialise(Scene scene, IConfigSource source) 50 public void Initialise(Scene scene, IConfigSource source)
@@ -52,9 +52,9 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
52 if (m_scene == null) 52 if (m_scene == null)
53 { 53 {
54 m_scene = scene; 54 m_scene = scene;
55 random = new Random();
56 } 55 }
57 56
57 m_scenes.Add(scene);
58 scene.EventManager.OnNewClient += OnNewClient; 58 scene.EventManager.OnNewClient += OnNewClient;
59 } 59 }
60 60
@@ -65,6 +65,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
65 public void Close() 65 public void Close()
66 { 66 {
67 m_scene = null; 67 m_scene = null;
68 m_scenes.Clear();
68 } 69 }
69 70
70 public string Name 71 public string Name
@@ -110,7 +111,11 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
110 if (mapName.Contains(".") && mapName.Contains(":")) 111 if (mapName.Contains(".") && mapName.Contains(":"))
111 { 112 {
112 // It probably is a domain name. Try to link to it. 113 // It probably is a domain name. Try to link to it.
113 TryLinkRegion(remoteClient, mapName, regionInfos); 114 RegionInfo regInfo;
115 Scene cScene = GetClientScene(remoteClient);
116 regInfo = HGHyperlink.TryLinkRegion(cScene, remoteClient, mapName);
117 if (regInfo != null)
118 regionInfos.Add(regInfo);
114 } 119 }
115 } 120 }
116 121
@@ -154,116 +159,14 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
154 return (m_scene.SceneGridService is HGSceneCommunicationService); 159 return (m_scene.SceneGridService is HGSceneCommunicationService);
155 } 160 }
156 161
157 private void TryLinkRegion(IClientAPI client, string mapName, List<RegionInfo> regionInfos) 162 private Scene GetClientScene(IClientAPI client)
158 { 163 {
159 string host = "127.0.0.1"; 164 foreach (Scene s in m_scenes)
160 string portstr;
161 uint port = 9000;
162 string[] parts = mapName.Split(new char[] { ':' });
163 if (parts.Length >= 1)
164 { 165 {
165 host = parts[0]; 166 if (client.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle)
167 return s;
166 } 168 }
167 if (parts.Length >= 2) 169 return m_scene;
168 {
169 portstr = parts[1];
170 UInt32.TryParse(portstr, out port);
171 }
172
173 // Sanity check. Don't ever link to this sim.
174 IPAddress ipaddr = null;
175 try
176 {
177 ipaddr = Util.GetHostFromDNS(host);
178 }
179 catch { }
180
181 if ((ipaddr != null) &&
182 !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port)))
183 {
184 uint xloc = (uint)(random.Next(0, Int16.MaxValue));
185 RegionInfo regInfo;
186 bool success = TryCreateLink(client, xloc, 0, port, host, out regInfo);
187 if (success)
188 {
189 regInfo.RegionName = mapName;
190 regionInfos.Add(regInfo);
191 }
192 }
193 }
194
195 private bool TryCreateLink(IClientAPI client, uint xloc, uint yloc, uint externalPort, string externalHostName, out RegionInfo regInfo)
196 {
197 m_log.DebugFormat("[HGrid]: Dynamic link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc);
198
199 regInfo = new RegionInfo();
200 regInfo.RegionLocX = xloc;
201 regInfo.RegionLocY = yloc;
202 regInfo.ExternalHostName = externalHostName;
203 regInfo.HttpPort = externalPort;
204 try
205 {
206 regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
207 }
208 catch (Exception e)
209 {
210 m_log.Warn("[HGrid] Wrong format for link-region: " + e.Message);
211 return false;
212 }
213 //regInfo.RemotingAddress = regInfo.ExternalEndPoint.Address.ToString();
214
215 // Finally, link it
216 try
217 {
218 m_scene.CommsManager.GridService.RegisterRegion(regInfo);
219 }
220 catch (Exception e)
221 {
222 m_log.Warn("[HGrid] Unable to dynamically link region: " + e.Message);
223 return false;
224 }
225
226 if (!Check4096(client, regInfo))
227 {
228 return false;
229 }
230
231 m_log.Debug("[HGrid] Dynamic link region succeeded");
232 return true;
233 } 170 }
234
235 /// <summary>
236 /// Cope with this viewer limitation.
237 /// </summary>
238 /// <param name="regInfo"></param>
239 /// <returns></returns>
240 private bool Check4096(IClientAPI client, RegionInfo regInfo)
241 {
242 ulong realHandle;
243 if (UInt64.TryParse(regInfo.regionSecret, out realHandle))
244 {
245 uint x, y;
246 Utils.LongToUInts(realHandle, out x, out y);
247 x = x / Constants.RegionSize;
248 y = y / Constants.RegionSize;
249
250 if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) ||
251 (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096))
252 {
253 m_scene.CommsManager.GridService.DeregisterRegion(regInfo);
254 m_log.Debug("[HGrid]: Region deregistered.");
255 client.SendAlertMessage("Region is too far (" + x + ", " + y + ")");
256 return false;
257 }
258 return true;
259 }
260 else
261 {
262 m_scene.CommsManager.GridService.RegisterRegion(regInfo);
263 m_log.Debug("[HGrid]: Gnomes. Region deregistered.");
264 return false;
265 }
266 }
267
268 } 171 }
269} 172}