aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Hypergrid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Hypergrid')
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGHyperlink.cs232
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs3
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs6
3 files changed, 7 insertions, 234 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGHyperlink.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGHyperlink.cs
deleted file mode 100644
index a576feb..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGHyperlink.cs
+++ /dev/null
@@ -1,232 +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.Net;
30using System.Reflection;
31using log4net;
32using OpenMetaverse;
33using OpenSim.Framework;
34
35namespace OpenSim.Region.Framework.Scenes.Hypergrid
36{
37 public class HGHyperlink
38 {
39 private static readonly ILog m_log =
40 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 private static Random random = new Random();
42
43 public static RegionInfo TryLinkRegionToCoords(Scene m_scene, IClientAPI client, string mapName, uint xloc, uint yloc)
44 {
45 string host = "127.0.0.1";
46 string portstr;
47 string regionName = "";
48 uint port = 9000;
49 string[] parts = mapName.Split(new char[] { ':' });
50 if (parts.Length >= 1)
51 {
52 host = parts[0];
53 }
54 if (parts.Length >= 2)
55 {
56 portstr = parts[1];
57 if (!UInt32.TryParse(portstr, out port))
58 regionName = parts[1];
59 }
60 // always take the last one
61 if (parts.Length >= 3)
62 {
63 regionName = parts[2];
64 }
65
66 // Sanity check. Don't ever link to this sim.
67 IPAddress ipaddr = null;
68 try
69 {
70 ipaddr = Util.GetHostFromDNS(host);
71 }
72 catch { }
73
74 if ((ipaddr != null) &&
75 !((m_scene.RegionInfo.ExternalEndPoint.Address.Equals(ipaddr)) && (m_scene.RegionInfo.HttpPort == port)))
76 {
77 RegionInfo regInfo;
78 bool success = TryCreateLink(m_scene, client, xloc, yloc, regionName, port, host, out regInfo);
79 if (success)
80 {
81 regInfo.RegionName = mapName;
82 return regInfo;
83 }
84 }
85
86 return null;
87 }
88
89 public static RegionInfo TryLinkRegion(Scene m_scene, IClientAPI client, string mapName)
90 {
91 uint xloc = (uint)(random.Next(0, Int16.MaxValue));
92 return TryLinkRegionToCoords(m_scene, client, mapName, xloc, 0);
93 }
94
95 public static bool TryCreateLink(Scene m_scene, IClientAPI client, uint xloc, uint yloc,
96 string externalRegionName, uint externalPort, string externalHostName, out RegionInfo regInfo)
97 {
98 m_log.DebugFormat("[HGrid]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc);
99
100 regInfo = new RegionInfo();
101 regInfo.RegionName = externalRegionName;
102 regInfo.HttpPort = externalPort;
103 regInfo.ExternalHostName = externalHostName;
104 regInfo.RegionLocX = xloc;
105 regInfo.RegionLocY = yloc;
106
107 try
108 {
109 regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
110 }
111 catch (Exception e)
112 {
113 m_log.Warn("[HGrid]: Wrong format for link-region: " + e.Message);
114 return false;
115 }
116 regInfo.RemotingAddress = regInfo.ExternalEndPoint.Address.ToString();
117
118 // Finally, link it
119 try
120 {
121 m_scene.CommsManager.GridService.RegisterRegion(regInfo);
122 }
123 catch (Exception e)
124 {
125 m_log.Warn("[HGrid]: Unable to link region: " + e.Message);
126 return false;
127 }
128
129 uint x, y;
130 if (!Check4096(m_scene, regInfo, out x, out y))
131 {
132 m_scene.CommsManager.GridService.DeregisterRegion(regInfo);
133 if (client != null)
134 client.SendAlertMessage("Region is too far (" + x + ", " + y + ")");
135 m_log.Info("[HGrid]: Unable to link, region is too far (" + x + ", " + y + ")");
136 return false;
137 }
138
139 if (!CheckCoords(m_scene.RegionInfo.RegionLocX, m_scene.RegionInfo.RegionLocY, x, y))
140 {
141 m_scene.CommsManager.GridService.DeregisterRegion(regInfo);
142 if (client != null)
143 client.SendAlertMessage("Region has incompatible coordinates (" + x + ", " + y + ")");
144 m_log.Info("[HGrid]: Unable to link, region has incompatible coordinates (" + x + ", " + y + ")");
145 return false;
146 }
147
148 m_log.Debug("[HGrid]: link region succeeded");
149 return true;
150 }
151
152 public static bool TryUnlinkRegion(Scene m_scene, string mapName)
153 {
154 RegionInfo regInfo = null;
155 if (mapName.Contains(":"))
156 {
157 string host = "127.0.0.1";
158 //string portstr;
159 //string regionName = "";
160 uint port = 9000;
161 string[] parts = mapName.Split(new char[] { ':' });
162 if (parts.Length >= 1)
163 {
164 host = parts[0];
165 }
166// if (parts.Length >= 2)
167// {
168// portstr = parts[1];
169// if (!UInt32.TryParse(portstr, out port))
170// regionName = parts[1];
171// }
172 // always take the last one
173// if (parts.Length >= 3)
174// {
175// regionName = parts[2];
176// }
177 regInfo = m_scene.CommsManager.GridService.RequestNeighbourInfo(host, port);
178 }
179 else
180 {
181 regInfo = m_scene.CommsManager.GridService.RequestNeighbourInfo(mapName);
182 }
183 if (regInfo != null)
184 {
185 return m_scene.CommsManager.GridService.DeregisterRegion(regInfo);
186 }
187 else
188 {
189 m_log.InfoFormat("[HGrid]: Region {0} not found", mapName);
190 return false;
191 }
192 }
193
194 /// <summary>
195 /// Cope with this viewer limitation.
196 /// </summary>
197 /// <param name="regInfo"></param>
198 /// <returns></returns>
199 public static bool Check4096(Scene m_scene, RegionInfo regInfo, out uint x, out uint y)
200 {
201 ulong realHandle;
202 if (UInt64.TryParse(regInfo.regionSecret, out realHandle))
203 {
204 Utils.LongToUInts(realHandle, out x, out y);
205 x = x / Constants.RegionSize;
206 y = y / Constants.RegionSize;
207
208 if ((Math.Abs((int)m_scene.RegionInfo.RegionLocX - (int)x) >= 4096) ||
209 (Math.Abs((int)m_scene.RegionInfo.RegionLocY - (int)y) >= 4096))
210 {
211 return false;
212 }
213 return true;
214 }
215 else
216 {
217 m_scene.CommsManager.GridService.RegisterRegion(regInfo);
218 m_log.Debug("[HGrid]: Gnomes. Region deregistered.");
219 x = y = 0;
220 return false;
221 }
222 }
223
224 public static bool CheckCoords(uint thisx, uint thisy, uint x, uint y)
225 {
226 if ((thisx == x) && (thisy == y))
227 return false;
228 return true;
229 }
230
231 }
232}
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs
index bf55df7..b1981b6 100644
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs
+++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.cs
@@ -29,6 +29,7 @@ using OpenMetaverse;
29using OpenSim.Framework; 29using OpenSim.Framework;
30using OpenSim.Framework.Communications.Cache; 30using OpenSim.Framework.Communications.Cache;
31using TPFlags = OpenSim.Framework.Constants.TeleportFlags; 31using TPFlags = OpenSim.Framework.Constants.TeleportFlags;
32using GridRegion = OpenSim.Services.Interfaces.GridRegion;
32 33
33namespace OpenSim.Region.Framework.Scenes.Hypergrid 34namespace OpenSim.Region.Framework.Scenes.Hypergrid
34{ 35{
@@ -50,7 +51,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
50 51
51 if (UserProfile != null) 52 if (UserProfile != null)
52 { 53 {
53 RegionInfo regionInfo = CommsManager.GridService.RequestNeighbourInfo(UserProfile.HomeRegion); 54 GridRegion regionInfo = GridService.GetRegionByUUID(UUID.Zero, UserProfile.HomeRegionID);
54 //if (regionInfo != null) 55 //if (regionInfo != null)
55 //{ 56 //{
56 // UserProfile.HomeRegionID = regionInfo.RegionID; 57 // UserProfile.HomeRegionID = regionInfo.RegionID;
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
index 5c99d73..e8e5e78 100644
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
@@ -38,6 +38,7 @@ using OpenSim.Framework.Communications;
38using OpenSim.Framework.Communications.Cache; 38using OpenSim.Framework.Communications.Cache;
39using OpenSim.Framework.Capabilities; 39using OpenSim.Framework.Capabilities;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41 42
42namespace OpenSim.Region.Framework.Scenes.Hypergrid 43namespace OpenSim.Region.Framework.Scenes.Hypergrid
43{ 44{
@@ -106,7 +107,10 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
106 } 107 }
107 else 108 else
108 { 109 {
109 RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle); 110 uint x = 0, y = 0;
111 Utils.LongToUInts(regionHandle, out x, out y);
112 GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
113
110 if (reg != null) 114 if (reg != null)
111 { 115 {
112 116