aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs103
1 files changed, 101 insertions, 2 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
index 8cc707c..cb05092 100644
--- a/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapSearchModule.cs
@@ -27,9 +27,11 @@
27using System; 27using System;
28using System.Reflection; 28using System.Reflection;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Net;
30using OpenSim.Framework; 31using OpenSim.Framework;
31using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
32using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
34using OpenSim.Region.Environment.Scenes.Hypergrid;
33using OpenMetaverse; 35using OpenMetaverse;
34using log4net; 36using log4net;
35using Nini.Config; 37using Nini.Config;
@@ -42,11 +44,17 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
42 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 44 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 45
44 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;
45 48
46 #region IRegionModule Members 49 #region IRegionModule Members
47 public void Initialise(Scene scene, IConfigSource source) 50 public void Initialise(Scene scene, IConfigSource source)
48 { 51 {
49 if (m_scene == null) m_scene = scene; 52 if (m_scene == null)
53 {
54 m_scene = scene;
55 random = new Random();
56 }
57
50 scene.EventManager.OnNewClient += OnNewClient; 58 scene.EventManager.OnNewClient += OnNewClient;
51 } 59 }
52 60
@@ -95,6 +103,17 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
95 if (info != null) regionInfos.Add(info); 103 if (info != null) regionInfos.Add(info);
96 } 104 }
97 105
106 if ((regionInfos.Count == 0) && IsHypergridOn())
107 {
108 // OK, we tried but there are no regions matching that name.
109 // Let's check quickly if this is a domain name, and if so link to it
110 if (mapName.Contains(".") && mapName.Contains(":"))
111 {
112 // It probably is a domain name. Try to link to it.
113 TryLinkRegion(mapName, regionInfos);
114 }
115 }
116
98 List<MapBlockData> blocks = new List<MapBlockData>(); 117 List<MapBlockData> blocks = new List<MapBlockData>();
99 118
100 MapBlockData data; 119 MapBlockData data;
@@ -105,7 +124,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
105 data = new MapBlockData(); 124 data = new MapBlockData();
106 data.Agents = 0; 125 data.Agents = 0;
107 data.Access = 21; // TODO what's this? 126 data.Access = 21; // TODO what's this?
108 data.MapImageId = info.RegionSettings.TerrainImageID; 127 data.MapImageId = info.RegionSettings.TerrainImageID;
109 data.Name = info.RegionName; 128 data.Name = info.RegionName;
110 data.RegionFlags = 0; // TODO not used? 129 data.RegionFlags = 0; // TODO not used?
111 data.WaterHeight = 0; // not used 130 data.WaterHeight = 0; // not used
@@ -129,5 +148,85 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
129 148
130 remoteClient.SendMapBlock(blocks, 0); 149 remoteClient.SendMapBlock(blocks, 0);
131 } 150 }
151
152 private bool IsHypergridOn()
153 {
154 return (m_scene.SceneGridService is HGSceneCommunicationService);
155 }
156
157 private void TryLinkRegion(string mapName, List<RegionInfo> regionInfos)
158 {
159 string host = "127.0.0.1";
160 string portstr;
161 uint port = 9000;
162 string[] parts = mapName.Split(new char[] { ':' });
163 if (parts.Length >= 1)
164 {
165 host = parts[0];
166 }
167 if (parts.Length >= 2)
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(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(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);
223 return false;
224 }
225
226 m_log.Debug("[HGrid] Dynamic link region succeeded");
227
228 return true;
229 }
230
132 } 231 }
133} 232}