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 ++++- OpenSim/Grid/UserServer/UserManager.cs | 25 ++++---------- 3 files changed, 73 insertions(+), 21 deletions(-) (limited to 'OpenSim') 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()); + } } /// diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index d4fb187..b48f20e 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -190,28 +190,15 @@ namespace OpenSim.Grid.UserServer { // ulong cregionhandle = 0; LLUUID regionUUID = LLUUID.Zero; - LLUUID AvatarID = LLUUID.Zero; + LLUUID avatarUUID = LLUUID.Zero; - Helpers.TryParse((string)requestData["avatar_id"], out AvatarID); + Helpers.TryParse((string)requestData["avatar_id"], out avatarUUID); Helpers.TryParse((string)requestData["region_uuid"], out regionUUID); - // try - // { - // cregionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]); - // } - // catch (ArgumentException) - // { - // } - // catch (OverflowException) - // { - // } - // catch (FormatException) - // { - // } - - if (AvatarID != LLUUID.Zero) + + if (avatarUUID != LLUUID.Zero) { - UserProfileData userProfile = GetUserProfile(new LLUUID((string)requestData["avatar_id"])); - userProfile.CurrentAgent.Region = new LLUUID((string)requestData["region_uuid"]); + UserProfileData userProfile = GetUserProfile(avatarUUID); + userProfile.CurrentAgent.Region = regionUUID; userProfile.CurrentAgent.Handle = (ulong)Convert.ToInt64((string)requestData["region_handle"]); //userProfile.CurrentAgent. CommitAgent(ref userProfile); -- cgit v1.1