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/Framework/MessageServerConfig.cs | 116 +++++++++++++++
OpenSim/Framework/Servers/MessageServerInfo.cs | 17 +++
OpenSim/Grid/MessagingServer/Main.cs | 88 ++----------
OpenSim/Grid/UserServer/Main.cs | 18 ++-
OpenSim/Grid/UserServer/MessageServersConnector.cs | 157 +++++++++++++++++++++
OpenSim/Grid/UserServer/UserLoginService.cs | 9 ++
6 files changed, 330 insertions(+), 75 deletions(-)
create mode 100644 OpenSim/Framework/MessageServerConfig.cs
create mode 100644 OpenSim/Framework/Servers/MessageServerInfo.cs
create mode 100644 OpenSim/Grid/UserServer/MessageServersConnector.cs
diff --git a/OpenSim/Framework/MessageServerConfig.cs b/OpenSim/Framework/MessageServerConfig.cs
new file mode 100644
index 0000000..2859c25
--- /dev/null
+++ b/OpenSim/Framework/MessageServerConfig.cs
@@ -0,0 +1,116 @@
+/*
+* Copyright (c) Contributors, http://opensimulator.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the OpenSim Project nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Framework
+{
+ ///
+ /// Message Server Config - Configuration of the Message Server
+ ///
+ public class MessageServerConfig
+ {
+ public string DefaultStartupMsg = "";
+ public string UserServerURL = "";
+ public string UserSendKey = "";
+ public string UserRecvKey = "";
+
+ public string DatabaseProvider = "";
+ public string GridCommsProvider = "";
+
+ public static uint DefaultHttpPort = 8006;
+ public static bool DefaultHttpSSL = false;
+ public uint HttpPort = DefaultHttpPort;
+ public bool HttpSSL = DefaultHttpSSL;
+
+ private ConfigurationMember configMember;
+
+ public MessageServerConfig(string description, string filename)
+ {
+ configMember =
+ new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, true);
+ configMember.performConfigurationRetrieve();
+ }
+ public void loadConfigurationOptions()
+ {
+
+ configMember.addConfigurationOption("default_user_server",
+ ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY,
+ "Default User Server URI",
+ "http://127.0.0.1:" + MessageServerConfig.DefaultHttpPort.ToString() + "/", false);
+ configMember.addConfigurationOption("user_send_key", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
+ "Key to send to user server", "null", false);
+ configMember.addConfigurationOption("user_recv_key", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
+ "Key to expect from user server", "null", false);
+
+ configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
+ "DLL for database provider", "OpenSim.Framework.Data.MySQL.dll", false);
+
+ configMember.addConfigurationOption("region_comms_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING,
+ "DLL for comms provider", "OpenSim.Region.Communications.OGS1.dll", false);
+
+ configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
+ "Http Listener port", DefaultHttpPort.ToString(), false);
+ configMember.addConfigurationOption("http_ssl", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN,
+ "Use SSL? true/false", DefaultHttpSSL.ToString(), false);
+
+ }
+
+ public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
+ {
+ switch (configuration_key)
+ {
+
+ case "default_user_server":
+ UserServerURL = (string)configuration_result;
+ break;
+ case "user_send_key":
+ UserSendKey = (string)configuration_result;
+ break;
+ case "user_recv_key":
+ UserRecvKey = (string)configuration_result;
+ break;
+ case "database_provider":
+ DatabaseProvider = (string)configuration_result;
+ break;
+ case "http_port":
+ HttpPort = (uint)configuration_result;
+ break;
+ case "http_ssl":
+ HttpSSL = (bool)configuration_result;
+ break;
+ case "region_comms_provider":
+ GridCommsProvider = (string)configuration_result;
+ break;
+ }
+
+ return true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenSim/Framework/Servers/MessageServerInfo.cs b/OpenSim/Framework/Servers/MessageServerInfo.cs
new file mode 100644
index 0000000..13d65f9
--- /dev/null
+++ b/OpenSim/Framework/Servers/MessageServerInfo.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Framework.Servers
+{
+ public class MessageServerInfo
+ {
+ public string URI;
+ public string sendkey;
+ public string recvkey;
+ public List responsibleForRegions;
+ public MessageServerInfo()
+ {
+ }
+ }
+}
diff --git a/OpenSim/Grid/MessagingServer/Main.cs b/OpenSim/Grid/MessagingServer/Main.cs
index a69cef3..8f64113 100644
--- a/OpenSim/Grid/MessagingServer/Main.cs
+++ b/OpenSim/Grid/MessagingServer/Main.cs
@@ -39,9 +39,9 @@ namespace OpenSim.Grid.MessagingServer
{
///
///
- public class OpenUser_Main : conscmd_callback
+ public class OpenMessage_Main : conscmd_callback
{
- private UserConfig Cfg;
+ private MessageServerConfig Cfg;
//public UserManager m_userManager;
//public UserLoginService m_loginService;
@@ -52,22 +52,22 @@ namespace OpenSim.Grid.MessagingServer
[STAThread]
public static void Main(string[] args)
{
- Console.WriteLine("Launching UserServer...");
+ Console.WriteLine("Launching MessagingServer...");
- OpenUser_Main userserver = new OpenUser_Main();
+ OpenMessage_Main messageserver = new OpenMessage_Main();
- userserver.Startup();
- userserver.Work();
+ messageserver.Startup();
+ messageserver.Work();
}
- private OpenUser_Main()
+ private OpenMessage_Main()
{
if (!Directory.Exists(Util.logDir()))
{
Directory.CreateDirectory(Util.logDir());
}
m_console =
- new LogBase((Path.Combine(Util.logDir(), "opengrid-messagingserver-console.log")), "OpenUser", this, true);
+ new LogBase((Path.Combine(Util.logDir(), "opengrid-messagingserver-console.log")), "OpenMessage", this, true);
MainLog.Instance = m_console;
}
@@ -83,9 +83,9 @@ namespace OpenSim.Grid.MessagingServer
public void Startup()
{
- Cfg = new UserConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml")));
+ Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml")));
- MainLog.Instance.Verbose("REGION", "Establishing data connection");
+ //MainLog.Instance.Verbose("REGION", "Establishing data connection");
//m_userManager = new UserManager();
//m_userManager._config = Cfg;
//m_userManager.AddPlugin(Cfg.DatabaseProvider);
@@ -120,21 +120,7 @@ namespace OpenSim.Grid.MessagingServer
switch (what)
{
case "user":
- string tempfirstname;
- string templastname;
- string tempMD5Passwd;
- uint regX = 1000;
- uint regY = 1000;
-
- tempfirstname = m_console.CmdPrompt("First name");
- templastname = m_console.CmdPrompt("Last name");
- tempMD5Passwd = m_console.PasswdPrompt("Password");
- regX = Convert.ToUInt32(m_console.CmdPrompt("Start Region X"));
- regY = Convert.ToUInt32(m_console.CmdPrompt("Start Region Y"));
-
- tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + "");
-
- LLUUID userID = new LLUUID();
+
try
{
//userID =
@@ -153,7 +139,7 @@ namespace OpenSim.Grid.MessagingServer
{
m_console.Error("SERVER", "Error creating inventory for user: {0}", ex.ToString());
}
- m_lastCreatedUser = userID;
+ // m_lastCreatedUser = userID;
break;
}
}
@@ -163,64 +149,18 @@ namespace OpenSim.Grid.MessagingServer
switch (cmd)
{
case "help":
- m_console.Notice("create user - create a new user");
- m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
- break;
-
- case "create":
- do_create(cmdparams[0]);
+ m_console.Notice("shutdown - shutdown the message server (USE CAUTION!)");
break;
case "shutdown":
m_console.Close();
Environment.Exit(0);
break;
-
- case "test-inventory":
- // RestObjectPosterResponse> requester = new RestObjectPosterResponse>();
- // requester.ReturnResponseVal = TestResponse;
- // requester.BeginPostObject(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
- //List folders =
- //SynchronousRestObjectPoster.BeginPostObject>("POST",
- //m_userManager.
- //_config.
- //InventoryUrl +
- //"RootFolders/",
- //m_lastCreatedUser);
- break;
}
}
- public void TestResponse(List resp)
- {
- Console.WriteLine("response got");
- }
-
- /*private void ConfigDB(IGenericConfig configData)
- {
- try
- {
- string attri = "";
- attri = configData.GetAttribute("DataBaseProvider");
- if (attri == "")
- {
- StorageDll = "OpenSim.Framework.Data.DB4o.dll";
- configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll");
- }
- else
- {
- StorageDll = attri;
- }
- configData.Commit();
- }
- catch
- {
-
- }
- }*/
-
public void Show(string ShowWhat)
{
}
}
-}
\ No newline at end of file
+}
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