diff options
author | Diva Canto | 2010-01-16 21:42:44 -0800 |
---|---|---|
committer | Diva Canto | 2010-01-16 21:42:44 -0800 |
commit | 04e29c1bacbc1e2df980ae15896a847ce7535da2 (patch) | |
tree | e799d2837af1a41bc2c3b2d571201e9a8a6d7ae7 /OpenSim/Services/HypergridService | |
parent | Finished moving object crossings into EntityTransferModule (diff) | |
download | opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.zip opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.gz opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.bz2 opensim-SC-04e29c1bacbc1e2df980ae15896a847ce7535da2.tar.xz |
Beginning of rewriting HG. Compiles, and runs, but HG functions not restored yet.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/HypergridService/GatekeeperService.cs | 167 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/HGCommands.cs (renamed from OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs) | 90 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/HypergridService.cs | 415 | ||||
-rw-r--r-- | OpenSim/Services/HypergridService/HypergridServiceBase.cs | 84 |
4 files changed, 718 insertions, 38 deletions
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs new file mode 100644 index 0000000..174174c --- /dev/null +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs | |||
@@ -0,0 +1,167 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Services.Interfaces; | ||
7 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
8 | using OpenSim.Server.Base; | ||
9 | |||
10 | using OpenMetaverse; | ||
11 | |||
12 | using Nini.Config; | ||
13 | using log4net; | ||
14 | |||
15 | namespace OpenSim.Services.HypergridService | ||
16 | { | ||
17 | public class GatekeeperService : IGatekeeperService | ||
18 | { | ||
19 | private static readonly ILog m_log = | ||
20 | LogManager.GetLogger( | ||
21 | MethodBase.GetCurrentMethod().DeclaringType); | ||
22 | |||
23 | IGridService m_GridService; | ||
24 | IPresenceService m_PresenceService; | ||
25 | IAuthenticationService m_AuthenticationService; | ||
26 | IUserAccountService m_UserAccountService; | ||
27 | ISimulationService m_SimulationService; | ||
28 | |||
29 | string m_AuthDll; | ||
30 | |||
31 | UUID m_ScopeID; | ||
32 | bool m_AllowTeleportsToAnyRegion; | ||
33 | GridRegion m_DefaultGatewayRegion; | ||
34 | |||
35 | public GatekeeperService(IConfigSource config, ISimulationService simService) | ||
36 | { | ||
37 | IConfig serverConfig = config.Configs["GatekeeperService"]; | ||
38 | if (serverConfig == null) | ||
39 | throw new Exception(String.Format("No section GatekeeperService in config file")); | ||
40 | |||
41 | string accountService = serverConfig.GetString("UserAccountService", String.Empty); | ||
42 | string gridService = serverConfig.GetString("GridService", String.Empty); | ||
43 | string presenceService = serverConfig.GetString("PresenceService", String.Empty); | ||
44 | string simulationService = serverConfig.GetString("SimulationService", String.Empty); | ||
45 | |||
46 | m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty); | ||
47 | |||
48 | if (accountService == string.Empty || gridService == string.Empty || | ||
49 | presenceService == string.Empty || m_AuthDll == string.Empty) | ||
50 | throw new Exception("Incomplete specifications, Gatekeeper Service cannot function."); | ||
51 | |||
52 | string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString()); | ||
53 | UUID.TryParse(scope, out m_ScopeID); | ||
54 | //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!"); | ||
55 | m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true); | ||
56 | |||
57 | Object[] args = new Object[] { config }; | ||
58 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); | ||
59 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
60 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); | ||
61 | if (simService != null) | ||
62 | m_SimulationService = simService; | ||
63 | else if (simulationService != string.Empty) | ||
64 | m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args); | ||
65 | |||
66 | if (m_UserAccountService == null || m_GridService == null || | ||
67 | m_PresenceService == null || m_SimulationService == null) | ||
68 | throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function."); | ||
69 | |||
70 | m_log.Debug("[GATEKEEPER SERVICE]: Starting..."); | ||
71 | } | ||
72 | |||
73 | public GatekeeperService(IConfigSource config) | ||
74 | : this(config, null) | ||
75 | { | ||
76 | } | ||
77 | |||
78 | public bool LinkRegion(string regionName, out UUID regionID, out ulong regionHandle, out string imageURL, out string reason) | ||
79 | { | ||
80 | regionID = m_DefaultGatewayRegion.RegionID; | ||
81 | regionHandle = m_DefaultGatewayRegion.RegionHandle; | ||
82 | imageURL = string.Empty; | ||
83 | reason = string.Empty; | ||
84 | |||
85 | if (!m_AllowTeleportsToAnyRegion) | ||
86 | { | ||
87 | regionID = m_DefaultGatewayRegion.RegionID; | ||
88 | regionHandle = m_DefaultGatewayRegion.RegionHandle; | ||
89 | if (regionName != string.Empty) | ||
90 | { | ||
91 | reason = "Direct links to regions not allowed"; | ||
92 | return false; | ||
93 | } | ||
94 | |||
95 | return true; | ||
96 | } | ||
97 | |||
98 | GridRegion region = m_GridService.GetRegionByName(m_ScopeID, regionName); | ||
99 | if (region == null) | ||
100 | { | ||
101 | reason = "Region not found"; | ||
102 | return false; | ||
103 | } | ||
104 | |||
105 | regionID = region.RegionID; | ||
106 | regionHandle = region.RegionHandle; | ||
107 | string regionimage = "regionImage" + region.RegionID.ToString(); | ||
108 | regionimage = regionimage.Replace("-", ""); | ||
109 | |||
110 | imageURL = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/index.php?method=" + regionimage; | ||
111 | |||
112 | return true; | ||
113 | } | ||
114 | |||
115 | public GridRegion GetHyperlinkRegion(UUID regionID) | ||
116 | { | ||
117 | if (!m_AllowTeleportsToAnyRegion) | ||
118 | // Don't even check the given regionID | ||
119 | return m_DefaultGatewayRegion; | ||
120 | |||
121 | GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID); | ||
122 | return region; | ||
123 | } | ||
124 | |||
125 | public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination) | ||
126 | { | ||
127 | if (!Authenticate(aCircuit)) | ||
128 | return false; | ||
129 | |||
130 | // Check to see if we have a local user with that UUID | ||
131 | UserAccount account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); | ||
132 | if (account != null) | ||
133 | // No, sorry; go away | ||
134 | return false; | ||
135 | |||
136 | // May want to authorize | ||
137 | |||
138 | // Login the presence | ||
139 | if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) | ||
140 | return false; | ||
141 | |||
142 | // Finally launch the agent at the destination | ||
143 | string reason = string.Empty; | ||
144 | return m_SimulationService.CreateAgent(destination, aCircuit, 0, out reason); | ||
145 | } | ||
146 | |||
147 | public bool LoginAttachments(ISceneObject sog, GridRegion destination) | ||
148 | { | ||
149 | // May want to filter attachments | ||
150 | return m_SimulationService.CreateObject(destination, sog, false); | ||
151 | } | ||
152 | |||
153 | protected bool Authenticate(AgentCircuitData aCircuit) | ||
154 | { | ||
155 | string authURL = string.Empty; // GetAuthURL(aCircuit); | ||
156 | if (authURL == string.Empty) | ||
157 | return false; | ||
158 | |||
159 | Object[] args = new Object[] { authURL }; | ||
160 | IAuthenticationService authService = ServerUtils.LoadPlugin<IAuthenticationService>(m_AuthDll, args); | ||
161 | if (authService != null) | ||
162 | return authService.Verify(aCircuit.AgentID, aCircuit.SecureSessionID.ToString(), 30); | ||
163 | |||
164 | return false; | ||
165 | } | ||
166 | } | ||
167 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Services/HypergridService/HGCommands.cs index 0974372..10d04ff 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs +++ b/OpenSim/Services/HypergridService/HGCommands.cs | |||
@@ -34,41 +34,52 @@ using Nini.Config; | |||
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | //using OpenSim.Framework.Communications; | 35 | //using OpenSim.Framework.Communications; |
36 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
37 | using OpenSim.Region.Framework; | 37 | using OpenSim.Services.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
41 | 39 | ||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | 40 | namespace OpenSim.Services.HypergridService |
43 | { | 41 | { |
44 | public class HGCommands | 42 | public class HGCommands |
45 | { | 43 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | private HGGridConnector m_HGGridConnector; | 45 | private HypergridService m_HypergridService; |
48 | private Scene m_scene; | ||
49 | 46 | ||
50 | private static uint m_autoMappingX = 0; | 47 | private static uint m_autoMappingX = 0; |
51 | private static uint m_autoMappingY = 0; | 48 | private static uint m_autoMappingY = 0; |
52 | private static bool m_enableAutoMapping = false; | 49 | private static bool m_enableAutoMapping = false; |
53 | 50 | ||
54 | public HGCommands(HGGridConnector hgConnector, Scene scene) | 51 | public HGCommands(HypergridService service) |
55 | { | 52 | { |
56 | m_HGGridConnector = hgConnector; | 53 | m_HypergridService = service; |
57 | m_scene = scene; | ||
58 | } | 54 | } |
59 | 55 | ||
60 | //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager, | 56 | public void HandleShow(string module, string[] cmd) |
61 | // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version) | 57 | { |
62 | //{ | 58 | if (cmd.Length != 2) |
63 | // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices); | 59 | { |
64 | 60 | MainConsole.Instance.Output("Syntax: show hyperlinks"); | |
65 | // return | 61 | return; |
66 | // new HGScene( | 62 | } |
67 | // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager, | 63 | List<GridRegion> regions = new List<GridRegion>(m_HypergridService.m_HyperlinkRegions.Values); |
68 | // m_moduleLoader, false, m_configSettings.PhysicalPrim, | 64 | if (regions == null || regions.Count < 1) |
69 | // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version); | 65 | { |
70 | //} | 66 | MainConsole.Instance.Output("No hyperlinks"); |
67 | return; | ||
68 | } | ||
71 | 69 | ||
70 | MainConsole.Instance.Output("Region Name Region UUID"); | ||
71 | MainConsole.Instance.Output("Location URI"); | ||
72 | MainConsole.Instance.Output("Owner ID Flags"); | ||
73 | MainConsole.Instance.Output("-------------------------------------------------------------------------------"); | ||
74 | foreach (GridRegion r in regions) | ||
75 | { | ||
76 | MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} \n\n", | ||
77 | r.RegionName, r.RegionID, | ||
78 | String.Format("{0},{1}", r.RegionLocX, r.RegionLocY), "http://" + r.ExternalHostName + ":" + r.HttpPort.ToString(), | ||
79 | r.EstateOwner.ToString())); | ||
80 | } | ||
81 | return; | ||
82 | } | ||
72 | public void RunCommand(string module, string[] cmdparams) | 83 | public void RunCommand(string module, string[] cmdparams) |
73 | { | 84 | { |
74 | List<string> args = new List<string>(cmdparams); | 85 | List<string> args = new List<string>(cmdparams); |
@@ -133,13 +144,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
133 | for (int i = 3; i < cmdparams.Length; i++) | 144 | for (int i = 3; i < cmdparams.Length; i++) |
134 | mapName += " " + cmdparams[i]; | 145 | mapName += " " + cmdparams[i]; |
135 | 146 | ||
136 | m_log.Info(">> MapName: " + mapName); | 147 | //m_log.Info(">> MapName: " + mapName); |
137 | //internalPort = Convert.ToUInt32(cmdparams[4]); | ||
138 | //remotingPort = Convert.ToUInt32(cmdparams[5]); | ||
139 | } | 148 | } |
140 | catch (Exception e) | 149 | catch (Exception e) |
141 | { | 150 | { |
142 | m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); | 151 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); |
143 | LinkRegionCmdUsage(); | 152 | LinkRegionCmdUsage(); |
144 | return; | 153 | return; |
145 | } | 154 | } |
@@ -147,7 +156,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
147 | // Convert cell coordinates given by the user to meters | 156 | // Convert cell coordinates given by the user to meters |
148 | xloc = xloc * (int)Constants.RegionSize; | 157 | xloc = xloc * (int)Constants.RegionSize; |
149 | yloc = yloc * (int)Constants.RegionSize; | 158 | yloc = yloc * (int)Constants.RegionSize; |
150 | m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc); | 159 | string reason = string.Empty; |
160 | if (m_HypergridService.TryLinkRegionToCoords(mapName, xloc, yloc, out reason) == null) | ||
161 | MainConsole.Instance.Output("Failed to link region: " + reason); | ||
151 | } | 162 | } |
152 | else | 163 | else |
153 | { | 164 | { |
@@ -167,7 +178,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
167 | } | 178 | } |
168 | catch (Exception e) | 179 | catch (Exception e) |
169 | { | 180 | { |
170 | m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message); | 181 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); |
171 | LinkRegionCmdUsage(); | 182 | LinkRegionCmdUsage(); |
172 | return; | 183 | return; |
173 | } | 184 | } |
@@ -175,7 +186,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
175 | // Convert cell coordinates given by the user to meters | 186 | // Convert cell coordinates given by the user to meters |
176 | xloc = xloc * (int)Constants.RegionSize; | 187 | xloc = xloc * (int)Constants.RegionSize; |
177 | yloc = yloc * (int)Constants.RegionSize; | 188 | yloc = yloc * (int)Constants.RegionSize; |
178 | if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo)) | 189 | string reason = string.Empty; |
190 | if (m_HypergridService.TryCreateLink(xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason)) | ||
179 | { | 191 | { |
180 | if (cmdparams.Length >= 5) | 192 | if (cmdparams.Length >= 5) |
181 | { | 193 | { |
@@ -194,10 +206,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
194 | UnlinkRegionCmdUsage(); | 206 | UnlinkRegionCmdUsage(); |
195 | return; | 207 | return; |
196 | } | 208 | } |
197 | if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0])) | 209 | if (m_HypergridService.TryUnlinkRegion(cmdparams[0])) |
198 | m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]); | 210 | MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]); |
199 | else | 211 | else |
200 | m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]); | 212 | MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found."); |
201 | } | 213 | } |
202 | } | 214 | } |
203 | 215 | ||
@@ -276,27 +288,29 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid | |||
276 | { | 288 | { |
277 | xloc = xloc * (int)Constants.RegionSize; | 289 | xloc = xloc * (int)Constants.RegionSize; |
278 | yloc = yloc * (int)Constants.RegionSize; | 290 | yloc = yloc * (int)Constants.RegionSize; |
279 | if ( | 291 | string reason = string.Empty; |
280 | m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, | 292 | if (m_HypergridService.TryCreateLink(xloc, yloc, "", externalPort, |
281 | externalHostName, out regInfo)) | 293 | externalHostName, out regInfo, out reason)) |
282 | { | 294 | { |
283 | regInfo.RegionName = config.GetString("localName", ""); | 295 | regInfo.RegionName = config.GetString("localName", ""); |
284 | } | 296 | } |
297 | else | ||
298 | MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason); | ||
285 | } | 299 | } |
286 | } | 300 | } |
287 | 301 | ||
288 | 302 | ||
289 | private void LinkRegionCmdUsage() | 303 | private void LinkRegionCmdUsage() |
290 | { | 304 | { |
291 | m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]"); | 305 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]"); |
292 | m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]"); | 306 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]"); |
293 | m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]"); | 307 | MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]"); |
294 | } | 308 | } |
295 | 309 | ||
296 | private void UnlinkRegionCmdUsage() | 310 | private void UnlinkRegionCmdUsage() |
297 | { | 311 | { |
298 | m_log.Info("Usage: unlink-region <HostName>:<HttpPort>"); | 312 | MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>"); |
299 | m_log.Info("Usage: unlink-region <LocalName>"); | 313 | MainConsole.Instance.Output("Usage: unlink-region <LocalName>"); |
300 | } | 314 | } |
301 | 315 | ||
302 | } | 316 | } |
diff --git a/OpenSim/Services/HypergridService/HypergridService.cs b/OpenSim/Services/HypergridService/HypergridService.cs new file mode 100644 index 0000000..747b98a --- /dev/null +++ b/OpenSim/Services/HypergridService/HypergridService.cs | |||
@@ -0,0 +1,415 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using log4net; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenSim.Services.Connectors.Hypergrid; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Services.HypergridService | ||
44 | { | ||
45 | public class HypergridService : HypergridServiceBase, IHypergridService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private static HypergridService m_RootInstance = null; | ||
52 | protected IConfigSource m_config; | ||
53 | |||
54 | protected IAuthenticationService m_AuthenticationService = null; | ||
55 | protected IGridService m_GridService; | ||
56 | protected IAssetService m_AssetService; | ||
57 | protected HypergridServiceConnector m_HypergridConnector; | ||
58 | |||
59 | protected bool m_AllowDuplicateNames = false; | ||
60 | protected UUID m_ScopeID = UUID.Zero; | ||
61 | |||
62 | // Hyperlink regions are hyperlinks on the map | ||
63 | public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>(); | ||
64 | protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>(); | ||
65 | |||
66 | protected GridRegion m_DefaultRegion; | ||
67 | protected GridRegion DefaultRegion | ||
68 | { | ||
69 | get | ||
70 | { | ||
71 | if (m_DefaultRegion == null) | ||
72 | { | ||
73 | List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); | ||
74 | if (defs != null && defs.Count > 0) | ||
75 | m_DefaultRegion = defs[0]; | ||
76 | else | ||
77 | { | ||
78 | // Best guess, may be totally off | ||
79 | m_DefaultRegion = new GridRegion(1000, 1000); | ||
80 | m_log.WarnFormat("[HYPERGRID SERVICE]: This grid does not have a default region. Assuming default coordinates at 1000, 1000."); | ||
81 | } | ||
82 | } | ||
83 | return m_DefaultRegion; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | public HypergridService(IConfigSource config) | ||
88 | : base(config) | ||
89 | { | ||
90 | m_log.DebugFormat("[HYPERGRID SERVICE]: Starting..."); | ||
91 | |||
92 | m_config = config; | ||
93 | IConfig gridConfig = config.Configs["HypergridService"]; | ||
94 | if (gridConfig != null) | ||
95 | { | ||
96 | string gridService = gridConfig.GetString("GridService", string.Empty); | ||
97 | string authService = gridConfig.GetString("AuthenticationService", String.Empty); | ||
98 | string assetService = gridConfig.GetString("AssetService", string.Empty); | ||
99 | |||
100 | Object[] args = new Object[] { config }; | ||
101 | if (gridService != string.Empty) | ||
102 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
103 | |||
104 | if (m_GridService == null) | ||
105 | throw new Exception("HypergridService cannot function without a GridService"); | ||
106 | |||
107 | if (authService != String.Empty) | ||
108 | m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); | ||
109 | |||
110 | if (assetService != string.Empty) | ||
111 | m_AssetService = ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
112 | |||
113 | m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); | ||
114 | |||
115 | string scope = gridConfig.GetString("ScopeID", string.Empty); | ||
116 | if (scope != string.Empty) | ||
117 | UUID.TryParse(scope, out m_ScopeID); | ||
118 | |||
119 | m_HypergridConnector = new HypergridServiceConnector(m_AssetService); | ||
120 | |||
121 | m_log.DebugFormat("[HYPERGRID SERVICE]: Loaded all services..."); | ||
122 | } | ||
123 | |||
124 | if (m_RootInstance == null) | ||
125 | { | ||
126 | m_RootInstance = this; | ||
127 | |||
128 | HGCommands hgCommands = new HGCommands(this); | ||
129 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region", | ||
130 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | ||
131 | "Link a hypergrid region", hgCommands.RunCommand); | ||
132 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "unlink-region", | ||
133 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
134 | "Unlink a hypergrid region", hgCommands.RunCommand); | ||
135 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>", | ||
136 | "Set local coordinate to map HG regions to", hgCommands.RunCommand); | ||
137 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "show hyperlinks", "show hyperlinks <cr>", | ||
138 | "List the HG regions", hgCommands.HandleShow); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | #region Link Region | ||
143 | |||
144 | public bool LinkRegion(string regionDescriptor, out UUID regionID, out ulong regionHandle, out string imageURL, out string reason) | ||
145 | { | ||
146 | regionID = UUID.Zero; | ||
147 | imageURL = string.Empty; | ||
148 | regionHandle = 0; | ||
149 | reason = string.Empty; | ||
150 | int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize; | ||
151 | GridRegion region = TryLinkRegionToCoords(regionDescriptor, xloc, 0, out reason); | ||
152 | if (region == null) | ||
153 | return false; | ||
154 | |||
155 | regionID = region.RegionID; | ||
156 | regionHandle = region.RegionHandle; | ||
157 | return true; | ||
158 | } | ||
159 | |||
160 | private static Random random = new Random(); | ||
161 | |||
162 | // From the command line link-region | ||
163 | public GridRegion TryLinkRegionToCoords(string mapName, int xloc, int yloc, out string reason) | ||
164 | { | ||
165 | reason = string.Empty; | ||
166 | string host = "127.0.0.1"; | ||
167 | string portstr; | ||
168 | string regionName = ""; | ||
169 | uint port = 9000; | ||
170 | string[] parts = mapName.Split(new char[] { ':' }); | ||
171 | if (parts.Length >= 1) | ||
172 | { | ||
173 | host = parts[0]; | ||
174 | } | ||
175 | if (parts.Length >= 2) | ||
176 | { | ||
177 | portstr = parts[1]; | ||
178 | //m_log.Debug("-- port = " + portstr); | ||
179 | if (!UInt32.TryParse(portstr, out port)) | ||
180 | regionName = parts[1]; | ||
181 | } | ||
182 | // always take the last one | ||
183 | if (parts.Length >= 3) | ||
184 | { | ||
185 | regionName = parts[2]; | ||
186 | } | ||
187 | |||
188 | // Sanity check. Don't ever link to this sim. | ||
189 | IPAddress ipaddr = null; | ||
190 | try | ||
191 | { | ||
192 | ipaddr = Util.GetHostFromDNS(host); | ||
193 | } | ||
194 | catch { } | ||
195 | |||
196 | GridRegion regInfo; | ||
197 | bool success = TryCreateLink(xloc, yloc, regionName, port, host, out regInfo, out reason); | ||
198 | if (success) | ||
199 | { | ||
200 | regInfo.RegionName = mapName; | ||
201 | return regInfo; | ||
202 | } | ||
203 | |||
204 | return null; | ||
205 | } | ||
206 | |||
207 | |||
208 | // From the command line and the 2 above | ||
209 | public bool TryCreateLink(int xloc, int yloc, | ||
210 | string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason) | ||
211 | { | ||
212 | m_log.DebugFormat("[HYPERGRID SERVICE]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); | ||
213 | |||
214 | reason = string.Empty; | ||
215 | regInfo = new GridRegion(); | ||
216 | regInfo.RegionName = externalRegionName; | ||
217 | regInfo.HttpPort = externalPort; | ||
218 | regInfo.ExternalHostName = externalHostName; | ||
219 | regInfo.RegionLocX = xloc; | ||
220 | regInfo.RegionLocY = yloc; | ||
221 | |||
222 | try | ||
223 | { | ||
224 | regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); | ||
225 | } | ||
226 | catch (Exception e) | ||
227 | { | ||
228 | m_log.Warn("[HYPERGRID SERVICE]: Wrong format for link-region: " + e.Message); | ||
229 | reason = "Internal error"; | ||
230 | return false; | ||
231 | } | ||
232 | |||
233 | // Finally, link it | ||
234 | ulong handle = 0; | ||
235 | UUID regionID = UUID.Zero; | ||
236 | string imageURL = string.Empty; | ||
237 | if (!m_HypergridConnector.LinkRegion(regInfo, out regionID, out handle, out imageURL, out reason)) | ||
238 | return false; | ||
239 | |||
240 | if (regionID != UUID.Zero) | ||
241 | { | ||
242 | regInfo.RegionID = regionID; | ||
243 | |||
244 | AddHyperlinkRegion(regInfo, handle); | ||
245 | m_log.Info("[HYPERGRID SERVICE]: Successfully linked to region_uuid " + regInfo.RegionID); | ||
246 | |||
247 | // Try get the map image | ||
248 | regInfo.TerrainImage = m_HypergridConnector.GetMapImage(regionID, imageURL); | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | m_log.Warn("[HYPERGRID SERVICE]: Unable to link region"); | ||
253 | reason = "Remote region could not be found"; | ||
254 | return false; | ||
255 | } | ||
256 | |||
257 | uint x, y; | ||
258 | if (!Check4096(regInfo, out x, out y)) | ||
259 | { | ||
260 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
261 | reason = "Region is too far (" + x + ", " + y + ")"; | ||
262 | m_log.Info("[HYPERGRID SERVICE]: Unable to link, region is too far (" + x + ", " + y + ")"); | ||
263 | return false; | ||
264 | } | ||
265 | |||
266 | m_log.Debug("[HYPERGRID SERVICE]: link region succeeded"); | ||
267 | return true; | ||
268 | } | ||
269 | |||
270 | public bool TryUnlinkRegion(string mapName) | ||
271 | { | ||
272 | GridRegion regInfo = null; | ||
273 | if (mapName.Contains(":")) | ||
274 | { | ||
275 | string host = "127.0.0.1"; | ||
276 | //string portstr; | ||
277 | //string regionName = ""; | ||
278 | uint port = 9000; | ||
279 | string[] parts = mapName.Split(new char[] { ':' }); | ||
280 | if (parts.Length >= 1) | ||
281 | { | ||
282 | host = parts[0]; | ||
283 | } | ||
284 | |||
285 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
286 | if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) | ||
287 | regInfo = r; | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
292 | if (r.RegionName.Equals(mapName)) | ||
293 | regInfo = r; | ||
294 | } | ||
295 | if (regInfo != null) | ||
296 | { | ||
297 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
298 | return true; | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | m_log.InfoFormat("[HYPERGRID SERVICE]: Region {0} not found", mapName); | ||
303 | return false; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | /// <summary> | ||
308 | /// Cope with this viewer limitation. | ||
309 | /// </summary> | ||
310 | /// <param name="regInfo"></param> | ||
311 | /// <returns></returns> | ||
312 | public bool Check4096(GridRegion regInfo, out uint x, out uint y) | ||
313 | { | ||
314 | GridRegion defRegion = DefaultRegion; | ||
315 | |||
316 | ulong realHandle = m_HyperlinkHandles[regInfo.RegionID]; | ||
317 | uint ux = 0, uy = 0; | ||
318 | Utils.LongToUInts(realHandle, out ux, out uy); | ||
319 | x = ux / Constants.RegionSize; | ||
320 | y = uy / Constants.RegionSize; | ||
321 | |||
322 | if ((Math.Abs((int)defRegion.RegionLocX - ux) >= 4096 * Constants.RegionSize) || | ||
323 | (Math.Abs((int)defRegion.RegionLocY - uy) >= 4096 * Constants.RegionSize)) | ||
324 | { | ||
325 | return false; | ||
326 | } | ||
327 | return true; | ||
328 | } | ||
329 | |||
330 | private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) | ||
331 | { | ||
332 | m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; | ||
333 | m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; | ||
334 | } | ||
335 | |||
336 | private void RemoveHyperlinkRegion(UUID regionID) | ||
337 | { | ||
338 | // Try the hyperlink collection | ||
339 | if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
340 | { | ||
341 | m_HyperlinkRegions.Remove(regionID); | ||
342 | m_HyperlinkHandles.Remove(regionID); | ||
343 | } | ||
344 | } | ||
345 | |||
346 | #endregion | ||
347 | |||
348 | #region Get Hyperlinks | ||
349 | |||
350 | public GridRegion GetHyperlinkRegion(UUID regionID) | ||
351 | { | ||
352 | //GridRegion region = m_HypergridConnector. | ||
353 | return null; | ||
354 | } | ||
355 | |||
356 | #endregion | ||
357 | |||
358 | #region GetRegionBy X | ||
359 | |||
360 | public GridRegion GetRegionByUUID(UUID regionID) | ||
361 | { | ||
362 | if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
363 | return m_HyperlinkRegions[regionID]; | ||
364 | |||
365 | return null; | ||
366 | } | ||
367 | |||
368 | public GridRegion GetRegionByPosition(int x, int y) | ||
369 | { | ||
370 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
371 | if (r.RegionLocX == x && r.RegionLocY == y) | ||
372 | return r; | ||
373 | |||
374 | return null; | ||
375 | } | ||
376 | |||
377 | public GridRegion GetRegionByName(string name) | ||
378 | { | ||
379 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
380 | if (r.RegionName.ToLower() == name.ToLower()) | ||
381 | return r; | ||
382 | |||
383 | return null; | ||
384 | } | ||
385 | |||
386 | public List<GridRegion> GetRegionsByName(string name) | ||
387 | { | ||
388 | List<GridRegion> regions = new List<GridRegion>(); | ||
389 | |||
390 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
391 | if ((r.RegionName != null) && r.RegionName.ToLower().StartsWith(name.ToLower())) | ||
392 | regions.Add(r); | ||
393 | |||
394 | return regions; | ||
395 | |||
396 | } | ||
397 | |||
398 | public List<GridRegion> GetRegionRange(int xmin, int xmax, int ymin, int ymax) | ||
399 | { | ||
400 | List<GridRegion> regions = new List<GridRegion>(); | ||
401 | |||
402 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
403 | if ((r.RegionLocX > xmin) && (r.RegionLocX < xmax) && | ||
404 | (r.RegionLocY > ymin) && (r.RegionLocY < ymax)) | ||
405 | regions.Add(r); | ||
406 | |||
407 | return regions; | ||
408 | } | ||
409 | |||
410 | #endregion | ||
411 | |||
412 | |||
413 | |||
414 | } | ||
415 | } | ||
diff --git a/OpenSim/Services/HypergridService/HypergridServiceBase.cs b/OpenSim/Services/HypergridService/HypergridServiceBase.cs new file mode 100644 index 0000000..4f91f64 --- /dev/null +++ b/OpenSim/Services/HypergridService/HypergridServiceBase.cs | |||
@@ -0,0 +1,84 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | |||
36 | namespace OpenSim.Services.HypergridService | ||
37 | { | ||
38 | public class HypergridServiceBase : ServiceBase | ||
39 | { | ||
40 | protected IRegionData m_Database = null; | ||
41 | |||
42 | public HypergridServiceBase(IConfigSource config) | ||
43 | : base(config) | ||
44 | { | ||
45 | string dllName = String.Empty; | ||
46 | string connString = String.Empty; | ||
47 | string realm = "TBD"; | ||
48 | |||
49 | // | ||
50 | // Try reading the [DatabaseService] section, if it exists | ||
51 | // | ||
52 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
53 | if (dbConfig != null) | ||
54 | { | ||
55 | if (dllName == String.Empty) | ||
56 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
57 | if (connString == String.Empty) | ||
58 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
59 | } | ||
60 | |||
61 | // | ||
62 | // [HypergridService] section overrides [DatabaseService], if it exists | ||
63 | // | ||
64 | IConfig gridConfig = config.Configs["HypergridService"]; | ||
65 | if (gridConfig != null) | ||
66 | { | ||
67 | dllName = gridConfig.GetString("StorageProvider", dllName); | ||
68 | connString = gridConfig.GetString("ConnectionString", connString); | ||
69 | realm = gridConfig.GetString("Realm", realm); | ||
70 | } | ||
71 | |||
72 | //// | ||
73 | //// We tried, but this doesn't exist. We can't proceed. | ||
74 | //// | ||
75 | //if (dllName.Equals(String.Empty)) | ||
76 | // throw new Exception("No StorageProvider configured"); | ||
77 | |||
78 | //m_Database = LoadPlugin<IRegionData>(dllName, new Object[] { connString, realm }); | ||
79 | //if (m_Database == null) | ||
80 | // throw new Exception("Could not find a storage interface in the given module"); | ||
81 | |||
82 | } | ||
83 | } | ||
84 | } | ||