diff options
author | Melanie | 2010-03-06 12:37:24 +0000 |
---|---|---|
committer | Melanie | 2010-03-06 12:37:24 +0000 |
commit | 8180c72cbc9cafff247d614ac14db29499fc32a9 (patch) | |
tree | fd92204394e657b805e094a237ffecaf50066df6 /OpenSim/Data | |
parent | Merge branch 'master' into careminster-presence-refactor (diff) | |
parent | Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff) | |
download | opensim-SC_OLD-8180c72cbc9cafff247d614ac14db29499fc32a9.zip opensim-SC_OLD-8180c72cbc9cafff247d614ac14db29499fc32a9.tar.gz opensim-SC_OLD-8180c72cbc9cafff247d614ac14db29499fc32a9.tar.bz2 opensim-SC_OLD-8180c72cbc9cafff247d614ac14db29499fc32a9.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Data')
-rw-r--r-- | OpenSim/Data/IGridUserData.cs | 50 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 3 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLGridUserData.cs | 64 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLPresenceData.cs | 4 | ||||
-rw-r--r-- | OpenSim/Data/Null/NullPresenceData.cs | 56 |
5 files changed, 157 insertions, 20 deletions
diff --git a/OpenSim/Data/IGridUserData.cs b/OpenSim/Data/IGridUserData.cs new file mode 100644 index 0000000..abd2cef --- /dev/null +++ b/OpenSim/Data/IGridUserData.cs | |||
@@ -0,0 +1,50 @@ | |||
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 GridUserData | ||
37 | { | ||
38 | public string UserID; | ||
39 | public Dictionary<string, string> Data; | ||
40 | } | ||
41 | |||
42 | /// <summary> | ||
43 | /// An interface for connecting to the user grid datastore | ||
44 | /// </summary> | ||
45 | public interface IGridUserData | ||
46 | { | ||
47 | GridUserData GetGridUserData(string userID); | ||
48 | bool StoreGridUserData(GridUserData data); | ||
49 | } | ||
50 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index b170dde..756b42d 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | |||
@@ -197,8 +197,7 @@ namespace OpenSim.Data.MySQL | |||
197 | public virtual T[] Get(string where) | 197 | public virtual T[] Get(string where) |
198 | { | 198 | { |
199 | using (MySqlCommand cmd = new MySqlCommand()) | 199 | using (MySqlCommand cmd = new MySqlCommand()) |
200 | { | 200 | { |
201 | |||
202 | string query = String.Format("select * from {0} where {1}", | 201 | string query = String.Format("select * from {0} where {1}", |
203 | m_Realm, where); | 202 | m_Realm, where); |
204 | 203 | ||
diff --git a/OpenSim/Data/MySQL/MySQLGridUserData.cs b/OpenSim/Data/MySQL/MySQLGridUserData.cs new file mode 100644 index 0000000..15834d2 --- /dev/null +++ b/OpenSim/Data/MySQL/MySQLGridUserData.cs | |||
@@ -0,0 +1,64 @@ | |||
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 user grid data | ||
42 | /// </summary> | ||
43 | public class MySQLGridUserData : MySQLGenericTableHandler<GridUserData>, IGridUserData | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public MySQLGridUserData(string connectionString, string realm) : base(connectionString, realm, "UserGrid") {} | ||
48 | |||
49 | public GridUserData GetGridUserData(string userID) | ||
50 | { | ||
51 | GridUserData[] ret = Get("UserID", userID); | ||
52 | |||
53 | if (ret.Length == 0) | ||
54 | return null; | ||
55 | |||
56 | return ret[0]; | ||
57 | } | ||
58 | |||
59 | public bool StoreGridUserData(GridUserData data) | ||
60 | { | ||
61 | return Store(data); | ||
62 | } | ||
63 | } | ||
64 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs index fcbe3d6..68a68af 100644 --- a/OpenSim/Data/MySQL/MySQLPresenceData.cs +++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs | |||
@@ -122,7 +122,7 @@ namespace OpenSim.Data.MySQL | |||
122 | cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); | 122 | cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); |
123 | 123 | ||
124 | cmd.Parameters.AddWithValue("?UserID", userID); | 124 | cmd.Parameters.AddWithValue("?UserID", userID); |
125 | ; | 125 | |
126 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 126 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
127 | { | 127 | { |
128 | dbcon.Open(); | 128 | dbcon.Open(); |
@@ -131,7 +131,6 @@ namespace OpenSim.Data.MySQL | |||
131 | 131 | ||
132 | using (IDataReader reader = cmd.ExecuteReader()) | 132 | using (IDataReader reader = cmd.ExecuteReader()) |
133 | { | 133 | { |
134 | |||
135 | List<UUID> deleteSessions = new List<UUID>(); | 134 | List<UUID> deleteSessions = new List<UUID>(); |
136 | int online = 0; | 135 | int online = 0; |
137 | 136 | ||
@@ -143,6 +142,7 @@ namespace OpenSim.Data.MySQL | |||
143 | deleteSessions.Add(new UUID(reader["SessionID"].ToString())); | 142 | deleteSessions.Add(new UUID(reader["SessionID"].ToString())); |
144 | } | 143 | } |
145 | 144 | ||
145 | // Leave one session behind so that we can pick up details such as home location | ||
146 | if (online == 0 && deleteSessions.Count > 0) | 146 | if (online == 0 && deleteSessions.Count > 0) |
147 | deleteSessions.RemoveAt(0); | 147 | deleteSessions.RemoveAt(0); |
148 | 148 | ||
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs index 5f78691..9fc4595 100644 --- a/OpenSim/Data/Null/NullPresenceData.cs +++ b/OpenSim/Data/Null/NullPresenceData.cs | |||
@@ -28,6 +28,8 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | ||
32 | using log4net; | ||
31 | using OpenMetaverse; | 33 | using OpenMetaverse; |
32 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
33 | using OpenSim.Data; | 35 | using OpenSim.Data; |
@@ -36,6 +38,8 @@ namespace OpenSim.Data.Null | |||
36 | { | 38 | { |
37 | public class NullPresenceData : IPresenceData | 39 | public class NullPresenceData : IPresenceData |
38 | { | 40 | { |
41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
39 | private static NullPresenceData Instance; | 43 | private static NullPresenceData Instance; |
40 | 44 | ||
41 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); | 45 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); |
@@ -47,21 +51,17 @@ namespace OpenSim.Data.Null | |||
47 | Instance = this; | 51 | Instance = this; |
48 | 52 | ||
49 | //Console.WriteLine("[XXX] NullRegionData constructor"); | 53 | //Console.WriteLine("[XXX] NullRegionData constructor"); |
50 | // Let's stick in a test presence | ||
51 | PresenceData p = new PresenceData(); | ||
52 | p.SessionID = UUID.Zero; | ||
53 | p.UserID = UUID.Zero.ToString(); | ||
54 | p.Data = new Dictionary<string, string>(); | ||
55 | p.Data["Online"] = true.ToString(); | ||
56 | m_presenceData.Add(UUID.Zero, p); | ||
57 | } | 54 | } |
58 | } | 55 | } |
59 | 56 | ||
60 | public bool Store(PresenceData data) | 57 | public bool Store(PresenceData data) |
61 | { | 58 | { |
62 | if (Instance != this) | 59 | if (Instance != this) |
63 | return Instance.Store(data); | 60 | return Instance.Store(data); |
64 | 61 | ||
62 | // m_log.DebugFormat("[NULL PRESENCE DATA]: Storing presence {0}", data.UserID); | ||
63 | // Console.WriteLine("HOME for " + data.UserID + " is " + (data.Data.ContainsKey("HomeRegionID") ? data.Data["HomeRegionID"] : "Not found")); | ||
64 | |||
65 | m_presenceData[data.SessionID] = data; | 65 | m_presenceData[data.SessionID] = data; |
66 | return true; | 66 | return true; |
67 | } | 67 | } |
@@ -100,6 +100,7 @@ namespace OpenSim.Data.Null | |||
100 | { | 100 | { |
101 | if (Instance != this) | 101 | if (Instance != this) |
102 | return Instance.ReportAgent(sessionID, regionID, position, lookAt); | 102 | return Instance.ReportAgent(sessionID, regionID, position, lookAt); |
103 | |||
103 | if (m_presenceData.ContainsKey(sessionID)) | 104 | if (m_presenceData.ContainsKey(sessionID)) |
104 | { | 105 | { |
105 | m_presenceData[sessionID].RegionID = regionID; | 106 | m_presenceData[sessionID].RegionID = regionID; |
@@ -112,7 +113,7 @@ namespace OpenSim.Data.Null | |||
112 | } | 113 | } |
113 | 114 | ||
114 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | 115 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) |
115 | { | 116 | { |
116 | if (Instance != this) | 117 | if (Instance != this) |
117 | return Instance.SetHomeLocation(userID, regionID, position, lookAt); | 118 | return Instance.SetHomeLocation(userID, regionID, position, lookAt); |
118 | 119 | ||
@@ -121,27 +122,40 @@ namespace OpenSim.Data.Null | |||
121 | { | 122 | { |
122 | if (p.UserID == userID) | 123 | if (p.UserID == userID) |
123 | { | 124 | { |
125 | // m_log.DebugFormat( | ||
126 | // "[NULL PRESENCE DATA]: Setting home location {0} {1} {2} for {3}", | ||
127 | // regionID, position, lookAt, p.UserID); | ||
128 | |||
124 | p.Data["HomeRegionID"] = regionID.ToString(); | 129 | p.Data["HomeRegionID"] = regionID.ToString(); |
125 | p.Data["HomePosition"] = position.ToString(); | 130 | p.Data["HomePosition"] = position.ToString(); |
126 | p.Data["HomeLookAt"] = lookAt.ToString(); | 131 | p.Data["HomeLookAt"] = lookAt.ToString(); |
127 | foundone = true; | 132 | foundone = true; |
128 | } | 133 | } |
129 | } | 134 | } |
130 | 135 | ||
131 | return foundone; | 136 | return foundone; |
132 | } | 137 | } |
133 | 138 | ||
134 | public PresenceData[] Get(string field, string data) | 139 | public PresenceData[] Get(string field, string data) |
135 | { | 140 | { |
136 | if (Instance != this) | 141 | if (Instance != this) |
137 | return Instance.Get(field, data); | 142 | return Instance.Get(field, data); |
138 | 143 | ||
144 | // m_log.DebugFormat( | ||
145 | // "[NULL PRESENCE DATA]: Getting presence data for field {0} with parameter {1}", field, data); | ||
146 | |||
139 | List<PresenceData> presences = new List<PresenceData>(); | 147 | List<PresenceData> presences = new List<PresenceData>(); |
140 | if (field == "UserID") | 148 | if (field == "UserID") |
141 | { | 149 | { |
142 | foreach (PresenceData p in m_presenceData.Values) | 150 | foreach (PresenceData p in m_presenceData.Values) |
143 | if (p.UserID == data) | 151 | { |
144 | presences.Add(p); | 152 | if (p.UserID == data) |
153 | { | ||
154 | presences.Add(p); | ||
155 | // Console.WriteLine("HOME for " + p.UserID + " is " + (p.Data.ContainsKey("HomeRegionID") ? p.Data["HomeRegionID"] : "Not found")); | ||
156 | } | ||
157 | } | ||
158 | |||
145 | return presences.ToArray(); | 159 | return presences.ToArray(); |
146 | } | 160 | } |
147 | else if (field == "SessionID") | 161 | else if (field == "SessionID") |
@@ -180,36 +194,46 @@ namespace OpenSim.Data.Null | |||
180 | } | 194 | } |
181 | 195 | ||
182 | public void Prune(string userID) | 196 | public void Prune(string userID) |
183 | { | 197 | { |
184 | if (Instance != this) | 198 | if (Instance != this) |
185 | { | 199 | { |
186 | Instance.Prune(userID); | 200 | Instance.Prune(userID); |
187 | return; | 201 | return; |
188 | } | 202 | } |
189 | 203 | ||
204 | // m_log.DebugFormat("[NULL PRESENCE DATA]: Prune called for {0}", userID); | ||
205 | |||
190 | List<UUID> deleteSessions = new List<UUID>(); | 206 | List<UUID> deleteSessions = new List<UUID>(); |
191 | int online = 0; | 207 | int online = 0; |
192 | 208 | ||
193 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | 209 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) |
194 | { | 210 | { |
211 | // m_log.DebugFormat("Online: {0}", kvp.Value.Data["Online"]); | ||
212 | |||
195 | bool on = false; | 213 | bool on = false; |
196 | if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) | 214 | if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) |
197 | online++; | 215 | online++; |
198 | else | 216 | else |
199 | deleteSessions.Add(kvp.Key); | 217 | deleteSessions.Add(kvp.Key); |
200 | } | 218 | } |
219 | |||
220 | // m_log.DebugFormat("[NULL PRESENCE DATA]: online [{0}], deleteSession.Count [{1}]", online, deleteSessions.Count); | ||
221 | |||
222 | // Leave one session behind so that we can pick up details such as home location | ||
201 | if (online == 0 && deleteSessions.Count > 0) | 223 | if (online == 0 && deleteSessions.Count > 0) |
202 | deleteSessions.RemoveAt(0); | 224 | deleteSessions.RemoveAt(0); |
203 | 225 | ||
204 | foreach (UUID s in deleteSessions) | 226 | foreach (UUID s in deleteSessions) |
205 | m_presenceData.Remove(s); | 227 | m_presenceData.Remove(s); |
206 | |||
207 | } | 228 | } |
208 | 229 | ||
209 | public bool Delete(string field, string data) | 230 | public bool Delete(string field, string data) |
210 | { | 231 | { |
232 | // m_log.DebugFormat( | ||
233 | // "[NULL PRESENCE DATA]: Deleting presence data for field {0} with parameter {1}", field, data); | ||
234 | |||
211 | if (Instance != this) | 235 | if (Instance != this) |
212 | return Delete(field, data); | 236 | return Instance.Delete(field, data); |
213 | 237 | ||
214 | List<UUID> presences = new List<UUID>(); | 238 | List<UUID> presences = new List<UUID>(); |
215 | if (field == "UserID") | 239 | if (field == "UserID") |