From 01f6aee020eddb46893cbfbcf3b1e114a85ac261 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 31 Dec 2009 02:26:00 +0000 Subject: [PATCH] Implement avatar picker queries --- OpenSim/Data/IUserAccountData.cs | 1 + OpenSim/Data/MSSQL/MSSQLUserAccountData.cs | 5 +++ OpenSim/Data/MySQL/MySQLUserAccountData.cs | 38 ++++++++++++++++++- .../UserAccountService/UserAccountService.cs | 12 +++++- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/OpenSim/Data/IUserAccountData.cs b/OpenSim/Data/IUserAccountData.cs index e350a18f38..6ee5995fd1 100644 --- a/OpenSim/Data/IUserAccountData.cs +++ b/OpenSim/Data/IUserAccountData.cs @@ -48,5 +48,6 @@ namespace OpenSim.Data { UserAccountData[] Get(string[] fields, string[] values); bool Store(UserAccountData data); + UserAccountData[] GetUsers(UUID scopeID, string query); } } diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs index ca09029dc4..01c64dce86 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs @@ -194,5 +194,10 @@ namespace OpenSim.Data.MSSQL { return null; } + + public UserAccountData[] GetUsers(UUID scopeID, string query) + { + return null; + } } } diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index ae7d5caa97..aa69d680a7 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs @@ -42,9 +42,43 @@ namespace OpenSim.Data.MySQL { } - public bool Store(UserAccountData data) + public UserAccountData[] GetUsers(UUID scopeID, string query) { - return Store(data); + 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]; + + MySqlCommand cmd = new MySqlCommand(); + + if (words.Length == 1) + { + cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?search or LastName like ?search)", m_Realm); + cmd.Parameters.AddWithValue("?search", "%" + words[0] + "%"); + cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); + } + else + { + cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst or LastName like ?searchLast)", m_Realm); + cmd.Parameters.AddWithValue("?searchFirst", "%" + words[0] + "%"); + cmd.Parameters.AddWithValue("?searchLast", "%" + words[1] + "%"); + cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); + } + + return DoQuery(cmd); } } } diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 29545893c5..c14651df7e 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -168,7 +168,17 @@ namespace OpenSim.Services.UserAccountService public List GetUserAccounts(UUID scopeID, string query) { - return null; + UserAccountData[] d = m_Database.GetUsers(scopeID, query); + + if (d == null) + return new List(); + + List ret = new List(); + + foreach (UserAccountData data in d) + ret.Add(MakeUserAccount(data)); + + return ret; } } }