diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut')
24 files changed, 1946 insertions, 2288 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs index 0aa753d..af2f3d6 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs | |||
@@ -31,7 +31,7 @@ using System; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications.Cache; | 34 | |
35 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
36 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
@@ -366,18 +366,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset | |||
366 | 366 | ||
367 | public string GetUserAssetServer(UUID userID) | 367 | public string GetUserAssetServer(UUID userID) |
368 | { | 368 | { |
369 | CachedUserInfo uinfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(userID); | 369 | UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, userID); |
370 | if ((uinfo != null) && (uinfo.UserProfile != null)) | 370 | |
371 | { | 371 | if (account != null && account.ServiceURLs.ContainsKey("AssetServerURI") && account.ServiceURLs["AssetServerURI"] != null) |
372 | if ((uinfo.UserProfile.UserAssetURI == string.Empty) || (uinfo.UserProfile.UserAssetURI == "")) | 372 | return account.ServiceURLs["AssetServerURI"].ToString(); |
373 | return m_LocalAssetServiceURI; | 373 | |
374 | return uinfo.UserProfile.UserAssetURI.Trim('/'); | 374 | return string.Empty; |
375 | } | ||
376 | else | ||
377 | { | ||
378 | // we don't know anyting about this user | ||
379 | return string.Empty; | ||
380 | } | ||
381 | } | 375 | } |
382 | 376 | ||
383 | public string GetSimAssetServer() | 377 | public string GetSimAssetServer() |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs new file mode 100644 index 0000000..acc362b --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs | |||
@@ -0,0 +1,164 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication | ||
41 | { | ||
42 | public class LocalAuthenticationServicesConnector : ISharedRegionModule, IAuthenticationService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private IAuthenticationService m_AuthenticationService; | ||
49 | |||
50 | private bool m_Enabled = false; | ||
51 | |||
52 | #region ISharedRegionModule | ||
53 | |||
54 | public Type ReplaceableInterface | ||
55 | { | ||
56 | get { return null; } | ||
57 | } | ||
58 | |||
59 | public string Name | ||
60 | { | ||
61 | get { return "LocalAuthenticationServicesConnector"; } | ||
62 | } | ||
63 | |||
64 | public void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig moduleConfig = source.Configs["Modules"]; | ||
67 | if (moduleConfig != null) | ||
68 | { | ||
69 | string name = moduleConfig.GetString("AuthenticationServices", ""); | ||
70 | if (name == Name) | ||
71 | { | ||
72 | IConfig userConfig = source.Configs["AuthenticationService"]; | ||
73 | if (userConfig == null) | ||
74 | { | ||
75 | m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | string serviceDll = userConfig.GetString("LocalServiceModule", | ||
80 | String.Empty); | ||
81 | |||
82 | if (serviceDll == String.Empty) | ||
83 | { | ||
84 | m_log.Error("[AUTH CONNECTOR]: No LocalServiceModule named in section AuthenticationService"); | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | Object[] args = new Object[] { source }; | ||
89 | m_AuthenticationService = | ||
90 | ServerUtils.LoadPlugin<IAuthenticationService>(serviceDll, | ||
91 | args); | ||
92 | |||
93 | if (m_AuthenticationService == null) | ||
94 | { | ||
95 | m_log.Error("[AUTH CONNECTOR]: Can't load Authentication service"); | ||
96 | return; | ||
97 | } | ||
98 | m_Enabled = true; | ||
99 | m_log.Info("[AUTH CONNECTOR]: Local Authentication connector enabled"); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | public void PostInitialise() | ||
105 | { | ||
106 | if (!m_Enabled) | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | public void Close() | ||
111 | { | ||
112 | if (!m_Enabled) | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | public void AddRegion(Scene scene) | ||
117 | { | ||
118 | if (!m_Enabled) | ||
119 | return; | ||
120 | |||
121 | scene.RegisterModuleInterface<IAuthenticationService>(m_AuthenticationService); | ||
122 | } | ||
123 | |||
124 | public void RemoveRegion(Scene scene) | ||
125 | { | ||
126 | if (!m_Enabled) | ||
127 | return; | ||
128 | } | ||
129 | |||
130 | public void RegionLoaded(Scene scene) | ||
131 | { | ||
132 | if (!m_Enabled) | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | #endregion | ||
137 | |||
138 | #region IAuthenticationService | ||
139 | |||
140 | public string Authenticate(UUID principalID, string password, int lifetime) | ||
141 | { | ||
142 | // Not implemented at the regions | ||
143 | return string.Empty; | ||
144 | } | ||
145 | |||
146 | public bool Verify(UUID principalID, string token, int lifetime) | ||
147 | { | ||
148 | return m_AuthenticationService.Verify(principalID, token, lifetime); | ||
149 | } | ||
150 | |||
151 | public bool Release(UUID principalID, string token) | ||
152 | { | ||
153 | return m_AuthenticationService.Release(principalID, token); | ||
154 | } | ||
155 | |||
156 | public bool SetPassword(UUID principalID, string passwd) | ||
157 | { | ||
158 | return m_AuthenticationService.SetPassword(principalID, passwd); | ||
159 | } | ||
160 | |||
161 | #endregion | ||
162 | |||
163 | } | ||
164 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs index cca5bb4..a053bc2 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/LocalUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs | |||
@@ -26,24 +26,23 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using Nini.Config; | 29 | using Nini.Config; |
30 | using log4net; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Region.Framework.Interfaces; | 32 | using OpenSim.Region.Framework.Interfaces; |
33 | using OpenSim.Region.Framework.Scenes; | 33 | using OpenSim.Region.Framework.Scenes; |
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Services.Interfaces; | 34 | using OpenSim.Services.Interfaces; |
35 | using OpenSim.Services.Connectors; | ||
36 | 36 | ||
37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | 37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication |
38 | { | 38 | { |
39 | public class LocalUserServicesConnector : ISharedRegionModule | 39 | public class RemoteAuthenticationServicesConnector : AuthenticationServicesConnector, |
40 | ISharedRegionModule, IAuthenticationService | ||
40 | { | 41 | { |
41 | private static readonly ILog m_log = | 42 | private static readonly ILog m_log = |
42 | LogManager.GetLogger( | 43 | LogManager.GetLogger( |
43 | MethodBase.GetCurrentMethod().DeclaringType); | 44 | MethodBase.GetCurrentMethod().DeclaringType); |
44 | 45 | ||
45 | private IUserAccountService m_UserService; | ||
46 | |||
47 | private bool m_Enabled = false; | 46 | private bool m_Enabled = false; |
48 | 47 | ||
49 | public Type ReplaceableInterface | 48 | public Type ReplaceableInterface |
@@ -53,45 +52,29 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
53 | 52 | ||
54 | public string Name | 53 | public string Name |
55 | { | 54 | { |
56 | get { return "LocalUserServicesConnector"; } | 55 | get { return "RemoteAuthenticationServicesConnector"; } |
57 | } | 56 | } |
58 | 57 | ||
59 | public void Initialise(IConfigSource source) | 58 | public override void Initialise(IConfigSource source) |
60 | { | 59 | { |
61 | IConfig moduleConfig = source.Configs["Modules"]; | 60 | IConfig moduleConfig = source.Configs["Modules"]; |
62 | if (moduleConfig != null) | 61 | if (moduleConfig != null) |
63 | { | 62 | { |
64 | string name = moduleConfig.GetString("UserServices", ""); | 63 | string name = moduleConfig.GetString("AuthenticationServices", ""); |
65 | if (name == Name) | 64 | if (name == Name) |
66 | { | 65 | { |
67 | IConfig userConfig = source.Configs["UserService"]; | 66 | IConfig userConfig = source.Configs["AuthenticationService"]; |
68 | if (userConfig == null) | 67 | if (userConfig == null) |
69 | { | 68 | { |
70 | m_log.Error("[USER CONNECTOR]: UserService missing from OpenSim.ini"); | 69 | m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpenSim.ini"); |
71 | return; | 70 | return; |
72 | } | 71 | } |
73 | 72 | ||
74 | string serviceDll = userConfig.GetString("LocalServiceModule", | 73 | m_Enabled = true; |
75 | String.Empty); | ||
76 | |||
77 | if (serviceDll == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section UserService"); | ||
80 | return; | ||
81 | } | ||
82 | 74 | ||
83 | Object[] args = new Object[] { source }; | 75 | base.Initialise(source); |
84 | m_UserService = | ||
85 | ServerUtils.LoadPlugin<IUserAccountService>(serviceDll, | ||
86 | args); | ||
87 | 76 | ||
88 | if (m_UserService == null) | 77 | m_log.Info("[AUTH CONNECTOR]: Remote Authentication enabled"); |
89 | { | ||
90 | m_log.Error("[USER CONNECTOR]: Can't load user service"); | ||
91 | return; | ||
92 | } | ||
93 | m_Enabled = true; | ||
94 | m_log.Info("[USER CONNECTOR]: Local user connector enabled"); | ||
95 | } | 78 | } |
96 | } | 79 | } |
97 | } | 80 | } |
@@ -113,7 +96,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
113 | if (!m_Enabled) | 96 | if (!m_Enabled) |
114 | return; | 97 | return; |
115 | 98 | ||
116 | scene.RegisterModuleInterface<IUserAccountService>(m_UserService); | 99 | scene.RegisterModuleInterface<IAuthenticationService>(this); |
117 | } | 100 | } |
118 | 101 | ||
119 | public void RemoveRegion(Scene scene) | 102 | public void RemoveRegion(Scene scene) |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs index 68499f3..01a2615 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs | |||
@@ -139,9 +139,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization | |||
139 | 139 | ||
140 | if (scene != null) | 140 | if (scene != null) |
141 | { | 141 | { |
142 | UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(new UUID(userID)); | 142 | UserAccount account = scene.UserAccountService.GetUserAccount(UUID.Zero, userID); |
143 | isAuthorized = IsAuthorizedForRegion(userID, profile.FirstName, profile.SurName, | 143 | isAuthorized = IsAuthorizedForRegion(userID, account.FirstName, account.LastName, |
144 | profile.Email, scene.RegionInfo.RegionName, regionID, out message); | 144 | account.Email, scene.RegionInfo.RegionName, regionID, out message); |
145 | } | 145 | } |
146 | else | 146 | else |
147 | { | 147 | { |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs new file mode 100644 index 0000000..47f19a3 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs | |||
@@ -0,0 +1,168 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar | ||
41 | { | ||
42 | public class LocalAvatarServicesConnector : ISharedRegionModule, IAvatarService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private IAvatarService m_AvatarService; | ||
49 | |||
50 | private bool m_Enabled = false; | ||
51 | |||
52 | #region ISharedRegionModule | ||
53 | |||
54 | public Type ReplaceableInterface | ||
55 | { | ||
56 | get { return null; } | ||
57 | } | ||
58 | |||
59 | public string Name | ||
60 | { | ||
61 | get { return "LocalAvatarServicesConnector"; } | ||
62 | } | ||
63 | |||
64 | public void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig moduleConfig = source.Configs["Modules"]; | ||
67 | if (moduleConfig != null) | ||
68 | { | ||
69 | string name = moduleConfig.GetString("AvatarServices", ""); | ||
70 | if (name == Name) | ||
71 | { | ||
72 | IConfig userConfig = source.Configs["AvatarService"]; | ||
73 | if (userConfig == null) | ||
74 | { | ||
75 | m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini"); | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | string serviceDll = userConfig.GetString("LocalServiceModule", | ||
80 | String.Empty); | ||
81 | |||
82 | if (serviceDll == String.Empty) | ||
83 | { | ||
84 | m_log.Error("[AVATAR CONNECTOR]: No LocalServiceModule named in section AvatarService"); | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | Object[] args = new Object[] { source }; | ||
89 | m_AvatarService = | ||
90 | ServerUtils.LoadPlugin<IAvatarService>(serviceDll, | ||
91 | args); | ||
92 | |||
93 | if (m_AvatarService == null) | ||
94 | { | ||
95 | m_log.Error("[AVATAR CONNECTOR]: Can't load user account service"); | ||
96 | return; | ||
97 | } | ||
98 | m_Enabled = true; | ||
99 | m_log.Info("[AVATAR CONNECTOR]: Local avatar connector enabled"); | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | public void PostInitialise() | ||
105 | { | ||
106 | if (!m_Enabled) | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | public void Close() | ||
111 | { | ||
112 | if (!m_Enabled) | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | public void AddRegion(Scene scene) | ||
117 | { | ||
118 | if (!m_Enabled) | ||
119 | return; | ||
120 | |||
121 | scene.RegisterModuleInterface<IAvatarService>(this); | ||
122 | } | ||
123 | |||
124 | public void RemoveRegion(Scene scene) | ||
125 | { | ||
126 | if (!m_Enabled) | ||
127 | return; | ||
128 | } | ||
129 | |||
130 | public void RegionLoaded(Scene scene) | ||
131 | { | ||
132 | if (!m_Enabled) | ||
133 | return; | ||
134 | } | ||
135 | |||
136 | #endregion | ||
137 | |||
138 | #region IAvatarService | ||
139 | |||
140 | public AvatarData GetAvatar(UUID userID) | ||
141 | { | ||
142 | return m_AvatarService.GetAvatar(userID); | ||
143 | } | ||
144 | |||
145 | public bool SetAvatar(UUID userID, AvatarData avatar) | ||
146 | { | ||
147 | return m_AvatarService.SetAvatar(userID, avatar); | ||
148 | } | ||
149 | |||
150 | public bool ResetAvatar(UUID userID) | ||
151 | { | ||
152 | return m_AvatarService.ResetAvatar(userID); | ||
153 | } | ||
154 | |||
155 | public bool SetItems(UUID userID, string[] names, string[] values) | ||
156 | { | ||
157 | return m_AvatarService.SetItems(userID, names, values); | ||
158 | } | ||
159 | |||
160 | public bool RemoveItems(UUID userID, string[] names) | ||
161 | { | ||
162 | return m_AvatarService.RemoveItems(userID, names); | ||
163 | } | ||
164 | |||
165 | #endregion | ||
166 | |||
167 | } | ||
168 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs index cef9129..48759b5 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/User/RemoteUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs | |||
@@ -34,10 +34,10 @@ using OpenSim.Region.Framework.Scenes; | |||
34 | using OpenSim.Services.Interfaces; | 34 | using OpenSim.Services.Interfaces; |
35 | using OpenSim.Services.Connectors; | 35 | using OpenSim.Services.Connectors; |
36 | 36 | ||
37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | 37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar |
38 | { | 38 | { |
39 | public class RemoteUserServicesConnector : UserServicesConnector, | 39 | public class RemoteAvatarServicesConnector : AvatarServicesConnector, |
40 | ISharedRegionModule, IUserAccountService | 40 | ISharedRegionModule, IAvatarService |
41 | { | 41 | { |
42 | private static readonly ILog m_log = | 42 | private static readonly ILog m_log = |
43 | LogManager.GetLogger( | 43 | LogManager.GetLogger( |
@@ -52,7 +52,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
52 | 52 | ||
53 | public string Name | 53 | public string Name |
54 | { | 54 | { |
55 | get { return "RemoteUserServicesConnector"; } | 55 | get { return "RemoteAvatarServicesConnector"; } |
56 | } | 56 | } |
57 | 57 | ||
58 | public override void Initialise(IConfigSource source) | 58 | public override void Initialise(IConfigSource source) |
@@ -60,13 +60,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
60 | IConfig moduleConfig = source.Configs["Modules"]; | 60 | IConfig moduleConfig = source.Configs["Modules"]; |
61 | if (moduleConfig != null) | 61 | if (moduleConfig != null) |
62 | { | 62 | { |
63 | string name = moduleConfig.GetString("UserServices", ""); | 63 | string name = moduleConfig.GetString("AvatarServices", ""); |
64 | if (name == Name) | 64 | if (name == Name) |
65 | { | 65 | { |
66 | IConfig userConfig = source.Configs["UserService"]; | 66 | IConfig userConfig = source.Configs["AvatarService"]; |
67 | if (userConfig == null) | 67 | if (userConfig == null) |
68 | { | 68 | { |
69 | m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini"); | 69 | m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpanSim.ini"); |
70 | return; | 70 | return; |
71 | } | 71 | } |
72 | 72 | ||
@@ -74,7 +74,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
74 | 74 | ||
75 | base.Initialise(source); | 75 | base.Initialise(source); |
76 | 76 | ||
77 | m_log.Info("[USER CONNECTOR]: Remote users enabled"); | 77 | m_log.Info("[AVATAR CONNECTOR]: Remote avatars enabled"); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | } | 80 | } |
@@ -96,7 +96,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.User | |||
96 | if (!m_Enabled) | 96 | if (!m_Enabled) |
97 | return; | 97 | return; |
98 | 98 | ||
99 | scene.RegisterModuleInterface<IUserAccountService>(this); | 99 | scene.RegisterModuleInterface<IAvatarService>(this); |
100 | } | 100 | } |
101 | 101 | ||
102 | public void RemoveRegion(Scene scene) | 102 | public void RemoveRegion(Scene scene) |
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | //using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | |||
42 | namespace 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework.Communications.Cache; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
41 | using OpenSim.Server.Base; | ||
42 | using OpenSim.Services.Connectors.Grid; | ||
43 | using OpenSim.Framework.Console; | ||
44 | |||
45 | using OpenMetaverse; | ||
46 | using log4net; | ||
47 | using Nini.Config; | ||
48 | |||
49 | namespace 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 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs deleted file mode 100644 index fa3681a..0000000 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/RESTInterregionComms.cs +++ /dev/null | |||
@@ -1,843 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Framework.Communications.Clients; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Region.Framework.Scenes.Hypergrid; | ||
44 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
47 | |||
48 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | ||
49 | { | ||
50 | public class RESTInterregionComms : ISharedRegionModule, IInterregionCommsOut | ||
51 | { | ||
52 | private bool initialized = false; | ||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | protected bool m_enabled = false; | ||
56 | protected Scene m_aScene; | ||
57 | // RESTInterregionComms does not care about local regions; it delegates that to the Local module | ||
58 | protected LocalInterregionComms m_localBackend; | ||
59 | |||
60 | protected CommunicationsManager m_commsManager; | ||
61 | |||
62 | protected RegionToRegionClient m_regionClient; | ||
63 | |||
64 | protected IHyperlinkService m_hyperlinkService; | ||
65 | |||
66 | protected bool m_safemode; | ||
67 | protected IPAddress m_thisIP; | ||
68 | |||
69 | #region IRegionModule | ||
70 | |||
71 | public virtual void Initialise(IConfigSource config) | ||
72 | { | ||
73 | IConfig startupConfig = config.Configs["Communications"]; | ||
74 | |||
75 | if ((startupConfig == null) || ((startupConfig != null) | ||
76 | && (startupConfig.GetString("InterregionComms", "RESTComms") == "RESTComms"))) | ||
77 | { | ||
78 | m_log.Info("[REST COMMS]: Enabling InterregionComms RESTComms module"); | ||
79 | m_enabled = true; | ||
80 | if (config.Configs["Hypergrid"] != null) | ||
81 | m_safemode = config.Configs["Hypergrid"].GetBoolean("safemode", false); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | public virtual void PostInitialise() | ||
86 | { | ||
87 | } | ||
88 | |||
89 | public virtual void Close() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | public void AddRegion(Scene scene) | ||
94 | { | ||
95 | } | ||
96 | |||
97 | public void RemoveRegion(Scene scene) | ||
98 | { | ||
99 | if (m_enabled) | ||
100 | { | ||
101 | m_localBackend.RemoveScene(scene); | ||
102 | scene.UnregisterModuleInterface<IInterregionCommsOut>(this); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public void RegionLoaded(Scene scene) | ||
107 | { | ||
108 | if (m_enabled) | ||
109 | { | ||
110 | if (!initialized) | ||
111 | { | ||
112 | InitOnce(scene); | ||
113 | initialized = true; | ||
114 | AddHTTPHandlers(); | ||
115 | } | ||
116 | InitEach(scene); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public Type ReplaceableInterface | ||
121 | { | ||
122 | get { return null; } | ||
123 | } | ||
124 | |||
125 | public virtual string Name | ||
126 | { | ||
127 | get { return "RESTInterregionCommsModule"; } | ||
128 | } | ||
129 | |||
130 | protected virtual void InitEach(Scene scene) | ||
131 | { | ||
132 | m_localBackend.Init(scene); | ||
133 | scene.RegisterModuleInterface<IInterregionCommsOut>(this); | ||
134 | } | ||
135 | |||
136 | protected virtual void InitOnce(Scene scene) | ||
137 | { | ||
138 | m_localBackend = new LocalInterregionComms(); | ||
139 | m_commsManager = scene.CommsManager; | ||
140 | m_aScene = scene; | ||
141 | m_hyperlinkService = m_aScene.RequestModuleInterface<IHyperlinkService>(); | ||
142 | m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService); | ||
143 | m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName); | ||
144 | } | ||
145 | |||
146 | protected virtual void AddHTTPHandlers() | ||
147 | { | ||
148 | MainServer.Instance.AddHTTPHandler("/agent/", AgentHandler); | ||
149 | MainServer.Instance.AddHTTPHandler("/object/", ObjectHandler); | ||
150 | } | ||
151 | |||
152 | #endregion /* IRegionModule */ | ||
153 | |||
154 | #region IInterregionComms | ||
155 | |||
156 | /** | ||
157 | * Agent-related communications | ||
158 | */ | ||
159 | |||
160 | public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
161 | { | ||
162 | // Try local first | ||
163 | if (m_localBackend.SendCreateChildAgent(regionHandle, aCircuit, teleportFlags, out reason)) | ||
164 | return true; | ||
165 | |||
166 | // else do the remote thing | ||
167 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
168 | { | ||
169 | uint x = 0, y = 0; | ||
170 | Utils.LongToUInts(regionHandle, out x, out y); | ||
171 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
172 | if (regInfo != null) | ||
173 | { | ||
174 | m_regionClient.SendUserInformation(regInfo, aCircuit); | ||
175 | |||
176 | return m_regionClient.DoCreateChildAgentCall(regInfo, aCircuit, "None", teleportFlags, out reason); | ||
177 | } | ||
178 | //else | ||
179 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
180 | } | ||
181 | return false; | ||
182 | } | ||
183 | |||
184 | public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) | ||
185 | { | ||
186 | // Try local first | ||
187 | if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData)) | ||
188 | return true; | ||
189 | |||
190 | // else do the remote thing | ||
191 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
192 | { | ||
193 | uint x = 0, y = 0; | ||
194 | Utils.LongToUInts(regionHandle, out x, out y); | ||
195 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
196 | if (regInfo != null) | ||
197 | { | ||
198 | return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); | ||
199 | } | ||
200 | //else | ||
201 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
202 | } | ||
203 | return false; | ||
204 | |||
205 | } | ||
206 | |||
207 | public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData) | ||
208 | { | ||
209 | // Try local first | ||
210 | if (m_localBackend.SendChildAgentUpdate(regionHandle, cAgentData)) | ||
211 | return true; | ||
212 | |||
213 | // else do the remote thing | ||
214 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
215 | { | ||
216 | uint x = 0, y = 0; | ||
217 | Utils.LongToUInts(regionHandle, out x, out y); | ||
218 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
219 | if (regInfo != null) | ||
220 | { | ||
221 | return m_regionClient.DoChildAgentUpdateCall(regInfo, cAgentData); | ||
222 | } | ||
223 | //else | ||
224 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
225 | } | ||
226 | return false; | ||
227 | |||
228 | } | ||
229 | |||
230 | public bool SendRetrieveRootAgent(ulong regionHandle, UUID id, out IAgentData agent) | ||
231 | { | ||
232 | // Try local first | ||
233 | if (m_localBackend.SendRetrieveRootAgent(regionHandle, id, out agent)) | ||
234 | return true; | ||
235 | |||
236 | // else do the remote thing | ||
237 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
238 | { | ||
239 | uint x = 0, y = 0; | ||
240 | Utils.LongToUInts(regionHandle, out x, out y); | ||
241 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
242 | if (regInfo != null) | ||
243 | { | ||
244 | return m_regionClient.DoRetrieveRootAgentCall(regInfo, id, out agent); | ||
245 | } | ||
246 | //else | ||
247 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
248 | } | ||
249 | return false; | ||
250 | |||
251 | } | ||
252 | |||
253 | public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri) | ||
254 | { | ||
255 | // Try local first | ||
256 | if (m_localBackend.SendReleaseAgent(regionHandle, id, uri)) | ||
257 | return true; | ||
258 | |||
259 | // else do the remote thing | ||
260 | return m_regionClient.DoReleaseAgentCall(regionHandle, id, uri); | ||
261 | } | ||
262 | |||
263 | |||
264 | public bool SendCloseAgent(ulong regionHandle, UUID id) | ||
265 | { | ||
266 | // Try local first | ||
267 | if (m_localBackend.SendCloseAgent(regionHandle, id)) | ||
268 | return true; | ||
269 | |||
270 | // else do the remote thing | ||
271 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
272 | { | ||
273 | uint x = 0, y = 0; | ||
274 | Utils.LongToUInts(regionHandle, out x, out y); | ||
275 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
276 | if (regInfo != null) | ||
277 | { | ||
278 | return m_regionClient.DoCloseAgentCall(regInfo, id); | ||
279 | } | ||
280 | //else | ||
281 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
282 | } | ||
283 | return false; | ||
284 | } | ||
285 | |||
286 | /** | ||
287 | * Object-related communications | ||
288 | */ | ||
289 | |||
290 | public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall) | ||
291 | { | ||
292 | // Try local first | ||
293 | if (m_localBackend.SendCreateObject(regionHandle, sog, true)) | ||
294 | { | ||
295 | //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded"); | ||
296 | return true; | ||
297 | } | ||
298 | |||
299 | // else do the remote thing | ||
300 | if (!m_localBackend.IsLocalRegion(regionHandle)) | ||
301 | { | ||
302 | uint x = 0, y = 0; | ||
303 | Utils.LongToUInts(regionHandle, out x, out y); | ||
304 | GridRegion regInfo = m_aScene.GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y); | ||
305 | if (regInfo != null) | ||
306 | { | ||
307 | return m_regionClient.DoCreateObjectCall( | ||
308 | regInfo, sog, SceneObjectSerializer.ToXml2Format(sog), m_aScene.m_allowScriptCrossings); | ||
309 | } | ||
310 | //else | ||
311 | // m_log.Warn("[REST COMMS]: Region not found " + regionHandle); | ||
312 | } | ||
313 | return false; | ||
314 | } | ||
315 | |||
316 | public bool SendCreateObject(ulong regionHandle, UUID userID, UUID itemID) | ||
317 | { | ||
318 | // Not Implemented | ||
319 | return false; | ||
320 | } | ||
321 | |||
322 | #endregion /* IInterregionComms */ | ||
323 | |||
324 | #region Incoming calls from remote instances | ||
325 | |||
326 | /** | ||
327 | * Agent-related incoming calls | ||
328 | */ | ||
329 | |||
330 | public Hashtable AgentHandler(Hashtable request) | ||
331 | { | ||
332 | //m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); | ||
333 | |||
334 | m_log.Debug("---------------------------"); | ||
335 | m_log.Debug(" >> uri=" + request["uri"]); | ||
336 | m_log.Debug(" >> content-type=" + request["content-type"]); | ||
337 | m_log.Debug(" >> http-method=" + request["http-method"]); | ||
338 | m_log.Debug("---------------------------\n"); | ||
339 | |||
340 | Hashtable responsedata = new Hashtable(); | ||
341 | responsedata["content_type"] = "text/html"; | ||
342 | responsedata["keepalive"] = false; | ||
343 | |||
344 | |||
345 | UUID agentID; | ||
346 | string action; | ||
347 | ulong regionHandle; | ||
348 | if (!GetParams((string)request["uri"], out agentID, out regionHandle, out action)) | ||
349 | { | ||
350 | m_log.InfoFormat("[REST COMMS]: Invalid parameters for agent message {0}", request["uri"]); | ||
351 | responsedata["int_response_code"] = 404; | ||
352 | responsedata["str_response_string"] = "false"; | ||
353 | |||
354 | return responsedata; | ||
355 | } | ||
356 | |||
357 | // Next, let's parse the verb | ||
358 | string method = (string)request["http-method"]; | ||
359 | if (method.Equals("PUT")) | ||
360 | { | ||
361 | DoAgentPut(request, responsedata); | ||
362 | return responsedata; | ||
363 | } | ||
364 | else if (method.Equals("POST")) | ||
365 | { | ||
366 | DoAgentPost(request, responsedata, agentID); | ||
367 | return responsedata; | ||
368 | } | ||
369 | else if (method.Equals("GET")) | ||
370 | { | ||
371 | DoAgentGet(request, responsedata, agentID, regionHandle); | ||
372 | return responsedata; | ||
373 | } | ||
374 | else if (method.Equals("DELETE")) | ||
375 | { | ||
376 | DoAgentDelete(request, responsedata, agentID, action, regionHandle); | ||
377 | return responsedata; | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | m_log.InfoFormat("[REST COMMS]: method {0} not supported in agent message", method); | ||
382 | responsedata["int_response_code"] = 404; | ||
383 | responsedata["str_response_string"] = "false"; | ||
384 | |||
385 | return responsedata; | ||
386 | } | ||
387 | |||
388 | } | ||
389 | |||
390 | protected virtual void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id) | ||
391 | { | ||
392 | if (m_safemode) | ||
393 | { | ||
394 | // Authentication | ||
395 | string authority = string.Empty; | ||
396 | string authToken = string.Empty; | ||
397 | if (!GetAuthentication(request, out authority, out authToken)) | ||
398 | { | ||
399 | m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); | ||
400 | responsedata["int_response_code"] = 403; | ||
401 | responsedata["str_response_string"] = "Forbidden"; | ||
402 | return ; | ||
403 | } | ||
404 | if (!VerifyKey(id, authority, authToken)) | ||
405 | { | ||
406 | m_log.InfoFormat("[REST COMMS]: Authentication failed for agent message {0}", request["uri"]); | ||
407 | responsedata["int_response_code"] = 403; | ||
408 | responsedata["str_response_string"] = "Forbidden"; | ||
409 | return ; | ||
410 | } | ||
411 | m_log.DebugFormat("[REST COMMS]: Authentication succeeded for {0}", id); | ||
412 | } | ||
413 | |||
414 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); | ||
415 | if (args == null) | ||
416 | { | ||
417 | responsedata["int_response_code"] = 400; | ||
418 | responsedata["str_response_string"] = "false"; | ||
419 | return; | ||
420 | } | ||
421 | |||
422 | // retrieve the regionhandle | ||
423 | ulong regionhandle = 0; | ||
424 | if (args["destination_handle"] != null) | ||
425 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | ||
426 | |||
427 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
428 | try | ||
429 | { | ||
430 | aCircuit.UnpackAgentCircuitData(args); | ||
431 | } | ||
432 | catch (Exception ex) | ||
433 | { | ||
434 | m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildCreate message {0}", ex.Message); | ||
435 | return; | ||
436 | } | ||
437 | |||
438 | OSDMap resp = new OSDMap(2); | ||
439 | string reason = String.Empty; | ||
440 | uint teleportFlags = 0; | ||
441 | if (args.ContainsKey("teleport_flags")) | ||
442 | { | ||
443 | teleportFlags = args["teleport_flags"].AsUInteger(); | ||
444 | } | ||
445 | |||
446 | // This is the meaning of POST agent | ||
447 | m_regionClient.AdjustUserInformation(aCircuit); | ||
448 | bool result = m_localBackend.SendCreateChildAgent(regionhandle, aCircuit, teleportFlags, out reason); | ||
449 | |||
450 | resp["reason"] = OSD.FromString(reason); | ||
451 | resp["success"] = OSD.FromBoolean(result); | ||
452 | |||
453 | // TODO: add reason if not String.Empty? | ||
454 | responsedata["int_response_code"] = 200; | ||
455 | responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); | ||
456 | } | ||
457 | |||
458 | protected virtual void DoAgentPut(Hashtable request, Hashtable responsedata) | ||
459 | { | ||
460 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); | ||
461 | if (args == null) | ||
462 | { | ||
463 | responsedata["int_response_code"] = 400; | ||
464 | responsedata["str_response_string"] = "false"; | ||
465 | return; | ||
466 | } | ||
467 | |||
468 | // retrieve the regionhandle | ||
469 | ulong regionhandle = 0; | ||
470 | if (args["destination_handle"] != null) | ||
471 | UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle); | ||
472 | |||
473 | string messageType; | ||
474 | if (args["message_type"] != null) | ||
475 | messageType = args["message_type"].AsString(); | ||
476 | else | ||
477 | { | ||
478 | m_log.Warn("[REST COMMS]: Agent Put Message Type not found. "); | ||
479 | messageType = "AgentData"; | ||
480 | } | ||
481 | |||
482 | bool result = true; | ||
483 | if ("AgentData".Equals(messageType)) | ||
484 | { | ||
485 | AgentData agent = new AgentData(); | ||
486 | try | ||
487 | { | ||
488 | agent.Unpack(args); | ||
489 | } | ||
490 | catch (Exception ex) | ||
491 | { | ||
492 | m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
493 | return; | ||
494 | } | ||
495 | |||
496 | //agent.Dump(); | ||
497 | // This is one of the meanings of PUT agent | ||
498 | result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); | ||
499 | |||
500 | } | ||
501 | else if ("AgentPosition".Equals(messageType)) | ||
502 | { | ||
503 | AgentPosition agent = new AgentPosition(); | ||
504 | try | ||
505 | { | ||
506 | agent.Unpack(args); | ||
507 | } | ||
508 | catch (Exception ex) | ||
509 | { | ||
510 | m_log.InfoFormat("[REST COMMS]: exception on unpacking ChildAgentUpdate message {0}", ex.Message); | ||
511 | return; | ||
512 | } | ||
513 | //agent.Dump(); | ||
514 | // This is one of the meanings of PUT agent | ||
515 | result = m_localBackend.SendChildAgentUpdate(regionhandle, agent); | ||
516 | |||
517 | } | ||
518 | |||
519 | responsedata["int_response_code"] = 200; | ||
520 | responsedata["str_response_string"] = result.ToString(); | ||
521 | } | ||
522 | |||
523 | protected virtual void DoAgentGet(Hashtable request, Hashtable responsedata, UUID id, ulong regionHandle) | ||
524 | { | ||
525 | IAgentData agent = null; | ||
526 | bool result = m_localBackend.SendRetrieveRootAgent(regionHandle, id, out agent); | ||
527 | OSDMap map = null; | ||
528 | if (result) | ||
529 | { | ||
530 | if (agent != null) // just to make sure | ||
531 | { | ||
532 | map = agent.Pack(); | ||
533 | string strBuffer = ""; | ||
534 | try | ||
535 | { | ||
536 | strBuffer = OSDParser.SerializeJsonString(map); | ||
537 | } | ||
538 | catch (Exception e) | ||
539 | { | ||
540 | m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
541 | // ignore. buffer will be empty, caller should check. | ||
542 | } | ||
543 | |||
544 | responsedata["content_type"] = "application/json"; | ||
545 | responsedata["int_response_code"] = 200; | ||
546 | responsedata["str_response_string"] = strBuffer; | ||
547 | } | ||
548 | else | ||
549 | { | ||
550 | responsedata["int_response_code"] = 500; | ||
551 | responsedata["str_response_string"] = "Internal error"; | ||
552 | } | ||
553 | } | ||
554 | else | ||
555 | { | ||
556 | responsedata["int_response_code"] = 404; | ||
557 | responsedata["str_response_string"] = "Not Found"; | ||
558 | } | ||
559 | } | ||
560 | |||
561 | protected virtual void DoAgentDelete(Hashtable request, Hashtable responsedata, UUID id, string action, ulong regionHandle) | ||
562 | { | ||
563 | //m_log.Debug(" >>> DoDelete action:" + action + "; regionHandle:" + regionHandle); | ||
564 | |||
565 | if (action.Equals("release")) | ||
566 | m_localBackend.SendReleaseAgent(regionHandle, id, ""); | ||
567 | else | ||
568 | m_localBackend.SendCloseAgent(regionHandle, id); | ||
569 | |||
570 | responsedata["int_response_code"] = 200; | ||
571 | responsedata["str_response_string"] = "OpenSim agent " + id.ToString(); | ||
572 | |||
573 | m_log.Debug("[REST COMMS]: Agent Deleted."); | ||
574 | } | ||
575 | |||
576 | /** | ||
577 | * Object-related incoming calls | ||
578 | */ | ||
579 | |||
580 | public Hashtable ObjectHandler(Hashtable request) | ||
581 | { | ||
582 | m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); | ||
583 | |||
584 | m_log.Debug("---------------------------"); | ||
585 | m_log.Debug(" >> uri=" + request["uri"]); | ||
586 | m_log.Debug(" >> content-type=" + request["content-type"]); | ||
587 | m_log.Debug(" >> http-method=" + request["http-method"]); | ||
588 | m_log.Debug("---------------------------\n"); | ||
589 | |||
590 | Hashtable responsedata = new Hashtable(); | ||
591 | responsedata["content_type"] = "text/html"; | ||
592 | |||
593 | UUID objectID; | ||
594 | string action; | ||
595 | ulong regionHandle; | ||
596 | if (!GetParams((string)request["uri"], out objectID, out regionHandle, out action)) | ||
597 | { | ||
598 | m_log.InfoFormat("[REST COMMS]: Invalid parameters for object message {0}", request["uri"]); | ||
599 | responsedata["int_response_code"] = 404; | ||
600 | responsedata["str_response_string"] = "false"; | ||
601 | |||
602 | return responsedata; | ||
603 | } | ||
604 | |||
605 | // Next, let's parse the verb | ||
606 | string method = (string)request["http-method"]; | ||
607 | if (method.Equals("POST")) | ||
608 | { | ||
609 | DoObjectPost(request, responsedata, regionHandle); | ||
610 | return responsedata; | ||
611 | } | ||
612 | else if (method.Equals("PUT")) | ||
613 | { | ||
614 | DoObjectPut(request, responsedata, regionHandle); | ||
615 | return responsedata; | ||
616 | } | ||
617 | //else if (method.Equals("DELETE")) | ||
618 | //{ | ||
619 | // DoObjectDelete(request, responsedata, agentID, action, regionHandle); | ||
620 | // return responsedata; | ||
621 | //} | ||
622 | else | ||
623 | { | ||
624 | m_log.InfoFormat("[REST COMMS]: method {0} not supported in object message", method); | ||
625 | responsedata["int_response_code"] = 404; | ||
626 | responsedata["str_response_string"] = "false"; | ||
627 | |||
628 | return responsedata; | ||
629 | } | ||
630 | |||
631 | } | ||
632 | |||
633 | protected virtual void DoObjectPost(Hashtable request, Hashtable responsedata, ulong regionhandle) | ||
634 | { | ||
635 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); | ||
636 | if (args == null) | ||
637 | { | ||
638 | responsedata["int_response_code"] = 400; | ||
639 | responsedata["str_response_string"] = "false"; | ||
640 | return; | ||
641 | } | ||
642 | |||
643 | string sogXmlStr = "", extraStr = "", stateXmlStr = ""; | ||
644 | if (args["sog"] != null) | ||
645 | sogXmlStr = args["sog"].AsString(); | ||
646 | if (args["extra"] != null) | ||
647 | extraStr = args["extra"].AsString(); | ||
648 | |||
649 | IScene s = m_localBackend.GetScene(regionhandle); | ||
650 | SceneObjectGroup sog = null; | ||
651 | try | ||
652 | { | ||
653 | sog = SceneObjectSerializer.FromXml2Format(sogXmlStr); | ||
654 | sog.ExtraFromXmlString(extraStr); | ||
655 | } | ||
656 | catch (Exception ex) | ||
657 | { | ||
658 | m_log.InfoFormat("[REST COMMS]: exception on deserializing scene object {0}", ex.Message); | ||
659 | responsedata["int_response_code"] = 400; | ||
660 | responsedata["str_response_string"] = "false"; | ||
661 | return; | ||
662 | } | ||
663 | |||
664 | if ((args["state"] != null) && m_aScene.m_allowScriptCrossings) | ||
665 | { | ||
666 | stateXmlStr = args["state"].AsString(); | ||
667 | if (stateXmlStr != "") | ||
668 | { | ||
669 | try | ||
670 | { | ||
671 | sog.SetState(stateXmlStr, s); | ||
672 | } | ||
673 | catch (Exception ex) | ||
674 | { | ||
675 | m_log.InfoFormat("[REST COMMS]: exception on setting state for scene object {0}", ex.Message); | ||
676 | |||
677 | } | ||
678 | } | ||
679 | } | ||
680 | // This is the meaning of POST object | ||
681 | bool result = m_localBackend.SendCreateObject(regionhandle, sog, false); | ||
682 | |||
683 | responsedata["int_response_code"] = 200; | ||
684 | responsedata["str_response_string"] = result.ToString(); | ||
685 | } | ||
686 | |||
687 | protected virtual void DoObjectPut(Hashtable request, Hashtable responsedata, ulong regionhandle) | ||
688 | { | ||
689 | OSDMap args = RegionClient.GetOSDMap((string)request["body"]); | ||
690 | if (args == null) | ||
691 | { | ||
692 | responsedata["int_response_code"] = 400; | ||
693 | responsedata["str_response_string"] = "false"; | ||
694 | return; | ||
695 | } | ||
696 | |||
697 | UUID userID = UUID.Zero, itemID = UUID.Zero; | ||
698 | if (args["userid"] != null) | ||
699 | userID = args["userid"].AsUUID(); | ||
700 | if (args["itemid"] != null) | ||
701 | itemID = args["itemid"].AsUUID(); | ||
702 | |||
703 | // This is the meaning of PUT object | ||
704 | bool result = m_localBackend.SendCreateObject(regionhandle, userID, itemID); | ||
705 | |||
706 | responsedata["int_response_code"] = 200; | ||
707 | responsedata["str_response_string"] = result.ToString(); | ||
708 | } | ||
709 | |||
710 | #endregion | ||
711 | |||
712 | #region Misc | ||
713 | |||
714 | |||
715 | /// <summary> | ||
716 | /// Extract the param from an uri. | ||
717 | /// </summary> | ||
718 | /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param> | ||
719 | /// <param name="uri">uuid on uuid field</param> | ||
720 | /// <param name="action">optional action</param> | ||
721 | public static bool GetParams(string uri, out UUID uuid, out ulong regionHandle, out string action) | ||
722 | { | ||
723 | uuid = UUID.Zero; | ||
724 | action = ""; | ||
725 | regionHandle = 0; | ||
726 | |||
727 | uri = uri.Trim(new char[] { '/' }); | ||
728 | string[] parts = uri.Split('/'); | ||
729 | if (parts.Length <= 1) | ||
730 | { | ||
731 | return false; | ||
732 | } | ||
733 | else | ||
734 | { | ||
735 | if (!UUID.TryParse(parts[1], out uuid)) | ||
736 | return false; | ||
737 | |||
738 | if (parts.Length >= 3) | ||
739 | UInt64.TryParse(parts[2], out regionHandle); | ||
740 | if (parts.Length >= 4) | ||
741 | action = parts[3]; | ||
742 | |||
743 | return true; | ||
744 | } | ||
745 | } | ||
746 | |||
747 | public static bool GetAuthentication(Hashtable request, out string authority, out string authKey) | ||
748 | { | ||
749 | authority = string.Empty; | ||
750 | authKey = string.Empty; | ||
751 | |||
752 | Uri authUri; | ||
753 | Hashtable headers = (Hashtable)request["headers"]; | ||
754 | |||
755 | // Authorization keys look like this: | ||
756 | // http://orgrid.org:8002/<uuid> | ||
757 | if (headers.ContainsKey("authorization") && (string)headers["authorization"] != "None") | ||
758 | { | ||
759 | if (Uri.TryCreate((string)headers["authorization"], UriKind.Absolute, out authUri)) | ||
760 | { | ||
761 | authority = authUri.Authority; | ||
762 | authKey = authUri.PathAndQuery.Trim('/'); | ||
763 | m_log.DebugFormat("[REST COMMS]: Got authority {0} and key {1}", authority, authKey); | ||
764 | return true; | ||
765 | } | ||
766 | else | ||
767 | m_log.Debug("[REST COMMS]: Wrong format for Authorization header: " + (string)headers["authorization"]); | ||
768 | } | ||
769 | else | ||
770 | m_log.Debug("[REST COMMS]: Authorization header not found"); | ||
771 | |||
772 | return false; | ||
773 | } | ||
774 | |||
775 | bool VerifyKey(UUID userID, string authority, string key) | ||
776 | { | ||
777 | string[] parts = authority.Split(':'); | ||
778 | IPAddress ipaddr = IPAddress.None; | ||
779 | uint port = 0; | ||
780 | if (parts.Length <= 2) | ||
781 | ipaddr = Util.GetHostFromDNS(parts[0]); | ||
782 | if (parts.Length == 2) | ||
783 | UInt32.TryParse(parts[1], out port); | ||
784 | |||
785 | // local authority (standalone), local call | ||
786 | if (m_thisIP.Equals(ipaddr) && (m_aScene.RegionInfo.HttpPort == port)) | ||
787 | return ((IAuthentication)m_aScene.CommsManager.UserAdminService).VerifyKey(userID, key); | ||
788 | // remote call | ||
789 | else | ||
790 | return AuthClient.VerifyKey("http://" + authority, userID, key); | ||
791 | } | ||
792 | |||
793 | |||
794 | #endregion Misc | ||
795 | |||
796 | protected class RegionToRegionClient : RegionClient | ||
797 | { | ||
798 | Scene m_aScene = null; | ||
799 | IHyperlinkService m_hyperlinkService; | ||
800 | |||
801 | public RegionToRegionClient(Scene s, IHyperlinkService hyperService) | ||
802 | { | ||
803 | m_aScene = s; | ||
804 | m_hyperlinkService = hyperService; | ||
805 | } | ||
806 | |||
807 | public override ulong GetRegionHandle(ulong handle) | ||
808 | { | ||
809 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | ||
810 | { | ||
811 | if (m_hyperlinkService != null) | ||
812 | return m_hyperlinkService.FindRegionHandle(handle); | ||
813 | } | ||
814 | |||
815 | return handle; | ||
816 | } | ||
817 | |||
818 | public override bool IsHyperlink(ulong handle) | ||
819 | { | ||
820 | if (m_aScene.SceneGridService is HGSceneCommunicationService) | ||
821 | { | ||
822 | if ((m_hyperlinkService != null) && (m_hyperlinkService.GetHyperlinkRegion(handle) != null)) | ||
823 | return true; | ||
824 | } | ||
825 | return false; | ||
826 | } | ||
827 | |||
828 | public override void SendUserInformation(GridRegion regInfo, AgentCircuitData aCircuit) | ||
829 | { | ||
830 | if (m_hyperlinkService != null) | ||
831 | m_hyperlinkService.SendUserInformation(regInfo, aCircuit); | ||
832 | |||
833 | } | ||
834 | |||
835 | public override void AdjustUserInformation(AgentCircuitData aCircuit) | ||
836 | { | ||
837 | if (m_hyperlinkService != null) | ||
838 | m_hyperlinkService.AdjustUserInformation(aCircuit); | ||
839 | } | ||
840 | } | ||
841 | |||
842 | } | ||
843 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs index 811569f..1e51187 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs | |||
@@ -40,12 +40,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
40 | { | 40 | { |
41 | public abstract class BaseInventoryConnector : IInventoryService | 41 | public abstract class BaseInventoryConnector : IInventoryService |
42 | { | 42 | { |
43 | protected InventoryCache m_cache; | 43 | protected static InventoryCache m_cache; |
44 | private static bool m_Initialized; | ||
44 | 45 | ||
45 | protected virtual void Init(IConfigSource source) | 46 | protected virtual void Init(IConfigSource source) |
46 | { | 47 | { |
47 | m_cache = new InventoryCache(); | 48 | if (!m_Initialized) |
48 | m_cache.Init(source, this); | 49 | { |
50 | m_cache = new InventoryCache(); | ||
51 | m_cache.Init(source, this); | ||
52 | m_Initialized = true; | ||
53 | } | ||
49 | } | 54 | } |
50 | 55 | ||
51 | /// <summary> | 56 | /// <summary> |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs index 1fdf1ef..c6312e0 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs | |||
@@ -31,7 +31,7 @@ using System; | |||
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications.Cache; | 34 | |
35 | using OpenSim.Server.Base; | 35 | using OpenSim.Server.Base; |
36 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
@@ -41,31 +41,20 @@ using OpenMetaverse; | |||
41 | 41 | ||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | 42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory |
43 | { | 43 | { |
44 | public class HGInventoryBroker : BaseInventoryConnector, ISharedRegionModule, IInventoryService | 44 | public class HGInventoryBroker : BaseInventoryConnector, INonSharedRegionModule, IInventoryService |
45 | { | 45 | { |
46 | private static readonly ILog m_log = | 46 | private static readonly ILog m_log = |
47 | LogManager.GetLogger( | 47 | LogManager.GetLogger( |
48 | MethodBase.GetCurrentMethod().DeclaringType); | 48 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | private bool m_Enabled = false; | 50 | private static bool m_Initialized = false; |
51 | private bool m_Initialized = false; | 51 | private static bool m_Enabled = false; |
52 | private Scene m_Scene; | ||
53 | private UserProfileCacheService m_UserProfileService; // This should change to IUserProfileService | ||
54 | |||
55 | private IInventoryService m_GridService; | ||
56 | private ISessionAuthInventoryService m_HGService; | ||
57 | 52 | ||
58 | private string m_LocalGridInventoryURI = string.Empty; | 53 | private static IInventoryService m_GridService; |
54 | private static ISessionAuthInventoryService m_HGService; | ||
59 | 55 | ||
60 | private string LocalGridInventory | 56 | private Scene m_Scene; |
61 | { | 57 | private IUserAccountService m_UserAccountService; |
62 | get | ||
63 | { | ||
64 | if (m_LocalGridInventoryURI == null || m_LocalGridInventoryURI == "") | ||
65 | m_LocalGridInventoryURI = m_Scene.CommsManager.NetworkServersInfo.InventoryURL; | ||
66 | return m_LocalGridInventoryURI; | ||
67 | } | ||
68 | } | ||
69 | 58 | ||
70 | public Type ReplaceableInterface | 59 | public Type ReplaceableInterface |
71 | { | 60 | { |
@@ -79,65 +68,67 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
79 | 68 | ||
80 | public void Initialise(IConfigSource source) | 69 | public void Initialise(IConfigSource source) |
81 | { | 70 | { |
82 | IConfig moduleConfig = source.Configs["Modules"]; | 71 | if (!m_Initialized) |
83 | if (moduleConfig != null) | ||
84 | { | 72 | { |
85 | string name = moduleConfig.GetString("InventoryServices", ""); | 73 | IConfig moduleConfig = source.Configs["Modules"]; |
86 | if (name == Name) | 74 | if (moduleConfig != null) |
87 | { | 75 | { |
88 | IConfig inventoryConfig = source.Configs["InventoryService"]; | 76 | string name = moduleConfig.GetString("InventoryServices", ""); |
89 | if (inventoryConfig == null) | 77 | if (name == Name) |
90 | { | ||
91 | m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | string localDll = inventoryConfig.GetString("LocalGridInventoryService", | ||
96 | String.Empty); | ||
97 | string HGDll = inventoryConfig.GetString("HypergridInventoryService", | ||
98 | String.Empty); | ||
99 | |||
100 | if (localDll == String.Empty) | ||
101 | { | ||
102 | m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService"); | ||
103 | //return; | ||
104 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | ||
105 | } | ||
106 | |||
107 | if (HGDll == String.Empty) | ||
108 | { | 78 | { |
109 | m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService"); | 79 | IConfig inventoryConfig = source.Configs["InventoryService"]; |
110 | //return; | 80 | if (inventoryConfig == null) |
111 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | 81 | { |
82 | m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini"); | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | string localDll = inventoryConfig.GetString("LocalGridInventoryService", | ||
87 | String.Empty); | ||
88 | string HGDll = inventoryConfig.GetString("HypergridInventoryService", | ||
89 | String.Empty); | ||
90 | |||
91 | if (localDll == String.Empty) | ||
92 | { | ||
93 | m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService"); | ||
94 | //return; | ||
95 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | ||
96 | } | ||
97 | |||
98 | if (HGDll == String.Empty) | ||
99 | { | ||
100 | m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService"); | ||
101 | //return; | ||
102 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | ||
103 | } | ||
104 | |||
105 | Object[] args = new Object[] { source }; | ||
106 | m_GridService = | ||
107 | ServerUtils.LoadPlugin<IInventoryService>(localDll, | ||
108 | args); | ||
109 | |||
110 | m_HGService = | ||
111 | ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll, | ||
112 | args); | ||
113 | |||
114 | if (m_GridService == null) | ||
115 | { | ||
116 | m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service"); | ||
117 | return; | ||
118 | } | ||
119 | if (m_HGService == null) | ||
120 | { | ||
121 | m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service"); | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | Init(source); | ||
126 | |||
127 | m_Enabled = true; | ||
128 | m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled"); | ||
112 | } | 129 | } |
113 | |||
114 | Object[] args = new Object[] { source }; | ||
115 | m_GridService = | ||
116 | ServerUtils.LoadPlugin<IInventoryService>(localDll, | ||
117 | args); | ||
118 | |||
119 | m_HGService = | ||
120 | ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll, | ||
121 | args); | ||
122 | |||
123 | if (m_GridService == null) | ||
124 | { | ||
125 | m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service"); | ||
126 | return; | ||
127 | } | ||
128 | if (m_HGService == null) | ||
129 | { | ||
130 | m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service"); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty); | ||
135 | |||
136 | Init(source); | ||
137 | |||
138 | m_Enabled = true; | ||
139 | m_log.Info("[HG INVENTORY CONNECTOR]: HG inventory broker enabled"); | ||
140 | } | 130 | } |
131 | m_Initialized = true; | ||
141 | } | 132 | } |
142 | } | 133 | } |
143 | 134 | ||
@@ -154,17 +145,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
154 | if (!m_Enabled) | 145 | if (!m_Enabled) |
155 | return; | 146 | return; |
156 | 147 | ||
157 | if (!m_Initialized) | 148 | m_Scene = scene; |
158 | { | 149 | m_UserAccountService = m_Scene.UserAccountService; |
159 | m_Scene = scene; | ||
160 | // HACK for now. Ugh! | ||
161 | m_UserProfileService = m_Scene.CommsManager.UserProfileCacheService; | ||
162 | // ugh! | ||
163 | m_UserProfileService.SetInventoryService(this); | ||
164 | scene.CommsManager.UserService.SetInventoryService(this); | ||
165 | |||
166 | m_Initialized = true; | ||
167 | } | ||
168 | 150 | ||
169 | scene.RegisterModuleInterface<IInventoryService>(this); | 151 | scene.RegisterModuleInterface<IInventoryService>(this); |
170 | m_cache.AddRegion(scene); | 152 | m_cache.AddRegion(scene); |
@@ -201,22 +183,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
201 | 183 | ||
202 | public override InventoryCollection GetUserInventory(UUID userID) | 184 | public override InventoryCollection GetUserInventory(UUID userID) |
203 | { | 185 | { |
204 | if (IsLocalGridUser(userID)) | 186 | return null; |
205 | return m_GridService.GetUserInventory(userID); | ||
206 | else | ||
207 | return null; | ||
208 | } | 187 | } |
209 | 188 | ||
210 | public override void GetUserInventory(UUID userID, InventoryReceiptCallback callback) | 189 | public override void GetUserInventory(UUID userID, InventoryReceiptCallback callback) |
211 | { | 190 | { |
212 | if (IsLocalGridUser(userID)) | ||
213 | m_GridService.GetUserInventory(userID, callback); | ||
214 | else | ||
215 | { | ||
216 | UUID sessionID = GetSessionID(userID); | ||
217 | string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); | ||
218 | m_HGService.GetUserInventory(uri, sessionID, callback); | ||
219 | } | ||
220 | } | 191 | } |
221 | 192 | ||
222 | // Inherited. See base | 193 | // Inherited. See base |
@@ -236,19 +207,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
236 | 207 | ||
237 | public override InventoryCollection GetFolderContent(UUID userID, UUID folderID) | 208 | public override InventoryCollection GetFolderContent(UUID userID, UUID folderID) |
238 | { | 209 | { |
239 | if (IsLocalGridUser(userID)) | 210 | string uri = string.Empty; |
211 | if (!IsForeignUser(userID, out uri)) | ||
240 | return m_GridService.GetFolderContent(userID, folderID); | 212 | return m_GridService.GetFolderContent(userID, folderID); |
241 | else | 213 | else |
242 | { | 214 | { |
243 | UUID sessionID = GetSessionID(userID); | 215 | UUID sessionID = GetSessionID(userID); |
244 | string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); | 216 | uri = uri + "/" + userID.ToString(); |
245 | return m_HGService.GetFolderContent(uri, folderID, sessionID); | 217 | return m_HGService.GetFolderContent(uri, folderID, sessionID); |
246 | } | 218 | } |
247 | } | 219 | } |
248 | 220 | ||
249 | public override Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) | 221 | public override Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID) |
250 | { | 222 | { |
251 | if (IsLocalGridUser(userID)) | 223 | string uri = string.Empty; |
224 | if (!IsForeignUser(userID, out uri)) | ||
252 | { | 225 | { |
253 | // This is not pretty, but it will have to do for now | 226 | // This is not pretty, but it will have to do for now |
254 | if (m_GridService is BaseInventoryConnector) | 227 | if (m_GridService is BaseInventoryConnector) |
@@ -265,7 +238,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
265 | else | 238 | else |
266 | { | 239 | { |
267 | UUID sessionID = GetSessionID(userID); | 240 | UUID sessionID = GetSessionID(userID); |
268 | string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); | 241 | uri = uri + "/" + userID.ToString(); |
269 | return m_HGService.GetSystemFolders(uri, sessionID); | 242 | return m_HGService.GetSystemFolders(uri, sessionID); |
270 | } | 243 | } |
271 | } | 244 | } |
@@ -301,12 +274,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
301 | 274 | ||
302 | public override List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) | 275 | public override List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) |
303 | { | 276 | { |
304 | if (IsLocalGridUser(userID)) | 277 | string uri = string.Empty; |
278 | if (!IsForeignUser(userID, out uri)) | ||
305 | return m_GridService.GetFolderItems(userID, folderID); | 279 | return m_GridService.GetFolderItems(userID, folderID); |
306 | else | 280 | else |
307 | { | 281 | { |
308 | UUID sessionID = GetSessionID(userID); | 282 | UUID sessionID = GetSessionID(userID); |
309 | string uri = GetUserInventoryURI(userID) + "/" + userID; | 283 | uri = uri + "/" + userID.ToString(); |
310 | return m_HGService.GetFolderItems(uri, folderID, sessionID); | 284 | return m_HGService.GetFolderItems(uri, folderID, sessionID); |
311 | } | 285 | } |
312 | } | 286 | } |
@@ -316,12 +290,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
316 | if (folder == null) | 290 | if (folder == null) |
317 | return false; | 291 | return false; |
318 | 292 | ||
319 | if (IsLocalGridUser(folder.Owner)) | 293 | string uri = string.Empty; |
294 | if (!IsForeignUser(folder.Owner, out uri)) | ||
320 | return m_GridService.AddFolder(folder); | 295 | return m_GridService.AddFolder(folder); |
321 | else | 296 | else |
322 | { | 297 | { |
323 | UUID sessionID = GetSessionID(folder.Owner); | 298 | UUID sessionID = GetSessionID(folder.Owner); |
324 | string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); | 299 | uri = uri + "/" + folder.Owner.ToString(); |
325 | return m_HGService.AddFolder(uri, folder, sessionID); | 300 | return m_HGService.AddFolder(uri, folder, sessionID); |
326 | } | 301 | } |
327 | } | 302 | } |
@@ -331,12 +306,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
331 | if (folder == null) | 306 | if (folder == null) |
332 | return false; | 307 | return false; |
333 | 308 | ||
334 | if (IsLocalGridUser(folder.Owner)) | 309 | string uri = string.Empty; |
310 | if (!IsForeignUser(folder.Owner, out uri)) | ||
335 | return m_GridService.UpdateFolder(folder); | 311 | return m_GridService.UpdateFolder(folder); |
336 | else | 312 | else |
337 | { | 313 | { |
338 | UUID sessionID = GetSessionID(folder.Owner); | 314 | UUID sessionID = GetSessionID(folder.Owner); |
339 | string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); | 315 | uri = uri + "/" + folder.Owner.ToString(); |
340 | return m_HGService.UpdateFolder(uri, folder, sessionID); | 316 | return m_HGService.UpdateFolder(uri, folder, sessionID); |
341 | } | 317 | } |
342 | } | 318 | } |
@@ -348,12 +324,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
348 | if (folderIDs.Count == 0) | 324 | if (folderIDs.Count == 0) |
349 | return false; | 325 | return false; |
350 | 326 | ||
351 | if (IsLocalGridUser(ownerID)) | 327 | string uri = string.Empty; |
328 | if (!IsForeignUser(ownerID, out uri)) | ||
352 | return m_GridService.DeleteFolders(ownerID, folderIDs); | 329 | return m_GridService.DeleteFolders(ownerID, folderIDs); |
353 | else | 330 | else |
354 | { | 331 | { |
355 | UUID sessionID = GetSessionID(ownerID); | 332 | UUID sessionID = GetSessionID(ownerID); |
356 | string uri = GetUserInventoryURI(ownerID) + "/" + ownerID.ToString(); | 333 | uri = uri + "/" + ownerID.ToString(); |
357 | return m_HGService.DeleteFolders(uri, folderIDs, sessionID); | 334 | return m_HGService.DeleteFolders(uri, folderIDs, sessionID); |
358 | } | 335 | } |
359 | } | 336 | } |
@@ -363,12 +340,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
363 | if (folder == null) | 340 | if (folder == null) |
364 | return false; | 341 | return false; |
365 | 342 | ||
366 | if (IsLocalGridUser(folder.Owner)) | 343 | string uri = string.Empty; |
344 | if (!IsForeignUser(folder.Owner, out uri)) | ||
367 | return m_GridService.MoveFolder(folder); | 345 | return m_GridService.MoveFolder(folder); |
368 | else | 346 | else |
369 | { | 347 | { |
370 | UUID sessionID = GetSessionID(folder.Owner); | 348 | UUID sessionID = GetSessionID(folder.Owner); |
371 | string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); | 349 | uri = uri + "/" + folder.Owner.ToString(); |
372 | return m_HGService.MoveFolder(uri, folder, sessionID); | 350 | return m_HGService.MoveFolder(uri, folder, sessionID); |
373 | } | 351 | } |
374 | } | 352 | } |
@@ -378,12 +356,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
378 | if (folder == null) | 356 | if (folder == null) |
379 | return false; | 357 | return false; |
380 | 358 | ||
381 | if (IsLocalGridUser(folder.Owner)) | 359 | string uri = string.Empty; |
360 | if (!IsForeignUser(folder.Owner, out uri)) | ||
382 | return m_GridService.PurgeFolder(folder); | 361 | return m_GridService.PurgeFolder(folder); |
383 | else | 362 | else |
384 | { | 363 | { |
385 | UUID sessionID = GetSessionID(folder.Owner); | 364 | UUID sessionID = GetSessionID(folder.Owner); |
386 | string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); | 365 | uri = uri + "/" + folder.Owner.ToString(); |
387 | return m_HGService.PurgeFolder(uri, folder, sessionID); | 366 | return m_HGService.PurgeFolder(uri, folder, sessionID); |
388 | } | 367 | } |
389 | } | 368 | } |
@@ -396,14 +375,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
396 | if (item == null) | 375 | if (item == null) |
397 | return false; | 376 | return false; |
398 | 377 | ||
399 | if (IsLocalGridUser(item.Owner)) | 378 | string uri = string.Empty; |
379 | if (!IsForeignUser(item.Owner, out uri)) | ||
400 | { | 380 | { |
401 | return m_GridService.AddItem(item); | 381 | return m_GridService.AddItem(item); |
402 | } | 382 | } |
403 | else | 383 | else |
404 | { | 384 | { |
405 | UUID sessionID = GetSessionID(item.Owner); | 385 | UUID sessionID = GetSessionID(item.Owner); |
406 | string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); | 386 | uri = uri + "/" + item.Owner.ToString(); |
407 | return m_HGService.AddItem(uri, item, sessionID); | 387 | return m_HGService.AddItem(uri, item, sessionID); |
408 | } | 388 | } |
409 | } | 389 | } |
@@ -413,12 +393,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
413 | if (item == null) | 393 | if (item == null) |
414 | return false; | 394 | return false; |
415 | 395 | ||
416 | if (IsLocalGridUser(item.Owner)) | 396 | string uri = string.Empty; |
397 | if (!IsForeignUser(item.Owner, out uri)) | ||
417 | return m_GridService.UpdateItem(item); | 398 | return m_GridService.UpdateItem(item); |
418 | else | 399 | else |
419 | { | 400 | { |
420 | UUID sessionID = GetSessionID(item.Owner); | 401 | UUID sessionID = GetSessionID(item.Owner); |
421 | string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); | 402 | uri = uri + "/" + item.Owner.ToString(); |
422 | return m_HGService.UpdateItem(uri, item, sessionID); | 403 | return m_HGService.UpdateItem(uri, item, sessionID); |
423 | } | 404 | } |
424 | } | 405 | } |
@@ -430,12 +411,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
430 | if (items.Count == 0) | 411 | if (items.Count == 0) |
431 | return true; | 412 | return true; |
432 | 413 | ||
433 | if (IsLocalGridUser(ownerID)) | 414 | string uri = string.Empty; |
415 | if (!IsForeignUser(ownerID, out uri)) | ||
434 | return m_GridService.MoveItems(ownerID, items); | 416 | return m_GridService.MoveItems(ownerID, items); |
435 | else | 417 | else |
436 | { | 418 | { |
437 | UUID sessionID = GetSessionID(ownerID); | 419 | UUID sessionID = GetSessionID(ownerID); |
438 | string uri = GetUserInventoryURI(ownerID) + "/" + ownerID.ToString(); | 420 | uri = uri + "/" + ownerID.ToString(); |
439 | return m_HGService.MoveItems(uri, items, sessionID); | 421 | return m_HGService.MoveItems(uri, items, sessionID); |
440 | } | 422 | } |
441 | } | 423 | } |
@@ -449,12 +431,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
449 | if (itemIDs.Count == 0) | 431 | if (itemIDs.Count == 0) |
450 | return true; | 432 | return true; |
451 | 433 | ||
452 | if (IsLocalGridUser(ownerID)) | 434 | string uri = string.Empty; |
435 | if (!IsForeignUser(ownerID, out uri)) | ||
453 | return m_GridService.DeleteItems(ownerID, itemIDs); | 436 | return m_GridService.DeleteItems(ownerID, itemIDs); |
454 | else | 437 | else |
455 | { | 438 | { |
456 | UUID sessionID = GetSessionID(ownerID); | 439 | UUID sessionID = GetSessionID(ownerID); |
457 | string uri = GetUserInventoryURI(ownerID) + "/" + ownerID.ToString(); | 440 | uri = uri + "/" + ownerID.ToString(); |
458 | return m_HGService.DeleteItems(uri, itemIDs, sessionID); | 441 | return m_HGService.DeleteItems(uri, itemIDs, sessionID); |
459 | } | 442 | } |
460 | } | 443 | } |
@@ -464,12 +447,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
464 | if (item == null) | 447 | if (item == null) |
465 | return null; | 448 | return null; |
466 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetItem {0} for user {1}", item.ID, item.Owner); | 449 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetItem {0} for user {1}", item.ID, item.Owner); |
467 | if (IsLocalGridUser(item.Owner)) | 450 | string uri = string.Empty; |
451 | if (!IsForeignUser(item.Owner, out uri)) | ||
468 | return m_GridService.GetItem(item); | 452 | return m_GridService.GetItem(item); |
469 | else | 453 | else |
470 | { | 454 | { |
471 | UUID sessionID = GetSessionID(item.Owner); | 455 | UUID sessionID = GetSessionID(item.Owner); |
472 | string uri = GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString(); | 456 | uri = uri + "/" + item.Owner.ToString(); |
473 | return m_HGService.QueryItem(uri, item, sessionID); | 457 | return m_HGService.QueryItem(uri, item, sessionID); |
474 | } | 458 | } |
475 | } | 459 | } |
@@ -479,12 +463,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
479 | if (folder == null) | 463 | if (folder == null) |
480 | return null; | 464 | return null; |
481 | 465 | ||
482 | if (IsLocalGridUser(folder.Owner)) | 466 | string uri = string.Empty; |
467 | if (!IsForeignUser(folder.Owner, out uri)) | ||
483 | return m_GridService.GetFolder(folder); | 468 | return m_GridService.GetFolder(folder); |
484 | else | 469 | else |
485 | { | 470 | { |
486 | UUID sessionID = GetSessionID(folder.Owner); | 471 | UUID sessionID = GetSessionID(folder.Owner); |
487 | string uri = GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString(); | 472 | uri = uri + "/" + folder.Owner.ToString(); |
488 | return m_HGService.QueryFolder(uri, folder, sessionID); | 473 | return m_HGService.QueryFolder(uri, folder, sessionID); |
489 | } | 474 | } |
490 | } | 475 | } |
@@ -501,12 +486,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
501 | 486 | ||
502 | public override int GetAssetPermissions(UUID userID, UUID assetID) | 487 | public override int GetAssetPermissions(UUID userID, UUID assetID) |
503 | { | 488 | { |
504 | if (IsLocalGridUser(userID)) | 489 | string uri = string.Empty; |
490 | if (!IsForeignUser(userID, out uri)) | ||
505 | return m_GridService.GetAssetPermissions(userID, assetID); | 491 | return m_GridService.GetAssetPermissions(userID, assetID); |
506 | else | 492 | else |
507 | { | 493 | { |
508 | UUID sessionID = GetSessionID(userID); | 494 | UUID sessionID = GetSessionID(userID); |
509 | string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); | 495 | uri = uri + "/" + userID.ToString(); |
510 | return m_HGService.GetAssetPermissions(uri, assetID, sessionID); | 496 | return m_HGService.GetAssetPermissions(uri, assetID, sessionID); |
511 | } | 497 | } |
512 | } | 498 | } |
@@ -515,61 +501,40 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
515 | 501 | ||
516 | private UUID GetSessionID(UUID userID) | 502 | private UUID GetSessionID(UUID userID) |
517 | { | 503 | { |
518 | CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); | 504 | ScenePresence sp = null; |
519 | if (uinfo != null) | 505 | if (m_Scene.TryGetAvatar(userID, out sp)) |
520 | return uinfo.SessionID; | 506 | { |
507 | return sp.ControllingClient.SessionId; | ||
508 | } | ||
521 | 509 | ||
522 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: user profile for {0} not found", userID); | 510 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: scene presence for {0} not found", userID); |
523 | return UUID.Zero; | 511 | return UUID.Zero; |
524 | } | 512 | } |
525 | 513 | ||
526 | private bool IsLocalGridUser(UUID userID) | 514 | private bool IsForeignUser(UUID userID, out string inventoryURL) |
527 | { | 515 | { |
528 | if (m_UserProfileService == null) | 516 | inventoryURL = string.Empty; |
529 | { | 517 | UserAccount account = null; |
530 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: IsLocalGridUser, no profile service. Returning false."); | 518 | if (m_Scene.UserAccountService != null) |
531 | return false; | 519 | account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID); |
532 | } | ||
533 | 520 | ||
534 | CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); | 521 | if (account == null) // foreign user |
535 | if (uinfo == null) | ||
536 | { | 522 | { |
537 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: IsLocalGridUser, no profile for user {0}. Returning true.", userID); | 523 | ScenePresence sp = null; |
538 | return true; | 524 | m_Scene.TryGetAvatar(userID, out sp); |
539 | } | 525 | if (sp != null) |
540 | 526 | { | |
541 | if ((uinfo.UserProfile.UserInventoryURI == null) || (uinfo.UserProfile.UserInventoryURI == "")) | 527 | AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); |
542 | // this happens in standalone profiles, apparently | 528 | if (aCircuit.ServiceURLs.ContainsKey("InventoryServerURI")) |
543 | return true; | 529 | { |
544 | 530 | inventoryURL = aCircuit.ServiceURLs["InventoryServerURI"].ToString(); | |
545 | string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); | 531 | inventoryURL = inventoryURL.Trim(new char[] { '/' }); |
546 | 532 | return true; | |
547 | string uri = LocalGridInventory.TrimEnd('/'); | 533 | } |
548 | 534 | } | |
549 | if ((userInventoryServerURI == uri) || (userInventoryServerURI == "")) | ||
550 | { | ||
551 | return true; | ||
552 | } | 535 | } |
553 | m_log.DebugFormat("[HG INVENTORY CONNECTOR]: user {0} is foreign({1} - {2})", userID, userInventoryServerURI, uri); | ||
554 | return false; | 536 | return false; |
555 | } | 537 | } |
556 | 538 | ||
557 | private string GetUserInventoryURI(UUID userID) | ||
558 | { | ||
559 | string invURI = LocalGridInventory; | ||
560 | |||
561 | CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); | ||
562 | if ((uinfo == null) || (uinfo.UserProfile == null)) | ||
563 | return invURI; | ||
564 | |||
565 | string userInventoryServerURI = Util.ServerURI(uinfo.UserProfile.UserInventoryURI); | ||
566 | |||
567 | if ((userInventoryServerURI != null) && | ||
568 | (userInventoryServerURI != "")) | ||
569 | invURI = userInventoryServerURI; | ||
570 | return invURI; | ||
571 | } | ||
572 | |||
573 | |||
574 | } | 539 | } |
575 | } | 540 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs index 66d11dd..9d6da4f 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs | |||
@@ -131,9 +131,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
131 | 131 | ||
132 | if (!m_Initialized) | 132 | if (!m_Initialized) |
133 | { | 133 | { |
134 | // ugh! | ||
135 | scene.CommsManager.UserProfileCacheService.SetInventoryService(this); | ||
136 | scene.CommsManager.UserService.SetInventoryService(this); | ||
137 | m_Initialized = true; | 134 | m_Initialized = true; |
138 | } | 135 | } |
139 | 136 | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs index 69504df..aa3b30d 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs | |||
@@ -32,7 +32,7 @@ using System.Reflection; | |||
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Statistics; | 34 | using OpenSim.Framework.Statistics; |
35 | using OpenSim.Framework.Communications.Cache; | 35 | |
36 | using OpenSim.Services.Connectors; | 36 | using OpenSim.Services.Connectors; |
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
@@ -49,7 +49,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
49 | private bool m_Enabled = false; | 49 | private bool m_Enabled = false; |
50 | private bool m_Initialized = false; | 50 | private bool m_Initialized = false; |
51 | private Scene m_Scene; | 51 | private Scene m_Scene; |
52 | private UserProfileCacheService m_UserProfileService; | ||
53 | private InventoryServicesConnector m_RemoteConnector; | 52 | private InventoryServicesConnector m_RemoteConnector; |
54 | 53 | ||
55 | public Type ReplaceableInterface | 54 | public Type ReplaceableInterface |
@@ -114,9 +113,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
114 | 113 | ||
115 | if (!m_Initialized) | 114 | if (!m_Initialized) |
116 | { | 115 | { |
117 | // ugh! | ||
118 | scene.CommsManager.UserProfileCacheService.SetInventoryService(this); | ||
119 | scene.CommsManager.UserService.SetInventoryService(this); | ||
120 | m_Initialized = true; | 116 | m_Initialized = true; |
121 | } | 117 | } |
122 | 118 | ||
@@ -134,10 +130,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
134 | 130 | ||
135 | public void RegionLoaded(Scene scene) | 131 | public void RegionLoaded(Scene scene) |
136 | { | 132 | { |
137 | m_UserProfileService = m_Scene.CommsManager.UserProfileCacheService; | ||
138 | if (m_UserProfileService != null) | ||
139 | m_log.Debug("[XXXX] Set m_UserProfileService in " + m_Scene.RegionInfo.RegionName); | ||
140 | |||
141 | if (!m_Enabled) | 133 | if (!m_Enabled) |
142 | return; | 134 | return; |
143 | 135 | ||
@@ -345,23 +337,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | |||
345 | 337 | ||
346 | private UUID GetSessionID(UUID userID) | 338 | private UUID GetSessionID(UUID userID) |
347 | { | 339 | { |
348 | //if (m_Scene == null) | ||
349 | //{ | ||
350 | // m_log.Debug("[INVENTORY CONNECTOR]: OOPS! scene is null"); | ||
351 | //} | ||
352 | |||
353 | if (m_UserProfileService == null) | ||
354 | { | ||
355 | //m_log.Debug("[INVENTORY CONNECTOR]: OOPS! UserProfileCacheService is null"); | ||
356 | return UUID.Zero; | ||
357 | } | ||
358 | |||
359 | CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID); | ||
360 | if (uinfo != null) | ||
361 | return uinfo.SessionID; | ||
362 | m_log.DebugFormat("[INVENTORY CONNECTOR]: user profile for {0} not found", userID); | ||
363 | return UUID.Zero; | 340 | return UUID.Zero; |
364 | |||
365 | } | 341 | } |
366 | 342 | ||
367 | } | 343 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs new file mode 100644 index 0000000..d78daf9 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs | |||
@@ -0,0 +1,200 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | |||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | using Nini.Config; | ||
40 | |||
41 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence | ||
42 | { | ||
43 | public class LocalPresenceServicesConnector : ISharedRegionModule, IPresenceService | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private bool m_Enabled = false; | ||
48 | |||
49 | private PresenceDetector m_PresenceDetector; | ||
50 | private IPresenceService m_PresenceService; | ||
51 | |||
52 | public LocalPresenceServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public LocalPresenceServicesConnector(IConfigSource source) | ||
57 | { | ||
58 | Initialise(source); | ||
59 | } | ||
60 | |||
61 | #region ISharedRegionModule | ||
62 | |||
63 | public Type ReplaceableInterface | ||
64 | { | ||
65 | get { return null; } | ||
66 | } | ||
67 | |||
68 | public string Name | ||
69 | { | ||
70 | get { return "LocalPresenceServicesConnector"; } | ||
71 | } | ||
72 | |||
73 | public void Initialise(IConfigSource source) | ||
74 | { | ||
75 | IConfig moduleConfig = source.Configs["Modules"]; | ||
76 | if (moduleConfig != null) | ||
77 | { | ||
78 | string name = moduleConfig.GetString("PresenceServices", ""); | ||
79 | if (name == Name) | ||
80 | { | ||
81 | IConfig inventoryConfig = source.Configs["PresenceService"]; | ||
82 | if (inventoryConfig == null) | ||
83 | { | ||
84 | m_log.Error("[LOCAL PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | string serviceDll = inventoryConfig.GetString("LocalServiceModule", String.Empty); | ||
89 | |||
90 | if (serviceDll == String.Empty) | ||
91 | { | ||
92 | m_log.Error("[LOCAL PRESENCE CONNECTOR]: No LocalServiceModule named in section PresenceService"); | ||
93 | return; | ||
94 | } | ||
95 | |||
96 | Object[] args = new Object[] { source }; | ||
97 | m_log.DebugFormat("[LOCAL PRESENCE CONNECTOR]: Service dll = {0}", serviceDll); | ||
98 | |||
99 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(serviceDll, args); | ||
100 | |||
101 | if (m_PresenceService == null) | ||
102 | { | ||
103 | m_log.Error("[LOCAL PRESENCE CONNECTOR]: Can't load presence service"); | ||
104 | //return; | ||
105 | throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's"); | ||
106 | } | ||
107 | |||
108 | //Init(source); | ||
109 | |||
110 | m_PresenceDetector = new PresenceDetector(this); | ||
111 | |||
112 | m_Enabled = true; | ||
113 | m_log.Info("[LOCAL PRESENCE CONNECTOR]: Local presence connector enabled"); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | public void PostInitialise() | ||
119 | { | ||
120 | } | ||
121 | |||
122 | public void Close() | ||
123 | { | ||
124 | } | ||
125 | |||
126 | public void AddRegion(Scene scene) | ||
127 | { | ||
128 | if (!m_Enabled) | ||
129 | return; | ||
130 | |||
131 | // m_log.DebugFormat( | ||
132 | // "[LOCAL PRESENCE CONNECTOR]: Registering IPresenceService to scene {0}", scene.RegionInfo.RegionName); | ||
133 | |||
134 | scene.RegisterModuleInterface<IPresenceService>(this); | ||
135 | m_PresenceDetector.AddRegion(scene); | ||
136 | |||
137 | m_log.InfoFormat("[LOCAL PRESENCE CONNECTOR]: Enabled local presence for region {0}", scene.RegionInfo.RegionName); | ||
138 | |||
139 | } | ||
140 | |||
141 | public void RemoveRegion(Scene scene) | ||
142 | { | ||
143 | if (!m_Enabled) | ||
144 | return; | ||
145 | |||
146 | m_PresenceDetector.RemoveRegion(scene); | ||
147 | } | ||
148 | |||
149 | public void RegionLoaded(Scene scene) | ||
150 | { | ||
151 | if (!m_Enabled) | ||
152 | return; | ||
153 | |||
154 | } | ||
155 | |||
156 | #endregion | ||
157 | |||
158 | #region IPresenceService | ||
159 | |||
160 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
161 | { | ||
162 | m_log.Warn("[LOCAL PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators"); | ||
163 | return false; | ||
164 | } | ||
165 | |||
166 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
167 | { | ||
168 | return m_PresenceService.LogoutAgent(sessionID, position, lookat); | ||
169 | } | ||
170 | |||
171 | |||
172 | public bool LogoutRegionAgents(UUID regionID) | ||
173 | { | ||
174 | return m_PresenceService.LogoutRegionAgents(regionID); | ||
175 | } | ||
176 | |||
177 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
178 | { | ||
179 | return m_PresenceService.ReportAgent(sessionID, regionID, position, lookAt); | ||
180 | } | ||
181 | |||
182 | public PresenceInfo GetAgent(UUID sessionID) | ||
183 | { | ||
184 | return m_PresenceService.GetAgent(sessionID); | ||
185 | } | ||
186 | |||
187 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
188 | { | ||
189 | return m_PresenceService.GetAgents(userIDs); | ||
190 | } | ||
191 | |||
192 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
193 | { | ||
194 | return m_PresenceService.SetHomeLocation(userID, regionID, position, lookAt); | ||
195 | } | ||
196 | |||
197 | #endregion | ||
198 | |||
199 | } | ||
200 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs new file mode 100644 index 0000000..891fc14 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs | |||
@@ -0,0 +1,100 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | |||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | |||
35 | using OpenMetaverse; | ||
36 | using log4net; | ||
37 | |||
38 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence | ||
39 | { | ||
40 | public class PresenceDetector | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | private IPresenceService m_PresenceService; | ||
45 | private Scene m_aScene; | ||
46 | |||
47 | public PresenceDetector(IPresenceService presenceservice) | ||
48 | { | ||
49 | m_PresenceService = presenceservice; | ||
50 | } | ||
51 | |||
52 | public void AddRegion(Scene scene) | ||
53 | { | ||
54 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
55 | scene.EventManager.OnNewClient += OnNewClient; | ||
56 | |||
57 | m_PresenceService.LogoutRegionAgents(scene.RegionInfo.RegionID); | ||
58 | |||
59 | if (m_aScene == null) | ||
60 | m_aScene = scene; | ||
61 | } | ||
62 | |||
63 | public void RemoveRegion(Scene scene) | ||
64 | { | ||
65 | scene.EventManager.OnMakeRootAgent -= OnMakeRootAgent; | ||
66 | scene.EventManager.OnNewClient -= OnNewClient; | ||
67 | |||
68 | m_PresenceService.LogoutRegionAgents(scene.RegionInfo.RegionID); | ||
69 | |||
70 | } | ||
71 | |||
72 | public void OnMakeRootAgent(ScenePresence sp) | ||
73 | { | ||
74 | m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName); | ||
75 | m_PresenceService.ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); | ||
76 | } | ||
77 | |||
78 | public void OnNewClient(IClientAPI client) | ||
79 | { | ||
80 | client.OnLogout += OnLogout; | ||
81 | } | ||
82 | |||
83 | public void OnLogout(IClientAPI client) | ||
84 | { | ||
85 | client.OnLogout -= OnLogout; | ||
86 | |||
87 | ScenePresence sp = null; | ||
88 | Vector3 position = new Vector3(128, 128, 0); | ||
89 | Vector3 lookat = new Vector3(0, 1, 0); | ||
90 | |||
91 | if (m_aScene.TryGetAvatar(client.AgentId, out sp)) | ||
92 | { | ||
93 | position = sp.AbsolutePosition; | ||
94 | lookat = sp.Lookat; | ||
95 | } | ||
96 | m_PresenceService.LogoutAgent(client.SessionId, position, lookat); | ||
97 | |||
98 | } | ||
99 | } | ||
100 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs new file mode 100644 index 0000000..865f99e --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs | |||
@@ -0,0 +1,164 @@ | |||
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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | |||
31 | using OpenSim.Region.Framework.Interfaces; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Server.Base; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Services.Connectors; | ||
36 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | using log4net; | ||
40 | using Nini.Config; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence | ||
43 | { | ||
44 | public class RemotePresenceServicesConnector : ISharedRegionModule, IPresenceService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | #region ISharedRegionModule | ||
49 | |||
50 | private bool m_Enabled = false; | ||
51 | |||
52 | private PresenceDetector m_PresenceDetector; | ||
53 | private IPresenceService m_RemoteConnector; | ||
54 | |||
55 | public Type ReplaceableInterface | ||
56 | { | ||
57 | get { return null; } | ||
58 | } | ||
59 | |||
60 | public string Name | ||
61 | { | ||
62 | get { return "RemotePresenceServicesConnector"; } | ||
63 | } | ||
64 | |||
65 | public void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig moduleConfig = source.Configs["Modules"]; | ||
68 | if (moduleConfig != null) | ||
69 | { | ||
70 | string name = moduleConfig.GetString("PresenceServices", ""); | ||
71 | if (name == Name) | ||
72 | { | ||
73 | m_RemoteConnector = new PresenceServicesConnector(source); | ||
74 | |||
75 | m_Enabled = true; | ||
76 | |||
77 | m_PresenceDetector = new PresenceDetector(this); | ||
78 | |||
79 | m_log.Info("[INVENTORY CONNECTOR]: Remote presence enabled"); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | } | ||
84 | |||
85 | public void PostInitialise() | ||
86 | { | ||
87 | } | ||
88 | |||
89 | public void Close() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | public void AddRegion(Scene scene) | ||
94 | { | ||
95 | if (!m_Enabled) | ||
96 | return; | ||
97 | |||
98 | scene.RegisterModuleInterface<IPresenceService>(this); | ||
99 | m_PresenceDetector.AddRegion(scene); | ||
100 | |||
101 | m_log.InfoFormat("[REMOTE PRESENCE CONNECTOR]: Enabled remote presence for region {0}", scene.RegionInfo.RegionName); | ||
102 | |||
103 | } | ||
104 | |||
105 | public void RemoveRegion(Scene scene) | ||
106 | { | ||
107 | if (!m_Enabled) | ||
108 | return; | ||
109 | |||
110 | m_PresenceDetector.RemoveRegion(scene); | ||
111 | } | ||
112 | |||
113 | public void RegionLoaded(Scene scene) | ||
114 | { | ||
115 | if (!m_Enabled) | ||
116 | return; | ||
117 | |||
118 | } | ||
119 | |||
120 | #endregion | ||
121 | |||
122 | #region IPresenceService | ||
123 | |||
124 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
125 | { | ||
126 | m_log.Warn("[REMOTE PRESENCE CONNECTOR]: LoginAgent connector not implemented at the simulators"); | ||
127 | return false; | ||
128 | } | ||
129 | |||
130 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
131 | { | ||
132 | return m_RemoteConnector.LogoutAgent(sessionID, position, lookat); | ||
133 | } | ||
134 | |||
135 | |||
136 | public bool LogoutRegionAgents(UUID regionID) | ||
137 | { | ||
138 | return m_RemoteConnector.LogoutRegionAgents(regionID); | ||
139 | } | ||
140 | |||
141 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
142 | { | ||
143 | return m_RemoteConnector.ReportAgent(sessionID, regionID, position, lookAt); | ||
144 | } | ||
145 | |||
146 | public PresenceInfo GetAgent(UUID sessionID) | ||
147 | { | ||
148 | return m_RemoteConnector.GetAgent(sessionID); | ||
149 | } | ||
150 | |||
151 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
152 | { | ||
153 | return m_RemoteConnector.GetAgents(userIDs); | ||
154 | } | ||
155 | |||
156 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
157 | { | ||
158 | return m_RemoteConnector.SetHomeLocation(userID, regionID, position, lookAt); | ||
159 | } | ||
160 | |||
161 | #endregion | ||
162 | |||
163 | } | ||
164 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs new file mode 100644 index 0000000..9ba1bdc --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs | |||
@@ -0,0 +1,104 @@ | |||
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.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net.Config; | ||
34 | using NUnit.Framework; | ||
35 | using NUnit.Framework.SyntaxHelpers; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using Nini.Config; | ||
39 | |||
40 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
43 | using OpenSim.Tests.Common; | ||
44 | using OpenSim.Tests.Common.Setup; | ||
45 | |||
46 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests | ||
47 | { | ||
48 | [TestFixture] | ||
49 | public class PresenceConnectorsTests | ||
50 | { | ||
51 | LocalPresenceServicesConnector m_LocalConnector; | ||
52 | private void SetUp() | ||
53 | { | ||
54 | IConfigSource config = new IniConfigSource(); | ||
55 | config.AddConfig("Modules"); | ||
56 | config.AddConfig("PresenceService"); | ||
57 | config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector"); | ||
58 | config.Configs["PresenceService"].Set("LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService"); | ||
59 | config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullPresenceData"); | ||
60 | |||
61 | m_LocalConnector = new LocalPresenceServicesConnector(config); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Test OpenSim Presence. | ||
66 | /// </summary> | ||
67 | [Test] | ||
68 | public void TestPresenceV0_1() | ||
69 | { | ||
70 | SetUp(); | ||
71 | |||
72 | string user1 = UUID.Zero.ToString(); | ||
73 | UUID session1 = UUID.Zero; | ||
74 | |||
75 | // this is not implemented by this connector | ||
76 | //m_LocalConnector.LoginAgent(user1, session1, UUID.Zero); | ||
77 | PresenceInfo result = m_LocalConnector.GetAgent(session1); | ||
78 | Assert.IsNotNull(result, "Retrieved GetAgent is null"); | ||
79 | Assert.That(result.UserID, Is.EqualTo(user1), "Retrieved userID does not match"); | ||
80 | Assert.IsTrue(result.Online, "Agent just logged in but is offline"); | ||
81 | |||
82 | UUID region1 = UUID.Random(); | ||
83 | bool r = m_LocalConnector.ReportAgent(session1, region1, Vector3.Zero, Vector3.Zero); | ||
84 | Assert.IsTrue(r, "First ReportAgent returned false"); | ||
85 | result = m_LocalConnector.GetAgent(session1); | ||
86 | Assert.That(result.RegionID, Is.EqualTo(region1), "Agent is not in the right region (region1)"); | ||
87 | |||
88 | UUID region2 = UUID.Random(); | ||
89 | r = m_LocalConnector.ReportAgent(session1, region2, Vector3.Zero, Vector3.Zero); | ||
90 | Assert.IsTrue(r, "Second ReportAgent returned false"); | ||
91 | result = m_LocalConnector.GetAgent(session1); | ||
92 | Assert.That(result.RegionID, Is.EqualTo(region2), "Agent is not in the right region (region2)"); | ||
93 | |||
94 | r = m_LocalConnector.LogoutAgent(session1, Vector3.Zero, Vector3.UnitY); | ||
95 | Assert.IsTrue(r, "LogoutAgent returned false"); | ||
96 | result = m_LocalConnector.GetAgent(session1); | ||
97 | Assert.IsNotNull(result, "Agent session disappeared from storage after logout"); | ||
98 | Assert.IsFalse(result.Online, "Agent is reported to be Online after logout"); | ||
99 | |||
100 | r = m_LocalConnector.ReportAgent(session1, region1, Vector3.Zero, Vector3.Zero); | ||
101 | Assert.IsFalse(r, "ReportAgent of non-logged in user returned true"); | ||
102 | } | ||
103 | } | ||
104 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs index d68c683..e913891 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Interregion/LocalInterregionComms.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs | |||
@@ -33,33 +33,49 @@ using OpenMetaverse; | |||
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Region.Framework.Interfaces; | 34 | using OpenSim.Region.Framework.Interfaces; |
35 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | 38 | ||
37 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | 39 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation |
38 | { | 40 | { |
39 | public class LocalInterregionComms : ISharedRegionModule, IInterregionCommsOut, IInterregionCommsIn | 41 | public class LocalSimulationConnectorModule : ISharedRegionModule, ISimulationService |
40 | { | 42 | { |
41 | private bool m_enabled = false; | ||
42 | |||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | private List<Scene> m_sceneList = new List<Scene>(); | 44 | private List<Scene> m_sceneList = new List<Scene>(); |
45 | 45 | ||
46 | #region Events | 46 | private IEntityTransferModule m_AgentTransferModule; |
47 | public event ChildAgentUpdateReceived OnChildAgentUpdate; | 47 | protected IEntityTransferModule AgentTransferModule |
48 | { | ||
49 | get | ||
50 | { | ||
51 | if (m_AgentTransferModule == null) | ||
52 | m_AgentTransferModule = m_sceneList[0].RequestModuleInterface<IEntityTransferModule>(); | ||
53 | return m_AgentTransferModule; | ||
54 | } | ||
55 | } | ||
48 | 56 | ||
49 | #endregion /* Events */ | 57 | private bool m_ModuleEnabled = false; |
50 | 58 | ||
51 | #region IRegionModule | 59 | #region IRegionModule |
52 | 60 | ||
53 | public void Initialise(IConfigSource config) | 61 | public void Initialise(IConfigSource config) |
54 | { | 62 | { |
55 | if (m_sceneList.Count == 0) | 63 | IConfig moduleConfig = config.Configs["Modules"]; |
64 | if (moduleConfig != null) | ||
56 | { | 65 | { |
57 | IConfig startupConfig = config.Configs["Communications"]; | 66 | string name = moduleConfig.GetString("SimulationServices", ""); |
58 | 67 | if (name == Name) | |
59 | if ((startupConfig != null) && (startupConfig.GetString("InterregionComms", "RESTComms") == "LocalComms")) | ||
60 | { | 68 | { |
61 | m_log.Debug("[LOCAL COMMS]: Enabling InterregionComms LocalComms module"); | 69 | //IConfig userConfig = config.Configs["SimulationService"]; |
62 | m_enabled = true; | 70 | //if (userConfig == null) |
71 | //{ | ||
72 | // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini"); | ||
73 | // return; | ||
74 | //} | ||
75 | |||
76 | m_ModuleEnabled = true; | ||
77 | |||
78 | m_log.Info("[SIMULATION CONNECTOR]: Local simulation enabled"); | ||
63 | } | 79 | } |
64 | } | 80 | } |
65 | } | 81 | } |
@@ -70,22 +86,24 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
70 | 86 | ||
71 | public void AddRegion(Scene scene) | 87 | public void AddRegion(Scene scene) |
72 | { | 88 | { |
89 | if (!m_ModuleEnabled) | ||
90 | return; | ||
91 | |||
92 | Init(scene); | ||
93 | scene.RegisterModuleInterface<ISimulationService>(this); | ||
73 | } | 94 | } |
74 | 95 | ||
75 | public void RemoveRegion(Scene scene) | 96 | public void RemoveRegion(Scene scene) |
76 | { | 97 | { |
77 | if (m_enabled) | 98 | if (!m_ModuleEnabled) |
78 | { | 99 | return; |
79 | RemoveScene(scene); | 100 | |
80 | } | 101 | RemoveScene(scene); |
102 | scene.UnregisterModuleInterface<ISimulationService>(this); | ||
81 | } | 103 | } |
82 | 104 | ||
83 | public void RegionLoaded(Scene scene) | 105 | public void RegionLoaded(Scene scene) |
84 | { | 106 | { |
85 | if (m_enabled) | ||
86 | { | ||
87 | Init(scene); | ||
88 | } | ||
89 | } | 107 | } |
90 | 108 | ||
91 | public void Close() | 109 | public void Close() |
@@ -99,7 +117,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
99 | 117 | ||
100 | public string Name | 118 | public string Name |
101 | { | 119 | { |
102 | get { return "LocalInterregionCommsModule"; } | 120 | get { return "LocalSimulationConnectorModule"; } |
103 | } | 121 | } |
104 | 122 | ||
105 | /// <summary> | 123 | /// <summary> |
@@ -128,9 +146,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
128 | lock (m_sceneList) | 146 | lock (m_sceneList) |
129 | { | 147 | { |
130 | m_sceneList.Add(scene); | 148 | m_sceneList.Add(scene); |
131 | if (m_enabled) | ||
132 | scene.RegisterModuleInterface<IInterregionCommsOut>(this); | ||
133 | scene.RegisterModuleInterface<IInterregionCommsIn>(this); | ||
134 | } | 149 | } |
135 | 150 | ||
136 | } | 151 | } |
@@ -138,40 +153,58 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
138 | 153 | ||
139 | #endregion /* IRegionModule */ | 154 | #endregion /* IRegionModule */ |
140 | 155 | ||
141 | #region IInterregionComms | 156 | #region ISimulation |
157 | |||
158 | public IScene GetScene(ulong regionhandle) | ||
159 | { | ||
160 | foreach (Scene s in m_sceneList) | ||
161 | { | ||
162 | if (s.RegionInfo.RegionHandle == regionhandle) | ||
163 | return s; | ||
164 | } | ||
165 | // ? weird. should not happen | ||
166 | return m_sceneList[0]; | ||
167 | } | ||
142 | 168 | ||
143 | /** | 169 | /** |
144 | * Agent-related communications | 170 | * Agent-related communications |
145 | */ | 171 | */ |
146 | 172 | ||
147 | public bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | 173 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) |
148 | { | 174 | { |
175 | if (destination == null) | ||
176 | { | ||
177 | reason = "Given destination was null"; | ||
178 | m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: CreateAgent was given a null destination"); | ||
179 | return false; | ||
180 | } | ||
149 | 181 | ||
150 | foreach (Scene s in m_sceneList) | 182 | foreach (Scene s in m_sceneList) |
151 | { | 183 | { |
152 | if (s.RegionInfo.RegionHandle == regionHandle) | 184 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
153 | { | 185 | { |
154 | // m_log.DebugFormat("[LOCAL COMMS]: Found region {0} to send SendCreateChildAgent", regionHandle); | 186 | m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Found region {0} to send SendCreateChildAgent", destination.RegionName); |
155 | return s.NewUserConnection(aCircuit, teleportFlags, out reason); | 187 | return s.NewUserConnection(aCircuit, teleportFlags, out reason); |
156 | } | 188 | } |
157 | } | 189 | } |
158 | 190 | ||
159 | // m_log.DebugFormat("[LOCAL COMMS]: Did not find region {0} for SendCreateChildAgent", regionHandle); | 191 | m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Did not find region {0} for SendCreateChildAgent", destination.RegionName); |
160 | uint x = 0, y = 0; | 192 | reason = "Did not find region " + destination.RegionName; |
161 | Utils.LongToUInts(regionHandle, out x, out y); | ||
162 | reason = "Did not find region " + x + "-" + y; | ||
163 | return false; | 193 | return false; |
164 | } | 194 | } |
165 | 195 | ||
166 | public bool SendChildAgentUpdate(ulong regionHandle, AgentData cAgentData) | 196 | public bool UpdateAgent(GridRegion destination, AgentData cAgentData) |
167 | { | 197 | { |
198 | if (destination == null) | ||
199 | return false; | ||
200 | |||
168 | foreach (Scene s in m_sceneList) | 201 | foreach (Scene s in m_sceneList) |
169 | { | 202 | { |
170 | if (s.RegionInfo.RegionHandle == regionHandle) | 203 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
171 | { | 204 | { |
172 | //m_log.DebugFormat( | 205 | m_log.DebugFormat( |
173 | // "[LOCAL COMMS]: Found region {0} {1} to send ChildAgentUpdate", | 206 | "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate", |
174 | // s.RegionInfo.RegionName, regionHandle); | 207 | s.RegionInfo.RegionName, destination.RegionHandle); |
175 | 208 | ||
176 | s.IncomingChildAgentDataUpdate(cAgentData); | 209 | s.IncomingChildAgentDataUpdate(cAgentData); |
177 | return true; | 210 | return true; |
@@ -182,11 +215,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
182 | return false; | 215 | return false; |
183 | } | 216 | } |
184 | 217 | ||
185 | public bool SendChildAgentUpdate(ulong regionHandle, AgentPosition cAgentData) | 218 | public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData) |
186 | { | 219 | { |
220 | if (destination == null) | ||
221 | return false; | ||
222 | |||
187 | foreach (Scene s in m_sceneList) | 223 | foreach (Scene s in m_sceneList) |
188 | { | 224 | { |
189 | if (s.RegionInfo.RegionHandle == regionHandle) | 225 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
190 | { | 226 | { |
191 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | 227 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); |
192 | s.IncomingChildAgentDataUpdate(cAgentData); | 228 | s.IncomingChildAgentDataUpdate(cAgentData); |
@@ -197,12 +233,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
197 | return false; | 233 | return false; |
198 | } | 234 | } |
199 | 235 | ||
200 | public bool SendRetrieveRootAgent(ulong regionHandle, UUID id, out IAgentData agent) | 236 | public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) |
201 | { | 237 | { |
202 | agent = null; | 238 | agent = null; |
239 | |||
240 | if (destination == null) | ||
241 | return false; | ||
242 | |||
203 | foreach (Scene s in m_sceneList) | 243 | foreach (Scene s in m_sceneList) |
204 | { | 244 | { |
205 | if (s.RegionInfo.RegionHandle == regionHandle) | 245 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
206 | { | 246 | { |
207 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); | 247 | //m_log.Debug("[LOCAL COMMS]: Found region to send ChildAgentUpdate"); |
208 | return s.IncomingRetrieveRootAgent(id, out agent); | 248 | return s.IncomingRetrieveRootAgent(id, out agent); |
@@ -212,35 +252,30 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
212 | return false; | 252 | return false; |
213 | } | 253 | } |
214 | 254 | ||
215 | public bool SendReleaseAgent(ulong regionHandle, UUID id, string uri) | 255 | public bool ReleaseAgent(UUID origin, UUID id, string uri) |
216 | { | 256 | { |
217 | //uint x, y; | ||
218 | //Utils.LongToUInts(regionHandle, out x, out y); | ||
219 | //x = x / Constants.RegionSize; | ||
220 | //y = y / Constants.RegionSize; | ||
221 | //m_log.Debug("\n >>> Local SendReleaseAgent " + x + "-" + y); | ||
222 | foreach (Scene s in m_sceneList) | 257 | foreach (Scene s in m_sceneList) |
223 | { | 258 | { |
224 | if (s.RegionInfo.RegionHandle == regionHandle) | 259 | if (s.RegionInfo.RegionID == origin) |
225 | { | 260 | { |
226 | //m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); | 261 | m_log.Debug("[LOCAL COMMS]: Found region to SendReleaseAgent"); |
227 | return s.IncomingReleaseAgent(id); | 262 | AgentTransferModule.AgentArrivedAtDestination(id); |
263 | return true; | ||
264 | // return s.IncomingReleaseAgent(id); | ||
228 | } | 265 | } |
229 | } | 266 | } |
230 | //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent"); | 267 | //m_log.Debug("[LOCAL COMMS]: region not found in SendReleaseAgent " + origin); |
231 | return false; | 268 | return false; |
232 | } | 269 | } |
233 | 270 | ||
234 | public bool SendCloseAgent(ulong regionHandle, UUID id) | 271 | public bool CloseAgent(GridRegion destination, UUID id) |
235 | { | 272 | { |
236 | //uint x, y; | 273 | if (destination == null) |
237 | //Utils.LongToUInts(regionHandle, out x, out y); | 274 | return false; |
238 | //x = x / Constants.RegionSize; | 275 | |
239 | //y = y / Constants.RegionSize; | ||
240 | //m_log.Debug("\n >>> Local SendCloseAgent " + x + "-" + y); | ||
241 | foreach (Scene s in m_sceneList) | 276 | foreach (Scene s in m_sceneList) |
242 | { | 277 | { |
243 | if (s.RegionInfo.RegionHandle == regionHandle) | 278 | if (s.RegionInfo.RegionID == destination.RegionID) |
244 | { | 279 | { |
245 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); | 280 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCloseAgent"); |
246 | return s.IncomingCloseAgent(id); | 281 | return s.IncomingCloseAgent(id); |
@@ -254,11 +289,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
254 | * Object-related communications | 289 | * Object-related communications |
255 | */ | 290 | */ |
256 | 291 | ||
257 | public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall) | 292 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) |
258 | { | 293 | { |
294 | if (destination == null) | ||
295 | return false; | ||
296 | |||
259 | foreach (Scene s in m_sceneList) | 297 | foreach (Scene s in m_sceneList) |
260 | { | 298 | { |
261 | if (s.RegionInfo.RegionHandle == regionHandle) | 299 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
262 | { | 300 | { |
263 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); | 301 | //m_log.Debug("[LOCAL COMMS]: Found region to SendCreateObject"); |
264 | if (isLocalCall) | 302 | if (isLocalCall) |
@@ -278,11 +316,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
278 | return false; | 316 | return false; |
279 | } | 317 | } |
280 | 318 | ||
281 | public bool SendCreateObject(ulong regionHandle, UUID userID, UUID itemID) | 319 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) |
282 | { | 320 | { |
321 | if (destination == null) | ||
322 | return false; | ||
323 | |||
283 | foreach (Scene s in m_sceneList) | 324 | foreach (Scene s in m_sceneList) |
284 | { | 325 | { |
285 | if (s.RegionInfo.RegionHandle == regionHandle) | 326 | if (s.RegionInfo.RegionHandle == destination.RegionHandle) |
286 | { | 327 | { |
287 | return s.IncomingCreateObject(userID, itemID); | 328 | return s.IncomingCreateObject(userID, itemID); |
288 | } | 329 | } |
@@ -295,21 +336,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Interregion | |||
295 | 336 | ||
296 | #region Misc | 337 | #region Misc |
297 | 338 | ||
298 | public Scene GetScene(ulong regionhandle) | 339 | public bool IsLocalRegion(ulong regionhandle) |
299 | { | 340 | { |
300 | foreach (Scene s in m_sceneList) | 341 | foreach (Scene s in m_sceneList) |
301 | { | ||
302 | if (s.RegionInfo.RegionHandle == regionhandle) | 342 | if (s.RegionInfo.RegionHandle == regionhandle) |
303 | return s; | 343 | return true; |
304 | } | 344 | return false; |
305 | // ? weird. should not happen | ||
306 | return m_sceneList[0]; | ||
307 | } | 345 | } |
308 | 346 | ||
309 | public bool IsLocalRegion(ulong regionhandle) | 347 | public bool IsLocalRegion(UUID id) |
310 | { | 348 | { |
311 | foreach (Scene s in m_sceneList) | 349 | foreach (Scene s in m_sceneList) |
312 | if (s.RegionInfo.RegionHandle == regionhandle) | 350 | if (s.RegionInfo.RegionID == id) |
313 | return true; | 351 | return true; |
314 | return false; | 352 | return false; |
315 | } | 353 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs new file mode 100644 index 0000000..2b1f815 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs | |||
@@ -0,0 +1,300 @@ | |||
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; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
43 | using OpenSim.Services.Interfaces; | ||
44 | using OpenSim.Services.Connectors.Simulation; | ||
45 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
46 | |||
47 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation | ||
48 | { | ||
49 | public class RemoteSimulationConnectorModule : ISharedRegionModule, ISimulationService | ||
50 | { | ||
51 | private bool initialized = false; | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | protected bool m_enabled = false; | ||
55 | protected Scene m_aScene; | ||
56 | // RemoteSimulationConnector does not care about local regions; it delegates that to the Local module | ||
57 | protected LocalSimulationConnectorModule m_localBackend; | ||
58 | protected SimulationServiceConnector m_remoteConnector; | ||
59 | |||
60 | protected bool m_safemode; | ||
61 | protected IPAddress m_thisIP; | ||
62 | |||
63 | #region IRegionModule | ||
64 | |||
65 | public virtual void Initialise(IConfigSource config) | ||
66 | { | ||
67 | |||
68 | IConfig moduleConfig = config.Configs["Modules"]; | ||
69 | if (moduleConfig != null) | ||
70 | { | ||
71 | string name = moduleConfig.GetString("SimulationServices", ""); | ||
72 | if (name == Name) | ||
73 | { | ||
74 | //IConfig userConfig = config.Configs["SimulationService"]; | ||
75 | //if (userConfig == null) | ||
76 | //{ | ||
77 | // m_log.Error("[AVATAR CONNECTOR]: SimulationService missing from OpanSim.ini"); | ||
78 | // return; | ||
79 | //} | ||
80 | |||
81 | m_remoteConnector = new SimulationServiceConnector(); | ||
82 | |||
83 | m_enabled = true; | ||
84 | |||
85 | m_log.Info("[SIMULATION CONNECTOR]: Remote simulation enabled"); | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | public virtual void PostInitialise() | ||
91 | { | ||
92 | } | ||
93 | |||
94 | public virtual void Close() | ||
95 | { | ||
96 | } | ||
97 | |||
98 | public void AddRegion(Scene scene) | ||
99 | { | ||
100 | if (!m_enabled) | ||
101 | return; | ||
102 | |||
103 | if (!initialized) | ||
104 | { | ||
105 | InitOnce(scene); | ||
106 | initialized = true; | ||
107 | } | ||
108 | InitEach(scene); | ||
109 | } | ||
110 | |||
111 | public void RemoveRegion(Scene scene) | ||
112 | { | ||
113 | if (m_enabled) | ||
114 | { | ||
115 | m_localBackend.RemoveScene(scene); | ||
116 | scene.UnregisterModuleInterface<ISimulationService>(this); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public void RegionLoaded(Scene scene) | ||
121 | { | ||
122 | if (!m_enabled) | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | public Type ReplaceableInterface | ||
127 | { | ||
128 | get { return null; } | ||
129 | } | ||
130 | |||
131 | public virtual string Name | ||
132 | { | ||
133 | get { return "RemoteSimulationConnectorModule"; } | ||
134 | } | ||
135 | |||
136 | protected virtual void InitEach(Scene scene) | ||
137 | { | ||
138 | m_localBackend.Init(scene); | ||
139 | scene.RegisterModuleInterface<ISimulationService>(this); | ||
140 | } | ||
141 | |||
142 | protected virtual void InitOnce(Scene scene) | ||
143 | { | ||
144 | m_localBackend = new LocalSimulationConnectorModule(); | ||
145 | m_aScene = scene; | ||
146 | //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService); | ||
147 | m_thisIP = Util.GetHostFromDNS(scene.RegionInfo.ExternalHostName); | ||
148 | } | ||
149 | |||
150 | #endregion /* IRegionModule */ | ||
151 | |||
152 | #region IInterregionComms | ||
153 | |||
154 | public IScene GetScene(ulong handle) | ||
155 | { | ||
156 | return m_localBackend.GetScene(handle); | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * Agent-related communications | ||
161 | */ | ||
162 | |||
163 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) | ||
164 | { | ||
165 | if (destination == null) | ||
166 | { | ||
167 | reason = "Given destination was null"; | ||
168 | m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent was given a null destination"); | ||
169 | return false; | ||
170 | } | ||
171 | |||
172 | // Try local first | ||
173 | if (m_localBackend.CreateAgent(destination, aCircuit, teleportFlags, out reason)) | ||
174 | return true; | ||
175 | |||
176 | // else do the remote thing | ||
177 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
178 | { | ||
179 | //m_regionClient.SendUserInformation(regInfo, aCircuit); | ||
180 | return m_remoteConnector.CreateAgent(destination, aCircuit, teleportFlags, out reason); | ||
181 | } | ||
182 | return false; | ||
183 | } | ||
184 | |||
185 | public bool UpdateAgent(GridRegion destination, AgentData cAgentData) | ||
186 | { | ||
187 | if (destination == null) | ||
188 | return false; | ||
189 | |||
190 | // Try local first | ||
191 | if (m_localBackend.UpdateAgent(destination, cAgentData)) | ||
192 | return true; | ||
193 | |||
194 | // else do the remote thing | ||
195 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
196 | return m_remoteConnector.UpdateAgent(destination, cAgentData); | ||
197 | |||
198 | return false; | ||
199 | |||
200 | } | ||
201 | |||
202 | public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData) | ||
203 | { | ||
204 | if (destination == null) | ||
205 | return false; | ||
206 | |||
207 | // Try local first | ||
208 | if (m_localBackend.UpdateAgent(destination, cAgentData)) | ||
209 | return true; | ||
210 | |||
211 | // else do the remote thing | ||
212 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
213 | return m_remoteConnector.UpdateAgent(destination, cAgentData); | ||
214 | |||
215 | return false; | ||
216 | |||
217 | } | ||
218 | |||
219 | public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) | ||
220 | { | ||
221 | agent = null; | ||
222 | |||
223 | if (destination == null) | ||
224 | return false; | ||
225 | |||
226 | // Try local first | ||
227 | if (m_localBackend.RetrieveAgent(destination, id, out agent)) | ||
228 | return true; | ||
229 | |||
230 | // else do the remote thing | ||
231 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
232 | return m_remoteConnector.RetrieveAgent(destination, id, out agent); | ||
233 | |||
234 | return false; | ||
235 | |||
236 | } | ||
237 | |||
238 | public bool ReleaseAgent(UUID origin, UUID id, string uri) | ||
239 | { | ||
240 | // Try local first | ||
241 | if (m_localBackend.ReleaseAgent(origin, id, uri)) | ||
242 | return true; | ||
243 | |||
244 | // else do the remote thing | ||
245 | if (!m_localBackend.IsLocalRegion(origin)) | ||
246 | return m_remoteConnector.ReleaseAgent(origin, id, uri); | ||
247 | |||
248 | return false; | ||
249 | } | ||
250 | |||
251 | |||
252 | public bool CloseAgent(GridRegion destination, UUID id) | ||
253 | { | ||
254 | if (destination == null) | ||
255 | return false; | ||
256 | |||
257 | // Try local first | ||
258 | if (m_localBackend.CloseAgent(destination, id)) | ||
259 | return true; | ||
260 | |||
261 | // else do the remote thing | ||
262 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
263 | return m_remoteConnector.CloseAgent(destination, id); | ||
264 | |||
265 | return false; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Object-related communications | ||
270 | */ | ||
271 | |||
272 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
273 | { | ||
274 | if (destination == null) | ||
275 | return false; | ||
276 | |||
277 | // Try local first | ||
278 | if (m_localBackend.CreateObject(destination, sog, isLocalCall)) | ||
279 | { | ||
280 | //m_log.Debug("[REST COMMS]: LocalBackEnd SendCreateObject succeeded"); | ||
281 | return true; | ||
282 | } | ||
283 | |||
284 | // else do the remote thing | ||
285 | if (!m_localBackend.IsLocalRegion(destination.RegionHandle)) | ||
286 | return m_remoteConnector.CreateObject(destination, sog, isLocalCall); | ||
287 | |||
288 | return false; | ||
289 | } | ||
290 | |||
291 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
292 | { | ||
293 | // Not Implemented | ||
294 | return false; | ||
295 | } | ||
296 | |||
297 | #endregion /* IInterregionComms */ | ||
298 | |||
299 | } | ||
300 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs new file mode 100644 index 0000000..07fee79 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs | |||
@@ -0,0 +1,189 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | ||
41 | { | ||
42 | public class LocalUserAccountServicesConnector : ISharedRegionModule, IUserAccountService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private IUserAccountService m_UserService; | ||
49 | private UserAccountCache m_Cache; | ||
50 | |||
51 | private bool m_Enabled = false; | ||
52 | |||
53 | #region ISharedRegionModule | ||
54 | |||
55 | public Type ReplaceableInterface | ||
56 | { | ||
57 | get { return null; } | ||
58 | } | ||
59 | |||
60 | public string Name | ||
61 | { | ||
62 | get { return "LocalUserAccountServicesConnector"; } | ||
63 | } | ||
64 | |||
65 | public void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig moduleConfig = source.Configs["Modules"]; | ||
68 | if (moduleConfig != null) | ||
69 | { | ||
70 | string name = moduleConfig.GetString("UserAccountServices", ""); | ||
71 | if (name == Name) | ||
72 | { | ||
73 | IConfig userConfig = source.Configs["UserAccountService"]; | ||
74 | if (userConfig == null) | ||
75 | { | ||
76 | m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpenSim.ini"); | ||
77 | return; | ||
78 | } | ||
79 | |||
80 | string serviceDll = userConfig.GetString("LocalServiceModule", | ||
81 | String.Empty); | ||
82 | |||
83 | if (serviceDll == String.Empty) | ||
84 | { | ||
85 | m_log.Error("[USER CONNECTOR]: No LocalServiceModule named in section UserService"); | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | Object[] args = new Object[] { source }; | ||
90 | m_UserService = | ||
91 | ServerUtils.LoadPlugin<IUserAccountService>(serviceDll, | ||
92 | args); | ||
93 | |||
94 | if (m_UserService == null) | ||
95 | { | ||
96 | m_log.Error("[USER CONNECTOR]: Can't load user account service"); | ||
97 | return; | ||
98 | } | ||
99 | m_Enabled = true; | ||
100 | m_Cache = new UserAccountCache(); | ||
101 | |||
102 | m_log.Info("[USER CONNECTOR]: Local user connector enabled"); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public void PostInitialise() | ||
108 | { | ||
109 | if (!m_Enabled) | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | public void Close() | ||
114 | { | ||
115 | if (!m_Enabled) | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | public void AddRegion(Scene scene) | ||
120 | { | ||
121 | if (!m_Enabled) | ||
122 | return; | ||
123 | |||
124 | scene.RegisterModuleInterface<IUserAccountService>(m_UserService); | ||
125 | } | ||
126 | |||
127 | public void RemoveRegion(Scene scene) | ||
128 | { | ||
129 | if (!m_Enabled) | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | public void RegionLoaded(Scene scene) | ||
134 | { | ||
135 | if (!m_Enabled) | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | #endregion | ||
140 | |||
141 | #region IUserAccountService | ||
142 | |||
143 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
144 | { | ||
145 | UserAccount account = m_Cache.Get(userID); | ||
146 | if (account != null) | ||
147 | return account; | ||
148 | |||
149 | account = m_UserService.GetUserAccount(scopeID, userID); | ||
150 | if (account != null) | ||
151 | m_Cache.Cache(account); | ||
152 | |||
153 | return account; | ||
154 | } | ||
155 | |||
156 | public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
157 | { | ||
158 | UserAccount account = m_Cache.Get(firstName + " " + lastName); | ||
159 | if (account != null) | ||
160 | return account; | ||
161 | |||
162 | account = m_UserService.GetUserAccount(scopeID, firstName, lastName); | ||
163 | if (account != null) | ||
164 | m_Cache.Cache(account); | ||
165 | |||
166 | return account; | ||
167 | } | ||
168 | |||
169 | public UserAccount GetUserAccount(UUID scopeID, string Email) | ||
170 | { | ||
171 | return m_UserService.GetUserAccount(scopeID, Email); | ||
172 | } | ||
173 | |||
174 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
175 | { | ||
176 | return m_UserService.GetUserAccounts(scopeID, query); | ||
177 | } | ||
178 | |||
179 | // Update all updatable fields | ||
180 | // | ||
181 | public bool StoreUserAccount(UserAccount data) | ||
182 | { | ||
183 | return m_UserService.StoreUserAccount(data); | ||
184 | } | ||
185 | |||
186 | #endregion | ||
187 | |||
188 | } | ||
189 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs new file mode 100644 index 0000000..13acdf2 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs | |||
@@ -0,0 +1,148 @@ | |||
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 Nini.Config; | ||
30 | using log4net; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Region.Framework.Interfaces; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OpenSim.Services.Connectors; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | ||
40 | { | ||
41 | public class RemoteUserAccountServicesConnector : UserAccountServicesConnector, | ||
42 | ISharedRegionModule, IUserAccountService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private bool m_Enabled = false; | ||
49 | private UserAccountCache m_Cache; | ||
50 | |||
51 | public Type ReplaceableInterface | ||
52 | { | ||
53 | get { return null; } | ||
54 | } | ||
55 | |||
56 | public string Name | ||
57 | { | ||
58 | get { return "RemoteUserAccountServicesConnector"; } | ||
59 | } | ||
60 | |||
61 | public override void Initialise(IConfigSource source) | ||
62 | { | ||
63 | IConfig moduleConfig = source.Configs["Modules"]; | ||
64 | if (moduleConfig != null) | ||
65 | { | ||
66 | string name = moduleConfig.GetString("UserAccountServices", ""); | ||
67 | if (name == Name) | ||
68 | { | ||
69 | IConfig userConfig = source.Configs["UserAccountService"]; | ||
70 | if (userConfig == null) | ||
71 | { | ||
72 | m_log.Error("[USER CONNECTOR]: UserAccountService missing from OpanSim.ini"); | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | m_Enabled = true; | ||
77 | |||
78 | base.Initialise(source); | ||
79 | m_Cache = new UserAccountCache(); | ||
80 | |||
81 | m_log.Info("[USER CONNECTOR]: Remote users enabled"); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public void PostInitialise() | ||
87 | { | ||
88 | if (!m_Enabled) | ||
89 | return; | ||
90 | } | ||
91 | |||
92 | public void Close() | ||
93 | { | ||
94 | if (!m_Enabled) | ||
95 | return; | ||
96 | } | ||
97 | |||
98 | public void AddRegion(Scene scene) | ||
99 | { | ||
100 | if (!m_Enabled) | ||
101 | return; | ||
102 | |||
103 | scene.RegisterModuleInterface<IUserAccountService>(this); | ||
104 | } | ||
105 | |||
106 | public void RemoveRegion(Scene scene) | ||
107 | { | ||
108 | if (!m_Enabled) | ||
109 | return; | ||
110 | } | ||
111 | |||
112 | public void RegionLoaded(Scene scene) | ||
113 | { | ||
114 | if (!m_Enabled) | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | #region Overwritten methods from IUserAccountService | ||
119 | |||
120 | public override UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
121 | { | ||
122 | UserAccount account = m_Cache.Get(userID); | ||
123 | if (account != null) | ||
124 | return account; | ||
125 | |||
126 | account = base.GetUserAccount(scopeID, userID); | ||
127 | if (account != null) | ||
128 | m_Cache.Cache(account); | ||
129 | |||
130 | return account; | ||
131 | } | ||
132 | |||
133 | public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
134 | { | ||
135 | UserAccount account = m_Cache.Get(firstName + " " + lastName); | ||
136 | if (account != null) | ||
137 | return account; | ||
138 | |||
139 | account = base.GetUserAccount(scopeID, firstName, lastName); | ||
140 | if (account != null) | ||
141 | m_Cache.Cache(account); | ||
142 | |||
143 | return account; | ||
144 | } | ||
145 | |||
146 | #endregion | ||
147 | } | ||
148 | } | ||
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs new file mode 100644 index 0000000..e430fc7 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs | |||
@@ -0,0 +1,87 @@ | |||
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 | using System; | ||
28 | using System.Reflection; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenMetaverse; | ||
33 | using log4net; | ||
34 | |||
35 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | ||
36 | { | ||
37 | public class UserAccountCache | ||
38 | { | ||
39 | //private static readonly ILog m_log = | ||
40 | // LogManager.GetLogger( | ||
41 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | private ICnmCache<UUID, UserAccount> m_UUIDCache; | ||
44 | private Dictionary<string, UUID> m_NameCache; | ||
45 | |||
46 | public UserAccountCache() | ||
47 | { | ||
48 | // Warning: the size values are a bit fuzzy. What matters | ||
49 | // most for this cache is the count value (128 entries). | ||
50 | m_UUIDCache = CnmSynchronizedCache<UUID, UserAccount>.Synchronized(new CnmMemoryCache<UUID, UserAccount>( | ||
51 | 128, 128*512, TimeSpan.FromMinutes(30.0))); | ||
52 | m_NameCache = new Dictionary<string, UUID>(); // this one is unbound | ||
53 | } | ||
54 | |||
55 | public void Cache(UserAccount account) | ||
56 | { | ||
57 | m_UUIDCache.Set(account.PrincipalID, account, 512); | ||
58 | m_NameCache[account.Name] = account.PrincipalID; | ||
59 | |||
60 | //m_log.DebugFormat("[USER CACHE]: cached user {0} {1}", account.FirstName, account.LastName); | ||
61 | } | ||
62 | |||
63 | public UserAccount Get(UUID userID) | ||
64 | { | ||
65 | UserAccount account = null; | ||
66 | if (m_UUIDCache.TryGetValue(userID, out account)) | ||
67 | { | ||
68 | //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); | ||
69 | return account; | ||
70 | } | ||
71 | |||
72 | return null; | ||
73 | } | ||
74 | |||
75 | public UserAccount Get(string name) | ||
76 | { | ||
77 | if (!m_NameCache.ContainsKey(name)) | ||
78 | return null; | ||
79 | |||
80 | UserAccount account = null; | ||
81 | if (m_UUIDCache.TryGetValue(m_NameCache[name], out account)) | ||
82 | return account; | ||
83 | |||
84 | return null; | ||
85 | } | ||
86 | } | ||
87 | } | ||