From cbd02218704287640ba5c7b564440a6590e038cf Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 23 Nov 2008 05:16:07 +0000 Subject: Plumb in the presence notifications and region shutdown/restart messages from the presence module to the message server, through the user server and on into the database. This should fix the "Already logged in" issue that grids see after a sim crashes, or a user crashes out of a sim. Not yet a 100% solution for friends, but getting there. --- OpenSim/Grid/MessagingServer/Main.cs | 4 + OpenSim/Grid/MessagingServer/MessageService.cs | 77 ++++++++++++++++-- OpenSim/Grid/UserServer/Main.cs | 29 +++++++ OpenSim/Grid/UserServer/MessageServersConnector.cs | 93 +++++++++++++++++++++- OpenSim/Grid/UserServer/UserManager.cs | 47 +++++++++++ 5 files changed, 242 insertions(+), 8 deletions(-) (limited to 'OpenSim/Grid') diff --git a/OpenSim/Grid/MessagingServer/Main.cs b/OpenSim/Grid/MessagingServer/Main.cs index 8472571..5568f73 100644 --- a/OpenSim/Grid/MessagingServer/Main.cs +++ b/OpenSim/Grid/MessagingServer/Main.cs @@ -88,6 +88,10 @@ namespace OpenSim.Grid.MessagingServer m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn); m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff); m_httpServer.AddXmlRPCHandler("get_presence_info_bulk", msgsvc.GetPresenceInfoBulk); + m_httpServer.AddXmlRPCHandler("region_startup", msgsvc.RegionStartup); + m_httpServer.AddXmlRPCHandler("region_shutdown", msgsvc.RegionShutdown); + m_httpServer.AddXmlRPCHandler("agent_location", msgsvc.AgentLocation); + m_httpServer.AddXmlRPCHandler("agent_leaving", msgsvc.AgentLeaving); m_httpServer.Start(); m_log.Info("[SERVER]: Userserver registration was successful"); diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs index 66916b6..a4e54c7 100644 --- a/OpenSim/Grid/MessagingServer/MessageService.cs +++ b/OpenSim/Grid/MessagingServer/MessageService.cs @@ -558,24 +558,30 @@ namespace OpenSim.Grid.MessagingServer public bool deregisterWithUserServer() { - Hashtable UserParams = new Hashtable(); + Hashtable request = new Hashtable(); + + return SendToUserServer(request, "deregister_messageserver"); + } + + public bool SendToUserServer(Hashtable request, string method) + { // Login / Authentication if (m_cfg.HttpSSL) { - UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; + request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; } else { - UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; + request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; } - UserParams["recvkey"] = m_cfg.UserRecvKey; - UserParams["sendkey"] = m_cfg.UserRecvKey; + request["recvkey"] = m_cfg.UserRecvKey; + request["sendkey"] = m_cfg.UserRecvKey; // Package into an XMLRPC Request ArrayList SendParams = new ArrayList(); - SendParams.Add(UserParams); + SendParams.Add(request); bool success = true; string[] servers = m_cfg.UserServerURL.Split(' '); @@ -585,7 +591,7 @@ namespace OpenSim.Grid.MessagingServer { try { - XmlRpcRequest UserReq = new XmlRpcRequest("deregister_messageserver", SendParams); + XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams); XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000); // Process Response Hashtable UserRespData = (Hashtable)UserResp.Value; @@ -603,5 +609,62 @@ namespace OpenSim.Grid.MessagingServer } #endregion + + public XmlRpcResponse RegionStartup(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + result["success"] = "FALSE"; + + if(SendToUserServer(requestData, "region_startup")) + result["success"] = "TRUE"; + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse RegionShutdown(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + result["success"] = "FALSE"; + + if(SendToUserServer(requestData, "region_shutdown")) + result["success"] = "TRUE"; + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse AgentLocation(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + result["success"] = "FALSE"; + + if(SendToUserServer(requestData, "agent_location")) + result["success"] = "TRUE"; + + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse AgentLeaving(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + result["success"] = "FALSE"; + + if(SendToUserServer(requestData, "agent_leaving")) + result["success"] = "TRUE"; + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } } } diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index eb47259..f894ca0 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -110,6 +110,11 @@ namespace OpenSim.Grid.UserServer m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation; m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff; + m_messagesService.OnAgentLocation += HandleAgentLocation; + m_messagesService.OnAgentLeaving += HandleAgentLeaving; + m_messagesService.OnRegionStartup += HandleRegionStartup; + m_messagesService.OnRegionShutdown += HandleRegionShutdown; + m_log.Info("[REGION]: Starting HTTP process"); m_httpServer = new BaseHttpServer(Cfg.HttpPort); @@ -147,6 +152,10 @@ namespace OpenSim.Grid.UserServer m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", m_userManager.XmlRPCGetAgentMethodUUID); m_httpServer.AddXmlRPCHandler("check_auth_session", m_userManager.XmlRPCCheckAuthSession); m_httpServer.AddXmlRPCHandler("set_login_params", m_loginService.XmlRPCSetLoginParams); + m_httpServer.AddXmlRPCHandler("region_startup", m_messagesService.RegionStartup); + m_httpServer.AddXmlRPCHandler("region_shutdown", m_messagesService.RegionShutdown); + m_httpServer.AddXmlRPCHandler("agent_location", m_messagesService.AgentLocation); + m_httpServer.AddXmlRPCHandler("agent_leaving", m_messagesService.AgentLeaving); // Message Server ---> User Server m_httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer); m_httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion); @@ -442,5 +451,25 @@ namespace OpenSim.Grid.UserServer m_messagesService.TellMessageServersAboutUser(agentID, sessionID, RegionID, regionhandle, positionX, positionY, positionZ, firstname, lastname); } + + public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle) + { + m_userManager.HandleAgentLocation(agentID, regionID, regionHandle); + } + + public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle) + { + m_userManager.HandleAgentLeaving(agentID, regionID, regionHandle); + } + + public void HandleRegionStartup(UUID regionID) + { + m_userManager.HandleRegionStartup(regionID); + } + + public void HandleRegionShutdown(UUID regionID) + { + m_userManager.HandleRegionShutdown(regionID); + } } } diff --git a/OpenSim/Grid/UserServer/MessageServersConnector.cs b/OpenSim/Grid/UserServer/MessageServersConnector.cs index 61f125e..6659617 100644 --- a/OpenSim/Grid/UserServer/MessageServersConnector.cs +++ b/OpenSim/Grid/UserServer/MessageServersConnector.cs @@ -57,7 +57,13 @@ namespace OpenSim.Grid.UserServer public float positionZ; public string firstname; public string lastname; - }; + } + + public delegate void AgentLocationDelegate(UUID agentID, UUID regionID, ulong regionHandle); + public delegate void AgentLeavingDelegate(UUID agentID, UUID regionID, ulong regionHandle); + public delegate void RegionStartupDelegate(UUID regionID); + public delegate void RegionShutdownDelegate(UUID regionID); + public class MessageServersConnector { @@ -70,6 +76,11 @@ namespace OpenSim.Grid.UserServer Thread m_NotifyThread; + public event AgentLocationDelegate OnAgentLocation; + public event AgentLeavingDelegate OnAgentLeaving; + public event RegionStartupDelegate OnRegionStartup; + public event RegionShutdownDelegate OnRegionShutdown; + public MessageServersConnector() { MessageServers = new Dictionary(); @@ -337,5 +348,85 @@ namespace OpenSim.Grid.UserServer } } } + + public XmlRpcResponse RegionStartup(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + + UUID regionID; + if (UUID.TryParse((string)requestData["RegionUUID"], out regionID)) + { + if (OnRegionStartup != null) + OnRegionStartup(regionID); + + result["responsestring"] = "TRUE"; + } + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse RegionShutdown(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + + UUID regionID; + if (UUID.TryParse((string)requestData["RegionUUID"], out regionID)) + { + if (OnRegionShutdown != null) + OnRegionShutdown(regionID); + + result["responsestring"] = "TRUE"; + } + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse AgentLocation(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + + UUID agentID; + UUID regionID; + ulong regionHandle; + if (UUID.TryParse((string)requestData["AgentID"], out agentID) && UUID.TryParse((string)requestData["RegionUUID"], out regionID) && ulong.TryParse((string)requestData["RegionHandle"], out regionHandle)) + { + if (OnAgentLocation != null) + OnAgentLocation(agentID, regionID, regionHandle); + + result["responsestring"] = "TRUE"; + } + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } + + public XmlRpcResponse AgentLeaving(XmlRpcRequest request) + { + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable result = new Hashtable(); + + UUID agentID; + UUID regionID; + ulong regionHandle; + if (UUID.TryParse((string)requestData["AgentID"], out agentID) && UUID.TryParse((string)requestData["RegionUUID"], out regionID) && ulong.TryParse((string)requestData["RegionHandle"], out regionHandle)) + { + if (OnAgentLeaving != null) + OnAgentLeaving(agentID, regionID, regionHandle); + + result["responsestring"] = "TRUE"; + } + + XmlRpcResponse response = new XmlRpcResponse(); + response.Value = result; + return response; + } } } diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index f7e4e3c..04510b2 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -758,5 +758,52 @@ namespace OpenSim.Grid.UserServer { throw new Exception("The method or operation is not implemented."); } + + public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle) + { + UserProfileData userProfile = GetUserProfile(agentID); + if (userProfile != null) + { + userProfile.CurrentAgent.Region = regionID; + userProfile.CurrentAgent.Handle = regionHandle; + CommitAgent(ref userProfile); + } + } + + public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle) + { + UserProfileData userProfile = GetUserProfile(agentID); + if (userProfile != null) + { + if (userProfile.CurrentAgent.Region == regionID) + { + UserAgentData userAgent = userProfile.CurrentAgent; + if (userAgent != null && userAgent.AgentOnline) + { + userAgent.AgentOnline = false; + userAgent.LogoutTime = Util.UnixTimeSinceEpoch(); + if (regionID != UUID.Zero) + { + userAgent.Region = regionID; + } + userAgent.Handle = regionHandle; + userProfile.LastLogin = userAgent.LogoutTime; + + CommitAgent(ref userProfile); + } + } + } + } + + public void HandleRegionStartup(UUID regionID) + { + LogoutUsers(regionID); + } + + public void HandleRegionShutdown(UUID regionID) + { + LogoutUsers(regionID); + } + } } -- cgit v1.1