From b8efd5f2949dd247590c1e40509e71031faf3413 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sun, 6 Jan 2008 18:18:19 +0000 Subject: * Added some userserver glue for communications with the message server * Added some code for the message server, fixed a few references and starting to flesh it out. --- OpenSim/Grid/UserServer/Main.cs | 18 ++- OpenSim/Grid/UserServer/MessageServersConnector.cs | 157 +++++++++++++++++++++ OpenSim/Grid/UserServer/UserLoginService.cs | 9 ++ 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Grid/UserServer/MessageServersConnector.cs (limited to 'OpenSim/Grid/UserServer') diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 5264870..8e6817d 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -42,9 +42,11 @@ namespace OpenSim.Grid.UserServer public class OpenUser_Main : conscmd_callback { private UserConfig Cfg; + public UserManager m_userManager; public UserLoginService m_loginService; + public MessageServersConnector m_messagesService; private LogBase m_console; private LLUUID m_lastCreatedUser = LLUUID.Random(); @@ -93,6 +95,10 @@ namespace OpenSim.Grid.UserServer m_loginService = new UserLoginService( m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg); + m_messagesService = new MessageServersConnector(MainLog.Instance); + + m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation; + MainLog.Instance.Verbose("REGION", "Starting HTTP process"); BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort); @@ -106,7 +112,12 @@ namespace OpenSim.Grid.UserServer httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend); httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms); httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); - + + // Message Server ---> User Server + httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer); + httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion); + httpServer.AddXmlRPCHandler("deregister_messageserver", m_messagesService.XmlRPCDeRegisterMessageServer); + httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); @@ -173,6 +184,7 @@ namespace OpenSim.Grid.UserServer break; case "shutdown": + m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation; m_console.Close(); Environment.Exit(0); break; @@ -196,6 +208,10 @@ namespace OpenSim.Grid.UserServer { Console.WriteLine("response got"); } + public void NotifyMessageServersUserLoggedInToLocation(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position) + { + m_messagesService.TellMessageServersAboutUser(agentID, sessionID, RegionID, regionhandle, Position); + } /*private void ConfigDB(IGenericConfig configData) { diff --git a/OpenSim/Grid/UserServer/MessageServersConnector.cs b/OpenSim/Grid/UserServer/MessageServersConnector.cs new file mode 100644 index 0000000..deec739 --- /dev/null +++ b/OpenSim/Grid/UserServer/MessageServersConnector.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using libsecondlife; +using Nwc.XmlRpc; +using OpenSim.Framework; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Console; +using OpenSim.Framework.Servers; + +namespace OpenSim.Grid.UserServer +{ + + public class MessageServersConnector + { + private LogBase m_log; + public Dictionary MessageServers; + + public MessageServersConnector(LogBase log) + { + m_log=log; + MessageServers = new Dictionary(); + } + + public void RegisterMessageServer(string URI, MessageServerInfo serverData) + { + MessageServers.Add(URI, serverData); + } + + public void DeRegisterMessageServer(string URI) + { + MessageServers.Remove(URI); + } + + public void AddResponsibleRegion(string URI, ulong regionhandle) + { + if (!MessageServers.ContainsKey(URI)) + { + m_log.Warn("MSGSERVER", "Got addResponsibleRegion Request for a MessageServer that isn't registered"); + } + else + { + MessageServerInfo msginfo = MessageServers["URI"]; + msginfo.responsibleForRegions.Add(regionhandle); + MessageServers["URI"] = msginfo; + } + } + public void RemoveResponsibleRegion(string URI, ulong regionhandle) + { + if (!MessageServers.ContainsKey(URI)) + { + m_log.Warn("MSGSERVER", "Got RemoveResponsibleRegion Request for a MessageServer that isn't registered"); + } + else + { + MessageServerInfo msginfo = MessageServers["URI"]; + if (msginfo.responsibleForRegions.Contains(regionhandle)) + { + msginfo.responsibleForRegions.Remove(regionhandle); + MessageServers["URI"] = msginfo; + } + } + + } + public XmlRpcResponse XmlRPCRegisterMessageServer(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable responseData = new Hashtable(); + + if (requestData.Contains("uri")) + { + string URI = (string)requestData["URI"]; + string sendkey=(string)requestData["sendkey"]; + string recvkey=(string)requestData["recvkey"]; + MessageServerInfo m = new MessageServerInfo(); + m.URI = URI; + m.sendkey = sendkey; + m.recvkey = recvkey; + RegisterMessageServer(URI, m); + responseData["responsestring"] = "TRUE"; + response.Value = responseData; + } + return response; + } + public XmlRpcResponse XmlRPCDeRegisterMessageServer(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable responseData = new Hashtable(); + + if (requestData.Contains("uri")) + { + string URI = (string)requestData["URI"]; + + DeRegisterMessageServer(URI); + responseData["responsestring"] = "TRUE"; + response.Value = responseData; + } + return response; + } + public XmlRpcResponse XmlRPCUserMovedtoRegion(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable responseData = new Hashtable(); + + if (requestData.Contains("fromuri")) + { + string sURI = (string)requestData["fromuri"]; + string sagentID = (string)requestData["agentid"]; + string ssessionID = (string)requestData["sessionid"]; + string scurrentRegionID = (string)requestData["regionid"]; + string sregionhandle = (string)requestData["regionhandle"]; + string scurrentpos = (string)requestData["currentpos"]; + //LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos); + // TODO: Okay now raise event so the user server can pass this data to the Usermanager + + responseData["responsestring"] = "TRUE"; + response.Value = responseData; + } + return response; + } + + public void TellMessageServersAboutUser(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position) + { + // Loop over registered Message Servers ( AND THERE WILL BE MORE THEN ONE :D ) + foreach (MessageServerInfo serv in MessageServers.Values) + { + NotifyMessageServerAboutUser(serv, agentID, sessionID, RegionID, regionhandle, Position); + } + } + + private void NotifyMessageServerAboutUser(MessageServerInfo serv, LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position) + { + Hashtable reqparams = new Hashtable(); + reqparams["sendkey"] = serv.sendkey; + reqparams["agentid"] = agentID.ToString(); + reqparams["sessionid"] = sessionID.ToString(); + reqparams["regionid"] = RegionID.ToString(); + reqparams["regionhandle"] = regionhandle.ToString(); + reqparams["position"] = Position.ToString(); + + ArrayList SendParams = new ArrayList(); + SendParams.Add(reqparams); + + XmlRpcRequest GridReq = new XmlRpcRequest("user_login", SendParams); + XmlRpcResponse GridResp = GridReq.Send(serv.URI, 6000); + m_log.Verbose("LOGIN","Notified : " + serv.URI + " about user login"); + + } + + + } +} diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 1a3bf2e..98d19f7 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -43,8 +43,13 @@ using InventoryFolder=OpenSim.Framework.InventoryFolder; namespace OpenSim.Grid.UserServer { + public delegate void UserLoggedInAtLocation(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position); + + public class UserLoginService : LoginService { + public event UserLoggedInAtLocation OnUserLoggedInAtLocation; + public UserConfig m_config; public UserLoginService( @@ -198,6 +203,10 @@ namespace OpenSim.Grid.UserServer // Send XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + if (OnUserLoggedInAtLocation != null) + { + OnUserLoggedInAtLocation(theUser.UUID, theUser.currentAgent.sessionID, theUser.currentAgent.currentRegion, theUser.currentAgent.currentHandle, theUser.currentAgent.currentPos); + } } catch (Exception e) -- cgit v1.1