diff options
Diffstat (limited to '')
49 files changed, 7356 insertions, 775 deletions
diff --git a/OpenSim/Services/UserService/UserService.cs b/OpenSim/Data/MySQL/MySQLAvatarData.cs index e8b9fc3..5611302 100644 --- a/OpenSim/Services/UserService/UserService.cs +++ b/OpenSim/Data/MySQL/MySQLAvatarData.cs | |||
@@ -26,51 +26,42 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Data; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | ||
36 | using MySql.Data.MySqlClient; | ||
35 | 37 | ||
36 | namespace OpenSim.Services.UserAccountService | 38 | namespace OpenSim.Data.MySQL |
37 | { | 39 | { |
38 | public class UserAccountService : UserAccountServiceBase, IUserAccountService | 40 | /// <summary> |
41 | /// A MySQL Interface for the Grid Server | ||
42 | /// </summary> | ||
43 | public class MySQLAvatarData : MySQLGenericTableHandler<AvatarBaseData>, | ||
44 | IAvatarData | ||
39 | { | 45 | { |
40 | public UserAccountService(IConfigSource config) : base(config) | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | { | ||
42 | } | ||
43 | 47 | ||
44 | public UserAccount GetUserAccount(UUID scopeID, string firstName, | 48 | public MySQLAvatarData(string connectionString, string realm) : |
45 | string lastName) | 49 | base(connectionString, realm, "Avatar") |
46 | { | 50 | { |
47 | return null; | ||
48 | } | 51 | } |
49 | 52 | ||
50 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | 53 | public bool Delete(UUID principalID, string name) |
51 | { | 54 | { |
52 | return null; | 55 | MySqlCommand cmd = new MySqlCommand(); |
53 | } | ||
54 | 56 | ||
55 | public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) | 57 | cmd.CommandText = String.Format("delete from {0} where `PrincipalID` = ?PrincipalID and `Name` = ?Name", m_Realm); |
56 | { | 58 | cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString()); |
57 | return false; | 59 | cmd.Parameters.AddWithValue("?Name", name); |
58 | } | ||
59 | 60 | ||
60 | public bool SetUserAccount(UserAccount data, UUID principalID, string token) | 61 | if (ExecuteNonQuery(cmd) > 0) |
61 | { | 62 | return true; |
62 | return false; | ||
63 | } | ||
64 | 63 | ||
65 | public bool CreateUserAccount(UserAccount data, UUID principalID, string token) | ||
66 | { | ||
67 | return false; | 64 | return false; |
68 | } | 65 | } |
69 | |||
70 | public List<UserAccount> GetUserAccount(UUID scopeID, | ||
71 | string query) | ||
72 | { | ||
73 | return null; | ||
74 | } | ||
75 | } | 66 | } |
76 | } | 67 | } |
diff --git a/OpenSim/Services/Interfaces/IHyperlink.cs b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs index ed3ff23..e8738c4 100644 --- a/OpenSim/Services/Interfaces/IHyperlink.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityTransferModule.cs | |||
@@ -25,25 +25,36 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using OpenSim.Framework; | 28 | using System; |
29 | using OpenSim.Services.Interfaces; | ||
29 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 30 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
30 | 31 | ||
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
32 | 35 | ||
33 | namespace OpenSim.Services.Interfaces | 36 | namespace OpenSim.Region.Framework.Interfaces |
34 | { | 37 | { |
35 | public interface IHyperlinkService | 38 | public interface IEntityTransferModule |
36 | { | 39 | { |
37 | GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor); | 40 | void Teleport(ScenePresence agent, ulong regionHandle, Vector3 position, |
38 | GridRegion GetHyperlinkRegion(ulong handle); | 41 | Vector3 lookAt, uint teleportFlags); |
39 | ulong FindRegionHandle(ulong handle); | 42 | |
43 | void TeleportHome(UUID id, IClientAPI client); | ||
44 | |||
45 | void Cross(ScenePresence agent, bool isFlying); | ||
40 | 46 | ||
41 | bool SendUserInformation(GridRegion region, AgentCircuitData aCircuit); | 47 | void AgentArrivedAtDestination(UUID agent); |
42 | void AdjustUserInformation(AgentCircuitData aCircuit); | ||
43 | 48 | ||
44 | bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome); | 49 | void EnableChildAgents(ScenePresence agent); |
45 | void AcceptUser(ForeignUserProfileData user, GridRegion home); | ||
46 | 50 | ||
47 | bool IsLocalUser(UUID userID); | 51 | void EnableChildAgent(ScenePresence agent, GridRegion region); |
52 | |||
53 | void Cross(SceneObjectGroup sog, Vector3 position, bool silent); | ||
54 | } | ||
55 | |||
56 | public interface IUserAgentVerificationModule | ||
57 | { | ||
58 | bool VerifyClient(AgentCircuitData aCircuit, string token); | ||
48 | } | 59 | } |
49 | } | 60 | } |
diff --git a/OpenSim/Services/Connectors/User/UserServiceConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index 683990f..f2d9321 100644 --- a/OpenSim/Services/Connectors/User/UserServiceConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -25,90 +25,58 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using log4net; | ||
29 | using System; | 28 | using System; |
30 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
31 | using System.IO; | ||
32 | using System.Reflection; | 30 | using System.Reflection; |
33 | using Nini.Config; | 31 | using Nini.Config; |
34 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Communications; | 33 | using OpenSim.Server.Base; |
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | 34 | using OpenSim.Services.Interfaces; |
38 | using OpenMetaverse; | 35 | using OpenSim.Framework.Servers.HttpServer; |
36 | using OpenSim.Server.Handlers.Base; | ||
39 | 37 | ||
40 | namespace OpenSim.Services.Connectors | 38 | using log4net; |
39 | |||
40 | namespace OpenSim.Server.Handlers.Hypergrid | ||
41 | { | 41 | { |
42 | public class UserServicesConnector : IUserAccountService | 42 | public class GatekeeperServiceInConnector : ServiceConnector |
43 | { | 43 | { |
44 | private static readonly ILog m_log = | 44 | private static readonly ILog m_log = |
45 | LogManager.GetLogger( | 45 | LogManager.GetLogger( |
46 | MethodBase.GetCurrentMethod().DeclaringType); | 46 | MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | // private string m_ServerURI = String.Empty; | 48 | private IGatekeeperService m_GatekeeperService; |
49 | 49 | public IGatekeeperService GateKeeper | |
50 | public UserServicesConnector() | ||
51 | { | 50 | { |
51 | get { return m_GatekeeperService; } | ||
52 | } | 52 | } |
53 | 53 | ||
54 | public UserServicesConnector(string serverURI) | 54 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : |
55 | base(config, server, String.Empty) | ||
55 | { | 56 | { |
56 | // m_ServerURI = serverURI.TrimEnd('/'); | 57 | IConfig gridConfig = config.Configs["GatekeeperService"]; |
57 | } | 58 | if (gridConfig != null) |
58 | |||
59 | public UserServicesConnector(IConfigSource source) | ||
60 | { | ||
61 | Initialise(source); | ||
62 | } | ||
63 | |||
64 | public virtual void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig assetConfig = source.Configs["UserService"]; | ||
67 | if (assetConfig == null) | ||
68 | { | 59 | { |
69 | m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini"); | 60 | string serviceDll = gridConfig.GetString("LocalServiceModule", string.Empty); |
70 | throw new Exception("User connector init error"); | 61 | Object[] args = new Object[] { config, simService }; |
71 | } | 62 | m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(serviceDll, args); |
72 | 63 | ||
73 | string serviceURI = assetConfig.GetString("UserServerURI", | ||
74 | String.Empty); | ||
75 | |||
76 | if (serviceURI == String.Empty) | ||
77 | { | ||
78 | m_log.Error("[USER CONNECTOR]: No Server URI named in section UserService"); | ||
79 | throw new Exception("User connector init error"); | ||
80 | } | 64 | } |
81 | //m_ServerURI = serviceURI; | 65 | if (m_GatekeeperService == null) |
82 | } | 66 | throw new Exception("Gatekeeper server connector cannot proceed because of missing service"); |
83 | 67 | ||
84 | public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | 68 | HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); |
85 | { | 69 | server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); |
86 | return null; | 70 | server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); |
87 | } | ||
88 | 71 | ||
89 | public UserAccount GetUserAccount(UUID scopeID, UUID userID) | 72 | server.AddHTTPHandler("/foreignagent/", new GatekeeperAgentHandler(m_GatekeeperService).Handler); |
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | 73 | ||
94 | public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) | ||
95 | { | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | public bool SetUserAccount(UserAccount data, UUID principalID, string token) | ||
100 | { | ||
101 | return false; | ||
102 | } | 74 | } |
103 | 75 | ||
104 | public bool CreateUserAccount(UserAccount data, UUID principalID, string token) | 76 | public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server) |
77 | : this(config, server, null) | ||
105 | { | 78 | { |
106 | return false; | ||
107 | } | 79 | } |
108 | 80 | ||
109 | public List<UserAccount> GetUserAccount(UUID scopeID, string query) | ||
110 | { | ||
111 | return null; | ||
112 | } | ||
113 | } | 81 | } |
114 | } | 82 | } |
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index a91b632..b9723a8 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs | |||
@@ -81,12 +81,12 @@ namespace OpenSim.Services.AssetService | |||
81 | } | 81 | } |
82 | 82 | ||
83 | public AssetBase Get(string id) | 83 | public AssetBase Get(string id) |
84 | { | 84 | { |
85 | UUID assetID; | 85 | UUID assetID; |
86 | 86 | ||
87 | if (!UUID.TryParse(id, out assetID)) | 87 | if (!UUID.TryParse(id, out assetID)) |
88 | { | 88 | { |
89 | m_log.WarnFormat("[ASSET SERVICE]: Could not parse requested sset id {0}", id); | 89 | m_log.WarnFormat("[ASSET SERVICE]: Could not parse requested sset id {0}", id); |
90 | return null; | 90 | return null; |
91 | } | 91 | } |
92 | 92 | ||
diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs index dcf090e..9af61a9 100644 --- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs +++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs | |||
@@ -32,6 +32,7 @@ using Nini.Config; | |||
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Services.Base; | 33 | using OpenSim.Services.Base; |
34 | using OpenSim.Data; | 34 | using OpenSim.Data; |
35 | using OpenSim.Framework; | ||
35 | 36 | ||
36 | namespace OpenSim.Services.AuthenticationService | 37 | namespace OpenSim.Services.AuthenticationService |
37 | { | 38 | { |
@@ -43,9 +44,9 @@ namespace OpenSim.Services.AuthenticationService | |||
43 | // | 44 | // |
44 | public class AuthenticationServiceBase : ServiceBase | 45 | public class AuthenticationServiceBase : ServiceBase |
45 | { | 46 | { |
46 | // private static readonly ILog m_log = | 47 | private static readonly ILog m_log = |
47 | // LogManager.GetLogger( | 48 | LogManager.GetLogger( |
48 | // MethodBase.GetCurrentMethod().DeclaringType); | 49 | MethodBase.GetCurrentMethod().DeclaringType); |
49 | 50 | ||
50 | protected IAuthenticationData m_Database; | 51 | protected IAuthenticationData m_Database; |
51 | 52 | ||
@@ -100,6 +101,32 @@ namespace OpenSim.Services.AuthenticationService | |||
100 | return m_Database.CheckToken(principalID, token, 0); | 101 | return m_Database.CheckToken(principalID, token, 0); |
101 | } | 102 | } |
102 | 103 | ||
104 | public virtual bool SetPassword(UUID principalID, string password) | ||
105 | { | ||
106 | string passwordSalt = Util.Md5Hash(UUID.Random().ToString()); | ||
107 | string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + passwordSalt); | ||
108 | |||
109 | AuthenticationData auth = m_Database.Get(principalID); | ||
110 | if (auth == null) | ||
111 | { | ||
112 | auth = new AuthenticationData(); | ||
113 | auth.PrincipalID = principalID; | ||
114 | auth.Data = new System.Collections.Generic.Dictionary<string, object>(); | ||
115 | auth.Data["accountType"] = "UserAccount"; | ||
116 | auth.Data["webLoginKey"] = UUID.Zero.ToString(); | ||
117 | } | ||
118 | auth.Data["passwordHash"] = md5PasswdHash; | ||
119 | auth.Data["passwordSalt"] = passwordSalt; | ||
120 | if (!m_Database.Store(auth)) | ||
121 | { | ||
122 | m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data"); | ||
123 | return false; | ||
124 | } | ||
125 | |||
126 | m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID); | ||
127 | return true; | ||
128 | } | ||
129 | |||
103 | protected string GetToken(UUID principalID, int lifetime) | 130 | protected string GetToken(UUID principalID, int lifetime) |
104 | { | 131 | { |
105 | UUID token = UUID.Random(); | 132 | UUID token = UUID.Random(); |
@@ -109,5 +136,6 @@ namespace OpenSim.Services.AuthenticationService | |||
109 | 136 | ||
110 | return String.Empty; | 137 | return String.Empty; |
111 | } | 138 | } |
139 | |||
112 | } | 140 | } |
113 | } | 141 | } |
diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs index d65665a..021dcf3 100644 --- a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs +++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs | |||
@@ -47,9 +47,9 @@ namespace OpenSim.Services.AuthenticationService | |||
47 | public class PasswordAuthenticationService : | 47 | public class PasswordAuthenticationService : |
48 | AuthenticationServiceBase, IAuthenticationService | 48 | AuthenticationServiceBase, IAuthenticationService |
49 | { | 49 | { |
50 | // private static readonly ILog m_log = | 50 | //private static readonly ILog m_log = |
51 | // LogManager.GetLogger( | 51 | // LogManager.GetLogger( |
52 | // MethodBase.GetCurrentMethod().DeclaringType); | 52 | // MethodBase.GetCurrentMethod().DeclaringType); |
53 | 53 | ||
54 | public PasswordAuthenticationService(IConfigSource config) : | 54 | public PasswordAuthenticationService(IConfigSource config) : |
55 | base(config) | 55 | base(config) |
@@ -66,9 +66,11 @@ namespace OpenSim.Services.AuthenticationService | |||
66 | return String.Empty; | 66 | return String.Empty; |
67 | } | 67 | } |
68 | 68 | ||
69 | string hashed = Util.Md5Hash(Util.Md5Hash(password) + ":" + | 69 | string hashed = Util.Md5Hash(password + ":" + |
70 | data.Data["passwordSalt"].ToString()); | 70 | data.Data["passwordSalt"].ToString()); |
71 | 71 | ||
72 | //m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); | ||
73 | |||
72 | if (data.Data["passwordHash"].ToString() == hashed) | 74 | if (data.Data["passwordHash"].ToString() == hashed) |
73 | { | 75 | { |
74 | return GetToken(principalID, lifetime); | 76 | return GetToken(principalID, lifetime); |
diff --git a/OpenSim/Services/AvatarService/AvatarService.cs b/OpenSim/Services/AvatarService/AvatarService.cs new file mode 100644 index 0000000..19e662c --- /dev/null +++ b/OpenSim/Services/AvatarService/AvatarService.cs | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using log4net; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenMetaverse; | ||
39 | |||
40 | namespace OpenSim.Services.AvatarService | ||
41 | { | ||
42 | public class AvatarService : AvatarServiceBase, IAvatarService | ||
43 | { | ||
44 | private static readonly ILog m_log = | ||
45 | LogManager.GetLogger( | ||
46 | MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | public AvatarService(IConfigSource config) | ||
49 | : base(config) | ||
50 | { | ||
51 | m_log.Debug("[AVATAR SERVICE]: Starting avatar service"); | ||
52 | } | ||
53 | |||
54 | public AvatarData GetAvatar(UUID principalID) | ||
55 | { | ||
56 | AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString()); | ||
57 | if (av.Length == 0) | ||
58 | return null; | ||
59 | |||
60 | AvatarData ret = new AvatarData(); | ||
61 | ret.Data = new Dictionary<string,string>(); | ||
62 | |||
63 | foreach (AvatarBaseData b in av) | ||
64 | { | ||
65 | if (b.Data["Name"] == "AvatarType") | ||
66 | ret.AvatarType = Convert.ToInt32(b.Data["Value"]); | ||
67 | else | ||
68 | ret.Data[b.Data["Name"]] = b.Data["Value"]; | ||
69 | } | ||
70 | |||
71 | return ret; | ||
72 | } | ||
73 | |||
74 | public bool SetAvatar(UUID principalID, AvatarData avatar) | ||
75 | { | ||
76 | int count = 0; | ||
77 | foreach (KeyValuePair<string, string> kvp in avatar.Data) | ||
78 | if (kvp.Key.StartsWith("_")) | ||
79 | count++; | ||
80 | |||
81 | m_log.DebugFormat("[AVATAR SERVICE]: SetAvatar for {0}, attachs={1}", principalID, count); | ||
82 | m_Database.Delete("PrincipalID", principalID.ToString()); | ||
83 | |||
84 | AvatarBaseData av = new AvatarBaseData(); | ||
85 | av.Data = new Dictionary<string,string>(); | ||
86 | |||
87 | av.PrincipalID = principalID; | ||
88 | av.Data["Name"] = "AvatarType"; | ||
89 | av.Data["Value"] = avatar.AvatarType.ToString(); | ||
90 | |||
91 | if (!m_Database.Store(av)) | ||
92 | return false; | ||
93 | |||
94 | foreach (KeyValuePair<string,string> kvp in avatar.Data) | ||
95 | { | ||
96 | av.Data["Name"] = kvp.Key; | ||
97 | av.Data["Value"] = kvp.Value; | ||
98 | |||
99 | if (!m_Database.Store(av)) | ||
100 | { | ||
101 | m_Database.Delete("PrincipalID", principalID.ToString()); | ||
102 | return false; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | return true; | ||
107 | } | ||
108 | |||
109 | public bool ResetAvatar(UUID principalID) | ||
110 | { | ||
111 | return m_Database.Delete("PrincipalID", principalID.ToString()); | ||
112 | } | ||
113 | |||
114 | public bool SetItems(UUID principalID, string[] names, string[] values) | ||
115 | { | ||
116 | AvatarBaseData av = new AvatarBaseData(); | ||
117 | av.Data = new Dictionary<string,string>(); | ||
118 | av.PrincipalID = principalID; | ||
119 | |||
120 | if (names.Length != values.Length) | ||
121 | return false; | ||
122 | |||
123 | for (int i = 0 ; i < names.Length ; i++) | ||
124 | { | ||
125 | av.Data["Name"] = names[i]; | ||
126 | av.Data["Value"] = values[i]; | ||
127 | |||
128 | if (!m_Database.Store(av)) | ||
129 | return false; | ||
130 | } | ||
131 | |||
132 | return true; | ||
133 | } | ||
134 | |||
135 | public bool RemoveItems(UUID principalID, string[] names) | ||
136 | { | ||
137 | foreach (string name in names) | ||
138 | { | ||
139 | m_Database.Delete(principalID, name); | ||
140 | } | ||
141 | return true; | ||
142 | } | ||
143 | } | ||
144 | } | ||
diff --git a/OpenSim/Services/AvatarService/AvatarServiceBase.cs b/OpenSim/Services/AvatarService/AvatarServiceBase.cs new file mode 100644 index 0000000..ab9d7cd --- /dev/null +++ b/OpenSim/Services/AvatarService/AvatarServiceBase.cs | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | |||
36 | namespace OpenSim.Services.AvatarService | ||
37 | { | ||
38 | public class AvatarServiceBase : ServiceBase | ||
39 | { | ||
40 | protected IAvatarData m_Database = null; | ||
41 | |||
42 | public AvatarServiceBase(IConfigSource config) | ||
43 | : base(config) | ||
44 | { | ||
45 | string dllName = String.Empty; | ||
46 | string connString = String.Empty; | ||
47 | string realm = "Avatars"; | ||
48 | |||
49 | // | ||
50 | // Try reading the [DatabaseService] section, if it exists | ||
51 | // | ||
52 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
53 | if (dbConfig != null) | ||
54 | { | ||
55 | if (dllName == String.Empty) | ||
56 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
57 | if (connString == String.Empty) | ||
58 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
59 | } | ||
60 | |||
61 | // | ||
62 | // [AvatarService] section overrides [DatabaseService], if it exists | ||
63 | // | ||
64 | IConfig presenceConfig = config.Configs["AvatarService"]; | ||
65 | if (presenceConfig != null) | ||
66 | { | ||
67 | dllName = presenceConfig.GetString("StorageProvider", dllName); | ||
68 | connString = presenceConfig.GetString("ConnectionString", connString); | ||
69 | realm = presenceConfig.GetString("Realm", realm); | ||
70 | } | ||
71 | |||
72 | // | ||
73 | // We tried, but this doesn't exist. We can't proceed. | ||
74 | // | ||
75 | if (dllName.Equals(String.Empty)) | ||
76 | throw new Exception("No StorageProvider configured"); | ||
77 | |||
78 | m_Database = LoadPlugin<IAvatarData>(dllName, new Object[] { connString, realm }); | ||
79 | if (m_Database == null) | ||
80 | throw new Exception("Could not find a storage interface in the given module " + dllName); | ||
81 | |||
82 | } | ||
83 | } | ||
84 | } | ||
diff --git a/OpenSim/Services/Base/ServiceBase.cs b/OpenSim/Services/Base/ServiceBase.cs index 6bbe978..8e24d85 100644 --- a/OpenSim/Services/Base/ServiceBase.cs +++ b/OpenSim/Services/Base/ServiceBase.cs | |||
@@ -64,7 +64,7 @@ namespace OpenSim.Services.Base | |||
64 | foreach (Type pluginType in pluginAssembly.GetTypes()) | 64 | foreach (Type pluginType in pluginAssembly.GetTypes()) |
65 | { | 65 | { |
66 | if (pluginType.IsPublic) | 66 | if (pluginType.IsPublic) |
67 | { | 67 | { |
68 | if (className != String.Empty && | 68 | if (className != String.Empty && |
69 | pluginType.ToString() != | 69 | pluginType.ToString() != |
70 | pluginType.Namespace + "." + className) | 70 | pluginType.Namespace + "." + className) |
@@ -84,8 +84,9 @@ namespace OpenSim.Services.Base | |||
84 | 84 | ||
85 | return null; | 85 | return null; |
86 | } | 86 | } |
87 | catch (Exception) | 87 | catch (Exception e) |
88 | { | 88 | { |
89 | Console.WriteLine("XXX Exception " + e.StackTrace); | ||
89 | return null; | 90 | return null; |
90 | } | 91 | } |
91 | } | 92 | } |
diff --git a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs index 6d442b7..6847852 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServiceConnector.cs | |||
@@ -93,7 +93,7 @@ namespace OpenSim.Services.Connectors | |||
93 | } | 93 | } |
94 | 94 | ||
95 | public AssetBase Get(string id) | 95 | public AssetBase Get(string id) |
96 | { | 96 | { |
97 | string uri = m_ServerURI + "/assets/" + id; | 97 | string uri = m_ServerURI + "/assets/" + id; |
98 | 98 | ||
99 | AssetBase asset = null; | 99 | AssetBase asset = null; |
@@ -243,7 +243,7 @@ namespace OpenSim.Services.Connectors | |||
243 | if (metadata == null) | 243 | if (metadata == null) |
244 | return false; | 244 | return false; |
245 | 245 | ||
246 | asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type); | 246 | asset = new AssetBase(metadata.FullID, metadata.Name, metadata.Type, UUID.Zero.ToString()); |
247 | asset.Metadata = metadata; | 247 | asset.Metadata = metadata; |
248 | } | 248 | } |
249 | asset.Data = data; | 249 | asset.Data = data; |
diff --git a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs index 19bb3e2..f36fe5b 100644 --- a/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs +++ b/OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs | |||
@@ -67,7 +67,7 @@ namespace OpenSim.Services.Connectors | |||
67 | IConfig assetConfig = source.Configs["AuthenticationService"]; | 67 | IConfig assetConfig = source.Configs["AuthenticationService"]; |
68 | if (assetConfig == null) | 68 | if (assetConfig == null) |
69 | { | 69 | { |
70 | m_log.Error("[USER CONNECTOR]: AuthenticationService missing from OpanSim.ini"); | 70 | m_log.Error("[AUTH CONNECTOR]: AuthenticationService missing from OpanSim.ini"); |
71 | throw new Exception("Authentication connector init error"); | 71 | throw new Exception("Authentication connector init error"); |
72 | } | 72 | } |
73 | 73 | ||
@@ -76,7 +76,7 @@ namespace OpenSim.Services.Connectors | |||
76 | 76 | ||
77 | if (serviceURI == String.Empty) | 77 | if (serviceURI == String.Empty) |
78 | { | 78 | { |
79 | m_log.Error("[USER CONNECTOR]: No Server URI named in section AuthenticationService"); | 79 | m_log.Error("[AUTH CONNECTOR]: No Server URI named in section AuthenticationService"); |
80 | throw new Exception("Authentication connector init error"); | 80 | throw new Exception("Authentication connector init error"); |
81 | } | 81 | } |
82 | m_ServerURI = serviceURI; | 82 | m_ServerURI = serviceURI; |
@@ -146,5 +146,11 @@ namespace OpenSim.Services.Connectors | |||
146 | 146 | ||
147 | return true; | 147 | return true; |
148 | } | 148 | } |
149 | |||
150 | public bool SetPassword(UUID principalID, string passwd) | ||
151 | { | ||
152 | // nope, we don't do this | ||
153 | return false; | ||
154 | } | ||
149 | } | 155 | } |
150 | } | 156 | } |
diff --git a/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs new file mode 100644 index 0000000..96c05a9 --- /dev/null +++ b/OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs | |||
@@ -0,0 +1,317 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using IAvatarService = OpenSim.Services.Interfaces.IAvatarService; | ||
40 | using OpenSim.Server.Base; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Services.Connectors | ||
44 | { | ||
45 | public class AvatarServicesConnector : IAvatarService | ||
46 | { | ||
47 | private static readonly ILog m_log = | ||
48 | LogManager.GetLogger( | ||
49 | MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private string m_ServerURI = String.Empty; | ||
52 | |||
53 | public AvatarServicesConnector() | ||
54 | { | ||
55 | } | ||
56 | |||
57 | public AvatarServicesConnector(string serverURI) | ||
58 | { | ||
59 | m_ServerURI = serverURI.TrimEnd('/'); | ||
60 | } | ||
61 | |||
62 | public AvatarServicesConnector(IConfigSource source) | ||
63 | { | ||
64 | Initialise(source); | ||
65 | } | ||
66 | |||
67 | public virtual void Initialise(IConfigSource source) | ||
68 | { | ||
69 | IConfig gridConfig = source.Configs["AvatarService"]; | ||
70 | if (gridConfig == null) | ||
71 | { | ||
72 | m_log.Error("[AVATAR CONNECTOR]: AvatarService missing from OpenSim.ini"); | ||
73 | throw new Exception("Avatar connector init error"); | ||
74 | } | ||
75 | |||
76 | string serviceURI = gridConfig.GetString("AvatarServerURI", | ||
77 | String.Empty); | ||
78 | |||
79 | if (serviceURI == String.Empty) | ||
80 | { | ||
81 | m_log.Error("[AVATAR CONNECTOR]: No Server URI named in section AvatarService"); | ||
82 | throw new Exception("Avatar connector init error"); | ||
83 | } | ||
84 | m_ServerURI = serviceURI; | ||
85 | } | ||
86 | |||
87 | |||
88 | #region IAvatarService | ||
89 | |||
90 | public AvatarData GetAvatar(UUID userID) | ||
91 | { | ||
92 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
93 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
94 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
95 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
96 | sendData["METHOD"] = "getavatar"; | ||
97 | |||
98 | sendData["UserID"] = userID; | ||
99 | |||
100 | string reply = string.Empty; | ||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/avatar", | ||
107 | reqString); | ||
108 | if (reply == null || (reply != null && reply == string.Empty)) | ||
109 | { | ||
110 | m_log.DebugFormat("[AVATAR CONNECTOR]: GetAgent received null or empty reply"); | ||
111 | return null; | ||
112 | } | ||
113 | } | ||
114 | catch (Exception e) | ||
115 | { | ||
116 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
117 | } | ||
118 | |||
119 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
120 | AvatarData avatar = null; | ||
121 | |||
122 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
123 | { | ||
124 | if (replyData["result"] is Dictionary<string, object>) | ||
125 | { | ||
126 | avatar = new AvatarData((Dictionary<string, object>)replyData["result"]); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return avatar; | ||
131 | |||
132 | } | ||
133 | |||
134 | public bool SetAvatar(UUID userID, AvatarData avatar) | ||
135 | { | ||
136 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
137 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
138 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
139 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
140 | sendData["METHOD"] = "setavatar"; | ||
141 | |||
142 | sendData["UserID"] = userID.ToString(); | ||
143 | |||
144 | Dictionary<string, object> structData = avatar.ToKeyValuePairs(); | ||
145 | |||
146 | foreach (KeyValuePair<string, object> kvp in structData) | ||
147 | sendData[kvp.Key] = kvp.Value.ToString(); | ||
148 | |||
149 | |||
150 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
151 | //m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
152 | try | ||
153 | { | ||
154 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
155 | m_ServerURI + "/avatar", | ||
156 | reqString); | ||
157 | if (reply != string.Empty) | ||
158 | { | ||
159 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
160 | |||
161 | if (replyData.ContainsKey("result")) | ||
162 | { | ||
163 | if (replyData["result"].ToString().ToLower() == "success") | ||
164 | return true; | ||
165 | else | ||
166 | return false; | ||
167 | } | ||
168 | else | ||
169 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar reply data does not contain result field"); | ||
170 | |||
171 | } | ||
172 | else | ||
173 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetAvatar received empty reply"); | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
178 | } | ||
179 | |||
180 | return false; | ||
181 | } | ||
182 | |||
183 | public bool ResetAvatar(UUID userID) | ||
184 | { | ||
185 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
186 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
187 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
188 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
189 | sendData["METHOD"] = "resetavatar"; | ||
190 | |||
191 | sendData["UserID"] = userID.ToString(); | ||
192 | |||
193 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
194 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
195 | try | ||
196 | { | ||
197 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
198 | m_ServerURI + "/avatar", | ||
199 | reqString); | ||
200 | if (reply != string.Empty) | ||
201 | { | ||
202 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
203 | |||
204 | if (replyData.ContainsKey("result")) | ||
205 | { | ||
206 | if (replyData["result"].ToString().ToLower() == "success") | ||
207 | return true; | ||
208 | else | ||
209 | return false; | ||
210 | } | ||
211 | else | ||
212 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); | ||
213 | |||
214 | } | ||
215 | else | ||
216 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); | ||
217 | } | ||
218 | catch (Exception e) | ||
219 | { | ||
220 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
221 | } | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
226 | public bool SetItems(UUID userID, string[] names, string[] values) | ||
227 | { | ||
228 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
229 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
230 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
231 | sendData["METHOD"] = "setitems"; | ||
232 | |||
233 | sendData["UserID"] = userID.ToString(); | ||
234 | sendData["Names"] = new List<string>(names); | ||
235 | sendData["Values"] = new List<string>(values); | ||
236 | |||
237 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
238 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
239 | try | ||
240 | { | ||
241 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
242 | m_ServerURI + "/avatar", | ||
243 | reqString); | ||
244 | if (reply != string.Empty) | ||
245 | { | ||
246 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
247 | |||
248 | if (replyData.ContainsKey("result")) | ||
249 | { | ||
250 | if (replyData["result"].ToString().ToLower() == "success") | ||
251 | return true; | ||
252 | else | ||
253 | return false; | ||
254 | } | ||
255 | else | ||
256 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems reply data does not contain result field"); | ||
257 | |||
258 | } | ||
259 | else | ||
260 | m_log.DebugFormat("[AVATAR CONNECTOR]: SetItems received empty reply"); | ||
261 | } | ||
262 | catch (Exception e) | ||
263 | { | ||
264 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
265 | } | ||
266 | |||
267 | return false; | ||
268 | } | ||
269 | |||
270 | public bool RemoveItems(UUID userID, string[] names) | ||
271 | { | ||
272 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
273 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
274 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
275 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
276 | sendData["METHOD"] = "removeitems"; | ||
277 | |||
278 | sendData["UserID"] = userID.ToString(); | ||
279 | sendData["Names"] = new List<string>(names); | ||
280 | |||
281 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
282 | // m_log.DebugFormat("[AVATAR CONNECTOR]: queryString = {0}", reqString); | ||
283 | try | ||
284 | { | ||
285 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
286 | m_ServerURI + "/avatar", | ||
287 | reqString); | ||
288 | if (reply != string.Empty) | ||
289 | { | ||
290 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
291 | |||
292 | if (replyData.ContainsKey("result")) | ||
293 | { | ||
294 | if (replyData["result"].ToString().ToLower() == "success") | ||
295 | return true; | ||
296 | else | ||
297 | return false; | ||
298 | } | ||
299 | else | ||
300 | m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems reply data does not contain result field"); | ||
301 | |||
302 | } | ||
303 | else | ||
304 | m_log.DebugFormat("[AVATAR CONNECTOR]: RemoveItems received empty reply"); | ||
305 | } | ||
306 | catch (Exception e) | ||
307 | { | ||
308 | m_log.DebugFormat("[AVATAR CONNECTOR]: Exception when contacting avatar server: {0}", e.Message); | ||
309 | } | ||
310 | |||
311 | return false; | ||
312 | } | ||
313 | |||
314 | #endregion | ||
315 | |||
316 | } | ||
317 | } | ||
diff --git a/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs new file mode 100644 index 0000000..baefebd --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsServiceConnector.cs | |||
@@ -0,0 +1,241 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class FriendsServicesConnector : IFriendsService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public FriendsServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public FriendsServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public FriendsServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["FriendsService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[FRIENDS CONNECTOR]: FriendsService missing from OpenSim.ini"); | ||
72 | throw new Exception("Friends connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("FriendsServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[FRIENDS CONNECTOR]: No Server URI named in section FriendsService"); | ||
81 | throw new Exception("Friends connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IFriendsService | ||
88 | |||
89 | public FriendInfo[] GetFriends(UUID PrincipalID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | |||
93 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
94 | sendData["METHOD"] = "getfriends"; | ||
95 | |||
96 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
97 | |||
98 | try | ||
99 | { | ||
100 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
101 | m_ServerURI + "/friends", | ||
102 | reqString); | ||
103 | if (reply != string.Empty) | ||
104 | { | ||
105 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
106 | |||
107 | if (replyData != null) | ||
108 | { | ||
109 | if (replyData.ContainsKey("result") && (replyData["result"].ToString().ToLower() == "null")) | ||
110 | { | ||
111 | return new FriendInfo[0]; | ||
112 | } | ||
113 | |||
114 | List<FriendInfo> finfos = new List<FriendInfo>(); | ||
115 | Dictionary<string, object>.ValueCollection finfosList = replyData.Values; | ||
116 | //m_log.DebugFormat("[FRIENDS CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count); | ||
117 | foreach (object f in finfosList) | ||
118 | { | ||
119 | if (f is Dictionary<string, object>) | ||
120 | { | ||
121 | FriendInfo finfo = new FriendInfo((Dictionary<string, object>)f); | ||
122 | finfos.Add(finfo); | ||
123 | } | ||
124 | else | ||
125 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received invalid response type {1}", | ||
126 | PrincipalID, f.GetType()); | ||
127 | } | ||
128 | |||
129 | // Success | ||
130 | return finfos.ToArray(); | ||
131 | } | ||
132 | |||
133 | else | ||
134 | m_log.DebugFormat("[FRIENDS CONNECTOR]: GetFriends {0} received null response", | ||
135 | PrincipalID); | ||
136 | |||
137 | } | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
142 | } | ||
143 | |||
144 | return new FriendInfo[0]; | ||
145 | |||
146 | } | ||
147 | |||
148 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | ||
149 | { | ||
150 | FriendInfo finfo = new FriendInfo(); | ||
151 | finfo.PrincipalID = PrincipalID; | ||
152 | finfo.Friend = Friend; | ||
153 | finfo.MyFlags = flags; | ||
154 | |||
155 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
156 | |||
157 | sendData["METHOD"] = "storefriend"; | ||
158 | |||
159 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
160 | |||
161 | string reply = string.Empty; | ||
162 | try | ||
163 | { | ||
164 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
165 | m_ServerURI + "/friends", | ||
166 | ServerUtils.BuildQueryString(sendData)); | ||
167 | } | ||
168 | catch (Exception e) | ||
169 | { | ||
170 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
171 | return false; | ||
172 | } | ||
173 | |||
174 | if (reply != string.Empty) | ||
175 | { | ||
176 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
177 | |||
178 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
179 | { | ||
180 | bool success = false; | ||
181 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
182 | return success; | ||
183 | } | ||
184 | else | ||
185 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", | ||
186 | PrincipalID, Friend); | ||
187 | } | ||
188 | else | ||
189 | m_log.DebugFormat("[FRIENDS CONNECTOR]: StoreFriend received null reply"); | ||
190 | |||
191 | return false; | ||
192 | |||
193 | } | ||
194 | |||
195 | public bool Delete(UUID PrincipalID, string Friend) | ||
196 | { | ||
197 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
198 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
199 | sendData["FRIENDS"] = Friend; | ||
200 | sendData["METHOD"] = "deletefriend"; | ||
201 | |||
202 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
203 | |||
204 | string reply = string.Empty; | ||
205 | try | ||
206 | { | ||
207 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
208 | m_ServerURI + "/friends", | ||
209 | ServerUtils.BuildQueryString(sendData)); | ||
210 | } | ||
211 | catch (Exception e) | ||
212 | { | ||
213 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting friends server: {0}", e.Message); | ||
214 | return false; | ||
215 | } | ||
216 | |||
217 | if (reply != string.Empty) | ||
218 | { | ||
219 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
220 | |||
221 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
222 | { | ||
223 | bool success = false; | ||
224 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
225 | return success; | ||
226 | } | ||
227 | else | ||
228 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend {0} {1} received null response", | ||
229 | PrincipalID, Friend); | ||
230 | } | ||
231 | else | ||
232 | m_log.DebugFormat("[FRIENDS CONNECTOR]: DeleteFriend received null reply"); | ||
233 | |||
234 | return false; | ||
235 | |||
236 | } | ||
237 | |||
238 | #endregion | ||
239 | |||
240 | } | ||
241 | } | ||
diff --git a/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs new file mode 100644 index 0000000..a29ac28 --- /dev/null +++ b/OpenSim/Services/Connectors/Friends/FriendsSimConnector.cs | |||
@@ -0,0 +1,167 @@ | |||
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 | |||
32 | using OpenSim.Services.Interfaces; | ||
33 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
34 | using OpenSim.Server.Base; | ||
35 | using OpenSim.Framework.Servers.HttpServer; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Services.Connectors.Friends | ||
41 | { | ||
42 | public class FriendsSimConnector | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | public bool FriendshipOffered(GridRegion region, UUID userID, UUID friendID, string message) | ||
47 | { | ||
48 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
49 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
50 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
51 | sendData["METHOD"] = "friendship_offered"; | ||
52 | |||
53 | sendData["FromID"] = userID.ToString(); | ||
54 | sendData["ToID"] = friendID.ToString(); | ||
55 | sendData["Message"] = message; | ||
56 | |||
57 | return Call(region, sendData); | ||
58 | |||
59 | } | ||
60 | |||
61 | public bool FriendshipApproved(GridRegion region, UUID userID, string userName, UUID friendID) | ||
62 | { | ||
63 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
64 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
65 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
66 | sendData["METHOD"] = "friendship_approved"; | ||
67 | |||
68 | sendData["FromID"] = userID.ToString(); | ||
69 | sendData["FromName"] = userName; | ||
70 | sendData["ToID"] = friendID.ToString(); | ||
71 | |||
72 | return Call(region, sendData); | ||
73 | } | ||
74 | |||
75 | public bool FriendshipDenied(GridRegion region, UUID userID, string userName, UUID friendID) | ||
76 | { | ||
77 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
78 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
79 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
80 | sendData["METHOD"] = "friendship_denied"; | ||
81 | |||
82 | sendData["FromID"] = userID.ToString(); | ||
83 | sendData["FromName"] = userName; | ||
84 | sendData["ToID"] = friendID.ToString(); | ||
85 | |||
86 | return Call(region, sendData); | ||
87 | } | ||
88 | |||
89 | public bool FriendshipTerminated(GridRegion region, UUID userID, UUID friendID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
93 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
94 | sendData["METHOD"] = "friendship_terminated"; | ||
95 | |||
96 | sendData["FromID"] = userID.ToString(); | ||
97 | sendData["ToID"] = friendID.ToString(); | ||
98 | |||
99 | return Call(region, sendData); | ||
100 | } | ||
101 | |||
102 | public bool GrantRights(GridRegion region, UUID userID, UUID friendID, int userFlags, int rights) | ||
103 | { | ||
104 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
105 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
106 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
107 | sendData["METHOD"] = "grant_rights"; | ||
108 | |||
109 | sendData["FromID"] = userID.ToString(); | ||
110 | sendData["ToID"] = friendID.ToString(); | ||
111 | sendData["UserFlags"] = userFlags.ToString(); | ||
112 | sendData["Rights"] = rights.ToString(); | ||
113 | |||
114 | return Call(region, sendData); | ||
115 | } | ||
116 | |||
117 | public bool StatusNotify(GridRegion region, UUID userID, UUID friendID, bool online) | ||
118 | { | ||
119 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
120 | //sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
121 | //sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
122 | sendData["METHOD"] = "status"; | ||
123 | |||
124 | sendData["FromID"] = userID.ToString(); | ||
125 | sendData["ToID"] = friendID.ToString(); | ||
126 | sendData["Online"] = online.ToString(); | ||
127 | |||
128 | return Call(region, sendData); | ||
129 | } | ||
130 | |||
131 | private bool Call(GridRegion region, Dictionary<string, object> sendData) | ||
132 | { | ||
133 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
134 | // m_log.DebugFormat("[FRIENDS CONNECTOR]: queryString = {0}", reqString); | ||
135 | try | ||
136 | { | ||
137 | string url = "http://" + region.ExternalHostName + ":" + region.HttpPort; | ||
138 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
139 | url + "/friends", | ||
140 | reqString); | ||
141 | if (reply != string.Empty) | ||
142 | { | ||
143 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
144 | |||
145 | if (replyData.ContainsKey("RESULT")) | ||
146 | { | ||
147 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
148 | return true; | ||
149 | else | ||
150 | return false; | ||
151 | } | ||
152 | else | ||
153 | m_log.DebugFormat("[FRIENDS CONNECTOR]: reply data does not contain result field"); | ||
154 | |||
155 | } | ||
156 | else | ||
157 | m_log.DebugFormat("[FRIENDS CONNECTOR]: received empty reply"); | ||
158 | } | ||
159 | catch (Exception e) | ||
160 | { | ||
161 | m_log.DebugFormat("[FRIENDS CONNECTOR]: Exception when contacting remote sim: {0}", e.Message); | ||
162 | } | ||
163 | |||
164 | return false; | ||
165 | } | ||
166 | } | ||
167 | } | ||
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 04c7c53..a453d99 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | |||
@@ -460,6 +460,153 @@ namespace OpenSim.Services.Connectors | |||
460 | return rinfos; | 460 | return rinfos; |
461 | } | 461 | } |
462 | 462 | ||
463 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
464 | { | ||
465 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
466 | |||
467 | sendData["SCOPEID"] = scopeID.ToString(); | ||
468 | |||
469 | sendData["METHOD"] = "get_default_regions"; | ||
470 | |||
471 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
472 | string reply = string.Empty; | ||
473 | try | ||
474 | { | ||
475 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
476 | m_ServerURI + "/grid", | ||
477 | ServerUtils.BuildQueryString(sendData)); | ||
478 | |||
479 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
480 | } | ||
481 | catch (Exception e) | ||
482 | { | ||
483 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
484 | return rinfos; | ||
485 | } | ||
486 | |||
487 | if (reply != string.Empty) | ||
488 | { | ||
489 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
490 | |||
491 | if (replyData != null) | ||
492 | { | ||
493 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
494 | foreach (object r in rinfosList) | ||
495 | { | ||
496 | if (r is Dictionary<string, object>) | ||
497 | { | ||
498 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
499 | rinfos.Add(rinfo); | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | else | ||
504 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", | ||
505 | scopeID); | ||
506 | } | ||
507 | else | ||
508 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); | ||
509 | |||
510 | return rinfos; | ||
511 | } | ||
512 | |||
513 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
514 | { | ||
515 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
516 | |||
517 | sendData["SCOPEID"] = scopeID.ToString(); | ||
518 | sendData["X"] = x.ToString(); | ||
519 | sendData["Y"] = y.ToString(); | ||
520 | |||
521 | sendData["METHOD"] = "get_fallback_regions"; | ||
522 | |||
523 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
524 | string reply = string.Empty; | ||
525 | try | ||
526 | { | ||
527 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
528 | m_ServerURI + "/grid", | ||
529 | ServerUtils.BuildQueryString(sendData)); | ||
530 | |||
531 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
532 | } | ||
533 | catch (Exception e) | ||
534 | { | ||
535 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
536 | return rinfos; | ||
537 | } | ||
538 | |||
539 | if (reply != string.Empty) | ||
540 | { | ||
541 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
542 | |||
543 | if (replyData != null) | ||
544 | { | ||
545 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
546 | foreach (object r in rinfosList) | ||
547 | { | ||
548 | if (r is Dictionary<string, object>) | ||
549 | { | ||
550 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
551 | rinfos.Add(rinfo); | ||
552 | } | ||
553 | } | ||
554 | } | ||
555 | else | ||
556 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", | ||
557 | scopeID, x, y); | ||
558 | } | ||
559 | else | ||
560 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); | ||
561 | |||
562 | return rinfos; | ||
563 | } | ||
564 | |||
565 | public virtual int GetRegionFlags(UUID scopeID, UUID regionID) | ||
566 | { | ||
567 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
568 | |||
569 | sendData["SCOPEID"] = scopeID.ToString(); | ||
570 | sendData["REGIONID"] = regionID.ToString(); | ||
571 | |||
572 | sendData["METHOD"] = "get_region_flags"; | ||
573 | |||
574 | string reply = string.Empty; | ||
575 | try | ||
576 | { | ||
577 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
578 | m_ServerURI + "/grid", | ||
579 | ServerUtils.BuildQueryString(sendData)); | ||
580 | } | ||
581 | catch (Exception e) | ||
582 | { | ||
583 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
584 | return -1; | ||
585 | } | ||
586 | |||
587 | int flags = -1; | ||
588 | |||
589 | if (reply != string.Empty) | ||
590 | { | ||
591 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
592 | |||
593 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
594 | { | ||
595 | Int32.TryParse((string)replyData["result"], out flags); | ||
596 | //else | ||
597 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", | ||
598 | // scopeID, regionID, replyData["result"].GetType()); | ||
599 | } | ||
600 | else | ||
601 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", | ||
602 | scopeID, regionID); | ||
603 | } | ||
604 | else | ||
605 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); | ||
606 | |||
607 | return flags; | ||
608 | } | ||
609 | |||
463 | #endregion | 610 | #endregion |
464 | 611 | ||
465 | } | 612 | } |
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs deleted file mode 100644 index 7098b07..0000000 --- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs +++ /dev/null | |||
@@ -1,254 +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.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Drawing; | ||
33 | using System.Net; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Services.Interfaces; | ||
36 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | |||
38 | using OpenSim.Framework; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | |||
45 | namespace OpenSim.Services.Connectors.Grid | ||
46 | { | ||
47 | public class HypergridServiceConnector | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IAssetService m_AssetService; | ||
52 | |||
53 | public HypergridServiceConnector(IAssetService assService) | ||
54 | { | ||
55 | m_AssetService = assService; | ||
56 | } | ||
57 | |||
58 | public UUID LinkRegion(GridRegion info, out ulong realHandle) | ||
59 | { | ||
60 | UUID uuid = UUID.Zero; | ||
61 | realHandle = 0; | ||
62 | |||
63 | Hashtable hash = new Hashtable(); | ||
64 | hash["region_name"] = info.RegionName; | ||
65 | |||
66 | IList paramList = new ArrayList(); | ||
67 | paramList.Add(hash); | ||
68 | |||
69 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
70 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
71 | m_log.Debug("[HGrid]: Linking to " + uri); | ||
72 | XmlRpcResponse response = null; | ||
73 | try | ||
74 | { | ||
75 | response = request.Send(uri, 10000); | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
80 | return uuid; | ||
81 | } | ||
82 | |||
83 | if (response.IsFault) | ||
84 | { | ||
85 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | hash = (Hashtable)response.Value; | ||
90 | //foreach (Object o in hash) | ||
91 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
92 | try | ||
93 | { | ||
94 | UUID.TryParse((string)hash["uuid"], out uuid); | ||
95 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
96 | info.RegionID = uuid; | ||
97 | if ((string)hash["handle"] != null) | ||
98 | { | ||
99 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
100 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
101 | } | ||
102 | //if (hash["region_image"] != null) | ||
103 | //{ | ||
104 | // UUID img = UUID.Zero; | ||
105 | // UUID.TryParse((string)hash["region_image"], out img); | ||
106 | // info.RegionSettings.TerrainImageID = img; | ||
107 | //} | ||
108 | if (hash["region_name"] != null) | ||
109 | { | ||
110 | info.RegionName = (string)hash["region_name"]; | ||
111 | //m_log.Debug(">> " + info.RegionName); | ||
112 | } | ||
113 | if (hash["internal_port"] != null) | ||
114 | { | ||
115 | int port = Convert.ToInt32((string)hash["internal_port"]); | ||
116 | info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port); | ||
117 | //m_log.Debug(">> " + info.InternalEndPoint.ToString()); | ||
118 | } | ||
119 | |||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
124 | } | ||
125 | } | ||
126 | return uuid; | ||
127 | } | ||
128 | |||
129 | public void GetMapImage(GridRegion info) | ||
130 | { | ||
131 | try | ||
132 | { | ||
133 | string regionimage = "regionImage" + info.RegionID.ToString(); | ||
134 | regionimage = regionimage.Replace("-", ""); | ||
135 | |||
136 | WebClient c = new WebClient(); | ||
137 | string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage; | ||
138 | //m_log.Debug("JPEG: " + uri); | ||
139 | c.DownloadFile(uri, info.RegionID.ToString() + ".jpg"); | ||
140 | Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg"); | ||
141 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
142 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
143 | AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString(), (sbyte)AssetType.Texture); | ||
144 | |||
145 | // !!! for now | ||
146 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
147 | |||
148 | ass.Temporary = true; | ||
149 | ass.Local = true; | ||
150 | ass.Data = imageData; | ||
151 | |||
152 | m_AssetService.Store(ass); | ||
153 | |||
154 | // finally | ||
155 | info.TerrainImage = ass.FullID; | ||
156 | |||
157 | } | ||
158 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
159 | { | ||
160 | m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache"); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | public bool InformRegionOfUser(GridRegion regInfo, AgentCircuitData agentData, GridRegion home, string userServer, string assetServer, string inventoryServer) | ||
165 | { | ||
166 | string capsPath = agentData.CapsPath; | ||
167 | Hashtable loginParams = new Hashtable(); | ||
168 | loginParams["session_id"] = agentData.SessionID.ToString(); | ||
169 | |||
170 | loginParams["firstname"] = agentData.firstname; | ||
171 | loginParams["lastname"] = agentData.lastname; | ||
172 | |||
173 | loginParams["agent_id"] = agentData.AgentID.ToString(); | ||
174 | loginParams["circuit_code"] = agentData.circuitcode.ToString(); | ||
175 | loginParams["startpos_x"] = agentData.startpos.X.ToString(); | ||
176 | loginParams["startpos_y"] = agentData.startpos.Y.ToString(); | ||
177 | loginParams["startpos_z"] = agentData.startpos.Z.ToString(); | ||
178 | loginParams["caps_path"] = capsPath; | ||
179 | |||
180 | if (home != null) | ||
181 | { | ||
182 | loginParams["region_uuid"] = home.RegionID.ToString(); | ||
183 | loginParams["regionhandle"] = home.RegionHandle.ToString(); | ||
184 | loginParams["home_address"] = home.ExternalHostName; | ||
185 | loginParams["home_port"] = home.HttpPort.ToString(); | ||
186 | loginParams["internal_port"] = home.InternalEndPoint.Port.ToString(); | ||
187 | |||
188 | m_log.Debug(" --------- Home -------"); | ||
189 | m_log.Debug(" >> " + loginParams["home_address"] + " <<"); | ||
190 | m_log.Debug(" >> " + loginParams["region_uuid"] + " <<"); | ||
191 | m_log.Debug(" >> " + loginParams["regionhandle"] + " <<"); | ||
192 | m_log.Debug(" >> " + loginParams["home_port"] + " <<"); | ||
193 | m_log.Debug(" --------- ------------ -------"); | ||
194 | } | ||
195 | else | ||
196 | m_log.WarnFormat("[HGrid]: Home region not found for {0} {1}", agentData.firstname, agentData.lastname); | ||
197 | |||
198 | loginParams["userserver_id"] = userServer; | ||
199 | loginParams["assetserver_id"] = assetServer; | ||
200 | loginParams["inventoryserver_id"] = inventoryServer; | ||
201 | |||
202 | |||
203 | ArrayList SendParams = new ArrayList(); | ||
204 | SendParams.Add(loginParams); | ||
205 | |||
206 | // Send | ||
207 | string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/"; | ||
208 | //m_log.Debug("XXX uri: " + uri); | ||
209 | XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams); | ||
210 | XmlRpcResponse reply; | ||
211 | try | ||
212 | { | ||
213 | reply = request.Send(uri, 6000); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | if (!reply.IsFault) | ||
222 | { | ||
223 | bool responseSuccess = true; | ||
224 | if (reply.Value != null) | ||
225 | { | ||
226 | Hashtable resp = (Hashtable)reply.Value; | ||
227 | if (resp.ContainsKey("success")) | ||
228 | { | ||
229 | if ((string)resp["success"] == "FALSE") | ||
230 | { | ||
231 | responseSuccess = false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | if (responseSuccess) | ||
236 | { | ||
237 | m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID); | ||
238 | return true; | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients"); | ||
243 | return false; | ||
244 | } | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode); | ||
249 | return false; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | } | ||
254 | } | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs new file mode 100644 index 0000000..9f73b38 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | |||
@@ -0,0 +1,245 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Drawing; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | |||
8 | using OpenSim.Framework; | ||
9 | using OpenSim.Services.Interfaces; | ||
10 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using OpenMetaverse.Imaging; | ||
14 | using Nwc.XmlRpc; | ||
15 | using log4net; | ||
16 | |||
17 | using OpenSim.Services.Connectors.Simulation; | ||
18 | |||
19 | namespace OpenSim.Services.Connectors.Hypergrid | ||
20 | { | ||
21 | public class GatekeeperServiceConnector : SimulationServiceConnector | ||
22 | { | ||
23 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
24 | |||
25 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
26 | |||
27 | private IAssetService m_AssetService; | ||
28 | |||
29 | public GatekeeperServiceConnector() : base() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | public GatekeeperServiceConnector(IAssetService assService) | ||
34 | { | ||
35 | m_AssetService = assService; | ||
36 | } | ||
37 | |||
38 | protected override string AgentPath() | ||
39 | { | ||
40 | return "/foreignagent/"; | ||
41 | } | ||
42 | |||
43 | protected override string ObjectPath() | ||
44 | { | ||
45 | return "/foreignobject/"; | ||
46 | } | ||
47 | |||
48 | public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string externalName, out string imageURL, out string reason) | ||
49 | { | ||
50 | regionID = UUID.Zero; | ||
51 | imageURL = string.Empty; | ||
52 | realHandle = 0; | ||
53 | externalName = string.Empty; | ||
54 | reason = string.Empty; | ||
55 | |||
56 | Hashtable hash = new Hashtable(); | ||
57 | hash["region_name"] = info.RegionName; | ||
58 | |||
59 | IList paramList = new ArrayList(); | ||
60 | paramList.Add(hash); | ||
61 | |||
62 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
63 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
64 | //m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Linking to " + uri); | ||
65 | XmlRpcResponse response = null; | ||
66 | try | ||
67 | { | ||
68 | response = request.Send(uri, 10000); | ||
69 | } | ||
70 | catch (Exception e) | ||
71 | { | ||
72 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
73 | reason = "Error contacting remote server"; | ||
74 | return false; | ||
75 | } | ||
76 | |||
77 | if (response.IsFault) | ||
78 | { | ||
79 | reason = response.FaultString; | ||
80 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | hash = (Hashtable)response.Value; | ||
85 | //foreach (Object o in hash) | ||
86 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
87 | try | ||
88 | { | ||
89 | bool success = false; | ||
90 | Boolean.TryParse((string)hash["result"], out success); | ||
91 | if (success) | ||
92 | { | ||
93 | UUID.TryParse((string)hash["uuid"], out regionID); | ||
94 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
95 | if ((string)hash["handle"] != null) | ||
96 | { | ||
97 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
98 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
99 | } | ||
100 | if (hash["region_image"] != null) | ||
101 | imageURL = (string)hash["region_image"]; | ||
102 | if (hash["external_name"] != null) | ||
103 | externalName = (string)hash["external_name"]; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | catch (Exception e) | ||
108 | { | ||
109 | reason = "Error parsing return arguments"; | ||
110 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | return true; | ||
115 | } | ||
116 | |||
117 | UUID m_MissingTexture = new UUID("5748decc-f629-461c-9a36-a35a221fe21f"); | ||
118 | |||
119 | public UUID GetMapImage(UUID regionID, string imageURL) | ||
120 | { | ||
121 | if (m_AssetService == null) | ||
122 | return m_MissingTexture; | ||
123 | |||
124 | try | ||
125 | { | ||
126 | |||
127 | WebClient c = new WebClient(); | ||
128 | //m_log.Debug("JPEG: " + imageURL); | ||
129 | string filename = regionID.ToString(); | ||
130 | c.DownloadFile(imageURL, filename + ".jpg"); | ||
131 | Bitmap m = new Bitmap(filename + ".jpg"); | ||
132 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
133 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
134 | AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture, regionID.ToString()); | ||
135 | |||
136 | // !!! for now | ||
137 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
138 | |||
139 | ass.Temporary = true; | ||
140 | ass.Local = true; | ||
141 | ass.Data = imageData; | ||
142 | |||
143 | m_AssetService.Store(ass); | ||
144 | |||
145 | // finally | ||
146 | return ass.FullID; | ||
147 | |||
148 | } | ||
149 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
150 | { | ||
151 | m_log.Warn("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache"); | ||
152 | } | ||
153 | return UUID.Zero; | ||
154 | } | ||
155 | |||
156 | public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID) | ||
157 | { | ||
158 | Hashtable hash = new Hashtable(); | ||
159 | hash["region_uuid"] = regionID.ToString(); | ||
160 | |||
161 | IList paramList = new ArrayList(); | ||
162 | paramList.Add(hash); | ||
163 | |||
164 | XmlRpcRequest request = new XmlRpcRequest("get_region", paramList); | ||
165 | string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/"; | ||
166 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: contacting " + uri); | ||
167 | XmlRpcResponse response = null; | ||
168 | try | ||
169 | { | ||
170 | response = request.Send(uri, 10000); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
175 | return null; | ||
176 | } | ||
177 | |||
178 | if (response.IsFault) | ||
179 | { | ||
180 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
181 | return null; | ||
182 | } | ||
183 | |||
184 | hash = (Hashtable)response.Value; | ||
185 | //foreach (Object o in hash) | ||
186 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
187 | try | ||
188 | { | ||
189 | bool success = false; | ||
190 | Boolean.TryParse((string)hash["result"], out success); | ||
191 | if (success) | ||
192 | { | ||
193 | GridRegion region = new GridRegion(); | ||
194 | |||
195 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
196 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
197 | int n = 0; | ||
198 | if (hash["x"] != null) | ||
199 | { | ||
200 | Int32.TryParse((string)hash["x"], out n); | ||
201 | region.RegionLocX = n; | ||
202 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
203 | } | ||
204 | if (hash["y"] != null) | ||
205 | { | ||
206 | Int32.TryParse((string)hash["y"], out n); | ||
207 | region.RegionLocY = n; | ||
208 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
209 | } | ||
210 | if (hash["region_name"] != null) | ||
211 | { | ||
212 | region.RegionName = (string)hash["region_name"]; | ||
213 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
214 | } | ||
215 | if (hash["hostname"] != null) | ||
216 | region.ExternalHostName = (string)hash["hostname"]; | ||
217 | if (hash["http_port"] != null) | ||
218 | { | ||
219 | uint p = 0; | ||
220 | UInt32.TryParse((string)hash["http_port"], out p); | ||
221 | region.HttpPort = p; | ||
222 | } | ||
223 | if (hash["internal_port"] != null) | ||
224 | { | ||
225 | int p = 0; | ||
226 | Int32.TryParse((string)hash["internal_port"], out p); | ||
227 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
228 | } | ||
229 | |||
230 | // Successful return | ||
231 | return region; | ||
232 | } | ||
233 | |||
234 | } | ||
235 | catch (Exception e) | ||
236 | { | ||
237 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
238 | return null; | ||
239 | } | ||
240 | |||
241 | return null; | ||
242 | } | ||
243 | |||
244 | } | ||
245 | } | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs new file mode 100644 index 0000000..83d3449 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | |||
@@ -0,0 +1,370 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.IO; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | using System.Text; | ||
8 | |||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Services.Interfaces; | ||
11 | using OpenSim.Services.Connectors.Simulation; | ||
12 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
13 | |||
14 | using OpenMetaverse; | ||
15 | using OpenMetaverse.StructuredData; | ||
16 | using log4net; | ||
17 | using Nwc.XmlRpc; | ||
18 | using Nini.Config; | ||
19 | |||
20 | namespace OpenSim.Services.Connectors.Hypergrid | ||
21 | { | ||
22 | public class UserAgentServiceConnector : IUserAgentService | ||
23 | { | ||
24 | private static readonly ILog m_log = | ||
25 | LogManager.GetLogger( | ||
26 | MethodBase.GetCurrentMethod().DeclaringType); | ||
27 | |||
28 | string m_ServerURL; | ||
29 | public UserAgentServiceConnector(string url) | ||
30 | { | ||
31 | m_ServerURL = url; | ||
32 | } | ||
33 | |||
34 | public UserAgentServiceConnector(IConfigSource config) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) | ||
39 | { | ||
40 | reason = String.Empty; | ||
41 | |||
42 | if (destination == null) | ||
43 | { | ||
44 | reason = "Destination is null"; | ||
45 | m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null"); | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | string uri = m_ServerURL + "/homeagent/" + aCircuit.AgentID + "/"; | ||
50 | |||
51 | Console.WriteLine(" >>> LoginAgentToGrid <<< " + uri); | ||
52 | |||
53 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
54 | AgentCreateRequest.Method = "POST"; | ||
55 | AgentCreateRequest.ContentType = "application/json"; | ||
56 | AgentCreateRequest.Timeout = 10000; | ||
57 | //AgentCreateRequest.KeepAlive = false; | ||
58 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
59 | |||
60 | // Fill it in | ||
61 | OSDMap args = PackCreateAgentArguments(aCircuit, gatekeeper, destination); | ||
62 | |||
63 | string strBuffer = ""; | ||
64 | byte[] buffer = new byte[1]; | ||
65 | try | ||
66 | { | ||
67 | strBuffer = OSDParser.SerializeJsonString(args); | ||
68 | Encoding str = Util.UTF8; | ||
69 | buffer = str.GetBytes(strBuffer); | ||
70 | |||
71 | } | ||
72 | catch (Exception e) | ||
73 | { | ||
74 | m_log.WarnFormat("[USER AGENT CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
75 | // ignore. buffer will be empty, caller should check. | ||
76 | } | ||
77 | |||
78 | Stream os = null; | ||
79 | try | ||
80 | { // send the Post | ||
81 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
82 | os = AgentCreateRequest.GetRequestStream(); | ||
83 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
84 | m_log.InfoFormat("[USER AGENT CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
85 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
86 | } | ||
87 | //catch (WebException ex) | ||
88 | catch | ||
89 | { | ||
90 | //m_log.InfoFormat("[USER AGENT CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
91 | reason = "cannot contact remote region"; | ||
92 | return false; | ||
93 | } | ||
94 | finally | ||
95 | { | ||
96 | if (os != null) | ||
97 | os.Close(); | ||
98 | } | ||
99 | |||
100 | // Let's wait for the response | ||
101 | //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
102 | |||
103 | WebResponse webResponse = null; | ||
104 | StreamReader sr = null; | ||
105 | try | ||
106 | { | ||
107 | webResponse = AgentCreateRequest.GetResponse(); | ||
108 | if (webResponse == null) | ||
109 | { | ||
110 | m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
111 | } | ||
112 | else | ||
113 | { | ||
114 | |||
115 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
116 | string response = sr.ReadToEnd().Trim(); | ||
117 | m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
118 | |||
119 | if (!String.IsNullOrEmpty(response)) | ||
120 | { | ||
121 | try | ||
122 | { | ||
123 | // we assume we got an OSDMap back | ||
124 | OSDMap r = Util.GetOSDMap(response); | ||
125 | bool success = r["success"].AsBoolean(); | ||
126 | reason = r["reason"].AsString(); | ||
127 | return success; | ||
128 | } | ||
129 | catch (NullReferenceException e) | ||
130 | { | ||
131 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
132 | |||
133 | // check for old style response | ||
134 | if (response.ToLower().StartsWith("true")) | ||
135 | return true; | ||
136 | |||
137 | return false; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | catch (WebException ex) | ||
143 | { | ||
144 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
145 | reason = "Destination did not reply"; | ||
146 | return false; | ||
147 | } | ||
148 | finally | ||
149 | { | ||
150 | if (sr != null) | ||
151 | sr.Close(); | ||
152 | } | ||
153 | |||
154 | return true; | ||
155 | |||
156 | } | ||
157 | |||
158 | protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination) | ||
159 | { | ||
160 | OSDMap args = null; | ||
161 | try | ||
162 | { | ||
163 | args = aCircuit.PackAgentCircuitData(); | ||
164 | } | ||
165 | catch (Exception e) | ||
166 | { | ||
167 | m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
168 | } | ||
169 | // Add the input arguments | ||
170 | args["gatekeeper_host"] = OSD.FromString(gatekeeper.ExternalHostName); | ||
171 | args["gatekeeper_port"] = OSD.FromString(gatekeeper.HttpPort.ToString()); | ||
172 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
173 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
174 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
175 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
176 | |||
177 | return args; | ||
178 | } | ||
179 | |||
180 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) | ||
181 | { | ||
182 | position = Vector3.UnitY; lookAt = Vector3.UnitY; | ||
183 | |||
184 | Hashtable hash = new Hashtable(); | ||
185 | hash["userID"] = userID.ToString(); | ||
186 | |||
187 | IList paramList = new ArrayList(); | ||
188 | paramList.Add(hash); | ||
189 | |||
190 | XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList); | ||
191 | XmlRpcResponse response = null; | ||
192 | try | ||
193 | { | ||
194 | response = request.Send(m_ServerURL, 10000); | ||
195 | } | ||
196 | catch (Exception e) | ||
197 | { | ||
198 | return null; | ||
199 | } | ||
200 | |||
201 | if (response.IsFault) | ||
202 | { | ||
203 | return null; | ||
204 | } | ||
205 | |||
206 | hash = (Hashtable)response.Value; | ||
207 | //foreach (Object o in hash) | ||
208 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
209 | try | ||
210 | { | ||
211 | bool success = false; | ||
212 | Boolean.TryParse((string)hash["result"], out success); | ||
213 | if (success) | ||
214 | { | ||
215 | GridRegion region = new GridRegion(); | ||
216 | |||
217 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
218 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
219 | int n = 0; | ||
220 | if (hash["x"] != null) | ||
221 | { | ||
222 | Int32.TryParse((string)hash["x"], out n); | ||
223 | region.RegionLocX = n; | ||
224 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
225 | } | ||
226 | if (hash["y"] != null) | ||
227 | { | ||
228 | Int32.TryParse((string)hash["y"], out n); | ||
229 | region.RegionLocY = n; | ||
230 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
231 | } | ||
232 | if (hash["region_name"] != null) | ||
233 | { | ||
234 | region.RegionName = (string)hash["region_name"]; | ||
235 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
236 | } | ||
237 | if (hash["hostname"] != null) | ||
238 | region.ExternalHostName = (string)hash["hostname"]; | ||
239 | if (hash["http_port"] != null) | ||
240 | { | ||
241 | uint p = 0; | ||
242 | UInt32.TryParse((string)hash["http_port"], out p); | ||
243 | region.HttpPort = p; | ||
244 | } | ||
245 | if (hash["internal_port"] != null) | ||
246 | { | ||
247 | int p = 0; | ||
248 | Int32.TryParse((string)hash["internal_port"], out p); | ||
249 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
250 | } | ||
251 | if (hash["position"] != null) | ||
252 | Vector3.TryParse((string)hash["position"], out position); | ||
253 | if (hash["lookAt"] != null) | ||
254 | Vector3.TryParse((string)hash["lookAt"], out lookAt); | ||
255 | |||
256 | // Successful return | ||
257 | return region; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | return null; | ||
264 | } | ||
265 | |||
266 | return null; | ||
267 | |||
268 | } | ||
269 | |||
270 | public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName) | ||
271 | { | ||
272 | Hashtable hash = new Hashtable(); | ||
273 | hash["sessionID"] = sessionID.ToString(); | ||
274 | hash["externalName"] = thisGridExternalName; | ||
275 | |||
276 | IList paramList = new ArrayList(); | ||
277 | paramList.Add(hash); | ||
278 | |||
279 | XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList); | ||
280 | string reason = string.Empty; | ||
281 | return GetBoolResponse(request, out reason); | ||
282 | } | ||
283 | |||
284 | public bool VerifyAgent(UUID sessionID, string token) | ||
285 | { | ||
286 | Hashtable hash = new Hashtable(); | ||
287 | hash["sessionID"] = sessionID.ToString(); | ||
288 | hash["token"] = token; | ||
289 | |||
290 | IList paramList = new ArrayList(); | ||
291 | paramList.Add(hash); | ||
292 | |||
293 | XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList); | ||
294 | string reason = string.Empty; | ||
295 | return GetBoolResponse(request, out reason); | ||
296 | } | ||
297 | |||
298 | public bool VerifyClient(UUID sessionID, string token) | ||
299 | { | ||
300 | Hashtable hash = new Hashtable(); | ||
301 | hash["sessionID"] = sessionID.ToString(); | ||
302 | hash["token"] = token; | ||
303 | |||
304 | IList paramList = new ArrayList(); | ||
305 | paramList.Add(hash); | ||
306 | |||
307 | XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList); | ||
308 | string reason = string.Empty; | ||
309 | return GetBoolResponse(request, out reason); | ||
310 | } | ||
311 | |||
312 | public void LogoutAgent(UUID userID, UUID sessionID) | ||
313 | { | ||
314 | Hashtable hash = new Hashtable(); | ||
315 | hash["sessionID"] = sessionID.ToString(); | ||
316 | hash["userID"] = userID.ToString(); | ||
317 | |||
318 | IList paramList = new ArrayList(); | ||
319 | paramList.Add(hash); | ||
320 | |||
321 | XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList); | ||
322 | string reason = string.Empty; | ||
323 | GetBoolResponse(request, out reason); | ||
324 | } | ||
325 | |||
326 | |||
327 | private bool GetBoolResponse(XmlRpcRequest request, out string reason) | ||
328 | { | ||
329 | //m_log.Debug("[HGrid]: Linking to " + uri); | ||
330 | XmlRpcResponse response = null; | ||
331 | try | ||
332 | { | ||
333 | response = request.Send(m_ServerURL, 10000); | ||
334 | } | ||
335 | catch (Exception e) | ||
336 | { | ||
337 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
338 | reason = "Exception: " + e.Message; | ||
339 | return false; | ||
340 | } | ||
341 | |||
342 | if (response.IsFault) | ||
343 | { | ||
344 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
345 | reason = "XMLRPC Fault"; | ||
346 | return false; | ||
347 | } | ||
348 | |||
349 | Hashtable hash = (Hashtable)response.Value; | ||
350 | //foreach (Object o in hash) | ||
351 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
352 | try | ||
353 | { | ||
354 | bool success = false; | ||
355 | reason = string.Empty; | ||
356 | Boolean.TryParse((string)hash["result"], out success); | ||
357 | |||
358 | return success; | ||
359 | } | ||
360 | catch (Exception e) | ||
361 | { | ||
362 | m_log.Error("[HGrid]: Got exception while parsing GetEndPoint response " + e.StackTrace); | ||
363 | reason = "Exception: " + e.Message; | ||
364 | return false; | ||
365 | } | ||
366 | |||
367 | } | ||
368 | |||
369 | } | ||
370 | } | ||
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs index b9ccd7e..3309d16 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs | |||
@@ -92,6 +92,8 @@ namespace OpenSim.Services.Connectors | |||
92 | 92 | ||
93 | if (ret == null) | 93 | if (ret == null) |
94 | return false; | 94 | return false; |
95 | if (ret.Count == 0) | ||
96 | return false; | ||
95 | 97 | ||
96 | return bool.Parse(ret["RESULT"].ToString()); | 98 | return bool.Parse(ret["RESULT"].ToString()); |
97 | } | 99 | } |
@@ -105,6 +107,8 @@ namespace OpenSim.Services.Connectors | |||
105 | 107 | ||
106 | if (ret == null) | 108 | if (ret == null) |
107 | return null; | 109 | return null; |
110 | if (ret.Count == 0) | ||
111 | return null; | ||
108 | 112 | ||
109 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | 113 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); |
110 | 114 | ||
@@ -122,8 +126,7 @@ namespace OpenSim.Services.Connectors | |||
122 | }); | 126 | }); |
123 | 127 | ||
124 | if (ret == null) | 128 | if (ret == null) |
125 | return null; | 129 | return null; |
126 | |||
127 | if (ret.Count == 0) | 130 | if (ret.Count == 0) |
128 | return null; | 131 | return null; |
129 | 132 | ||
@@ -140,7 +143,6 @@ namespace OpenSim.Services.Connectors | |||
140 | 143 | ||
141 | if (ret == null) | 144 | if (ret == null) |
142 | return null; | 145 | return null; |
143 | |||
144 | if (ret.Count == 0) | 146 | if (ret.Count == 0) |
145 | return null; | 147 | return null; |
146 | 148 | ||
@@ -157,7 +159,6 @@ namespace OpenSim.Services.Connectors | |||
157 | 159 | ||
158 | if (ret == null) | 160 | if (ret == null) |
159 | return null; | 161 | return null; |
160 | |||
161 | if (ret.Count == 0) | 162 | if (ret.Count == 0) |
162 | return null; | 163 | return null; |
163 | 164 | ||
@@ -182,7 +183,7 @@ namespace OpenSim.Services.Connectors | |||
182 | 183 | ||
183 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | 184 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) |
184 | { | 185 | { |
185 | Dictionary<string,object> ret = MakeRequest("GETFOLDERCONTENT", | 186 | Dictionary<string,object> ret = MakeRequest("GETFOLDERITEMS", |
186 | new Dictionary<string,object> { | 187 | new Dictionary<string,object> { |
187 | { "PRINCIPAL", principalID.ToString() }, | 188 | { "PRINCIPAL", principalID.ToString() }, |
188 | { "FOLDER", folderID.ToString() } | 189 | { "FOLDER", folderID.ToString() } |
@@ -190,7 +191,6 @@ namespace OpenSim.Services.Connectors | |||
190 | 191 | ||
191 | if (ret == null) | 192 | if (ret == null) |
192 | return null; | 193 | return null; |
193 | |||
194 | if (ret.Count == 0) | 194 | if (ret.Count == 0) |
195 | return null; | 195 | return null; |
196 | 196 | ||
@@ -244,7 +244,8 @@ namespace OpenSim.Services.Connectors | |||
244 | Dictionary<string,object> ret = MakeRequest("MOVEFOLDER", | 244 | Dictionary<string,object> ret = MakeRequest("MOVEFOLDER", |
245 | new Dictionary<string,object> { | 245 | new Dictionary<string,object> { |
246 | { "ParentID", folder.ParentID.ToString() }, | 246 | { "ParentID", folder.ParentID.ToString() }, |
247 | { "ID", folder.ID.ToString() } | 247 | { "ID", folder.ID.ToString() }, |
248 | { "PRINCIPAL", folder.Owner.ToString() } | ||
248 | }); | 249 | }); |
249 | 250 | ||
250 | if (ret == null) | 251 | if (ret == null) |
@@ -362,7 +363,7 @@ namespace OpenSim.Services.Connectors | |||
362 | 363 | ||
363 | Dictionary<string,object> ret = MakeRequest("MOVEITEMS", | 364 | Dictionary<string,object> ret = MakeRequest("MOVEITEMS", |
364 | new Dictionary<string,object> { | 365 | new Dictionary<string,object> { |
365 | { "PrincipalID", principalID.ToString() }, | 366 | { "PRINCIPAL", principalID.ToString() }, |
366 | { "IDLIST", idlist }, | 367 | { "IDLIST", idlist }, |
367 | { "DESTLIST", destlist } | 368 | { "DESTLIST", destlist } |
368 | }); | 369 | }); |
@@ -401,7 +402,6 @@ namespace OpenSim.Services.Connectors | |||
401 | 402 | ||
402 | if (ret == null) | 403 | if (ret == null) |
403 | return null; | 404 | return null; |
404 | |||
405 | if (ret.Count == 0) | 405 | if (ret.Count == 0) |
406 | return null; | 406 | return null; |
407 | 407 | ||
@@ -417,7 +417,6 @@ namespace OpenSim.Services.Connectors | |||
417 | 417 | ||
418 | if (ret == null) | 418 | if (ret == null) |
419 | return null; | 419 | return null; |
420 | |||
421 | if (ret.Count == 0) | 420 | if (ret.Count == 0) |
422 | return null; | 421 | return null; |
423 | 422 | ||
@@ -531,5 +530,6 @@ namespace OpenSim.Services.Connectors | |||
531 | 530 | ||
532 | return item; | 531 | return item; |
533 | } | 532 | } |
533 | |||
534 | } | 534 | } |
535 | } | 535 | } |
diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs new file mode 100644 index 0000000..4dadd9e --- /dev/null +++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs | |||
@@ -0,0 +1,423 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class PresenceServicesConnector : IPresenceService | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger( | ||
48 | MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private string m_ServerURI = String.Empty; | ||
51 | |||
52 | public PresenceServicesConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public PresenceServicesConnector(string serverURI) | ||
57 | { | ||
58 | m_ServerURI = serverURI.TrimEnd('/'); | ||
59 | } | ||
60 | |||
61 | public PresenceServicesConnector(IConfigSource source) | ||
62 | { | ||
63 | Initialise(source); | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource source) | ||
67 | { | ||
68 | IConfig gridConfig = source.Configs["PresenceService"]; | ||
69 | if (gridConfig == null) | ||
70 | { | ||
71 | m_log.Error("[PRESENCE CONNECTOR]: PresenceService missing from OpenSim.ini"); | ||
72 | throw new Exception("Presence connector init error"); | ||
73 | } | ||
74 | |||
75 | string serviceURI = gridConfig.GetString("PresenceServerURI", | ||
76 | String.Empty); | ||
77 | |||
78 | if (serviceURI == String.Empty) | ||
79 | { | ||
80 | m_log.Error("[PRESENCE CONNECTOR]: No Server URI named in section PresenceService"); | ||
81 | throw new Exception("Presence connector init error"); | ||
82 | } | ||
83 | m_ServerURI = serviceURI; | ||
84 | } | ||
85 | |||
86 | |||
87 | #region IPresenceService | ||
88 | |||
89 | public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) | ||
90 | { | ||
91 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
92 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
93 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
94 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
95 | sendData["METHOD"] = "login"; | ||
96 | |||
97 | sendData["UserID"] = userID; | ||
98 | sendData["SessionID"] = sessionID.ToString(); | ||
99 | sendData["SecureSessionID"] = secureSessionID.ToString(); | ||
100 | |||
101 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
102 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
103 | try | ||
104 | { | ||
105 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
106 | m_ServerURI + "/presence", | ||
107 | reqString); | ||
108 | if (reply != string.Empty) | ||
109 | { | ||
110 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
111 | |||
112 | if (replyData.ContainsKey("result")) | ||
113 | { | ||
114 | if (replyData["result"].ToString().ToLower() == "success") | ||
115 | return true; | ||
116 | else | ||
117 | return false; | ||
118 | } | ||
119 | else | ||
120 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent reply data does not contain result field"); | ||
121 | |||
122 | } | ||
123 | else | ||
124 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LoginAgent received empty reply"); | ||
125 | } | ||
126 | catch (Exception e) | ||
127 | { | ||
128 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
129 | } | ||
130 | |||
131 | return false; | ||
132 | |||
133 | } | ||
134 | |||
135 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
136 | { | ||
137 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
138 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
139 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
140 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
141 | sendData["METHOD"] = "logout"; | ||
142 | |||
143 | sendData["SessionID"] = sessionID.ToString(); | ||
144 | sendData["Position"] = position.ToString(); | ||
145 | sendData["LookAt"] = lookat.ToString(); | ||
146 | |||
147 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
148 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
149 | try | ||
150 | { | ||
151 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
152 | m_ServerURI + "/presence", | ||
153 | reqString); | ||
154 | if (reply != string.Empty) | ||
155 | { | ||
156 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
157 | |||
158 | if (replyData.ContainsKey("result")) | ||
159 | { | ||
160 | if (replyData["result"].ToString().ToLower() == "success") | ||
161 | return true; | ||
162 | else | ||
163 | return false; | ||
164 | } | ||
165 | else | ||
166 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent reply data does not contain result field"); | ||
167 | |||
168 | } | ||
169 | else | ||
170 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutAgent received empty reply"); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
175 | } | ||
176 | |||
177 | return false; | ||
178 | } | ||
179 | |||
180 | public bool LogoutRegionAgents(UUID regionID) | ||
181 | { | ||
182 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
183 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
184 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
185 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
186 | sendData["METHOD"] = "logoutregion"; | ||
187 | |||
188 | sendData["RegionID"] = regionID.ToString(); | ||
189 | |||
190 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
191 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
192 | try | ||
193 | { | ||
194 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
195 | m_ServerURI + "/presence", | ||
196 | reqString); | ||
197 | if (reply != string.Empty) | ||
198 | { | ||
199 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
200 | |||
201 | if (replyData.ContainsKey("result")) | ||
202 | { | ||
203 | if (replyData["result"].ToString().ToLower() == "success") | ||
204 | return true; | ||
205 | else | ||
206 | return false; | ||
207 | } | ||
208 | else | ||
209 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents reply data does not contain result field"); | ||
210 | |||
211 | } | ||
212 | else | ||
213 | m_log.DebugFormat("[PRESENCE CONNECTOR]: LogoutRegionAgents received empty reply"); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
218 | } | ||
219 | |||
220 | return false; | ||
221 | } | ||
222 | |||
223 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
224 | { | ||
225 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
226 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
227 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
228 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
229 | sendData["METHOD"] = "report"; | ||
230 | |||
231 | sendData["SessionID"] = sessionID.ToString(); | ||
232 | sendData["RegionID"] = regionID.ToString(); | ||
233 | sendData["position"] = position.ToString(); | ||
234 | sendData["lookAt"] = lookAt.ToString(); | ||
235 | |||
236 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
237 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
238 | try | ||
239 | { | ||
240 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
241 | m_ServerURI + "/presence", | ||
242 | reqString); | ||
243 | if (reply != string.Empty) | ||
244 | { | ||
245 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
246 | |||
247 | if (replyData.ContainsKey("result")) | ||
248 | { | ||
249 | if (replyData["result"].ToString().ToLower() == "success") | ||
250 | return true; | ||
251 | else | ||
252 | return false; | ||
253 | } | ||
254 | else | ||
255 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent reply data does not contain result field"); | ||
256 | |||
257 | } | ||
258 | else | ||
259 | m_log.DebugFormat("[PRESENCE CONNECTOR]: ReportAgent received empty reply"); | ||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
264 | } | ||
265 | |||
266 | return false; | ||
267 | } | ||
268 | |||
269 | public PresenceInfo GetAgent(UUID sessionID) | ||
270 | { | ||
271 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
272 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
273 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
274 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
275 | sendData["METHOD"] = "getagent"; | ||
276 | |||
277 | sendData["SessionID"] = sessionID.ToString(); | ||
278 | |||
279 | string reply = string.Empty; | ||
280 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
281 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
282 | try | ||
283 | { | ||
284 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
285 | m_ServerURI + "/presence", | ||
286 | reqString); | ||
287 | if (reply == null || (reply != null && reply == string.Empty)) | ||
288 | { | ||
289 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
290 | return null; | ||
291 | } | ||
292 | } | ||
293 | catch (Exception e) | ||
294 | { | ||
295 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
296 | } | ||
297 | |||
298 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
299 | PresenceInfo pinfo = null; | ||
300 | |||
301 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
302 | { | ||
303 | if (replyData["result"] is Dictionary<string, object>) | ||
304 | { | ||
305 | pinfo = new PresenceInfo((Dictionary<string, object>)replyData["result"]); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | return pinfo; | ||
310 | } | ||
311 | |||
312 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
313 | { | ||
314 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
315 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
316 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
317 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
318 | sendData["METHOD"] = "getagents"; | ||
319 | |||
320 | sendData["uuids"] = new List<string>(userIDs); | ||
321 | |||
322 | string reply = string.Empty; | ||
323 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
324 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
325 | try | ||
326 | { | ||
327 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
328 | m_ServerURI + "/presence", | ||
329 | reqString); | ||
330 | if (reply == null || (reply != null && reply == string.Empty)) | ||
331 | { | ||
332 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgent received null or empty reply"); | ||
333 | return null; | ||
334 | } | ||
335 | } | ||
336 | catch (Exception e) | ||
337 | { | ||
338 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
339 | } | ||
340 | |||
341 | List<PresenceInfo> rinfos = new List<PresenceInfo>(); | ||
342 | |||
343 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
344 | |||
345 | if (replyData != null) | ||
346 | { | ||
347 | if (replyData.ContainsKey("result") && | ||
348 | (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) | ||
349 | { | ||
350 | return new PresenceInfo[0]; | ||
351 | } | ||
352 | |||
353 | Dictionary<string, object>.ValueCollection pinfosList = replyData.Values; | ||
354 | //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
355 | foreach (object presence in pinfosList) | ||
356 | { | ||
357 | if (presence is Dictionary<string, object>) | ||
358 | { | ||
359 | PresenceInfo pinfo = new PresenceInfo((Dictionary<string, object>)presence); | ||
360 | rinfos.Add(pinfo); | ||
361 | } | ||
362 | else | ||
363 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received invalid response type {0}", | ||
364 | presence.GetType()); | ||
365 | } | ||
366 | } | ||
367 | else | ||
368 | m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents received null response"); | ||
369 | |||
370 | return rinfos.ToArray(); | ||
371 | } | ||
372 | |||
373 | |||
374 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
375 | { | ||
376 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
377 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
378 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
379 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
380 | sendData["METHOD"] = "sethome"; | ||
381 | |||
382 | sendData["UserID"] = userID; | ||
383 | sendData["RegionID"] = regionID.ToString(); | ||
384 | sendData["position"] = position.ToString(); | ||
385 | sendData["lookAt"] = lookAt.ToString(); | ||
386 | |||
387 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
388 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
389 | try | ||
390 | { | ||
391 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
392 | m_ServerURI + "/presence", | ||
393 | reqString); | ||
394 | if (reply != string.Empty) | ||
395 | { | ||
396 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
397 | |||
398 | if (replyData.ContainsKey("result")) | ||
399 | { | ||
400 | if (replyData["result"].ToString().ToLower() == "success") | ||
401 | return true; | ||
402 | else | ||
403 | return false; | ||
404 | } | ||
405 | else | ||
406 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); | ||
407 | |||
408 | } | ||
409 | else | ||
410 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); | ||
411 | } | ||
412 | catch (Exception e) | ||
413 | { | ||
414 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
415 | } | ||
416 | |||
417 | return false; | ||
418 | } | ||
419 | |||
420 | #endregion | ||
421 | |||
422 | } | ||
423 | } | ||
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs new file mode 100644 index 0000000..d3be1a8 --- /dev/null +++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs | |||
@@ -0,0 +1,596 @@ | |||
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.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | using Nini.Config; | ||
43 | |||
44 | namespace OpenSim.Services.Connectors.Simulation | ||
45 | { | ||
46 | public class SimulationServiceConnector : ISimulationService | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | //private GridRegion m_Region; | ||
51 | |||
52 | public SimulationServiceConnector() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public SimulationServiceConnector(IConfigSource config) | ||
57 | { | ||
58 | //m_Region = region; | ||
59 | } | ||
60 | |||
61 | public IScene GetScene(ulong regionHandle) | ||
62 | { | ||
63 | return null; | ||
64 | } | ||
65 | |||
66 | #region Agents | ||
67 | |||
68 | protected virtual string AgentPath() | ||
69 | { | ||
70 | return "/agent/"; | ||
71 | } | ||
72 | |||
73 | public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) | ||
74 | { | ||
75 | reason = String.Empty; | ||
76 | |||
77 | if (destination == null) | ||
78 | { | ||
79 | reason = "Destination is null"; | ||
80 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | // Eventually, we want to use a caps url instead of the agentID | ||
85 | string uri = string.Empty; | ||
86 | try | ||
87 | { | ||
88 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + aCircuit.AgentID + "/"; | ||
89 | } | ||
90 | catch (Exception e) | ||
91 | { | ||
92 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent create. Reason: " + e.Message); | ||
93 | reason = e.Message; | ||
94 | return false; | ||
95 | } | ||
96 | |||
97 | //Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri); | ||
98 | |||
99 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
100 | AgentCreateRequest.Method = "POST"; | ||
101 | AgentCreateRequest.ContentType = "application/json"; | ||
102 | AgentCreateRequest.Timeout = 10000; | ||
103 | //AgentCreateRequest.KeepAlive = false; | ||
104 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
105 | |||
106 | // Fill it in | ||
107 | OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags); | ||
108 | if (args == null) | ||
109 | return false; | ||
110 | |||
111 | string strBuffer = ""; | ||
112 | byte[] buffer = new byte[1]; | ||
113 | try | ||
114 | { | ||
115 | strBuffer = OSDParser.SerializeJsonString(args); | ||
116 | Encoding str = Util.UTF8; | ||
117 | buffer = str.GetBytes(strBuffer); | ||
118 | |||
119 | } | ||
120 | catch (Exception e) | ||
121 | { | ||
122 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
123 | // ignore. buffer will be empty, caller should check. | ||
124 | } | ||
125 | |||
126 | Stream os = null; | ||
127 | try | ||
128 | { // send the Post | ||
129 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
130 | os = AgentCreateRequest.GetRequestStream(); | ||
131 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
132 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
133 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
134 | } | ||
135 | //catch (WebException ex) | ||
136 | catch | ||
137 | { | ||
138 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
139 | reason = "cannot contact remote region"; | ||
140 | return false; | ||
141 | } | ||
142 | finally | ||
143 | { | ||
144 | if (os != null) | ||
145 | os.Close(); | ||
146 | } | ||
147 | |||
148 | // Let's wait for the response | ||
149 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
150 | |||
151 | WebResponse webResponse = null; | ||
152 | StreamReader sr = null; | ||
153 | try | ||
154 | { | ||
155 | webResponse = AgentCreateRequest.GetResponse(); | ||
156 | if (webResponse == null) | ||
157 | { | ||
158 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | |||
163 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
164 | string response = sr.ReadToEnd().Trim(); | ||
165 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
166 | |||
167 | if (!String.IsNullOrEmpty(response)) | ||
168 | { | ||
169 | try | ||
170 | { | ||
171 | // we assume we got an OSDMap back | ||
172 | OSDMap r = Util.GetOSDMap(response); | ||
173 | bool success = r["success"].AsBoolean(); | ||
174 | reason = r["reason"].AsString(); | ||
175 | return success; | ||
176 | } | ||
177 | catch (NullReferenceException e) | ||
178 | { | ||
179 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
180 | |||
181 | // check for old style response | ||
182 | if (response.ToLower().StartsWith("true")) | ||
183 | return true; | ||
184 | |||
185 | return false; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | catch (WebException ex) | ||
191 | { | ||
192 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
193 | reason = "Destination did not reply"; | ||
194 | return false; | ||
195 | } | ||
196 | finally | ||
197 | { | ||
198 | if (sr != null) | ||
199 | sr.Close(); | ||
200 | } | ||
201 | |||
202 | return true; | ||
203 | } | ||
204 | |||
205 | protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags) | ||
206 | { | ||
207 | OSDMap args = null; | ||
208 | try | ||
209 | { | ||
210 | args = aCircuit.PackAgentCircuitData(); | ||
211 | } | ||
212 | catch (Exception e) | ||
213 | { | ||
214 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
215 | return null; | ||
216 | } | ||
217 | // Add the input arguments | ||
218 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
219 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
220 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
221 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
222 | args["teleport_flags"] = OSD.FromString(flags.ToString()); | ||
223 | |||
224 | return args; | ||
225 | } | ||
226 | |||
227 | public bool UpdateAgent(GridRegion destination, AgentData data) | ||
228 | { | ||
229 | return UpdateAgent(destination, (IAgentData)data); | ||
230 | } | ||
231 | |||
232 | public bool UpdateAgent(GridRegion destination, AgentPosition data) | ||
233 | { | ||
234 | return UpdateAgent(destination, (IAgentData)data); | ||
235 | } | ||
236 | |||
237 | private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) | ||
238 | { | ||
239 | // Eventually, we want to use a caps url instead of the agentID | ||
240 | string uri = string.Empty; | ||
241 | try | ||
242 | { | ||
243 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + cAgentData.AgentID + "/"; | ||
244 | } | ||
245 | catch (Exception e) | ||
246 | { | ||
247 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent update. Reason: " + e.Message); | ||
248 | return false; | ||
249 | } | ||
250 | //Console.WriteLine(" >>> DoAgentUpdateCall <<< " + uri); | ||
251 | |||
252 | HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
253 | ChildUpdateRequest.Method = "PUT"; | ||
254 | ChildUpdateRequest.ContentType = "application/json"; | ||
255 | ChildUpdateRequest.Timeout = 10000; | ||
256 | //ChildUpdateRequest.KeepAlive = false; | ||
257 | |||
258 | // Fill it in | ||
259 | OSDMap args = null; | ||
260 | try | ||
261 | { | ||
262 | args = cAgentData.Pack(); | ||
263 | } | ||
264 | catch (Exception e) | ||
265 | { | ||
266 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message); | ||
267 | } | ||
268 | // Add the input arguments | ||
269 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
270 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
271 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
272 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
273 | |||
274 | string strBuffer = ""; | ||
275 | byte[] buffer = new byte[1]; | ||
276 | try | ||
277 | { | ||
278 | strBuffer = OSDParser.SerializeJsonString(args); | ||
279 | Encoding str = Util.UTF8; | ||
280 | buffer = str.GetBytes(strBuffer); | ||
281 | |||
282 | } | ||
283 | catch (Exception e) | ||
284 | { | ||
285 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message); | ||
286 | // ignore. buffer will be empty, caller should check. | ||
287 | } | ||
288 | |||
289 | Stream os = null; | ||
290 | try | ||
291 | { // send the Post | ||
292 | ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
293 | os = ChildUpdateRequest.GetRequestStream(); | ||
294 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
295 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri); | ||
296 | } | ||
297 | catch (WebException ex) | ||
298 | //catch | ||
299 | { | ||
300 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message); | ||
301 | |||
302 | return false; | ||
303 | } | ||
304 | finally | ||
305 | { | ||
306 | if (os != null) | ||
307 | os.Close(); | ||
308 | } | ||
309 | |||
310 | // Let's wait for the response | ||
311 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate"); | ||
312 | |||
313 | WebResponse webResponse = null; | ||
314 | StreamReader sr = null; | ||
315 | try | ||
316 | { | ||
317 | webResponse = ChildUpdateRequest.GetResponse(); | ||
318 | if (webResponse == null) | ||
319 | { | ||
320 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post"); | ||
321 | } | ||
322 | |||
323 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
324 | //reply = sr.ReadToEnd().Trim(); | ||
325 | sr.ReadToEnd().Trim(); | ||
326 | sr.Close(); | ||
327 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
328 | |||
329 | } | ||
330 | catch (WebException ex) | ||
331 | { | ||
332 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate {0}", ex.Message); | ||
333 | // ignore, really | ||
334 | } | ||
335 | finally | ||
336 | { | ||
337 | if (sr != null) | ||
338 | sr.Close(); | ||
339 | } | ||
340 | |||
341 | return true; | ||
342 | } | ||
343 | |||
344 | public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) | ||
345 | { | ||
346 | agent = null; | ||
347 | // Eventually, we want to use a caps url instead of the agentID | ||
348 | string uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; | ||
349 | //Console.WriteLine(" >>> DoRetrieveRootAgentCall <<< " + uri); | ||
350 | |||
351 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
352 | request.Method = "GET"; | ||
353 | request.Timeout = 10000; | ||
354 | //request.Headers.Add("authorization", ""); // coming soon | ||
355 | |||
356 | HttpWebResponse webResponse = null; | ||
357 | string reply = string.Empty; | ||
358 | StreamReader sr = null; | ||
359 | try | ||
360 | { | ||
361 | webResponse = (HttpWebResponse)request.GetResponse(); | ||
362 | if (webResponse == null) | ||
363 | { | ||
364 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); | ||
365 | } | ||
366 | |||
367 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
368 | reply = sr.ReadToEnd().Trim(); | ||
369 | |||
370 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was " + reply); | ||
371 | |||
372 | } | ||
373 | catch (WebException ex) | ||
374 | { | ||
375 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message); | ||
376 | // ignore, really | ||
377 | return false; | ||
378 | } | ||
379 | finally | ||
380 | { | ||
381 | if (sr != null) | ||
382 | sr.Close(); | ||
383 | } | ||
384 | |||
385 | if (webResponse.StatusCode == HttpStatusCode.OK) | ||
386 | { | ||
387 | // we know it's jason | ||
388 | OSDMap args = Util.GetOSDMap(reply); | ||
389 | if (args == null) | ||
390 | { | ||
391 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: Error getting OSDMap from reply"); | ||
392 | return false; | ||
393 | } | ||
394 | |||
395 | agent = new CompleteAgentData(); | ||
396 | agent.Unpack(args); | ||
397 | return true; | ||
398 | } | ||
399 | |||
400 | //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode); | ||
401 | return false; | ||
402 | } | ||
403 | |||
404 | public bool ReleaseAgent(UUID origin, UUID id, string uri) | ||
405 | { | ||
406 | WebRequest request = WebRequest.Create(uri); | ||
407 | request.Method = "DELETE"; | ||
408 | request.Timeout = 10000; | ||
409 | |||
410 | StreamReader sr = null; | ||
411 | try | ||
412 | { | ||
413 | WebResponse webResponse = request.GetResponse(); | ||
414 | if (webResponse == null) | ||
415 | { | ||
416 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent"); | ||
417 | } | ||
418 | |||
419 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
420 | //reply = sr.ReadToEnd().Trim(); | ||
421 | sr.ReadToEnd().Trim(); | ||
422 | sr.Close(); | ||
423 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
424 | |||
425 | } | ||
426 | catch (WebException ex) | ||
427 | { | ||
428 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message); | ||
429 | return false; | ||
430 | } | ||
431 | finally | ||
432 | { | ||
433 | if (sr != null) | ||
434 | sr.Close(); | ||
435 | } | ||
436 | |||
437 | return true; | ||
438 | } | ||
439 | |||
440 | public bool CloseAgent(GridRegion destination, UUID id) | ||
441 | { | ||
442 | string uri = string.Empty; | ||
443 | try | ||
444 | { | ||
445 | uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; | ||
446 | } | ||
447 | catch (Exception e) | ||
448 | { | ||
449 | m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent close. Reason: " + e.Message); | ||
450 | return false; | ||
451 | } | ||
452 | |||
453 | //Console.WriteLine(" >>> DoCloseAgentCall <<< " + uri); | ||
454 | |||
455 | WebRequest request = WebRequest.Create(uri); | ||
456 | request.Method = "DELETE"; | ||
457 | request.Timeout = 10000; | ||
458 | |||
459 | StreamReader sr = null; | ||
460 | try | ||
461 | { | ||
462 | WebResponse webResponse = request.GetResponse(); | ||
463 | if (webResponse == null) | ||
464 | { | ||
465 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete "); | ||
466 | } | ||
467 | |||
468 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
469 | //reply = sr.ReadToEnd().Trim(); | ||
470 | sr.ReadToEnd().Trim(); | ||
471 | sr.Close(); | ||
472 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply); | ||
473 | |||
474 | } | ||
475 | catch (WebException ex) | ||
476 | { | ||
477 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete {0}", ex.Message); | ||
478 | return false; | ||
479 | } | ||
480 | finally | ||
481 | { | ||
482 | if (sr != null) | ||
483 | sr.Close(); | ||
484 | } | ||
485 | |||
486 | return true; | ||
487 | } | ||
488 | |||
489 | #endregion Agents | ||
490 | |||
491 | #region Objects | ||
492 | |||
493 | protected virtual string ObjectPath() | ||
494 | { | ||
495 | return "/object/"; | ||
496 | } | ||
497 | |||
498 | public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) | ||
499 | { | ||
500 | string uri | ||
501 | = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + ObjectPath() + sog.UUID + "/"; | ||
502 | //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri); | ||
503 | |||
504 | WebRequest ObjectCreateRequest = WebRequest.Create(uri); | ||
505 | ObjectCreateRequest.Method = "POST"; | ||
506 | ObjectCreateRequest.ContentType = "application/json"; | ||
507 | ObjectCreateRequest.Timeout = 10000; | ||
508 | |||
509 | OSDMap args = new OSDMap(2); | ||
510 | args["sog"] = OSD.FromString(sog.ToXml2()); | ||
511 | args["extra"] = OSD.FromString(sog.ExtraToXmlString()); | ||
512 | string state = sog.GetStateSnapshot(); | ||
513 | if (state.Length > 0) | ||
514 | args["state"] = OSD.FromString(state); | ||
515 | // Add the input general arguments | ||
516 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
517 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
518 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
519 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
520 | |||
521 | string strBuffer = ""; | ||
522 | byte[] buffer = new byte[1]; | ||
523 | try | ||
524 | { | ||
525 | strBuffer = OSDParser.SerializeJsonString(args); | ||
526 | Encoding str = Util.UTF8; | ||
527 | buffer = str.GetBytes(strBuffer); | ||
528 | |||
529 | } | ||
530 | catch (Exception e) | ||
531 | { | ||
532 | m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message); | ||
533 | // ignore. buffer will be empty, caller should check. | ||
534 | } | ||
535 | |||
536 | Stream os = null; | ||
537 | try | ||
538 | { // send the Post | ||
539 | ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
540 | os = ObjectCreateRequest.GetRequestStream(); | ||
541 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
542 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri); | ||
543 | } | ||
544 | catch (WebException ex) | ||
545 | { | ||
546 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message); | ||
547 | return false; | ||
548 | } | ||
549 | finally | ||
550 | { | ||
551 | if (os != null) | ||
552 | os.Close(); | ||
553 | } | ||
554 | |||
555 | // Let's wait for the response | ||
556 | //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
557 | |||
558 | StreamReader sr = null; | ||
559 | try | ||
560 | { | ||
561 | WebResponse webResponse = ObjectCreateRequest.GetResponse(); | ||
562 | if (webResponse == null) | ||
563 | { | ||
564 | m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post"); | ||
565 | return false; | ||
566 | } | ||
567 | |||
568 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
569 | //reply = sr.ReadToEnd().Trim(); | ||
570 | sr.ReadToEnd().Trim(); | ||
571 | //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); | ||
572 | |||
573 | } | ||
574 | catch (WebException ex) | ||
575 | { | ||
576 | m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message); | ||
577 | return false; | ||
578 | } | ||
579 | finally | ||
580 | { | ||
581 | if (sr != null) | ||
582 | sr.Close(); | ||
583 | } | ||
584 | |||
585 | return true; | ||
586 | } | ||
587 | |||
588 | public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) | ||
589 | { | ||
590 | // TODO, not that urgent | ||
591 | return false; | ||
592 | } | ||
593 | |||
594 | #endregion Objects | ||
595 | } | ||
596 | } | ||
diff --git a/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs new file mode 100644 index 0000000..e1621b8 --- /dev/null +++ b/OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs | |||
@@ -0,0 +1,277 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors | ||
42 | { | ||
43 | public class UserAccountServicesConnector : IUserAccountService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | |||
51 | public UserAccountServicesConnector() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public UserAccountServicesConnector(string serverURI) | ||
56 | { | ||
57 | m_ServerURI = serverURI.TrimEnd('/'); | ||
58 | } | ||
59 | |||
60 | public UserAccountServicesConnector(IConfigSource source) | ||
61 | { | ||
62 | Initialise(source); | ||
63 | } | ||
64 | |||
65 | public virtual void Initialise(IConfigSource source) | ||
66 | { | ||
67 | IConfig assetConfig = source.Configs["UserAccountService"]; | ||
68 | if (assetConfig == null) | ||
69 | { | ||
70 | m_log.Error("[ACCOUNT CONNECTOR]: UserAccountService missing from OpenSim.ini"); | ||
71 | throw new Exception("User account connector init error"); | ||
72 | } | ||
73 | |||
74 | string serviceURI = assetConfig.GetString("UserAccountServerURI", | ||
75 | String.Empty); | ||
76 | |||
77 | if (serviceURI == String.Empty) | ||
78 | { | ||
79 | m_log.Error("[ACCOUNT CONNECTOR]: No Server URI named in section UserAccountService"); | ||
80 | throw new Exception("User account connector init error"); | ||
81 | } | ||
82 | m_ServerURI = serviceURI; | ||
83 | } | ||
84 | |||
85 | public virtual UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) | ||
86 | { | ||
87 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
88 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
89 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
90 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
91 | sendData["METHOD"] = "getaccount"; | ||
92 | |||
93 | sendData["ScopeID"] = scopeID; | ||
94 | sendData["FirstName"] = firstName.ToString(); | ||
95 | sendData["LastName"] = lastName.ToString(); | ||
96 | |||
97 | return SendAndGetReply(sendData); | ||
98 | } | ||
99 | |||
100 | public virtual UserAccount GetUserAccount(UUID scopeID, string email) | ||
101 | { | ||
102 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
103 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
104 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
105 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
106 | sendData["METHOD"] = "getaccount"; | ||
107 | |||
108 | sendData["ScopeID"] = scopeID; | ||
109 | sendData["Email"] = email; | ||
110 | |||
111 | return SendAndGetReply(sendData); | ||
112 | } | ||
113 | |||
114 | public virtual UserAccount GetUserAccount(UUID scopeID, UUID userID) | ||
115 | { | ||
116 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
117 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
118 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
119 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
120 | sendData["METHOD"] = "getaccount"; | ||
121 | |||
122 | sendData["ScopeID"] = scopeID; | ||
123 | sendData["UserID"] = userID.ToString(); | ||
124 | |||
125 | return SendAndGetReply(sendData); | ||
126 | } | ||
127 | |||
128 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
129 | { | ||
130 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
131 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
132 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
133 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
134 | sendData["METHOD"] = "getagents"; | ||
135 | |||
136 | sendData["ScopeID"] = scopeID.ToString(); | ||
137 | sendData["query"] = query; | ||
138 | |||
139 | string reply = string.Empty; | ||
140 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
141 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
142 | try | ||
143 | { | ||
144 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
145 | m_ServerURI + "/accounts", | ||
146 | reqString); | ||
147 | if (reply == null || (reply != null && reply == string.Empty)) | ||
148 | { | ||
149 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received null or empty reply"); | ||
150 | return null; | ||
151 | } | ||
152 | } | ||
153 | catch (Exception e) | ||
154 | { | ||
155 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting accounts server: {0}", e.Message); | ||
156 | } | ||
157 | |||
158 | List<UserAccount> accounts = new List<UserAccount>(); | ||
159 | |||
160 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
161 | |||
162 | if (replyData != null) | ||
163 | { | ||
164 | if (replyData.ContainsKey("result") && replyData.ContainsKey("result").ToString() == "null") | ||
165 | { | ||
166 | return accounts; | ||
167 | } | ||
168 | |||
169 | Dictionary<string, object>.ValueCollection accountList = replyData.Values; | ||
170 | //m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); | ||
171 | foreach (object acc in accountList) | ||
172 | { | ||
173 | if (acc is Dictionary<string, object>) | ||
174 | { | ||
175 | UserAccount pinfo = new UserAccount((Dictionary<string, object>)acc); | ||
176 | accounts.Add(pinfo); | ||
177 | } | ||
178 | else | ||
179 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccounts received invalid response type {0}", | ||
180 | acc.GetType()); | ||
181 | } | ||
182 | } | ||
183 | else | ||
184 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: GetUserAccounts received null response"); | ||
185 | |||
186 | return accounts; | ||
187 | } | ||
188 | |||
189 | public bool StoreUserAccount(UserAccount data) | ||
190 | { | ||
191 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
192 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
193 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
194 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
195 | sendData["METHOD"] = "setaccount"; | ||
196 | |||
197 | Dictionary<string, object> structData = data.ToKeyValuePairs(); | ||
198 | |||
199 | foreach (KeyValuePair<string,object> kvp in structData) | ||
200 | sendData[kvp.Key] = kvp.Value.ToString(); | ||
201 | |||
202 | return SendAndGetBoolReply(sendData); | ||
203 | } | ||
204 | |||
205 | private UserAccount SendAndGetReply(Dictionary<string, object> sendData) | ||
206 | { | ||
207 | string reply = string.Empty; | ||
208 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
209 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
210 | try | ||
211 | { | ||
212 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
213 | m_ServerURI + "/accounts", | ||
214 | reqString); | ||
215 | if (reply == null || (reply != null && reply == string.Empty)) | ||
216 | { | ||
217 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: GetUserAccount received null or empty reply"); | ||
218 | return null; | ||
219 | } | ||
220 | } | ||
221 | catch (Exception e) | ||
222 | { | ||
223 | m_log.DebugFormat("[ACCOUNT CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
224 | } | ||
225 | |||
226 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
227 | UserAccount account = null; | ||
228 | |||
229 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
230 | { | ||
231 | if (replyData["result"] is Dictionary<string, object>) | ||
232 | { | ||
233 | account = new UserAccount((Dictionary<string, object>)replyData["result"]); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | return account; | ||
238 | |||
239 | } | ||
240 | |||
241 | private bool SendAndGetBoolReply(Dictionary<string, object> sendData) | ||
242 | { | ||
243 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
244 | // m_log.DebugFormat("[ACCOUNTS CONNECTOR]: queryString = {0}", reqString); | ||
245 | try | ||
246 | { | ||
247 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
248 | m_ServerURI + "/accounts", | ||
249 | reqString); | ||
250 | if (reply != string.Empty) | ||
251 | { | ||
252 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
253 | |||
254 | if (replyData.ContainsKey("result")) | ||
255 | { | ||
256 | if (replyData["result"].ToString().ToLower() == "success") | ||
257 | return true; | ||
258 | else | ||
259 | return false; | ||
260 | } | ||
261 | else | ||
262 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount reply data does not contain result field"); | ||
263 | |||
264 | } | ||
265 | else | ||
266 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Set or Create UserAccount received empty reply"); | ||
267 | } | ||
268 | catch (Exception e) | ||
269 | { | ||
270 | m_log.DebugFormat("[ACCOUNTS CONNECTOR]: Exception when contacting user account server: {0}", e.Message); | ||
271 | } | ||
272 | |||
273 | return false; | ||
274 | } | ||
275 | |||
276 | } | ||
277 | } | ||
diff --git a/OpenSim/Services/Friends/FriendsService.cs b/OpenSim/Services/Friends/FriendsService.cs new file mode 100644 index 0000000..3c64ecc --- /dev/null +++ b/OpenSim/Services/Friends/FriendsService.cs | |||
@@ -0,0 +1,85 @@ | |||
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 OpenMetaverse; | ||
29 | using OpenSim.Framework; | ||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Data; | ||
34 | using Nini.Config; | ||
35 | using log4net; | ||
36 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
37 | |||
38 | namespace OpenSim.Services.Friends | ||
39 | { | ||
40 | public class FriendsService : FriendsServiceBase, IFriendsService | ||
41 | { | ||
42 | public FriendsService(IConfigSource config) : base(config) | ||
43 | { | ||
44 | } | ||
45 | |||
46 | public FriendInfo[] GetFriends(UUID PrincipalID) | ||
47 | { | ||
48 | FriendsData[] data = m_Database.GetFriends(PrincipalID); | ||
49 | |||
50 | List<FriendInfo> info = new List<FriendInfo>(); | ||
51 | |||
52 | foreach (FriendsData d in data) | ||
53 | { | ||
54 | FriendInfo i = new FriendInfo(); | ||
55 | |||
56 | i.PrincipalID = d.PrincipalID; | ||
57 | i.Friend = d.Friend; | ||
58 | i.MyFlags = Convert.ToInt32(d.Data["Flags"]); | ||
59 | i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]); | ||
60 | |||
61 | info.Add(i); | ||
62 | } | ||
63 | |||
64 | return info.ToArray(); | ||
65 | } | ||
66 | |||
67 | public bool StoreFriend(UUID PrincipalID, string Friend, int flags) | ||
68 | { | ||
69 | FriendsData d = new FriendsData(); | ||
70 | |||
71 | d.PrincipalID = PrincipalID; | ||
72 | d.Friend = Friend; | ||
73 | d.Data = new Dictionary<string, string>(); | ||
74 | d.Data["Flags"] = flags.ToString(); | ||
75 | |||
76 | return m_Database.Store(d); | ||
77 | } | ||
78 | |||
79 | public bool Delete(UUID PrincipalID, string Friend) | ||
80 | { | ||
81 | return m_Database.Delete(PrincipalID, Friend); | ||
82 | } | ||
83 | |||
84 | } | ||
85 | } | ||
diff --git a/OpenSim/Services/Friends/FriendsServiceBase.cs b/OpenSim/Services/Friends/FriendsServiceBase.cs new file mode 100644 index 0000000..9858972 --- /dev/null +++ b/OpenSim/Services/Friends/FriendsServiceBase.cs | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | using Nini.Config; | ||
36 | using log4net; | ||
37 | |||
38 | namespace OpenSim.Services.Friends | ||
39 | { | ||
40 | public class FriendsServiceBase : ServiceBase | ||
41 | { | ||
42 | protected IFriendsData m_Database = null; | ||
43 | |||
44 | public FriendsServiceBase(IConfigSource config) : base(config) | ||
45 | { | ||
46 | string dllName = String.Empty; | ||
47 | string connString = String.Empty; | ||
48 | |||
49 | // | ||
50 | // Try reading the [FriendsService] section first, if it exists | ||
51 | // | ||
52 | IConfig friendsConfig = config.Configs["FriendsService"]; | ||
53 | if (friendsConfig != null) | ||
54 | { | ||
55 | dllName = friendsConfig.GetString("StorageProvider", dllName); | ||
56 | connString = friendsConfig.GetString("ConnectionString", connString); | ||
57 | } | ||
58 | |||
59 | // | ||
60 | // Try reading the [DatabaseService] section, if it exists | ||
61 | // | ||
62 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
63 | if (dbConfig != null) | ||
64 | { | ||
65 | if (dllName == String.Empty) | ||
66 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
67 | if (connString == String.Empty) | ||
68 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
69 | } | ||
70 | |||
71 | // | ||
72 | // We tried, but this doesn't exist. We can't proceed. | ||
73 | // | ||
74 | if (String.Empty.Equals(dllName)) | ||
75 | throw new Exception("No StorageProvider configured"); | ||
76 | |||
77 | string realm = "Friends"; | ||
78 | if (friendsConfig != null) | ||
79 | realm = friendsConfig.GetString("Realm", realm); | ||
80 | |||
81 | m_Database = LoadPlugin<IFriendsData>(dllName, new Object[] { connString, realm }); | ||
82 | if (m_Database == null) | ||
83 | throw new Exception("Could not find a storage interface in the given module"); | ||
84 | } | ||
85 | } | ||
86 | } | ||
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs index 7749c37..1368e46 100644 --- a/OpenSim/Services/GridService/GridService.cs +++ b/OpenSim/Services/GridService/GridService.cs | |||
@@ -34,6 +34,7 @@ using log4net; | |||
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Console; | 35 | using OpenSim.Framework.Console; |
36 | using OpenSim.Data; | 36 | using OpenSim.Data; |
37 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | 38 | using OpenSim.Services.Interfaces; |
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
39 | using OpenMetaverse; | 40 | using OpenMetaverse; |
@@ -46,17 +47,58 @@ namespace OpenSim.Services.GridService | |||
46 | LogManager.GetLogger( | 47 | LogManager.GetLogger( |
47 | MethodBase.GetCurrentMethod().DeclaringType); | 48 | MethodBase.GetCurrentMethod().DeclaringType); |
48 | 49 | ||
50 | private bool m_DeleteOnUnregister = true; | ||
51 | private static GridService m_RootInstance = null; | ||
52 | protected IConfigSource m_config; | ||
53 | protected HypergridLinker m_HypergridLinker; | ||
54 | |||
55 | protected IAuthenticationService m_AuthenticationService = null; | ||
49 | protected bool m_AllowDuplicateNames = false; | 56 | protected bool m_AllowDuplicateNames = false; |
57 | protected bool m_AllowHypergridMapSearch = false; | ||
50 | 58 | ||
51 | public GridService(IConfigSource config) | 59 | public GridService(IConfigSource config) |
52 | : base(config) | 60 | : base(config) |
53 | { | 61 | { |
54 | m_log.DebugFormat("[GRID SERVICE]: Starting..."); | 62 | m_log.DebugFormat("[GRID SERVICE]: Starting..."); |
55 | 63 | ||
64 | m_config = config; | ||
56 | IConfig gridConfig = config.Configs["GridService"]; | 65 | IConfig gridConfig = config.Configs["GridService"]; |
57 | if (gridConfig != null) | 66 | if (gridConfig != null) |
58 | { | 67 | { |
68 | m_DeleteOnUnregister = gridConfig.GetBoolean("DeleteOnUnregister", true); | ||
69 | |||
70 | string authService = gridConfig.GetString("AuthenticationService", String.Empty); | ||
71 | |||
72 | if (authService != String.Empty) | ||
73 | { | ||
74 | Object[] args = new Object[] { config }; | ||
75 | m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); | ||
76 | } | ||
59 | m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); | 77 | m_AllowDuplicateNames = gridConfig.GetBoolean("AllowDuplicateNames", m_AllowDuplicateNames); |
78 | m_AllowHypergridMapSearch = gridConfig.GetBoolean("AllowHypergridMapSearch", m_AllowHypergridMapSearch); | ||
79 | } | ||
80 | |||
81 | if (m_RootInstance == null) | ||
82 | { | ||
83 | m_RootInstance = this; | ||
84 | |||
85 | if (MainConsole.Instance != null) | ||
86 | { | ||
87 | MainConsole.Instance.Commands.AddCommand("grid", true, | ||
88 | "show region", | ||
89 | "show region <Region name>", | ||
90 | "Show details on a region", | ||
91 | String.Empty, | ||
92 | HandleShowRegion); | ||
93 | |||
94 | MainConsole.Instance.Commands.AddCommand("grid", true, | ||
95 | "set region flags", | ||
96 | "set region flags <Region name> <flags>", | ||
97 | "Set database flags for region", | ||
98 | String.Empty, | ||
99 | HandleSetFlags); | ||
100 | } | ||
101 | m_HypergridLinker = new HypergridLinker(m_config, this, m_Database); | ||
60 | } | 102 | } |
61 | } | 103 | } |
62 | 104 | ||
@@ -64,9 +106,48 @@ namespace OpenSim.Services.GridService | |||
64 | 106 | ||
65 | public string RegisterRegion(UUID scopeID, GridRegion regionInfos) | 107 | public string RegisterRegion(UUID scopeID, GridRegion regionInfos) |
66 | { | 108 | { |
109 | IConfig gridConfig = m_config.Configs["GridService"]; | ||
67 | // This needs better sanity testing. What if regionInfo is registering in | 110 | // This needs better sanity testing. What if regionInfo is registering in |
68 | // overlapping coords? | 111 | // overlapping coords? |
69 | RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); | 112 | RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); |
113 | if (region != null) | ||
114 | { | ||
115 | // There is a preexisting record | ||
116 | // | ||
117 | // Get it's flags | ||
118 | // | ||
119 | OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(region.Data["flags"]); | ||
120 | |||
121 | // Is this a reservation? | ||
122 | // | ||
123 | if ((rflags & OpenSim.Data.RegionFlags.Reservation) != 0) | ||
124 | { | ||
125 | // Regions reserved for the null key cannot be taken. | ||
126 | // | ||
127 | if (region.Data["PrincipalID"] == UUID.Zero.ToString()) | ||
128 | return "Region location us reserved"; | ||
129 | |||
130 | // Treat it as an auth request | ||
131 | // | ||
132 | // NOTE: Fudging the flags value here, so these flags | ||
133 | // should not be used elsewhere. Don't optimize | ||
134 | // this with the later retrieval of the same flags! | ||
135 | // | ||
136 | rflags |= OpenSim.Data.RegionFlags.Authenticate; | ||
137 | } | ||
138 | |||
139 | if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0) | ||
140 | { | ||
141 | // Can we authenticate at all? | ||
142 | // | ||
143 | if (m_AuthenticationService == null) | ||
144 | return "No authentication possible"; | ||
145 | |||
146 | if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30)) | ||
147 | return "Bad authentication"; | ||
148 | } | ||
149 | } | ||
150 | |||
70 | if ((region != null) && (region.RegionID != regionInfos.RegionID)) | 151 | if ((region != null) && (region.RegionID != regionInfos.RegionID)) |
71 | { | 152 | { |
72 | m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", | 153 | m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", |
@@ -76,6 +157,9 @@ namespace OpenSim.Services.GridService | |||
76 | if ((region != null) && (region.RegionID == regionInfos.RegionID) && | 157 | if ((region != null) && (region.RegionID == regionInfos.RegionID) && |
77 | ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) | 158 | ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) |
78 | { | 159 | { |
160 | if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0) | ||
161 | return "Can't move this region"; | ||
162 | |||
79 | // Region reregistering in other coordinates. Delete the old entry | 163 | // Region reregistering in other coordinates. Delete the old entry |
80 | m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.", | 164 | m_log.DebugFormat("[GRID SERVICE]: Region {0} ({1}) was previously registered at {2}-{3}. Deleting old entry.", |
81 | regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY); | 165 | regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY); |
@@ -110,8 +194,37 @@ namespace OpenSim.Services.GridService | |||
110 | // Everything is ok, let's register | 194 | // Everything is ok, let's register |
111 | RegionData rdata = RegionInfo2RegionData(regionInfos); | 195 | RegionData rdata = RegionInfo2RegionData(regionInfos); |
112 | rdata.ScopeID = scopeID; | 196 | rdata.ScopeID = scopeID; |
197 | |||
198 | if (region != null) | ||
199 | { | ||
200 | int oldFlags = Convert.ToInt32(region.Data["flags"]); | ||
201 | if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0) | ||
202 | return "Region locked out"; | ||
203 | |||
204 | oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation; | ||
205 | |||
206 | rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | rdata.Data["flags"] = "0"; | ||
211 | if ((gridConfig != null) && rdata.RegionName != string.Empty) | ||
212 | { | ||
213 | int newFlags = 0; | ||
214 | string regionName = rdata.RegionName.Trim().Replace(' ', '_'); | ||
215 | newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty)); | ||
216 | newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + rdata.RegionID.ToString(), String.Empty)); | ||
217 | rdata.Data["flags"] = newFlags.ToString(); | ||
218 | } | ||
219 | } | ||
220 | |||
221 | int flags = Convert.ToInt32(rdata.Data["flags"]); | ||
222 | flags |= (int)OpenSim.Data.RegionFlags.RegionOnline; | ||
223 | rdata.Data["flags"] = flags.ToString(); | ||
224 | |||
113 | try | 225 | try |
114 | { | 226 | { |
227 | rdata.Data["last_seen"] = Util.UnixTimeSinceEpoch(); | ||
115 | m_Database.Store(rdata); | 228 | m_Database.Store(rdata); |
116 | } | 229 | } |
117 | catch (Exception e) | 230 | catch (Exception e) |
@@ -128,6 +241,30 @@ namespace OpenSim.Services.GridService | |||
128 | public bool DeregisterRegion(UUID regionID) | 241 | public bool DeregisterRegion(UUID regionID) |
129 | { | 242 | { |
130 | m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); | 243 | m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); |
244 | RegionData region = m_Database.Get(regionID, UUID.Zero); | ||
245 | if (region == null) | ||
246 | return false; | ||
247 | |||
248 | int flags = Convert.ToInt32(region.Data["flags"]); | ||
249 | |||
250 | if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Data.RegionFlags.Persistent) != 0) | ||
251 | { | ||
252 | flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline; | ||
253 | region.Data["flags"] = flags.ToString(); | ||
254 | region.Data["last_seen"] = Util.UnixTimeSinceEpoch(); | ||
255 | try | ||
256 | { | ||
257 | m_Database.Store(region); | ||
258 | } | ||
259 | catch (Exception e) | ||
260 | { | ||
261 | m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e); | ||
262 | } | ||
263 | |||
264 | return true; | ||
265 | |||
266 | } | ||
267 | |||
131 | return m_Database.Delete(regionID); | 268 | return m_Database.Delete(regionID); |
132 | } | 269 | } |
133 | 270 | ||
@@ -194,6 +331,13 @@ namespace OpenSim.Services.GridService | |||
194 | } | 331 | } |
195 | } | 332 | } |
196 | 333 | ||
334 | if (m_AllowHypergridMapSearch && rdatas == null || (rdatas != null && rdatas.Count == 0) && name.Contains(".")) | ||
335 | { | ||
336 | GridRegion r = m_HypergridLinker.LinkRegion(scopeID, name); | ||
337 | if (r != null) | ||
338 | rinfos.Add(r); | ||
339 | } | ||
340 | |||
197 | return rinfos; | 341 | return rinfos; |
198 | } | 342 | } |
199 | 343 | ||
@@ -216,7 +360,7 @@ namespace OpenSim.Services.GridService | |||
216 | 360 | ||
217 | #region Data structure conversions | 361 | #region Data structure conversions |
218 | 362 | ||
219 | protected RegionData RegionInfo2RegionData(GridRegion rinfo) | 363 | public RegionData RegionInfo2RegionData(GridRegion rinfo) |
220 | { | 364 | { |
221 | RegionData rdata = new RegionData(); | 365 | RegionData rdata = new RegionData(); |
222 | rdata.posX = (int)rinfo.RegionLocX; | 366 | rdata.posX = (int)rinfo.RegionLocX; |
@@ -229,7 +373,7 @@ namespace OpenSim.Services.GridService | |||
229 | return rdata; | 373 | return rdata; |
230 | } | 374 | } |
231 | 375 | ||
232 | protected GridRegion RegionData2RegionInfo(RegionData rdata) | 376 | public GridRegion RegionData2RegionInfo(RegionData rdata) |
233 | { | 377 | { |
234 | GridRegion rinfo = new GridRegion(rdata.Data); | 378 | GridRegion rinfo = new GridRegion(rdata.Data); |
235 | rinfo.RegionLocX = rdata.posX; | 379 | rinfo.RegionLocX = rdata.posX; |
@@ -243,5 +387,142 @@ namespace OpenSim.Services.GridService | |||
243 | 387 | ||
244 | #endregion | 388 | #endregion |
245 | 389 | ||
390 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
391 | { | ||
392 | List<GridRegion> ret = new List<GridRegion>(); | ||
393 | |||
394 | List<RegionData> regions = m_Database.GetDefaultRegions(scopeID); | ||
395 | |||
396 | foreach (RegionData r in regions) | ||
397 | { | ||
398 | if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0) | ||
399 | ret.Add(RegionData2RegionInfo(r)); | ||
400 | } | ||
401 | |||
402 | return ret; | ||
403 | } | ||
404 | |||
405 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
406 | { | ||
407 | List<GridRegion> ret = new List<GridRegion>(); | ||
408 | |||
409 | List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y); | ||
410 | |||
411 | foreach (RegionData r in regions) | ||
412 | { | ||
413 | if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0) | ||
414 | ret.Add(RegionData2RegionInfo(r)); | ||
415 | } | ||
416 | |||
417 | m_log.DebugFormat("[GRID SERVICE]: Fallback returned {0} regions", ret.Count); | ||
418 | return ret; | ||
419 | } | ||
420 | |||
421 | public int GetRegionFlags(UUID scopeID, UUID regionID) | ||
422 | { | ||
423 | RegionData region = m_Database.Get(regionID, scopeID); | ||
424 | |||
425 | if (region != null) | ||
426 | { | ||
427 | int flags = Convert.ToInt32(region.Data["flags"]); | ||
428 | //m_log.DebugFormat("[GRID SERVICE]: Request for flags of {0}: {1}", regionID, flags); | ||
429 | return flags; | ||
430 | } | ||
431 | else | ||
432 | return -1; | ||
433 | } | ||
434 | |||
435 | private void HandleShowRegion(string module, string[] cmd) | ||
436 | { | ||
437 | if (cmd.Length != 3) | ||
438 | { | ||
439 | MainConsole.Instance.Output("Syntax: show region <region name>"); | ||
440 | return; | ||
441 | } | ||
442 | List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero); | ||
443 | if (regions == null || regions.Count < 1) | ||
444 | { | ||
445 | MainConsole.Instance.Output("Region not found"); | ||
446 | return; | ||
447 | } | ||
448 | |||
449 | MainConsole.Instance.Output("Region Name Region UUID"); | ||
450 | MainConsole.Instance.Output("Location URI"); | ||
451 | MainConsole.Instance.Output("Owner ID Flags"); | ||
452 | MainConsole.Instance.Output("-------------------------------------------------------------------------------"); | ||
453 | foreach (RegionData r in regions) | ||
454 | { | ||
455 | OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]); | ||
456 | MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n", | ||
457 | r.RegionName, r.RegionID, | ||
458 | String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(), | ||
459 | r.Data["owner_uuid"].ToString(), flags.ToString())); | ||
460 | } | ||
461 | return; | ||
462 | } | ||
463 | |||
464 | private int ParseFlags(int prev, string flags) | ||
465 | { | ||
466 | OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev; | ||
467 | |||
468 | string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries); | ||
469 | |||
470 | foreach (string p in parts) | ||
471 | { | ||
472 | int val; | ||
473 | |||
474 | try | ||
475 | { | ||
476 | if (p.StartsWith("+")) | ||
477 | { | ||
478 | val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1)); | ||
479 | f |= (OpenSim.Data.RegionFlags)val; | ||
480 | } | ||
481 | else if (p.StartsWith("-")) | ||
482 | { | ||
483 | val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1)); | ||
484 | f &= ~(OpenSim.Data.RegionFlags)val; | ||
485 | } | ||
486 | else | ||
487 | { | ||
488 | val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p); | ||
489 | f |= (OpenSim.Data.RegionFlags)val; | ||
490 | } | ||
491 | } | ||
492 | catch (Exception e) | ||
493 | { | ||
494 | MainConsole.Instance.Output("Error in flag specification: " + p); | ||
495 | } | ||
496 | } | ||
497 | |||
498 | return (int)f; | ||
499 | } | ||
500 | |||
501 | private void HandleSetFlags(string module, string[] cmd) | ||
502 | { | ||
503 | if (cmd.Length < 5) | ||
504 | { | ||
505 | MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>"); | ||
506 | return; | ||
507 | } | ||
508 | |||
509 | List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero); | ||
510 | if (regions == null || regions.Count < 1) | ||
511 | { | ||
512 | MainConsole.Instance.Output("Region not found"); | ||
513 | return; | ||
514 | } | ||
515 | |||
516 | foreach (RegionData r in regions) | ||
517 | { | ||
518 | int flags = Convert.ToInt32(r.Data["flags"]); | ||
519 | flags = ParseFlags(flags, cmd[4]); | ||
520 | r.Data["flags"] = flags.ToString(); | ||
521 | OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags; | ||
522 | |||
523 | MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f)); | ||
524 | m_Database.Store(r); | ||
525 | } | ||
526 | } | ||
246 | } | 527 | } |
247 | } | 528 | } |
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs new file mode 100644 index 0000000..de5df9d --- /dev/null +++ b/OpenSim/Services/GridService/HypergridLinker.cs | |||
@@ -0,0 +1,634 @@ | |||
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 Nini.Config; | ||
35 | using log4net; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using OpenSim.Services.Connectors.Hypergrid; | ||
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
43 | using OpenMetaverse; | ||
44 | |||
45 | namespace OpenSim.Services.GridService | ||
46 | { | ||
47 | public class HypergridLinker | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger( | ||
51 | MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
54 | |||
55 | private static uint m_autoMappingX = 0; | ||
56 | private static uint m_autoMappingY = 0; | ||
57 | private static bool m_enableAutoMapping = false; | ||
58 | |||
59 | protected IRegionData m_Database; | ||
60 | protected GridService m_GridService; | ||
61 | protected IAssetService m_AssetService; | ||
62 | protected GatekeeperServiceConnector m_GatekeeperConnector; | ||
63 | |||
64 | protected UUID m_ScopeID = UUID.Zero; | ||
65 | |||
66 | // Hyperlink regions are hyperlinks on the map | ||
67 | public readonly Dictionary<UUID, GridRegion> m_HyperlinkRegions = new Dictionary<UUID, GridRegion>(); | ||
68 | protected Dictionary<UUID, ulong> m_HyperlinkHandles = new Dictionary<UUID, ulong>(); | ||
69 | |||
70 | protected GridRegion m_DefaultRegion; | ||
71 | protected GridRegion DefaultRegion | ||
72 | { | ||
73 | get | ||
74 | { | ||
75 | if (m_DefaultRegion == null) | ||
76 | { | ||
77 | List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); | ||
78 | if (defs != null && defs.Count > 0) | ||
79 | m_DefaultRegion = defs[0]; | ||
80 | else | ||
81 | { | ||
82 | // Best guess, may be totally off | ||
83 | m_DefaultRegion = new GridRegion(1000, 1000); | ||
84 | m_log.WarnFormat("[HYPERGRID LINKER]: This grid does not have a default region. Assuming default coordinates at 1000, 1000."); | ||
85 | } | ||
86 | } | ||
87 | return m_DefaultRegion; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public HypergridLinker(IConfigSource config, GridService gridService, IRegionData db) | ||
92 | { | ||
93 | m_log.DebugFormat("[HYPERGRID LINKER]: Starting..."); | ||
94 | |||
95 | m_Database = db; | ||
96 | m_GridService = gridService; | ||
97 | |||
98 | IConfig gridConfig = config.Configs["GridService"]; | ||
99 | if (gridConfig != null) | ||
100 | { | ||
101 | string assetService = gridConfig.GetString("AssetService", string.Empty); | ||
102 | |||
103 | Object[] args = new Object[] { config }; | ||
104 | |||
105 | if (assetService != string.Empty) | ||
106 | m_AssetService = ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
107 | |||
108 | string scope = gridConfig.GetString("ScopeID", string.Empty); | ||
109 | if (scope != string.Empty) | ||
110 | UUID.TryParse(scope, out m_ScopeID); | ||
111 | |||
112 | m_GatekeeperConnector = new GatekeeperServiceConnector(m_AssetService); | ||
113 | |||
114 | m_log.DebugFormat("[HYPERGRID LINKER]: Loaded all services..."); | ||
115 | } | ||
116 | |||
117 | if (MainConsole.Instance != null) | ||
118 | { | ||
119 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region", | ||
120 | "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>", | ||
121 | "Link a hypergrid region", RunCommand); | ||
122 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "unlink-region", | ||
123 | "unlink-region <local name> or <HostName>:<HttpPort> <cr>", | ||
124 | "Unlink a hypergrid region", RunCommand); | ||
125 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>", | ||
126 | "Set local coordinate to map HG regions to", RunCommand); | ||
127 | MainConsole.Instance.Commands.AddCommand("hypergrid", false, "show hyperlinks", "show hyperlinks <cr>", | ||
128 | "List the HG regions", HandleShow); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | |||
133 | #region Link Region | ||
134 | |||
135 | public GridRegion LinkRegion(UUID scopeID, string regionDescriptor) | ||
136 | { | ||
137 | string reason = string.Empty; | ||
138 | int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize; | ||
139 | return TryLinkRegionToCoords(scopeID, regionDescriptor, xloc, 0, out reason); | ||
140 | } | ||
141 | |||
142 | private static Random random = new Random(); | ||
143 | |||
144 | // From the command line link-region | ||
145 | public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason) | ||
146 | { | ||
147 | reason = string.Empty; | ||
148 | string host = "127.0.0.1"; | ||
149 | string portstr; | ||
150 | string regionName = ""; | ||
151 | uint port = 9000; | ||
152 | string[] parts = mapName.Split(new char[] { ':' }); | ||
153 | if (parts.Length >= 1) | ||
154 | { | ||
155 | host = parts[0]; | ||
156 | } | ||
157 | if (parts.Length >= 2) | ||
158 | { | ||
159 | portstr = parts[1]; | ||
160 | //m_log.Debug("-- port = " + portstr); | ||
161 | if (!UInt32.TryParse(portstr, out port)) | ||
162 | regionName = parts[1]; | ||
163 | } | ||
164 | // always take the last one | ||
165 | if (parts.Length >= 3) | ||
166 | { | ||
167 | regionName = parts[2]; | ||
168 | } | ||
169 | |||
170 | // Sanity check. | ||
171 | IPAddress ipaddr = null; | ||
172 | try | ||
173 | { | ||
174 | ipaddr = Util.GetHostFromDNS(host); | ||
175 | } | ||
176 | catch | ||
177 | { | ||
178 | reason = "Malformed hostname"; | ||
179 | return null; | ||
180 | } | ||
181 | |||
182 | GridRegion regInfo; | ||
183 | bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason); | ||
184 | if (success) | ||
185 | { | ||
186 | regInfo.RegionName = mapName; | ||
187 | return regInfo; | ||
188 | } | ||
189 | |||
190 | return null; | ||
191 | } | ||
192 | |||
193 | |||
194 | // From the command line and the 2 above | ||
195 | public bool TryCreateLink(UUID scopeID, int xloc, int yloc, | ||
196 | string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason) | ||
197 | { | ||
198 | m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc); | ||
199 | |||
200 | reason = string.Empty; | ||
201 | regInfo = new GridRegion(); | ||
202 | regInfo.RegionName = externalRegionName; | ||
203 | regInfo.HttpPort = externalPort; | ||
204 | regInfo.ExternalHostName = externalHostName; | ||
205 | regInfo.RegionLocX = xloc; | ||
206 | regInfo.RegionLocY = yloc; | ||
207 | regInfo.ScopeID = scopeID; | ||
208 | |||
209 | try | ||
210 | { | ||
211 | regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0); | ||
212 | } | ||
213 | catch (Exception e) | ||
214 | { | ||
215 | m_log.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message); | ||
216 | reason = "Internal error"; | ||
217 | return false; | ||
218 | } | ||
219 | |||
220 | // Finally, link it | ||
221 | ulong handle = 0; | ||
222 | UUID regionID = UUID.Zero; | ||
223 | string externalName = string.Empty; | ||
224 | string imageURL = string.Empty; | ||
225 | if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason)) | ||
226 | return false; | ||
227 | |||
228 | if (regionID != UUID.Zero) | ||
229 | { | ||
230 | GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID); | ||
231 | if (r != null) | ||
232 | { | ||
233 | m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize); | ||
234 | regInfo = r; | ||
235 | return true; | ||
236 | } | ||
237 | |||
238 | regInfo.RegionID = regionID; | ||
239 | Uri uri = null; | ||
240 | try | ||
241 | { | ||
242 | uri = new Uri(externalName); | ||
243 | regInfo.ExternalHostName = uri.Host; | ||
244 | regInfo.HttpPort = (uint)uri.Port; | ||
245 | } | ||
246 | catch | ||
247 | { | ||
248 | m_log.WarnFormat("[HYPERGRID LINKER]: Remote Gatekeeper at {0} provided malformed ExternalName {1}", regInfo.ExternalHostName, externalName); | ||
249 | } | ||
250 | regInfo.RegionName = regInfo.ExternalHostName + ":" + regInfo.HttpPort + ":" + regInfo.RegionName; | ||
251 | // Try get the map image | ||
252 | //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL); | ||
253 | // I need a texture that works for this... the one I tried doesn't seem to be working | ||
254 | regInfo.TerrainImage = m_HGMapImage; | ||
255 | |||
256 | AddHyperlinkRegion(regInfo, handle); | ||
257 | m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID); | ||
258 | |||
259 | } | ||
260 | else | ||
261 | { | ||
262 | m_log.Warn("[HYPERGRID LINKER]: Unable to link region"); | ||
263 | reason = "Remote region could not be found"; | ||
264 | return false; | ||
265 | } | ||
266 | |||
267 | uint x, y; | ||
268 | if (!Check4096(handle, out x, out y)) | ||
269 | { | ||
270 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
271 | reason = "Region is too far (" + x + ", " + y + ")"; | ||
272 | m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")"); | ||
273 | return false; | ||
274 | } | ||
275 | |||
276 | m_log.Debug("[HYPERGRID LINKER]: link region succeeded"); | ||
277 | return true; | ||
278 | } | ||
279 | |||
280 | public bool TryUnlinkRegion(string mapName) | ||
281 | { | ||
282 | GridRegion regInfo = null; | ||
283 | if (mapName.Contains(":")) | ||
284 | { | ||
285 | string host = "127.0.0.1"; | ||
286 | //string portstr; | ||
287 | //string regionName = ""; | ||
288 | uint port = 9000; | ||
289 | string[] parts = mapName.Split(new char[] { ':' }); | ||
290 | if (parts.Length >= 1) | ||
291 | { | ||
292 | host = parts[0]; | ||
293 | } | ||
294 | |||
295 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
296 | if (host.Equals(r.ExternalHostName) && (port == r.HttpPort)) | ||
297 | regInfo = r; | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | foreach (GridRegion r in m_HyperlinkRegions.Values) | ||
302 | if (r.RegionName.Equals(mapName)) | ||
303 | regInfo = r; | ||
304 | } | ||
305 | if (regInfo != null) | ||
306 | { | ||
307 | RemoveHyperlinkRegion(regInfo.RegionID); | ||
308 | return true; | ||
309 | } | ||
310 | else | ||
311 | { | ||
312 | m_log.InfoFormat("[HYPERGRID LINKER]: Region {0} not found", mapName); | ||
313 | return false; | ||
314 | } | ||
315 | } | ||
316 | |||
317 | /// <summary> | ||
318 | /// Cope with this viewer limitation. | ||
319 | /// </summary> | ||
320 | /// <param name="regInfo"></param> | ||
321 | /// <returns></returns> | ||
322 | public bool Check4096(ulong realHandle, out uint x, out uint y) | ||
323 | { | ||
324 | GridRegion defRegion = DefaultRegion; | ||
325 | |||
326 | uint ux = 0, uy = 0; | ||
327 | Utils.LongToUInts(realHandle, out ux, out uy); | ||
328 | x = ux / Constants.RegionSize; | ||
329 | y = uy / Constants.RegionSize; | ||
330 | |||
331 | if ((Math.Abs((int)defRegion.RegionLocX - ux) >= 4096 * Constants.RegionSize) || | ||
332 | (Math.Abs((int)defRegion.RegionLocY - uy) >= 4096 * Constants.RegionSize)) | ||
333 | { | ||
334 | return false; | ||
335 | } | ||
336 | return true; | ||
337 | } | ||
338 | |||
339 | private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle) | ||
340 | { | ||
341 | //m_HyperlinkRegions[regionInfo.RegionID] = regionInfo; | ||
342 | //m_HyperlinkHandles[regionInfo.RegionID] = regionHandle; | ||
343 | |||
344 | RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo); | ||
345 | int flags = (int)OpenSim.Data.RegionFlags.Hyperlink + (int)OpenSim.Data.RegionFlags.NoDirectLogin + (int)OpenSim.Data.RegionFlags.RegionOnline; | ||
346 | rdata.Data["flags"] = flags.ToString(); | ||
347 | |||
348 | m_Database.Store(rdata); | ||
349 | |||
350 | } | ||
351 | |||
352 | private void RemoveHyperlinkRegion(UUID regionID) | ||
353 | { | ||
354 | //// Try the hyperlink collection | ||
355 | //if (m_HyperlinkRegions.ContainsKey(regionID)) | ||
356 | //{ | ||
357 | // m_HyperlinkRegions.Remove(regionID); | ||
358 | // m_HyperlinkHandles.Remove(regionID); | ||
359 | //} | ||
360 | m_Database.Delete(regionID); | ||
361 | } | ||
362 | |||
363 | #endregion | ||
364 | |||
365 | |||
366 | #region Console Commands | ||
367 | |||
368 | public void HandleShow(string module, string[] cmd) | ||
369 | { | ||
370 | MainConsole.Instance.Output("Not Implemented Yet"); | ||
371 | //if (cmd.Length != 2) | ||
372 | //{ | ||
373 | // MainConsole.Instance.Output("Syntax: show hyperlinks"); | ||
374 | // return; | ||
375 | //} | ||
376 | //List<GridRegion> regions = new List<GridRegion>(m_HypergridService.m_HyperlinkRegions.Values); | ||
377 | //if (regions == null || regions.Count < 1) | ||
378 | //{ | ||
379 | // MainConsole.Instance.Output("No hyperlinks"); | ||
380 | // return; | ||
381 | //} | ||
382 | |||
383 | //MainConsole.Instance.Output("Region Name Region UUID"); | ||
384 | //MainConsole.Instance.Output("Location URI"); | ||
385 | //MainConsole.Instance.Output("Owner ID "); | ||
386 | //MainConsole.Instance.Output("-------------------------------------------------------------------------------"); | ||
387 | //foreach (GridRegion r in regions) | ||
388 | //{ | ||
389 | // MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} \n\n", | ||
390 | // r.RegionName, r.RegionID, | ||
391 | // String.Format("{0},{1}", r.RegionLocX, r.RegionLocY), "http://" + r.ExternalHostName + ":" + r.HttpPort.ToString(), | ||
392 | // r.EstateOwner.ToString())); | ||
393 | //} | ||
394 | //return; | ||
395 | } | ||
396 | public void RunCommand(string module, string[] cmdparams) | ||
397 | { | ||
398 | List<string> args = new List<string>(cmdparams); | ||
399 | if (args.Count < 1) | ||
400 | return; | ||
401 | |||
402 | string command = args[0]; | ||
403 | args.RemoveAt(0); | ||
404 | |||
405 | cmdparams = args.ToArray(); | ||
406 | |||
407 | RunHGCommand(command, cmdparams); | ||
408 | |||
409 | } | ||
410 | |||
411 | private void RunHGCommand(string command, string[] cmdparams) | ||
412 | { | ||
413 | if (command.Equals("link-mapping")) | ||
414 | { | ||
415 | if (cmdparams.Length == 2) | ||
416 | { | ||
417 | try | ||
418 | { | ||
419 | m_autoMappingX = Convert.ToUInt32(cmdparams[0]); | ||
420 | m_autoMappingY = Convert.ToUInt32(cmdparams[1]); | ||
421 | m_enableAutoMapping = true; | ||
422 | } | ||
423 | catch (Exception) | ||
424 | { | ||
425 | m_autoMappingX = 0; | ||
426 | m_autoMappingY = 0; | ||
427 | m_enableAutoMapping = false; | ||
428 | } | ||
429 | } | ||
430 | } | ||
431 | else if (command.Equals("link-region")) | ||
432 | { | ||
433 | if (cmdparams.Length < 3) | ||
434 | { | ||
435 | if ((cmdparams.Length == 1) || (cmdparams.Length == 2)) | ||
436 | { | ||
437 | LoadXmlLinkFile(cmdparams); | ||
438 | } | ||
439 | else | ||
440 | { | ||
441 | LinkRegionCmdUsage(); | ||
442 | } | ||
443 | return; | ||
444 | } | ||
445 | |||
446 | if (cmdparams[2].Contains(":")) | ||
447 | { | ||
448 | // New format | ||
449 | int xloc, yloc; | ||
450 | string mapName; | ||
451 | try | ||
452 | { | ||
453 | xloc = Convert.ToInt32(cmdparams[0]); | ||
454 | yloc = Convert.ToInt32(cmdparams[1]); | ||
455 | mapName = cmdparams[2]; | ||
456 | if (cmdparams.Length > 3) | ||
457 | for (int i = 3; i < cmdparams.Length; i++) | ||
458 | mapName += " " + cmdparams[i]; | ||
459 | |||
460 | //m_log.Info(">> MapName: " + mapName); | ||
461 | } | ||
462 | catch (Exception e) | ||
463 | { | ||
464 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); | ||
465 | LinkRegionCmdUsage(); | ||
466 | return; | ||
467 | } | ||
468 | |||
469 | // Convert cell coordinates given by the user to meters | ||
470 | xloc = xloc * (int)Constants.RegionSize; | ||
471 | yloc = yloc * (int)Constants.RegionSize; | ||
472 | string reason = string.Empty; | ||
473 | if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null) | ||
474 | MainConsole.Instance.Output("Failed to link region: " + reason); | ||
475 | else | ||
476 | MainConsole.Instance.Output("Hyperlink established"); | ||
477 | } | ||
478 | else | ||
479 | { | ||
480 | // old format | ||
481 | GridRegion regInfo; | ||
482 | int xloc, yloc; | ||
483 | uint externalPort; | ||
484 | string externalHostName; | ||
485 | try | ||
486 | { | ||
487 | xloc = Convert.ToInt32(cmdparams[0]); | ||
488 | yloc = Convert.ToInt32(cmdparams[1]); | ||
489 | externalPort = Convert.ToUInt32(cmdparams[3]); | ||
490 | externalHostName = cmdparams[2]; | ||
491 | //internalPort = Convert.ToUInt32(cmdparams[4]); | ||
492 | //remotingPort = Convert.ToUInt32(cmdparams[5]); | ||
493 | } | ||
494 | catch (Exception e) | ||
495 | { | ||
496 | MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message); | ||
497 | LinkRegionCmdUsage(); | ||
498 | return; | ||
499 | } | ||
500 | |||
501 | // Convert cell coordinates given by the user to meters | ||
502 | xloc = xloc * (int)Constants.RegionSize; | ||
503 | yloc = yloc * (int)Constants.RegionSize; | ||
504 | string reason = string.Empty; | ||
505 | if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason)) | ||
506 | { | ||
507 | if (cmdparams.Length >= 5) | ||
508 | { | ||
509 | regInfo.RegionName = ""; | ||
510 | for (int i = 4; i < cmdparams.Length; i++) | ||
511 | regInfo.RegionName += cmdparams[i] + " "; | ||
512 | } | ||
513 | } | ||
514 | } | ||
515 | return; | ||
516 | } | ||
517 | else if (command.Equals("unlink-region")) | ||
518 | { | ||
519 | if (cmdparams.Length < 1) | ||
520 | { | ||
521 | UnlinkRegionCmdUsage(); | ||
522 | return; | ||
523 | } | ||
524 | if (TryUnlinkRegion(cmdparams[0])) | ||
525 | MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]); | ||
526 | else | ||
527 | MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found."); | ||
528 | } | ||
529 | } | ||
530 | |||
531 | private void LoadXmlLinkFile(string[] cmdparams) | ||
532 | { | ||
533 | //use http://www.hgurl.com/hypergrid.xml for test | ||
534 | try | ||
535 | { | ||
536 | XmlReader r = XmlReader.Create(cmdparams[0]); | ||
537 | XmlConfigSource cs = new XmlConfigSource(r); | ||
538 | string[] excludeSections = null; | ||
539 | |||
540 | if (cmdparams.Length == 2) | ||
541 | { | ||
542 | if (cmdparams[1].ToLower().StartsWith("excludelist:")) | ||
543 | { | ||
544 | string excludeString = cmdparams[1].ToLower(); | ||
545 | excludeString = excludeString.Remove(0, 12); | ||
546 | char[] splitter = { ';' }; | ||
547 | |||
548 | excludeSections = excludeString.Split(splitter); | ||
549 | } | ||
550 | } | ||
551 | |||
552 | for (int i = 0; i < cs.Configs.Count; i++) | ||
553 | { | ||
554 | bool skip = false; | ||
555 | if ((excludeSections != null) && (excludeSections.Length > 0)) | ||
556 | { | ||
557 | for (int n = 0; n < excludeSections.Length; n++) | ||
558 | { | ||
559 | if (excludeSections[n] == cs.Configs[i].Name.ToLower()) | ||
560 | { | ||
561 | skip = true; | ||
562 | break; | ||
563 | } | ||
564 | } | ||
565 | } | ||
566 | if (!skip) | ||
567 | { | ||
568 | ReadLinkFromConfig(cs.Configs[i]); | ||
569 | } | ||
570 | } | ||
571 | } | ||
572 | catch (Exception e) | ||
573 | { | ||
574 | m_log.Error(e.ToString()); | ||
575 | } | ||
576 | } | ||
577 | |||
578 | |||
579 | private void ReadLinkFromConfig(IConfig config) | ||
580 | { | ||
581 | GridRegion regInfo; | ||
582 | int xloc, yloc; | ||
583 | uint externalPort; | ||
584 | string externalHostName; | ||
585 | uint realXLoc, realYLoc; | ||
586 | |||
587 | xloc = Convert.ToInt32(config.GetString("xloc", "0")); | ||
588 | yloc = Convert.ToInt32(config.GetString("yloc", "0")); | ||
589 | externalPort = Convert.ToUInt32(config.GetString("externalPort", "0")); | ||
590 | externalHostName = config.GetString("externalHostName", ""); | ||
591 | realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0")); | ||
592 | realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0")); | ||
593 | |||
594 | if (m_enableAutoMapping) | ||
595 | { | ||
596 | xloc = (int)((xloc % 100) + m_autoMappingX); | ||
597 | yloc = (int)((yloc % 100) + m_autoMappingY); | ||
598 | } | ||
599 | |||
600 | if (((realXLoc == 0) && (realYLoc == 0)) || | ||
601 | (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) && | ||
602 | ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896)))) | ||
603 | { | ||
604 | xloc = xloc * (int)Constants.RegionSize; | ||
605 | yloc = yloc * (int)Constants.RegionSize; | ||
606 | string reason = string.Empty; | ||
607 | if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, | ||
608 | externalHostName, out regInfo, out reason)) | ||
609 | { | ||
610 | regInfo.RegionName = config.GetString("localName", ""); | ||
611 | } | ||
612 | else | ||
613 | MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason); | ||
614 | } | ||
615 | } | ||
616 | |||
617 | |||
618 | private void LinkRegionCmdUsage() | ||
619 | { | ||
620 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]"); | ||
621 | MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]"); | ||
622 | MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]"); | ||
623 | } | ||
624 | |||
625 | private void UnlinkRegionCmdUsage() | ||
626 | { | ||
627 | MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>"); | ||
628 | MainConsole.Instance.Output("Usage: unlink-region <LocalName>"); | ||
629 | } | ||
630 | |||
631 | #endregion | ||
632 | |||
633 | } | ||
634 | } | ||
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs new file mode 100644 index 0000000..56744b6 --- /dev/null +++ b/OpenSim/Services/HypergridService/GatekeeperService.cs | |||
@@ -0,0 +1,321 @@ | |||
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 | |||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Connectors.Hypergrid; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | |||
41 | using Nini.Config; | ||
42 | using log4net; | ||
43 | |||
44 | namespace OpenSim.Services.HypergridService | ||
45 | { | ||
46 | public class GatekeeperService : IGatekeeperService | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | IGridService m_GridService; | ||
53 | IPresenceService m_PresenceService; | ||
54 | IUserAccountService m_UserAccountService; | ||
55 | IUserAgentService m_UserAgentService; | ||
56 | ISimulationService m_SimulationService; | ||
57 | |||
58 | string m_AuthDll; | ||
59 | |||
60 | UUID m_ScopeID; | ||
61 | bool m_AllowTeleportsToAnyRegion; | ||
62 | string m_ExternalName; | ||
63 | GridRegion m_DefaultGatewayRegion; | ||
64 | |||
65 | public GatekeeperService(IConfigSource config, ISimulationService simService) | ||
66 | { | ||
67 | IConfig serverConfig = config.Configs["GatekeeperService"]; | ||
68 | if (serverConfig == null) | ||
69 | throw new Exception(String.Format("No section GatekeeperService in config file")); | ||
70 | |||
71 | string accountService = serverConfig.GetString("UserAccountService", String.Empty); | ||
72 | string homeUsersService = serverConfig.GetString("HomeUsersSecurityService", string.Empty); | ||
73 | string gridService = serverConfig.GetString("GridService", String.Empty); | ||
74 | string presenceService = serverConfig.GetString("PresenceService", String.Empty); | ||
75 | string simulationService = serverConfig.GetString("SimulationService", String.Empty); | ||
76 | |||
77 | //m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty); | ||
78 | |||
79 | // These 3 are mandatory, the others aren't | ||
80 | if (gridService == string.Empty || presenceService == string.Empty || m_AuthDll == string.Empty) | ||
81 | throw new Exception("Incomplete specifications, Gatekeeper Service cannot function."); | ||
82 | |||
83 | string scope = serverConfig.GetString("ScopeID", UUID.Zero.ToString()); | ||
84 | UUID.TryParse(scope, out m_ScopeID); | ||
85 | //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!"); | ||
86 | m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true); | ||
87 | m_ExternalName = serverConfig.GetString("ExternalName", string.Empty); | ||
88 | |||
89 | Object[] args = new Object[] { config }; | ||
90 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
91 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); | ||
92 | |||
93 | if (accountService != string.Empty) | ||
94 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); | ||
95 | if (homeUsersService != string.Empty) | ||
96 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args); | ||
97 | |||
98 | if (simService != null) | ||
99 | m_SimulationService = simService; | ||
100 | else if (simulationService != string.Empty) | ||
101 | m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args); | ||
102 | |||
103 | if (m_GridService == null || m_PresenceService == null || m_SimulationService == null) | ||
104 | throw new Exception("Unable to load a required plugin, Gatekeeper Service cannot function."); | ||
105 | |||
106 | m_log.Debug("[GATEKEEPER SERVICE]: Starting..."); | ||
107 | } | ||
108 | |||
109 | public GatekeeperService(IConfigSource config) | ||
110 | : this(config, null) | ||
111 | { | ||
112 | } | ||
113 | |||
114 | public bool LinkRegion(string regionName, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason) | ||
115 | { | ||
116 | regionID = UUID.Zero; | ||
117 | regionHandle = 0; | ||
118 | externalName = m_ExternalName; | ||
119 | imageURL = string.Empty; | ||
120 | reason = string.Empty; | ||
121 | |||
122 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty ? "default region" : regionName)); | ||
123 | if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty) | ||
124 | { | ||
125 | List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); | ||
126 | if (defs != null && defs.Count > 0) | ||
127 | m_DefaultGatewayRegion = defs[0]; | ||
128 | |||
129 | try | ||
130 | { | ||
131 | regionID = m_DefaultGatewayRegion.RegionID; | ||
132 | regionHandle = m_DefaultGatewayRegion.RegionHandle; | ||
133 | } | ||
134 | catch | ||
135 | { | ||
136 | reason = "Grid setup problem. Try specifying a particular region here."; | ||
137 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to send information. Please specify a default region for this grid!"); | ||
138 | return false; | ||
139 | } | ||
140 | |||
141 | return true; | ||
142 | } | ||
143 | |||
144 | GridRegion region = m_GridService.GetRegionByName(m_ScopeID, regionName); | ||
145 | if (region == null) | ||
146 | { | ||
147 | reason = "Region not found"; | ||
148 | return false; | ||
149 | } | ||
150 | |||
151 | regionID = region.RegionID; | ||
152 | regionHandle = region.RegionHandle; | ||
153 | string regionimage = "regionImage" + region.RegionID.ToString(); | ||
154 | regionimage = regionimage.Replace("-", ""); | ||
155 | |||
156 | imageURL = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/index.php?method=" + regionimage; | ||
157 | |||
158 | return true; | ||
159 | } | ||
160 | |||
161 | public GridRegion GetHyperlinkRegion(UUID regionID) | ||
162 | { | ||
163 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to get hyperlink region {0}", regionID); | ||
164 | |||
165 | if (!m_AllowTeleportsToAnyRegion) | ||
166 | // Don't even check the given regionID | ||
167 | return m_DefaultGatewayRegion; | ||
168 | |||
169 | GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID); | ||
170 | return region; | ||
171 | } | ||
172 | |||
173 | #region Login Agent | ||
174 | public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason) | ||
175 | { | ||
176 | reason = string.Empty; | ||
177 | |||
178 | string authURL = string.Empty; | ||
179 | if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) | ||
180 | authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); | ||
181 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to login foreign agent {0} {1} @ {2} ({3}) at destination {4}", | ||
182 | aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName); | ||
183 | |||
184 | // | ||
185 | // Authenticate the user | ||
186 | // | ||
187 | if (!Authenticate(aCircuit)) | ||
188 | { | ||
189 | reason = "Unable to verify identity"; | ||
190 | m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); | ||
191 | return false; | ||
192 | } | ||
193 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); | ||
194 | |||
195 | // | ||
196 | // Check for impersonations | ||
197 | // | ||
198 | UserAccount account = null; | ||
199 | if (m_UserAccountService != null) | ||
200 | { | ||
201 | // Check to see if we have a local user with that UUID | ||
202 | account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); | ||
203 | if (account != null) | ||
204 | { | ||
205 | // Make sure this is the user coming home, and not a foreign user with same UUID as a local user | ||
206 | if (m_UserAgentService != null) | ||
207 | { | ||
208 | if (!m_UserAgentService.AgentIsComingHome(aCircuit.SessionID, m_ExternalName)) | ||
209 | { | ||
210 | // Can't do, sorry | ||
211 | reason = "Unauthorized"; | ||
212 | m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", | ||
213 | aCircuit.firstname, aCircuit.lastname); | ||
214 | return false; | ||
215 | |||
216 | } | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | m_log.DebugFormat("[GATEKEEPER SERVICE]: User is ok"); | ||
221 | |||
222 | // May want to authorize | ||
223 | |||
224 | // | ||
225 | // Login the presence | ||
226 | // | ||
227 | if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) | ||
228 | { | ||
229 | reason = "Unable to login presence"; | ||
230 | m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.", | ||
231 | aCircuit.firstname, aCircuit.lastname); | ||
232 | return false; | ||
233 | } | ||
234 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok"); | ||
235 | |||
236 | // | ||
237 | // Get the region | ||
238 | // | ||
239 | destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID); | ||
240 | if (destination == null) | ||
241 | { | ||
242 | reason = "Destination region not found"; | ||
243 | return false; | ||
244 | } | ||
245 | m_log.DebugFormat("[GATEKEEPER SERVICE]: destination ok: {0}", destination.RegionName); | ||
246 | |||
247 | // | ||
248 | // Adjust the visible name | ||
249 | // | ||
250 | if (account != null) | ||
251 | { | ||
252 | aCircuit.firstname = account.FirstName; | ||
253 | aCircuit.lastname = account.LastName; | ||
254 | } | ||
255 | if (account == null && !aCircuit.lastname.StartsWith("@")) | ||
256 | { | ||
257 | aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; | ||
258 | aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); | ||
259 | } | ||
260 | |||
261 | // | ||
262 | // Finally launch the agent at the destination | ||
263 | // | ||
264 | return m_SimulationService.CreateAgent(destination, aCircuit, (uint)Constants.TeleportFlags.ViaLogin, out reason); | ||
265 | } | ||
266 | |||
267 | protected bool Authenticate(AgentCircuitData aCircuit) | ||
268 | { | ||
269 | if (!CheckAddress(aCircuit.ServiceSessionID)) | ||
270 | return false; | ||
271 | |||
272 | string userURL = string.Empty; | ||
273 | if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) | ||
274 | userURL = aCircuit.ServiceURLs["HomeURI"].ToString(); | ||
275 | |||
276 | if (userURL == string.Empty) | ||
277 | { | ||
278 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL"); | ||
279 | return false; | ||
280 | } | ||
281 | |||
282 | Object[] args = new Object[] { userURL }; | ||
283 | IUserAgentService userAgentService = new UserAgentServiceConnector(userURL); //ServerUtils.LoadPlugin<IUserAgentService>(m_AuthDll, args); | ||
284 | if (userAgentService != null) | ||
285 | { | ||
286 | try | ||
287 | { | ||
288 | return userAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID); | ||
289 | } | ||
290 | catch | ||
291 | { | ||
292 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to contact authentication service at {0}", userURL); | ||
293 | return false; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | return false; | ||
298 | } | ||
299 | |||
300 | // Check that the service token was generated for *this* grid. | ||
301 | // If it wasn't then that's a fake agent. | ||
302 | protected bool CheckAddress(string serviceToken) | ||
303 | { | ||
304 | string[] parts = serviceToken.Split(new char[] { ';' }); | ||
305 | if (parts.Length < 2) | ||
306 | return false; | ||
307 | |||
308 | string addressee = parts[0]; | ||
309 | m_log.DebugFormat("[GATEKEEPER SERVICE]: Verifying {0} against {1}", addressee, m_ExternalName); | ||
310 | return (addressee == m_ExternalName); | ||
311 | } | ||
312 | |||
313 | #endregion | ||
314 | |||
315 | |||
316 | #region Misc | ||
317 | |||
318 | |||
319 | #endregion | ||
320 | } | ||
321 | } | ||
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs new file mode 100644 index 0000000..15379b5 --- /dev/null +++ b/OpenSim/Services/HypergridService/UserAgentService.cs | |||
@@ -0,0 +1,217 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Net; | ||
4 | using System.Reflection; | ||
5 | |||
6 | using OpenSim.Framework; | ||
7 | using OpenSim.Services.Connectors.Hypergrid; | ||
8 | using OpenSim.Services.Interfaces; | ||
9 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
10 | using OpenSim.Server.Base; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using log4net; | ||
14 | using Nini.Config; | ||
15 | |||
16 | namespace OpenSim.Services.HypergridService | ||
17 | { | ||
18 | /// <summary> | ||
19 | /// This service is for HG1.5 only, to make up for the fact that clients don't | ||
20 | /// keep any private information in themselves, and that their 'home service' | ||
21 | /// needs to do it for them. | ||
22 | /// Once we have better clients, this shouldn't be needed. | ||
23 | /// </summary> | ||
24 | public class UserAgentService : IUserAgentService | ||
25 | { | ||
26 | private static readonly ILog m_log = | ||
27 | LogManager.GetLogger( | ||
28 | MethodBase.GetCurrentMethod().DeclaringType); | ||
29 | |||
30 | // This will need to go into a DB table | ||
31 | static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>(); | ||
32 | |||
33 | static bool m_Initialized = false; | ||
34 | |||
35 | protected static IPresenceService m_PresenceService; | ||
36 | protected static IGridService m_GridService; | ||
37 | protected static GatekeeperServiceConnector m_GatekeeperConnector; | ||
38 | |||
39 | public UserAgentService(IConfigSource config) | ||
40 | { | ||
41 | if (!m_Initialized) | ||
42 | { | ||
43 | m_log.DebugFormat("[HOME USERS SECURITY]: Starting..."); | ||
44 | |||
45 | IConfig serverConfig = config.Configs["UserAgentService"]; | ||
46 | if (serverConfig == null) | ||
47 | throw new Exception(String.Format("No section UserAgentService in config file")); | ||
48 | |||
49 | string gridService = serverConfig.GetString("GridService", String.Empty); | ||
50 | string presenceService = serverConfig.GetString("PresenceService", String.Empty); | ||
51 | |||
52 | if (gridService == string.Empty || presenceService == string.Empty) | ||
53 | throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function.")); | ||
54 | |||
55 | Object[] args = new Object[] { config }; | ||
56 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
57 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); | ||
58 | m_GatekeeperConnector = new GatekeeperServiceConnector(); | ||
59 | |||
60 | m_Initialized = true; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) | ||
65 | { | ||
66 | position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY; | ||
67 | |||
68 | m_log.DebugFormat("[USER AGENT SERVICE]: Request to get home region of user {0}", userID); | ||
69 | |||
70 | GridRegion home = null; | ||
71 | PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { userID.ToString() }); | ||
72 | if (presences != null && presences.Length > 0) | ||
73 | { | ||
74 | UUID homeID = presences[0].HomeRegionID; | ||
75 | if (homeID != UUID.Zero) | ||
76 | { | ||
77 | home = m_GridService.GetRegionByUUID(UUID.Zero, homeID); | ||
78 | position = presences[0].HomePosition; | ||
79 | lookAt = presences[0].HomeLookAt; | ||
80 | } | ||
81 | if (home == null) | ||
82 | { | ||
83 | List<GridRegion> defs = m_GridService.GetDefaultRegions(UUID.Zero); | ||
84 | if (defs != null && defs.Count > 0) | ||
85 | home = defs[0]; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | return home; | ||
90 | } | ||
91 | |||
92 | public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason) | ||
93 | { | ||
94 | m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} to grid {2}", | ||
95 | agentCircuit.firstname, agentCircuit.lastname, gatekeeper.ExternalHostName +":"+ gatekeeper.HttpPort); | ||
96 | |||
97 | // Take the IP address + port of the gatekeeper (reg) plus the info of finalDestination | ||
98 | GridRegion region = new GridRegion(gatekeeper); | ||
99 | region.RegionName = finalDestination.RegionName; | ||
100 | region.RegionID = finalDestination.RegionID; | ||
101 | region.RegionLocX = finalDestination.RegionLocX; | ||
102 | region.RegionLocY = finalDestination.RegionLocY; | ||
103 | |||
104 | // Generate a new service session | ||
105 | agentCircuit.ServiceSessionID = "http://" + region.ExternalHostName + ":" + region.HttpPort + ";" + UUID.Random(); | ||
106 | TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region); | ||
107 | |||
108 | bool success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out reason); | ||
109 | |||
110 | if (!success) | ||
111 | { | ||
112 | m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}", | ||
113 | agentCircuit.firstname, agentCircuit.lastname, region.ExternalHostName + ":" + region.HttpPort, reason); | ||
114 | |||
115 | // restore the old travel info | ||
116 | lock (m_TravelingAgents) | ||
117 | m_TravelingAgents[agentCircuit.SessionID] = old; | ||
118 | |||
119 | return false; | ||
120 | } | ||
121 | |||
122 | return true; | ||
123 | } | ||
124 | |||
125 | TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region) | ||
126 | { | ||
127 | TravelingAgentInfo travel = new TravelingAgentInfo(); | ||
128 | TravelingAgentInfo old = null; | ||
129 | lock (m_TravelingAgents) | ||
130 | { | ||
131 | if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID)) | ||
132 | { | ||
133 | old = m_TravelingAgents[agentCircuit.SessionID]; | ||
134 | } | ||
135 | |||
136 | m_TravelingAgents[agentCircuit.SessionID] = travel; | ||
137 | } | ||
138 | travel.UserID = agentCircuit.AgentID; | ||
139 | travel.GridExternalName = region.ExternalHostName + ":" + region.HttpPort; | ||
140 | travel.ServiceToken = agentCircuit.ServiceSessionID; | ||
141 | if (old != null) | ||
142 | travel.ClientToken = old.ClientToken; | ||
143 | |||
144 | return old; | ||
145 | } | ||
146 | |||
147 | public void LogoutAgent(UUID userID, UUID sessionID) | ||
148 | { | ||
149 | m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID); | ||
150 | |||
151 | lock (m_TravelingAgents) | ||
152 | { | ||
153 | List<UUID> travels = new List<UUID>(); | ||
154 | foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents) | ||
155 | if (kvp.Value == null) // do some clean up | ||
156 | travels.Add(kvp.Key); | ||
157 | else if (kvp.Value.UserID == userID) | ||
158 | travels.Add(kvp.Key); | ||
159 | foreach (UUID session in travels) | ||
160 | m_TravelingAgents.Remove(session); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | // We need to prevent foreign users with the same UUID as a local user | ||
165 | public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName) | ||
166 | { | ||
167 | if (!m_TravelingAgents.ContainsKey(sessionID)) | ||
168 | return false; | ||
169 | |||
170 | TravelingAgentInfo travel = m_TravelingAgents[sessionID]; | ||
171 | return travel.GridExternalName == thisGridExternalName; | ||
172 | } | ||
173 | |||
174 | public bool VerifyClient(UUID sessionID, string token) | ||
175 | { | ||
176 | return true; | ||
177 | |||
178 | // Commenting this for now until I understand better what part of a sender's | ||
179 | // info stays unchanged throughout a session | ||
180 | // | ||
181 | //if (m_TravelingAgents.ContainsKey(sessionID)) | ||
182 | //{ | ||
183 | // // Aquiles heel. Must trust the first grid upon login | ||
184 | // if (m_TravelingAgents[sessionID].ClientToken == string.Empty) | ||
185 | // { | ||
186 | // m_TravelingAgents[sessionID].ClientToken = token; | ||
187 | // return true; | ||
188 | // } | ||
189 | // return m_TravelingAgents[sessionID].ClientToken == token; | ||
190 | //} | ||
191 | //return false; | ||
192 | } | ||
193 | |||
194 | public bool VerifyAgent(UUID sessionID, string token) | ||
195 | { | ||
196 | if (m_TravelingAgents.ContainsKey(sessionID)) | ||
197 | { | ||
198 | m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken); | ||
199 | return m_TravelingAgents[sessionID].ServiceToken == token; | ||
200 | } | ||
201 | |||
202 | m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID); | ||
203 | |||
204 | return false; | ||
205 | } | ||
206 | |||
207 | } | ||
208 | |||
209 | class TravelingAgentInfo | ||
210 | { | ||
211 | public UUID UserID; | ||
212 | public string GridExternalName = string.Empty; | ||
213 | public string ServiceToken = string.Empty; | ||
214 | public string ClientToken = string.Empty; | ||
215 | } | ||
216 | |||
217 | } | ||
diff --git a/OpenSim/Services/Interfaces/IAuthenticationService.cs b/OpenSim/Services/Interfaces/IAuthenticationService.cs index 9225773..9de261b 100644 --- a/OpenSim/Services/Interfaces/IAuthenticationService.cs +++ b/OpenSim/Services/Interfaces/IAuthenticationService.cs | |||
@@ -66,6 +66,17 @@ namespace OpenSim.Services.Interfaces | |||
66 | bool Release(UUID principalID, string token); | 66 | bool Release(UUID principalID, string token); |
67 | 67 | ||
68 | ////////////////////////////////////////////////////// | 68 | ////////////////////////////////////////////////////// |
69 | // SetPassword for a principal | ||
70 | // | ||
71 | // This method exists for the service, but may or may not | ||
72 | // be served remotely. That is, the authentication | ||
73 | // handlers may not include one handler for this, | ||
74 | // because it's a bit risky. Such handlers require | ||
75 | // authentication/authorization. | ||
76 | // | ||
77 | bool SetPassword(UUID principalID, string passwd); | ||
78 | |||
79 | ////////////////////////////////////////////////////// | ||
69 | // Grid | 80 | // Grid |
70 | // | 81 | // |
71 | // We no longer need a shared secret between grid | 82 | // We no longer need a shared secret between grid |
diff --git a/OpenSim/Services/Interfaces/IAvatarService.cs b/OpenSim/Services/Interfaces/IAvatarService.cs new file mode 100644 index 0000000..de3bcf9 --- /dev/null +++ b/OpenSim/Services/Interfaces/IAvatarService.cs | |||
@@ -0,0 +1,241 @@ | |||
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.Collections.Generic; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | |||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Services.Interfaces | ||
37 | { | ||
38 | public interface IAvatarService | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Called by the login service | ||
42 | /// </summary> | ||
43 | /// <param name="userID"></param> | ||
44 | /// <returns></returns> | ||
45 | AvatarData GetAvatar(UUID userID); | ||
46 | |||
47 | /// <summary> | ||
48 | /// Called by everyone who can change the avatar data (so, regions) | ||
49 | /// </summary> | ||
50 | /// <param name="userID"></param> | ||
51 | /// <param name="avatar"></param> | ||
52 | /// <returns></returns> | ||
53 | bool SetAvatar(UUID userID, AvatarData avatar); | ||
54 | |||
55 | /// <summary> | ||
56 | /// Not sure if it's needed | ||
57 | /// </summary> | ||
58 | /// <param name="userID"></param> | ||
59 | /// <returns></returns> | ||
60 | bool ResetAvatar(UUID userID); | ||
61 | |||
62 | /// <summary> | ||
63 | /// These methods raison d'etre: | ||
64 | /// No need to send the entire avatar data (SetAvatar) for changing attachments | ||
65 | /// </summary> | ||
66 | /// <param name="userID"></param> | ||
67 | /// <param name="attach"></param> | ||
68 | /// <returns></returns> | ||
69 | bool SetItems(UUID userID, string[] names, string[] values); | ||
70 | bool RemoveItems(UUID userID, string[] names); | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Each region/client that uses avatars will have a data structure | ||
75 | /// of this type representing the avatars. | ||
76 | /// </summary> | ||
77 | public class AvatarData | ||
78 | { | ||
79 | // This pretty much determines which name/value pairs will be | ||
80 | // present below. The name/value pair describe a part of | ||
81 | // the avatar. For SL avatars, these would be "shape", "texture1", | ||
82 | // etc. For other avatars, they might be "mesh", "skin", etc. | ||
83 | // The value portion is a URL that is expected to resolve to an | ||
84 | // asset of the type required by the handler for that field. | ||
85 | // It is required that regions can access these URLs. Allowing | ||
86 | // direct access by a viewer is not required, and, if provided, | ||
87 | // may be read-only. A "naked" UUID can be used to refer to an | ||
88 | // asset int he current region's asset service, which is not | ||
89 | // portable, but allows legacy appearance to continue to | ||
90 | // function. Closed, LL-based grids will never need URLs here. | ||
91 | |||
92 | public int AvatarType; | ||
93 | public Dictionary<string,string> Data; | ||
94 | |||
95 | public AvatarData() | ||
96 | { | ||
97 | } | ||
98 | |||
99 | public AvatarData(Dictionary<string, object> kvp) | ||
100 | { | ||
101 | Data = new Dictionary<string, string>(); | ||
102 | |||
103 | if (kvp.ContainsKey("AvatarType")) | ||
104 | Int32.TryParse(kvp["AvatarType"].ToString(), out AvatarType); | ||
105 | |||
106 | foreach (KeyValuePair<string, object> _kvp in kvp) | ||
107 | { | ||
108 | if (_kvp.Value != null) | ||
109 | Data[_kvp.Key] = _kvp.Value.ToString(); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// </summary> | ||
115 | /// <returns></returns> | ||
116 | public Dictionary<string, object> ToKeyValuePairs() | ||
117 | { | ||
118 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
119 | |||
120 | result["AvatarType"] = AvatarType.ToString(); | ||
121 | foreach (KeyValuePair<string, string> _kvp in Data) | ||
122 | { | ||
123 | if (_kvp.Value != null) | ||
124 | result[_kvp.Key] = _kvp.Value; | ||
125 | } | ||
126 | return result; | ||
127 | } | ||
128 | |||
129 | public AvatarData(AvatarAppearance appearance) | ||
130 | { | ||
131 | AvatarType = 1; // SL avatars | ||
132 | Data = new Dictionary<string, string>(); | ||
133 | |||
134 | Data["Serial"] = appearance.Serial.ToString(); | ||
135 | // Wearables | ||
136 | Data["AvatarHeight"] = appearance.AvatarHeight.ToString(); | ||
137 | Data["BodyItem"] = appearance.BodyItem.ToString(); | ||
138 | Data["EyesItem"] = appearance.EyesItem.ToString(); | ||
139 | Data["GlovesItem"] = appearance.GlovesItem.ToString(); | ||
140 | Data["HairItem"] = appearance.HairItem.ToString(); | ||
141 | Data["JacketItem"] = appearance.JacketItem.ToString(); | ||
142 | Data["PantsItem"] = appearance.PantsItem.ToString(); | ||
143 | Data["ShirtItem"] = appearance.ShirtItem.ToString(); | ||
144 | Data["ShoesItem"] = appearance.ShoesItem.ToString(); | ||
145 | Data["SkinItem"] = appearance.SkinItem.ToString(); | ||
146 | Data["SkirtItem"] = appearance.SkirtItem.ToString(); | ||
147 | Data["SocksItem"] = appearance.SocksItem.ToString(); | ||
148 | Data["UnderPantsItem"] = appearance.UnderPantsItem.ToString(); | ||
149 | Data["UnderShirtItem"] = appearance.UnderShirtItem.ToString(); | ||
150 | |||
151 | Data["BodyAsset"] = appearance.BodyAsset.ToString(); | ||
152 | Data["EyesAsset"] = appearance.EyesAsset.ToString(); | ||
153 | Data["GlovesAsset"] = appearance.GlovesAsset.ToString(); | ||
154 | Data["HairAsset"] = appearance.HairAsset.ToString(); | ||
155 | Data["JacketAsset"] = appearance.JacketAsset.ToString(); | ||
156 | Data["PantsAsset"] = appearance.PantsAsset.ToString(); | ||
157 | Data["ShirtAsset"] = appearance.ShirtAsset.ToString(); | ||
158 | Data["ShoesAsset"] = appearance.ShoesAsset.ToString(); | ||
159 | Data["SkinAsset"] = appearance.SkinAsset.ToString(); | ||
160 | Data["SkirtAsset"] = appearance.SkirtAsset.ToString(); | ||
161 | Data["SocksAsset"] = appearance.SocksAsset.ToString(); | ||
162 | Data["UnderPantsAsset"] = appearance.UnderPantsAsset.ToString(); | ||
163 | Data["UnderShirtAsset"] = appearance.UnderShirtAsset.ToString(); | ||
164 | |||
165 | // Attachments | ||
166 | Hashtable attachs = appearance.GetAttachments(); | ||
167 | if (attachs != null) | ||
168 | foreach (DictionaryEntry dentry in attachs) | ||
169 | { | ||
170 | if (dentry.Value != null) | ||
171 | { | ||
172 | Hashtable tab = (Hashtable)dentry.Value; | ||
173 | if (tab.ContainsKey("item") && tab["item"] != null) | ||
174 | Data["_ap_" + dentry.Key] = tab["item"].ToString(); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | public AvatarAppearance ToAvatarAppearance(UUID owner) | ||
180 | { | ||
181 | AvatarAppearance appearance = new AvatarAppearance(owner); | ||
182 | try | ||
183 | { | ||
184 | appearance.Serial = Int32.Parse(Data["Serial"]); | ||
185 | |||
186 | // Wearables | ||
187 | appearance.BodyItem = UUID.Parse(Data["BodyItem"]); | ||
188 | appearance.EyesItem = UUID.Parse(Data["EyesItem"]); | ||
189 | appearance.GlovesItem = UUID.Parse(Data["GlovesItem"]); | ||
190 | appearance.HairItem = UUID.Parse(Data["HairItem"]); | ||
191 | appearance.JacketItem = UUID.Parse(Data["JacketItem"]); | ||
192 | appearance.PantsItem = UUID.Parse(Data["PantsItem"]); | ||
193 | appearance.ShirtItem = UUID.Parse(Data["ShirtItem"]); | ||
194 | appearance.ShoesItem = UUID.Parse(Data["ShoesItem"]); | ||
195 | appearance.SkinItem = UUID.Parse(Data["SkinItem"]); | ||
196 | appearance.SkirtItem = UUID.Parse(Data["SkirtItem"]); | ||
197 | appearance.SocksItem = UUID.Parse(Data["SocksItem"]); | ||
198 | appearance.UnderPantsItem = UUID.Parse(Data["UnderPantsItem"]); | ||
199 | appearance.UnderShirtItem = UUID.Parse(Data["UnderShirtItem"]); | ||
200 | |||
201 | appearance.BodyAsset = UUID.Parse(Data["BodyAsset"]); | ||
202 | appearance.EyesAsset = UUID.Parse(Data["EyesAsset"]); | ||
203 | appearance.GlovesAsset = UUID.Parse(Data["GlovesAsset"]); | ||
204 | appearance.HairAsset = UUID.Parse(Data["HairAsset"]); | ||
205 | appearance.JacketAsset = UUID.Parse(Data["JacketAsset"]); | ||
206 | appearance.PantsAsset = UUID.Parse(Data["PantsAsset"]); | ||
207 | appearance.ShirtAsset = UUID.Parse(Data["ShirtAsset"]); | ||
208 | appearance.ShoesAsset = UUID.Parse(Data["ShoesAsset"]); | ||
209 | appearance.SkinAsset = UUID.Parse(Data["SkinAsset"]); | ||
210 | appearance.SkirtAsset = UUID.Parse(Data["SkirtAsset"]); | ||
211 | appearance.SocksAsset = UUID.Parse(Data["SocksAsset"]); | ||
212 | appearance.UnderPantsAsset = UUID.Parse(Data["UnderPantsAsset"]); | ||
213 | appearance.UnderShirtAsset = UUID.Parse(Data["UnderShirtAsset"]); | ||
214 | |||
215 | // Attachments | ||
216 | Dictionary<string, string> attchs = new Dictionary<string, string>(); | ||
217 | foreach (KeyValuePair<string, string> _kvp in Data) | ||
218 | if (_kvp.Key.StartsWith("_ap_")) | ||
219 | attchs[_kvp.Key] = _kvp.Value; | ||
220 | Hashtable aaAttachs = new Hashtable(); | ||
221 | foreach (KeyValuePair<string, string> _kvp in attchs) | ||
222 | { | ||
223 | string pointStr = _kvp.Key.Substring(4); | ||
224 | int point = 0; | ||
225 | if (!Int32.TryParse(pointStr, out point)) | ||
226 | continue; | ||
227 | Hashtable tmp = new Hashtable(); | ||
228 | UUID uuid = UUID.Zero; | ||
229 | UUID.TryParse(_kvp.Value, out uuid); | ||
230 | tmp["item"] = uuid; | ||
231 | tmp["asset"] = UUID.Zero.ToString(); | ||
232 | aaAttachs[point] = tmp; | ||
233 | } | ||
234 | appearance.SetAttachments(aaAttachs); | ||
235 | } | ||
236 | catch { } | ||
237 | |||
238 | return appearance; | ||
239 | } | ||
240 | } | ||
241 | } | ||
diff --git a/OpenSim/Services/Interfaces/IFriendsService.cs b/OpenSim/Services/Interfaces/IFriendsService.cs new file mode 100644 index 0000000..2692c48 --- /dev/null +++ b/OpenSim/Services/Interfaces/IFriendsService.cs | |||
@@ -0,0 +1,80 @@ | |||
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 OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | using System.Collections.Generic; | ||
32 | |||
33 | namespace OpenSim.Services.Interfaces | ||
34 | { | ||
35 | public class FriendInfo | ||
36 | { | ||
37 | public UUID PrincipalID; | ||
38 | public string Friend; | ||
39 | public int MyFlags; | ||
40 | public int TheirFlags; | ||
41 | |||
42 | public FriendInfo() | ||
43 | { | ||
44 | } | ||
45 | |||
46 | public FriendInfo(Dictionary<string, object> kvp) | ||
47 | { | ||
48 | PrincipalID = UUID.Zero; | ||
49 | if (kvp.ContainsKey("PrincipalID") && kvp["PrincipalID"] != null) | ||
50 | UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID); | ||
51 | Friend = string.Empty; | ||
52 | if (kvp.ContainsKey("Friend") && kvp["Friend"] != null) | ||
53 | Friend = kvp["Friend"].ToString(); | ||
54 | MyFlags = 0; | ||
55 | if (kvp.ContainsKey("MyFlags") && kvp["MyFlags"] != null) | ||
56 | Int32.TryParse(kvp["MyFlags"].ToString(), out MyFlags); | ||
57 | TheirFlags = 0; | ||
58 | if (kvp.ContainsKey("TheirFlags") && kvp["TheirFlags"] != null) | ||
59 | Int32.TryParse(kvp["TheirFlags"].ToString(), out TheirFlags); | ||
60 | } | ||
61 | |||
62 | public Dictionary<string, object> ToKeyValuePairs() | ||
63 | { | ||
64 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
65 | result["PricipalID"] = PrincipalID.ToString(); | ||
66 | result["Friend"] = Friend; | ||
67 | result["MyFlags"] = MyFlags.ToString(); | ||
68 | result["TheirFlags"] = TheirFlags.ToString(); | ||
69 | |||
70 | return result; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | public interface IFriendsService | ||
75 | { | ||
76 | FriendInfo[] GetFriends(UUID PrincipalID); | ||
77 | bool StoreFriend(UUID PrincipalID, string Friend, int flags); | ||
78 | bool Delete(UUID PrincipalID, string Friend); | ||
79 | } | ||
80 | } | ||
diff --git a/OpenSim/Services/Interfaces/IGatekeeperService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs new file mode 100644 index 0000000..ca7b9b3 --- /dev/null +++ b/OpenSim/Services/Interfaces/IGatekeeperService.cs | |||
@@ -0,0 +1,59 @@ | |||
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.Net; | ||
30 | using System.Collections.Generic; | ||
31 | |||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | namespace OpenSim.Services.Interfaces | ||
36 | { | ||
37 | public interface IGatekeeperService | ||
38 | { | ||
39 | bool LinkRegion(string regionDescriptor, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason); | ||
40 | GridRegion GetHyperlinkRegion(UUID regionID); | ||
41 | |||
42 | bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason); | ||
43 | |||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// HG1.5 only | ||
48 | /// </summary> | ||
49 | public interface IUserAgentService | ||
50 | { | ||
51 | bool LoginAgentToGrid(AgentCircuitData agent, GridRegion gatekeeper, GridRegion finalDestination, out string reason); | ||
52 | void LogoutAgent(UUID userID, UUID sessionID); | ||
53 | GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); | ||
54 | |||
55 | bool AgentIsComingHome(UUID sessionID, string thisGridExternalName); | ||
56 | bool VerifyAgent(UUID sessionID, string token); | ||
57 | bool VerifyClient(UUID sessionID, string token); | ||
58 | } | ||
59 | } | ||
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs index 5135f6d..e55b633 100644 --- a/OpenSim/Services/Interfaces/IGridService.cs +++ b/OpenSim/Services/Interfaces/IGridService.cs | |||
@@ -90,6 +90,10 @@ namespace OpenSim.Services.Interfaces | |||
90 | 90 | ||
91 | List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); | 91 | List<GridRegion> GetRegionRange(UUID scopeID, int xmin, int xmax, int ymin, int ymax); |
92 | 92 | ||
93 | List<GridRegion> GetDefaultRegions(UUID scopeID); | ||
94 | List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y); | ||
95 | |||
96 | int GetRegionFlags(UUID scopeID, UUID regionID); | ||
93 | } | 97 | } |
94 | 98 | ||
95 | public class GridRegion | 99 | public class GridRegion |
@@ -154,7 +158,8 @@ namespace OpenSim.Services.Interfaces | |||
154 | public UUID TerrainImage = UUID.Zero; | 158 | public UUID TerrainImage = UUID.Zero; |
155 | public byte Access; | 159 | public byte Access; |
156 | public int Maturity; | 160 | public int Maturity; |
157 | public string RegionSecret; | 161 | public string RegionSecret = string.Empty; |
162 | public string Token = string.Empty; | ||
158 | 163 | ||
159 | public GridRegion() | 164 | public GridRegion() |
160 | { | 165 | { |
@@ -200,12 +205,6 @@ namespace OpenSim.Services.Interfaces | |||
200 | Maturity = ConvertFrom.RegionSettings.Maturity; | 205 | Maturity = ConvertFrom.RegionSettings.Maturity; |
201 | RegionSecret = ConvertFrom.regionSecret; | 206 | RegionSecret = ConvertFrom.regionSecret; |
202 | EstateOwner = ConvertFrom.EstateSettings.EstateOwner; | 207 | EstateOwner = ConvertFrom.EstateSettings.EstateOwner; |
203 | if (EstateOwner == UUID.Zero) | ||
204 | { | ||
205 | EstateOwner = ConvertFrom.MasterAvatarAssignedUUID; | ||
206 | ConvertFrom.EstateSettings.EstateOwner = EstateOwner; | ||
207 | ConvertFrom.EstateSettings.Save(); | ||
208 | } | ||
209 | } | 208 | } |
210 | 209 | ||
211 | public GridRegion(GridRegion ConvertFrom) | 210 | public GridRegion(GridRegion ConvertFrom) |
@@ -267,8 +266,6 @@ namespace OpenSim.Services.Interfaces | |||
267 | 266 | ||
268 | return new IPEndPoint(ia, m_internalEndPoint.Port); | 267 | return new IPEndPoint(ia, m_internalEndPoint.Port); |
269 | } | 268 | } |
270 | |||
271 | set { m_externalHostName = value.ToString(); } | ||
272 | } | 269 | } |
273 | 270 | ||
274 | public string ExternalHostName | 271 | public string ExternalHostName |
@@ -288,11 +285,6 @@ namespace OpenSim.Services.Interfaces | |||
288 | get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); } | 285 | get { return Util.UIntsToLong((uint)RegionLocX, (uint)RegionLocY); } |
289 | } | 286 | } |
290 | 287 | ||
291 | public int getInternalEndPointPort() | ||
292 | { | ||
293 | return m_internalEndPoint.Port; | ||
294 | } | ||
295 | |||
296 | public Dictionary<string, object> ToKeyValuePairs() | 288 | public Dictionary<string, object> ToKeyValuePairs() |
297 | { | 289 | { |
298 | Dictionary<string, object> kvp = new Dictionary<string, object>(); | 290 | Dictionary<string, object> kvp = new Dictionary<string, object>(); |
@@ -308,6 +300,7 @@ namespace OpenSim.Services.Interfaces | |||
308 | kvp["access"] = Access.ToString(); | 300 | kvp["access"] = Access.ToString(); |
309 | kvp["regionSecret"] = RegionSecret; | 301 | kvp["regionSecret"] = RegionSecret; |
310 | kvp["owner_uuid"] = EstateOwner.ToString(); | 302 | kvp["owner_uuid"] = EstateOwner.ToString(); |
303 | kvp["Token"] = Token.ToString(); | ||
311 | // Maturity doesn't seem to exist in the DB | 304 | // Maturity doesn't seem to exist in the DB |
312 | return kvp; | 305 | return kvp; |
313 | } | 306 | } |
@@ -365,6 +358,9 @@ namespace OpenSim.Services.Interfaces | |||
365 | if (kvp.ContainsKey("owner_uuid")) | 358 | if (kvp.ContainsKey("owner_uuid")) |
366 | EstateOwner = new UUID(kvp["owner_uuid"].ToString()); | 359 | EstateOwner = new UUID(kvp["owner_uuid"].ToString()); |
367 | 360 | ||
361 | if (kvp.ContainsKey("Token")) | ||
362 | Token = kvp["Token"].ToString(); | ||
363 | |||
368 | } | 364 | } |
369 | } | 365 | } |
370 | 366 | ||
diff --git a/OpenSim/Framework/Communications/IMessagingService.cs b/OpenSim/Services/Interfaces/ILibraryService.cs index 5d65f19..861cf0e 100644 --- a/OpenSim/Framework/Communications/IMessagingService.cs +++ b/OpenSim/Services/Interfaces/ILibraryService.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -25,13 +25,19 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | |||
31 | using OpenSim.Framework; | ||
29 | using OpenMetaverse; | 32 | using OpenMetaverse; |
30 | 33 | ||
31 | namespace OpenSim.Framework.Communications | 34 | namespace OpenSim.Services.Interfaces |
32 | { | 35 | { |
33 | public interface IMessagingService | 36 | public interface ILibraryService |
34 | { | 37 | { |
35 | Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids); | 38 | InventoryFolderImpl LibraryRootFolder { get; } |
39 | |||
40 | Dictionary<UUID, InventoryFolderImpl> GetAllFolders(); | ||
36 | } | 41 | } |
42 | |||
37 | } | 43 | } |
diff --git a/OpenSim/Grid/Framework/IMessagingServerDiscovery.cs b/OpenSim/Services/Interfaces/ILoginService.cs index c996f4f..24bf342 100644 --- a/OpenSim/Grid/Framework/IMessagingServerDiscovery.cs +++ b/OpenSim/Services/Interfaces/ILoginService.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -26,15 +26,28 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | ||
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
30 | using OpenSim.Framework.Servers; | 31 | using System.Net; |
31 | 32 | ||
32 | namespace OpenSim.Grid.Framework | 33 | using OpenMetaverse.StructuredData; |
34 | |||
35 | namespace OpenSim.Services.Interfaces | ||
33 | { | 36 | { |
34 | public interface IMessagingServerDiscovery | 37 | public abstract class LoginResponse |
35 | { | 38 | { |
36 | List<MessageServerInfo> GetMessageServersList(); | 39 | public abstract Hashtable ToHashtable(); |
37 | void RegisterMessageServer(MessageServerInfo m); | 40 | public abstract OSD ToOSDMap(); |
38 | void DeRegisterMessageServer(MessageServerInfo m); | ||
39 | } | 41 | } |
42 | |||
43 | public abstract class FailedLoginResponse : LoginResponse | ||
44 | { | ||
45 | } | ||
46 | |||
47 | public interface ILoginService | ||
48 | { | ||
49 | LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, IPEndPoint clientIP); | ||
50 | } | ||
51 | |||
52 | |||
40 | } | 53 | } |
diff --git a/OpenSim/Services/Interfaces/IPresenceService.cs b/OpenSim/Services/Interfaces/IPresenceService.cs index aa1c5bf..b4c1859 100644 --- a/OpenSim/Services/Interfaces/IPresenceService.cs +++ b/OpenSim/Services/Interfaces/IPresenceService.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using OpenSim.Framework; | 29 | using OpenSim.Framework; |
29 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
30 | using OpenMetaverse; | 31 | using OpenMetaverse; |
@@ -33,13 +34,94 @@ namespace OpenSim.Services.Interfaces | |||
33 | { | 34 | { |
34 | public class PresenceInfo | 35 | public class PresenceInfo |
35 | { | 36 | { |
36 | public UUID PrincipalID; | 37 | public string UserID; |
37 | public UUID RegionID; | 38 | public UUID RegionID; |
38 | public Dictionary<string, string> Data; | 39 | public bool Online; |
40 | public DateTime Login; | ||
41 | public DateTime Logout; | ||
42 | public Vector3 Position; | ||
43 | public Vector3 LookAt; | ||
44 | public UUID HomeRegionID; | ||
45 | public Vector3 HomePosition; | ||
46 | public Vector3 HomeLookAt; | ||
47 | |||
48 | public PresenceInfo() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | public PresenceInfo(Dictionary<string, object> kvp) | ||
53 | { | ||
54 | if (kvp.ContainsKey("UserID")) | ||
55 | UserID = kvp["UserID"].ToString(); | ||
56 | if (kvp.ContainsKey("RegionID")) | ||
57 | UUID.TryParse(kvp["RegionID"].ToString(), out RegionID); | ||
58 | if (kvp.ContainsKey("login")) | ||
59 | DateTime.TryParse(kvp["login"].ToString(), out Login); | ||
60 | if (kvp.ContainsKey("logout")) | ||
61 | DateTime.TryParse(kvp["logout"].ToString(), out Logout); | ||
62 | if (kvp.ContainsKey("lookAt")) | ||
63 | Vector3.TryParse(kvp["lookAt"].ToString(), out LookAt); | ||
64 | if (kvp.ContainsKey("online")) | ||
65 | Boolean.TryParse(kvp["online"].ToString(), out Online); | ||
66 | if (kvp.ContainsKey("position")) | ||
67 | Vector3.TryParse(kvp["position"].ToString(), out Position); | ||
68 | if (kvp.ContainsKey("HomeRegionID")) | ||
69 | UUID.TryParse(kvp["HomeRegionID"].ToString(), out HomeRegionID); | ||
70 | if (kvp.ContainsKey("HomePosition")) | ||
71 | Vector3.TryParse(kvp["HomePosition"].ToString(), out HomePosition); | ||
72 | if (kvp.ContainsKey("HomeLookAt")) | ||
73 | Vector3.TryParse(kvp["HomeLookAt"].ToString(), out HomeLookAt); | ||
74 | |||
75 | } | ||
76 | |||
77 | public Dictionary<string, object> ToKeyValuePairs() | ||
78 | { | ||
79 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
80 | result["UserID"] = UserID; | ||
81 | result["RegionID"] = RegionID.ToString(); | ||
82 | result["online"] = Online.ToString(); | ||
83 | result["login"] = Login.ToString(); | ||
84 | result["logout"] = Logout.ToString(); | ||
85 | result["position"] = Position.ToString(); | ||
86 | result["lookAt"] = LookAt.ToString(); | ||
87 | result["HomeRegionID"] = HomeRegionID.ToString(); | ||
88 | result["HomePosition"] = HomePosition.ToString(); | ||
89 | result["HomeLookAt"] = HomeLookAt.ToString(); | ||
90 | |||
91 | return result; | ||
92 | } | ||
93 | |||
94 | public static PresenceInfo[] GetOnlinePresences(PresenceInfo[] pinfos) | ||
95 | { | ||
96 | if (pinfos == null) | ||
97 | return null; | ||
98 | |||
99 | List<PresenceInfo> lst = new List<PresenceInfo>(pinfos); | ||
100 | lst = lst.FindAll(delegate(PresenceInfo each) { return each.Online; }); | ||
101 | |||
102 | return lst.ToArray(); | ||
103 | } | ||
104 | |||
105 | public static PresenceInfo GetOnlinePresence(PresenceInfo[] pinfos) | ||
106 | { | ||
107 | pinfos = GetOnlinePresences(pinfos); | ||
108 | if (pinfos != null && pinfos.Length >= 1) | ||
109 | return pinfos[0]; | ||
110 | |||
111 | return null; | ||
112 | } | ||
39 | } | 113 | } |
40 | 114 | ||
41 | public interface IPresenceService | 115 | public interface IPresenceService |
42 | { | 116 | { |
43 | bool Report(PresenceInfo presence); | 117 | bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID); |
118 | bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookAt); | ||
119 | bool LogoutRegionAgents(UUID regionID); | ||
120 | |||
121 | bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); | ||
122 | bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); | ||
123 | |||
124 | PresenceInfo GetAgent(UUID sessionID); | ||
125 | PresenceInfo[] GetAgents(string[] userIDs); | ||
44 | } | 126 | } |
45 | } | 127 | } |
diff --git a/OpenSim/Services/Interfaces/ISimulationService.cs b/OpenSim/Services/Interfaces/ISimulationService.cs index a169ab7..ec24d90 100644 --- a/OpenSim/Services/Interfaces/ISimulationService.cs +++ b/OpenSim/Services/Interfaces/ISimulationService.cs | |||
@@ -29,13 +29,17 @@ using System; | |||
29 | using OpenSim.Framework; | 29 | using OpenSim.Framework; |
30 | using OpenMetaverse; | 30 | using OpenMetaverse; |
31 | 31 | ||
32 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
33 | |||
32 | namespace OpenSim.Services.Interfaces | 34 | namespace OpenSim.Services.Interfaces |
33 | { | 35 | { |
34 | public interface ISimulationService | 36 | public interface ISimulationService |
35 | { | 37 | { |
38 | IScene GetScene(ulong regionHandle); | ||
39 | |||
36 | #region Agents | 40 | #region Agents |
37 | 41 | ||
38 | bool CreateAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason); | 42 | bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason); |
39 | 43 | ||
40 | /// <summary> | 44 | /// <summary> |
41 | /// Full child agent update. | 45 | /// Full child agent update. |
@@ -43,7 +47,7 @@ namespace OpenSim.Services.Interfaces | |||
43 | /// <param name="regionHandle"></param> | 47 | /// <param name="regionHandle"></param> |
44 | /// <param name="data"></param> | 48 | /// <param name="data"></param> |
45 | /// <returns></returns> | 49 | /// <returns></returns> |
46 | bool UpdateAgent(ulong regionHandle, AgentData data); | 50 | bool UpdateAgent(GridRegion destination, AgentData data); |
47 | 51 | ||
48 | /// <summary> | 52 | /// <summary> |
49 | /// Short child agent update, mostly for position. | 53 | /// Short child agent update, mostly for position. |
@@ -51,9 +55,9 @@ namespace OpenSim.Services.Interfaces | |||
51 | /// <param name="regionHandle"></param> | 55 | /// <param name="regionHandle"></param> |
52 | /// <param name="data"></param> | 56 | /// <param name="data"></param> |
53 | /// <returns></returns> | 57 | /// <returns></returns> |
54 | bool UpdateAgent(ulong regionHandle, AgentPosition data); | 58 | bool UpdateAgent(GridRegion destination, AgentPosition data); |
55 | 59 | ||
56 | bool RetrieveAgent(ulong regionHandle, UUID id, out IAgentData agent); | 60 | bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent); |
57 | 61 | ||
58 | /// <summary> | 62 | /// <summary> |
59 | /// Message from receiving region to departing region, telling it got contacted by the client. | 63 | /// Message from receiving region to departing region, telling it got contacted by the client. |
@@ -63,7 +67,7 @@ namespace OpenSim.Services.Interfaces | |||
63 | /// <param name="id"></param> | 67 | /// <param name="id"></param> |
64 | /// <param name="uri"></param> | 68 | /// <param name="uri"></param> |
65 | /// <returns></returns> | 69 | /// <returns></returns> |
66 | bool ReleaseAgent(ulong regionHandle, UUID id, string uri); | 70 | bool ReleaseAgent(UUID originRegion, UUID id, string uri); |
67 | 71 | ||
68 | /// <summary> | 72 | /// <summary> |
69 | /// Close agent. | 73 | /// Close agent. |
@@ -71,7 +75,7 @@ namespace OpenSim.Services.Interfaces | |||
71 | /// <param name="regionHandle"></param> | 75 | /// <param name="regionHandle"></param> |
72 | /// <param name="id"></param> | 76 | /// <param name="id"></param> |
73 | /// <returns></returns> | 77 | /// <returns></returns> |
74 | bool CloseAgent(ulong regionHandle, UUID id); | 78 | bool CloseAgent(GridRegion destination, UUID id); |
75 | 79 | ||
76 | #endregion Agents | 80 | #endregion Agents |
77 | 81 | ||
@@ -84,7 +88,7 @@ namespace OpenSim.Services.Interfaces | |||
84 | /// <param name="sog"></param> | 88 | /// <param name="sog"></param> |
85 | /// <param name="isLocalCall"></param> | 89 | /// <param name="isLocalCall"></param> |
86 | /// <returns></returns> | 90 | /// <returns></returns> |
87 | bool CreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall); | 91 | bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall); |
88 | 92 | ||
89 | /// <summary> | 93 | /// <summary> |
90 | /// Create an object from the user's inventory in the destination region. | 94 | /// Create an object from the user's inventory in the destination region. |
@@ -94,15 +98,9 @@ namespace OpenSim.Services.Interfaces | |||
94 | /// <param name="userID"></param> | 98 | /// <param name="userID"></param> |
95 | /// <param name="itemID"></param> | 99 | /// <param name="itemID"></param> |
96 | /// <returns></returns> | 100 | /// <returns></returns> |
97 | bool CreateObject(ulong regionHandle, UUID userID, UUID itemID); | 101 | bool CreateObject(GridRegion destination, UUID userID, UUID itemID); |
98 | 102 | ||
99 | #endregion Objects | 103 | #endregion Objects |
100 | 104 | ||
101 | #region Regions | ||
102 | |||
103 | bool HelloNeighbour(ulong regionHandle, RegionInfo thisRegion); | ||
104 | |||
105 | #endregion Regions | ||
106 | |||
107 | } | 105 | } |
108 | } | 106 | } |
diff --git a/OpenSim/Services/Interfaces/IUserAccountService.cs b/OpenSim/Services/Interfaces/IUserAccountService.cs new file mode 100644 index 0000000..3dacf53 --- /dev/null +++ b/OpenSim/Services/Interfaces/IUserAccountService.cs | |||
@@ -0,0 +1,153 @@ | |||
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 OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Services.Interfaces | ||
33 | { | ||
34 | public class UserAccount | ||
35 | { | ||
36 | public UserAccount() | ||
37 | { | ||
38 | } | ||
39 | |||
40 | public UserAccount(UUID principalID) | ||
41 | { | ||
42 | PrincipalID = principalID; | ||
43 | } | ||
44 | |||
45 | public UserAccount(UUID scopeID, string firstName, string lastName, string email) | ||
46 | { | ||
47 | PrincipalID = UUID.Random(); | ||
48 | ScopeID = scopeID; | ||
49 | FirstName = firstName; | ||
50 | LastName = lastName; | ||
51 | Email = email; | ||
52 | ServiceURLs = new Dictionary<string, object>(); | ||
53 | // Created = ??? | ||
54 | } | ||
55 | |||
56 | public string FirstName; | ||
57 | public string LastName; | ||
58 | public string Email; | ||
59 | public UUID PrincipalID; | ||
60 | public UUID ScopeID; | ||
61 | public int UserLevel; | ||
62 | public int UserFlags; | ||
63 | public string UserTitle; | ||
64 | |||
65 | public Dictionary<string, object> ServiceURLs; | ||
66 | |||
67 | public int Created; | ||
68 | |||
69 | public string Name | ||
70 | { | ||
71 | get { return FirstName + " " + LastName; } | ||
72 | } | ||
73 | |||
74 | public UserAccount(Dictionary<string, object> kvp) | ||
75 | { | ||
76 | if (kvp.ContainsKey("FirstName")) | ||
77 | FirstName = kvp["FirstName"].ToString(); | ||
78 | if (kvp.ContainsKey("LastName")) | ||
79 | LastName = kvp["LastName"].ToString(); | ||
80 | if (kvp.ContainsKey("Email")) | ||
81 | Email = kvp["Email"].ToString(); | ||
82 | if (kvp.ContainsKey("PrincipalID")) | ||
83 | UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID); | ||
84 | if (kvp.ContainsKey("ScopeID")) | ||
85 | UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID); | ||
86 | if (kvp.ContainsKey("UserLevel")) | ||
87 | Convert.ToInt32(kvp["UserLevel"].ToString()); | ||
88 | if (kvp.ContainsKey("UserFlags")) | ||
89 | Convert.ToInt32(kvp["UserFlags"].ToString()); | ||
90 | if (kvp.ContainsKey("UserTitle")) | ||
91 | Email = kvp["UserTitle"].ToString(); | ||
92 | |||
93 | if (kvp.ContainsKey("Created")) | ||
94 | Convert.ToInt32(kvp["Created"].ToString()); | ||
95 | if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null) | ||
96 | { | ||
97 | ServiceURLs = new Dictionary<string, object>(); | ||
98 | string str = kvp["ServiceURLs"].ToString(); | ||
99 | if (str != string.Empty) | ||
100 | { | ||
101 | string[] parts = str.Split(new char[] { ';' }); | ||
102 | Dictionary<string, object> dic = new Dictionary<string, object>(); | ||
103 | foreach (string s in parts) | ||
104 | { | ||
105 | string[] parts2 = s.Split(new char[] { '*' }); | ||
106 | if (parts2.Length == 2) | ||
107 | ServiceURLs[parts2[0]] = parts2[1]; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public Dictionary<string, object> ToKeyValuePairs() | ||
114 | { | ||
115 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
116 | result["FirstName"] = FirstName; | ||
117 | result["LastName"] = LastName; | ||
118 | result["Email"] = Email; | ||
119 | result["PrincipalID"] = PrincipalID.ToString(); | ||
120 | result["ScopeID"] = ScopeID.ToString(); | ||
121 | result["Created"] = Created.ToString(); | ||
122 | result["UserLevel"] = UserLevel.ToString(); | ||
123 | result["UserFlags"] = UserFlags.ToString(); | ||
124 | result["UserTitle"] = UserTitle; | ||
125 | |||
126 | string str = string.Empty; | ||
127 | foreach (KeyValuePair<string, object> kvp in ServiceURLs) | ||
128 | { | ||
129 | str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";"; | ||
130 | } | ||
131 | result["ServiceURLs"] = str; | ||
132 | |||
133 | return result; | ||
134 | } | ||
135 | |||
136 | }; | ||
137 | |||
138 | public interface IUserAccountService | ||
139 | { | ||
140 | UserAccount GetUserAccount(UUID scopeID, UUID userID); | ||
141 | UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName); | ||
142 | UserAccount GetUserAccount(UUID scopeID, string Email); | ||
143 | // Returns the list of avatars that matches both the search | ||
144 | // criterion and the scope ID passed | ||
145 | // | ||
146 | List<UserAccount> GetUserAccounts(UUID scopeID, string query); | ||
147 | |||
148 | // Store the data given, wich replaces the sotred data, therefore | ||
149 | // must be complete. | ||
150 | // | ||
151 | bool StoreUserAccount(UserAccount data); | ||
152 | } | ||
153 | } | ||
diff --git a/OpenSim/Services/Interfaces/IUserService.cs b/OpenSim/Services/Interfaces/IUserService.cs deleted file mode 100644 index 92bd8ef..0000000 --- a/OpenSim/Services/Interfaces/IUserService.cs +++ /dev/null | |||
@@ -1,103 +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.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Services.Interfaces | ||
32 | { | ||
33 | public class UserAccount | ||
34 | { | ||
35 | public UserAccount() | ||
36 | { | ||
37 | } | ||
38 | |||
39 | public UserAccount(UUID userID, UUID homeRegionID, float homePositionX, | ||
40 | float homePositionY, float homePositionZ, float homeLookAtX, | ||
41 | float homeLookAtY, float homeLookAtZ) | ||
42 | { | ||
43 | UserID = userID; | ||
44 | HomeRegionID = homeRegionID; | ||
45 | HomePositionX = homePositionX; | ||
46 | HomePositionY = homePositionY; | ||
47 | HomePositionZ = homePositionZ; | ||
48 | HomeLookAtX = homeLookAtX; | ||
49 | HomeLookAtY = homeLookAtY; | ||
50 | HomeLookAtZ = homeLookAtZ; | ||
51 | } | ||
52 | |||
53 | public string FirstName; | ||
54 | public string LastName; | ||
55 | public UUID UserID; | ||
56 | public UUID ScopeID; | ||
57 | |||
58 | // For informational purposes only! | ||
59 | // | ||
60 | public string HomeRegionName; | ||
61 | |||
62 | public UUID HomeRegionID; | ||
63 | public float HomePositionX; | ||
64 | public float HomePositionY; | ||
65 | public float HomePositionZ; | ||
66 | public float HomeLookAtX; | ||
67 | public float HomeLookAtY; | ||
68 | public float HomeLookAtZ; | ||
69 | |||
70 | // These are here because they | ||
71 | // concern the account rather than | ||
72 | // the profile. They just happen to | ||
73 | // be used in the Linden profile as well | ||
74 | // | ||
75 | public int GodLevel; | ||
76 | public int UserFlags; | ||
77 | public string AccountType; | ||
78 | |||
79 | }; | ||
80 | |||
81 | public interface IUserAccountService | ||
82 | { | ||
83 | UserAccount GetUserAccount(UUID scopeID, UUID userID); | ||
84 | UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName); | ||
85 | // Returns the list of avatars that matches both the search | ||
86 | // criterion and the scope ID passed | ||
87 | // | ||
88 | List<UserAccount> GetUserAccount(UUID scopeID, string query); | ||
89 | |||
90 | |||
91 | // This will set only the home region portion of the data! | ||
92 | // Can't be used to set god level, flags, type or change the name! | ||
93 | // | ||
94 | bool SetHomePosition(UserAccount data, UUID RegionID, UUID RegionSecret); | ||
95 | |||
96 | // Update all updatable fields | ||
97 | // | ||
98 | bool SetUserAccount(UserAccount data, UUID PrincipalID, string token); | ||
99 | |||
100 | // Creates a user data record | ||
101 | bool CreateUserAccount(UserAccount data, UUID PrincipalID, string token); | ||
102 | } | ||
103 | } | ||
diff --git a/OpenSim/Services/InventoryService/HGInventoryService.cs b/OpenSim/Services/InventoryService/HGInventoryService.cs new file mode 100644 index 0000000..061effe --- /dev/null +++ b/OpenSim/Services/InventoryService/HGInventoryService.cs | |||
@@ -0,0 +1,302 @@ | |||
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 OpenMetaverse; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using System.Reflection; | ||
34 | using OpenSim.Services.Base; | ||
35 | using OpenSim.Services.Interfaces; | ||
36 | using OpenSim.Data; | ||
37 | using OpenSim.Framework; | ||
38 | |||
39 | namespace OpenSim.Services.InventoryService | ||
40 | { | ||
41 | public class HGInventoryService : XInventoryService, IInventoryService | ||
42 | { | ||
43 | private static readonly ILog m_log = | ||
44 | LogManager.GetLogger( | ||
45 | MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | protected IXInventoryData m_Database; | ||
48 | |||
49 | public HGInventoryService(IConfigSource config) | ||
50 | : base(config) | ||
51 | { | ||
52 | string dllName = String.Empty; | ||
53 | string connString = String.Empty; | ||
54 | //string realm = "Inventory"; // OSG version doesn't use this | ||
55 | |||
56 | // | ||
57 | // Try reading the [DatabaseService] section, if it exists | ||
58 | // | ||
59 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
60 | if (dbConfig != null) | ||
61 | { | ||
62 | if (dllName == String.Empty) | ||
63 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
64 | if (connString == String.Empty) | ||
65 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
66 | } | ||
67 | |||
68 | // | ||
69 | // Try reading the [InventoryService] section, if it exists | ||
70 | // | ||
71 | IConfig authConfig = config.Configs["InventoryService"]; | ||
72 | if (authConfig != null) | ||
73 | { | ||
74 | dllName = authConfig.GetString("StorageProvider", dllName); | ||
75 | connString = authConfig.GetString("ConnectionString", connString); | ||
76 | // realm = authConfig.GetString("Realm", realm); | ||
77 | } | ||
78 | |||
79 | // | ||
80 | // We tried, but this doesn't exist. We can't proceed. | ||
81 | // | ||
82 | if (dllName == String.Empty) | ||
83 | throw new Exception("No StorageProvider configured"); | ||
84 | |||
85 | m_Database = LoadPlugin<IXInventoryData>(dllName, | ||
86 | new Object[] {connString, String.Empty}); | ||
87 | if (m_Database == null) | ||
88 | throw new Exception("Could not find a storage interface in the given module"); | ||
89 | |||
90 | m_log.Debug("[HG INVENTORY SERVICE]: Starting..."); | ||
91 | } | ||
92 | |||
93 | public override bool CreateUserInventory(UUID principalID) | ||
94 | { | ||
95 | // NOGO | ||
96 | return false; | ||
97 | } | ||
98 | |||
99 | |||
100 | public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) | ||
101 | { | ||
102 | // NOGO for this inventory service | ||
103 | return new List<InventoryFolderBase>(); | ||
104 | } | ||
105 | |||
106 | public override InventoryFolderBase GetRootFolder(UUID principalID) | ||
107 | { | ||
108 | // Warp! Root folder for travelers | ||
109 | XInventoryFolder[] folders = m_Database.GetFolders( | ||
110 | new string[] { "agentID", "folderName"}, | ||
111 | new string[] { principalID.ToString(), "Suitcase" }); | ||
112 | |||
113 | if (folders.Length > 0) | ||
114 | return ConvertToOpenSim(folders[0]); | ||
115 | |||
116 | // make one | ||
117 | XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "Suitcase"); | ||
118 | return ConvertToOpenSim(suitcase); | ||
119 | } | ||
120 | |||
121 | //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase) | ||
122 | //{ | ||
123 | |||
124 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations"); | ||
125 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts"); | ||
126 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards"); | ||
127 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing"); | ||
128 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures"); | ||
129 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks"); | ||
130 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found"); | ||
131 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards"); | ||
132 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects"); | ||
133 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album"); | ||
134 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts"); | ||
135 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds"); | ||
136 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures"); | ||
137 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash"); | ||
138 | |||
139 | // return true; | ||
140 | //} | ||
141 | |||
142 | |||
143 | public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) | ||
144 | { | ||
145 | return GetRootFolder(principalID); | ||
146 | } | ||
147 | |||
148 | // | ||
149 | // Use the inherited methods | ||
150 | // | ||
151 | //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) | ||
152 | //{ | ||
153 | //} | ||
154 | |||
155 | //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | ||
156 | //{ | ||
157 | //} | ||
158 | |||
159 | //public override bool AddFolder(InventoryFolderBase folder) | ||
160 | //{ | ||
161 | // // Check if it's under the Suitcase folder | ||
162 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner); | ||
163 | // InventoryFolderBase suitcase = GetRootFolder(folder.Owner); | ||
164 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
165 | |||
166 | // foreach (InventoryFolderBase f in suitDescendents) | ||
167 | // if (folder.ParentID == f.ID) | ||
168 | // { | ||
169 | // XInventoryFolder xFolder = ConvertFromOpenSim(folder); | ||
170 | // return m_Database.StoreFolder(xFolder); | ||
171 | // } | ||
172 | // return false; | ||
173 | //} | ||
174 | |||
175 | private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root) | ||
176 | { | ||
177 | List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; }); | ||
178 | if (direct == null) | ||
179 | return new List<InventoryFolderBase>(); | ||
180 | |||
181 | List<InventoryFolderBase> indirect = new List<InventoryFolderBase>(); | ||
182 | foreach (InventoryFolderBase f in direct) | ||
183 | indirect.AddRange(GetDescendents(lst, f.ID)); | ||
184 | |||
185 | direct.AddRange(indirect); | ||
186 | return direct; | ||
187 | } | ||
188 | |||
189 | // Use inherited method | ||
190 | //public bool UpdateFolder(InventoryFolderBase folder) | ||
191 | //{ | ||
192 | //} | ||
193 | |||
194 | //public override bool MoveFolder(InventoryFolderBase folder) | ||
195 | //{ | ||
196 | // XInventoryFolder[] x = m_Database.GetFolders( | ||
197 | // new string[] { "folderID" }, | ||
198 | // new string[] { folder.ID.ToString() }); | ||
199 | |||
200 | // if (x.Length == 0) | ||
201 | // return false; | ||
202 | |||
203 | // // Check if it's under the Suitcase folder | ||
204 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner); | ||
205 | // InventoryFolderBase suitcase = GetRootFolder(folder.Owner); | ||
206 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
207 | |||
208 | // foreach (InventoryFolderBase f in suitDescendents) | ||
209 | // if (folder.ParentID == f.ID) | ||
210 | // { | ||
211 | // x[0].parentFolderID = folder.ParentID; | ||
212 | // return m_Database.StoreFolder(x[0]); | ||
213 | // } | ||
214 | |||
215 | // return false; | ||
216 | //} | ||
217 | |||
218 | public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs) | ||
219 | { | ||
220 | // NOGO | ||
221 | return false; | ||
222 | } | ||
223 | |||
224 | public override bool PurgeFolder(InventoryFolderBase folder) | ||
225 | { | ||
226 | // NOGO | ||
227 | return false; | ||
228 | } | ||
229 | |||
230 | // Unfortunately we need to use the inherited method because of how DeRez works. | ||
231 | // The viewer sends the folderID hard-wired in the derez message | ||
232 | //public override bool AddItem(InventoryItemBase item) | ||
233 | //{ | ||
234 | // // Check if it's under the Suitcase folder | ||
235 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner); | ||
236 | // InventoryFolderBase suitcase = GetRootFolder(item.Owner); | ||
237 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
238 | |||
239 | // foreach (InventoryFolderBase f in suitDescendents) | ||
240 | // if (item.Folder == f.ID) | ||
241 | // return m_Database.StoreItem(ConvertFromOpenSim(item)); | ||
242 | |||
243 | // return false; | ||
244 | //} | ||
245 | |||
246 | //public override bool UpdateItem(InventoryItemBase item) | ||
247 | //{ | ||
248 | // // Check if it's under the Suitcase folder | ||
249 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner); | ||
250 | // InventoryFolderBase suitcase = GetRootFolder(item.Owner); | ||
251 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
252 | |||
253 | // foreach (InventoryFolderBase f in suitDescendents) | ||
254 | // if (item.Folder == f.ID) | ||
255 | // return m_Database.StoreItem(ConvertFromOpenSim(item)); | ||
256 | |||
257 | // return false; | ||
258 | //} | ||
259 | |||
260 | //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items) | ||
261 | //{ | ||
262 | // // Principal is b0rked. *sigh* | ||
263 | // // | ||
264 | // // Let's assume they all have the same principal | ||
265 | // // Check if it's under the Suitcase folder | ||
266 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner); | ||
267 | // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner); | ||
268 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
269 | |||
270 | // foreach (InventoryItemBase i in items) | ||
271 | // { | ||
272 | // foreach (InventoryFolderBase f in suitDescendents) | ||
273 | // if (i.Folder == f.ID) | ||
274 | // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString()); | ||
275 | // } | ||
276 | |||
277 | // return true; | ||
278 | //} | ||
279 | |||
280 | // Let these pass. Use inherited methods. | ||
281 | //public bool DeleteItems(UUID principalID, List<UUID> itemIDs) | ||
282 | //{ | ||
283 | //} | ||
284 | |||
285 | //public InventoryItemBase GetItem(InventoryItemBase item) | ||
286 | //{ | ||
287 | //} | ||
288 | |||
289 | //public InventoryFolderBase GetFolder(InventoryFolderBase folder) | ||
290 | //{ | ||
291 | //} | ||
292 | |||
293 | //public List<InventoryItemBase> GetActiveGestures(UUID principalID) | ||
294 | //{ | ||
295 | //} | ||
296 | |||
297 | //public int GetAssetPermissions(UUID principalID, UUID assetID) | ||
298 | //{ | ||
299 | //} | ||
300 | |||
301 | } | ||
302 | } | ||
diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index 95007f1..0d6577e 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs | |||
@@ -66,6 +66,7 @@ namespace OpenSim.Services.InventoryService | |||
66 | // Agent has no inventory structure yet. | 66 | // Agent has no inventory structure yet. |
67 | if (null == rootFolder) | 67 | if (null == rootFolder) |
68 | { | 68 | { |
69 | m_log.DebugFormat("[INVENTORY SERVICE]: No root folder"); | ||
69 | return null; | 70 | return null; |
70 | } | 71 | } |
71 | 72 | ||
@@ -298,6 +299,7 @@ namespace OpenSim.Services.InventoryService | |||
298 | if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) | 299 | if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) |
299 | folders[(AssetType)folder.Type] = folder; | 300 | folders[(AssetType)folder.Type] = folder; |
300 | } | 301 | } |
302 | m_log.DebugFormat("[INVENTORY SERVICE]: Got {0} system folders for {1}", folders.Count, userID); | ||
301 | return folders; | 303 | return folders; |
302 | } | 304 | } |
303 | } | 305 | } |
diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Services/InventoryService/LibraryService.cs index 74ba0a5..383f311 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Services/InventoryService/LibraryService.cs | |||
@@ -30,20 +30,32 @@ using System.Collections.Generic; | |||
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Xml; | 32 | using System.Xml; |
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Services.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | |||
33 | using log4net; | 38 | using log4net; |
34 | using Nini.Config; | 39 | using Nini.Config; |
35 | using OpenMetaverse; | 40 | using OpenMetaverse; |
36 | 41 | ||
37 | namespace OpenSim.Framework.Communications.Cache | 42 | namespace OpenSim.Services.InventoryService |
38 | { | 43 | { |
39 | /// <summary> | 44 | /// <summary> |
40 | /// Basically a hack to give us a Inventory library while we don't have a inventory server | 45 | /// Basically a hack to give us a Inventory library while we don't have a inventory server |
41 | /// once the server is fully implemented then should read the data from that | 46 | /// once the server is fully implemented then should read the data from that |
42 | /// </summary> | 47 | /// </summary> |
43 | public class LibraryRootFolder : InventoryFolderImpl | 48 | public class LibraryService : ServiceBase, ILibraryService |
44 | { | 49 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 51 | ||
52 | private InventoryFolderImpl m_LibraryRootFolder; | ||
53 | |||
54 | public InventoryFolderImpl LibraryRootFolder | ||
55 | { | ||
56 | get { return m_LibraryRootFolder; } | ||
57 | } | ||
58 | |||
47 | private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000"); | 59 | private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000"); |
48 | 60 | ||
49 | /// <summary> | 61 | /// <summary> |
@@ -52,17 +64,31 @@ namespace OpenSim.Framework.Communications.Cache | |||
52 | /// </summary> | 64 | /// </summary> |
53 | protected Dictionary<UUID, InventoryFolderImpl> libraryFolders | 65 | protected Dictionary<UUID, InventoryFolderImpl> libraryFolders |
54 | = new Dictionary<UUID, InventoryFolderImpl>(); | 66 | = new Dictionary<UUID, InventoryFolderImpl>(); |
55 | 67 | ||
56 | public LibraryRootFolder(string pLibrariesLocation) | 68 | public LibraryService(IConfigSource config) |
69 | : base(config) | ||
57 | { | 70 | { |
58 | Owner = libOwner; | 71 | string pLibrariesLocation = Path.Combine("inventory", "Libraries.xml"); |
59 | ID = new UUID("00000112-000f-0000-0000-000100bba000"); | 72 | string pLibName = "OpenSim Library"; |
60 | Name = "OpenSim Library"; | 73 | |
61 | ParentID = UUID.Zero; | 74 | IConfig libConfig = config.Configs["LibraryService"]; |
62 | Type = (short) 8; | 75 | if (libConfig != null) |
63 | Version = (ushort) 1; | 76 | { |
77 | pLibrariesLocation = libConfig.GetString("DefaultLibrary", pLibrariesLocation); | ||
78 | pLibName = libConfig.GetString("LibraryName", pLibName); | ||
79 | } | ||
80 | |||
81 | m_log.Debug("[LIBRARY]: Starting library service..."); | ||
82 | |||
83 | m_LibraryRootFolder = new InventoryFolderImpl(); | ||
84 | m_LibraryRootFolder.Owner = libOwner; | ||
85 | m_LibraryRootFolder.ID = new UUID("00000112-000f-0000-0000-000100bba000"); | ||
86 | m_LibraryRootFolder.Name = pLibName; | ||
87 | m_LibraryRootFolder.ParentID = UUID.Zero; | ||
88 | m_LibraryRootFolder.Type = (short)8; | ||
89 | m_LibraryRootFolder.Version = (ushort)1; | ||
64 | 90 | ||
65 | libraryFolders.Add(ID, this); | 91 | libraryFolders.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder); |
66 | 92 | ||
67 | LoadLibraries(pLibrariesLocation); | 93 | LoadLibraries(pLibrariesLocation); |
68 | } | 94 | } |
@@ -126,9 +152,9 @@ namespace OpenSim.Framework.Communications.Cache | |||
126 | { | 152 | { |
127 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); | 153 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); |
128 | 154 | ||
129 | folderInfo.ID = new UUID(config.GetString("folderID", ID.ToString())); | 155 | folderInfo.ID = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString())); |
130 | folderInfo.Name = config.GetString("name", "unknown"); | 156 | folderInfo.Name = config.GetString("name", "unknown"); |
131 | folderInfo.ParentID = new UUID(config.GetString("parentFolderID", ID.ToString())); | 157 | folderInfo.ParentID = new UUID(config.GetString("parentFolderID", m_LibraryRootFolder.ID.ToString())); |
132 | folderInfo.Type = (short)config.GetInt("type", 8); | 158 | folderInfo.Type = (short)config.GetInt("type", 8); |
133 | 159 | ||
134 | folderInfo.Owner = libOwner; | 160 | folderInfo.Owner = libOwner; |
@@ -160,9 +186,9 @@ namespace OpenSim.Framework.Communications.Cache | |||
160 | InventoryItemBase item = new InventoryItemBase(); | 186 | InventoryItemBase item = new InventoryItemBase(); |
161 | item.Owner = libOwner; | 187 | item.Owner = libOwner; |
162 | item.CreatorId = libOwner.ToString(); | 188 | item.CreatorId = libOwner.ToString(); |
163 | item.ID = new UUID(config.GetString("inventoryID", ID.ToString())); | 189 | item.ID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString())); |
164 | item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString())); | 190 | item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString())); |
165 | item.Folder = new UUID(config.GetString("folderID", ID.ToString())); | 191 | item.Folder = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString())); |
166 | item.Name = config.GetString("name", String.Empty); | 192 | item.Name = config.GetString("name", String.Empty); |
167 | item.Description = config.GetString("description", item.Name); | 193 | item.Description = config.GetString("description", item.Name); |
168 | item.InvType = config.GetInt("inventoryType", 0); | 194 | item.InvType = config.GetInt("inventoryType", 0); |
@@ -230,11 +256,11 @@ namespace OpenSim.Framework.Communications.Cache | |||
230 | /// methods in the superclass | 256 | /// methods in the superclass |
231 | /// </summary> | 257 | /// </summary> |
232 | /// <returns></returns> | 258 | /// <returns></returns> |
233 | public Dictionary<UUID, InventoryFolderImpl> RequestSelfAndDescendentFolders() | 259 | public Dictionary<UUID, InventoryFolderImpl> GetAllFolders() |
234 | { | 260 | { |
235 | Dictionary<UUID, InventoryFolderImpl> fs = new Dictionary<UUID, InventoryFolderImpl>(); | 261 | Dictionary<UUID, InventoryFolderImpl> fs = new Dictionary<UUID, InventoryFolderImpl>(); |
236 | fs.Add(ID, this); | 262 | fs.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder); |
237 | List<InventoryFolderImpl> fis = TraverseFolder(this); | 263 | List<InventoryFolderImpl> fis = TraverseFolder(m_LibraryRootFolder); |
238 | foreach (InventoryFolderImpl f in fis) | 264 | foreach (InventoryFolderImpl f in fis) |
239 | { | 265 | { |
240 | fs.Add(f.ID, f); | 266 | fs.Add(f.ID, f); |
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs index 2c79c77..bbd37d1 100644 --- a/OpenSim/Services/InventoryService/XInventoryService.cs +++ b/OpenSim/Services/InventoryService/XInventoryService.cs | |||
@@ -87,7 +87,7 @@ namespace OpenSim.Services.InventoryService | |||
87 | throw new Exception("Could not find a storage interface in the given module"); | 87 | throw new Exception("Could not find a storage interface in the given module"); |
88 | } | 88 | } |
89 | 89 | ||
90 | public bool CreateUserInventory(UUID principalID) | 90 | public virtual bool CreateUserInventory(UUID principalID) |
91 | { | 91 | { |
92 | // This is braindeaad. We can't ever communicate that we fixed | 92 | // This is braindeaad. We can't ever communicate that we fixed |
93 | // an existing inventory. Well, just return root folder status, | 93 | // an existing inventory. Well, just return root folder status, |
@@ -99,7 +99,7 @@ namespace OpenSim.Services.InventoryService | |||
99 | 99 | ||
100 | if (rootFolder == null) | 100 | if (rootFolder == null) |
101 | { | 101 | { |
102 | rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Inventory")); | 102 | rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)AssetType.RootFolder, "My Inventory")); |
103 | result = true; | 103 | result = true; |
104 | } | 104 | } |
105 | 105 | ||
@@ -137,7 +137,7 @@ namespace OpenSim.Services.InventoryService | |||
137 | return result; | 137 | return result; |
138 | } | 138 | } |
139 | 139 | ||
140 | private XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name) | 140 | protected XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name) |
141 | { | 141 | { |
142 | XInventoryFolder newFolder = new XInventoryFolder(); | 142 | XInventoryFolder newFolder = new XInventoryFolder(); |
143 | 143 | ||
@@ -153,7 +153,7 @@ namespace OpenSim.Services.InventoryService | |||
153 | return newFolder; | 153 | return newFolder; |
154 | } | 154 | } |
155 | 155 | ||
156 | private XInventoryFolder[] GetSystemFolders(UUID principalID) | 156 | protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID) |
157 | { | 157 | { |
158 | XInventoryFolder[] allFolders = m_Database.GetFolders( | 158 | XInventoryFolder[] allFolders = m_Database.GetFolders( |
159 | new string[] { "agentID" }, | 159 | new string[] { "agentID" }, |
@@ -171,7 +171,7 @@ namespace OpenSim.Services.InventoryService | |||
171 | return sysFolders; | 171 | return sysFolders; |
172 | } | 172 | } |
173 | 173 | ||
174 | public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) | 174 | public virtual List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) |
175 | { | 175 | { |
176 | XInventoryFolder[] allFolders = m_Database.GetFolders( | 176 | XInventoryFolder[] allFolders = m_Database.GetFolders( |
177 | new string[] { "agentID" }, | 177 | new string[] { "agentID" }, |
@@ -191,7 +191,7 @@ namespace OpenSim.Services.InventoryService | |||
191 | return folders; | 191 | return folders; |
192 | } | 192 | } |
193 | 193 | ||
194 | public InventoryFolderBase GetRootFolder(UUID principalID) | 194 | public virtual InventoryFolderBase GetRootFolder(UUID principalID) |
195 | { | 195 | { |
196 | XInventoryFolder[] folders = m_Database.GetFolders( | 196 | XInventoryFolder[] folders = m_Database.GetFolders( |
197 | new string[] { "agentID", "parentFolderID"}, | 197 | new string[] { "agentID", "parentFolderID"}, |
@@ -203,7 +203,7 @@ namespace OpenSim.Services.InventoryService | |||
203 | return ConvertToOpenSim(folders[0]); | 203 | return ConvertToOpenSim(folders[0]); |
204 | } | 204 | } |
205 | 205 | ||
206 | public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) | 206 | public virtual InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) |
207 | { | 207 | { |
208 | XInventoryFolder[] folders = m_Database.GetFolders( | 208 | XInventoryFolder[] folders = m_Database.GetFolders( |
209 | new string[] { "agentID", "type"}, | 209 | new string[] { "agentID", "type"}, |
@@ -215,7 +215,7 @@ namespace OpenSim.Services.InventoryService | |||
215 | return ConvertToOpenSim(folders[0]); | 215 | return ConvertToOpenSim(folders[0]); |
216 | } | 216 | } |
217 | 217 | ||
218 | public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) | 218 | public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID) |
219 | { | 219 | { |
220 | // This method doesn't receive a valud principal id from the | 220 | // This method doesn't receive a valud principal id from the |
221 | // connector. So we disregard the principal and look | 221 | // connector. So we disregard the principal and look |
@@ -250,7 +250,7 @@ namespace OpenSim.Services.InventoryService | |||
250 | return inventory; | 250 | return inventory; |
251 | } | 251 | } |
252 | 252 | ||
253 | public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | 253 | public virtual List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) |
254 | { | 254 | { |
255 | // Since we probably don't get a valid principal here, either ... | 255 | // Since we probably don't get a valid principal here, either ... |
256 | // | 256 | // |
@@ -266,18 +266,18 @@ namespace OpenSim.Services.InventoryService | |||
266 | return invItems; | 266 | return invItems; |
267 | } | 267 | } |
268 | 268 | ||
269 | public bool AddFolder(InventoryFolderBase folder) | 269 | public virtual bool AddFolder(InventoryFolderBase folder) |
270 | { | 270 | { |
271 | XInventoryFolder xFolder = ConvertFromOpenSim(folder); | 271 | XInventoryFolder xFolder = ConvertFromOpenSim(folder); |
272 | return m_Database.StoreFolder(xFolder); | 272 | return m_Database.StoreFolder(xFolder); |
273 | } | 273 | } |
274 | 274 | ||
275 | public bool UpdateFolder(InventoryFolderBase folder) | 275 | public virtual bool UpdateFolder(InventoryFolderBase folder) |
276 | { | 276 | { |
277 | return AddFolder(folder); | 277 | return AddFolder(folder); |
278 | } | 278 | } |
279 | 279 | ||
280 | public bool MoveFolder(InventoryFolderBase folder) | 280 | public virtual bool MoveFolder(InventoryFolderBase folder) |
281 | { | 281 | { |
282 | XInventoryFolder[] x = m_Database.GetFolders( | 282 | XInventoryFolder[] x = m_Database.GetFolders( |
283 | new string[] { "folderID" }, | 283 | new string[] { "folderID" }, |
@@ -293,7 +293,7 @@ namespace OpenSim.Services.InventoryService | |||
293 | 293 | ||
294 | // We don't check the principal's ID here | 294 | // We don't check the principal's ID here |
295 | // | 295 | // |
296 | public bool DeleteFolders(UUID principalID, List<UUID> folderIDs) | 296 | public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs) |
297 | { | 297 | { |
298 | // Ignore principal ID, it's bogus at connector level | 298 | // Ignore principal ID, it's bogus at connector level |
299 | // | 299 | // |
@@ -308,7 +308,7 @@ namespace OpenSim.Services.InventoryService | |||
308 | return true; | 308 | return true; |
309 | } | 309 | } |
310 | 310 | ||
311 | public bool PurgeFolder(InventoryFolderBase folder) | 311 | public virtual bool PurgeFolder(InventoryFolderBase folder) |
312 | { | 312 | { |
313 | XInventoryFolder[] subFolders = m_Database.GetFolders( | 313 | XInventoryFolder[] subFolders = m_Database.GetFolders( |
314 | new string[] { "parentFolderID" }, | 314 | new string[] { "parentFolderID" }, |
@@ -325,17 +325,17 @@ namespace OpenSim.Services.InventoryService | |||
325 | return true; | 325 | return true; |
326 | } | 326 | } |
327 | 327 | ||
328 | public bool AddItem(InventoryItemBase item) | 328 | public virtual bool AddItem(InventoryItemBase item) |
329 | { | 329 | { |
330 | return m_Database.StoreItem(ConvertFromOpenSim(item)); | 330 | return m_Database.StoreItem(ConvertFromOpenSim(item)); |
331 | } | 331 | } |
332 | 332 | ||
333 | public bool UpdateItem(InventoryItemBase item) | 333 | public virtual bool UpdateItem(InventoryItemBase item) |
334 | { | 334 | { |
335 | return m_Database.StoreItem(ConvertFromOpenSim(item)); | 335 | return m_Database.StoreItem(ConvertFromOpenSim(item)); |
336 | } | 336 | } |
337 | 337 | ||
338 | public bool MoveItems(UUID principalID, List<InventoryItemBase> items) | 338 | public virtual bool MoveItems(UUID principalID, List<InventoryItemBase> items) |
339 | { | 339 | { |
340 | // Principal is b0rked. *sigh* | 340 | // Principal is b0rked. *sigh* |
341 | // | 341 | // |
@@ -347,7 +347,7 @@ namespace OpenSim.Services.InventoryService | |||
347 | return true; | 347 | return true; |
348 | } | 348 | } |
349 | 349 | ||
350 | public bool DeleteItems(UUID principalID, List<UUID> itemIDs) | 350 | public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs) |
351 | { | 351 | { |
352 | // Just use the ID... *facepalms* | 352 | // Just use the ID... *facepalms* |
353 | // | 353 | // |
@@ -357,7 +357,7 @@ namespace OpenSim.Services.InventoryService | |||
357 | return true; | 357 | return true; |
358 | } | 358 | } |
359 | 359 | ||
360 | public InventoryItemBase GetItem(InventoryItemBase item) | 360 | public virtual InventoryItemBase GetItem(InventoryItemBase item) |
361 | { | 361 | { |
362 | XInventoryItem[] items = m_Database.GetItems( | 362 | XInventoryItem[] items = m_Database.GetItems( |
363 | new string[] { "inventoryID" }, | 363 | new string[] { "inventoryID" }, |
@@ -369,7 +369,7 @@ namespace OpenSim.Services.InventoryService | |||
369 | return ConvertToOpenSim(items[0]); | 369 | return ConvertToOpenSim(items[0]); |
370 | } | 370 | } |
371 | 371 | ||
372 | public InventoryFolderBase GetFolder(InventoryFolderBase folder) | 372 | public virtual InventoryFolderBase GetFolder(InventoryFolderBase folder) |
373 | { | 373 | { |
374 | XInventoryFolder[] folders = m_Database.GetFolders( | 374 | XInventoryFolder[] folders = m_Database.GetFolders( |
375 | new string[] { "folderID"}, | 375 | new string[] { "folderID"}, |
@@ -381,7 +381,7 @@ namespace OpenSim.Services.InventoryService | |||
381 | return ConvertToOpenSim(folders[0]); | 381 | return ConvertToOpenSim(folders[0]); |
382 | } | 382 | } |
383 | 383 | ||
384 | public List<InventoryItemBase> GetActiveGestures(UUID principalID) | 384 | public virtual List<InventoryItemBase> GetActiveGestures(UUID principalID) |
385 | { | 385 | { |
386 | XInventoryItem[] items = m_Database.GetActiveGestures(principalID); | 386 | XInventoryItem[] items = m_Database.GetActiveGestures(principalID); |
387 | 387 | ||
@@ -396,7 +396,7 @@ namespace OpenSim.Services.InventoryService | |||
396 | return ret; | 396 | return ret; |
397 | } | 397 | } |
398 | 398 | ||
399 | public int GetAssetPermissions(UUID principalID, UUID assetID) | 399 | public virtual int GetAssetPermissions(UUID principalID, UUID assetID) |
400 | { | 400 | { |
401 | return m_Database.GetAssetPermissions(principalID, assetID); | 401 | return m_Database.GetAssetPermissions(principalID, assetID); |
402 | } | 402 | } |
@@ -421,7 +421,7 @@ namespace OpenSim.Services.InventoryService | |||
421 | 421 | ||
422 | // CM Helpers | 422 | // CM Helpers |
423 | // | 423 | // |
424 | private InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder) | 424 | protected InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder) |
425 | { | 425 | { |
426 | InventoryFolderBase newFolder = new InventoryFolderBase(); | 426 | InventoryFolderBase newFolder = new InventoryFolderBase(); |
427 | 427 | ||
@@ -435,7 +435,7 @@ namespace OpenSim.Services.InventoryService | |||
435 | return newFolder; | 435 | return newFolder; |
436 | } | 436 | } |
437 | 437 | ||
438 | private XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder) | 438 | protected XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder) |
439 | { | 439 | { |
440 | XInventoryFolder newFolder = new XInventoryFolder(); | 440 | XInventoryFolder newFolder = new XInventoryFolder(); |
441 | 441 | ||
@@ -449,7 +449,7 @@ namespace OpenSim.Services.InventoryService | |||
449 | return newFolder; | 449 | return newFolder; |
450 | } | 450 | } |
451 | 451 | ||
452 | private InventoryItemBase ConvertToOpenSim(XInventoryItem item) | 452 | protected InventoryItemBase ConvertToOpenSim(XInventoryItem item) |
453 | { | 453 | { |
454 | InventoryItemBase newItem = new InventoryItemBase(); | 454 | InventoryItemBase newItem = new InventoryItemBase(); |
455 | 455 | ||
@@ -468,7 +468,10 @@ namespace OpenSim.Services.InventoryService | |||
468 | newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions; | 468 | newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions; |
469 | newItem.GroupPermissions = (uint)item.inventoryGroupPermissions; | 469 | newItem.GroupPermissions = (uint)item.inventoryGroupPermissions; |
470 | newItem.GroupID = item.groupID; | 470 | newItem.GroupID = item.groupID; |
471 | newItem.GroupOwned = item.groupOwned; | 471 | if (item.groupOwned == 0) |
472 | newItem.GroupOwned = false; | ||
473 | else | ||
474 | newItem.GroupOwned = true; | ||
472 | newItem.SalePrice = item.salePrice; | 475 | newItem.SalePrice = item.salePrice; |
473 | newItem.SaleType = (byte)item.saleType; | 476 | newItem.SaleType = (byte)item.saleType; |
474 | newItem.Flags = (uint)item.flags; | 477 | newItem.Flags = (uint)item.flags; |
@@ -477,7 +480,7 @@ namespace OpenSim.Services.InventoryService | |||
477 | return newItem; | 480 | return newItem; |
478 | } | 481 | } |
479 | 482 | ||
480 | private XInventoryItem ConvertFromOpenSim(InventoryItemBase item) | 483 | protected XInventoryItem ConvertFromOpenSim(InventoryItemBase item) |
481 | { | 484 | { |
482 | XInventoryItem newItem = new XInventoryItem(); | 485 | XInventoryItem newItem = new XInventoryItem(); |
483 | 486 | ||
@@ -496,7 +499,10 @@ namespace OpenSim.Services.InventoryService | |||
496 | newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions; | 499 | newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions; |
497 | newItem.inventoryGroupPermissions = (int)item.GroupPermissions; | 500 | newItem.inventoryGroupPermissions = (int)item.GroupPermissions; |
498 | newItem.groupID = item.GroupID; | 501 | newItem.groupID = item.GroupID; |
499 | newItem.groupOwned = item.GroupOwned; | 502 | if (item.GroupOwned) |
503 | newItem.groupOwned = 1; | ||
504 | else | ||
505 | newItem.groupOwned = 0; | ||
500 | newItem.salePrice = item.SalePrice; | 506 | newItem.salePrice = item.SalePrice; |
501 | newItem.saleType = (int)item.SaleType; | 507 | newItem.saleType = (int)item.SaleType; |
502 | newItem.flags = (int)item.Flags; | 508 | newItem.flags = (int)item.Flags; |
diff --git a/OpenSim/Framework/Communications/Services/LoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs index ec5f428..05f5b4c 100644 --- a/OpenSim/Framework/Communications/Services/LoginResponse.cs +++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs | |||
@@ -28,25 +28,108 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | ||
31 | using System.Reflection; | 32 | using System.Reflection; |
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Capabilities; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
39 | |||
32 | using log4net; | 40 | using log4net; |
33 | using Nwc.XmlRpc; | ||
34 | using OpenMetaverse; | 41 | using OpenMetaverse; |
35 | using OpenMetaverse.StructuredData; | 42 | using OpenMetaverse.StructuredData; |
43 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
44 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
36 | 45 | ||
37 | namespace OpenSim.Framework.Communications.Services | 46 | namespace OpenSim.Services.LLLoginService |
38 | { | 47 | { |
48 | public class LLFailedLoginResponse : OpenSim.Services.Interfaces.FailedLoginResponse | ||
49 | { | ||
50 | string m_key; | ||
51 | string m_value; | ||
52 | string m_login; | ||
53 | |||
54 | public static LLFailedLoginResponse UserProblem; | ||
55 | public static LLFailedLoginResponse AuthorizationProblem; | ||
56 | public static LLFailedLoginResponse GridProblem; | ||
57 | public static LLFailedLoginResponse InventoryProblem; | ||
58 | public static LLFailedLoginResponse DeadRegionProblem; | ||
59 | public static LLFailedLoginResponse LoginBlockedProblem; | ||
60 | public static LLFailedLoginResponse AlreadyLoggedInProblem; | ||
61 | public static LLFailedLoginResponse InternalError; | ||
62 | |||
63 | static LLFailedLoginResponse() | ||
64 | { | ||
65 | UserProblem = new LLFailedLoginResponse("key", | ||
66 | "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", | ||
67 | "false"); | ||
68 | AuthorizationProblem = new LLFailedLoginResponse("key", | ||
69 | "Error connecting to grid. Unable to authorize your session into the region.", | ||
70 | "false"); | ||
71 | GridProblem = new LLFailedLoginResponse("key", | ||
72 | "Error connecting to the desired location. Try connecting to another region.", | ||
73 | "false"); | ||
74 | InventoryProblem = new LLFailedLoginResponse("key", | ||
75 | "The inventory service is not responding. Please notify your login region operator.", | ||
76 | "false"); | ||
77 | DeadRegionProblem = new LLFailedLoginResponse("key", | ||
78 | "The region you are attempting to log into is not responding. Please select another region and try again.", | ||
79 | "false"); | ||
80 | LoginBlockedProblem = new LLFailedLoginResponse("presence", | ||
81 | "Logins are currently restricted. Please try again later.", | ||
82 | "false"); | ||
83 | AlreadyLoggedInProblem = new LLFailedLoginResponse("presence", | ||
84 | "You appear to be already logged in. " + | ||
85 | "If this is not the case please wait for your session to timeout. " + | ||
86 | "If this takes longer than a few minutes please contact the grid owner. " + | ||
87 | "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.", | ||
88 | "false"); | ||
89 | InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false"); | ||
90 | } | ||
91 | |||
92 | public LLFailedLoginResponse(string key, string value, string login) | ||
93 | { | ||
94 | m_key = key; | ||
95 | m_value = value; | ||
96 | m_login = login; | ||
97 | } | ||
98 | |||
99 | public override Hashtable ToHashtable() | ||
100 | { | ||
101 | Hashtable loginError = new Hashtable(); | ||
102 | loginError["reason"] = m_key; | ||
103 | loginError["message"] = m_value; | ||
104 | loginError["login"] = m_login; | ||
105 | return loginError; | ||
106 | } | ||
107 | |||
108 | public override OSD ToOSDMap() | ||
109 | { | ||
110 | OSDMap map = new OSDMap(); | ||
111 | |||
112 | map["reason"] = OSD.FromString(m_key); | ||
113 | map["message"] = OSD.FromString(m_value); | ||
114 | map["login"] = OSD.FromString(m_login); | ||
115 | |||
116 | return map; | ||
117 | } | ||
118 | } | ||
119 | |||
39 | /// <summary> | 120 | /// <summary> |
40 | /// A temp class to handle login response. | 121 | /// A class to handle LL login response. |
41 | /// Should make use of UserProfileManager where possible. | ||
42 | /// </summary> | 122 | /// </summary> |
43 | public class LoginResponse | 123 | public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse |
44 | { | 124 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 125 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
126 | private static Hashtable globalTexturesHash; | ||
127 | // Global Textures | ||
128 | private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; | ||
129 | private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
130 | private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
46 | 131 | ||
47 | private Hashtable loginFlagsHash; | 132 | private Hashtable loginFlagsHash; |
48 | private Hashtable globalTexturesHash; | ||
49 | private Hashtable loginError; | ||
50 | private Hashtable uiConfigHash; | 133 | private Hashtable uiConfigHash; |
51 | 134 | ||
52 | private ArrayList loginFlags; | 135 | private ArrayList loginFlags; |
@@ -87,19 +170,10 @@ namespace OpenSim.Framework.Communications.Services | |||
87 | private string firstname; | 170 | private string firstname; |
88 | private string lastname; | 171 | private string lastname; |
89 | 172 | ||
90 | // Global Textures | ||
91 | private string sunTexture; | ||
92 | private string cloudTexture; | ||
93 | private string moonTexture; | ||
94 | |||
95 | // Error Flags | 173 | // Error Flags |
96 | private string errorReason; | 174 | private string errorReason; |
97 | private string errorMessage; | 175 | private string errorMessage; |
98 | 176 | ||
99 | // Response | ||
100 | private XmlRpcResponse xmlRpcResponse; | ||
101 | // private XmlRpcResponse defaultXmlRpcResponse; | ||
102 | |||
103 | private string welcomeMessage; | 177 | private string welcomeMessage; |
104 | private string startLocation; | 178 | private string startLocation; |
105 | private string allowFirstLife; | 179 | private string allowFirstLife; |
@@ -109,7 +183,17 @@ namespace OpenSim.Framework.Communications.Services | |||
109 | 183 | ||
110 | private BuddyList m_buddyList = null; | 184 | private BuddyList m_buddyList = null; |
111 | 185 | ||
112 | public LoginResponse() | 186 | static LLLoginResponse() |
187 | { | ||
188 | // This is being set, but it's not used | ||
189 | // not sure why. | ||
190 | globalTexturesHash = new Hashtable(); | ||
191 | globalTexturesHash["sun_texture_id"] = sunTexture; | ||
192 | globalTexturesHash["cloud_texture_id"] = cloudTexture; | ||
193 | globalTexturesHash["moon_texture_id"] = moonTexture; | ||
194 | } | ||
195 | |||
196 | public LLLoginResponse() | ||
113 | { | 197 | { |
114 | loginFlags = new ArrayList(); | 198 | loginFlags = new ArrayList(); |
115 | globalTextures = new ArrayList(); | 199 | globalTextures = new ArrayList(); |
@@ -117,7 +201,6 @@ namespace OpenSim.Framework.Communications.Services | |||
117 | uiConfig = new ArrayList(); | 201 | uiConfig = new ArrayList(); |
118 | classifiedCategories = new ArrayList(); | 202 | classifiedCategories = new ArrayList(); |
119 | 203 | ||
120 | loginError = new Hashtable(); | ||
121 | uiConfigHash = new Hashtable(); | 204 | uiConfigHash = new Hashtable(); |
122 | 205 | ||
123 | // defaultXmlRpcResponse = new XmlRpcResponse(); | 206 | // defaultXmlRpcResponse = new XmlRpcResponse(); |
@@ -129,12 +212,136 @@ namespace OpenSim.Framework.Communications.Services | |||
129 | inventoryLibraryOwner = new ArrayList(); | 212 | inventoryLibraryOwner = new ArrayList(); |
130 | activeGestures = new ArrayList(); | 213 | activeGestures = new ArrayList(); |
131 | 214 | ||
132 | xmlRpcResponse = new XmlRpcResponse(); | ||
133 | // defaultXmlRpcResponse = new XmlRpcResponse(); | ||
134 | |||
135 | SetDefaultValues(); | 215 | SetDefaultValues(); |
136 | } | 216 | } |
137 | 217 | ||
218 | public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, PresenceInfo pinfo, | ||
219 | GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService, | ||
220 | string where, string startlocation, Vector3 position, Vector3 lookAt, string message, | ||
221 | GridRegion home, IPEndPoint clientIP) | ||
222 | : this() | ||
223 | { | ||
224 | FillOutInventoryData(invSkel, libService); | ||
225 | |||
226 | CircuitCode = (int)aCircuit.circuitcode; | ||
227 | Lastname = account.LastName; | ||
228 | Firstname = account.FirstName; | ||
229 | AgentID = account.PrincipalID; | ||
230 | SessionID = aCircuit.SessionID; | ||
231 | SecureSessionID = aCircuit.SecureSessionID; | ||
232 | Message = message; | ||
233 | BuddList = ConvertFriendListItem(friendsList); | ||
234 | StartLocation = where; | ||
235 | |||
236 | FillOutHomeData(pinfo, home); | ||
237 | LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z); | ||
238 | |||
239 | FillOutRegionData(destination); | ||
240 | |||
241 | FillOutSeedCap(aCircuit, destination, clientIP); | ||
242 | |||
243 | } | ||
244 | |||
245 | private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService) | ||
246 | { | ||
247 | InventoryData inventData = null; | ||
248 | |||
249 | try | ||
250 | { | ||
251 | inventData = GetInventorySkeleton(invSkel); | ||
252 | } | ||
253 | catch (Exception e) | ||
254 | { | ||
255 | m_log.WarnFormat( | ||
256 | "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}", | ||
257 | agentID, e); | ||
258 | |||
259 | // ignore and continue | ||
260 | } | ||
261 | |||
262 | if (inventData != null) | ||
263 | { | ||
264 | ArrayList AgentInventoryArray = inventData.InventoryArray; | ||
265 | |||
266 | Hashtable InventoryRootHash = new Hashtable(); | ||
267 | InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); | ||
268 | InventoryRoot = new ArrayList(); | ||
269 | InventoryRoot.Add(InventoryRootHash); | ||
270 | InventorySkeleton = AgentInventoryArray; | ||
271 | } | ||
272 | |||
273 | // Inventory Library Section | ||
274 | if (libService != null && libService.LibraryRootFolder != null) | ||
275 | { | ||
276 | Hashtable InventoryLibRootHash = new Hashtable(); | ||
277 | InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; | ||
278 | InventoryLibRoot = new ArrayList(); | ||
279 | InventoryLibRoot.Add(InventoryLibRootHash); | ||
280 | |||
281 | InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder); | ||
282 | InventoryLibrary = GetInventoryLibrary(libService); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | private void FillOutHomeData(PresenceInfo pinfo, GridRegion home) | ||
287 | { | ||
288 | int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize; | ||
289 | if (home != null) | ||
290 | { | ||
291 | x = home.RegionLocX; | ||
292 | y = home.RegionLocY; | ||
293 | } | ||
294 | |||
295 | Home = string.Format( | ||
296 | "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", | ||
297 | x, | ||
298 | y, | ||
299 | pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z, | ||
300 | pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z); | ||
301 | |||
302 | } | ||
303 | |||
304 | private void FillOutRegionData(GridRegion destination) | ||
305 | { | ||
306 | IPEndPoint endPoint = destination.ExternalEndPoint; | ||
307 | SimAddress = endPoint.Address.ToString(); | ||
308 | SimPort = (uint)endPoint.Port; | ||
309 | RegionX = (uint)destination.RegionLocX; | ||
310 | RegionY = (uint)destination.RegionLocY; | ||
311 | } | ||
312 | |||
313 | private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient) | ||
314 | { | ||
315 | string capsSeedPath = String.Empty; | ||
316 | |||
317 | // Don't use the following! It Fails for logging into any region not on the same port as the http server! | ||
318 | // Kept here so it doesn't happen again! | ||
319 | // response.SeedCapability = regionInfo.ServerURI + capsSeedPath; | ||
320 | |||
321 | #region IP Translation for NAT | ||
322 | if (ipepClient != null) | ||
323 | { | ||
324 | capsSeedPath | ||
325 | = "http://" | ||
326 | + NetworkUtil.GetHostFor(ipepClient.Address, destination.ExternalHostName) | ||
327 | + ":" | ||
328 | + destination.HttpPort | ||
329 | + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath); | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | capsSeedPath | ||
334 | = "http://" | ||
335 | + destination.ExternalHostName | ||
336 | + ":" | ||
337 | + destination.HttpPort | ||
338 | + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath); | ||
339 | } | ||
340 | #endregion | ||
341 | |||
342 | SeedCapability = capsSeedPath; | ||
343 | } | ||
344 | |||
138 | private void SetDefaultValues() | 345 | private void SetDefaultValues() |
139 | { | 346 | { |
140 | DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; | 347 | DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; |
@@ -149,10 +356,6 @@ namespace OpenSim.Framework.Communications.Services | |||
149 | startLocation = "last"; | 356 | startLocation = "last"; |
150 | allowFirstLife = "Y"; | 357 | allowFirstLife = "Y"; |
151 | 358 | ||
152 | SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; | ||
153 | CloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
154 | MoonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
155 | |||
156 | ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; | 359 | ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; |
157 | ErrorReason = "key"; | 360 | ErrorReason = "key"; |
158 | welcomeMessage = "Welcome to OpenSim!"; | 361 | welcomeMessage = "Welcome to OpenSim!"; |
@@ -186,149 +389,8 @@ namespace OpenSim.Framework.Communications.Services | |||
186 | initialOutfit.Add(InitialOutfitHash); | 389 | initialOutfit.Add(InitialOutfitHash); |
187 | } | 390 | } |
188 | 391 | ||
189 | #region Login Failure Methods | ||
190 | |||
191 | public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login) | ||
192 | { | ||
193 | // Overwrite any default values; | ||
194 | xmlRpcResponse = new XmlRpcResponse(); | ||
195 | |||
196 | // Ensure Login Failed message/reason; | ||
197 | ErrorMessage = message; | ||
198 | ErrorReason = reason; | ||
199 | |||
200 | loginError["reason"] = ErrorReason; | ||
201 | loginError["message"] = ErrorMessage; | ||
202 | loginError["login"] = login; | ||
203 | xmlRpcResponse.Value = loginError; | ||
204 | return (xmlRpcResponse); | ||
205 | } | ||
206 | 392 | ||
207 | public OSD GenerateFailureResponseLLSD(string reason, string message, string login) | 393 | public override Hashtable ToHashtable() |
208 | { | ||
209 | OSDMap map = new OSDMap(); | ||
210 | |||
211 | // Ensure Login Failed message/reason; | ||
212 | ErrorMessage = message; | ||
213 | ErrorReason = reason; | ||
214 | |||
215 | map["reason"] = OSD.FromString(ErrorReason); | ||
216 | map["message"] = OSD.FromString(ErrorMessage); | ||
217 | map["login"] = OSD.FromString(login); | ||
218 | |||
219 | return map; | ||
220 | } | ||
221 | |||
222 | public XmlRpcResponse CreateFailedResponse() | ||
223 | { | ||
224 | return (CreateLoginFailedResponse()); | ||
225 | } | ||
226 | |||
227 | public OSD CreateFailedResponseLLSD() | ||
228 | { | ||
229 | return CreateLoginFailedResponseLLSD(); | ||
230 | } | ||
231 | |||
232 | public XmlRpcResponse CreateLoginFailedResponse() | ||
233 | { | ||
234 | return | ||
235 | (GenerateFailureResponse("key", | ||
236 | "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", | ||
237 | "false")); | ||
238 | } | ||
239 | |||
240 | public OSD CreateLoginFailedResponseLLSD() | ||
241 | { | ||
242 | return GenerateFailureResponseLLSD( | ||
243 | "key", | ||
244 | "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", | ||
245 | "false"); | ||
246 | } | ||
247 | |||
248 | /// <summary> | ||
249 | /// Response to indicate that login failed because the agent's inventory was not available. | ||
250 | /// </summary> | ||
251 | /// <returns></returns> | ||
252 | public XmlRpcResponse CreateLoginInventoryFailedResponse() | ||
253 | { | ||
254 | return GenerateFailureResponse( | ||
255 | "key", | ||
256 | "The avatar inventory service is not responding. Please notify your login region operator.", | ||
257 | "false"); | ||
258 | } | ||
259 | |||
260 | public XmlRpcResponse CreateAlreadyLoggedInResponse() | ||
261 | { | ||
262 | return | ||
263 | (GenerateFailureResponse("presence", | ||
264 | "You appear to be already logged in. " + | ||
265 | "If this is not the case please wait for your session to timeout. " + | ||
266 | "If this takes longer than a few minutes please contact the grid owner. " + | ||
267 | "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.", | ||
268 | "false")); | ||
269 | } | ||
270 | |||
271 | public OSD CreateAlreadyLoggedInResponseLLSD() | ||
272 | { | ||
273 | return GenerateFailureResponseLLSD( | ||
274 | "presence", | ||
275 | "You appear to be already logged in. " + | ||
276 | "If this is not the case please wait for your session to timeout. " + | ||
277 | "If this takes longer than a few minutes please contact the grid owner", | ||
278 | "false"); | ||
279 | } | ||
280 | |||
281 | public XmlRpcResponse CreateLoginBlockedResponse() | ||
282 | { | ||
283 | return | ||
284 | (GenerateFailureResponse("presence", | ||
285 | "Logins are currently restricted. Please try again later", | ||
286 | "false")); | ||
287 | } | ||
288 | |||
289 | public OSD CreateLoginBlockedResponseLLSD() | ||
290 | { | ||
291 | return GenerateFailureResponseLLSD( | ||
292 | "presence", | ||
293 | "Logins are currently restricted. Please try again later", | ||
294 | "false"); | ||
295 | } | ||
296 | |||
297 | public XmlRpcResponse CreateDeadRegionResponse() | ||
298 | { | ||
299 | return | ||
300 | (GenerateFailureResponse("key", | ||
301 | "The region you are attempting to log into is not responding. Please select another region and try again.", | ||
302 | "false")); | ||
303 | } | ||
304 | |||
305 | public OSD CreateDeadRegionResponseLLSD() | ||
306 | { | ||
307 | return GenerateFailureResponseLLSD( | ||
308 | "key", | ||
309 | "The region you are attempting to log into is not responding. Please select another region and try again.", | ||
310 | "false"); | ||
311 | } | ||
312 | |||
313 | public XmlRpcResponse CreateGridErrorResponse() | ||
314 | { | ||
315 | return | ||
316 | (GenerateFailureResponse("key", | ||
317 | "Error connecting to grid. Could not percieve credentials from login XML.", | ||
318 | "false")); | ||
319 | } | ||
320 | |||
321 | public OSD CreateGridErrorResponseLLSD() | ||
322 | { | ||
323 | return GenerateFailureResponseLLSD( | ||
324 | "key", | ||
325 | "Error connecting to grid. Could not perceive credentials from login XML.", | ||
326 | "false"); | ||
327 | } | ||
328 | |||
329 | #endregion | ||
330 | |||
331 | public virtual XmlRpcResponse ToXmlRpcResponse() | ||
332 | { | 394 | { |
333 | try | 395 | try |
334 | { | 396 | { |
@@ -346,10 +408,6 @@ namespace OpenSim.Framework.Communications.Services | |||
346 | responseData["agent_access"] = agentAccess; | 408 | responseData["agent_access"] = agentAccess; |
347 | responseData["agent_access_max"] = agentAccessMax; | 409 | responseData["agent_access_max"] = agentAccessMax; |
348 | 410 | ||
349 | globalTexturesHash = new Hashtable(); | ||
350 | globalTexturesHash["sun_texture_id"] = SunTexture; | ||
351 | globalTexturesHash["cloud_texture_id"] = CloudTexture; | ||
352 | globalTexturesHash["moon_texture_id"] = MoonTexture; | ||
353 | globalTextures.Add(globalTexturesHash); | 411 | globalTextures.Add(globalTexturesHash); |
354 | // this.eventCategories.Add(this.eventCategoriesHash); | 412 | // this.eventCategories.Add(this.eventCategoriesHash); |
355 | 413 | ||
@@ -389,8 +447,8 @@ namespace OpenSim.Framework.Communications.Services | |||
389 | responseData["home"] = home; | 447 | responseData["home"] = home; |
390 | responseData["look_at"] = lookAt; | 448 | responseData["look_at"] = lookAt; |
391 | responseData["message"] = welcomeMessage; | 449 | responseData["message"] = welcomeMessage; |
392 | responseData["region_x"] = (Int32)(RegionX * Constants.RegionSize); | 450 | responseData["region_x"] = (Int32)(RegionX); |
393 | responseData["region_y"] = (Int32)(RegionY * Constants.RegionSize); | 451 | responseData["region_y"] = (Int32)(RegionY); |
394 | 452 | ||
395 | if (m_buddyList != null) | 453 | if (m_buddyList != null) |
396 | { | 454 | { |
@@ -398,19 +456,18 @@ namespace OpenSim.Framework.Communications.Services | |||
398 | } | 456 | } |
399 | 457 | ||
400 | responseData["login"] = "true"; | 458 | responseData["login"] = "true"; |
401 | xmlRpcResponse.Value = responseData; | ||
402 | 459 | ||
403 | return (xmlRpcResponse); | 460 | return responseData; |
404 | } | 461 | } |
405 | catch (Exception e) | 462 | catch (Exception e) |
406 | { | 463 | { |
407 | m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message); | 464 | m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message); |
408 | 465 | ||
409 | return (GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); | 466 | return LLFailedLoginResponse.InternalError.ToHashtable(); |
410 | } | 467 | } |
411 | } | 468 | } |
412 | 469 | ||
413 | public OSD ToLLSDResponse() | 470 | public override OSD ToOSDMap() |
414 | { | 471 | { |
415 | try | 472 | try |
416 | { | 473 | { |
@@ -486,8 +543,8 @@ namespace OpenSim.Framework.Communications.Services | |||
486 | map["home"] = OSD.FromString(home); | 543 | map["home"] = OSD.FromString(home); |
487 | map["look_at"] = OSD.FromString(lookAt); | 544 | map["look_at"] = OSD.FromString(lookAt); |
488 | map["message"] = OSD.FromString(welcomeMessage); | 545 | map["message"] = OSD.FromString(welcomeMessage); |
489 | map["region_x"] = OSD.FromInteger(RegionX * Constants.RegionSize); | 546 | map["region_x"] = OSD.FromInteger(RegionX); |
490 | map["region_y"] = OSD.FromInteger(RegionY * Constants.RegionSize); | 547 | map["region_y"] = OSD.FromInteger(RegionY); |
491 | 548 | ||
492 | if (m_buddyList != null) | 549 | if (m_buddyList != null) |
493 | { | 550 | { |
@@ -502,7 +559,7 @@ namespace OpenSim.Framework.Communications.Services | |||
502 | { | 559 | { |
503 | m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message); | 560 | m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message); |
504 | 561 | ||
505 | return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); | 562 | return LLFailedLoginResponse.InternalError.ToOSDMap(); |
506 | } | 563 | } |
507 | } | 564 | } |
508 | 565 | ||
@@ -548,6 +605,98 @@ namespace OpenSim.Framework.Communications.Services | |||
548 | // this.classifiedCategoriesHash.Clear(); | 605 | // this.classifiedCategoriesHash.Clear(); |
549 | } | 606 | } |
550 | 607 | ||
608 | |||
609 | private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList) | ||
610 | { | ||
611 | LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList(); | ||
612 | foreach (FriendInfo finfo in friendsList) | ||
613 | { | ||
614 | if (finfo.TheirFlags == -1) | ||
615 | continue; | ||
616 | LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend); | ||
617 | buddyitem.BuddyID = finfo.Friend; | ||
618 | buddyitem.BuddyRightsHave = (int)finfo.TheirFlags; | ||
619 | buddyitem.BuddyRightsGiven = (int)finfo.MyFlags; | ||
620 | buddylistreturn.AddNewBuddy(buddyitem); | ||
621 | } | ||
622 | return buddylistreturn; | ||
623 | } | ||
624 | |||
625 | private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders) | ||
626 | { | ||
627 | UUID rootID = UUID.Zero; | ||
628 | ArrayList AgentInventoryArray = new ArrayList(); | ||
629 | Hashtable TempHash; | ||
630 | foreach (InventoryFolderBase InvFolder in folders) | ||
631 | { | ||
632 | if (InvFolder.ParentID == UUID.Zero) | ||
633 | { | ||
634 | rootID = InvFolder.ID; | ||
635 | } | ||
636 | TempHash = new Hashtable(); | ||
637 | TempHash["name"] = InvFolder.Name; | ||
638 | TempHash["parent_id"] = InvFolder.ParentID.ToString(); | ||
639 | TempHash["version"] = (Int32)InvFolder.Version; | ||
640 | TempHash["type_default"] = (Int32)InvFolder.Type; | ||
641 | TempHash["folder_id"] = InvFolder.ID.ToString(); | ||
642 | AgentInventoryArray.Add(TempHash); | ||
643 | } | ||
644 | |||
645 | return new InventoryData(AgentInventoryArray, rootID); | ||
646 | |||
647 | } | ||
648 | |||
649 | /// <summary> | ||
650 | /// Converts the inventory library skeleton into the form required by the rpc request. | ||
651 | /// </summary> | ||
652 | /// <returns></returns> | ||
653 | protected virtual ArrayList GetInventoryLibrary(ILibraryService library) | ||
654 | { | ||
655 | Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders(); | ||
656 | m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count); | ||
657 | //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>(); | ||
658 | ArrayList folderHashes = new ArrayList(); | ||
659 | |||
660 | foreach (InventoryFolderBase folder in rootFolders.Values) | ||
661 | { | ||
662 | Hashtable TempHash = new Hashtable(); | ||
663 | TempHash["name"] = folder.Name; | ||
664 | TempHash["parent_id"] = folder.ParentID.ToString(); | ||
665 | TempHash["version"] = (Int32)folder.Version; | ||
666 | TempHash["type_default"] = (Int32)folder.Type; | ||
667 | TempHash["folder_id"] = folder.ID.ToString(); | ||
668 | folderHashes.Add(TempHash); | ||
669 | } | ||
670 | |||
671 | return folderHashes; | ||
672 | } | ||
673 | |||
674 | /// <summary> | ||
675 | /// | ||
676 | /// </summary> | ||
677 | /// <returns></returns> | ||
678 | protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder) | ||
679 | { | ||
680 | //for now create random inventory library owner | ||
681 | Hashtable TempHash = new Hashtable(); | ||
682 | TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner | ||
683 | ArrayList inventoryLibOwner = new ArrayList(); | ||
684 | inventoryLibOwner.Add(TempHash); | ||
685 | return inventoryLibOwner; | ||
686 | } | ||
687 | |||
688 | public class InventoryData | ||
689 | { | ||
690 | public ArrayList InventoryArray = null; | ||
691 | public UUID RootFolderID = UUID.Zero; | ||
692 | |||
693 | public InventoryData(ArrayList invList, UUID rootID) | ||
694 | { | ||
695 | InventoryArray = invList; | ||
696 | RootFolderID = rootID; | ||
697 | } | ||
698 | } | ||
699 | |||
551 | #region Properties | 700 | #region Properties |
552 | 701 | ||
553 | public string Login | 702 | public string Login |
@@ -797,16 +946,16 @@ namespace OpenSim.Framework.Communications.Services | |||
797 | { | 946 | { |
798 | public int BuddyRightsHave = 1; | 947 | public int BuddyRightsHave = 1; |
799 | public int BuddyRightsGiven = 1; | 948 | public int BuddyRightsGiven = 1; |
800 | public UUID BuddyID; | 949 | public string BuddyID; |
801 | 950 | ||
802 | public BuddyInfo(string buddyID) | 951 | public BuddyInfo(string buddyID) |
803 | { | 952 | { |
804 | BuddyID = new UUID(buddyID); | 953 | BuddyID = buddyID; |
805 | } | 954 | } |
806 | 955 | ||
807 | public BuddyInfo(UUID buddyID) | 956 | public BuddyInfo(UUID buddyID) |
808 | { | 957 | { |
809 | BuddyID = buddyID; | 958 | BuddyID = buddyID.ToString(); |
810 | } | 959 | } |
811 | 960 | ||
812 | public Hashtable ToHashTable() | 961 | public Hashtable ToHashTable() |
@@ -814,7 +963,7 @@ namespace OpenSim.Framework.Communications.Services | |||
814 | Hashtable hTable = new Hashtable(); | 963 | Hashtable hTable = new Hashtable(); |
815 | hTable["buddy_rights_has"] = BuddyRightsHave; | 964 | hTable["buddy_rights_has"] = BuddyRightsHave; |
816 | hTable["buddy_rights_given"] = BuddyRightsGiven; | 965 | hTable["buddy_rights_given"] = BuddyRightsGiven; |
817 | hTable["buddy_id"] = BuddyID.ToString(); | 966 | hTable["buddy_id"] = BuddyID; |
818 | return hTable; | 967 | return hTable; |
819 | } | 968 | } |
820 | } | 969 | } |
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs new file mode 100644 index 0000000..143e5f1 --- /dev/null +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs | |||
@@ -0,0 +1,650 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Net; | ||
4 | using System.Reflection; | ||
5 | using System.Text.RegularExpressions; | ||
6 | |||
7 | using log4net; | ||
8 | using Nini.Config; | ||
9 | using OpenMetaverse; | ||
10 | |||
11 | using OpenSim.Framework; | ||
12 | using OpenSim.Framework.Capabilities; | ||
13 | using OpenSim.Framework.Console; | ||
14 | using OpenSim.Server.Base; | ||
15 | using OpenSim.Services.Interfaces; | ||
16 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
17 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
18 | using OpenSim.Services.Connectors.Hypergrid; | ||
19 | |||
20 | namespace OpenSim.Services.LLLoginService | ||
21 | { | ||
22 | public class LLLoginService : ILoginService | ||
23 | { | ||
24 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
25 | private static bool Initialized = false; | ||
26 | |||
27 | private IUserAccountService m_UserAccountService; | ||
28 | private IAuthenticationService m_AuthenticationService; | ||
29 | private IInventoryService m_InventoryService; | ||
30 | private IGridService m_GridService; | ||
31 | private IPresenceService m_PresenceService; | ||
32 | private ISimulationService m_LocalSimulationService; | ||
33 | private ISimulationService m_RemoteSimulationService; | ||
34 | private ILibraryService m_LibraryService; | ||
35 | private IFriendsService m_FriendsService; | ||
36 | private IAvatarService m_AvatarService; | ||
37 | private IUserAgentService m_UserAgentService; | ||
38 | |||
39 | private GatekeeperServiceConnector m_GatekeeperConnector; | ||
40 | |||
41 | private string m_DefaultRegionName; | ||
42 | private string m_WelcomeMessage; | ||
43 | private bool m_RequireInventory; | ||
44 | private int m_MinLoginLevel; | ||
45 | private string m_GatekeeperURL; | ||
46 | |||
47 | IConfig m_LoginServerConfig; | ||
48 | |||
49 | public LLLoginService(IConfigSource config, ISimulationService simService, ILibraryService libraryService) | ||
50 | { | ||
51 | m_LoginServerConfig = config.Configs["LoginService"]; | ||
52 | if (m_LoginServerConfig == null) | ||
53 | throw new Exception(String.Format("No section LoginService in config file")); | ||
54 | |||
55 | string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty); | ||
56 | string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty); | ||
57 | string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty); | ||
58 | string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty); | ||
59 | string gridService = m_LoginServerConfig.GetString("GridService", String.Empty); | ||
60 | string presenceService = m_LoginServerConfig.GetString("PresenceService", String.Empty); | ||
61 | string libService = m_LoginServerConfig.GetString("LibraryService", String.Empty); | ||
62 | string friendsService = m_LoginServerConfig.GetString("FriendsService", String.Empty); | ||
63 | string avatarService = m_LoginServerConfig.GetString("AvatarService", String.Empty); | ||
64 | string simulationService = m_LoginServerConfig.GetString("SimulationService", String.Empty); | ||
65 | |||
66 | m_DefaultRegionName = m_LoginServerConfig.GetString("DefaultRegion", String.Empty); | ||
67 | m_WelcomeMessage = m_LoginServerConfig.GetString("WelcomeMessage", "Welcome to OpenSim!"); | ||
68 | m_RequireInventory = m_LoginServerConfig.GetBoolean("RequireInventory", true); | ||
69 | m_GatekeeperURL = m_LoginServerConfig.GetString("GatekeeperURI", string.Empty); | ||
70 | |||
71 | // These are required; the others aren't | ||
72 | if (accountService == string.Empty || authService == string.Empty) | ||
73 | throw new Exception("LoginService is missing service specifications"); | ||
74 | |||
75 | Object[] args = new Object[] { config }; | ||
76 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); | ||
77 | m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args); | ||
78 | m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args); | ||
79 | if (gridService != string.Empty) | ||
80 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
81 | if (presenceService != string.Empty) | ||
82 | m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); | ||
83 | if (avatarService != string.Empty) | ||
84 | m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args); | ||
85 | if (friendsService != string.Empty) | ||
86 | m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args); | ||
87 | if (simulationService != string.Empty) | ||
88 | m_RemoteSimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args); | ||
89 | if (agentService != string.Empty) | ||
90 | m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(agentService, args); | ||
91 | |||
92 | // | ||
93 | // deal with the services given as argument | ||
94 | // | ||
95 | m_LocalSimulationService = simService; | ||
96 | if (libraryService != null) | ||
97 | { | ||
98 | m_log.DebugFormat("[LLOGIN SERVICE]: Using LibraryService given as argument"); | ||
99 | m_LibraryService = libraryService; | ||
100 | } | ||
101 | else if (libService != string.Empty) | ||
102 | { | ||
103 | m_log.DebugFormat("[LLOGIN SERVICE]: Using instantiated LibraryService"); | ||
104 | m_LibraryService = ServerUtils.LoadPlugin<ILibraryService>(libService, args); | ||
105 | } | ||
106 | |||
107 | m_GatekeeperConnector = new GatekeeperServiceConnector(); | ||
108 | |||
109 | if (!Initialized) | ||
110 | { | ||
111 | Initialized = true; | ||
112 | RegisterCommands(); | ||
113 | } | ||
114 | |||
115 | m_log.DebugFormat("[LLOGIN SERVICE]: Starting..."); | ||
116 | |||
117 | } | ||
118 | |||
119 | public LLLoginService(IConfigSource config) : this(config, null, null) | ||
120 | { | ||
121 | } | ||
122 | |||
123 | public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, IPEndPoint clientIP) | ||
124 | { | ||
125 | bool success = false; | ||
126 | UUID session = UUID.Random(); | ||
127 | |||
128 | try | ||
129 | { | ||
130 | // | ||
131 | // Get the account and check that it exists | ||
132 | // | ||
133 | UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName); | ||
134 | if (account == null) | ||
135 | { | ||
136 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: user not found"); | ||
137 | return LLFailedLoginResponse.UserProblem; | ||
138 | } | ||
139 | |||
140 | if (account.UserLevel < m_MinLoginLevel) | ||
141 | { | ||
142 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel); | ||
143 | return LLFailedLoginResponse.LoginBlockedProblem; | ||
144 | } | ||
145 | |||
146 | // | ||
147 | // Authenticate this user | ||
148 | // | ||
149 | if (!passwd.StartsWith("$1$")) | ||
150 | passwd = "$1$" + Util.Md5Hash(passwd); | ||
151 | passwd = passwd.Remove(0, 3); //remove $1$ | ||
152 | string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); | ||
153 | UUID secureSession = UUID.Zero; | ||
154 | if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) | ||
155 | { | ||
156 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: authentication failed"); | ||
157 | return LLFailedLoginResponse.UserProblem; | ||
158 | } | ||
159 | |||
160 | // | ||
161 | // Get the user's inventory | ||
162 | // | ||
163 | if (m_RequireInventory && m_InventoryService == null) | ||
164 | { | ||
165 | m_log.WarnFormat("[LLOGIN SERVICE]: Login failed, reason: inventory service not set up"); | ||
166 | return LLFailedLoginResponse.InventoryProblem; | ||
167 | } | ||
168 | List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); | ||
169 | if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0))) | ||
170 | { | ||
171 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory"); | ||
172 | return LLFailedLoginResponse.InventoryProblem; | ||
173 | } | ||
174 | |||
175 | // | ||
176 | // Login the presence | ||
177 | // | ||
178 | PresenceInfo presence = null; | ||
179 | GridRegion home = null; | ||
180 | if (m_PresenceService != null) | ||
181 | { | ||
182 | success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); | ||
183 | if (!success) | ||
184 | { | ||
185 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence"); | ||
186 | return LLFailedLoginResponse.GridProblem; | ||
187 | } | ||
188 | |||
189 | // Get the updated presence info | ||
190 | presence = m_PresenceService.GetAgent(session); | ||
191 | |||
192 | // Get the home region | ||
193 | if ((presence.HomeRegionID != UUID.Zero) && m_GridService != null) | ||
194 | { | ||
195 | home = m_GridService.GetRegionByUUID(account.ScopeID, presence.HomeRegionID); | ||
196 | } | ||
197 | } | ||
198 | |||
199 | // | ||
200 | // Find the destination region/grid | ||
201 | // | ||
202 | string where = string.Empty; | ||
203 | Vector3 position = Vector3.Zero; | ||
204 | Vector3 lookAt = Vector3.Zero; | ||
205 | GridRegion gatekeeper = null; | ||
206 | GridRegion destination = FindDestination(account, presence, session, startLocation, out gatekeeper, out where, out position, out lookAt); | ||
207 | if (destination == null) | ||
208 | { | ||
209 | m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt); | ||
210 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found"); | ||
211 | return LLFailedLoginResponse.GridProblem; | ||
212 | } | ||
213 | |||
214 | // | ||
215 | // Get the avatar | ||
216 | // | ||
217 | AvatarData avatar = null; | ||
218 | if (m_AvatarService != null) | ||
219 | { | ||
220 | avatar = m_AvatarService.GetAvatar(account.PrincipalID); | ||
221 | } | ||
222 | |||
223 | // | ||
224 | // Instantiate/get the simulation interface and launch an agent at the destination | ||
225 | // | ||
226 | string reason = string.Empty; | ||
227 | AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, out where, out reason); | ||
228 | |||
229 | if (aCircuit == null) | ||
230 | { | ||
231 | m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt); | ||
232 | m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason); | ||
233 | return LLFailedLoginResponse.AuthorizationProblem; | ||
234 | |||
235 | } | ||
236 | // Get Friends list | ||
237 | FriendInfo[] friendsList = new FriendInfo[0]; | ||
238 | if (m_FriendsService != null) | ||
239 | { | ||
240 | friendsList = m_FriendsService.GetFriends(account.PrincipalID); | ||
241 | m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length); | ||
242 | } | ||
243 | |||
244 | // | ||
245 | // Finally, fill out the response and return it | ||
246 | // | ||
247 | LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel, friendsList, m_LibraryService, | ||
248 | where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP); | ||
249 | |||
250 | return response; | ||
251 | } | ||
252 | catch (Exception e) | ||
253 | { | ||
254 | m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2}", firstName, lastName, e.ToString()); | ||
255 | if (m_PresenceService != null) | ||
256 | m_PresenceService.LogoutAgent(session, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); | ||
257 | return LLFailedLoginResponse.InternalError; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | private GridRegion FindDestination(UserAccount account, PresenceInfo pinfo, UUID sessionID, string startLocation, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt) | ||
262 | { | ||
263 | m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation); | ||
264 | |||
265 | gatekeeper = null; | ||
266 | where = "home"; | ||
267 | position = new Vector3(128, 128, 0); | ||
268 | lookAt = new Vector3(0, 1, 0); | ||
269 | |||
270 | if (m_GridService == null) | ||
271 | return null; | ||
272 | |||
273 | if (startLocation.Equals("home")) | ||
274 | { | ||
275 | // logging into home region | ||
276 | if (pinfo == null) | ||
277 | return null; | ||
278 | |||
279 | GridRegion region = null; | ||
280 | |||
281 | if (pinfo.HomeRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID)) == null) | ||
282 | { | ||
283 | List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID); | ||
284 | if (defaults != null && defaults.Count > 0) | ||
285 | { | ||
286 | region = defaults[0]; | ||
287 | where = "safe"; | ||
288 | } | ||
289 | else | ||
290 | m_log.WarnFormat("[LLOGIN SERVICE]: User {0} {1} does not have a home set and this grid does not have default locations.", | ||
291 | account.FirstName, account.LastName); | ||
292 | } | ||
293 | |||
294 | return region; | ||
295 | } | ||
296 | else if (startLocation.Equals("last")) | ||
297 | { | ||
298 | // logging into last visited region | ||
299 | where = "last"; | ||
300 | |||
301 | if (pinfo == null) | ||
302 | return null; | ||
303 | |||
304 | GridRegion region = null; | ||
305 | |||
306 | if (pinfo.RegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.RegionID)) == null) | ||
307 | { | ||
308 | List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID); | ||
309 | if (defaults != null && defaults.Count > 0) | ||
310 | { | ||
311 | region = defaults[0]; | ||
312 | where = "safe"; | ||
313 | } | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | position = pinfo.Position; | ||
318 | lookAt = pinfo.LookAt; | ||
319 | } | ||
320 | return region; | ||
321 | |||
322 | } | ||
323 | else | ||
324 | { | ||
325 | // free uri form | ||
326 | // e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34 | ||
327 | where = "url"; | ||
328 | Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); | ||
329 | Match uriMatch = reURI.Match(startLocation); | ||
330 | if (uriMatch == null) | ||
331 | { | ||
332 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation); | ||
333 | return null; | ||
334 | } | ||
335 | else | ||
336 | { | ||
337 | position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), | ||
338 | float.Parse(uriMatch.Groups["y"].Value), | ||
339 | float.Parse(uriMatch.Groups["z"].Value)); | ||
340 | |||
341 | string regionName = uriMatch.Groups["region"].ToString(); | ||
342 | if (regionName != null) | ||
343 | { | ||
344 | if (!regionName.Contains("@")) | ||
345 | { | ||
346 | |||
347 | List<GridRegion> regions = m_GridService.GetRegionsByName(account.ScopeID, regionName, 1); | ||
348 | if ((regions == null) || (regions != null && regions.Count == 0)) | ||
349 | { | ||
350 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName); | ||
351 | regions = m_GridService.GetDefaultRegions(UUID.Zero); | ||
352 | if (regions != null && regions.Count > 0) | ||
353 | { | ||
354 | where = "safe"; | ||
355 | return regions[0]; | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions.", startLocation); | ||
360 | return null; | ||
361 | } | ||
362 | } | ||
363 | return regions[0]; | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | if (m_UserAgentService == null) | ||
368 | { | ||
369 | m_log.WarnFormat("[LLLOGIN SERVICE]: This llogin service is not running a user agent service, as such it can't lauch agents at foreign grids"); | ||
370 | return null; | ||
371 | } | ||
372 | string[] parts = regionName.Split(new char[] { '@' }); | ||
373 | if (parts.Length < 2) | ||
374 | { | ||
375 | m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName); | ||
376 | return null; | ||
377 | } | ||
378 | // Valid specification of a remote grid | ||
379 | regionName = parts[0]; | ||
380 | string domainLocator = parts[1]; | ||
381 | parts = domainLocator.Split(new char[] {':'}); | ||
382 | string domainName = parts[0]; | ||
383 | uint port = 0; | ||
384 | if (parts.Length > 1) | ||
385 | UInt32.TryParse(parts[1], out port); | ||
386 | GridRegion region = FindForeignRegion(domainName, port, regionName, out gatekeeper); | ||
387 | return region; | ||
388 | } | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID); | ||
393 | if (defaults != null && defaults.Count > 0) | ||
394 | { | ||
395 | where = "safe"; | ||
396 | return defaults[0]; | ||
397 | } | ||
398 | else | ||
399 | return null; | ||
400 | } | ||
401 | } | ||
402 | //response.LookAt = "[r0,r1,r0]"; | ||
403 | //// can be: last, home, safe, url | ||
404 | //response.StartLocation = "url"; | ||
405 | |||
406 | } | ||
407 | |||
408 | } | ||
409 | |||
410 | private GridRegion FindForeignRegion(string domainName, uint port, string regionName, out GridRegion gatekeeper) | ||
411 | { | ||
412 | gatekeeper = new GridRegion(); | ||
413 | gatekeeper.ExternalHostName = domainName; | ||
414 | gatekeeper.HttpPort = port; | ||
415 | gatekeeper.RegionName = regionName; | ||
416 | gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); | ||
417 | |||
418 | UUID regionID; | ||
419 | ulong handle; | ||
420 | string imageURL = string.Empty, reason = string.Empty; | ||
421 | if (m_GatekeeperConnector.LinkRegion(gatekeeper, out regionID, out handle, out domainName, out imageURL, out reason)) | ||
422 | { | ||
423 | GridRegion destination = m_GatekeeperConnector.GetHyperlinkRegion(gatekeeper, regionID); | ||
424 | return destination; | ||
425 | } | ||
426 | |||
427 | return null; | ||
428 | } | ||
429 | |||
430 | private string hostName = string.Empty; | ||
431 | private int port = 0; | ||
432 | |||
433 | private void SetHostAndPort(string url) | ||
434 | { | ||
435 | try | ||
436 | { | ||
437 | Uri uri = new Uri(url); | ||
438 | hostName = uri.Host; | ||
439 | port = uri.Port; | ||
440 | } | ||
441 | catch | ||
442 | { | ||
443 | m_log.WarnFormat("[LLLogin SERVICE]: Unable to parse GatekeeperURL {0}", url); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | private AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarData avatar, | ||
448 | UUID session, UUID secureSession, Vector3 position, string currentWhere, out string where, out string reason) | ||
449 | { | ||
450 | where = currentWhere; | ||
451 | ISimulationService simConnector = null; | ||
452 | reason = string.Empty; | ||
453 | uint circuitCode = 0; | ||
454 | AgentCircuitData aCircuit = null; | ||
455 | |||
456 | if (m_UserAgentService == null) | ||
457 | { | ||
458 | // HG standalones have both a localSimulatonDll and a remoteSimulationDll | ||
459 | // non-HG standalones have just a localSimulationDll | ||
460 | // independent login servers have just a remoteSimulationDll | ||
461 | if (m_LocalSimulationService != null) | ||
462 | simConnector = m_LocalSimulationService; | ||
463 | else if (m_RemoteSimulationService != null) | ||
464 | simConnector = m_RemoteSimulationService; | ||
465 | } | ||
466 | else // User Agent Service is on | ||
467 | { | ||
468 | if (gatekeeper == null) // login to local grid | ||
469 | { | ||
470 | if (hostName == string.Empty) | ||
471 | SetHostAndPort(m_GatekeeperURL); | ||
472 | |||
473 | gatekeeper = new GridRegion(destination); | ||
474 | gatekeeper.ExternalHostName = hostName; | ||
475 | gatekeeper.HttpPort = (uint)port; | ||
476 | |||
477 | } | ||
478 | else // login to foreign grid | ||
479 | { | ||
480 | } | ||
481 | } | ||
482 | |||
483 | bool success = false; | ||
484 | |||
485 | if (m_UserAgentService == null && simConnector != null) | ||
486 | { | ||
487 | circuitCode = (uint)Util.RandomClass.Next(); ; | ||
488 | aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position); | ||
489 | success = LaunchAgentDirectly(simConnector, destination, aCircuit, out reason); | ||
490 | if (!success && m_GridService != null) | ||
491 | { | ||
492 | // Try the fallback regions | ||
493 | List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY); | ||
494 | if (fallbacks != null) | ||
495 | { | ||
496 | foreach (GridRegion r in fallbacks) | ||
497 | { | ||
498 | success = LaunchAgentDirectly(simConnector, r, aCircuit, out reason); | ||
499 | if (success) | ||
500 | { | ||
501 | where = "safe"; | ||
502 | destination = r; | ||
503 | break; | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | } | ||
509 | |||
510 | if (m_UserAgentService != null) | ||
511 | { | ||
512 | circuitCode = (uint)Util.RandomClass.Next(); ; | ||
513 | aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position); | ||
514 | success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, out reason); | ||
515 | if (!success && m_GridService != null) | ||
516 | { | ||
517 | // Try the fallback regions | ||
518 | List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY); | ||
519 | if (fallbacks != null) | ||
520 | { | ||
521 | foreach (GridRegion r in fallbacks) | ||
522 | { | ||
523 | success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, out reason); | ||
524 | if (success) | ||
525 | { | ||
526 | where = "safe"; | ||
527 | destination = r; | ||
528 | break; | ||
529 | } | ||
530 | } | ||
531 | } | ||
532 | } | ||
533 | } | ||
534 | |||
535 | if (success) | ||
536 | return aCircuit; | ||
537 | else | ||
538 | return null; | ||
539 | } | ||
540 | |||
541 | private AgentCircuitData MakeAgent(GridRegion region, UserAccount account, | ||
542 | AvatarData avatar, UUID session, UUID secureSession, uint circuit, Vector3 position) | ||
543 | { | ||
544 | AgentCircuitData aCircuit = new AgentCircuitData(); | ||
545 | |||
546 | aCircuit.AgentID = account.PrincipalID; | ||
547 | if (avatar != null) | ||
548 | aCircuit.Appearance = avatar.ToAvatarAppearance(account.PrincipalID); | ||
549 | else | ||
550 | aCircuit.Appearance = new AvatarAppearance(account.PrincipalID); | ||
551 | |||
552 | //aCircuit.BaseFolder = irrelevant | ||
553 | aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
554 | aCircuit.child = false; // the first login agent is root | ||
555 | aCircuit.ChildrenCapSeeds = new Dictionary<ulong, string>(); | ||
556 | aCircuit.circuitcode = circuit; | ||
557 | aCircuit.firstname = account.FirstName; | ||
558 | //aCircuit.InventoryFolder = irrelevant | ||
559 | aCircuit.lastname = account.LastName; | ||
560 | aCircuit.SecureSessionID = secureSession; | ||
561 | aCircuit.SessionID = session; | ||
562 | aCircuit.startpos = position; | ||
563 | SetServiceURLs(aCircuit, account); | ||
564 | |||
565 | return aCircuit; | ||
566 | |||
567 | //m_UserAgentService.LoginAgentToGrid(aCircuit, GatekeeperServiceConnector, region, out reason); | ||
568 | //if (simConnector.CreateAgent(region, aCircuit, 0, out reason)) | ||
569 | // return aCircuit; | ||
570 | |||
571 | //return null; | ||
572 | |||
573 | } | ||
574 | |||
575 | private void SetServiceURLs(AgentCircuitData aCircuit, UserAccount account) | ||
576 | { | ||
577 | aCircuit.ServiceURLs = new Dictionary<string, object>(); | ||
578 | if (account.ServiceURLs == null) | ||
579 | return; | ||
580 | |||
581 | foreach (KeyValuePair<string, object> kvp in account.ServiceURLs) | ||
582 | { | ||
583 | if (kvp.Value == null || (kvp.Value != null && kvp.Value.ToString() == string.Empty)) | ||
584 | { | ||
585 | aCircuit.ServiceURLs[kvp.Key] = m_LoginServerConfig.GetString(kvp.Key, string.Empty); | ||
586 | } | ||
587 | else | ||
588 | { | ||
589 | aCircuit.ServiceURLs[kvp.Key] = kvp.Value; | ||
590 | } | ||
591 | } | ||
592 | } | ||
593 | |||
594 | private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, out string reason) | ||
595 | { | ||
596 | return simConnector.CreateAgent(region, aCircuit, (int)Constants.TeleportFlags.ViaLogin, out reason); | ||
597 | } | ||
598 | |||
599 | private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, out string reason) | ||
600 | { | ||
601 | m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName); | ||
602 | return m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason); | ||
603 | } | ||
604 | |||
605 | #region Console Commands | ||
606 | private void RegisterCommands() | ||
607 | { | ||
608 | //MainConsole.Instance.Commands.AddCommand | ||
609 | MainConsole.Instance.Commands.AddCommand("loginservice", false, "login level", | ||
610 | "login level <level>", | ||
611 | "Set the minimum user level to log in", HandleLoginCommand); | ||
612 | |||
613 | MainConsole.Instance.Commands.AddCommand("loginservice", false, "login reset", | ||
614 | "login reset", | ||
615 | "Reset the login level to allow all users", | ||
616 | HandleLoginCommand); | ||
617 | |||
618 | MainConsole.Instance.Commands.AddCommand("loginservice", false, "login text", | ||
619 | "login text <text>", | ||
620 | "Set the text users will see on login", HandleLoginCommand); | ||
621 | |||
622 | } | ||
623 | |||
624 | private void HandleLoginCommand(string module, string[] cmd) | ||
625 | { | ||
626 | string subcommand = cmd[1]; | ||
627 | |||
628 | switch (subcommand) | ||
629 | { | ||
630 | case "level": | ||
631 | // Set the minimum level to allow login | ||
632 | // Useful to allow grid update without worrying about users. | ||
633 | // or fixing critical issues | ||
634 | // | ||
635 | if (cmd.Length > 2) | ||
636 | Int32.TryParse(cmd[2], out m_MinLoginLevel); | ||
637 | break; | ||
638 | case "reset": | ||
639 | m_MinLoginLevel = 0; | ||
640 | break; | ||
641 | case "text": | ||
642 | if (cmd.Length > 2) | ||
643 | m_WelcomeMessage = cmd[2]; | ||
644 | break; | ||
645 | } | ||
646 | } | ||
647 | } | ||
648 | |||
649 | #endregion | ||
650 | } | ||
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs index 2157462..1a31965 100644 --- a/OpenSim/Services/PresenceService/PresenceService.cs +++ b/OpenSim/Services/PresenceService/PresenceService.cs | |||
@@ -41,27 +41,178 @@ namespace OpenSim.Services.PresenceService | |||
41 | { | 41 | { |
42 | public class PresenceService : PresenceServiceBase, IPresenceService | 42 | public class PresenceService : PresenceServiceBase, IPresenceService |
43 | { | 43 | { |
44 | // private static readonly ILog m_log = | 44 | private static readonly ILog m_log = |
45 | // LogManager.GetLogger( | 45 | LogManager.GetLogger( |
46 | // MethodBase.GetCurrentMethod().DeclaringType); | 46 | MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | public PresenceService(IConfigSource config) | 48 | public PresenceService(IConfigSource config) |
49 | : base(config) | 49 | : base(config) |
50 | { | 50 | { |
51 | m_log.Debug("[PRESENCE SERVICE]: Starting presence service"); | ||
51 | } | 52 | } |
52 | 53 | ||
53 | public bool Report(PresenceInfo presence) | 54 | public bool LoginAgent(string userID, UUID sessionID, |
55 | UUID secureSessionID) | ||
54 | { | 56 | { |
55 | PresenceData p = new PresenceData(); | 57 | m_Database.Prune(userID); |
56 | p.Data = new Dictionary<string, string>(); | ||
57 | 58 | ||
58 | p.UUID = presence.PrincipalID; | 59 | PresenceData[] d = m_Database.Get("UserID", userID); |
59 | p.currentRegion = presence.RegionID; | ||
60 | 60 | ||
61 | foreach (KeyValuePair<string, string> kvp in presence.Data) | 61 | PresenceData data = new PresenceData(); |
62 | p.Data[kvp.Key] = kvp.Value; | ||
63 | 62 | ||
64 | return false; | 63 | data.UserID = userID; |
64 | data.RegionID = UUID.Zero; | ||
65 | data.SessionID = sessionID; | ||
66 | data.Data = new Dictionary<string, string>(); | ||
67 | data.Data["SecureSessionID"] = secureSessionID.ToString(); | ||
68 | data.Data["Online"] = "true"; | ||
69 | data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); | ||
70 | if (d != null && d.Length > 0) | ||
71 | { | ||
72 | data.Data["HomeRegionID"] = d[0].Data["HomeRegionID"]; | ||
73 | data.Data["HomePosition"] = d[0].Data["HomePosition"]; | ||
74 | data.Data["HomeLookAt"] = d[0].Data["HomeLookAt"]; | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | data.Data["HomeRegionID"] = UUID.Zero.ToString(); | ||
79 | data.Data["HomePosition"] = new Vector3(128, 128, 0).ToString(); | ||
80 | data.Data["HomeLookAt"] = new Vector3(0, 1, 0).ToString(); | ||
81 | } | ||
82 | |||
83 | m_Database.Store(data); | ||
84 | |||
85 | m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}", | ||
86 | userID, sessionID, secureSessionID); | ||
87 | return true; | ||
88 | } | ||
89 | |||
90 | public bool LogoutAgent(UUID sessionID, Vector3 position, Vector3 lookat) | ||
91 | { | ||
92 | PresenceData data = m_Database.Get(sessionID); | ||
93 | if (data == null) | ||
94 | return false; | ||
95 | |||
96 | PresenceData[] d = m_Database.Get("UserID", data.UserID); | ||
97 | |||
98 | m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent {0} with {1} sessions currently present", data.UserID, d.Length); | ||
99 | if (d.Length > 1) | ||
100 | { | ||
101 | m_Database.Delete("UserID", data.UserID); | ||
102 | } | ||
103 | |||
104 | data.Data["Online"] = "false"; | ||
105 | data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); | ||
106 | data.Data["Position"] = position.ToString(); | ||
107 | data.Data["LookAt"] = lookat.ToString(); | ||
108 | |||
109 | m_Database.Store(data); | ||
110 | |||
111 | return true; | ||
112 | } | ||
113 | |||
114 | public bool LogoutRegionAgents(UUID regionID) | ||
115 | { | ||
116 | m_Database.LogoutRegionAgents(regionID); | ||
117 | |||
118 | return true; | ||
119 | } | ||
120 | |||
121 | |||
122 | public bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
123 | { | ||
124 | m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID); | ||
125 | try | ||
126 | { | ||
127 | PresenceData pdata = m_Database.Get(sessionID); | ||
128 | if (pdata == null) | ||
129 | return false; | ||
130 | if (pdata.Data == null) | ||
131 | return false; | ||
132 | |||
133 | if (!pdata.Data.ContainsKey("Online") || (pdata.Data.ContainsKey("Online") && pdata.Data["Online"] == "false")) | ||
134 | { | ||
135 | m_log.WarnFormat("[PRESENCE SERVICE]: Someone tried to report presence of an agent who's not online"); | ||
136 | return false; | ||
137 | } | ||
138 | |||
139 | return m_Database.ReportAgent(sessionID, regionID, | ||
140 | position.ToString(), lookAt.ToString()); | ||
141 | } | ||
142 | catch (Exception e) | ||
143 | { | ||
144 | m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace); | ||
145 | return false; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | public PresenceInfo GetAgent(UUID sessionID) | ||
150 | { | ||
151 | PresenceInfo ret = new PresenceInfo(); | ||
152 | |||
153 | PresenceData data = m_Database.Get(sessionID); | ||
154 | if (data == null) | ||
155 | return null; | ||
156 | |||
157 | ret.UserID = data.UserID; | ||
158 | ret.RegionID = data.RegionID; | ||
159 | if (data.Data.ContainsKey("Online")) | ||
160 | ret.Online = bool.Parse(data.Data["Online"]); | ||
161 | if (data.Data.ContainsKey("Login")) | ||
162 | ret.Login = Util.ToDateTime(Convert.ToInt32(data.Data["Login"])); | ||
163 | if (data.Data.ContainsKey("Logout")) | ||
164 | ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"])); | ||
165 | if (data.Data.ContainsKey("Position")) | ||
166 | ret.Position = Vector3.Parse(data.Data["Position"]); | ||
167 | if (data.Data.ContainsKey("LookAt")) | ||
168 | ret.LookAt = Vector3.Parse(data.Data["LookAt"]); | ||
169 | if (data.Data.ContainsKey("HomeRegionID")) | ||
170 | ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]); | ||
171 | if (data.Data.ContainsKey("HomePosition")) | ||
172 | ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]); | ||
173 | if (data.Data.ContainsKey("HomeLookAt")) | ||
174 | ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]); | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | public PresenceInfo[] GetAgents(string[] userIDs) | ||
180 | { | ||
181 | List<PresenceInfo> info = new List<PresenceInfo>(); | ||
182 | |||
183 | foreach (string userIDStr in userIDs) | ||
184 | { | ||
185 | PresenceData[] data = m_Database.Get("UserID", | ||
186 | userIDStr); | ||
187 | |||
188 | foreach (PresenceData d in data) | ||
189 | { | ||
190 | PresenceInfo ret = new PresenceInfo(); | ||
191 | |||
192 | ret.UserID = d.UserID; | ||
193 | ret.RegionID = d.RegionID; | ||
194 | ret.Online = bool.Parse(d.Data["Online"]); | ||
195 | ret.Login = Util.ToDateTime(Convert.ToInt32( | ||
196 | d.Data["Login"])); | ||
197 | ret.Logout = Util.ToDateTime(Convert.ToInt32( | ||
198 | d.Data["Logout"])); | ||
199 | ret.Position = Vector3.Parse(d.Data["Position"]); | ||
200 | ret.LookAt = Vector3.Parse(d.Data["LookAt"]); | ||
201 | ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]); | ||
202 | ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]); | ||
203 | ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); | ||
204 | |||
205 | info.Add(ret); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | m_log.DebugFormat("[PRESENCE SERVICE]: GetAgents for {0} userIDs found {1} presences", userIDs.Length, info.Count); | ||
210 | return info.ToArray(); | ||
211 | } | ||
212 | |||
213 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
214 | { | ||
215 | return m_Database.SetHomeLocation(userID, regionID, position, lookAt); | ||
65 | } | 216 | } |
66 | } | 217 | } |
67 | } | 218 | } |
diff --git a/OpenSim/Services/PresenceService/PresenceServiceBase.cs b/OpenSim/Services/PresenceService/PresenceServiceBase.cs index 60a246b..a4adb2f 100644 --- a/OpenSim/Services/PresenceService/PresenceServiceBase.cs +++ b/OpenSim/Services/PresenceService/PresenceServiceBase.cs | |||
@@ -44,7 +44,7 @@ namespace OpenSim.Services.PresenceService | |||
44 | { | 44 | { |
45 | string dllName = String.Empty; | 45 | string dllName = String.Empty; |
46 | string connString = String.Empty; | 46 | string connString = String.Empty; |
47 | string realm = "agents"; | 47 | string realm = "Presence"; |
48 | 48 | ||
49 | // | 49 | // |
50 | // Try reading the [DatabaseService] section, if it exists | 50 | // Try reading the [DatabaseService] section, if it exists |
@@ -77,7 +77,7 @@ namespace OpenSim.Services.PresenceService | |||
77 | 77 | ||
78 | m_Database = LoadPlugin<IPresenceData>(dllName, new Object[] { connString, realm }); | 78 | m_Database = LoadPlugin<IPresenceData>(dllName, new Object[] { connString, realm }); |
79 | if (m_Database == null) | 79 | if (m_Database == null) |
80 | throw new Exception("Could not find a storage interface in the given module"); | 80 | throw new Exception("Could not find a storage interface in the given module " + dllName); |
81 | 81 | ||
82 | } | 82 | } |
83 | } | 83 | } |
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs new file mode 100644 index 0000000..e498bd5 --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs | |||
@@ -0,0 +1,362 @@ | |||
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 Nini.Config; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Services.UserAccountService | ||
41 | { | ||
42 | public class UserAccountService : UserAccountServiceBase, IUserAccountService | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | private static UserAccountService m_RootInstance; | ||
46 | |||
47 | protected IGridService m_GridService; | ||
48 | protected IAuthenticationService m_AuthenticationService; | ||
49 | protected IPresenceService m_PresenceService; | ||
50 | protected IInventoryService m_InventoryService; | ||
51 | |||
52 | public UserAccountService(IConfigSource config) | ||
53 | : base(config) | ||
54 | { | ||
55 | IConfig userConfig = config.Configs["UserAccountService"]; | ||
56 | if (userConfig == null) | ||
57 | throw new Exception("No UserAccountService configuration"); | ||
58 | |||
59 | // In case there are several instances of this class in the same process, | ||
60 | // the console commands are only registered for the root instance | ||
61 | if (m_RootInstance == null) | ||
62 | { | ||
63 | m_RootInstance = this; | ||
64 | string gridServiceDll = userConfig.GetString("GridService", string.Empty); | ||
65 | if (gridServiceDll != string.Empty) | ||
66 | m_GridService = LoadPlugin<IGridService>(gridServiceDll, new Object[] { config }); | ||
67 | |||
68 | string authServiceDll = userConfig.GetString("AuthenticationService", string.Empty); | ||
69 | if (authServiceDll != string.Empty) | ||
70 | m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config }); | ||
71 | |||
72 | string presenceServiceDll = userConfig.GetString("PresenceService", string.Empty); | ||
73 | if (presenceServiceDll != string.Empty) | ||
74 | m_PresenceService = LoadPlugin<IPresenceService>(presenceServiceDll, new Object[] { config }); | ||
75 | |||
76 | string invServiceDll = userConfig.GetString("InventoryService", string.Empty); | ||
77 | if (invServiceDll != string.Empty) | ||
78 | m_InventoryService = LoadPlugin<IInventoryService>(invServiceDll, new Object[] { config }); | ||
79 | |||
80 | if (MainConsole.Instance != null) | ||
81 | { | ||
82 | MainConsole.Instance.Commands.AddCommand("UserService", false, | ||
83 | "create user", | ||
84 | "create user [<first> [<last> [<pass> [<email>]]]]", | ||
85 | "Create a new user", HandleCreateUser); | ||
86 | MainConsole.Instance.Commands.AddCommand("UserService", false, "reset user password", | ||
87 | "reset user password [<first> [<last> [<password>]]]", | ||
88 | "Reset a user password", HandleResetUserPassword); | ||
89 | } | ||
90 | |||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | #region IUserAccountService | ||
96 | |||
97 | public UserAccount GetUserAccount(UUID scopeID, string firstName, | ||
98 | string lastName) | ||
99 | { | ||
100 | UserAccountData[] d; | ||
101 | |||
102 | if (scopeID != UUID.Zero) | ||
103 | { | ||
104 | d = m_Database.Get( | ||
105 | new string[] { "ScopeID", "FirstName", "LastName" }, | ||
106 | new string[] { scopeID.ToString(), firstName, lastName }); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | d = m_Database.Get( | ||
111 | new string[] { "FirstName", "LastName" }, | ||
112 | new string[] { firstName, lastName }); | ||
113 | } | ||
114 | |||
115 | if (d.Length < 1) | ||
116 | return null; | ||
117 | |||
118 | return MakeUserAccount(d[0]); | ||
119 | } | ||
120 | |||
121 | private UserAccount MakeUserAccount(UserAccountData d) | ||
122 | { | ||
123 | UserAccount u = new UserAccount(); | ||
124 | u.FirstName = d.FirstName; | ||
125 | u.LastName = d.LastName; | ||
126 | u.PrincipalID = d.PrincipalID; | ||
127 | u.ScopeID = d.ScopeID; | ||
128 | if (d.Data.ContainsKey("Email") && d.Data["Email"] != null) | ||
129 | u.Email = d.Data["Email"].ToString(); | ||
130 | else | ||
131 | u.Email = string.Empty; | ||
132 | u.Created = Convert.ToInt32(d.Data["Created"].ToString()); | ||
133 | if (d.Data.ContainsKey("UserTitle") && d.Data["UserTitle"] != null) | ||
134 | u.UserTitle = d.Data["UserTitle"].ToString(); | ||
135 | else | ||
136 | u.UserTitle = string.Empty; | ||
137 | |||
138 | if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null) | ||
139 | { | ||
140 | string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' }); | ||
141 | u.ServiceURLs = new Dictionary<string, object>(); | ||
142 | |||
143 | foreach (string url in URLs) | ||
144 | { | ||
145 | string[] parts = url.Split(new char[] { '=' }); | ||
146 | |||
147 | if (parts.Length != 2) | ||
148 | continue; | ||
149 | |||
150 | string name = System.Web.HttpUtility.UrlDecode(parts[0]); | ||
151 | string val = System.Web.HttpUtility.UrlDecode(parts[1]); | ||
152 | |||
153 | u.ServiceURLs[name] = val; | ||
154 | } | ||
155 | } | ||
156 | else | ||
157 | u.ServiceURLs = new Dictionary<string, object>(); | ||
158 | |||
159 | return u; | ||
160 | } | ||
161 | |||
162 | public UserAccount GetUserAccount(UUID scopeID, string email) | ||
163 | { | ||
164 | UserAccountData[] d; | ||
165 | |||
166 | if (scopeID != UUID.Zero) | ||
167 | { | ||
168 | d = m_Database.Get( | ||
169 | new string[] { "ScopeID", "Email" }, | ||
170 | new string[] { scopeID.ToString(), email }); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | d = m_Database.Get( | ||
175 | new string[] { "Email" }, | ||
176 | new string[] { email }); | ||
177 | } | ||
178 | |||
179 | if (d.Length < 1) | ||
180 | return null; | ||
181 | |||
182 | return MakeUserAccount(d[0]); | ||
183 | } | ||
184 | |||
185 | public UserAccount GetUserAccount(UUID scopeID, UUID principalID) | ||
186 | { | ||
187 | UserAccountData[] d; | ||
188 | |||
189 | if (scopeID != UUID.Zero) | ||
190 | { | ||
191 | d = m_Database.Get( | ||
192 | new string[] { "ScopeID", "PrincipalID" }, | ||
193 | new string[] { scopeID.ToString(), principalID.ToString() }); | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | d = m_Database.Get( | ||
198 | new string[] { "PrincipalID" }, | ||
199 | new string[] { principalID.ToString() }); | ||
200 | } | ||
201 | |||
202 | if (d.Length < 1) | ||
203 | return null; | ||
204 | |||
205 | return MakeUserAccount(d[0]); | ||
206 | } | ||
207 | |||
208 | public bool StoreUserAccount(UserAccount data) | ||
209 | { | ||
210 | UserAccountData d = new UserAccountData(); | ||
211 | |||
212 | d.FirstName = data.FirstName; | ||
213 | d.LastName = data.LastName; | ||
214 | d.PrincipalID = data.PrincipalID; | ||
215 | d.ScopeID = data.ScopeID; | ||
216 | d.Data = new Dictionary<string, string>(); | ||
217 | d.Data["Email"] = data.Email; | ||
218 | d.Data["Created"] = data.Created.ToString(); | ||
219 | |||
220 | List<string> parts = new List<string>(); | ||
221 | |||
222 | foreach (KeyValuePair<string, object> kvp in data.ServiceURLs) | ||
223 | { | ||
224 | string key = System.Web.HttpUtility.UrlEncode(kvp.Key); | ||
225 | string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); | ||
226 | parts.Add(key + "=" + val); | ||
227 | } | ||
228 | |||
229 | d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray()); | ||
230 | |||
231 | return m_Database.Store(d); | ||
232 | } | ||
233 | |||
234 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
235 | { | ||
236 | UserAccountData[] d = m_Database.GetUsers(scopeID, query); | ||
237 | |||
238 | if (d == null) | ||
239 | return new List<UserAccount>(); | ||
240 | |||
241 | List<UserAccount> ret = new List<UserAccount>(); | ||
242 | |||
243 | foreach (UserAccountData data in d) | ||
244 | ret.Add(MakeUserAccount(data)); | ||
245 | |||
246 | return ret; | ||
247 | } | ||
248 | |||
249 | #endregion | ||
250 | |||
251 | #region Console commands | ||
252 | /// <summary> | ||
253 | /// Create a new user | ||
254 | /// </summary> | ||
255 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
256 | protected void HandleCreateUser(string module, string[] cmdparams) | ||
257 | { | ||
258 | string firstName; | ||
259 | string lastName; | ||
260 | string password; | ||
261 | string email; | ||
262 | |||
263 | if (cmdparams.Length < 3) | ||
264 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||
265 | else firstName = cmdparams[2]; | ||
266 | |||
267 | if (cmdparams.Length < 4) | ||
268 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||
269 | else lastName = cmdparams[3]; | ||
270 | |||
271 | if (cmdparams.Length < 5) | ||
272 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
273 | else password = cmdparams[4]; | ||
274 | |||
275 | if (cmdparams.Length < 6) | ||
276 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
277 | else email = cmdparams[5]; | ||
278 | |||
279 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
280 | if (null == account) | ||
281 | { | ||
282 | account = new UserAccount(UUID.Zero, firstName, lastName, email); | ||
283 | if (StoreUserAccount(account)) | ||
284 | { | ||
285 | bool success = false; | ||
286 | if (m_AuthenticationService != null) | ||
287 | success = m_AuthenticationService.SetPassword(account.PrincipalID, password); | ||
288 | if (!success) | ||
289 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.", | ||
290 | firstName, lastName); | ||
291 | |||
292 | GridRegion home = null; | ||
293 | if (m_GridService != null) | ||
294 | { | ||
295 | List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero); | ||
296 | if (defaultRegions != null && defaultRegions.Count >= 1) | ||
297 | home = defaultRegions[0]; | ||
298 | |||
299 | if (m_PresenceService != null && home != null) | ||
300 | m_PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); | ||
301 | else | ||
302 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", | ||
303 | firstName, lastName); | ||
304 | |||
305 | } | ||
306 | else | ||
307 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", | ||
308 | firstName, lastName); | ||
309 | |||
310 | if (m_InventoryService != null) | ||
311 | success = m_InventoryService.CreateUserInventory(account.PrincipalID); | ||
312 | if (!success) | ||
313 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.", | ||
314 | firstName, lastName); | ||
315 | |||
316 | |||
317 | m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", firstName, lastName); | ||
318 | } | ||
319 | } | ||
320 | else | ||
321 | { | ||
322 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
323 | } | ||
324 | |||
325 | } | ||
326 | |||
327 | protected void HandleResetUserPassword(string module, string[] cmdparams) | ||
328 | { | ||
329 | string firstName; | ||
330 | string lastName; | ||
331 | string newPassword; | ||
332 | |||
333 | if (cmdparams.Length < 4) | ||
334 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
335 | else firstName = cmdparams[3]; | ||
336 | |||
337 | if (cmdparams.Length < 5) | ||
338 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
339 | else lastName = cmdparams[4]; | ||
340 | |||
341 | if (cmdparams.Length < 6) | ||
342 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
343 | else newPassword = cmdparams[5]; | ||
344 | |||
345 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
346 | if (account == null) | ||
347 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: No such user"); | ||
348 | |||
349 | bool success = false; | ||
350 | if (m_AuthenticationService != null) | ||
351 | success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword); | ||
352 | if (!success) | ||
353 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Unable to reset password for account {0} {1}.", | ||
354 | firstName, lastName); | ||
355 | else | ||
356 | m_log.InfoFormat("[USER ACCOUNT SERVICE]: Password reset for user {0} {1}", firstName, lastName); | ||
357 | } | ||
358 | |||
359 | #endregion | ||
360 | |||
361 | } | ||
362 | } | ||
diff --git a/OpenSim/Services/UserService/UserServiceBase.cs b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs index fea8b01..c1a7b76 100644 --- a/OpenSim/Services/UserService/UserServiceBase.cs +++ b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs | |||
@@ -40,20 +40,29 @@ namespace OpenSim.Services.UserAccountService | |||
40 | 40 | ||
41 | public UserAccountServiceBase(IConfigSource config) : base(config) | 41 | public UserAccountServiceBase(IConfigSource config) : base(config) |
42 | { | 42 | { |
43 | string dllName = String.Empty; | ||
44 | string connString = String.Empty; | ||
45 | string realm = "UserAccounts"; | ||
46 | |||
47 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
48 | if (dbConfig != null) | ||
49 | { | ||
50 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
51 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
52 | } | ||
53 | |||
43 | IConfig userConfig = config.Configs["UserAccountService"]; | 54 | IConfig userConfig = config.Configs["UserAccountService"]; |
44 | if (userConfig == null) | 55 | if (userConfig == null) |
45 | throw new Exception("No UserAccountService configuration"); | 56 | throw new Exception("No UserAccountService configuration"); |
46 | 57 | ||
47 | string dllName = userConfig.GetString("StorageProvider", | 58 | dllName = userConfig.GetString("StorageProvider", dllName); |
48 | String.Empty); | ||
49 | 59 | ||
50 | if (dllName == String.Empty) | 60 | if (dllName == String.Empty) |
51 | throw new Exception("No StorageProvider configured"); | 61 | throw new Exception("No StorageProvider configured"); |
52 | 62 | ||
53 | string connString = userConfig.GetString("ConnectionString", | 63 | connString = userConfig.GetString("ConnectionString", connString); |
54 | String.Empty); | ||
55 | 64 | ||
56 | string realm = userConfig.GetString("Realm", "users"); | 65 | realm = userConfig.GetString("Realm", realm); |
57 | 66 | ||
58 | m_Database = LoadPlugin<IUserAccountData>(dllName, new Object[] {connString, realm}); | 67 | m_Database = LoadPlugin<IUserAccountData>(dllName, new Object[] {connString, realm}); |
59 | 68 | ||