aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Null/NullUserAccountData.cs
diff options
context:
space:
mode:
authorDiva Canto2010-02-14 16:57:02 -0800
committerDiva Canto2010-02-14 16:57:02 -0800
commitdc197856727c06b0b06488ab839409831af84865 (patch)
tree52db90cc6ae1ad2abcb6103fca0129a69bea4716 /OpenSim/Data/Null/NullUserAccountData.cs
parentImplement the methods needed for the login service to populate the friendslist (diff)
downloadopensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.zip
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.gz
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.bz2
opensim-SC_OLD-dc197856727c06b0b06488ab839409831af84865.tar.xz
Added UserAccount, Avatar and Authentication to Data.Null, so that OpenSim can run out-of-the-box. #WaitingForSQLite
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/Null/NullUserAccountData.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/OpenSim/Data/Null/NullUserAccountData.cs b/OpenSim/Data/Null/NullUserAccountData.cs
new file mode 100644
index 0000000..fc2c5d5
--- /dev/null
+++ b/OpenSim/Data/Null/NullUserAccountData.cs
@@ -0,0 +1,139 @@
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 OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Data;
34
35namespace OpenSim.Data.Null
36{
37 public class NullUserAccountData : IUserAccountData
38 {
39 private static Dictionary<UUID, UserAccountData> m_DataByUUID = new Dictionary<UUID, UserAccountData>();
40 private static Dictionary<string, UserAccountData> m_DataByName = new Dictionary<string, UserAccountData>();
41 private static Dictionary<string, UserAccountData> m_DataByEmail = new Dictionary<string, UserAccountData>();
42
43 public NullUserAccountData(string connectionString, string realm)
44 {
45 }
46
47 /// <summary>
48 /// Tries to implement the Get [] semantics, but it cuts corners like crazy.
49 /// Specifically, it relies on the knowledge that the only Gets used are
50 /// keyed on PrincipalID, Email, and FirstName+LastName.
51 /// </summary>
52 /// <param name="fields"></param>
53 /// <param name="values"></param>
54 /// <returns></returns>
55 public UserAccountData[] Get(string[] fields, string[] values)
56 {
57 List<string> fieldsLst = new List<string>(fields);
58 if (fieldsLst.Contains("PrincipalID"))
59 {
60 int i = fieldsLst.IndexOf("PrincipalID");
61 UUID id = UUID.Zero;
62 if (UUID.TryParse(values[i], out id))
63 if (m_DataByUUID.ContainsKey(id))
64 return new UserAccountData[] { m_DataByUUID[id] };
65 }
66 if (fieldsLst.Contains("FirstName") && fieldsLst.Contains("LastName"))
67 {
68 int findex = fieldsLst.IndexOf("FirstName");
69 int lindex = fieldsLst.IndexOf("LastName");
70 if (m_DataByName.ContainsKey(values[findex] + " " + values[lindex]))
71 return new UserAccountData[] { m_DataByName[values[findex] + " " + values[lindex]] };
72 }
73 if (fieldsLst.Contains("Email"))
74 {
75 int i = fieldsLst.IndexOf("Email");
76 if (m_DataByEmail.ContainsKey(values[i]))
77 return new UserAccountData[] { m_DataByEmail[values[i]] };
78 }
79
80 // Fail
81 return new UserAccountData[0];
82 }
83
84 public bool Store(UserAccountData data)
85 {
86 if (data == null)
87 return false;
88
89 m_DataByUUID[data.PrincipalID] = data;
90 m_DataByName[data.FirstName + " " + data.LastName] = data;
91 if (data.Data.ContainsKey("Email") && data.Data["Email"] != string.Empty)
92 m_DataByEmail[data.Data["Email"]] = data;
93
94 return true;
95 }
96
97 public UserAccountData[] GetUsers(UUID scopeID, string query)
98 {
99 string[] words = query.Split(new char[] { ' ' });
100
101 for (int i = 0; i < words.Length; i++)
102 {
103 if (words[i].Length < 3)
104 {
105 if (i != words.Length - 1)
106 Array.Copy(words, i + 1, words, i, words.Length - i - 1);
107 Array.Resize(ref words, words.Length - 1);
108 }
109 }
110
111 if (words.Length == 0)
112 return new UserAccountData[0];
113
114 if (words.Length > 2)
115 return new UserAccountData[0];
116
117 List<string> lst = new List<string>(m_DataByName.Keys);
118 if (words.Length == 1)
119 {
120 lst = lst.FindAll(delegate(string s) { return s.StartsWith(words[0]); });
121 }
122 else
123 {
124 lst = lst.FindAll(delegate(string s) { return s.Contains(words[0]) || s.Contains(words[1]); });
125 }
126
127 if (lst == null || (lst != null && lst.Count == 0))
128 return new UserAccountData[0];
129
130 UserAccountData[] result = new UserAccountData[lst.Count];
131 int n = 0;
132 foreach (string key in lst)
133 result[n++] = m_DataByName[key];
134
135 return result;
136 }
137
138 }
139}