diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Null/NullPresenceData.cs | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs new file mode 100644 index 0000000..40700cf --- /dev/null +++ b/OpenSim/Data/Null/NullPresenceData.cs | |||
@@ -0,0 +1,257 @@ | |||
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 | private static NullPresenceData Instance; | ||
40 | |||
41 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); | ||
42 | |||
43 | public NullPresenceData(string connectionString, string realm) | ||
44 | { | ||
45 | if (Instance == null) | ||
46 | Instance = this; | ||
47 | |||
48 | //Console.WriteLine("[XXX] NullRegionData constructor"); | ||
49 | // Let's stick in a test presence | ||
50 | PresenceData p = new PresenceData(); | ||
51 | p.SessionID = UUID.Zero; | ||
52 | p.UserID = UUID.Zero.ToString(); | ||
53 | p.Data = new Dictionary<string, string>(); | ||
54 | p.Data["Online"] = "true"; | ||
55 | m_presenceData.Add(UUID.Zero, p); | ||
56 | } | ||
57 | |||
58 | public bool Store(PresenceData data) | ||
59 | { | ||
60 | if (Instance != this) | ||
61 | return Instance.Store(data); | ||
62 | |||
63 | m_presenceData[data.SessionID] = data; | ||
64 | return true; | ||
65 | } | ||
66 | |||
67 | public PresenceData Get(UUID sessionID) | ||
68 | { | ||
69 | if (Instance != this) | ||
70 | return Instance.Get(sessionID); | ||
71 | |||
72 | if (m_presenceData.ContainsKey(sessionID)) | ||
73 | return m_presenceData[sessionID]; | ||
74 | |||
75 | return null; | ||
76 | } | ||
77 | |||
78 | public void LogoutRegionAgents(UUID regionID) | ||
79 | { | ||
80 | if (Instance != this) | ||
81 | { | ||
82 | Instance.LogoutRegionAgents(regionID); | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | List<UUID> toBeDeleted = new List<UUID>(); | ||
87 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | ||
88 | if (kvp.Value.RegionID == regionID) | ||
89 | toBeDeleted.Add(kvp.Key); | ||
90 | |||
91 | foreach (UUID u in toBeDeleted) | ||
92 | m_presenceData.Remove(u); | ||
93 | } | ||
94 | |||
95 | public bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt) | ||
96 | { | ||
97 | if (Instance != this) | ||
98 | return Instance.ReportAgent(sessionID, regionID, position, lookAt); | ||
99 | if (m_presenceData.ContainsKey(sessionID)) | ||
100 | { | ||
101 | m_presenceData[sessionID].RegionID = regionID; | ||
102 | m_presenceData[sessionID].Data["Position"] = position; | ||
103 | m_presenceData[sessionID].Data["LookAt"] = lookAt; | ||
104 | return true; | ||
105 | } | ||
106 | |||
107 | return false; | ||
108 | } | ||
109 | |||
110 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
111 | { | ||
112 | if (Instance != this) | ||
113 | return Instance.SetHomeLocation(userID, regionID, position, lookAt); | ||
114 | |||
115 | bool foundone = false; | ||
116 | foreach (PresenceData p in m_presenceData.Values) | ||
117 | { | ||
118 | if (p.UserID == userID) | ||
119 | { | ||
120 | p.Data["HomeRegionID"] = regionID.ToString(); | ||
121 | p.Data["HomePosition"] = position.ToString(); | ||
122 | p.Data["HomeLookAt"] = lookAt.ToString(); | ||
123 | foundone = true; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | return foundone; | ||
128 | } | ||
129 | |||
130 | public PresenceData[] Get(string field, string data) | ||
131 | { | ||
132 | if (Instance != this) | ||
133 | return Instance.Get(field, data); | ||
134 | |||
135 | List<PresenceData> presences = new List<PresenceData>(); | ||
136 | if (field == "UserID") | ||
137 | { | ||
138 | foreach (PresenceData p in m_presenceData.Values) | ||
139 | if (p.UserID == data) | ||
140 | presences.Add(p); | ||
141 | return presences.ToArray(); | ||
142 | } | ||
143 | else if (field == "SessionID") | ||
144 | { | ||
145 | UUID session = UUID.Zero; | ||
146 | if (!UUID.TryParse(data, out session)) | ||
147 | return presences.ToArray(); | ||
148 | |||
149 | if (m_presenceData.ContainsKey(session)) | ||
150 | { | ||
151 | presences.Add(m_presenceData[session]); | ||
152 | return presences.ToArray(); | ||
153 | } | ||
154 | } | ||
155 | else if (field == "RegionID") | ||
156 | { | ||
157 | UUID region = UUID.Zero; | ||
158 | if (!UUID.TryParse(data, out region)) | ||
159 | return presences.ToArray(); | ||
160 | foreach (PresenceData p in m_presenceData.Values) | ||
161 | if (p.RegionID == region) | ||
162 | presences.Add(p); | ||
163 | return presences.ToArray(); | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | foreach (PresenceData p in m_presenceData.Values) | ||
168 | { | ||
169 | if (p.Data.ContainsKey(field) && p.Data[field] == data) | ||
170 | presences.Add(p); | ||
171 | } | ||
172 | return presences.ToArray(); | ||
173 | } | ||
174 | |||
175 | return presences.ToArray(); | ||
176 | } | ||
177 | |||
178 | public void Prune(string userID) | ||
179 | { | ||
180 | if (Instance != this) | ||
181 | { | ||
182 | Instance.Prune(userID); | ||
183 | return; | ||
184 | } | ||
185 | |||
186 | List<UUID> deleteSessions = new List<UUID>(); | ||
187 | int online = 0; | ||
188 | |||
189 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | ||
190 | { | ||
191 | bool on = false; | ||
192 | if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) | ||
193 | online++; | ||
194 | else | ||
195 | deleteSessions.Add(kvp.Key); | ||
196 | } | ||
197 | if (online == 0 && deleteSessions.Count > 0) | ||
198 | deleteSessions.RemoveAt(0); | ||
199 | |||
200 | foreach (UUID s in deleteSessions) | ||
201 | m_presenceData.Remove(s); | ||
202 | |||
203 | } | ||
204 | |||
205 | public bool Delete(string field, string data) | ||
206 | { | ||
207 | if (Instance != this) | ||
208 | return Delete(field, data); | ||
209 | |||
210 | List<UUID> presences = new List<UUID>(); | ||
211 | if (field == "UserID") | ||
212 | { | ||
213 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
214 | if (p.Value.UserID == data) | ||
215 | presences.Add(p.Key); | ||
216 | } | ||
217 | else if (field == "SessionID") | ||
218 | { | ||
219 | UUID session = UUID.Zero; | ||
220 | if (UUID.TryParse(data, out session)) | ||
221 | { | ||
222 | if (m_presenceData.ContainsKey(session)) | ||
223 | { | ||
224 | presences.Add(session); | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | else if (field == "RegionID") | ||
229 | { | ||
230 | UUID region = UUID.Zero; | ||
231 | if (UUID.TryParse(data, out region)) | ||
232 | { | ||
233 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
234 | if (p.Value.RegionID == region) | ||
235 | presences.Add(p.Key); | ||
236 | } | ||
237 | } | ||
238 | else | ||
239 | { | ||
240 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
241 | { | ||
242 | if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data) | ||
243 | presences.Add(p.Key); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | foreach (UUID u in presences) | ||
248 | m_presenceData.Remove(u); | ||
249 | |||
250 | if (presences.Count == 0) | ||
251 | return false; | ||
252 | |||
253 | return true; | ||
254 | } | ||
255 | |||
256 | } | ||
257 | } | ||