diff options
author | Melanie | 2009-12-28 23:42:08 +0000 |
---|---|---|
committer | Melanie | 2009-12-28 23:42:08 +0000 |
commit | e0fc854f05b137c353196356e5b26d11b6ee6867 (patch) | |
tree | 9a1c0a29178a9f3e10b10f5e184f46bce1c61078 /OpenSim | |
parent | Add the second step of the friends migration to pull data from the old table ... (diff) | |
download | opensim-SC_OLD-e0fc854f05b137c353196356e5b26d11b6ee6867.zip opensim-SC_OLD-e0fc854f05b137c353196356e5b26d11b6ee6867.tar.gz opensim-SC_OLD-e0fc854f05b137c353196356e5b26d11b6ee6867.tar.bz2 opensim-SC_OLD-e0fc854f05b137c353196356e5b26d11b6ee6867.tar.xz |
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.
Diffstat (limited to 'OpenSim')
9 files changed, 176 insertions, 4 deletions
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 | |||
51 | PresenceData Get(UUID sessionID); | 51 | PresenceData Get(UUID sessionID); |
52 | void LogoutRegionAgents(UUID regionID); | 52 | void LogoutRegionAgents(UUID regionID); |
53 | bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt); | 53 | bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt); |
54 | bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); | ||
54 | PresenceData[] Get(string field, string data); | 55 | PresenceData[] Get(string field, string data); |
56 | void Prune(string userID); | ||
57 | bool Delete(string field, string val); | ||
55 | } | 58 | } |
56 | } | 59 | } |
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 | |||
177 | result.Add(row); | 177 | result.Add(row); |
178 | } | 178 | } |
179 | 179 | ||
180 | reader.Close(); | ||
181 | |||
180 | CloseReaderCommand(cmd); | 182 | CloseReaderCommand(cmd); |
181 | 183 | ||
182 | return result.ToArray(); | 184 | 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 | |||
93 | 93 | ||
94 | return true; | 94 | return true; |
95 | } | 95 | } |
96 | |||
97 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
98 | { | ||
99 | PresenceData[] pd = Get("UserID", userID); | ||
100 | if (pd.Length == 0) | ||
101 | return false; | ||
102 | |||
103 | MySqlCommand cmd = new MySqlCommand(); | ||
104 | |||
105 | cmd.CommandText = String.Format("update {0} set HomeRegionID=?HomeRegionID, HomePosition=?HomePosition, HomeLookAt=?HomeLookAt where UserID=?UserID", m_Realm); | ||
106 | |||
107 | cmd.Parameters.AddWithValue("?UserID", userID); | ||
108 | cmd.Parameters.AddWithValue("?HomeRegionID", regionID.ToString()); | ||
109 | cmd.Parameters.AddWithValue("?HomePosition", position); | ||
110 | cmd.Parameters.AddWithValue("?HomeLookAt", lookAt); | ||
111 | |||
112 | if (ExecuteNonQuery(cmd) == 0) | ||
113 | return false; | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | |||
118 | public void Prune(string userID) | ||
119 | { | ||
120 | MySqlCommand cmd = new MySqlCommand(); | ||
121 | |||
122 | cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm); | ||
123 | |||
124 | cmd.Parameters.AddWithValue("?UserID", userID); | ||
125 | |||
126 | IDataReader reader = ExecuteReader(cmd); | ||
127 | |||
128 | List<UUID> deleteSessions = new List<UUID>(); | ||
129 | int online = 0; | ||
130 | |||
131 | while(reader.Read()) | ||
132 | { | ||
133 | if (bool.Parse(reader["Online"].ToString())) | ||
134 | online++; | ||
135 | else | ||
136 | deleteSessions.Add(new UUID(reader["SessionID"].ToString())); | ||
137 | } | ||
138 | |||
139 | if (online == 0 && deleteSessions.Count > 0) | ||
140 | deleteSessions.RemoveAt(0); | ||
141 | |||
142 | reader.Close(); | ||
143 | CloseReaderCommand(cmd); | ||
144 | |||
145 | foreach (UUID s in deleteSessions) | ||
146 | Delete("SessionID", s.ToString()); | ||
147 | } | ||
96 | } | 148 | } |
97 | } | 149 | } |
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 | |||
180 | return m_PresenceService.GetAgents(userIDs); | 180 | return m_PresenceService.GetAgents(userIDs); |
181 | } | 181 | } |
182 | 182 | ||
183 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
184 | { | ||
185 | return m_PresenceService.SetHomeLocation(userID, regionID, position, lookAt); | ||
186 | } | ||
187 | |||
183 | #endregion | 188 | #endregion |
184 | 189 | ||
185 | } | 190 | } |
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 | |||
153 | return m_RemoteConnector.GetAgents(userIDs); | 153 | return m_RemoteConnector.GetAgents(userIDs); |
154 | } | 154 | } |
155 | 155 | ||
156 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
157 | { | ||
158 | return m_RemoteConnector.SetHomeLocation(userID, regionID, position, lookAt); | ||
159 | } | ||
160 | |||
156 | #endregion | 161 | #endregion |
157 | 162 | ||
158 | } | 163 | } |
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 | |||
90 | return GetAgent(request); | 90 | return GetAgent(request); |
91 | case "getagents": | 91 | case "getagents": |
92 | return GetAgents(request); | 92 | return GetAgents(request); |
93 | case "sethome": | ||
94 | return SetHome(request); | ||
93 | } | 95 | } |
94 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); | 96 | m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method); |
95 | } | 97 | } |
@@ -303,5 +305,32 @@ namespace OpenSim.Server.Handlers.Presence | |||
303 | 305 | ||
304 | return ms.ToArray(); | 306 | return ms.ToArray(); |
305 | } | 307 | } |
308 | |||
309 | byte[] SetHome(Dictionary<string, object> request) | ||
310 | { | ||
311 | UUID region = UUID.Zero; | ||
312 | Vector3 position = new Vector3(128, 128, 70); | ||
313 | Vector3 look = Vector3.Zero; | ||
314 | |||
315 | if (!request.ContainsKey("SessionID") || !request.ContainsKey("RegionID")) | ||
316 | return FailureResult(); | ||
317 | |||
318 | string user = request["UserID"].ToString(); | ||
319 | |||
320 | if (!UUID.TryParse(request["RegionID"].ToString(), out region)) | ||
321 | return FailureResult(); | ||
322 | |||
323 | if (request.ContainsKey("position")) | ||
324 | Vector3.TryParse(request["position"].ToString(), out position); | ||
325 | |||
326 | if (request.ContainsKey("lookAt")) | ||
327 | Vector3.TryParse(request["lookAt"].ToString(), out look); | ||
328 | |||
329 | if (m_PresenceService.SetHomeLocation(user, region, position, look)) | ||
330 | return SuccessResult(); | ||
331 | |||
332 | return FailureResult(); | ||
333 | } | ||
334 | |||
306 | } | 335 | } |
307 | } | 336 | } |
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 | |||
371 | } | 371 | } |
372 | 372 | ||
373 | 373 | ||
374 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
375 | { | ||
376 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
377 | //sendData["SCOPEID"] = scopeID.ToString(); | ||
378 | sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); | ||
379 | sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); | ||
380 | sendData["METHOD"] = "sethome"; | ||
381 | |||
382 | sendData["UserID"] = userID; | ||
383 | sendData["RegionID"] = regionID.ToString(); | ||
384 | sendData["position"] = position.ToString(); | ||
385 | sendData["lookAt"] = lookAt.ToString(); | ||
386 | |||
387 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
388 | // m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); | ||
389 | try | ||
390 | { | ||
391 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
392 | m_ServerURI + "/presence", | ||
393 | reqString); | ||
394 | if (reply != string.Empty) | ||
395 | { | ||
396 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
397 | |||
398 | if (replyData.ContainsKey("Result")) | ||
399 | { | ||
400 | if (replyData["Result"].ToString().ToLower() == "success") | ||
401 | return true; | ||
402 | else | ||
403 | return false; | ||
404 | } | ||
405 | else | ||
406 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation reply data does not contain result field"); | ||
407 | |||
408 | } | ||
409 | else | ||
410 | m_log.DebugFormat("[PRESENCE CONNECTOR]: SetHomeLocation received empty reply"); | ||
411 | } | ||
412 | catch (Exception e) | ||
413 | { | ||
414 | m_log.DebugFormat("[PRESENCE CONNECTOR]: Exception when contacting presence server: {0}", e.Message); | ||
415 | } | ||
416 | |||
417 | return false; | ||
418 | } | ||
419 | |||
374 | #endregion | 420 | #endregion |
375 | 421 | ||
376 | } | 422 | } |
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 | |||
41 | public DateTime Logout; | 41 | public DateTime Logout; |
42 | public Vector3 Position; | 42 | public Vector3 Position; |
43 | public Vector3 LookAt; | 43 | public Vector3 LookAt; |
44 | public UUID HomeRegionID; | ||
45 | public Vector3 HomePosition; | ||
46 | public Vector3 HomeLookAt; | ||
44 | 47 | ||
45 | public PresenceInfo() | 48 | public PresenceInfo() |
46 | { | 49 | { |
@@ -87,6 +90,7 @@ namespace OpenSim.Services.Interfaces | |||
87 | bool LogoutRegionAgents(UUID regionID); | 90 | bool LogoutRegionAgents(UUID regionID); |
88 | 91 | ||
89 | bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); | 92 | bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt); |
93 | bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt); | ||
90 | 94 | ||
91 | PresenceInfo GetAgent(UUID sessionID); | 95 | PresenceInfo GetAgent(UUID sessionID); |
92 | PresenceInfo[] GetAgents(string[] userIDs); | 96 | 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 | |||
54 | public bool LoginAgent(string userID, UUID sessionID, | 54 | public bool LoginAgent(string userID, UUID sessionID, |
55 | UUID secureSessionID) | 55 | UUID secureSessionID) |
56 | { | 56 | { |
57 | // We have just logged in. If there is any info in the table | 57 | m_Database.Prune(userID); |
58 | // it's OK to overwrite. So we won't bother reading it first | 58 | |
59 | // | 59 | PresenceData[] d = m_Database.Get("UserID", userID); |
60 | |||
60 | PresenceData data = new PresenceData(); | 61 | PresenceData data = new PresenceData(); |
61 | 62 | ||
62 | data.UserID = userID; | 63 | data.UserID = userID; |
@@ -64,6 +65,12 @@ namespace OpenSim.Services.PresenceService | |||
64 | data.SessionID = sessionID; | 65 | data.SessionID = sessionID; |
65 | data.Data["SecureSessionID"] = secureSessionID.ToString(); | 66 | data.Data["SecureSessionID"] = secureSessionID.ToString(); |
66 | data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); | 67 | data.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); |
68 | if (d.Length > 0) | ||
69 | { | ||
70 | data.Data["HomeRegionID"] = d[0].Data["HomeRegionID"]; | ||
71 | data.Data["HomePosition"] = d[0].Data["HomePosition"]; | ||
72 | data.Data["HomeLookAt"] = d[0].Data["HomeLookAt"]; | ||
73 | } | ||
67 | 74 | ||
68 | m_Database.Store(data); | 75 | m_Database.Store(data); |
69 | 76 | ||
@@ -76,12 +83,20 @@ namespace OpenSim.Services.PresenceService | |||
76 | if (data == null) | 83 | if (data == null) |
77 | return false; | 84 | return false; |
78 | 85 | ||
86 | PresenceData[] d = m_Database.Get("UserID", data.UserID); | ||
87 | |||
88 | if (d.Length > 1) | ||
89 | { | ||
90 | m_Database.Delete("SessionID", sessionID.ToString()); | ||
91 | return true; | ||
92 | } | ||
93 | |||
79 | data.Data["Online"] = "false"; | 94 | data.Data["Online"] = "false"; |
80 | data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); | 95 | data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); |
81 | 96 | ||
82 | m_Database.Store(data); | 97 | m_Database.Store(data); |
83 | 98 | ||
84 | return false; | 99 | return true; |
85 | } | 100 | } |
86 | 101 | ||
87 | public bool LogoutRegionAgents(UUID regionID) | 102 | public bool LogoutRegionAgents(UUID regionID) |
@@ -114,6 +129,9 @@ namespace OpenSim.Services.PresenceService | |||
114 | ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"])); | 129 | ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"])); |
115 | ret.Position = Vector3.Parse(data.Data["Position"]); | 130 | ret.Position = Vector3.Parse(data.Data["Position"]); |
116 | ret.LookAt = Vector3.Parse(data.Data["LookAt"]); | 131 | ret.LookAt = Vector3.Parse(data.Data["LookAt"]); |
132 | ret.HomeRegionID = new UUID(data.Data["HomeRegionID"]); | ||
133 | ret.HomePosition = Vector3.Parse(data.Data["HomePosition"]); | ||
134 | ret.HomeLookAt = Vector3.Parse(data.Data["HomeLookAt"]); | ||
117 | 135 | ||
118 | return ret; | 136 | return ret; |
119 | } | 137 | } |
@@ -140,6 +158,9 @@ namespace OpenSim.Services.PresenceService | |||
140 | d.Data["Logout"])); | 158 | d.Data["Logout"])); |
141 | ret.Position = Vector3.Parse(d.Data["Position"]); | 159 | ret.Position = Vector3.Parse(d.Data["Position"]); |
142 | ret.LookAt = Vector3.Parse(d.Data["LookAt"]); | 160 | ret.LookAt = Vector3.Parse(d.Data["LookAt"]); |
161 | ret.HomeRegionID = new UUID(d.Data["HomeRegionID"]); | ||
162 | ret.HomePosition = Vector3.Parse(d.Data["HomePosition"]); | ||
163 | ret.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); | ||
143 | 164 | ||
144 | info.Add(ret); | 165 | info.Add(ret); |
145 | } | 166 | } |
@@ -147,5 +168,10 @@ namespace OpenSim.Services.PresenceService | |||
147 | 168 | ||
148 | return info.ToArray(); | 169 | return info.ToArray(); |
149 | } | 170 | } |
171 | |||
172 | public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt) | ||
173 | { | ||
174 | return m_Database.SetHomeLocation(userID, regionID, position, lookAt); | ||
175 | } | ||
150 | } | 176 | } |
151 | } | 177 | } |