123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Text;
- using log4net;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Data;
- namespace OpenSim.Data.Null
- {
- public class NullUserAccountData : IUserAccountData
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
- private Dictionary<UUID, UserAccountData> m_DataByUUID = new Dictionary<UUID, UserAccountData>();
- private Dictionary<string, UserAccountData> m_DataByName = new Dictionary<string, UserAccountData>();
- private Dictionary<string, UserAccountData> m_DataByEmail = new Dictionary<string, UserAccountData>();
- public NullUserAccountData(string connectionString, string realm)
- {
- }
-
-
-
-
-
-
-
-
- public UserAccountData[] Get(string[] fields, string[] values)
- {
-
- UserAccountData[] userAccounts = new UserAccountData[0];
-
- List<string> fieldsLst = new List<string>(fields);
- if (fieldsLst.Contains("PrincipalID"))
- {
- int i = fieldsLst.IndexOf("PrincipalID");
- UUID id = UUID.Zero;
- if (UUID.TryParse(values[i], out id))
- if (m_DataByUUID.ContainsKey(id))
- userAccounts = new UserAccountData[] { m_DataByUUID[id] };
- }
- else if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName"))
- {
- int findex = fieldsLst.IndexOf("FirstName");
- int lindex = fieldsLst.IndexOf("LastName");
- if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex]))
- {
- userAccounts = new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] };
- }
- }
- else if (fieldsLst.Contains("Email"))
- {
- int i = fieldsLst.IndexOf("Email");
- if (m_DataByEmail.ContainsKey(values[i]))
- userAccounts = new UserAccountData[] { m_DataByEmail[values[i]] };
- }
-
-
- return userAccounts;
- }
- public bool Store(UserAccountData data)
- {
- if (data == null)
- return false;
-
- m_log.DebugFormat(
- "[NULL USER ACCOUNT DATA]: Storing user account {0} {1} {2} {3}",
- data.FirstName, data.LastName, data.PrincipalID, this.GetHashCode());
-
- m_DataByUUID[data.PrincipalID] = data;
- m_DataByName[data.FirstName + " " + data.LastName] = data;
- if (data.Data.ContainsKey("Email") && data.Data["Email"] != null && data.Data["Email"] != string.Empty)
- m_DataByEmail[data.Data["Email"]] = data;
-
- return true;
- }
- public UserAccountData[] GetUsers(UUID scopeID, string query)
- {
-
- string[] words = query.Split(new char[] { ' ' });
- for (int i = 0; i < words.Length; i++)
- {
- if (words[i].Length < 3)
- {
- if (i != words.Length - 1)
- Array.Copy(words, i + 1, words, i, words.Length - i - 1);
- Array.Resize(ref words, words.Length - 1);
- }
- }
- if (words.Length == 0)
- return new UserAccountData[0];
- if (words.Length > 2)
- return new UserAccountData[0];
- List<string> lst = new List<string>(m_DataByName.Keys);
- if (words.Length == 1)
- {
- lst = lst.FindAll(delegate(string s) { return s.StartsWith(words[0]); });
- }
- else
- {
- lst = lst.FindAll(delegate(string s) { return s.Contains(words[0]) || s.Contains(words[1]); });
- }
- if (lst == null || (lst != null && lst.Count == 0))
- return new UserAccountData[0];
- UserAccountData[] result = new UserAccountData[lst.Count];
- int n = 0;
- foreach (string key in lst)
- result[n++] = m_DataByName[key];
- return result;
- }
- public bool Delete(string field, string val)
- {
-
- if (field.Equals("PrincipalID"))
- {
- UUID uuid = UUID.Zero;
- if (UUID.TryParse(val, out uuid) && m_DataByUUID.ContainsKey(uuid))
- {
- UserAccountData account = m_DataByUUID[uuid];
- m_DataByUUID.Remove(uuid);
- if (m_DataByName.ContainsKey(account.FirstName + " " + account.LastName))
- m_DataByName.Remove(account.FirstName + " " + account.LastName);
- if (account.Data.ContainsKey("Email") && account.Data["Email"] != string.Empty && m_DataByEmail.ContainsKey(account.Data["Email"]))
- m_DataByEmail.Remove(account.Data["Email"]);
- return true;
- }
- }
- return false;
- }
- }
- }
|