From e0fc854f05b137c353196356e5b26d11b6ee6867 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 28 Dec 2009 23:42:08 +0000 Subject: Adding new fields and home location methid to presence. Adding cleanup (deleting all but one presence record) on logout so that they don't pile up. --- OpenSim/Data/IPresenceData.cs | 3 ++ OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 2 + OpenSim/Data/MySQL/MySQLPresenceData.cs | 52 ++++++++++++++++++++++ .../Presence/LocalPresenceServiceConnector.cs | 5 +++ .../Presence/RemotePresenceServiceConnector.cs | 5 +++ .../Handlers/Presence/PresenceServerPostHandler.cs | 29 ++++++++++++ .../Presence/PresenceServiceConnector.cs | 46 +++++++++++++++++++ OpenSim/Services/Interfaces/IPresenceService.cs | 4 ++ .../Services/PresenceService/PresenceService.cs | 34 ++++++++++++-- 9 files changed, 176 insertions(+), 4 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/IPresenceData.cs b/OpenSim/Data/IPresenceData.cs index 98353ed..20eb7f6 100644 --- a/OpenSim/Data/IPresenceData.cs +++ b/OpenSim/Data/IPresenceData.cs @@ -51,6 +51,9 @@ namespace OpenSim.Data PresenceData Get(UUID sessionID); void LogoutRegionAgents(UUID regionID); bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt); + bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); PresenceData[] Get(string field, string data); + void Prune(string userID); + bool Delete(string field, string val); } } diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index b2bd5f6..873d6d4 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -177,6 +177,8 @@ namespace OpenSim.Data.MySQL result.Add(row); } + reader.Close(); + CloseReaderCommand(cmd); return result.ToArray(); diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs index 8ccad90..72b8a0c 100644 --- a/OpenSim/Data/MySQL/MySQLPresenceData.cs +++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs @@ -93,5 +93,57 @@ namespace OpenSim.Data.MySQL return true; } + + public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + PresenceData[] pd = Get("UserID", userID); + if (pd.Length == 0) + return false; + + MySqlCommand cmd = new MySqlCommand(); + + cmd.CommandText = String.Format("update {0} set HomeRegionID=?HomeRegionID, HomePosition=?HomePosition, HomeLookAt=?HomeLookAt where UserID=?UserID", m_Realm); + + cmd.Parameters.AddWithValue("?UserID", userID); + cmd.Parameters.AddWithValue("?HomeRegionID", regionID.ToString()); + cmd.Parameters.AddWithValue("?HomePosition", position); + cmd.Parameters.AddWithValue("?HomeLookAt", lookAt); + + if (ExecuteNonQuery(cmd) == 0) + return false; + + return true; + } + + public void Prune(string userID) + { + MySqlCommand cmd = new MySqlCommand(); + + cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); + + cmd.Parameters.AddWithValue("?UserID", userID); + + IDataReader reader = ExecuteReader(cmd); + + List deleteSessions = new List(); + int online = 0; + + while(reader.Read()) + { + if (bool.Parse(reader["Online"].ToString())) + online++; + else + deleteSessions.Add(new UUID(reader["SessionID"].ToString())); + } + + if (online == 0 && deleteSessions.Count > 0) + deleteSessions.RemoveAt(0); + + reader.Close(); + CloseReaderCommand(cmd); + + foreach (UUID s in deleteSessions) + Delete("SessionID", s.ToString()); + } } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs index a80a355..644d755 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/LocalPresenceServiceConnector.cs @@ -180,6 +180,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence return m_PresenceService.GetAgents(userIDs); } + public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + return m_PresenceService.SetHomeLocation(userID, regionID, position, lookAt); + } + #endregion } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs index e652773..e8e140a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/RemotePresenceServiceConnector.cs @@ -153,6 +153,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence return m_RemoteConnector.GetAgents(userIDs); } + public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + return m_RemoteConnector.SetHomeLocation(userID, regionID, position, lookAt); + } + #endregion } diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs index 580cb15..bb00a00 100644 --- a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs @@ -90,6 +90,8 @@ namespace OpenSim.Server.Handlers.Presence return GetAgent(request); case "getagents": return GetAgents(request); + case "sethome": + return SetHome(request); } m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); } @@ -303,5 +305,32 @@ namespace OpenSim.Server.Handlers.Presence return ms.ToArray(); } + + byte[] SetHome(Dictionary request) + { + UUID region = UUID.Zero; + Vector3 position = new Vector3(128, 128, 70); + Vector3 look = Vector3.Zero; + + if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) + return FailureResult(); + + string user = request["UserID"].ToString(); + + if (!UUID.TryParse(request["RegionID"].ToString(), out region)) + return FailureResult(); + + if (request.ContainsKey("position")) + Vector3.TryParse(request["position"].ToString(), out position); + + if (request.ContainsKey("lookAt")) + Vector3.TryParse(request["lookAt"].ToString(), out look); + + if (m_PresenceService.SetHomeLocation(user, region, position, look)) + return SuccessResult(); + + return FailureResult(); + } + } } diff --git a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs index 4ad457f..482862d 100644 --- a/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs +++ b/OpenSim/Services/Connectors/Presence/PresenceServiceConnector.cs @@ -371,6 +371,52 @@ namespace OpenSim.Services.Connectors } + public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + Dictionary sendData = new Dictionary(); + //sendData["SCOPEID"] = scopeID.ToString(); + sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); + sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); + sendData["METHOD"] = "sethome"; + + sendData["UserID"] = userID; + sendData["RegionID"] = regionID.ToString(); + sendData["position"] = position.ToString(); + sendData["lookAt"] = lookAt.ToString(); + + string reqString = ServerUtils.BuildQueryString(sendData); + // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); + try + { + string reply = SynchronousRestFormsRequester.MakeRequest("POST", + m_ServerURI + "/presence", + reqString); + if (reply != string.Empty) + { + Dictionary replyData = ServerUtils.ParseXmlResponse(reply); + + if (replyData.ContainsKey("Result")) + { + if (replyData["Result"].ToString().ToLower() == "success") + return true; + else + return false; + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); + + } + else + m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); + } + catch (Exception e) + { + m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); + } + + return false; + } + #endregion } diff --git a/OpenSim/Services/Interfaces/IPresenceService.cs b/OpenSim/Services/Interfaces/IPresenceService.cs index de3813a..2582648 100644 --- a/OpenSim/Services/Interfaces/IPresenceService.cs +++ b/OpenSim/Services/Interfaces/IPresenceService.cs @@ -41,6 +41,9 @@ namespace OpenSim.Services.Interfaces public DateTime Logout; public Vector3 Position; public Vector3 LookAt; + public UUID HomeRegionID; + public Vector3 HomePosition; + public Vector3 HomeLookAt; public PresenceInfo() { @@ -87,6 +90,7 @@ namespace OpenSim.Services.Interfaces bool LogoutRegionAgents(UUID regionID); bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); + bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); PresenceInfo GetAgent(UUID sessionID); PresenceInfo[] GetAgents(string[] userIDs); diff --git a/OpenSim/Services/PresenceService/PresenceService.cs b/OpenSim/Services/PresenceService/PresenceService.cs index adbf430..b3d8194 100644 --- a/OpenSim/Services/PresenceService/PresenceService.cs +++ b/OpenSim/Services/PresenceService/PresenceService.cs @@ -54,9 +54,10 @@ namespace OpenSim.Services.PresenceService public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID) { - // We have just logged in. If there is any info in the table - // it's OK to overwrite. So we won't bother reading it first - // + m_Database.Prune(userID); + + PresenceData[] d = m_Database.Get("UserID", userID); + PresenceData data = new PresenceData(); data.UserID = userID; @@ -64,6 +65,12 @@ namespace OpenSim.Services.PresenceService data.SessionID = sessionID; data.Data["SecureSessionID"] = secureSessionID.ToString(); data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); + if (d.Length > 0) + { + data.Data["HomeRegionID"] = d[0].Data["HomeRegionID"]; + data.Data["HomePosition"] = d[0].Data["HomePosition"]; + data.Data["HomeLookAt"] = d[0].Data["HomeLookAt"]; + } m_Database.Store(data); @@ -76,12 +83,20 @@ namespace OpenSim.Services.PresenceService if (data == null) return false; + PresenceData[] d = m_Database.Get("UserID", data.UserID); + + if (d.Length > 1) + { + m_Database.Delete("SessionID", sessionID.ToString()); + return true; + } + data.Data["Online"] = "false"; data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); m_Database.Store(data); - return false; + return true; } public bool LogoutRegionAgents(UUID regionID) @@ -114,6 +129,9 @@ namespace OpenSim.Services.PresenceService ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"])); ret.Position = Vector3.Parse(data.Data["Position"]); ret.LookAt = Vector3.Parse(data.Data["LookAt"]); + ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]); + ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]); + ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]); return ret; } @@ -140,6 +158,9 @@ namespace OpenSim.Services.PresenceService d.Data["Logout"])); ret.Position = Vector3.Parse(d.Data["Position"]); ret.LookAt = Vector3.Parse(d.Data["LookAt"]); + ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]); + ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]); + ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); info.Add(ret); } @@ -147,5 +168,10 @@ namespace OpenSim.Services.PresenceService return info.ToArray(); } + + public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) + { + return m_Database.SetHomeLocation(userID, regionID, position, lookAt); + } } } -- cgit v1.1