diff options
Diffstat (limited to 'OpenSim/Data')
20 files changed, 644 insertions, 146 deletions
diff --git a/OpenSim/Data/IAvatarData.cs b/OpenSim/Data/IAvatarData.cs new file mode 100644 index 0000000..0a18e21 --- /dev/null +++ b/OpenSim/Data/IAvatarData.cs | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Data | ||
34 | { | ||
35 | // This MUST be a ref type! | ||
36 | public class AvatarBaseData | ||
37 | { | ||
38 | public UUID PrincipalID; | ||
39 | public Dictionary<string, string> Data; | ||
40 | } | ||
41 | |||
42 | public interface IAvatarData | ||
43 | { | ||
44 | AvatarBaseData[] Get(string field, string val); | ||
45 | bool Store(AvatarBaseData data); | ||
46 | bool Delete(UUID principalID, string name); | ||
47 | bool Delete(string field, string val); | ||
48 | } | ||
49 | } | ||
diff --git a/OpenSim/Data/IPresenceData.cs b/OpenSim/Data/IPresenceData.cs index e5a8ebd..71d0e31 100644 --- a/OpenSim/Data/IPresenceData.cs +++ b/OpenSim/Data/IPresenceData.cs | |||
@@ -32,25 +32,28 @@ using OpenSim.Framework; | |||
32 | 32 | ||
33 | namespace OpenSim.Data | 33 | namespace OpenSim.Data |
34 | { | 34 | { |
35 | public struct PresenceData | 35 | // This MUST be a ref type! |
36 | public class PresenceData | ||
36 | { | 37 | { |
37 | public UUID UUID; | 38 | public string UserID; |
38 | public UUID currentRegion; | 39 | public UUID RegionID; |
40 | public UUID SessionID; | ||
39 | public Dictionary<string, string> Data; | 41 | public Dictionary<string, string> Data; |
40 | } | 42 | } |
41 | 43 | ||
42 | /// <summary> | 44 | /// <summary> |
43 | /// An interface for connecting to the authentication datastore | 45 | /// An interface for connecting to the presence datastore |
44 | /// </summary> | 46 | /// </summary> |
45 | public interface IPresenceData | 47 | public interface IPresenceData |
46 | { | 48 | { |
47 | bool Store(PresenceData data); | 49 | bool Store(PresenceData data); |
48 | 50 | ||
49 | PresenceData Get(UUID principalID); | 51 | PresenceData Get(UUID sessionID); |
50 | 52 | void LogoutRegionAgents(UUID regionID); | |
51 | bool SetUserDataItem(UUID principalID, string item, string value); | 53 | bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt); |
52 | bool SetRegionDataItem(UUID principalID, string item, string value); | 54 | bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); |
53 | 55 | PresenceData[] Get(string field, string data); | |
54 | bool Delete(UUID regionID); | 56 | void Prune(string userID); |
57 | bool Delete(string field, string val); | ||
55 | } | 58 | } |
56 | } | 59 | } |
diff --git a/OpenSim/Data/IUserAccountData.cs b/OpenSim/Data/IUserAccountData.cs index 6bec188..6ee5995 100644 --- a/OpenSim/Data/IUserAccountData.cs +++ b/OpenSim/Data/IUserAccountData.cs | |||
@@ -36,20 +36,18 @@ namespace OpenSim.Data | |||
36 | { | 36 | { |
37 | public UUID PrincipalID; | 37 | public UUID PrincipalID; |
38 | public UUID ScopeID; | 38 | public UUID ScopeID; |
39 | public Dictionary<string, object> Data; | 39 | public string FirstName; |
40 | public string LastName; | ||
41 | public Dictionary<string, string> Data; | ||
40 | } | 42 | } |
41 | 43 | ||
42 | /// <summary> | 44 | /// <summary> |
43 | /// An interface for connecting to the authentication datastore | 45 | /// An interface for connecting to the user accounts datastore |
44 | /// </summary> | 46 | /// </summary> |
45 | public interface IUserAccountData | 47 | public interface IUserAccountData |
46 | { | 48 | { |
47 | UserAccountData Get(UUID principalID, UUID ScopeID); | 49 | UserAccountData[] Get(string[] fields, string[] values); |
48 | |||
49 | List<UserAccountData> Query(UUID principalID, UUID ScopeID, string query); | ||
50 | |||
51 | bool Store(UserAccountData data); | 50 | bool Store(UserAccountData data); |
52 | 51 | UserAccountData[] GetUsers(UUID scopeID, string query); | |
53 | bool SetDataItem(UUID principalID, string item, string value); | ||
54 | } | 52 | } |
55 | } | 53 | } |
diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs index 2d92cb1..01c64dc 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | |||
@@ -65,7 +65,7 @@ namespace OpenSim.Data.MSSQL | |||
65 | public UserAccountData Get(UUID principalID, UUID scopeID) | 65 | public UserAccountData Get(UUID principalID, UUID scopeID) |
66 | { | 66 | { |
67 | UserAccountData ret = new UserAccountData(); | 67 | UserAccountData ret = new UserAccountData(); |
68 | ret.Data = new Dictionary<string, object>(); | 68 | ret.Data = new Dictionary<string, string>(); |
69 | 69 | ||
70 | string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm); | 70 | string sql = string.Format("select * from {0} where UUID = @principalID", m_Realm); |
71 | if (scopeID != UUID.Zero) | 71 | if (scopeID != UUID.Zero) |
@@ -168,6 +168,11 @@ namespace OpenSim.Data.MSSQL | |||
168 | return true; | 168 | return true; |
169 | } | 169 | } |
170 | 170 | ||
171 | public bool Store(UserAccountData data, UUID principalID, string token) | ||
172 | { | ||
173 | return false; | ||
174 | } | ||
175 | |||
171 | public bool SetDataItem(UUID principalID, string item, string value) | 176 | public bool SetDataItem(UUID principalID, string item, string value) |
172 | { | 177 | { |
173 | string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item); | 178 | string sql = string.Format("update {0} set {1} = @{1} where UUID = @UUID", m_Realm, item); |
@@ -184,5 +189,15 @@ namespace OpenSim.Data.MSSQL | |||
184 | } | 189 | } |
185 | return false; | 190 | return false; |
186 | } | 191 | } |
192 | |||
193 | public UserAccountData[] Get(string[] keys, string[] vals) | ||
194 | { | ||
195 | return null; | ||
196 | } | ||
197 | |||
198 | public UserAccountData[] GetUsers(UUID scopeID, string query) | ||
199 | { | ||
200 | return null; | ||
201 | } | ||
187 | } | 202 | } |
188 | } | 203 | } |
diff --git a/OpenSim/Data/Migration.cs b/OpenSim/Data/Migration.cs index e51dc22..4622e23 100644 --- a/OpenSim/Data/Migration.cs +++ b/OpenSim/Data/Migration.cs | |||
@@ -128,7 +128,7 @@ namespace OpenSim.Data | |||
128 | return; | 128 | return; |
129 | 129 | ||
130 | // to prevent people from killing long migrations. | 130 | // to prevent people from killing long migrations. |
131 | m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision.", _type); | 131 | m_log.InfoFormat("[MIGRATIONS] Upgrading {0} to latest revision {1}.", _type, migrations.Keys[migrations.Count - 1]); |
132 | m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!"); | 132 | m_log.Info("[MIGRATIONS] NOTE: this may take a while, don't interupt this process!"); |
133 | 133 | ||
134 | DbCommand cmd = _conn.CreateCommand(); | 134 | DbCommand cmd = _conn.CreateCommand(); |
@@ -138,7 +138,15 @@ namespace OpenSim.Data | |||
138 | cmd.CommandText = kvp.Value; | 138 | cmd.CommandText = kvp.Value; |
139 | // we need to up the command timeout to infinite as we might be doing long migrations. | 139 | // we need to up the command timeout to infinite as we might be doing long migrations. |
140 | cmd.CommandTimeout = 0; | 140 | cmd.CommandTimeout = 0; |
141 | cmd.ExecuteNonQuery(); | 141 | try |
142 | { | ||
143 | cmd.ExecuteNonQuery(); | ||
144 | } | ||
145 | catch (Exception e) | ||
146 | { | ||
147 | m_log.DebugFormat("[MIGRATIONS] Cmd was {0}", cmd.CommandText); | ||
148 | m_log.DebugFormat("[MIGRATIONS]: An error has occurred in the migration {0}.\n This may mean you could see errors trying to run OpenSim. If you see database related errors, you will need to fix the issue manually. Continuing.", e.Message); | ||
149 | } | ||
142 | 150 | ||
143 | if (version == 0) | 151 | if (version == 0) |
144 | { | 152 | { |
@@ -246,7 +254,8 @@ namespace OpenSim.Data | |||
246 | if (m.Success) | 254 | if (m.Success) |
247 | { | 255 | { |
248 | int version = int.Parse(m.Groups[1].ToString()); | 256 | int version = int.Parse(m.Groups[1].ToString()); |
249 | if (version > after) { | 257 | if (version > after) |
258 | { | ||
250 | using (Stream resource = _assem.GetManifestResourceStream(s)) | 259 | using (Stream resource = _assem.GetManifestResourceStream(s)) |
251 | { | 260 | { |
252 | using (StreamReader resourceReader = new StreamReader(resource)) | 261 | using (StreamReader resourceReader = new StreamReader(resource)) |
diff --git a/OpenSim/Data/MySQL/MySQLAvatarData.cs b/OpenSim/Data/MySQL/MySQLAvatarData.cs new file mode 100644 index 0000000..5611302 --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLAvatarData.cs | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using MySql.Data.MySqlClient; | ||
37 | |||
38 | namespace OpenSim.Data.MySQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A MySQL Interface for the Grid Server | ||
42 | /// </summary> | ||
43 | public class MySQLAvatarData : MySQLGenericTableHandler<AvatarBaseData>, | ||
44 | IAvatarData | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | public MySQLAvatarData(string connectionString, string realm) : | ||
49 | base(connectionString, realm, "Avatar") | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public bool Delete(UUID principalID, string name) | ||
54 | { | ||
55 | MySqlCommand cmd = new MySqlCommand(); | ||
56 | |||
57 | cmd.CommandText = String.Format("delete from {0} where `PrincipalID` = ?PrincipalID and `Name` = ?Name", m_Realm); | ||
58 | cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString()); | ||
59 | cmd.Parameters.AddWithValue("?Name", name); | ||
60 | |||
61 | if (ExecuteNonQuery(cmd) > 0) | ||
62 | return true; | ||
63 | |||
64 | return false; | ||
65 | } | ||
66 | } | ||
67 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index fdb98eb..2269d20 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | |||
@@ -95,12 +95,12 @@ namespace OpenSim.Data.MySQL | |||
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | public T[] Get(string field, string key) | 98 | public virtual T[] Get(string field, string key) |
99 | { | 99 | { |
100 | return Get(new string[] { field }, new string[] { key }); | 100 | return Get(new string[] { field }, new string[] { key }); |
101 | } | 101 | } |
102 | 102 | ||
103 | public T[] Get(string[] fields, string[] keys) | 103 | public virtual T[] Get(string[] fields, string[] keys) |
104 | { | 104 | { |
105 | if (fields.Length != keys.Length) | 105 | if (fields.Length != keys.Length) |
106 | return new T[0]; | 106 | return new T[0]; |
@@ -182,12 +182,14 @@ namespace OpenSim.Data.MySQL | |||
182 | result.Add(row); | 182 | result.Add(row); |
183 | } | 183 | } |
184 | 184 | ||
185 | reader.Close(); | ||
186 | |||
185 | CloseReaderCommand(cmd); | 187 | CloseReaderCommand(cmd); |
186 | 188 | ||
187 | return result.ToArray(); | 189 | return result.ToArray(); |
188 | } | 190 | } |
189 | 191 | ||
190 | public T[] Get(string where) | 192 | public virtual T[] Get(string where) |
191 | { | 193 | { |
192 | MySqlCommand cmd = new MySqlCommand(); | 194 | MySqlCommand cmd = new MySqlCommand(); |
193 | 195 | ||
@@ -199,7 +201,7 @@ namespace OpenSim.Data.MySQL | |||
199 | return DoQuery(cmd); | 201 | return DoQuery(cmd); |
200 | } | 202 | } |
201 | 203 | ||
202 | public bool Store(T row) | 204 | public virtual bool Store(T row) |
203 | { | 205 | { |
204 | MySqlCommand cmd = new MySqlCommand(); | 206 | MySqlCommand cmd = new MySqlCommand(); |
205 | 207 | ||
@@ -237,7 +239,7 @@ namespace OpenSim.Data.MySQL | |||
237 | return false; | 239 | return false; |
238 | } | 240 | } |
239 | 241 | ||
240 | public bool Delete(string field, string val) | 242 | public virtual bool Delete(string field, string val) |
241 | { | 243 | { |
242 | MySqlCommand cmd = new MySqlCommand(); | 244 | MySqlCommand cmd = new MySqlCommand(); |
243 | 245 | ||
diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs new file mode 100644 index 0000000..e5dd0e5 --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using MySql.Data.MySqlClient; | ||
37 | |||
38 | namespace OpenSim.Data.MySQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A MySQL Interface for the Grid Server | ||
42 | /// </summary> | ||
43 | public class MySQLPresenceData : MySQLGenericTableHandler<PresenceData>, | ||
44 | IPresenceData | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | public MySQLPresenceData(string connectionString, string realm) : | ||
49 | base(connectionString, realm, "Presence") | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public PresenceData Get(UUID sessionID) | ||
54 | { | ||
55 | PresenceData[] ret = Get("SessionID", | ||
56 | sessionID.ToString()); | ||
57 | |||
58 | if (ret.Length == 0) | ||
59 | return null; | ||
60 | |||
61 | return ret[0]; | ||
62 | } | ||
63 | |||
64 | public void LogoutRegionAgents(UUID regionID) | ||
65 | { | ||
66 | MySqlCommand cmd = new MySqlCommand(); | ||
67 | |||
68 | cmd.CommandText = String.Format("update {0} set Online='false' where `RegionID`=?RegionID", m_Realm); | ||
69 | |||
70 | cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); | ||
71 | |||
72 | ExecuteNonQuery(cmd); | ||
73 | } | ||
74 | |||
75 | public bool ReportAgent(UUID sessionID, UUID regionID, string position, | ||
76 | string lookAt) | ||
77 | { | ||
78 | PresenceData[] pd = Get("SessionID", sessionID.ToString()); | ||
79 | if (pd.Length == 0) | ||
80 | return false; | ||
81 | |||
82 | MySqlCommand cmd = new MySqlCommand(); | ||
83 | |||
84 | cmd.CommandText = String.Format("update {0} set RegionID=?RegionID, Position=?Position, LookAt=?LookAt, Online='true' where `SessionID`=?SessionID", m_Realm); | ||
85 | |||
86 | cmd.Parameters.AddWithValue("?SessionID", sessionID.ToString()); | ||
87 | cmd.Parameters.AddWithValue("?RegionID", regionID.ToString()); | ||
88 | cmd.Parameters.AddWithValue("?Position", position.ToString()); | ||
89 | cmd.Parameters.AddWithValue("?LookAt", lookAt.ToString()); | ||
90 | |||
91 | if (ExecuteNonQuery(cmd) == 0) | ||
92 | return false; | ||
93 | |||
94 | return true; | ||
95 | } | ||
96 | |||
97 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
98 | { | ||
99 | PresenceData[] pd = Get("UserID", userID); | ||
100 | if (pd.Length == 0) | ||
101 | return false; | ||
102 | |||
103 | MySqlCommand cmd = new MySqlCommand(); | ||
104 | |||
105 | cmd.CommandText = String.Format("update {0} set HomeRegionID=?HomeRegionID, HomePosition=?HomePosition, HomeLookAt=?HomeLookAt where UserID=?UserID", m_Realm); | ||
106 | |||
107 | cmd.Parameters.AddWithValue("?UserID", userID); | ||
108 | cmd.Parameters.AddWithValue("?HomeRegionID", regionID.ToString()); | ||
109 | cmd.Parameters.AddWithValue("?HomePosition", position); | ||
110 | cmd.Parameters.AddWithValue("?HomeLookAt", lookAt); | ||
111 | |||
112 | if (ExecuteNonQuery(cmd) == 0) | ||
113 | return false; | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | public void Prune(string userID) | ||
119 | { | ||
120 | MySqlCommand cmd = new MySqlCommand(); | ||
121 | |||
122 | cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); | ||
123 | |||
124 | cmd.Parameters.AddWithValue("?UserID", userID); | ||
125 | |||
126 | IDataReader reader = ExecuteReader(cmd); | ||
127 | |||
128 | List<UUID> deleteSessions = new List<UUID>(); | ||
129 | int online = 0; | ||
130 | |||
131 | while(reader.Read()) | ||
132 | { | ||
133 | if (bool.Parse(reader["Online"].ToString())) | ||
134 | online++; | ||
135 | else | ||
136 | deleteSessions.Add(new UUID(reader["SessionID"].ToString())); | ||
137 | } | ||
138 | |||
139 | if (online == 0 && deleteSessions.Count > 0) | ||
140 | deleteSessions.RemoveAt(0); | ||
141 | |||
142 | reader.Close(); | ||
143 | CloseReaderCommand(cmd); | ||
144 | |||
145 | foreach (UUID s in deleteSessions) | ||
146 | Delete("SessionID", s.ToString()); | ||
147 | } | ||
148 | } | ||
149 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index d48144d..aa69d68 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs | |||
@@ -35,146 +35,50 @@ using MySql.Data.MySqlClient; | |||
35 | 35 | ||
36 | namespace OpenSim.Data.MySQL | 36 | namespace OpenSim.Data.MySQL |
37 | { | 37 | { |
38 | public class MySqlUserAccountData : MySqlFramework, IUserAccountData | 38 | public class MySqlUserAccountData : MySQLGenericTableHandler<UserAccountData>, IUserAccountData |
39 | { | 39 | { |
40 | private string m_Realm; | ||
41 | private List<string> m_ColumnNames = null; | ||
42 | // private int m_LastExpire = 0; | ||
43 | |||
44 | public MySqlUserAccountData(string connectionString, string realm) | 40 | public MySqlUserAccountData(string connectionString, string realm) |
45 | : base(connectionString) | 41 | : base(connectionString, realm, "UserAccount") |
46 | { | ||
47 | m_Realm = realm; | ||
48 | |||
49 | Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore"); | ||
50 | m.Update(); | ||
51 | } | ||
52 | |||
53 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) | ||
54 | { | 42 | { |
55 | return null; | ||
56 | } | 43 | } |
57 | 44 | ||
58 | public UserAccountData Get(UUID principalID, UUID scopeID) | 45 | public UserAccountData[] GetUsers(UUID scopeID, string query) |
59 | { | 46 | { |
60 | UserAccountData ret = new UserAccountData(); | 47 | string[] words = query.Split(new char[] {' '}); |
61 | ret.Data = new Dictionary<string, object>(); | ||
62 | 48 | ||
63 | string command = "select * from `"+m_Realm+"` where UUID = ?principalID"; | 49 | for (int i = 0 ; i < words.Length ; i++) |
64 | if (scopeID != UUID.Zero) | ||
65 | command += " and ScopeID = ?scopeID"; | ||
66 | |||
67 | MySqlCommand cmd = new MySqlCommand(command); | ||
68 | |||
69 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); | ||
70 | cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); | ||
71 | |||
72 | IDataReader result = ExecuteReader(cmd); | ||
73 | |||
74 | if (result.Read()) | ||
75 | { | 50 | { |
76 | ret.PrincipalID = principalID; | 51 | if (words[i].Length < 3) |
77 | UUID scope; | ||
78 | UUID.TryParse(result["ScopeID"].ToString(), out scope); | ||
79 | ret.ScopeID = scope; | ||
80 | |||
81 | if (m_ColumnNames == null) | ||
82 | { | 52 | { |
83 | m_ColumnNames = new List<string>(); | 53 | if (i != words.Length - 1) |
84 | 54 | Array.Copy(words, i + 1, words, i, words.Length - i - 1); | |
85 | DataTable schemaTable = result.GetSchemaTable(); | 55 | Array.Resize(ref words, words.Length - 1); |
86 | foreach (DataRow row in schemaTable.Rows) | ||
87 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
88 | } | ||
89 | |||
90 | foreach (string s in m_ColumnNames) | ||
91 | { | ||
92 | if (s == "UUID") | ||
93 | continue; | ||
94 | if (s == "ScopeID") | ||
95 | continue; | ||
96 | |||
97 | ret.Data[s] = result[s].ToString(); | ||
98 | } | 56 | } |
99 | |||
100 | result.Close(); | ||
101 | CloseReaderCommand(cmd); | ||
102 | |||
103 | return ret; | ||
104 | } | 57 | } |
105 | 58 | ||
106 | result.Close(); | 59 | if (words.Length == 0) |
107 | CloseReaderCommand(cmd); | 60 | return new UserAccountData[0]; |
108 | 61 | ||
109 | return null; | 62 | if (words.Length > 2) |
110 | } | 63 | return new UserAccountData[0]; |
111 | |||
112 | public bool Store(UserAccountData data) | ||
113 | { | ||
114 | if (data.Data.ContainsKey("UUID")) | ||
115 | data.Data.Remove("UUID"); | ||
116 | if (data.Data.ContainsKey("ScopeID")) | ||
117 | data.Data.Remove("ScopeID"); | ||
118 | |||
119 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | ||
120 | 64 | ||
121 | MySqlCommand cmd = new MySqlCommand(); | 65 | MySqlCommand cmd = new MySqlCommand(); |
122 | 66 | ||
123 | string update = "update `"+m_Realm+"` set "; | 67 | if (words.Length == 1) |
124 | bool first = true; | ||
125 | foreach (string field in fields) | ||
126 | { | 68 | { |
127 | if (!first) | 69 | cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?search or LastName like ?search)", m_Realm); |
128 | update += ", "; | 70 | cmd.Parameters.AddWithValue("?search", "%" + words[0] + "%"); |
129 | update += "`" + field + "` = ?"+field; | 71 | cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); |
130 | |||
131 | first = false; | ||
132 | |||
133 | cmd.Parameters.AddWithValue("?"+field, data.Data[field]); | ||
134 | } | 72 | } |
135 | 73 | else | |
136 | update += " where UUID = ?principalID"; | ||
137 | |||
138 | if (data.ScopeID != UUID.Zero) | ||
139 | update += " and ScopeID = ?scopeID"; | ||
140 | |||
141 | cmd.CommandText = update; | ||
142 | cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); | ||
143 | cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); | ||
144 | |||
145 | if (ExecuteNonQuery(cmd) < 1) | ||
146 | { | 74 | { |
147 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + | 75 | cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst or LastName like ?searchLast)", m_Realm); |
148 | String.Join("`, `", fields) + | 76 | cmd.Parameters.AddWithValue("?searchFirst", "%" + words[0] + "%"); |
149 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | 77 | cmd.Parameters.AddWithValue("?searchLast", "%" + words[1] + "%"); |
150 | 78 | cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); | |
151 | cmd.CommandText = insert; | ||
152 | |||
153 | if (ExecuteNonQuery(cmd) < 1) | ||
154 | { | ||
155 | cmd.Dispose(); | ||
156 | return false; | ||
157 | } | ||
158 | } | 79 | } |
159 | 80 | ||
160 | cmd.Dispose(); | 81 | return DoQuery(cmd); |
161 | |||
162 | return true; | ||
163 | } | ||
164 | |||
165 | public bool SetDataItem(UUID principalID, string item, string value) | ||
166 | { | ||
167 | MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + | ||
168 | "` set `" + item + "` = ?" + item + " where UUID = ?UUID"); | ||
169 | |||
170 | |||
171 | cmd.Parameters.AddWithValue("?"+item, value); | ||
172 | cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); | ||
173 | |||
174 | if (ExecuteNonQuery(cmd) > 0) | ||
175 | return true; | ||
176 | |||
177 | return false; | ||
178 | } | 82 | } |
179 | } | 83 | } |
180 | } | 84 | } |
diff --git a/OpenSim/Data/MySQL/Resources/001_Avatar.sql b/OpenSim/Data/MySQL/Resources/001_Avatar.sql new file mode 100644 index 0000000..27a3072 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_Avatar.sql | |||
@@ -0,0 +1,5 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE TABLE Avatars (PrincipalID CHAR(36) NOT NULL, Name VARCHAR(32) NOT NULL, Value VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY(PrincipalID, Name), KEY(PrincipalID)); | ||
4 | |||
5 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/001_Friends.sql b/OpenSim/Data/MySQL/Resources/001_Friends.sql new file mode 100644 index 0000000..e158a2c --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_Friends.sql | |||
@@ -0,0 +1,9 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE TABLE `Friends` ( | ||
4 | `PrincipalID` CHAR(36) NOT NULL, | ||
5 | `FriendID` VARCHAR(255) NOT NULL, | ||
6 | `Flags` CHAR(16) NOT NULL DEFAULT '0' | ||
7 | ) ENGINE=InnoDB; | ||
8 | |||
9 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/001_Presence.sql b/OpenSim/Data/MySQL/Resources/001_Presence.sql new file mode 100644 index 0000000..b8abaf7 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_Presence.sql | |||
@@ -0,0 +1,15 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE TABLE `Presence` ( | ||
4 | `UserID` VARCHAR(255) NOT NULL, | ||
5 | `RegionID` CHAR(36) NOT NULL, | ||
6 | `SessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
7 | `SecureSessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
8 | `Online` CHAR(5) NOT NULL DEFAULT 'false', | ||
9 | `Login` CHAR(16) NOT NULL DEFAULT '0', | ||
10 | `Logout` CHAR(16) NOT NULL DEFAULT '0', | ||
11 | `Position` CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
12 | `LookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>' | ||
13 | ) ENGINE=InnoDB; | ||
14 | |||
15 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/001_UserAccount.sql b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql new file mode 100644 index 0000000..07da571 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql | |||
@@ -0,0 +1,13 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE TABLE `UserAccounts` ( | ||
4 | `PrincipalID` CHAR(36) NOT NULL, | ||
5 | `ScopeID` CHAR(36) NOT NULL, | ||
6 | `FirstName` VARCHAR(64) NOT NULL, | ||
7 | `LastName` VARCHAR(64) NOT NULL, | ||
8 | `Email` VARCHAR(64), | ||
9 | `ServiceURLs` TEXT, | ||
10 | `Created` INT(11) | ||
11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
12 | |||
13 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/002_AuthStore.sql b/OpenSim/Data/MySQL/Resources/002_AuthStore.sql new file mode 100644 index 0000000..dc7dfe0 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/002_AuthStore.sql | |||
@@ -0,0 +1,5 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | INSERT INTO auth (UUID, passwordHash, passwordSalt, webLoginKey) SELECT `UUID` AS UUID, `passwordHash` AS passwordHash, `passwordSalt` AS passwordSalt, `webLoginKey` AS webLoginKey FROM users; | ||
4 | |||
5 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/002_Friends.sql b/OpenSim/Data/MySQL/Resources/002_Friends.sql new file mode 100644 index 0000000..5ff6438 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/002_Friends.sql | |||
@@ -0,0 +1,5 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | INSERT INTO Friends (PrincipalID, FriendID, Flags) SELECT ownerID, friendID, friendPerms FROM userfriends; | ||
4 | |||
5 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/002_Presence.sql b/OpenSim/Data/MySQL/Resources/002_Presence.sql new file mode 100644 index 0000000..e65f105 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/002_Presence.sql | |||
@@ -0,0 +1,7 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | ALTER TABLE Presence ADD COLUMN `HomeRegionID` CHAR(36) NOT NULL; | ||
4 | ALTER TABLE Presence ADD COLUMN `HomePosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>'; | ||
5 | ALTER TABLE Presence ADD COLUMN `HomeLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>'; | ||
6 | |||
7 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/002_UserAccount.sql b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql new file mode 100644 index 0000000..ad2ddda --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql | |||
@@ -0,0 +1,5 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created) SELECT `UUID` AS PrincipalID, '00000000-0000-0000-0000-000000000000' AS ScopeID, username AS FirstName, lastname AS LastName, email as Email, CONCAT('AssetServerURI=', userAssetURI, ' InventoryServerURI=', userInventoryURI, ' GatewayURI= HomeURI=') AS ServiceURLs, created as Created FROM users; | ||
4 | |||
5 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/003_Presence.sql b/OpenSim/Data/MySQL/Resources/003_Presence.sql new file mode 100644 index 0000000..0efefa8 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/003_Presence.sql | |||
@@ -0,0 +1,6 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE UNIQUE INDEX SessionID ON Presence(SessionID); | ||
4 | CREATE INDEX UserID ON Presence(UserID); | ||
5 | |||
6 | COMMIT; | ||
diff --git a/OpenSim/Data/MySQL/Resources/003_UserAccount.sql b/OpenSim/Data/MySQL/Resources/003_UserAccount.sql new file mode 100644 index 0000000..e42d93b --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/003_UserAccount.sql | |||
@@ -0,0 +1,9 @@ | |||
1 | BEGIN; | ||
2 | |||
3 | CREATE UNIQUE INDEX PrincipalID ON UserAccounts(PrincipalID); | ||
4 | CREATE INDEX Email ON UserAccounts(Email); | ||
5 | CREATE INDEX FirstName ON UserAccounts(FirstName); | ||
6 | CREATE INDEX LastName ON UserAccounts(LastName); | ||
7 | CREATE INDEX Name ON UserAccounts(FirstName,LastName); | ||
8 | |||
9 | COMMIT; | ||
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs new file mode 100644 index 0000000..52fdc6f --- /dev/null +++ b/OpenSim/Data/Null/NullPresenceData.cs | |||
@@ -0,0 +1,223 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Data; | ||
34 | |||
35 | namespace OpenSim.Data.Null | ||
36 | { | ||
37 | public class NullPresenceData : IPresenceData | ||
38 | { | ||
39 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); | ||
40 | |||
41 | public NullPresenceData(string connectionString, string realm) | ||
42 | { | ||
43 | //Console.WriteLine("[XXX] NullRegionData constructor"); | ||
44 | // Let's stick in a test presence | ||
45 | PresenceData p = new PresenceData(); | ||
46 | p.SessionID = UUID.Zero; | ||
47 | p.UserID = UUID.Zero.ToString(); | ||
48 | p.Data = new Dictionary<string, string>(); | ||
49 | p.Data["Online"] = "true"; | ||
50 | m_presenceData.Add(UUID.Zero, p); | ||
51 | } | ||
52 | |||
53 | public bool Store(PresenceData data) | ||
54 | { | ||
55 | m_presenceData[data.SessionID] = data; | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | public PresenceData Get(UUID sessionID) | ||
60 | { | ||
61 | if (m_presenceData.ContainsKey(sessionID)) | ||
62 | return m_presenceData[sessionID]; | ||
63 | |||
64 | return null; | ||
65 | } | ||
66 | |||
67 | public void LogoutRegionAgents(UUID regionID) | ||
68 | { | ||
69 | List<UUID> toBeDeleted = new List<UUID>(); | ||
70 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | ||
71 | if (kvp.Value.RegionID == regionID) | ||
72 | toBeDeleted.Add(kvp.Key); | ||
73 | |||
74 | foreach (UUID u in toBeDeleted) | ||
75 | m_presenceData.Remove(u); | ||
76 | } | ||
77 | |||
78 | public bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt) | ||
79 | { | ||
80 | if (m_presenceData.ContainsKey(sessionID)) | ||
81 | { | ||
82 | m_presenceData[sessionID].RegionID = regionID; | ||
83 | m_presenceData[sessionID].Data["Position"] = position; | ||
84 | m_presenceData[sessionID].Data["LookAt"] = lookAt; | ||
85 | return true; | ||
86 | } | ||
87 | |||
88 | return false; | ||
89 | } | ||
90 | |||
91 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
92 | { | ||
93 | bool foundone = false; | ||
94 | foreach (PresenceData p in m_presenceData.Values) | ||
95 | { | ||
96 | if (p.UserID == userID) | ||
97 | { | ||
98 | p.Data["HomeRegionID"] = regionID.ToString(); | ||
99 | p.Data["HomePosition"] = position.ToString(); | ||
100 | p.Data["HomeLookAt"] = lookAt.ToString(); | ||
101 | foundone = true; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | return foundone; | ||
106 | } | ||
107 | |||
108 | public PresenceData[] Get(string field, string data) | ||
109 | { | ||
110 | List<PresenceData> presences = new List<PresenceData>(); | ||
111 | if (field == "UserID") | ||
112 | { | ||
113 | foreach (PresenceData p in m_presenceData.Values) | ||
114 | if (p.UserID == data) | ||
115 | presences.Add(p); | ||
116 | return presences.ToArray(); | ||
117 | } | ||
118 | else if (field == "SessionID") | ||
119 | { | ||
120 | UUID session = UUID.Zero; | ||
121 | if (!UUID.TryParse(data, out session)) | ||
122 | return presences.ToArray(); | ||
123 | |||
124 | if (m_presenceData.ContainsKey(session)) | ||
125 | { | ||
126 | presences.Add(m_presenceData[session]); | ||
127 | return presences.ToArray(); | ||
128 | } | ||
129 | } | ||
130 | else if (field == "RegionID") | ||
131 | { | ||
132 | UUID region = UUID.Zero; | ||
133 | if (!UUID.TryParse(data, out region)) | ||
134 | return presences.ToArray(); | ||
135 | foreach (PresenceData p in m_presenceData.Values) | ||
136 | if (p.RegionID == region) | ||
137 | presences.Add(p); | ||
138 | return presences.ToArray(); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | foreach (PresenceData p in m_presenceData.Values) | ||
143 | { | ||
144 | if (p.Data.ContainsKey(field) && p.Data[field] == data) | ||
145 | presences.Add(p); | ||
146 | } | ||
147 | return presences.ToArray(); | ||
148 | } | ||
149 | |||
150 | return presences.ToArray(); | ||
151 | } | ||
152 | |||
153 | public void Prune(string userID) | ||
154 | { | ||
155 | List<UUID> deleteSessions = new List<UUID>(); | ||
156 | int online = 0; | ||
157 | |||
158 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | ||
159 | { | ||
160 | bool on = false; | ||
161 | if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) | ||
162 | online++; | ||
163 | else | ||
164 | deleteSessions.Add(kvp.Key); | ||
165 | } | ||
166 | if (online == 0 && deleteSessions.Count > 0) | ||
167 | deleteSessions.RemoveAt(0); | ||
168 | |||
169 | foreach (UUID s in deleteSessions) | ||
170 | m_presenceData.Remove(s); | ||
171 | |||
172 | } | ||
173 | |||
174 | public bool Delete(string field, string data) | ||
175 | { | ||
176 | List<UUID> presences = new List<UUID>(); | ||
177 | if (field == "UserID") | ||
178 | { | ||
179 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
180 | if (p.Value.UserID == data) | ||
181 | presences.Add(p.Key); | ||
182 | } | ||
183 | else if (field == "SessionID") | ||
184 | { | ||
185 | UUID session = UUID.Zero; | ||
186 | if (UUID.TryParse(data, out session)) | ||
187 | { | ||
188 | if (m_presenceData.ContainsKey(session)) | ||
189 | { | ||
190 | presences.Add(session); | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | else if (field == "RegionID") | ||
195 | { | ||
196 | UUID region = UUID.Zero; | ||
197 | if (UUID.TryParse(data, out region)) | ||
198 | { | ||
199 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
200 | if (p.Value.RegionID == region) | ||
201 | presences.Add(p.Key); | ||
202 | } | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
207 | { | ||
208 | if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data) | ||
209 | presences.Add(p.Key); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | foreach (UUID u in presences) | ||
214 | m_presenceData.Remove(u); | ||
215 | |||
216 | if (presences.Count == 0) | ||
217 | return false; | ||
218 | |||
219 | return true; | ||
220 | } | ||
221 | |||
222 | } | ||
223 | } | ||