diff options
author | Melanie | 2010-03-03 02:07:03 +0000 |
---|---|---|
committer | Melanie | 2010-03-03 02:07:03 +0000 |
commit | 028a87fe37002e7a0611f66babf1deee46c83804 (patch) | |
tree | 387aec499fd60c2012bed8148e6a2ddc847c3d95 /OpenSim/Data/Null/NullPresenceData.cs | |
parent | Revert "test" (diff) | |
parent | Fixes Region.Framework tests. Although these tests don't fail, they need to b... (diff) | |
download | opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.zip opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.gz opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.bz2 opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.xz |
Merge branch 'master' into careminster-presence-refactor
This brings careminster on the level of master. To be tested
Diffstat (limited to 'OpenSim/Data/Null/NullPresenceData.cs')
-rw-r--r-- | OpenSim/Data/Null/NullPresenceData.cs | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs new file mode 100644 index 0000000..5f78691 --- /dev/null +++ b/OpenSim/Data/Null/NullPresenceData.cs | |||
@@ -0,0 +1,261 @@ | |||
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 | { | ||
47 | Instance = this; | ||
48 | |||
49 | //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 | } | ||
58 | } | ||
59 | |||
60 | public bool Store(PresenceData data) | ||
61 | { | ||
62 | if (Instance != this) | ||
63 | return Instance.Store(data); | ||
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 | if (m_presenceData.ContainsKey(sessionID)) | ||
104 | { | ||
105 | m_presenceData[sessionID].RegionID = regionID; | ||
106 | m_presenceData[sessionID].Data["Position"] = position; | ||
107 | m_presenceData[sessionID].Data["LookAt"] = lookAt; | ||
108 | return true; | ||
109 | } | ||
110 | |||
111 | return false; | ||
112 | } | ||
113 | |||
114 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
115 | { | ||
116 | if (Instance != this) | ||
117 | return Instance.SetHomeLocation(userID, regionID, position, lookAt); | ||
118 | |||
119 | bool foundone = false; | ||
120 | foreach (PresenceData p in m_presenceData.Values) | ||
121 | { | ||
122 | if (p.UserID == userID) | ||
123 | { | ||
124 | p.Data["HomeRegionID"] = regionID.ToString(); | ||
125 | p.Data["HomePosition"] = position.ToString(); | ||
126 | p.Data["HomeLookAt"] = lookAt.ToString(); | ||
127 | foundone = true; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return foundone; | ||
132 | } | ||
133 | |||
134 | public PresenceData[] Get(string field, string data) | ||
135 | { | ||
136 | if (Instance != this) | ||
137 | return Instance.Get(field, data); | ||
138 | |||
139 | List<PresenceData> presences = new List<PresenceData>(); | ||
140 | if (field == "UserID") | ||
141 | { | ||
142 | foreach (PresenceData p in m_presenceData.Values) | ||
143 | if (p.UserID == data) | ||
144 | presences.Add(p); | ||
145 | return presences.ToArray(); | ||
146 | } | ||
147 | else if (field == "SessionID") | ||
148 | { | ||
149 | UUID session = UUID.Zero; | ||
150 | if (!UUID.TryParse(data, out session)) | ||
151 | return presences.ToArray(); | ||
152 | |||
153 | if (m_presenceData.ContainsKey(session)) | ||
154 | { | ||
155 | presences.Add(m_presenceData[session]); | ||
156 | return presences.ToArray(); | ||
157 | } | ||
158 | } | ||
159 | else if (field == "RegionID") | ||
160 | { | ||
161 | UUID region = UUID.Zero; | ||
162 | if (!UUID.TryParse(data, out region)) | ||
163 | return presences.ToArray(); | ||
164 | foreach (PresenceData p in m_presenceData.Values) | ||
165 | if (p.RegionID == region) | ||
166 | presences.Add(p); | ||
167 | return presences.ToArray(); | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | foreach (PresenceData p in m_presenceData.Values) | ||
172 | { | ||
173 | if (p.Data.ContainsKey(field) && p.Data[field] == data) | ||
174 | presences.Add(p); | ||
175 | } | ||
176 | return presences.ToArray(); | ||
177 | } | ||
178 | |||
179 | return presences.ToArray(); | ||
180 | } | ||
181 | |||
182 | public void Prune(string userID) | ||
183 | { | ||
184 | if (Instance != this) | ||
185 | { | ||
186 | Instance.Prune(userID); | ||
187 | return; | ||
188 | } | ||
189 | |||
190 | List<UUID> deleteSessions = new List<UUID>(); | ||
191 | int online = 0; | ||
192 | |||
193 | foreach (KeyValuePair<UUID, PresenceData> kvp in m_presenceData) | ||
194 | { | ||
195 | bool on = false; | ||
196 | if (bool.TryParse(kvp.Value.Data["Online"], out on) && on) | ||
197 | online++; | ||
198 | else | ||
199 | deleteSessions.Add(kvp.Key); | ||
200 | } | ||
201 | if (online == 0 && deleteSessions.Count > 0) | ||
202 | deleteSessions.RemoveAt(0); | ||
203 | |||
204 | foreach (UUID s in deleteSessions) | ||
205 | m_presenceData.Remove(s); | ||
206 | |||
207 | } | ||
208 | |||
209 | public bool Delete(string field, string data) | ||
210 | { | ||
211 | if (Instance != this) | ||
212 | return Delete(field, data); | ||
213 | |||
214 | List<UUID> presences = new List<UUID>(); | ||
215 | if (field == "UserID") | ||
216 | { | ||
217 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
218 | if (p.Value.UserID == data) | ||
219 | presences.Add(p.Key); | ||
220 | } | ||
221 | else if (field == "SessionID") | ||
222 | { | ||
223 | UUID session = UUID.Zero; | ||
224 | if (UUID.TryParse(data, out session)) | ||
225 | { | ||
226 | if (m_presenceData.ContainsKey(session)) | ||
227 | { | ||
228 | presences.Add(session); | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | else if (field == "RegionID") | ||
233 | { | ||
234 | UUID region = UUID.Zero; | ||
235 | if (UUID.TryParse(data, out region)) | ||
236 | { | ||
237 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
238 | if (p.Value.RegionID == region) | ||
239 | presences.Add(p.Key); | ||
240 | } | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData) | ||
245 | { | ||
246 | if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data) | ||
247 | presences.Add(p.Key); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | foreach (UUID u in presences) | ||
252 | m_presenceData.Remove(u); | ||
253 | |||
254 | if (presences.Count == 0) | ||
255 | return false; | ||
256 | |||
257 | return true; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | } | ||