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.slimupdates
parent
2ed207509b
commit
e0fc854f05
|
@ -51,6 +51,9 @@ namespace OpenSim.Data
|
||||||
PresenceData Get(UUID sessionID);
|
PresenceData Get(UUID sessionID);
|
||||||
void LogoutRegionAgents(UUID regionID);
|
void LogoutRegionAgents(UUID regionID);
|
||||||
bool ReportAgent(UUID sessionID, UUID regionID, string position, string lookAt);
|
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);
|
PresenceData[] Get(string field, string data);
|
||||||
|
void Prune(string userID);
|
||||||
|
bool Delete(string field, string val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,8 @@ namespace OpenSim.Data.MySQL
|
||||||
result.Add(row);
|
result.Add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reader.Close();
|
||||||
|
|
||||||
CloseReaderCommand(cmd);
|
CloseReaderCommand(cmd);
|
||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
|
|
|
@ -93,5 +93,57 @@ namespace OpenSim.Data.MySQL
|
||||||
|
|
||||||
return true;
|
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<UUID> deleteSessions = new List<UUID>();
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
|
||||||
return m_PresenceService.GetAgents(userIDs);
|
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
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
|
||||||
return m_RemoteConnector.GetAgents(userIDs);
|
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
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,8 @@ namespace OpenSim.Server.Handlers.Presence
|
||||||
return GetAgent(request);
|
return GetAgent(request);
|
||||||
case "getagents":
|
case "getagents":
|
||||||
return GetAgents(request);
|
return GetAgents(request);
|
||||||
|
case "sethome":
|
||||||
|
return SetHome(request);
|
||||||
}
|
}
|
||||||
m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
|
m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
|
||||||
}
|
}
|
||||||
|
@ -303,5 +305,32 @@ namespace OpenSim.Server.Handlers.Presence
|
||||||
|
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
byte[] SetHome(Dictionary<string, object> 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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,6 +371,52 @@ namespace OpenSim.Services.Connectors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> sendData = new Dictionary<string, object>();
|
||||||
|
//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<string, object> 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
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ namespace OpenSim.Services.Interfaces
|
||||||
public DateTime Logout;
|
public DateTime Logout;
|
||||||
public Vector3 Position;
|
public Vector3 Position;
|
||||||
public Vector3 LookAt;
|
public Vector3 LookAt;
|
||||||
|
public UUID HomeRegionID;
|
||||||
|
public Vector3 HomePosition;
|
||||||
|
public Vector3 HomeLookAt;
|
||||||
|
|
||||||
public PresenceInfo()
|
public PresenceInfo()
|
||||||
{
|
{
|
||||||
|
@ -87,6 +90,7 @@ namespace OpenSim.Services.Interfaces
|
||||||
bool LogoutRegionAgents(UUID regionID);
|
bool LogoutRegionAgents(UUID regionID);
|
||||||
|
|
||||||
bool ReportAgent(UUID sessionID, UUID regionID, Vector3 position, Vector3 lookAt);
|
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 GetAgent(UUID sessionID);
|
||||||
PresenceInfo[] GetAgents(string[] userIDs);
|
PresenceInfo[] GetAgents(string[] userIDs);
|
||||||
|
|
|
@ -54,9 +54,10 @@ namespace OpenSim.Services.PresenceService
|
||||||
public bool LoginAgent(string userID, UUID sessionID,
|
public bool LoginAgent(string userID, UUID sessionID,
|
||||||
UUID secureSessionID)
|
UUID secureSessionID)
|
||||||
{
|
{
|
||||||
// We have just logged in. If there is any info in the table
|
m_Database.Prune(userID);
|
||||||
// it's OK to overwrite. So we won't bother reading it first
|
|
||||||
//
|
PresenceData[] d = m_Database.Get("UserID", userID);
|
||||||
|
|
||||||
PresenceData data = new PresenceData();
|
PresenceData data = new PresenceData();
|
||||||
|
|
||||||
data.UserID = userID;
|
data.UserID = userID;
|
||||||
|
@ -64,6 +65,12 @@ namespace OpenSim.Services.PresenceService
|
||||||
data.SessionID = sessionID;
|
data.SessionID = sessionID;
|
||||||
data.Data["SecureSessionID"] = secureSessionID.ToString();
|
data.Data["SecureSessionID"] = secureSessionID.ToString();
|
||||||
data.Data["Login"] = Util.UnixTimeSinceEpoch().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);
|
m_Database.Store(data);
|
||||||
|
|
||||||
|
@ -76,12 +83,20 @@ namespace OpenSim.Services.PresenceService
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return false;
|
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["Online"] = "false";
|
||||||
data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
|
data.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString();
|
||||||
|
|
||||||
m_Database.Store(data);
|
m_Database.Store(data);
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LogoutRegionAgents(UUID regionID)
|
public bool LogoutRegionAgents(UUID regionID)
|
||||||
|
@ -114,6 +129,9 @@ namespace OpenSim.Services.PresenceService
|
||||||
ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"]));
|
ret.Logout = Util.ToDateTime(Convert.ToInt32(data.Data["Logout"]));
|
||||||
ret.Position = Vector3.Parse(data.Data["Position"]);
|
ret.Position = Vector3.Parse(data.Data["Position"]);
|
||||||
ret.LookAt = Vector3.Parse(data.Data["LookAt"]);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -140,6 +158,9 @@ namespace OpenSim.Services.PresenceService
|
||||||
d.Data["Logout"]));
|
d.Data["Logout"]));
|
||||||
ret.Position = Vector3.Parse(d.Data["Position"]);
|
ret.Position = Vector3.Parse(d.Data["Position"]);
|
||||||
ret.LookAt = Vector3.Parse(d.Data["LookAt"]);
|
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);
|
info.Add(ret);
|
||||||
}
|
}
|
||||||
|
@ -147,5 +168,10 @@ namespace OpenSim.Services.PresenceService
|
||||||
|
|
||||||
return info.ToArray();
|
return info.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
|
||||||
|
{
|
||||||
|
return m_Database.SetHomeLocation(userID, regionID, position, lookAt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue