aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs29
-rw-r--r--OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs10
-rw-r--r--OpenSim/Services/AvatarService/AvatarService.cs144
-rw-r--r--OpenSim/Services/AvatarService/AvatarServiceBase.cs84
-rw-r--r--OpenSim/Services/Connectors/Authentication/AuthenticationServiceConnector.cs10
-rw-r--r--OpenSim/Services/Connectors/Avatar/AvatarServiceConnector.cs317
-rw-r--r--OpenSim/Services/Connectors/Grid/GridServiceConnector.cs147
-rw-r--r--OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs254
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs245
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs370
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs20
-rw-r--r--OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs423
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs596
-rw-r--r--OpenSim/Services/Connectors/User/UserServiceConnector.cs114
-rw-r--r--OpenSim/Services/Connectors/UserAccounts/UserAccountServiceConnector.cs277
-rw-r--r--OpenSim/Services/GridService/GridService.cs283
-rw-r--r--OpenSim/Services/GridService/HypergridLinker.cs632
-rw-r--r--OpenSim/Services/HypergridService/GatekeeperService.cs320
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs217
-rw-r--r--OpenSim/Services/Interfaces/IAuthenticationService.cs11
-rw-r--r--OpenSim/Services/Interfaces/IAvatarService.cs241
-rw-r--r--OpenSim/Services/Interfaces/IFriendsService.cs48
-rw-r--r--OpenSim/Services/Interfaces/IGatekeeperService.cs (renamed from OpenSim/Services/UserService/UserService.cs)59
-rw-r--r--OpenSim/Services/Interfaces/IGridService.cs17
-rw-r--r--OpenSim/Services/Interfaces/ILibraryService.cs (renamed from OpenSim/Services/Interfaces/IHyperlink.cs)22
-rw-r--r--OpenSim/Services/Interfaces/ILoginService.cs53
-rw-r--r--OpenSim/Services/Interfaces/IPresenceService.cs88
-rw-r--r--OpenSim/Services/Interfaces/ISimulationService.cs26
-rw-r--r--OpenSim/Services/Interfaces/IUserAccountService.cs153
-rw-r--r--OpenSim/Services/Interfaces/IUserService.cs103
-rw-r--r--OpenSim/Services/InventoryService/HGInventoryService.cs302
-rw-r--r--OpenSim/Services/InventoryService/InventoryService.cs1
-rw-r--r--OpenSim/Services/InventoryService/LibraryService.cs283
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs60
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginResponse.cs971
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs639
-rw-r--r--OpenSim/Services/PresenceService/PresenceService.cs172
-rw-r--r--OpenSim/Services/PresenceService/PresenceServiceBase.cs4
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountService.cs359
-rw-r--r--OpenSim/Services/UserAccountService/UserAccountServiceBase.cs (renamed from OpenSim/Services/UserService/UserServiceBase.cs)19
40 files changed, 7510 insertions, 613 deletions
diff --git a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
index dcf090e..f6dd085 100644
--- a/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
+++ b/OpenSim/Services/AuthenticationService/AuthenticationServiceBase.cs
@@ -32,6 +32,7 @@ using Nini.Config;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Services.Base; 33using OpenSim.Services.Base;
34using OpenSim.Data; 34using OpenSim.Data;
35using OpenSim.Framework;
35 36
36namespace OpenSim.Services.AuthenticationService 37namespace 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,27 @@ 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 = new AuthenticationData();
110 auth.PrincipalID = principalID;
111 auth.Data = new System.Collections.Generic.Dictionary<string, object>();
112 auth.Data["passwordHash"] = md5PasswdHash;
113 auth.Data["passwordSalt"] = passwordSalt;
114 auth.Data["webLoginKey"] = UUID.Zero.ToString();
115 if (!m_Database.Store(auth))
116 {
117 m_log.DebugFormat("[AUTHENTICATION DB]: Failed to store authentication data");
118 return false;
119 }
120
121 m_log.InfoFormat("[AUTHENTICATION DB]: Set password for principalID {0}", principalID);
122 return true;
123 }
124
103 protected string GetToken(UUID principalID, int lifetime) 125 protected string GetToken(UUID principalID, int lifetime)
104 { 126 {
105 UUID token = UUID.Random(); 127 UUID token = UUID.Random();
@@ -109,5 +131,6 @@ namespace OpenSim.Services.AuthenticationService
109 131
110 return String.Empty; 132 return String.Empty;
111 } 133 }
134
112 } 135 }
113} 136}
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
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using OpenSim.Data;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace 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
28using System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base;
35
36namespace 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/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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using IAvatarService = OpenSim.Services.Interfaces.IAvatarService;
40using OpenSim.Server.Base;
41using OpenMetaverse;
42
43namespace 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/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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Text;
32using System.Drawing;
33using System.Net;
34using System.Reflection;
35using OpenSim.Services.Interfaces;
36using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37
38using OpenSim.Framework;
39
40using OpenMetaverse;
41using OpenMetaverse.Imaging;
42using log4net;
43using Nwc.XmlRpc;
44
45namespace 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..608228d
--- /dev/null
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -0,0 +1,245 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Drawing;
5using System.Net;
6using System.Reflection;
7
8using OpenSim.Framework;
9using OpenSim.Services.Interfaces;
10using GridRegion = OpenSim.Services.Interfaces.GridRegion;
11
12using OpenMetaverse;
13using OpenMetaverse.Imaging;
14using Nwc.XmlRpc;
15using log4net;
16
17using OpenSim.Services.Connectors.Simulation;
18
19namespace 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);
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 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using System.Net;
6using System.Reflection;
7using System.Text;
8
9using OpenSim.Framework;
10using OpenSim.Services.Interfaces;
11using OpenSim.Services.Connectors.Simulation;
12using GridRegion = OpenSim.Services.Interfaces.GridRegion;
13
14using OpenMetaverse;
15using OpenMetaverse.StructuredData;
16using log4net;
17using Nwc.XmlRpc;
18using Nini.Config;
19
20namespace 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..fac3d1f
--- /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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using OpenMetaverse;
41
42namespace 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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Net;
32using System.Reflection;
33using System.Text;
34
35using OpenSim.Framework;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38
39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
41using log4net;
42using Nini.Config;
43
44namespace 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/User/UserServiceConnector.cs b/OpenSim/Services/Connectors/User/UserServiceConnector.cs
deleted file mode 100644
index 683990f..0000000
--- a/OpenSim/Services/Connectors/User/UserServiceConnector.cs
+++ /dev/null
@@ -1,114 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Services.Interfaces;
38using OpenMetaverse;
39
40namespace OpenSim.Services.Connectors
41{
42 public class UserServicesConnector : IUserAccountService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47
48// private string m_ServerURI = String.Empty;
49
50 public UserServicesConnector()
51 {
52 }
53
54 public UserServicesConnector(string serverURI)
55 {
56// m_ServerURI = serverURI.TrimEnd('/');
57 }
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 {
69 m_log.Error("[USER CONNECTOR]: UserService missing from OpanSim.ini");
70 throw new Exception("User connector init error");
71 }
72
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 }
81 //m_ServerURI = serviceURI;
82 }
83
84 public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
85 {
86 return null;
87 }
88
89 public UserAccount GetUserAccount(UUID scopeID, UUID userID)
90 {
91 return null;
92 }
93
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 }
103
104 public bool CreateUserAccount(UserAccount data, UUID principalID, string token)
105 {
106 return false;
107 }
108
109 public List<UserAccount> GetUserAccount(UUID scopeID, string query)
110 {
111 return null;
112 }
113 }
114}
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
28using log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers.HttpServer;
37using OpenSim.Server.Base;
38using OpenSim.Services.Interfaces;
39using OpenMetaverse;
40
41namespace 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/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 7749c37..4dee7a4 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -34,6 +34,7 @@ using log4net;
34using OpenSim.Framework; 34using OpenSim.Framework;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Data; 36using OpenSim.Data;
37using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion; 39using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenMetaverse; 40using OpenMetaverse;
@@ -46,17 +47,56 @@ 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 MainConsole.Instance.Commands.AddCommand("grid", true,
86 "show region",
87 "show region <Region name>",
88 "Show details on a region",
89 String.Empty,
90 HandleShowRegion);
91
92 MainConsole.Instance.Commands.AddCommand("grid", true,
93 "set region flags",
94 "set region flags <Region name> <flags>",
95 "Set database flags for region",
96 String.Empty,
97 HandleSetFlags);
98
99 m_HypergridLinker = new HypergridLinker(m_config, this, m_Database);
60 } 100 }
61 } 101 }
62 102
@@ -64,9 +104,48 @@ namespace OpenSim.Services.GridService
64 104
65 public string RegisterRegion(UUID scopeID, GridRegion regionInfos) 105 public string RegisterRegion(UUID scopeID, GridRegion regionInfos)
66 { 106 {
107 IConfig gridConfig = m_config.Configs["GridService"];
67 // This needs better sanity testing. What if regionInfo is registering in 108 // This needs better sanity testing. What if regionInfo is registering in
68 // overlapping coords? 109 // overlapping coords?
69 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID); 110 RegionData region = m_Database.Get(regionInfos.RegionLocX, regionInfos.RegionLocY, scopeID);
111 if (region != null)
112 {
113 // There is a preexisting record
114 //
115 // Get it's flags
116 //
117 OpenSim.Data.RegionFlags rflags = (OpenSim.Data.RegionFlags)Convert.ToInt32(region.Data["flags"]);
118
119 // Is this a reservation?
120 //
121 if ((rflags & OpenSim.Data.RegionFlags.Reservation) != 0)
122 {
123 // Regions reserved for the null key cannot be taken.
124 //
125 if (region.Data["PrincipalID"] == UUID.Zero.ToString())
126 return "Region location us reserved";
127
128 // Treat it as an auth request
129 //
130 // NOTE: Fudging the flags value here, so these flags
131 // should not be used elsewhere. Don't optimize
132 // this with the later retrieval of the same flags!
133 //
134 rflags |= OpenSim.Data.RegionFlags.Authenticate;
135 }
136
137 if ((rflags & OpenSim.Data.RegionFlags.Authenticate) != 0)
138 {
139 // Can we authenticate at all?
140 //
141 if (m_AuthenticationService == null)
142 return "No authentication possible";
143
144 if (!m_AuthenticationService.Verify(new UUID(region.Data["PrincipalID"].ToString()), regionInfos.Token, 30))
145 return "Bad authentication";
146 }
147 }
148
70 if ((region != null) && (region.RegionID != regionInfos.RegionID)) 149 if ((region != null) && (region.RegionID != regionInfos.RegionID))
71 { 150 {
72 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.", 151 m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register in coordinates {1}, {2} which are already in use in scope {3}.",
@@ -76,6 +155,9 @@ namespace OpenSim.Services.GridService
76 if ((region != null) && (region.RegionID == regionInfos.RegionID) && 155 if ((region != null) && (region.RegionID == regionInfos.RegionID) &&
77 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY))) 156 ((region.posX != regionInfos.RegionLocX) || (region.posY != regionInfos.RegionLocY)))
78 { 157 {
158 if ((Convert.ToInt32(region.Data["flags"]) & (int)OpenSim.Data.RegionFlags.NoMove) != 0)
159 return "Can't move this region";
160
79 // Region reregistering in other coordinates. Delete the old entry 161 // 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.", 162 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); 163 regionInfos.RegionName, regionInfos.RegionID, regionInfos.RegionLocX, regionInfos.RegionLocY);
@@ -110,8 +192,37 @@ namespace OpenSim.Services.GridService
110 // Everything is ok, let's register 192 // Everything is ok, let's register
111 RegionData rdata = RegionInfo2RegionData(regionInfos); 193 RegionData rdata = RegionInfo2RegionData(regionInfos);
112 rdata.ScopeID = scopeID; 194 rdata.ScopeID = scopeID;
195
196 if (region != null)
197 {
198 int oldFlags = Convert.ToInt32(region.Data["flags"]);
199 if ((oldFlags & (int)OpenSim.Data.RegionFlags.LockedOut) != 0)
200 return "Region locked out";
201
202 oldFlags &= ~(int)OpenSim.Data.RegionFlags.Reservation;
203
204 rdata.Data["flags"] = oldFlags.ToString(); // Preserve flags
205 }
206 else
207 {
208 rdata.Data["flags"] = "0";
209 if ((gridConfig != null) && rdata.RegionName != string.Empty)
210 {
211 int newFlags = 0;
212 string regionName = rdata.RegionName.Trim().Replace(' ', '_');
213 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + regionName, String.Empty));
214 newFlags = ParseFlags(newFlags, gridConfig.GetString("Region_" + rdata.RegionID.ToString(), String.Empty));
215 rdata.Data["flags"] = newFlags.ToString();
216 }
217 }
218
219 int flags = Convert.ToInt32(rdata.Data["flags"]);
220 flags |= (int)OpenSim.Data.RegionFlags.RegionOnline;
221 rdata.Data["flags"] = flags.ToString();
222
113 try 223 try
114 { 224 {
225 rdata.Data["last_seen"] = Util.UnixTimeSinceEpoch();
115 m_Database.Store(rdata); 226 m_Database.Store(rdata);
116 } 227 }
117 catch (Exception e) 228 catch (Exception e)
@@ -128,6 +239,30 @@ namespace OpenSim.Services.GridService
128 public bool DeregisterRegion(UUID regionID) 239 public bool DeregisterRegion(UUID regionID)
129 { 240 {
130 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID); 241 m_log.DebugFormat("[GRID SERVICE]: Region {0} deregistered", regionID);
242 RegionData region = m_Database.Get(regionID, UUID.Zero);
243 if (region == null)
244 return false;
245
246 int flags = Convert.ToInt32(region.Data["flags"]);
247
248 if (!m_DeleteOnUnregister || (flags & (int)OpenSim.Data.RegionFlags.Persistent) != 0)
249 {
250 flags &= ~(int)OpenSim.Data.RegionFlags.RegionOnline;
251 region.Data["flags"] = flags.ToString();
252 region.Data["last_seen"] = Util.UnixTimeSinceEpoch();
253 try
254 {
255 m_Database.Store(region);
256 }
257 catch (Exception e)
258 {
259 m_log.DebugFormat("[GRID SERVICE]: Database exception: {0}", e);
260 }
261
262 return true;
263
264 }
265
131 return m_Database.Delete(regionID); 266 return m_Database.Delete(regionID);
132 } 267 }
133 268
@@ -194,6 +329,13 @@ namespace OpenSim.Services.GridService
194 } 329 }
195 } 330 }
196 331
332 if (m_AllowHypergridMapSearch && rdatas == null || (rdatas != null && rdatas.Count == 0) && name.Contains("."))
333 {
334 GridRegion r = m_HypergridLinker.LinkRegion(scopeID, name);
335 if (r != null)
336 rinfos.Add(r);
337 }
338
197 return rinfos; 339 return rinfos;
198 } 340 }
199 341
@@ -216,7 +358,7 @@ namespace OpenSim.Services.GridService
216 358
217 #region Data structure conversions 359 #region Data structure conversions
218 360
219 protected RegionData RegionInfo2RegionData(GridRegion rinfo) 361 public RegionData RegionInfo2RegionData(GridRegion rinfo)
220 { 362 {
221 RegionData rdata = new RegionData(); 363 RegionData rdata = new RegionData();
222 rdata.posX = (int)rinfo.RegionLocX; 364 rdata.posX = (int)rinfo.RegionLocX;
@@ -229,7 +371,7 @@ namespace OpenSim.Services.GridService
229 return rdata; 371 return rdata;
230 } 372 }
231 373
232 protected GridRegion RegionData2RegionInfo(RegionData rdata) 374 public GridRegion RegionData2RegionInfo(RegionData rdata)
233 { 375 {
234 GridRegion rinfo = new GridRegion(rdata.Data); 376 GridRegion rinfo = new GridRegion(rdata.Data);
235 rinfo.RegionLocX = rdata.posX; 377 rinfo.RegionLocX = rdata.posX;
@@ -243,5 +385,142 @@ namespace OpenSim.Services.GridService
243 385
244 #endregion 386 #endregion
245 387
388 public List<GridRegion> GetDefaultRegions(UUID scopeID)
389 {
390 List<GridRegion> ret = new List<GridRegion>();
391
392 List<RegionData> regions = m_Database.GetDefaultRegions(scopeID);
393
394 foreach (RegionData r in regions)
395 {
396 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
397 ret.Add(RegionData2RegionInfo(r));
398 }
399
400 return ret;
401 }
402
403 public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y)
404 {
405 List<GridRegion> ret = new List<GridRegion>();
406
407 List<RegionData> regions = m_Database.GetFallbackRegions(scopeID, x, y);
408
409 foreach (RegionData r in regions)
410 {
411 if ((Convert.ToInt32(r.Data["flags"]) & (int)OpenSim.Data.RegionFlags.RegionOnline) != 0)
412 ret.Add(RegionData2RegionInfo(r));
413 }
414
415 m_log.DebugFormat("[GRID SERVICE]: Fallback returned {0} regions", ret.Count);
416 return ret;
417 }
418
419 public int GetRegionFlags(UUID scopeID, UUID regionID)
420 {
421 RegionData region = m_Database.Get(regionID, scopeID);
422
423 if (region != null)
424 {
425 int flags = Convert.ToInt32(region.Data["flags"]);
426 //m_log.DebugFormat("[GRID SERVICE]: Request for flags of {0}: {1}", regionID, flags);
427 return flags;
428 }
429 else
430 return -1;
431 }
432
433 private void HandleShowRegion(string module, string[] cmd)
434 {
435 if (cmd.Length != 3)
436 {
437 MainConsole.Instance.Output("Syntax: show region <region name>");
438 return;
439 }
440 List<RegionData> regions = m_Database.Get(cmd[2], UUID.Zero);
441 if (regions == null || regions.Count < 1)
442 {
443 MainConsole.Instance.Output("Region not found");
444 return;
445 }
446
447 MainConsole.Instance.Output("Region Name Region UUID");
448 MainConsole.Instance.Output("Location URI");
449 MainConsole.Instance.Output("Owner ID Flags");
450 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
451 foreach (RegionData r in regions)
452 {
453 OpenSim.Data.RegionFlags flags = (OpenSim.Data.RegionFlags)Convert.ToInt32(r.Data["flags"]);
454 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} {5}\n\n",
455 r.RegionName, r.RegionID,
456 String.Format("{0},{1}", r.posX, r.posY), "http://" + r.Data["serverIP"].ToString() + ":" + r.Data["serverPort"].ToString(),
457 r.Data["owner_uuid"].ToString(), flags.ToString()));
458 }
459 return;
460 }
461
462 private int ParseFlags(int prev, string flags)
463 {
464 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)prev;
465
466 string[] parts = flags.Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries);
467
468 foreach (string p in parts)
469 {
470 int val;
471
472 try
473 {
474 if (p.StartsWith("+"))
475 {
476 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
477 f |= (OpenSim.Data.RegionFlags)val;
478 }
479 else if (p.StartsWith("-"))
480 {
481 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p.Substring(1));
482 f &= ~(OpenSim.Data.RegionFlags)val;
483 }
484 else
485 {
486 val = (int)Enum.Parse(typeof(OpenSim.Data.RegionFlags), p);
487 f |= (OpenSim.Data.RegionFlags)val;
488 }
489 }
490 catch (Exception e)
491 {
492 MainConsole.Instance.Output("Error in flag specification: " + p);
493 }
494 }
495
496 return (int)f;
497 }
498
499 private void HandleSetFlags(string module, string[] cmd)
500 {
501 if (cmd.Length < 5)
502 {
503 MainConsole.Instance.Output("Syntax: set region flags <region name> <flags>");
504 return;
505 }
506
507 List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero);
508 if (regions == null || regions.Count < 1)
509 {
510 MainConsole.Instance.Output("Region not found");
511 return;
512 }
513
514 foreach (RegionData r in regions)
515 {
516 int flags = Convert.ToInt32(r.Data["flags"]);
517 flags = ParseFlags(flags, cmd[4]);
518 r.Data["flags"] = flags.ToString();
519 OpenSim.Data.RegionFlags f = (OpenSim.Data.RegionFlags)flags;
520
521 MainConsole.Instance.Output(String.Format("Set region {0} to {1}", r.RegionName, f));
522 m_Database.Store(r);
523 }
524 }
246 } 525 }
247} 526}
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
new file mode 100644
index 0000000..18d0586
--- /dev/null
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -0,0 +1,632 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32using System.Xml;
33
34using Nini.Config;
35using log4net;
36using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Data;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Services.Connectors.Hypergrid;
42using GridRegion = OpenSim.Services.Interfaces.GridRegion;
43using OpenMetaverse;
44
45namespace 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
118 MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-region",
119 "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
120 "Link a hypergrid region", RunCommand);
121 MainConsole.Instance.Commands.AddCommand("hypergrid", false, "unlink-region",
122 "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
123 "Unlink a hypergrid region", RunCommand);
124 MainConsole.Instance.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
125 "Set local coordinate to map HG regions to", RunCommand);
126 MainConsole.Instance.Commands.AddCommand("hypergrid", false, "show hyperlinks", "show hyperlinks <cr>",
127 "List the HG regions", HandleShow);
128 }
129
130
131 #region Link Region
132
133 public GridRegion LinkRegion(UUID scopeID, string regionDescriptor)
134 {
135 string reason = string.Empty;
136 int xloc = random.Next(0, Int16.MaxValue) * (int)Constants.RegionSize;
137 return TryLinkRegionToCoords(scopeID, regionDescriptor, xloc, 0, out reason);
138 }
139
140 private static Random random = new Random();
141
142 // From the command line link-region
143 public GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason)
144 {
145 reason = string.Empty;
146 string host = "127.0.0.1";
147 string portstr;
148 string regionName = "";
149 uint port = 9000;
150 string[] parts = mapName.Split(new char[] { ':' });
151 if (parts.Length >= 1)
152 {
153 host = parts[0];
154 }
155 if (parts.Length >= 2)
156 {
157 portstr = parts[1];
158 //m_log.Debug("-- port = " + portstr);
159 if (!UInt32.TryParse(portstr, out port))
160 regionName = parts[1];
161 }
162 // always take the last one
163 if (parts.Length >= 3)
164 {
165 regionName = parts[2];
166 }
167
168 // Sanity check.
169 IPAddress ipaddr = null;
170 try
171 {
172 ipaddr = Util.GetHostFromDNS(host);
173 }
174 catch
175 {
176 reason = "Malformed hostname";
177 return null;
178 }
179
180 GridRegion regInfo;
181 bool success = TryCreateLink(scopeID, xloc, yloc, regionName, port, host, out regInfo, out reason);
182 if (success)
183 {
184 regInfo.RegionName = mapName;
185 return regInfo;
186 }
187
188 return null;
189 }
190
191
192 // From the command line and the 2 above
193 public bool TryCreateLink(UUID scopeID, int xloc, int yloc,
194 string externalRegionName, uint externalPort, string externalHostName, out GridRegion regInfo, out string reason)
195 {
196 m_log.DebugFormat("[HYPERGRID LINKER]: Link to {0}:{1}, in {2}-{3}", externalHostName, externalPort, xloc, yloc);
197
198 reason = string.Empty;
199 regInfo = new GridRegion();
200 regInfo.RegionName = externalRegionName;
201 regInfo.HttpPort = externalPort;
202 regInfo.ExternalHostName = externalHostName;
203 regInfo.RegionLocX = xloc;
204 regInfo.RegionLocY = yloc;
205 regInfo.ScopeID = scopeID;
206
207 try
208 {
209 regInfo.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int)0);
210 }
211 catch (Exception e)
212 {
213 m_log.Warn("[HYPERGRID LINKER]: Wrong format for link-region: " + e.Message);
214 reason = "Internal error";
215 return false;
216 }
217
218 // Finally, link it
219 ulong handle = 0;
220 UUID regionID = UUID.Zero;
221 string externalName = string.Empty;
222 string imageURL = string.Empty;
223 if (!m_GatekeeperConnector.LinkRegion(regInfo, out regionID, out handle, out externalName, out imageURL, out reason))
224 return false;
225
226 if (regionID != UUID.Zero)
227 {
228 GridRegion r = m_GridService.GetRegionByUUID(scopeID, regionID);
229 if (r != null)
230 {
231 m_log.DebugFormat("[HYPERGRID LINKER]: Region already exists in coordinates {0} {1}", r.RegionLocX / Constants.RegionSize, r.RegionLocY / Constants.RegionSize);
232 regInfo = r;
233 return true;
234 }
235
236 regInfo.RegionID = regionID;
237 Uri uri = null;
238 try
239 {
240 uri = new Uri(externalName);
241 regInfo.ExternalHostName = uri.Host;
242 regInfo.HttpPort = (uint)uri.Port;
243 }
244 catch
245 {
246 m_log.WarnFormat("[HYPERGRID LINKER]: Remote Gatekeeper at {0} provided malformed ExternalName {1}", regInfo.ExternalHostName, externalName);
247 }
248 regInfo.RegionName = regInfo.ExternalHostName + ":" + regInfo.HttpPort + ":" + regInfo.RegionName;
249 // Try get the map image
250 //regInfo.TerrainImage = m_GatekeeperConnector.GetMapImage(regionID, imageURL);
251 // I need a texture that works for this... the one I tried doesn't seem to be working
252 regInfo.TerrainImage = m_HGMapImage;
253
254 AddHyperlinkRegion(regInfo, handle);
255 m_log.Info("[HYPERGRID LINKER]: Successfully linked to region_uuid " + regInfo.RegionID);
256
257 }
258 else
259 {
260 m_log.Warn("[HYPERGRID LINKER]: Unable to link region");
261 reason = "Remote region could not be found";
262 return false;
263 }
264
265 uint x, y;
266 if (!Check4096(handle, out x, out y))
267 {
268 RemoveHyperlinkRegion(regInfo.RegionID);
269 reason = "Region is too far (" + x + ", " + y + ")";
270 m_log.Info("[HYPERGRID LINKER]: Unable to link, region is too far (" + x + ", " + y + ")");
271 return false;
272 }
273
274 m_log.Debug("[HYPERGRID LINKER]: link region succeeded");
275 return true;
276 }
277
278 public bool TryUnlinkRegion(string mapName)
279 {
280 GridRegion regInfo = null;
281 if (mapName.Contains(":"))
282 {
283 string host = "127.0.0.1";
284 //string portstr;
285 //string regionName = "";
286 uint port = 9000;
287 string[] parts = mapName.Split(new char[] { ':' });
288 if (parts.Length >= 1)
289 {
290 host = parts[0];
291 }
292
293 foreach (GridRegion r in m_HyperlinkRegions.Values)
294 if (host.Equals(r.ExternalHostName) && (port == r.HttpPort))
295 regInfo = r;
296 }
297 else
298 {
299 foreach (GridRegion r in m_HyperlinkRegions.Values)
300 if (r.RegionName.Equals(mapName))
301 regInfo = r;
302 }
303 if (regInfo != null)
304 {
305 RemoveHyperlinkRegion(regInfo.RegionID);
306 return true;
307 }
308 else
309 {
310 m_log.InfoFormat("[HYPERGRID LINKER]: Region {0} not found", mapName);
311 return false;
312 }
313 }
314
315 /// <summary>
316 /// Cope with this viewer limitation.
317 /// </summary>
318 /// <param name="regInfo"></param>
319 /// <returns></returns>
320 public bool Check4096(ulong realHandle, out uint x, out uint y)
321 {
322 GridRegion defRegion = DefaultRegion;
323
324 uint ux = 0, uy = 0;
325 Utils.LongToUInts(realHandle, out ux, out uy);
326 x = ux / Constants.RegionSize;
327 y = uy / Constants.RegionSize;
328
329 if ((Math.Abs((int)defRegion.RegionLocX - ux) >= 4096 * Constants.RegionSize) ||
330 (Math.Abs((int)defRegion.RegionLocY - uy) >= 4096 * Constants.RegionSize))
331 {
332 return false;
333 }
334 return true;
335 }
336
337 private void AddHyperlinkRegion(GridRegion regionInfo, ulong regionHandle)
338 {
339 //m_HyperlinkRegions[regionInfo.RegionID] = regionInfo;
340 //m_HyperlinkHandles[regionInfo.RegionID] = regionHandle;
341
342 RegionData rdata = m_GridService.RegionInfo2RegionData(regionInfo);
343 int flags = (int)OpenSim.Data.RegionFlags.Hyperlink + (int)OpenSim.Data.RegionFlags.NoDirectLogin + (int)OpenSim.Data.RegionFlags.RegionOnline;
344 rdata.Data["flags"] = flags.ToString();
345
346 m_Database.Store(rdata);
347
348 }
349
350 private void RemoveHyperlinkRegion(UUID regionID)
351 {
352 //// Try the hyperlink collection
353 //if (m_HyperlinkRegions.ContainsKey(regionID))
354 //{
355 // m_HyperlinkRegions.Remove(regionID);
356 // m_HyperlinkHandles.Remove(regionID);
357 //}
358 m_Database.Delete(regionID);
359 }
360
361 #endregion
362
363
364 #region Console Commands
365
366 public void HandleShow(string module, string[] cmd)
367 {
368 MainConsole.Instance.Output("Not Implemented Yet");
369 //if (cmd.Length != 2)
370 //{
371 // MainConsole.Instance.Output("Syntax: show hyperlinks");
372 // return;
373 //}
374 //List<GridRegion> regions = new List<GridRegion>(m_HypergridService.m_HyperlinkRegions.Values);
375 //if (regions == null || regions.Count < 1)
376 //{
377 // MainConsole.Instance.Output("No hyperlinks");
378 // return;
379 //}
380
381 //MainConsole.Instance.Output("Region Name Region UUID");
382 //MainConsole.Instance.Output("Location URI");
383 //MainConsole.Instance.Output("Owner ID ");
384 //MainConsole.Instance.Output("-------------------------------------------------------------------------------");
385 //foreach (GridRegion r in regions)
386 //{
387 // MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} \n\n",
388 // r.RegionName, r.RegionID,
389 // String.Format("{0},{1}", r.RegionLocX, r.RegionLocY), "http://" + r.ExternalHostName + ":" + r.HttpPort.ToString(),
390 // r.EstateOwner.ToString()));
391 //}
392 //return;
393 }
394 public void RunCommand(string module, string[] cmdparams)
395 {
396 List<string> args = new List<string>(cmdparams);
397 if (args.Count < 1)
398 return;
399
400 string command = args[0];
401 args.RemoveAt(0);
402
403 cmdparams = args.ToArray();
404
405 RunHGCommand(command, cmdparams);
406
407 }
408
409 private void RunHGCommand(string command, string[] cmdparams)
410 {
411 if (command.Equals("link-mapping"))
412 {
413 if (cmdparams.Length == 2)
414 {
415 try
416 {
417 m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
418 m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
419 m_enableAutoMapping = true;
420 }
421 catch (Exception)
422 {
423 m_autoMappingX = 0;
424 m_autoMappingY = 0;
425 m_enableAutoMapping = false;
426 }
427 }
428 }
429 else if (command.Equals("link-region"))
430 {
431 if (cmdparams.Length < 3)
432 {
433 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
434 {
435 LoadXmlLinkFile(cmdparams);
436 }
437 else
438 {
439 LinkRegionCmdUsage();
440 }
441 return;
442 }
443
444 if (cmdparams[2].Contains(":"))
445 {
446 // New format
447 int xloc, yloc;
448 string mapName;
449 try
450 {
451 xloc = Convert.ToInt32(cmdparams[0]);
452 yloc = Convert.ToInt32(cmdparams[1]);
453 mapName = cmdparams[2];
454 if (cmdparams.Length > 3)
455 for (int i = 3; i < cmdparams.Length; i++)
456 mapName += " " + cmdparams[i];
457
458 //m_log.Info(">> MapName: " + mapName);
459 }
460 catch (Exception e)
461 {
462 MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
463 LinkRegionCmdUsage();
464 return;
465 }
466
467 // Convert cell coordinates given by the user to meters
468 xloc = xloc * (int)Constants.RegionSize;
469 yloc = yloc * (int)Constants.RegionSize;
470 string reason = string.Empty;
471 if (TryLinkRegionToCoords(UUID.Zero, mapName, xloc, yloc, out reason) == null)
472 MainConsole.Instance.Output("Failed to link region: " + reason);
473 else
474 MainConsole.Instance.Output("Hyperlink established");
475 }
476 else
477 {
478 // old format
479 GridRegion regInfo;
480 int xloc, yloc;
481 uint externalPort;
482 string externalHostName;
483 try
484 {
485 xloc = Convert.ToInt32(cmdparams[0]);
486 yloc = Convert.ToInt32(cmdparams[1]);
487 externalPort = Convert.ToUInt32(cmdparams[3]);
488 externalHostName = cmdparams[2];
489 //internalPort = Convert.ToUInt32(cmdparams[4]);
490 //remotingPort = Convert.ToUInt32(cmdparams[5]);
491 }
492 catch (Exception e)
493 {
494 MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
495 LinkRegionCmdUsage();
496 return;
497 }
498
499 // Convert cell coordinates given by the user to meters
500 xloc = xloc * (int)Constants.RegionSize;
501 yloc = yloc * (int)Constants.RegionSize;
502 string reason = string.Empty;
503 if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason))
504 {
505 if (cmdparams.Length >= 5)
506 {
507 regInfo.RegionName = "";
508 for (int i = 4; i < cmdparams.Length; i++)
509 regInfo.RegionName += cmdparams[i] + " ";
510 }
511 }
512 }
513 return;
514 }
515 else if (command.Equals("unlink-region"))
516 {
517 if (cmdparams.Length < 1)
518 {
519 UnlinkRegionCmdUsage();
520 return;
521 }
522 if (TryUnlinkRegion(cmdparams[0]))
523 MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]);
524 else
525 MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found.");
526 }
527 }
528
529 private void LoadXmlLinkFile(string[] cmdparams)
530 {
531 //use http://www.hgurl.com/hypergrid.xml for test
532 try
533 {
534 XmlReader r = XmlReader.Create(cmdparams[0]);
535 XmlConfigSource cs = new XmlConfigSource(r);
536 string[] excludeSections = null;
537
538 if (cmdparams.Length == 2)
539 {
540 if (cmdparams[1].ToLower().StartsWith("excludelist:"))
541 {
542 string excludeString = cmdparams[1].ToLower();
543 excludeString = excludeString.Remove(0, 12);
544 char[] splitter = { ';' };
545
546 excludeSections = excludeString.Split(splitter);
547 }
548 }
549
550 for (int i = 0; i < cs.Configs.Count; i++)
551 {
552 bool skip = false;
553 if ((excludeSections != null) && (excludeSections.Length > 0))
554 {
555 for (int n = 0; n < excludeSections.Length; n++)
556 {
557 if (excludeSections[n] == cs.Configs[i].Name.ToLower())
558 {
559 skip = true;
560 break;
561 }
562 }
563 }
564 if (!skip)
565 {
566 ReadLinkFromConfig(cs.Configs[i]);
567 }
568 }
569 }
570 catch (Exception e)
571 {
572 m_log.Error(e.ToString());
573 }
574 }
575
576
577 private void ReadLinkFromConfig(IConfig config)
578 {
579 GridRegion regInfo;
580 int xloc, yloc;
581 uint externalPort;
582 string externalHostName;
583 uint realXLoc, realYLoc;
584
585 xloc = Convert.ToInt32(config.GetString("xloc", "0"));
586 yloc = Convert.ToInt32(config.GetString("yloc", "0"));
587 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
588 externalHostName = config.GetString("externalHostName", "");
589 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
590 realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
591
592 if (m_enableAutoMapping)
593 {
594 xloc = (int)((xloc % 100) + m_autoMappingX);
595 yloc = (int)((yloc % 100) + m_autoMappingY);
596 }
597
598 if (((realXLoc == 0) && (realYLoc == 0)) ||
599 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
600 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
601 {
602 xloc = xloc * (int)Constants.RegionSize;
603 yloc = yloc * (int)Constants.RegionSize;
604 string reason = string.Empty;
605 if (TryCreateLink(UUID.Zero, xloc, yloc, "", externalPort,
606 externalHostName, out regInfo, out reason))
607 {
608 regInfo.RegionName = config.GetString("localName", "");
609 }
610 else
611 MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason);
612 }
613 }
614
615
616 private void LinkRegionCmdUsage()
617 {
618 MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
619 MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
620 MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]");
621 }
622
623 private void UnlinkRegionCmdUsage()
624 {
625 MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>");
626 MainConsole.Instance.Output("Usage: unlink-region <LocalName>");
627 }
628
629 #endregion
630
631 }
632}
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs
new file mode 100644
index 0000000..e2d0eb8
--- /dev/null
+++ b/OpenSim/Services/HypergridService/GatekeeperService.cs
@@ -0,0 +1,320 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32
33using OpenSim.Framework;
34using OpenSim.Services.Interfaces;
35using GridRegion = OpenSim.Services.Interfaces.GridRegion;
36using OpenSim.Server.Base;
37using OpenSim.Services.Connectors.Hypergrid;
38
39using OpenMetaverse;
40
41using Nini.Config;
42using log4net;
43
44namespace 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 return (addressee == m_ExternalName);
310 }
311
312 #endregion
313
314
315 #region Misc
316
317
318 #endregion
319 }
320}
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 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Reflection;
5
6using OpenSim.Framework;
7using OpenSim.Services.Connectors.Hypergrid;
8using OpenSim.Services.Interfaces;
9using GridRegion = OpenSim.Services.Interfaces.GridRegion;
10using OpenSim.Server.Base;
11
12using OpenMetaverse;
13using log4net;
14using Nini.Config;
15
16namespace 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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31
32using OpenSim.Framework;
33
34using OpenMetaverse;
35
36namespace 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..4e665cd
--- /dev/null
+++ b/OpenSim/Services/Interfaces/IFriendsService.cs
@@ -0,0 +1,48 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenMetaverse;
29using OpenSim.Framework;
30using System.Collections.Generic;
31
32namespace OpenSim.Region.Framework.Interfaces
33{
34 public struct FriendInfo
35 {
36 public UUID PrincipalID;
37 public string Friend;
38 int MyFlags;
39 int TheirFlags;
40 }
41
42 public interface IFriendsService
43 {
44 FriendInfo[] GetFriends(UUID PrincipalID);
45 bool StoreFriend(UUID PrincipalID, string Friend, int flags);
46 bool Delete(UUID PrincipalID, string Friend);
47 }
48}
diff --git a/OpenSim/Services/UserService/UserService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs
index e8b9fc3..ca7b9b3 100644
--- a/OpenSim/Services/UserService/UserService.cs
+++ b/OpenSim/Services/Interfaces/IGatekeeperService.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,51 +26,34 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Net;
30using Nini.Config;
31using OpenSim.Data;
32using OpenSim.Services.Interfaces;
33using System.Collections.Generic; 30using System.Collections.Generic;
31
32using OpenSim.Framework;
34using OpenMetaverse; 33using OpenMetaverse;
35 34
36namespace OpenSim.Services.UserAccountService 35namespace OpenSim.Services.Interfaces
37{ 36{
38 public class UserAccountService : UserAccountServiceBase, IUserAccountService 37 public interface IGatekeeperService
39 { 38 {
40 public UserAccountService(IConfigSource config) : base(config) 39 bool LinkRegion(string regionDescriptor, out UUID regionID, out ulong regionHandle, out string externalName, out string imageURL, out string reason);
41 { 40 GridRegion GetHyperlinkRegion(UUID regionID);
42 }
43
44 public UserAccount GetUserAccount(UUID scopeID, string firstName,
45 string lastName)
46 {
47 return null;
48 }
49
50 public UserAccount GetUserAccount(UUID scopeID, UUID userID)
51 {
52 return null;
53 }
54 41
55 public bool SetHomePosition(UserAccount data, UUID regionID, UUID regionSecret) 42 bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason);
56 {
57 return false;
58 }
59 43
60 public bool SetUserAccount(UserAccount data, UUID principalID, string token) 44 }
61 {
62 return false;
63 }
64 45
65 public bool CreateUserAccount(UserAccount data, UUID principalID, string token) 46 /// <summary>
66 { 47 /// HG1.5 only
67 return false; 48 /// </summary>
68 } 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);
69 54
70 public List<UserAccount> GetUserAccount(UUID scopeID, 55 bool AgentIsComingHome(UUID sessionID, string thisGridExternalName);
71 string query) 56 bool VerifyAgent(UUID sessionID, string token);
72 { 57 bool VerifyClient(UUID sessionID, string token);
73 return null;
74 }
75 } 58 }
76} 59}
diff --git a/OpenSim/Services/Interfaces/IGridService.cs b/OpenSim/Services/Interfaces/IGridService.cs
index 5135f6d..2f5e991 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)
@@ -308,6 +307,7 @@ namespace OpenSim.Services.Interfaces
308 kvp["access"] = Access.ToString(); 307 kvp["access"] = Access.ToString();
309 kvp["regionSecret"] = RegionSecret; 308 kvp["regionSecret"] = RegionSecret;
310 kvp["owner_uuid"] = EstateOwner.ToString(); 309 kvp["owner_uuid"] = EstateOwner.ToString();
310 kvp["Token"] = Token.ToString();
311 // Maturity doesn't seem to exist in the DB 311 // Maturity doesn't seem to exist in the DB
312 return kvp; 312 return kvp;
313 } 313 }
@@ -365,6 +365,9 @@ namespace OpenSim.Services.Interfaces
365 if (kvp.ContainsKey("owner_uuid")) 365 if (kvp.ContainsKey("owner_uuid"))
366 EstateOwner = new UUID(kvp["owner_uuid"].ToString()); 366 EstateOwner = new UUID(kvp["owner_uuid"].ToString());
367 367
368 if (kvp.ContainsKey("Token"))
369 Token = kvp["Token"].ToString();
370
368 } 371 }
369 } 372 }
370 373
diff --git a/OpenSim/Services/Interfaces/IHyperlink.cs b/OpenSim/Services/Interfaces/ILibraryService.cs
index ed3ff23..861cf0e 100644
--- a/OpenSim/Services/Interfaces/IHyperlink.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,25 +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
28using OpenSim.Framework; 28using System;
29using GridRegion = OpenSim.Services.Interfaces.GridRegion; 29using System.Collections.Generic;
30 30
31using OpenSim.Framework;
31using OpenMetaverse; 32using OpenMetaverse;
32 33
33namespace OpenSim.Services.Interfaces 34namespace OpenSim.Services.Interfaces
34{ 35{
35 public interface IHyperlinkService 36 public interface ILibraryService
36 { 37 {
37 GridRegion TryLinkRegion(IClientAPI client, string regionDescriptor); 38 InventoryFolderImpl LibraryRootFolder { get; }
38 GridRegion GetHyperlinkRegion(ulong handle);
39 ulong FindRegionHandle(ulong handle);
40
41 bool SendUserInformation(GridRegion region, AgentCircuitData aCircuit);
42 void AdjustUserInformation(AgentCircuitData aCircuit);
43 39
44 bool CheckUserAtEntry(UUID userID, UUID sessionID, out bool comingHome); 40 Dictionary<UUID, InventoryFolderImpl> GetAllFolders();
45 void AcceptUser(ForeignUserProfileData user, GridRegion home);
46
47 bool IsLocalUser(UUID userID);
48 } 41 }
42
49} 43}
diff --git a/OpenSim/Services/Interfaces/ILoginService.cs b/OpenSim/Services/Interfaces/ILoginService.cs
new file mode 100644
index 0000000..24bf342
--- /dev/null
+++ b/OpenSim/Services/Interfaces/ILoginService.cs
@@ -0,0 +1,53 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32
33using OpenMetaverse.StructuredData;
34
35namespace OpenSim.Services.Interfaces
36{
37 public abstract class LoginResponse
38 {
39 public abstract Hashtable ToHashtable();
40 public abstract OSD ToOSDMap();
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
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
28using System;
28using OpenSim.Framework; 29using OpenSim.Framework;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using OpenMetaverse; 31using 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;
29using OpenSim.Framework; 29using OpenSim.Framework;
30using OpenMetaverse; 30using OpenMetaverse;
31 31
32using GridRegion = OpenSim.Services.Interfaces.GridRegion;
33
32namespace OpenSim.Services.Interfaces 34namespace 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
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31
32namespace 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
28using System.Collections.Generic;
29using OpenMetaverse;
30
31namespace 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
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using log4net;
32using Nini.Config;
33using System.Reflection;
34using OpenSim.Services.Base;
35using OpenSim.Services.Interfaces;
36using OpenSim.Data;
37using OpenSim.Framework;
38
39namespace 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..781b89b 100644
--- a/OpenSim/Services/InventoryService/InventoryService.cs
+++ b/OpenSim/Services/InventoryService/InventoryService.cs
@@ -298,6 +298,7 @@ namespace OpenSim.Services.InventoryService
298 if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) 298 if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown))
299 folders[(AssetType)folder.Type] = folder; 299 folders[(AssetType)folder.Type] = folder;
300 } 300 }
301 m_log.DebugFormat("[INVENTORY SERVICE]: Got {0} system folders for {1}", folders.Count, userID);
301 return folders; 302 return folders;
302 } 303 }
303 } 304 }
diff --git a/OpenSim/Services/InventoryService/LibraryService.cs b/OpenSim/Services/InventoryService/LibraryService.cs
new file mode 100644
index 0000000..383f311
--- /dev/null
+++ b/OpenSim/Services/InventoryService/LibraryService.cs
@@ -0,0 +1,283 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33
34using OpenSim.Framework;
35using OpenSim.Services.Base;
36using OpenSim.Services.Interfaces;
37
38using log4net;
39using Nini.Config;
40using OpenMetaverse;
41
42namespace OpenSim.Services.InventoryService
43{
44 /// <summary>
45 /// Basically a hack to give us a Inventory library while we don't have a inventory server
46 /// once the server is fully implemented then should read the data from that
47 /// </summary>
48 public class LibraryService : ServiceBase, ILibraryService
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private InventoryFolderImpl m_LibraryRootFolder;
53
54 public InventoryFolderImpl LibraryRootFolder
55 {
56 get { return m_LibraryRootFolder; }
57 }
58
59 private UUID libOwner = new UUID("11111111-1111-0000-0000-000100bba000");
60
61 /// <summary>
62 /// Holds the root library folder and all its descendents. This is really only used during inventory
63 /// setup so that we don't have to repeatedly search the tree of library folders.
64 /// </summary>
65 protected Dictionary<UUID, InventoryFolderImpl> libraryFolders
66 = new Dictionary<UUID, InventoryFolderImpl>();
67
68 public LibraryService(IConfigSource config)
69 : base(config)
70 {
71 string pLibrariesLocation = Path.Combine("inventory", "Libraries.xml");
72 string pLibName = "OpenSim Library";
73
74 IConfig libConfig = config.Configs["LibraryService"];
75 if (libConfig != null)
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;
90
91 libraryFolders.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder);
92
93 LoadLibraries(pLibrariesLocation);
94 }
95
96 public InventoryItemBase CreateItem(UUID inventoryID, UUID assetID, string name, string description,
97 int assetType, int invType, UUID parentFolderID)
98 {
99 InventoryItemBase item = new InventoryItemBase();
100 item.Owner = libOwner;
101 item.CreatorId = libOwner.ToString();
102 item.ID = inventoryID;
103 item.AssetID = assetID;
104 item.Description = description;
105 item.Name = name;
106 item.AssetType = assetType;
107 item.InvType = invType;
108 item.Folder = parentFolderID;
109 item.BasePermissions = 0x7FFFFFFF;
110 item.EveryOnePermissions = 0x7FFFFFFF;
111 item.CurrentPermissions = 0x7FFFFFFF;
112 item.NextPermissions = 0x7FFFFFFF;
113 return item;
114 }
115
116 /// <summary>
117 /// Use the asset set information at path to load assets
118 /// </summary>
119 /// <param name="path"></param>
120 /// <param name="assets"></param>
121 protected void LoadLibraries(string librariesControlPath)
122 {
123 m_log.InfoFormat("[LIBRARY INVENTORY]: Loading library control file {0}", librariesControlPath);
124 LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig);
125 }
126
127 /// <summary>
128 /// Read a library set from config
129 /// </summary>
130 /// <param name="config"></param>
131 protected void ReadLibraryFromConfig(IConfig config, string path)
132 {
133 string basePath = Path.GetDirectoryName(path);
134 string foldersPath
135 = Path.Combine(
136 basePath, config.GetString("foldersFile", String.Empty));
137
138 LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig);
139
140 string itemsPath
141 = Path.Combine(
142 basePath, config.GetString("itemsFile", String.Empty));
143
144 LoadFromFile(itemsPath, "Library items", ReadItemFromConfig);
145 }
146
147 /// <summary>
148 /// Read a library inventory folder from a loaded configuration
149 /// </summary>
150 /// <param name="source"></param>
151 private void ReadFolderFromConfig(IConfig config, string path)
152 {
153 InventoryFolderImpl folderInfo = new InventoryFolderImpl();
154
155 folderInfo.ID = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString()));
156 folderInfo.Name = config.GetString("name", "unknown");
157 folderInfo.ParentID = new UUID(config.GetString("parentFolderID", m_LibraryRootFolder.ID.ToString()));
158 folderInfo.Type = (short)config.GetInt("type", 8);
159
160 folderInfo.Owner = libOwner;
161 folderInfo.Version = 1;
162
163 if (libraryFolders.ContainsKey(folderInfo.ParentID))
164 {
165 InventoryFolderImpl parentFolder = libraryFolders[folderInfo.ParentID];
166
167 libraryFolders.Add(folderInfo.ID, folderInfo);
168 parentFolder.AddChildFolder(folderInfo);
169
170// m_log.InfoFormat("[LIBRARY INVENTORY]: Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID);
171 }
172 else
173 {
174 m_log.WarnFormat(
175 "[LIBRARY INVENTORY]: Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!",
176 folderInfo.Name, folderInfo.ID, folderInfo.ParentID);
177 }
178 }
179
180 /// <summary>
181 /// Read a library inventory item metadata from a loaded configuration
182 /// </summary>
183 /// <param name="source"></param>
184 private void ReadItemFromConfig(IConfig config, string path)
185 {
186 InventoryItemBase item = new InventoryItemBase();
187 item.Owner = libOwner;
188 item.CreatorId = libOwner.ToString();
189 item.ID = new UUID(config.GetString("inventoryID", m_LibraryRootFolder.ID.ToString()));
190 item.AssetID = new UUID(config.GetString("assetID", item.ID.ToString()));
191 item.Folder = new UUID(config.GetString("folderID", m_LibraryRootFolder.ID.ToString()));
192 item.Name = config.GetString("name", String.Empty);
193 item.Description = config.GetString("description", item.Name);
194 item.InvType = config.GetInt("inventoryType", 0);
195 item.AssetType = config.GetInt("assetType", item.InvType);
196 item.CurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF);
197 item.NextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF);
198 item.EveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF);
199 item.BasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF);
200 item.Flags = (uint)config.GetInt("flags", 0);
201
202 if (libraryFolders.ContainsKey(item.Folder))
203 {
204 InventoryFolderImpl parentFolder = libraryFolders[item.Folder];
205 try
206 {
207 parentFolder.Items.Add(item.ID, item);
208 }
209 catch (Exception)
210 {
211 m_log.WarnFormat("[LIBRARY INVENTORY] Item {1} [{0}] not added, duplicate item", item.ID, item.Name);
212 }
213 }
214 else
215 {
216 m_log.WarnFormat(
217 "[LIBRARY INVENTORY]: Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!",
218 item.Name, item.ID, item.Folder);
219 }
220 }
221
222 private delegate void ConfigAction(IConfig config, string path);
223
224 /// <summary>
225 /// Load the given configuration at a path and perform an action on each Config contained within it
226 /// </summary>
227 /// <param name="path"></param>
228 /// <param name="fileDescription"></param>
229 /// <param name="action"></param>
230 private static void LoadFromFile(string path, string fileDescription, ConfigAction action)
231 {
232 if (File.Exists(path))
233 {
234 try
235 {
236 XmlConfigSource source = new XmlConfigSource(path);
237
238 for (int i = 0; i < source.Configs.Count; i++)
239 {
240 action(source.Configs[i], path);
241 }
242 }
243 catch (XmlException e)
244 {
245 m_log.ErrorFormat("[LIBRARY INVENTORY]: Error loading {0} : {1}", path, e);
246 }
247 }
248 else
249 {
250 m_log.ErrorFormat("[LIBRARY INVENTORY]: {0} file {1} does not exist!", fileDescription, path);
251 }
252 }
253
254 /// <summary>
255 /// Looks like a simple getter, but is written like this for some consistency with the other Request
256 /// methods in the superclass
257 /// </summary>
258 /// <returns></returns>
259 public Dictionary<UUID, InventoryFolderImpl> GetAllFolders()
260 {
261 Dictionary<UUID, InventoryFolderImpl> fs = new Dictionary<UUID, InventoryFolderImpl>();
262 fs.Add(m_LibraryRootFolder.ID, m_LibraryRootFolder);
263 List<InventoryFolderImpl> fis = TraverseFolder(m_LibraryRootFolder);
264 foreach (InventoryFolderImpl f in fis)
265 {
266 fs.Add(f.ID, f);
267 }
268 //return libraryFolders;
269 return fs;
270 }
271
272 private List<InventoryFolderImpl> TraverseFolder(InventoryFolderImpl node)
273 {
274 List<InventoryFolderImpl> folders = node.RequestListOfFolderImpls();
275 List<InventoryFolderImpl> subs = new List<InventoryFolderImpl>();
276 foreach (InventoryFolderImpl f in folders)
277 subs.AddRange(TraverseFolder(f));
278
279 folders.AddRange(subs);
280 return folders;
281 }
282 }
283}
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
index 2c79c77..68a4d7f 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,
@@ -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/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
new file mode 100644
index 0000000..4db6a05
--- /dev/null
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -0,0 +1,971 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Capabilities;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38
39using log4net;
40using OpenMetaverse;
41using OpenMetaverse.StructuredData;
42using OSDArray = OpenMetaverse.StructuredData.OSDArray;
43using OSDMap = OpenMetaverse.StructuredData.OSDMap;
44
45namespace OpenSim.Services.LLLoginService
46{
47 public class LLFailedLoginResponse : OpenSim.Services.Interfaces.FailedLoginResponse
48 {
49 string m_key;
50 string m_value;
51 string m_login;
52
53 public static LLFailedLoginResponse UserProblem;
54 public static LLFailedLoginResponse AuthorizationProblem;
55 public static LLFailedLoginResponse GridProblem;
56 public static LLFailedLoginResponse InventoryProblem;
57 public static LLFailedLoginResponse DeadRegionProblem;
58 public static LLFailedLoginResponse LoginBlockedProblem;
59 public static LLFailedLoginResponse AlreadyLoggedInProblem;
60 public static LLFailedLoginResponse InternalError;
61
62 static LLFailedLoginResponse()
63 {
64 UserProblem = new LLFailedLoginResponse("key",
65 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
66 "false");
67 AuthorizationProblem = new LLFailedLoginResponse("key",
68 "Error connecting to grid. Unable to authorize your session into the region.",
69 "false");
70 GridProblem = new LLFailedLoginResponse("key",
71 "Error connecting to the desired location. Try connecting to another region.",
72 "false");
73 InventoryProblem = new LLFailedLoginResponse("key",
74 "The inventory service is not responding. Please notify your login region operator.",
75 "false");
76 DeadRegionProblem = new LLFailedLoginResponse("key",
77 "The region you are attempting to log into is not responding. Please select another region and try again.",
78 "false");
79 LoginBlockedProblem = new LLFailedLoginResponse("presence",
80 "Logins are currently restricted. Please try again later.",
81 "false");
82 AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
83 "You appear to be already logged in. " +
84 "If this is not the case please wait for your session to timeout. " +
85 "If this takes longer than a few minutes please contact the grid owner. " +
86 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
87 "false");
88 InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false");
89 }
90
91 public LLFailedLoginResponse(string key, string value, string login)
92 {
93 m_key = key;
94 m_value = value;
95 m_login = login;
96 }
97
98 public override Hashtable ToHashtable()
99 {
100 Hashtable loginError = new Hashtable();
101 loginError["reason"] = m_key;
102 loginError["message"] = m_value;
103 loginError["login"] = m_login;
104 return loginError;
105 }
106
107 public override OSD ToOSDMap()
108 {
109 OSDMap map = new OSDMap();
110
111 map["reason"] = OSD.FromString(m_key);
112 map["message"] = OSD.FromString(m_value);
113 map["login"] = OSD.FromString(m_login);
114
115 return map;
116 }
117 }
118
119 /// <summary>
120 /// A class to handle LL login response.
121 /// </summary>
122 public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse
123 {
124 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
125 private static Hashtable globalTexturesHash;
126 // Global Textures
127 private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
128 private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
129 private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
130
131 private Hashtable loginFlagsHash;
132 private Hashtable uiConfigHash;
133
134 private ArrayList loginFlags;
135 private ArrayList globalTextures;
136 private ArrayList eventCategories;
137 private ArrayList uiConfig;
138 private ArrayList classifiedCategories;
139 private ArrayList inventoryRoot;
140 private ArrayList initialOutfit;
141 private ArrayList agentInventory;
142 private ArrayList inventoryLibraryOwner;
143 private ArrayList inventoryLibRoot;
144 private ArrayList inventoryLibrary;
145 private ArrayList activeGestures;
146
147 private UserInfo userProfile;
148
149 private UUID agentID;
150 private UUID sessionID;
151 private UUID secureSessionID;
152
153 // Login Flags
154 private string dst;
155 private string stipendSinceLogin;
156 private string gendered;
157 private string everLoggedIn;
158 private string login;
159 private uint simPort;
160 private uint simHttpPort;
161 private string simAddress;
162 private string agentAccess;
163 private string agentAccessMax;
164 private Int32 circuitCode;
165 private uint regionX;
166 private uint regionY;
167
168 // Login
169 private string firstname;
170 private string lastname;
171
172 // Error Flags
173 private string errorReason;
174 private string errorMessage;
175
176 private string welcomeMessage;
177 private string startLocation;
178 private string allowFirstLife;
179 private string home;
180 private string seedCapability;
181 private string lookAt;
182
183 private BuddyList m_buddyList = null;
184
185 static LLLoginResponse()
186 {
187 // This is being set, but it's not used
188 // not sure why.
189 globalTexturesHash = new Hashtable();
190 globalTexturesHash["sun_texture_id"] = sunTexture;
191 globalTexturesHash["cloud_texture_id"] = cloudTexture;
192 globalTexturesHash["moon_texture_id"] = moonTexture;
193 }
194
195 public LLLoginResponse()
196 {
197 loginFlags = new ArrayList();
198 globalTextures = new ArrayList();
199 eventCategories = new ArrayList();
200 uiConfig = new ArrayList();
201 classifiedCategories = new ArrayList();
202
203 uiConfigHash = new Hashtable();
204
205 // defaultXmlRpcResponse = new XmlRpcResponse();
206 userProfile = new UserInfo();
207 inventoryRoot = new ArrayList();
208 initialOutfit = new ArrayList();
209 agentInventory = new ArrayList();
210 inventoryLibrary = new ArrayList();
211 inventoryLibraryOwner = new ArrayList();
212 activeGestures = new ArrayList();
213
214 SetDefaultValues();
215 }
216
217 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, PresenceInfo pinfo,
218 GridRegion destination, List<InventoryFolderBase> invSkel, ILibraryService libService,
219 string where, string startlocation, Vector3 position, Vector3 lookAt, string message,
220 GridRegion home, IPEndPoint clientIP)
221 : this()
222 {
223 FillOutInventoryData(invSkel, libService);
224
225 CircuitCode = (int)aCircuit.circuitcode;
226 Lastname = account.LastName;
227 Firstname = account.FirstName;
228 AgentID = account.PrincipalID;
229 SessionID = aCircuit.SessionID;
230 SecureSessionID = aCircuit.SecureSessionID;
231 Message = message;
232 // While we don't have friends...
233 //BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
234 BuddList = new LLLoginResponse.BuddyList();
235 StartLocation = where;
236
237 FillOutHomeData(pinfo, home);
238 LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
239
240 FillOutRegionData(destination);
241
242 FillOutSeedCap(aCircuit, destination, clientIP);
243
244 }
245
246 private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService)
247 {
248 InventoryData inventData = null;
249
250 try
251 {
252 inventData = GetInventorySkeleton(invSkel);
253 }
254 catch (Exception e)
255 {
256 m_log.WarnFormat(
257 "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}",
258 agentID, e);
259
260 // ignore and continue
261 }
262
263 if (inventData != null)
264 {
265 ArrayList AgentInventoryArray = inventData.InventoryArray;
266
267 Hashtable InventoryRootHash = new Hashtable();
268 InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
269 InventoryRoot = new ArrayList();
270 InventoryRoot.Add(InventoryRootHash);
271 InventorySkeleton = AgentInventoryArray;
272 }
273
274 // Inventory Library Section
275 if (libService != null && libService.LibraryRootFolder != null)
276 {
277 Hashtable InventoryLibRootHash = new Hashtable();
278 InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
279 InventoryLibRoot = new ArrayList();
280 InventoryLibRoot.Add(InventoryLibRootHash);
281
282 InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
283 InventoryLibrary = GetInventoryLibrary(libService);
284 }
285 }
286
287 private void FillOutHomeData(PresenceInfo pinfo, GridRegion home)
288 {
289 int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize;
290 if (home != null)
291 {
292 x = home.RegionLocX;
293 y = home.RegionLocY;
294 }
295
296 Home = string.Format(
297 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
298 x,
299 y,
300 pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
301 pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
302
303 }
304
305 private void FillOutRegionData(GridRegion destination)
306 {
307 IPEndPoint endPoint = destination.ExternalEndPoint;
308 SimAddress = endPoint.Address.ToString();
309 SimPort = (uint)endPoint.Port;
310 RegionX = (uint)destination.RegionLocX;
311 RegionY = (uint)destination.RegionLocY;
312 }
313
314 private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient)
315 {
316 string capsSeedPath = String.Empty;
317
318 // Don't use the following! It Fails for logging into any region not on the same port as the http server!
319 // Kept here so it doesn't happen again!
320 // response.SeedCapability = regionInfo.ServerURI + capsSeedPath;
321
322 #region IP Translation for NAT
323 if (ipepClient != null)
324 {
325 capsSeedPath
326 = "http://"
327 + NetworkUtil.GetHostFor(ipepClient.Address, destination.ExternalHostName)
328 + ":"
329 + destination.HttpPort
330 + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
331 }
332 else
333 {
334 capsSeedPath
335 = "http://"
336 + destination.ExternalHostName
337 + ":"
338 + destination.HttpPort
339 + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
340 }
341 #endregion
342
343 SeedCapability = capsSeedPath;
344 }
345
346 private void SetDefaultValues()
347 {
348 DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
349 StipendSinceLogin = "N";
350 Gendered = "Y";
351 EverLoggedIn = "Y";
352 login = "false";
353 firstname = "Test";
354 lastname = "User";
355 agentAccess = "M";
356 agentAccessMax = "A";
357 startLocation = "last";
358 allowFirstLife = "Y";
359
360 ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
361 ErrorReason = "key";
362 welcomeMessage = "Welcome to OpenSim!";
363 seedCapability = String.Empty;
364 home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" +
365 userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" +
366 userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" +
367 userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}";
368 lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
369 RegionX = (uint) 255232;
370 RegionY = (uint) 254976;
371
372 // Classifieds;
373 AddClassifiedCategory((Int32) 1, "Shopping");
374 AddClassifiedCategory((Int32) 2, "Land Rental");
375 AddClassifiedCategory((Int32) 3, "Property Rental");
376 AddClassifiedCategory((Int32) 4, "Special Attraction");
377 AddClassifiedCategory((Int32) 5, "New Products");
378 AddClassifiedCategory((Int32) 6, "Employment");
379 AddClassifiedCategory((Int32) 7, "Wanted");
380 AddClassifiedCategory((Int32) 8, "Service");
381 AddClassifiedCategory((Int32) 9, "Personal");
382
383 SessionID = UUID.Random();
384 SecureSessionID = UUID.Random();
385 AgentID = UUID.Random();
386
387 Hashtable InitialOutfitHash = new Hashtable();
388 InitialOutfitHash["folder_name"] = "Nightclub Female";
389 InitialOutfitHash["gender"] = "female";
390 initialOutfit.Add(InitialOutfitHash);
391 }
392
393
394 public override Hashtable ToHashtable()
395 {
396 try
397 {
398 Hashtable responseData = new Hashtable();
399
400 loginFlagsHash = new Hashtable();
401 loginFlagsHash["daylight_savings"] = DST;
402 loginFlagsHash["stipend_since_login"] = StipendSinceLogin;
403 loginFlagsHash["gendered"] = Gendered;
404 loginFlagsHash["ever_logged_in"] = EverLoggedIn;
405 loginFlags.Add(loginFlagsHash);
406
407 responseData["first_name"] = Firstname;
408 responseData["last_name"] = Lastname;
409 responseData["agent_access"] = agentAccess;
410 responseData["agent_access_max"] = agentAccessMax;
411
412 globalTextures.Add(globalTexturesHash);
413 // this.eventCategories.Add(this.eventCategoriesHash);
414
415 AddToUIConfig("allow_first_life", allowFirstLife);
416 uiConfig.Add(uiConfigHash);
417
418 responseData["sim_port"] = (Int32) SimPort;
419 responseData["sim_ip"] = SimAddress;
420 responseData["http_port"] = (Int32)SimHttpPort;
421
422 responseData["agent_id"] = AgentID.ToString();
423 responseData["session_id"] = SessionID.ToString();
424 responseData["secure_session_id"] = SecureSessionID.ToString();
425 responseData["circuit_code"] = CircuitCode;
426 responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
427 responseData["login-flags"] = loginFlags;
428 responseData["global-textures"] = globalTextures;
429 responseData["seed_capability"] = seedCapability;
430
431 responseData["event_categories"] = eventCategories;
432 responseData["event_notifications"] = new ArrayList(); // todo
433 responseData["classified_categories"] = classifiedCategories;
434 responseData["ui-config"] = uiConfig;
435
436 if (agentInventory != null)
437 {
438 responseData["inventory-skeleton"] = agentInventory;
439 responseData["inventory-root"] = inventoryRoot;
440 }
441 responseData["inventory-skel-lib"] = inventoryLibrary;
442 responseData["inventory-lib-root"] = inventoryLibRoot;
443 responseData["gestures"] = activeGestures;
444 responseData["inventory-lib-owner"] = inventoryLibraryOwner;
445 responseData["initial-outfit"] = initialOutfit;
446 responseData["start_location"] = startLocation;
447 responseData["seed_capability"] = seedCapability;
448 responseData["home"] = home;
449 responseData["look_at"] = lookAt;
450 responseData["message"] = welcomeMessage;
451 responseData["region_x"] = (Int32)(RegionX);
452 responseData["region_y"] = (Int32)(RegionY);
453
454 if (m_buddyList != null)
455 {
456 responseData["buddy-list"] = m_buddyList.ToArray();
457 }
458
459 responseData["login"] = "true";
460
461 return responseData;
462 }
463 catch (Exception e)
464 {
465 m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
466
467 return LLFailedLoginResponse.InternalError.ToHashtable();
468 }
469 }
470
471 public override OSD ToOSDMap()
472 {
473 try
474 {
475 OSDMap map = new OSDMap();
476
477 map["first_name"] = OSD.FromString(Firstname);
478 map["last_name"] = OSD.FromString(Lastname);
479 map["agent_access"] = OSD.FromString(agentAccess);
480 map["agent_access_max"] = OSD.FromString(agentAccessMax);
481
482 map["sim_port"] = OSD.FromInteger(SimPort);
483 map["sim_ip"] = OSD.FromString(SimAddress);
484
485 map["agent_id"] = OSD.FromUUID(AgentID);
486 map["session_id"] = OSD.FromUUID(SessionID);
487 map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
488 map["circuit_code"] = OSD.FromInteger(CircuitCode);
489 map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
490
491 #region Login Flags
492
493 OSDMap loginFlagsLLSD = new OSDMap();
494 loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST);
495 loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin);
496 loginFlagsLLSD["gendered"] = OSD.FromString(Gendered);
497 loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn);
498 map["login-flags"] = WrapOSDMap(loginFlagsLLSD);
499
500 #endregion Login Flags
501
502 #region Global Textures
503
504 OSDMap globalTexturesLLSD = new OSDMap();
505 globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture);
506 globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture);
507 globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture);
508
509 map["global-textures"] = WrapOSDMap(globalTexturesLLSD);
510
511 #endregion Global Textures
512
513 map["seed_capability"] = OSD.FromString(seedCapability);
514
515 map["event_categories"] = ArrayListToOSDArray(eventCategories);
516 //map["event_notifications"] = new OSDArray(); // todo
517 map["classified_categories"] = ArrayListToOSDArray(classifiedCategories);
518
519 #region UI Config
520
521 OSDMap uiConfigLLSD = new OSDMap();
522 uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife);
523 map["ui-config"] = WrapOSDMap(uiConfigLLSD);
524
525 #endregion UI Config
526
527 #region Inventory
528
529 map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory);
530
531 map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary);
532 map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ;
533 map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot);
534 map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner);
535
536 #endregion Inventory
537
538 map["gestures"] = ArrayListToOSDArray(activeGestures);
539
540 map["initial-outfit"] = ArrayListToOSDArray(initialOutfit);
541 map["start_location"] = OSD.FromString(startLocation);
542
543 map["seed_capability"] = OSD.FromString(seedCapability);
544 map["home"] = OSD.FromString(home);
545 map["look_at"] = OSD.FromString(lookAt);
546 map["message"] = OSD.FromString(welcomeMessage);
547 map["region_x"] = OSD.FromInteger(RegionX);
548 map["region_y"] = OSD.FromInteger(RegionY);
549
550 if (m_buddyList != null)
551 {
552 map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray());
553 }
554
555 map["login"] = OSD.FromString("true");
556
557 return map;
558 }
559 catch (Exception e)
560 {
561 m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
562
563 return LLFailedLoginResponse.InternalError.ToOSDMap();
564 }
565 }
566
567 public OSDArray ArrayListToOSDArray(ArrayList arrlst)
568 {
569 OSDArray llsdBack = new OSDArray();
570 foreach (Hashtable ht in arrlst)
571 {
572 OSDMap mp = new OSDMap();
573 foreach (DictionaryEntry deHt in ht)
574 {
575 mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value));
576 }
577 llsdBack.Add(mp);
578 }
579 return llsdBack;
580 }
581
582 private static OSDArray WrapOSDMap(OSDMap wrapMe)
583 {
584 OSDArray array = new OSDArray();
585 array.Add(wrapMe);
586 return array;
587 }
588
589 public void SetEventCategories(string category, string value)
590 {
591 // this.eventCategoriesHash[category] = value;
592 //TODO
593 }
594
595 public void AddToUIConfig(string itemName, string item)
596 {
597 uiConfigHash[itemName] = item;
598 }
599
600 public void AddClassifiedCategory(Int32 ID, string categoryName)
601 {
602 Hashtable hash = new Hashtable();
603 hash["category_name"] = categoryName;
604 hash["category_id"] = ID;
605 classifiedCategories.Add(hash);
606 // this.classifiedCategoriesHash.Clear();
607 }
608
609
610 private static LLLoginResponse.BuddyList ConvertFriendListItem(List<FriendListItem> LFL)
611 {
612 LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
613 foreach (FriendListItem fl in LFL)
614 {
615 LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(fl.Friend);
616 buddyitem.BuddyID = fl.Friend;
617 buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms;
618 buddyitem.BuddyRightsGiven = (int)fl.FriendPerms;
619 buddylistreturn.AddNewBuddy(buddyitem);
620 }
621 return buddylistreturn;
622 }
623
624 private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
625 {
626 UUID rootID = UUID.Zero;
627 ArrayList AgentInventoryArray = new ArrayList();
628 Hashtable TempHash;
629 foreach (InventoryFolderBase InvFolder in folders)
630 {
631 if (InvFolder.ParentID == UUID.Zero)
632 {
633 rootID = InvFolder.ID;
634 }
635 TempHash = new Hashtable();
636 TempHash["name"] = InvFolder.Name;
637 TempHash["parent_id"] = InvFolder.ParentID.ToString();
638 TempHash["version"] = (Int32)InvFolder.Version;
639 TempHash["type_default"] = (Int32)InvFolder.Type;
640 TempHash["folder_id"] = InvFolder.ID.ToString();
641 AgentInventoryArray.Add(TempHash);
642 }
643
644 return new InventoryData(AgentInventoryArray, rootID);
645
646 }
647
648 /// <summary>
649 /// Converts the inventory library skeleton into the form required by the rpc request.
650 /// </summary>
651 /// <returns></returns>
652 protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
653 {
654 Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
655 m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
656 //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
657 ArrayList folderHashes = new ArrayList();
658
659 foreach (InventoryFolderBase folder in rootFolders.Values)
660 {
661 Hashtable TempHash = new Hashtable();
662 TempHash["name"] = folder.Name;
663 TempHash["parent_id"] = folder.ParentID.ToString();
664 TempHash["version"] = (Int32)folder.Version;
665 TempHash["type_default"] = (Int32)folder.Type;
666 TempHash["folder_id"] = folder.ID.ToString();
667 folderHashes.Add(TempHash);
668 }
669
670 return folderHashes;
671 }
672
673 /// <summary>
674 ///
675 /// </summary>
676 /// <returns></returns>
677 protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
678 {
679 //for now create random inventory library owner
680 Hashtable TempHash = new Hashtable();
681 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
682 ArrayList inventoryLibOwner = new ArrayList();
683 inventoryLibOwner.Add(TempHash);
684 return inventoryLibOwner;
685 }
686
687 public class InventoryData
688 {
689 public ArrayList InventoryArray = null;
690 public UUID RootFolderID = UUID.Zero;
691
692 public InventoryData(ArrayList invList, UUID rootID)
693 {
694 InventoryArray = invList;
695 RootFolderID = rootID;
696 }
697 }
698
699 #region Properties
700
701 public string Login
702 {
703 get { return login; }
704 set { login = value; }
705 }
706
707 public string DST
708 {
709 get { return dst; }
710 set { dst = value; }
711 }
712
713 public string StipendSinceLogin
714 {
715 get { return stipendSinceLogin; }
716 set { stipendSinceLogin = value; }
717 }
718
719 public string Gendered
720 {
721 get { return gendered; }
722 set { gendered = value; }
723 }
724
725 public string EverLoggedIn
726 {
727 get { return everLoggedIn; }
728 set { everLoggedIn = value; }
729 }
730
731 public uint SimPort
732 {
733 get { return simPort; }
734 set { simPort = value; }
735 }
736
737 public uint SimHttpPort
738 {
739 get { return simHttpPort; }
740 set { simHttpPort = value; }
741 }
742
743 public string SimAddress
744 {
745 get { return simAddress; }
746 set { simAddress = value; }
747 }
748
749 public UUID AgentID
750 {
751 get { return agentID; }
752 set { agentID = value; }
753 }
754
755 public UUID SessionID
756 {
757 get { return sessionID; }
758 set { sessionID = value; }
759 }
760
761 public UUID SecureSessionID
762 {
763 get { return secureSessionID; }
764 set { secureSessionID = value; }
765 }
766
767 public Int32 CircuitCode
768 {
769 get { return circuitCode; }
770 set { circuitCode = value; }
771 }
772
773 public uint RegionX
774 {
775 get { return regionX; }
776 set { regionX = value; }
777 }
778
779 public uint RegionY
780 {
781 get { return regionY; }
782 set { regionY = value; }
783 }
784
785 public string SunTexture
786 {
787 get { return sunTexture; }
788 set { sunTexture = value; }
789 }
790
791 public string CloudTexture
792 {
793 get { return cloudTexture; }
794 set { cloudTexture = value; }
795 }
796
797 public string MoonTexture
798 {
799 get { return moonTexture; }
800 set { moonTexture = value; }
801 }
802
803 public string Firstname
804 {
805 get { return firstname; }
806 set { firstname = value; }
807 }
808
809 public string Lastname
810 {
811 get { return lastname; }
812 set { lastname = value; }
813 }
814
815 public string AgentAccess
816 {
817 get { return agentAccess; }
818 set { agentAccess = value; }
819 }
820
821 public string AgentAccessMax
822 {
823 get { return agentAccessMax; }
824 set { agentAccessMax = value; }
825 }
826
827 public string StartLocation
828 {
829 get { return startLocation; }
830 set { startLocation = value; }
831 }
832
833 public string LookAt
834 {
835 get { return lookAt; }
836 set { lookAt = value; }
837 }
838
839 public string SeedCapability
840 {
841 get { return seedCapability; }
842 set { seedCapability = value; }
843 }
844
845 public string ErrorReason
846 {
847 get { return errorReason; }
848 set { errorReason = value; }
849 }
850
851 public string ErrorMessage
852 {
853 get { return errorMessage; }
854 set { errorMessage = value; }
855 }
856
857 public ArrayList InventoryRoot
858 {
859 get { return inventoryRoot; }
860 set { inventoryRoot = value; }
861 }
862
863 public ArrayList InventorySkeleton
864 {
865 get { return agentInventory; }
866 set { agentInventory = value; }
867 }
868
869 public ArrayList InventoryLibrary
870 {
871 get { return inventoryLibrary; }
872 set { inventoryLibrary = value; }
873 }
874
875 public ArrayList InventoryLibraryOwner
876 {
877 get { return inventoryLibraryOwner; }
878 set { inventoryLibraryOwner = value; }
879 }
880
881 public ArrayList InventoryLibRoot
882 {
883 get { return inventoryLibRoot; }
884 set { inventoryLibRoot = value; }
885 }
886
887 public ArrayList ActiveGestures
888 {
889 get { return activeGestures; }
890 set { activeGestures = value; }
891 }
892
893 public string Home
894 {
895 get { return home; }
896 set { home = value; }
897 }
898
899 public string Message
900 {
901 get { return welcomeMessage; }
902 set { welcomeMessage = value; }
903 }
904
905 public BuddyList BuddList
906 {
907 get { return m_buddyList; }
908 set { m_buddyList = value; }
909 }
910
911 #endregion
912
913 public class UserInfo
914 {
915 public string firstname;
916 public string lastname;
917 public ulong homeregionhandle;
918 public Vector3 homepos;
919 public Vector3 homelookat;
920 }
921
922 public class BuddyList
923 {
924 public List<BuddyInfo> Buddies = new List<BuddyInfo>();
925
926 public void AddNewBuddy(BuddyInfo buddy)
927 {
928 if (!Buddies.Contains(buddy))
929 {
930 Buddies.Add(buddy);
931 }
932 }
933
934 public ArrayList ToArray()
935 {
936 ArrayList buddyArray = new ArrayList();
937 foreach (BuddyInfo buddy in Buddies)
938 {
939 buddyArray.Add(buddy.ToHashTable());
940 }
941 return buddyArray;
942 }
943
944 public class BuddyInfo
945 {
946 public int BuddyRightsHave = 1;
947 public int BuddyRightsGiven = 1;
948 public UUID BuddyID;
949
950 public BuddyInfo(string buddyID)
951 {
952 BuddyID = new UUID(buddyID);
953 }
954
955 public BuddyInfo(UUID buddyID)
956 {
957 BuddyID = buddyID;
958 }
959
960 public Hashtable ToHashTable()
961 {
962 Hashtable hTable = new Hashtable();
963 hTable["buddy_rights_has"] = BuddyRightsHave;
964 hTable["buddy_rights_given"] = BuddyRightsGiven;
965 hTable["buddy_id"] = BuddyID.ToString();
966 return hTable;
967 }
968 }
969 }
970 }
971}
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
new file mode 100644
index 0000000..a3f52ff
--- /dev/null
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -0,0 +1,639 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Reflection;
5using System.Text.RegularExpressions;
6
7using log4net;
8using Nini.Config;
9using OpenMetaverse;
10
11using OpenSim.Framework;
12using OpenSim.Framework.Capabilities;
13using OpenSim.Framework.Console;
14using OpenSim.Server.Base;
15using OpenSim.Services.Interfaces;
16using GridRegion = OpenSim.Services.Interfaces.GridRegion;
17using OpenSim.Services.Connectors.Hypergrid;
18
19namespace OpenSim.Services.LLLoginService
20{
21 public class LLLoginService : ILoginService
22 {
23 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
24 private static bool Initialized = false;
25
26 private IUserAccountService m_UserAccountService;
27 private IAuthenticationService m_AuthenticationService;
28 private IInventoryService m_InventoryService;
29 private IGridService m_GridService;
30 private IPresenceService m_PresenceService;
31 private ISimulationService m_LocalSimulationService;
32 private ISimulationService m_RemoteSimulationService;
33 private ILibraryService m_LibraryService;
34 private IAvatarService m_AvatarService;
35 private IUserAgentService m_UserAgentService;
36
37 private GatekeeperServiceConnector m_GatekeeperConnector;
38
39 private string m_DefaultRegionName;
40 private string m_WelcomeMessage;
41 private bool m_RequireInventory;
42 private int m_MinLoginLevel;
43 private string m_GatekeeperURL;
44
45 IConfig m_LoginServerConfig;
46
47 public LLLoginService(IConfigSource config, ISimulationService simService, ILibraryService libraryService)
48 {
49 m_LoginServerConfig = config.Configs["LoginService"];
50 if (m_LoginServerConfig == null)
51 throw new Exception(String.Format("No section LoginService in config file"));
52
53 string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty);
54 string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty);
55 string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty);
56 string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty);
57 string gridService = m_LoginServerConfig.GetString("GridService", String.Empty);
58 string presenceService = m_LoginServerConfig.GetString("PresenceService", String.Empty);
59 string libService = m_LoginServerConfig.GetString("LibraryService", String.Empty);
60 string avatarService = m_LoginServerConfig.GetString("AvatarService", String.Empty);
61 string simulationService = m_LoginServerConfig.GetString("SimulationService", String.Empty);
62
63 m_DefaultRegionName = m_LoginServerConfig.GetString("DefaultRegion", String.Empty);
64 m_WelcomeMessage = m_LoginServerConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
65 m_RequireInventory = m_LoginServerConfig.GetBoolean("RequireInventory", true);
66 m_GatekeeperURL = m_LoginServerConfig.GetString("GatekeeperURI", string.Empty);
67
68 // These are required; the others aren't
69 if (accountService == string.Empty || authService == string.Empty)
70 throw new Exception("LoginService is missing service specifications");
71
72 Object[] args = new Object[] { config };
73 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
74 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args);
75 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
76 if (gridService != string.Empty)
77 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
78 if (presenceService != string.Empty)
79 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
80 if (avatarService != string.Empty)
81 m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
82 if (simulationService != string.Empty)
83 m_RemoteSimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
84 if (agentService != string.Empty)
85 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(agentService, args);
86
87 //
88 // deal with the services given as argument
89 //
90 m_LocalSimulationService = simService;
91 if (libraryService != null)
92 {
93 m_log.DebugFormat("[LLOGIN SERVICE]: Using LibraryService given as argument");
94 m_LibraryService = libraryService;
95 }
96 else if (libService != string.Empty)
97 {
98 m_log.DebugFormat("[LLOGIN SERVICE]: Using instantiated LibraryService");
99 m_LibraryService = ServerUtils.LoadPlugin<ILibraryService>(libService, args);
100 }
101
102 m_GatekeeperConnector = new GatekeeperServiceConnector();
103
104 if (!Initialized)
105 {
106 Initialized = true;
107 RegisterCommands();
108 }
109
110 m_log.DebugFormat("[LLOGIN SERVICE]: Starting...");
111
112 }
113
114 public LLLoginService(IConfigSource config) : this(config, null, null)
115 {
116 }
117
118 public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, IPEndPoint clientIP)
119 {
120 bool success = false;
121 UUID session = UUID.Random();
122
123 try
124 {
125 //
126 // Get the account and check that it exists
127 //
128 UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
129 if (account == null)
130 {
131 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: user not found");
132 return LLFailedLoginResponse.UserProblem;
133 }
134
135 if (account.UserLevel < m_MinLoginLevel)
136 {
137 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel);
138 return LLFailedLoginResponse.LoginBlockedProblem;
139 }
140
141 //
142 // Authenticate this user
143 //
144 if (!passwd.StartsWith("$1$"))
145 passwd = "$1$" + Util.Md5Hash(passwd);
146 passwd = passwd.Remove(0, 3); //remove $1$
147 string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30);
148 UUID secureSession = UUID.Zero;
149 if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
150 {
151 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: authentication failed");
152 return LLFailedLoginResponse.UserProblem;
153 }
154
155 //
156 // Get the user's inventory
157 //
158 if (m_RequireInventory && m_InventoryService == null)
159 {
160 m_log.WarnFormat("[LLOGIN SERVICE]: Login failed, reason: inventory service not set up");
161 return LLFailedLoginResponse.InventoryProblem;
162 }
163 List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
164 if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
165 {
166 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory");
167 return LLFailedLoginResponse.InventoryProblem;
168 }
169
170 //
171 // Login the presence
172 //
173 PresenceInfo presence = null;
174 GridRegion home = null;
175 if (m_PresenceService != null)
176 {
177 success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession);
178 if (!success)
179 {
180 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence");
181 return LLFailedLoginResponse.GridProblem;
182 }
183
184 // Get the updated presence info
185 presence = m_PresenceService.GetAgent(session);
186
187 // Get the home region
188 if ((presence.HomeRegionID != UUID.Zero) && m_GridService != null)
189 {
190 home = m_GridService.GetRegionByUUID(account.ScopeID, presence.HomeRegionID);
191 }
192 }
193
194 //
195 // Find the destination region/grid
196 //
197 string where = string.Empty;
198 Vector3 position = Vector3.Zero;
199 Vector3 lookAt = Vector3.Zero;
200 GridRegion gatekeeper = null;
201 GridRegion destination = FindDestination(account, presence, session, startLocation, out gatekeeper, out where, out position, out lookAt);
202 if (destination == null)
203 {
204 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt);
205 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found");
206 return LLFailedLoginResponse.GridProblem;
207 }
208
209 //
210 // Get the avatar
211 //
212 AvatarData avatar = null;
213 if (m_AvatarService != null)
214 {
215 avatar = m_AvatarService.GetAvatar(account.PrincipalID);
216 }
217
218 //
219 // Instantiate/get the simulation interface and launch an agent at the destination
220 //
221 string reason = string.Empty;
222 AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, out where, out reason);
223
224 if (aCircuit == null)
225 {
226 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt);
227 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason);
228 return LLFailedLoginResponse.AuthorizationProblem;
229
230 }
231 // TODO: Get Friends list...
232
233 //
234 // Finally, fill out the response and return it
235 //
236 LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel, m_LibraryService,
237 where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP);
238
239 return response;
240 }
241 catch (Exception e)
242 {
243 m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2}", firstName, lastName, e.StackTrace);
244 if (m_PresenceService != null)
245 m_PresenceService.LogoutAgent(session, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
246 return LLFailedLoginResponse.InternalError;
247 }
248 }
249
250 private GridRegion FindDestination(UserAccount account, PresenceInfo pinfo, UUID sessionID, string startLocation, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt)
251 {
252 m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation);
253
254 gatekeeper = null;
255 where = "home";
256 position = new Vector3(128, 128, 0);
257 lookAt = new Vector3(0, 1, 0);
258
259 if (m_GridService == null)
260 return null;
261
262 if (startLocation.Equals("home"))
263 {
264 // logging into home region
265 if (pinfo == null)
266 return null;
267
268 GridRegion region = null;
269
270 if (pinfo.HomeRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID)) == null)
271 {
272 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
273 if (defaults != null && defaults.Count > 0)
274 {
275 region = defaults[0];
276 where = "safe";
277 }
278 else
279 m_log.WarnFormat("[LLOGIN SERVICE]: User {0} {1} does not have a home set and this grid does not have default locations.",
280 account.FirstName, account.LastName);
281 }
282
283 return region;
284 }
285 else if (startLocation.Equals("last"))
286 {
287 // logging into last visited region
288 where = "last";
289
290 if (pinfo == null)
291 return null;
292
293 GridRegion region = null;
294
295 if (pinfo.RegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.RegionID)) == null)
296 {
297 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
298 if (defaults != null && defaults.Count > 0)
299 {
300 region = defaults[0];
301 where = "safe";
302 }
303 }
304 else
305 {
306 position = pinfo.Position;
307 lookAt = pinfo.LookAt;
308 }
309 return region;
310
311 }
312 else
313 {
314 // free uri form
315 // e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34
316 where = "url";
317 Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$");
318 Match uriMatch = reURI.Match(startLocation);
319 if (uriMatch == null)
320 {
321 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation);
322 return null;
323 }
324 else
325 {
326 position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
327 float.Parse(uriMatch.Groups["y"].Value),
328 float.Parse(uriMatch.Groups["z"].Value));
329
330 string regionName = uriMatch.Groups["region"].ToString();
331 if (regionName != null)
332 {
333 if (!regionName.Contains("@"))
334 {
335
336 List<GridRegion> regions = m_GridService.GetRegionsByName(account.ScopeID, regionName, 1);
337 if ((regions == null) || (regions != null && regions.Count == 0))
338 {
339 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName);
340 regions = m_GridService.GetDefaultRegions(UUID.Zero);
341 if (regions != null && regions.Count > 0)
342 {
343 where = "safe";
344 return regions[0];
345 }
346 else
347 {
348 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions.", startLocation);
349 return null;
350 }
351 }
352 return regions[0];
353 }
354 else
355 {
356 if (m_UserAgentService == null)
357 {
358 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");
359 return null;
360 }
361 string[] parts = regionName.Split(new char[] { '@' });
362 if (parts.Length < 2)
363 {
364 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName);
365 return null;
366 }
367 // Valid specification of a remote grid
368 regionName = parts[0];
369 string domainLocator = parts[1];
370 parts = domainLocator.Split(new char[] {':'});
371 string domainName = parts[0];
372 uint port = 0;
373 if (parts.Length > 1)
374 UInt32.TryParse(parts[1], out port);
375 GridRegion region = FindForeignRegion(domainName, port, regionName, out gatekeeper);
376 return region;
377 }
378 }
379 else
380 {
381 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
382 if (defaults != null && defaults.Count > 0)
383 {
384 where = "safe";
385 return defaults[0];
386 }
387 else
388 return null;
389 }
390 }
391 //response.LookAt = "[r0,r1,r0]";
392 //// can be: last, home, safe, url
393 //response.StartLocation = "url";
394
395 }
396
397 }
398
399 private GridRegion FindForeignRegion(string domainName, uint port, string regionName, out GridRegion gatekeeper)
400 {
401 gatekeeper = new GridRegion();
402 gatekeeper.ExternalHostName = domainName;
403 gatekeeper.HttpPort = port;
404 gatekeeper.RegionName = regionName;
405 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
406
407 UUID regionID;
408 ulong handle;
409 string imageURL = string.Empty, reason = string.Empty;
410 if (m_GatekeeperConnector.LinkRegion(gatekeeper, out regionID, out handle, out domainName, out imageURL, out reason))
411 {
412 GridRegion destination = m_GatekeeperConnector.GetHyperlinkRegion(gatekeeper, regionID);
413 return destination;
414 }
415
416 return null;
417 }
418
419 private string hostName = string.Empty;
420 private int port = 0;
421
422 private void SetHostAndPort(string url)
423 {
424 try
425 {
426 Uri uri = new Uri(url);
427 hostName = uri.Host;
428 port = uri.Port;
429 }
430 catch
431 {
432 m_log.WarnFormat("[LLLogin SERVICE]: Unable to parse GatekeeperURL {0}", url);
433 }
434 }
435
436 private AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarData avatar,
437 UUID session, UUID secureSession, Vector3 position, string currentWhere, out string where, out string reason)
438 {
439 where = currentWhere;
440 ISimulationService simConnector = null;
441 reason = string.Empty;
442 uint circuitCode = 0;
443 AgentCircuitData aCircuit = null;
444
445 if (m_UserAgentService == null)
446 {
447 // HG standalones have both a localSimulatonDll and a remoteSimulationDll
448 // non-HG standalones have just a localSimulationDll
449 // independent login servers have just a remoteSimulationDll
450 if (m_LocalSimulationService != null)
451 simConnector = m_LocalSimulationService;
452 else if (m_RemoteSimulationService != null)
453 simConnector = m_RemoteSimulationService;
454 }
455 else // User Agent Service is on
456 {
457 if (gatekeeper == null) // login to local grid
458 {
459 if (hostName == string.Empty)
460 SetHostAndPort(m_GatekeeperURL);
461
462 gatekeeper = new GridRegion(destination);
463 gatekeeper.ExternalHostName = hostName;
464 gatekeeper.HttpPort = (uint)port;
465
466 }
467 else // login to foreign grid
468 {
469 }
470 }
471
472 bool success = false;
473
474 if (m_UserAgentService == null && simConnector != null)
475 {
476 circuitCode = (uint)Util.RandomClass.Next(); ;
477 aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position);
478 success = LaunchAgentDirectly(simConnector, destination, aCircuit, out reason);
479 if (!success && m_GridService != null)
480 {
481 // Try the fallback regions
482 List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
483 if (fallbacks != null)
484 {
485 foreach (GridRegion r in fallbacks)
486 {
487 success = LaunchAgentDirectly(simConnector, r, aCircuit, out reason);
488 if (success)
489 {
490 where = "safe";
491 destination = r;
492 break;
493 }
494 }
495 }
496 }
497 }
498
499 if (m_UserAgentService != null)
500 {
501 circuitCode = (uint)Util.RandomClass.Next(); ;
502 aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position);
503 success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, out reason);
504 if (!success && m_GridService != null)
505 {
506 // Try the fallback regions
507 List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
508 if (fallbacks != null)
509 {
510 foreach (GridRegion r in fallbacks)
511 {
512 success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, out reason);
513 if (success)
514 {
515 where = "safe";
516 destination = r;
517 break;
518 }
519 }
520 }
521 }
522 }
523
524 if (success)
525 return aCircuit;
526 else
527 return null;
528 }
529
530 private AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
531 AvatarData avatar, UUID session, UUID secureSession, uint circuit, Vector3 position)
532 {
533 AgentCircuitData aCircuit = new AgentCircuitData();
534
535 aCircuit.AgentID = account.PrincipalID;
536 if (avatar != null)
537 aCircuit.Appearance = avatar.ToAvatarAppearance(account.PrincipalID);
538 else
539 aCircuit.Appearance = new AvatarAppearance(account.PrincipalID);
540
541 //aCircuit.BaseFolder = irrelevant
542 aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
543 aCircuit.child = false; // the first login agent is root
544 aCircuit.ChildrenCapSeeds = new Dictionary<ulong, string>();
545 aCircuit.circuitcode = circuit;
546 aCircuit.firstname = account.FirstName;
547 //aCircuit.InventoryFolder = irrelevant
548 aCircuit.lastname = account.LastName;
549 aCircuit.SecureSessionID = secureSession;
550 aCircuit.SessionID = session;
551 aCircuit.startpos = position;
552 SetServiceURLs(aCircuit, account);
553
554 return aCircuit;
555
556 //m_UserAgentService.LoginAgentToGrid(aCircuit, GatekeeperServiceConnector, region, out reason);
557 //if (simConnector.CreateAgent(region, aCircuit, 0, out reason))
558 // return aCircuit;
559
560 //return null;
561
562 }
563
564 private void SetServiceURLs(AgentCircuitData aCircuit, UserAccount account)
565 {
566 aCircuit.ServiceURLs = new Dictionary<string, object>();
567 if (account.ServiceURLs == null)
568 return;
569
570 foreach (KeyValuePair<string, object> kvp in account.ServiceURLs)
571 {
572 if (kvp.Value == null || (kvp.Value != null && kvp.Value.ToString() == string.Empty))
573 {
574 aCircuit.ServiceURLs[kvp.Key] = m_LoginServerConfig.GetString(kvp.Key, string.Empty);
575 }
576 else
577 {
578 aCircuit.ServiceURLs[kvp.Key] = kvp.Value;
579 }
580 }
581 }
582
583 private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, out string reason)
584 {
585 return simConnector.CreateAgent(region, aCircuit, (int)Constants.TeleportFlags.ViaLogin, out reason);
586 }
587
588 private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, out string reason)
589 {
590 m_log.Debug("XXX Launching agent at {0}" + destination.RegionName);
591 return m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason);
592 }
593
594 #region Console Commands
595 private void RegisterCommands()
596 {
597 //MainConsole.Instance.Commands.AddCommand
598 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login level",
599 "login level <level>",
600 "Set the minimum user level to log in", HandleLoginCommand);
601
602 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login reset",
603 "login reset",
604 "Reset the login level to allow all users",
605 HandleLoginCommand);
606
607 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login text",
608 "login text <text>",
609 "Set the text users will see on login", HandleLoginCommand);
610
611 }
612
613 private void HandleLoginCommand(string module, string[] cmd)
614 {
615 string subcommand = cmd[1];
616
617 switch (subcommand)
618 {
619 case "level":
620 // Set the minimum level to allow login
621 // Useful to allow grid update without worrying about users.
622 // or fixing critical issues
623 //
624 if (cmd.Length > 2)
625 Int32.TryParse(cmd[2], out m_MinLoginLevel);
626 break;
627 case "reset":
628 m_MinLoginLevel = 0;
629 break;
630 case "text":
631 if (cmd.Length > 2)
632 m_WelcomeMessage = cmd[2];
633 break;
634 }
635 }
636 }
637
638 #endregion
639}
diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs
index 2157462..350eac8 100644
--- a/OpenSim/Services/PresenceService/PresenceService.cs
+++ b/OpenSim/Services/PresenceService/PresenceService.cs
@@ -41,27 +41,177 @@ 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 return info.ToArray();
210 }
211
212 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
213 {
214 return m_Database.SetHomeLocation(userID, regionID, position, lookAt);
65 } 215 }
66 } 216 }
67} 217}
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..ffb9cca
--- /dev/null
+++ b/OpenSim/Services/UserAccountService/UserAccountService.cs
@@ -0,0 +1,359 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using Nini.Config;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Framework.Console;
35using GridRegion = OpenSim.Services.Interfaces.GridRegion;
36
37using OpenMetaverse;
38using log4net;
39
40namespace 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 MainConsole.Instance.Commands.AddCommand("UserService", false,
81 "create user",
82 "create user [<first> [<last> [<pass> [<email>]]]]",
83 "Create a new user", HandleCreateUser);
84 MainConsole.Instance.Commands.AddCommand("UserService", false, "reset user password",
85 "reset user password [<first> [<last> [<password>]]]",
86 "Reset a user password", HandleResetUserPassword);
87
88 }
89
90 }
91
92 #region IUserAccountService
93
94 public UserAccount GetUserAccount(UUID scopeID, string firstName,
95 string lastName)
96 {
97 UserAccountData[] d;
98
99 if (scopeID != UUID.Zero)
100 {
101 d = m_Database.Get(
102 new string[] { "ScopeID", "FirstName", "LastName" },
103 new string[] { scopeID.ToString(), firstName, lastName });
104 }
105 else
106 {
107 d = m_Database.Get(
108 new string[] { "FirstName", "LastName" },
109 new string[] { firstName, lastName });
110 }
111
112 if (d.Length < 1)
113 return null;
114
115 return MakeUserAccount(d[0]);
116 }
117
118 private UserAccount MakeUserAccount(UserAccountData d)
119 {
120 UserAccount u = new UserAccount();
121 u.FirstName = d.FirstName;
122 u.LastName = d.LastName;
123 u.PrincipalID = d.PrincipalID;
124 u.ScopeID = d.ScopeID;
125 if (d.Data.ContainsKey("Email") && d.Data["Email"] != null)
126 u.Email = d.Data["Email"].ToString();
127 else
128 u.Email = string.Empty;
129 u.Created = Convert.ToInt32(d.Data["Created"].ToString());
130 if (d.Data.ContainsKey("UserTitle") && d.Data["UserTitle"] != null)
131 u.UserTitle = d.Data["UserTitle"].ToString();
132 else
133 u.UserTitle = string.Empty;
134
135 if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null)
136 {
137 string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' });
138 u.ServiceURLs = new Dictionary<string, object>();
139
140 foreach (string url in URLs)
141 {
142 string[] parts = url.Split(new char[] { '=' });
143
144 if (parts.Length != 2)
145 continue;
146
147 string name = System.Web.HttpUtility.UrlDecode(parts[0]);
148 string val = System.Web.HttpUtility.UrlDecode(parts[1]);
149
150 u.ServiceURLs[name] = val;
151 }
152 }
153 else
154 u.ServiceURLs = new Dictionary<string, object>();
155
156 return u;
157 }
158
159 public UserAccount GetUserAccount(UUID scopeID, string email)
160 {
161 UserAccountData[] d;
162
163 if (scopeID != UUID.Zero)
164 {
165 d = m_Database.Get(
166 new string[] { "ScopeID", "Email" },
167 new string[] { scopeID.ToString(), email });
168 }
169 else
170 {
171 d = m_Database.Get(
172 new string[] { "Email" },
173 new string[] { email });
174 }
175
176 if (d.Length < 1)
177 return null;
178
179 return MakeUserAccount(d[0]);
180 }
181
182 public UserAccount GetUserAccount(UUID scopeID, UUID principalID)
183 {
184 UserAccountData[] d;
185
186 if (scopeID != UUID.Zero)
187 {
188 d = m_Database.Get(
189 new string[] { "ScopeID", "PrincipalID" },
190 new string[] { scopeID.ToString(), principalID.ToString() });
191 }
192 else
193 {
194 d = m_Database.Get(
195 new string[] { "PrincipalID" },
196 new string[] { principalID.ToString() });
197 }
198
199 if (d.Length < 1)
200 return null;
201
202 return MakeUserAccount(d[0]);
203 }
204
205 public bool StoreUserAccount(UserAccount data)
206 {
207 UserAccountData d = new UserAccountData();
208
209 d.FirstName = data.FirstName;
210 d.LastName = data.LastName;
211 d.PrincipalID = data.PrincipalID;
212 d.ScopeID = data.ScopeID;
213 d.Data = new Dictionary<string, string>();
214 d.Data["Email"] = data.Email;
215 d.Data["Created"] = data.Created.ToString();
216
217 List<string> parts = new List<string>();
218
219 foreach (KeyValuePair<string, object> kvp in data.ServiceURLs)
220 {
221 string key = System.Web.HttpUtility.UrlEncode(kvp.Key);
222 string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString());
223 parts.Add(key + "=" + val);
224 }
225
226 d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray());
227
228 return m_Database.Store(d);
229 }
230
231 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
232 {
233 UserAccountData[] d = m_Database.GetUsers(scopeID, query);
234
235 if (d == null)
236 return new List<UserAccount>();
237
238 List<UserAccount> ret = new List<UserAccount>();
239
240 foreach (UserAccountData data in d)
241 ret.Add(MakeUserAccount(data));
242
243 return ret;
244 }
245
246 #endregion
247
248 #region Console commands
249 /// <summary>
250 /// Create a new user
251 /// </summary>
252 /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
253 protected void HandleCreateUser(string module, string[] cmdparams)
254 {
255 string firstName;
256 string lastName;
257 string password;
258 string email;
259
260 if (cmdparams.Length < 3)
261 firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
262 else firstName = cmdparams[2];
263
264 if (cmdparams.Length < 4)
265 lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
266 else lastName = cmdparams[3];
267
268 if (cmdparams.Length < 5)
269 password = MainConsole.Instance.PasswdPrompt("Password");
270 else password = cmdparams[4];
271
272 if (cmdparams.Length < 6)
273 email = MainConsole.Instance.CmdPrompt("Email", "");
274 else email = cmdparams[5];
275
276 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
277 if (null == account)
278 {
279 account = new UserAccount(UUID.Zero, firstName, lastName, email);
280 if (StoreUserAccount(account))
281 {
282 bool success = false;
283 if (m_AuthenticationService != null)
284 success = m_AuthenticationService.SetPassword(account.PrincipalID, password);
285 if (!success)
286 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.",
287 firstName, lastName);
288
289 GridRegion home = null;
290 if (m_GridService != null)
291 {
292 List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero);
293 if (defaultRegions != null && defaultRegions.Count >= 1)
294 home = defaultRegions[0];
295
296 if (m_PresenceService != null && home != null)
297 m_PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
298 else
299 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.",
300 firstName, lastName);
301
302 }
303 else
304 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.",
305 firstName, lastName);
306
307 if (m_InventoryService != null)
308 success = m_InventoryService.CreateUserInventory(account.PrincipalID);
309 if (!success)
310 m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.",
311 firstName, lastName);
312
313
314 m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", firstName, lastName);
315 }
316 }
317 else
318 {
319 m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName);
320 }
321
322 }
323
324 protected void HandleResetUserPassword(string module, string[] cmdparams)
325 {
326 string firstName;
327 string lastName;
328 string newPassword;
329
330 if (cmdparams.Length < 4)
331 firstName = MainConsole.Instance.CmdPrompt("First name");
332 else firstName = cmdparams[3];
333
334 if (cmdparams.Length < 5)
335 lastName = MainConsole.Instance.CmdPrompt("Last name");
336 else lastName = cmdparams[4];
337
338 if (cmdparams.Length < 6)
339 newPassword = MainConsole.Instance.PasswdPrompt("New password");
340 else newPassword = cmdparams[5];
341
342 UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName);
343 if (account == null)
344 m_log.ErrorFormat("[USER ACCOUNT SERVICE]: No such user");
345
346 bool success = false;
347 if (m_AuthenticationService != null)
348 success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword);
349 if (!success)
350 m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Unable to reset password for account {0} {1}.",
351 firstName, lastName);
352 else
353 m_log.InfoFormat("[USER ACCOUNT SERVICE]: Password reset for user {0} {1}", firstName, lastName);
354 }
355
356 #endregion
357
358 }
359}
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