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.cs227
1 files changed, 227 insertions, 0 deletions
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs
new file mode 100644
index 0000000..91f1cc5
--- /dev/null
+++ b/OpenSim/Data/Null/NullPresenceData.cs
@@ -0,0 +1,227 @@
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)
100 {
101 if (Instance != this)
102 return Instance.ReportAgent(sessionID, regionID);
103
104 if (m_presenceData.ContainsKey(sessionID))
105 {
106 m_presenceData[sessionID].RegionID = regionID;
107 return true;
108 }
109
110 return false;
111 }
112
113
114 public PresenceData[] Get(string field, string data)
115 {
116 if (Instance != this)
117 return Instance.Get(field, data);
118
119// m_log.DebugFormat(
120// "[NULL PRESENCE DATA]: Getting presence data for field {0} with parameter {1}", field, data);
121
122 List<PresenceData> presences = new List<PresenceData>();
123 if (field == "UserID")
124 {
125 foreach (PresenceData p in m_presenceData.Values)
126 {
127 if (p.UserID == data)
128 {
129 presences.Add(p);
130// Console.WriteLine("HOME for " + p.UserID + " is " + (p.Data.ContainsKey("HomeRegionID") ? p.Data["HomeRegionID"] : "Not found"));
131 }
132 }
133
134 return presences.ToArray();
135 }
136 else if (field == "SessionID")
137 {
138 UUID session = UUID.Zero;
139 if (!UUID.TryParse(data, out session))
140 return presences.ToArray();
141
142 if (m_presenceData.ContainsKey(session))
143 {
144 presences.Add(m_presenceData[session]);
145 return presences.ToArray();
146 }
147 }
148 else if (field == "RegionID")
149 {
150 UUID region = UUID.Zero;
151 if (!UUID.TryParse(data, out region))
152 return presences.ToArray();
153 foreach (PresenceData p in m_presenceData.Values)
154 if (p.RegionID == region)
155 presences.Add(p);
156 return presences.ToArray();
157 }
158 else
159 {
160 foreach (PresenceData p in m_presenceData.Values)
161 {
162 if (p.Data.ContainsKey(field) && p.Data[field] == data)
163 presences.Add(p);
164 }
165 return presences.ToArray();
166 }
167
168 return presences.ToArray();
169 }
170
171
172 public bool Delete(string field, string data)
173 {
174// m_log.DebugFormat(
175// "[NULL PRESENCE DATA]: Deleting presence data for field {0} with parameter {1}", field, data);
176
177 if (Instance != this)
178 return Instance.Delete(field, data);
179
180 List<UUID> presences = new List<UUID>();
181 if (field == "UserID")
182 {
183 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
184 if (p.Value.UserID == data)
185 presences.Add(p.Key);
186 }
187 else if (field == "SessionID")
188 {
189 UUID session = UUID.Zero;
190 if (UUID.TryParse(data, out session))
191 {
192 if (m_presenceData.ContainsKey(session))
193 {
194 presences.Add(session);
195 }
196 }
197 }
198 else if (field == "RegionID")
199 {
200 UUID region = UUID.Zero;
201 if (UUID.TryParse(data, out region))
202 {
203 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
204 if (p.Value.RegionID == region)
205 presences.Add(p.Key);
206 }
207 }
208 else
209 {
210 foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
211 {
212 if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data)
213 presences.Add(p.Key);
214 }
215 }
216
217 foreach (UUID u in presences)
218 m_presenceData.Remove(u);
219
220 if (presences.Count == 0)
221 return false;
222
223 return true;
224 }
225
226 }
227}