OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
NullPresenceData.cs
Go to the documentation of this file.
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 System.Reflection;
32 using log4net;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Data;
36 
37 namespace OpenSim.Data.Null
38 {
40  {
41 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 
43  public 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  public PresenceData[] Get(string field, string data)
114  {
115  if (Instance != this)
116  return Instance.Get(field, data);
117 
118 // m_log.DebugFormat(
119 // "[NULL PRESENCE DATA]: Getting presence data for field {0} with parameter {1}", field, data);
120 
121  List<PresenceData> presences = new List<PresenceData>();
122  if (field == "UserID")
123  {
124  foreach (PresenceData p in m_presenceData.Values)
125  {
126  if (p.UserID == data)
127  {
128  presences.Add(p);
129 // Console.WriteLine("HOME for " + p.UserID + " is " + (p.Data.ContainsKey("HomeRegionID") ? p.Data["HomeRegionID"] : "Not found"));
130  }
131  }
132 
133  return presences.ToArray();
134  }
135  else if (field == "SessionID")
136  {
137  UUID session = UUID.Zero;
138  if (!UUID.TryParse(data, out session))
139  return presences.ToArray();
140 
141  if (m_presenceData.ContainsKey(session))
142  {
143  presences.Add(m_presenceData[session]);
144  return presences.ToArray();
145  }
146  }
147  else if (field == "RegionID")
148  {
149  UUID region = UUID.Zero;
150  if (!UUID.TryParse(data, out region))
151  return presences.ToArray();
152  foreach (PresenceData p in m_presenceData.Values)
153  if (p.RegionID == region)
154  presences.Add(p);
155  return presences.ToArray();
156  }
157  else
158  {
159  foreach (PresenceData p in m_presenceData.Values)
160  {
161  if (p.Data.ContainsKey(field) && p.Data[field] == data)
162  presences.Add(p);
163  }
164  return presences.ToArray();
165  }
166 
167  return presences.ToArray();
168  }
169 
170 
171  public bool Delete(string field, string data)
172  {
173 // m_log.DebugFormat(
174 // "[NULL PRESENCE DATA]: Deleting presence data for field {0} with parameter {1}", field, data);
175 
176  if (Instance != this)
177  return Instance.Delete(field, data);
178 
179  List<UUID> presences = new List<UUID>();
180  if (field == "UserID")
181  {
182  foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
183  if (p.Value.UserID == data)
184  presences.Add(p.Key);
185  }
186  else if (field == "SessionID")
187  {
188  UUID session = UUID.Zero;
189  if (UUID.TryParse(data, out session))
190  {
191  if (m_presenceData.ContainsKey(session))
192  {
193  presences.Add(session);
194  }
195  }
196  }
197  else if (field == "RegionID")
198  {
199  UUID region = UUID.Zero;
200  if (UUID.TryParse(data, out region))
201  {
202  foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
203  if (p.Value.RegionID == region)
204  presences.Add(p.Key);
205  }
206  }
207  else
208  {
209  foreach (KeyValuePair<UUID, PresenceData> p in m_presenceData)
210  {
211  if (p.Value.Data.ContainsKey(field) && p.Value.Data[field] == data)
212  presences.Add(p.Key);
213  }
214  }
215 
216  foreach (UUID u in presences)
217  m_presenceData.Remove(u);
218 
219  if (presences.Count == 0)
220  return false;
221 
222  return true;
223  }
224 
225  public bool VerifyAgent(UUID agentId, UUID secureSessionID)
226  {
227  if (Instance != this)
228  return Instance.VerifyAgent(agentId, secureSessionID);
229 
230  return false;
231  }
232 
233  }
234 }
bool VerifyAgent(UUID agentId, UUID secureSessionID)
An interface for connecting to the presence datastore
void LogoutRegionAgents(UUID regionID)
Dictionary< string, string > Data
static NullPresenceData Instance
bool ReportAgent(UUID sessionID, UUID regionID)
NullPresenceData(string connectionString, string realm)
bool Delete(string field, string data)
PresenceData Get(UUID sessionID)
PresenceData[] Get(string field, string data)