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.cs285
1 files changed, 285 insertions, 0 deletions
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs
new file mode 100644
index 0000000..b98b5c9
--- /dev/null
+++ b/OpenSim/Data/Null/NullPresenceData.cs
@@ -0,0 +1,285 @@
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.Reflection;
32using log4net;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Data;
36
37namespace OpenSim.Data.Null
38{
39 public class NullPresenceData : IPresenceData
40 {
41// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 private static NullPresenceData Instance;
44
45 Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>();
46
47 public NullPresenceData(string connectionString, string realm)
48 {
49 if (Instance == null)
50 {
51 Instance = this;
52
53 //Console.WriteLine("[XXX] NullRegionData constructor");
54 }
55 }
56
57 public bool Store(PresenceData data)
58 {
59 if (Instance != this)
60 return Instance.Store(data);
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;
66 return true;
67 }
68
69 public PresenceData Get(UUID sessionID)
70 {
71 if (Instance != this)
72 return Instance.Get(sessionID);
73
74 if (m_presenceData.ContainsKey(sessionID))
75 {
76 return m_presenceData[sessionID];
77 }
78
79 return null;
80 }
81
82 public void LogoutRegionAgents(UUID regionID)
83 {
84 if (Instance != this)
85 {
86 Instance.LogoutRegionAgents(regionID);
87 return;
88 }
89
90 List<UUID> toBeDeleted = new List<UUID>();
91 foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData)
92 if (kvp.Value.RegionID == regionID)
93 toBeDeleted.Add(kvp.Key);
94
95 foreach (UUID u in toBeDeleted)
96 m_presenceData.Remove(u);
97 }
98
99 public bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt)
100 {
101 if (Instance != this)
102 return Instance.ReportAgent(sessionID, regionID, position, lookAt);
103
104 if (m_presenceData.ContainsKey(sessionID))
105 {
106 m_presenceData[sessionID].RegionID = regionID;
107 m_presenceData[sessionID].Data["Position"] = position;
108 m_presenceData[sessionID].Data["LookAt"] = lookAt;
109 return true;
110 }
111
112 return false;
113 }
114
115 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
116 {
117 if (Instance != this)
118 return Instance.SetHomeLocation(userID, regionID, position, lookAt);
119
120 bool foundone = false;
121 foreach (PresenceData p in m_presenceData.Values)
122 {
123 if (p.UserID == userID)
124 {
125// m_log.DebugFormat(
126// "[NULL PRESENCE DATA]: Setting home location {0} {1} {2} for {3}",
127// regionID, position, lookAt, p.UserID);
128
129 p.Data["HomeRegionID"] = regionID.ToString();
130 p.Data["HomePosition"] = position.ToString();
131 p.Data["HomeLookAt"] = lookAt.ToString();
132 foundone = true;
133 }
134 }
135
136 return foundone;
137 }
138
139 public PresenceData[] Get(string field, string data)
140 {
141 if (Instance != this)
142 return Instance.Get(field, data);
143
144// m_log.DebugFormat(
145// "[NULL PRESENCE DATA]: Getting presence data for field {0} with parameter {1}", field, data);
146
147 List<PresenceData> presences = new List<PresenceData>();
148 if (field == "UserID")
149 {
150 foreach (PresenceData p in m_presenceData.Values)
151 {
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
159 return presences.ToArray();
160 }
161 else if (field == "SessionID")
162 {
163 UUID session = UUID.Zero;
164 if (!UUID.TryParse(data, out session))
165 return presences.ToArray();
166
167 if (m_presenceData.ContainsKey(session))
168 {
169 presences.Add(m_presenceData[session]);
170 return presences.ToArray();
171 }
172 }
173 else if (field == "RegionID")
174 {
175 UUID region = UUID.Zero;
176 if (!UUID.TryParse(data, out region))
177 return presences.ToArray();
178 foreach (PresenceData p in m_presenceData.Values)
179 if (p.RegionID == region)
180 presences.Add(p);
181 return presences.ToArray();
182 }
183 else
184 {
185 foreach (PresenceData p in m_presenceData.Values)
186 {
187 if (p.Data.ContainsKey(field) && p.Data[field] == data)
188 presences.Add(p);
189 }
190 return presences.ToArray();
191 }
192
193 return presences.ToArray();
194 }
195
196 public void Prune(string userID)
197 {
198 if (Instance != this)
199 {
200 Instance.Prune(userID);
201 return;
202 }
203
204// m_log.DebugFormat("[NULL PRESENCE DATA]: Prune called for {0}", userID);
205
206 List<UUID> deleteSessions = new List<UUID>();
207 int online = 0;
208
209 foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData)
210 {
211// m_log.DebugFormat("Online: {0}", kvp.Value.Data["Online"]);
212
213 bool on = false;
214 if (bool.TryParse(kvp.Value.Data["Online"], out on) && on)
215 online++;
216 else
217 deleteSessions.Add(kvp.Key);
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
223 if (online == 0 && deleteSessions.Count > 0)
224 deleteSessions.RemoveAt(0);
225
226 foreach (UUID s in deleteSessions)
227 m_presenceData.Remove(s);
228 }
229
230 public bool Delete(string field, string data)
231 {
232// m_log.DebugFormat(
233// "[NULL PRESENCE DATA]: Deleting presence data for field {0} with parameter {1}", field, data);
234
235 if (Instance != this)
236 return Instance.Delete(field, data);
237
238 List<UUID> presences = new List<UUID>();
239 if (field == "UserID")
240 {
241 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
242 if (p.Value.UserID == data)
243 presences.Add(p.Key);
244 }
245 else if (field == "SessionID")
246 {
247 UUID session = UUID.Zero;
248 if (UUID.TryParse(data, out session))
249 {
250 if (m_presenceData.ContainsKey(session))
251 {
252 presences.Add(session);
253 }
254 }
255 }
256 else if (field == "RegionID")
257 {
258 UUID region = UUID.Zero;
259 if (UUID.TryParse(data, out region))
260 {
261 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
262 if (p.Value.RegionID == region)
263 presences.Add(p.Key);
264 }
265 }
266 else
267 {
268 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
269 {
270 if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data)
271 presences.Add(p.Key);
272 }
273 }
274
275 foreach (UUID u in presences)
276 m_presenceData.Remove(u);
277
278 if (presences.Count == 0)
279 return false;
280
281 return true;
282 }
283
284 }
285}