diff --git a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs index 930b3f4569..4d65ee92f1 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs @@ -176,20 +176,24 @@ namespace OpenSim.Framework.Data.MySQL public List GeneratePickerResults(LLUUID queryID, string query) { List returnlist = new List(); + + System.Text.RegularExpressions.Regex objAlphaNumericPattern = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]"); + string[] querysplit; querysplit = query.Split(' '); if (querysplit.Length == 2) { + Dictionary param = new Dictionary(); + param["?first"] = objAlphaNumericPattern.Replace(querysplit[0],"") + "%"; + param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], "") + "%"; try { lock (database) { - Dictionary param = new Dictionary(); - param["?first"] = querysplit[0]; - param["?second"] = querysplit[1]; + IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = ?first AND lastname = ?second", param); + database.Query("SELECT UUID,username,surname FROM users WHERE username like ?first AND lastname like ?second LIMIT 100", param); IDataReader reader = result.ExecuteReader(); @@ -224,11 +228,10 @@ namespace OpenSim.Framework.Data.MySQL lock (database) { Dictionary param = new Dictionary(); - param["?first"] = querysplit[0]; - param["?second"] = querysplit[1]; + param["?first"] = objAlphaNumericPattern.Replace(querysplit[0],"") + "%"; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = ?first OR lastname = ?second", param); + database.Query("SELECT UUID,username,surname FROM users WHERE username like ?first OR lastname like ?second", param); IDataReader reader = result.ExecuteReader(); diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs index 3ae1fbab3e..3138911be7 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs @@ -110,31 +110,35 @@ namespace OpenSim.Framework.Data.MySQL public List GeneratePickerResults(LLUUID queryID, string query) { List returnlist = new List(); + + System.Text.RegularExpressions.Regex objAlphaNumericPattern = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]"); + string[] querysplit; querysplit = query.Split(' '); if (querysplit.Length == 2) { + Dictionary param = new Dictionary(); + param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], "") + "%"; + param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], "") + "%"; try { lock (database) { - Dictionary param = new Dictionary(); - param["?first"] = querysplit[0]; - param["?second"] = querysplit[1]; + IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = ?first AND lastname = ?second", param); + database.Query("SELECT UUID,username,lastname FROM users WHERE username like ?first AND lastname like ?second LIMIT 100", param); IDataReader reader = result.ExecuteReader(); - + while (reader.Read()) { OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar(); user.AvatarID = new LLUUID((string)reader["UUID"]); user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + user.lastName = (string)reader["lastname"]; returnlist.Add(user); - + } reader.Close(); result.Dispose(); @@ -148,7 +152,7 @@ namespace OpenSim.Framework.Data.MySQL } - + } else if (querysplit.Length == 1) { @@ -158,11 +162,10 @@ namespace OpenSim.Framework.Data.MySQL lock (database) { Dictionary param = new Dictionary(); - param["?first"] = querysplit[0]; - param["?second"] = querysplit[1]; + param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], "") + "%"; IDbCommand result = - database.Query("SELECT UUID,username,surname FROM users WHERE username = ?first OR lastname = ?second", param); + database.Query("SELECT UUID,username,lastname FROM users WHERE username like ?first OR lastname like ?first LIMIT 100", param); IDataReader reader = result.ExecuteReader(); @@ -171,7 +174,7 @@ namespace OpenSim.Framework.Data.MySQL OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar(); user.AvatarID = new LLUUID((string)reader["UUID"]); user.firstName = (string)reader["username"]; - user.lastName = (string)reader["surname"]; + user.lastName = (string)reader["lastname"]; returnlist.Add(user); } diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index c834690992..634698e367 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -98,6 +98,8 @@ namespace OpenSim.Grid.UserServer httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); + httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar); + httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index 58e9677bb2..16eedcda78 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -27,6 +27,7 @@ */ using System; using System.Collections; +using System.Collections.Generic; using libsecondlife; using Nwc.XmlRpc; using OpenSim.Framework; @@ -70,6 +71,24 @@ namespace OpenSim.Grid.UserServer return response; } + public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(LLUUID queryID, List returnUsers) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable responseData = new Hashtable(); + // Query Result Information + responseData["queryid"] = (string)queryID.ToStringHyphenated(); + responseData["avcount"] = (string)returnUsers.Count.ToString(); + + for (int i = 0; i < returnUsers.Count; i++) + { + responseData["avatarid" + i.ToString()] = returnUsers[i].AvatarID.ToStringHyphenated(); + responseData["firstname" + i.ToString()] = returnUsers[i].firstName; + responseData["lastname" + i.ToString()] = returnUsers[i].lastName; + } + response.Value = responseData; + + return response; + } /// /// Converts a user profile to an XML element which can be returned /// @@ -113,6 +132,23 @@ namespace OpenSim.Grid.UserServer #region XMLRPC User Methods + public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + List returnAvatar = new List(); + LLUUID queryID = new LLUUID(LLUUID.Zero.ToStringHyphenated()); + + if (requestData.Contains("avquery") && requestData.Contains("queryid")) + { + queryID = new LLUUID((string)requestData["queryid"]); + returnAvatar = GenerateAgentPickerRequestResponse(queryID,(string)requestData["avquery"]); + } + + Console.WriteLine("[AVATARINFO]: Servicing Avatar Query: " + (string)requestData["avquery"]); + return AvatarPickerListtoXmlRPCResponse(queryID,returnAvatar); + } + public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request) { XmlRpcResponse response = new XmlRpcResponse(); diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 475066e15c..ed77e20418 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -80,6 +80,34 @@ namespace OpenSim.Region.Communications.OGS1 return userData; } + public List ConvertXMLRPCDataToAvatarPickerList(LLUUID queryID,Hashtable data) + { + List pickerlist = new List(); + int pickercount = Convert.ToInt32((string)data["avcount"]); + LLUUID respqueryID = new LLUUID((string)data["queryid"]); + if (queryID == respqueryID) + { + for (int i = 0; i < pickercount; i++) + { + AvatarPickerAvatar apicker = new AvatarPickerAvatar(); + LLUUID avatarID = new LLUUID((string)data["avatarid" + i.ToString()]); + string firstname = (string)data["firstname" + i.ToString()]; + string lastname = (string)data["lastname" + i.ToString()]; + apicker.AvatarID = avatarID; + apicker.firstName = firstname; + apicker.lastName = lastname; + pickerlist.Add(apicker); + } + } + else + { + MainLog.Instance.Warn("INTERGRID", "Got invalid queryID from userServer"); + } + return pickerlist; + + } + + public UserProfileData GetUserProfile(string firstName, string lastName) { return GetUserProfile(firstName + " " + lastName); @@ -89,7 +117,25 @@ namespace OpenSim.Region.Communications.OGS1 public List GenerateAgentPickerRequestResponse(LLUUID queryID, string query) { List pickerlist = new List(); - + System.Text.RegularExpressions.Regex objAlphaNumericPattern = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 ]"); + try + { + Hashtable param = new Hashtable(); + param["queryid"] = (string)queryID.ToStringHyphenated(); + param["avquery"] = objAlphaNumericPattern.Replace(query, ""); + IList parameters = new ArrayList(); + parameters.Add(param); + XmlRpcRequest req = new XmlRpcRequest("get_avatar_picker_avatar", parameters); + XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000); + Hashtable respData = (Hashtable)resp.Value; + pickerlist = ConvertXMLRPCDataToAvatarPickerList(queryID,respData); + } + catch (WebException e) + { + MainLog.Instance.Warn("Error when trying to fetch Avatar Picker Response: " + + e.Message); + // Return Empty picker list (no results) + } return pickerlist; } public UserProfileData GetUserProfile(string name)