From 681433c4b75b30ddd5299b23a56fb706f1edb7ae Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Sun, 20 Jul 2008 22:16:50 +0000 Subject: Mantis#1796. Thank you kindly, StrawberryFride for a patch that: Agent table code (INSERT / UPDATE, etc) now added to MSSQL provider. --- OpenSim/Data/MSSQL/MSSQLManager.cs | 60 ++++++++++++++++++++++++++++++++++++- OpenSim/Data/MSSQL/MSSQLUserData.cs | 9 +++++- 2 files changed, 67 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MSSQL/MSSQLManager.cs b/OpenSim/Data/MSSQL/MSSQLManager.cs index fe4ca77..9cd9eca 100644 --- a/OpenSim/Data/MSSQL/MSSQLManager.cs +++ b/OpenSim/Data/MSSQL/MSSQLManager.cs @@ -354,7 +354,7 @@ namespace OpenSim.Data.MSSQL // Agent Who? retval.AgentIP = (string)reader["agentIP"]; retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString()); - retval.AgentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); + retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0; // Login/Logout times (UNIX Epoch) retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString()); @@ -528,5 +528,63 @@ namespace OpenSim.Data.MSSQL string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision); } + + public bool insertAgentRow(UserAgentData agentdata) + { + string sql = @" + +IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID) + BEGIN + UPDATE agents SET UUID = @UUID, sessionID = @sessionID, secureSessionID = @secureSessionID, agentIP = @agentIP, agentPort = @agentPort, agentOnline = @agentOnline, loginTime = @loginTime, logoutTime = @logoutTime, currentRegion = @currentRegion, currentHandle = @currentHandle, currentPos = @currentPos + WHERE UUID = @UUID + END +ELSE + BEGIN + INSERT INTO + agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES + (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos) + END +"; + + Dictionary parameters = new Dictionary(); + + parameters["@UUID"] = agentdata.ProfileID.ToString(); + parameters["@sessionID"] = agentdata.SessionID.ToString(); + parameters["@secureSessionID"] = agentdata.SecureSessionID.ToString(); + parameters["@agentIP"] = agentdata.AgentIP.ToString(); + parameters["@agentPort"] = agentdata.AgentPort.ToString(); + parameters["@agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0"; + parameters["@loginTime"] = agentdata.LoginTime.ToString(); + parameters["@logoutTime"] = agentdata.LogoutTime.ToString(); + parameters["@currentRegion"] = agentdata.Region.ToString(); + parameters["@currentHandle"] = agentdata.Handle.ToString(); + parameters["@currentPos"] = "<" + ((int)agentdata.Position.X).ToString() + "," + ((int)agentdata.Position.Y).ToString() + "," + ((int)agentdata.Position.Z).ToString() + ">"; + + + using (IDbCommand result = Query(sql, parameters)) + { + result.Transaction = result.Connection.BeginTransaction(IsolationLevel.Serializable); + try + { + if (result.ExecuteNonQuery() > 0) + { + result.Transaction.Commit(); + return true; + } + else + { + result.Transaction.Rollback(); + return false; + } + } + catch (Exception e) + { + result.Transaction.Rollback(); + m_log.Error(e.ToString()); + return false; + } + } + + } } } diff --git a/OpenSim/Data/MSSQL/MSSQLUserData.cs b/OpenSim/Data/MSSQL/MSSQLUserData.cs index 20c3acd..0593c62 100644 --- a/OpenSim/Data/MSSQL/MSSQLUserData.cs +++ b/OpenSim/Data/MSSQL/MSSQLUserData.cs @@ -610,7 +610,14 @@ namespace OpenSim.Data.MSSQL /// The agent to create override public void AddNewUserAgent(UserAgentData agent) { - // Do nothing. + try + { + database.insertAgentRow(agent); + } + catch (Exception e) + { + m_log.Error(e.ToString()); + } } /// -- cgit v1.1