From e13a17cc0c8514bc673d5ba39c86d23451278389 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 16 Jan 2012 02:19:19 +0100 Subject: [PATCH] Allow retrival of multiple user records in one operation, analog to presence --- .../GridUser/LocalGridUserServiceConnector.cs | 4 ++ .../RemoteGridUserServiceConnector.cs | 5 ++ .../GridUser/GridUserServerPostHandler.cs | 42 +++++++++++++ .../GridUser/GridUserServiceConnector.cs | 60 +++++++++++++++++++ .../SimianPresenceServiceConnector.cs | 4 ++ .../Services/Interfaces/IGridUserService.cs | 3 +- .../UserAccountService/GridUserService.cs | 12 +++- 7 files changed, 128 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs index 985aceca5d..90fe69e18c 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/LocalGridUserServiceConnector.cs @@ -171,6 +171,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser { return m_GridUserService.GetGridUserInfo(userID); } + public GridUserInfo[] GetGridUserInfo(string[] userID) + { + return m_GridUserService.GetGridUserInfo(userID); + } #endregion diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs index 95b3591ab4..badb5527fa 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/RemoteGridUserServiceConnector.cs @@ -147,6 +147,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser return m_RemoteConnector.GetGridUserInfo(userID); } + public GridUserInfo[] GetGridUserInfo(string[] userID) + { + return m_RemoteConnector.GetGridUserInfo(userID); + } + #endregion } diff --git a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs index 4c0d52e722..bf212554c7 100644 --- a/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs +++ b/OpenSim/Server/Handlers/GridUser/GridUserServerPostHandler.cs @@ -88,6 +88,8 @@ namespace OpenSim.Server.Handlers.GridUser return SetPosition(request); case "getgriduserinfo": return GetGridUserInfo(request); + case "getgriduserinfos": + return GetGridUserInfos(request); } m_log.DebugFormat("[GRID USER HANDLER]: unknown method request: {0}", method); } @@ -193,6 +195,46 @@ namespace OpenSim.Server.Handlers.GridUser } + byte[] GetGridUserInfos(Dictionary request) + { + + string[] userIDs; + + if (!request.ContainsKey("AgentIDs")) + { + m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos called without required uuids argument"); + return FailureResult(); + } + + if (!(request["AgentIDs"] is List)) + { + m_log.DebugFormat("[GRID USER HANDLER]: GetGridUserInfos input argument was of unexpected type {0}", request["uuids"].GetType().ToString()); + return FailureResult(); + } + + userIDs = ((List)request["AgentIDs"]).ToArray(); + + GridUserInfo[] pinfos = m_GridUserService.GetGridUserInfo(userIDs); + + Dictionary result = new Dictionary(); + if ((pinfos == null) || ((pinfos != null) && (pinfos.Length == 0))) + result["result"] = "null"; + else + { + int i = 0; + foreach (GridUserInfo pinfo in pinfos) + { + Dictionary rinfoDict = pinfo.ToKeyValuePairs(); + result["griduser" + i] = rinfoDict; + i++; + } + } + + string xmlString = ServerUtils.BuildXmlResponse(result); + UTF8Encoding encoding = new UTF8Encoding(); + return encoding.GetBytes(xmlString); + } + private bool UnpackArgs(Dictionary request, out string user, out UUID region, out Vector3 position, out Vector3 lookAt) { user = string.Empty; diff --git a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs index 738cc06949..aa98b5df49 100644 --- a/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs +++ b/OpenSim/Services/Connectors/GridUser/GridUserServiceConnector.cs @@ -223,5 +223,65 @@ namespace OpenSim.Services.Connectors } + public GridUserInfo[] GetGridUserInfo(string[] userIDs) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "getgriduserinfos"; + + sendData["AgentIDs"] = new List(userIDs); + + string reply = string.Empty; + string reqString = ServerUtils.BuildQueryString(sendData); + //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/griduser", + reqString); + if (reply == null || (reply != null && reply == string.Empty)) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply"); + return null; + } + } + catch (Exception e) + { + m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server: {0}", e.Message); + } + + List rinfos = new List(); + + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData != null) + { + if (replyData.ContainsKey("result") && + (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) + { + return new GridUserInfo[0]; + } + + Dictionary.ValueCollection pinfosList = replyData.Values; + //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); + foreach (object griduser in pinfosList) + { + if (griduser is Dictionary) + { + GridUserInfo pinfo = new GridUserInfo((Dictionary)griduser); + rinfos.Add(pinfo); + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}", + griduser.GetType()); + } + } + else + m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response"); + + return rinfos.ToArray(); + } } } diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs index 678f738abb..ca1b64f2b7 100644 --- a/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs +++ b/OpenSim/Services/Connectors/SimianGrid/SimianPresenceServiceConnector.cs @@ -472,6 +472,10 @@ namespace OpenSim.Services.Connectors.SimianGrid return false; } + public GridUserInfo[] GetGridUserInfo(string[] userIDs) + { + return new GridUserInfo[0]; + } #endregion Helpers } } diff --git a/OpenSim/Services/Interfaces/IGridUserService.cs b/OpenSim/Services/Interfaces/IGridUserService.cs index 6613ae769f..0a52bfaae4 100644 --- a/OpenSim/Services/Interfaces/IGridUserService.cs +++ b/OpenSim/Services/Interfaces/IGridUserService.cs @@ -131,5 +131,6 @@ namespace OpenSim.Services.Interfaces bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt); GridUserInfo GetGridUserInfo(string userID); + GridUserInfo[] GetGridUserInfo(string[] userID); } -} \ No newline at end of file +} diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs index 9b18915255..ac3d8fda44 100644 --- a/OpenSim/Services/UserAccountService/GridUserService.cs +++ b/OpenSim/Services/UserAccountService/GridUserService.cs @@ -73,6 +73,16 @@ namespace OpenSim.Services.UserAccountService return info; } + public GridUserInfo[] GetGridUserInfo(string[] userIDs) + { + List ret = new List(); + + foreach (string id in userIDs) + ret.Add(GetGridUserInfo(id)); + + return ret.ToArray(); + } + public GridUserInfo LoggedIn(string userID) { m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID); @@ -156,4 +166,4 @@ namespace OpenSim.Services.UserAccountService return m_Database.Store(d); } } -} \ No newline at end of file +}