aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Null/NullPresenceData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Null/NullPresenceData.cs')
-rw-r--r--OpenSim/Data/Null/NullPresenceData.cs56
1 files changed, 40 insertions, 16 deletions
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 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
31using OpenMetaverse; 33using OpenMetaverse;
32using OpenSim.Framework; 34using OpenSim.Framework;
33using OpenSim.Data; 35using 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")