From febe78d06249cd4d36a86e97610dd45ab518a757 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 31 May 2008 12:18:29 +0000 Subject: * Implements UserServer logoff in a few situations * User tries to log-in but is already logged in. Userserver will send message to simulator user was in to log the user out there. * From the UserServer, admin types 'logoff-user firstname lastname message'. * Some regions may not get the message because they're not updated yet. --- OpenSim/Grid/UserServer/Main.cs | 63 +++++++++++++++++++++++++++++ OpenSim/Grid/UserServer/UserLoginService.cs | 59 +++++++++++++++++++++++++++ OpenSim/Grid/UserServer/UserManager.cs | 48 ++++++++++++++++++++++ 3 files changed, 170 insertions(+) (limited to 'OpenSim/Grid/UserServer') diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 810c24e..9d7421c 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -129,6 +129,7 @@ namespace OpenSim.Grid.UserServer m_httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); m_httpServer.AddXmlRPCHandler("get_avatar_appearance", m_userManager.XmlRPCGetAvatarAppearance); m_httpServer.AddXmlRPCHandler("update_avatar_appearance", m_userManager.XmlRPCUpdateAvatarAppearance); + m_httpServer.AddXmlRPCHandler("update_user_current_region", m_userManager.XmlRPCAtRegion); m_httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID); // Message Server ---> User Server @@ -221,6 +222,7 @@ namespace OpenSim.Grid.UserServer { case "help": m_console.Notice("create user - create a new user"); + m_console.Notice("logoff-user - logs off the specified user from the grid"); break; case "create": @@ -238,6 +240,67 @@ namespace OpenSim.Grid.UserServer "RootFolders/", m_lastCreatedUser); break; + case "logoff-user": + + if (cmdparams.Length >= 3) + { + string firstname = cmdparams[0]; + string lastname = cmdparams[1]; + string message = ""; + + for (int i = 2; i < cmdparams.Length; i++) + message += " " + cmdparams[i]; + + UserProfileData theUser = null; + try + { + theUser = m_loginService.GetTheUser(firstname, lastname); + } + catch (Exception) + { + m_log.Error("[LOGOFF]: Error getting user data from the database."); + } + + if (theUser != null) + { + if (theUser.CurrentAgent != null) + { + if (theUser.CurrentAgent.AgentOnline) + { + m_log.Info("[LOGOFF]: Logging off requested user!"); + m_loginService.LogOffUser(theUser, message); + + theUser.CurrentAgent.AgentOnline = false; + + m_loginService.CommitAgent(ref theUser); + } + else + { + m_log.Info("[LOGOFF]: User Doesn't appear to be online, sending the logoff message anyway."); + m_loginService.LogOffUser(theUser, message); + + theUser.CurrentAgent.AgentOnline = false; + + m_loginService.CommitAgent(ref theUser); + } + } + else + { + m_log.Error("[LOGOFF]: Unable to logoff-user. User doesn't have an agent record so I can't find the simulator to notify"); + } + + } + else + { + m_log.Info("[LOGOFF]: User doesn't exist in the database"); + } + } + else + { + m_log.Error("[LOGOFF]: Invalid amount of parameters. logoff-user takes at least three. Firstname, Lastname, and message"); + } + + break; } } diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 628c471..d538d36 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -60,6 +60,65 @@ namespace OpenSim.Grid.UserServer { m_config = config; } + public override void LogOffUser(UserProfileData theUser, string message) + { + RegionProfileData SimInfo = null; + try + { + SimInfo = RegionProfileData.RequestSimProfileData( + theUser.CurrentAgent.Handle, m_config.GridServerURL, + m_config.GridSendKey, m_config.GridRecvKey); + if (SimInfo == null) + { + m_log.Error("[GRID]: Region user was in isn't currently logged in"); + return; + } + + } + catch (Exception) + { + m_log.Error("[GRID]: Unable to look up region to log user off"); + return; + } + // Prepare notification + Hashtable SimParams = new Hashtable(); + SimParams["agent_id"] = theUser.ID.ToString(); + SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); + //SimParams["region_secret"] = SimInfo.regionSecret; + //m_log.Info(SimInfo.regionSecret); + SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); + SimParams["message"] = message; + ArrayList SendParams = new ArrayList(); + SendParams.Add(SimParams); + + // Update agent with target sim + + m_log.InfoFormat( + "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", + SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, theUser.FirstName + " " + theUser.SurName); + try + { + XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); + XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + + if (GridResp.IsFault) + { + m_log.ErrorFormat( + "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", + SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); + } + } + catch (Exception) + { + m_log.Error("[LOGIN]: Error telling region to logout user!"); + } + + //base.LogOffUser(theUser); + } + //public override void LogOffUser(UserProfileData theUser) + //{ + + //} /// /// Customises the login response and fills in missing values. diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index a82505d..1b47289 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -179,6 +179,54 @@ namespace OpenSim.Grid.UserServer return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar); } + public XmlRpcResponse XmlRPCAtRegion(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable responseData = new Hashtable(); + string returnstring = "FALSE"; + + if (requestData.Contains("avatar_id") && requestData.Contains("region_handle") && requestData.Contains("region_uuid")) + { + ulong cregionhandle = 0; + LLUUID regionUUID = LLUUID.Zero; + LLUUID AvatarID = LLUUID.Zero; + + Helpers.TryParse((string)requestData["avatar_id"], out AvatarID); + 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) + { + UserProfileData userProfile = GetUserProfile(new LLUUID((string)requestData["avatar_id"])); + userProfile.CurrentAgent.Region = new LLUUID((string)requestData["region_uuid"]); + userProfile.CurrentAgent.Handle = (ulong)Convert.ToInt64((string)requestData["region_handle"]); + //userProfile.CurrentAgent. + CommitAgent(ref userProfile); + //setUserProfile(userProfile); + + + returnstring = "TRUE"; + } + + } + responseData.Add("returnString", returnstring); + response.Value = responseData; + return response; + } + public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request) { XmlRpcResponse response = new XmlRpcResponse(); -- cgit v1.1