* 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.
afrisby
Teravus Ovares 2008-01-06 18:18:19 +00:00
parent 3d7e6fc6d8
commit b8efd5f294
6 changed files with 330 additions and 75 deletions

View File

@ -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
{
/// <summary>
/// Message Server Config - Configuration of the Message Server
/// </summary>
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;
}
}
}

View File

@ -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<ulong> responsibleForRegions;
public MessageServerInfo()
{
}
}
}

View File

@ -39,9 +39,9 @@ namespace OpenSim.Grid.MessagingServer
{ {
/// <summary> /// <summary>
/// </summary> /// </summary>
public class OpenUser_Main : conscmd_callback public class OpenMessage_Main : conscmd_callback
{ {
private UserConfig Cfg; private MessageServerConfig Cfg;
//public UserManager m_userManager; //public UserManager m_userManager;
//public UserLoginService m_loginService; //public UserLoginService m_loginService;
@ -52,22 +52,22 @@ namespace OpenSim.Grid.MessagingServer
[STAThread] [STAThread]
public static void Main(string[] args) 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(); messageserver.Startup();
userserver.Work(); messageserver.Work();
} }
private OpenUser_Main() private OpenMessage_Main()
{ {
if (!Directory.Exists(Util.logDir())) if (!Directory.Exists(Util.logDir()))
{ {
Directory.CreateDirectory(Util.logDir()); Directory.CreateDirectory(Util.logDir());
} }
m_console = 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; MainLog.Instance = m_console;
} }
@ -83,9 +83,9 @@ namespace OpenSim.Grid.MessagingServer
public void Startup() 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 = new UserManager();
//m_userManager._config = Cfg; //m_userManager._config = Cfg;
//m_userManager.AddPlugin(Cfg.DatabaseProvider); //m_userManager.AddPlugin(Cfg.DatabaseProvider);
@ -120,21 +120,7 @@ namespace OpenSim.Grid.MessagingServer
switch (what) switch (what)
{ {
case "user": 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 try
{ {
//userID = //userID =
@ -153,7 +139,7 @@ namespace OpenSim.Grid.MessagingServer
{ {
m_console.Error("SERVER", "Error creating inventory for user: {0}", ex.ToString()); m_console.Error("SERVER", "Error creating inventory for user: {0}", ex.ToString());
} }
m_lastCreatedUser = userID; // m_lastCreatedUser = userID;
break; break;
} }
} }
@ -163,64 +149,18 @@ namespace OpenSim.Grid.MessagingServer
switch (cmd) switch (cmd)
{ {
case "help": case "help":
m_console.Notice("create user - create a new user"); m_console.Notice("shutdown - shutdown the message server (USE CAUTION!)");
m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
break;
case "create":
do_create(cmdparams[0]);
break; break;
case "shutdown": case "shutdown":
m_console.Close(); m_console.Close();
Environment.Exit(0); Environment.Exit(0);
break; break;
case "test-inventory":
// RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>();
// requester.ReturnResponseVal = TestResponse;
// requester.BeginPostObject<LLUUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
//List<InventoryFolderBase> folders =
//SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>("POST",
//m_userManager.
//_config.
//InventoryUrl +
//"RootFolders/",
//m_lastCreatedUser);
break;
} }
} }
public void TestResponse(List<InventoryFolderBase> 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) public void Show(string ShowWhat)
{ {
} }
} }
} }

View File

@ -42,9 +42,11 @@ namespace OpenSim.Grid.UserServer
public class OpenUser_Main : conscmd_callback public class OpenUser_Main : conscmd_callback
{ {
private UserConfig Cfg; private UserConfig Cfg;
public UserManager m_userManager; public UserManager m_userManager;
public UserLoginService m_loginService; public UserLoginService m_loginService;
public MessageServersConnector m_messagesService;
private LogBase m_console; private LogBase m_console;
private LLUUID m_lastCreatedUser = LLUUID.Random(); private LLUUID m_lastCreatedUser = LLUUID.Random();
@ -93,6 +95,10 @@ namespace OpenSim.Grid.UserServer
m_loginService = new UserLoginService( m_loginService = new UserLoginService(
m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg); m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
m_messagesService = new MessageServersConnector(MainLog.Instance);
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
MainLog.Instance.Verbose("REGION", "Starting HTTP process"); MainLog.Instance.Verbose("REGION", "Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort); BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
@ -106,7 +112,12 @@ namespace OpenSim.Grid.UserServer
httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend); httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend);
httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms); httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms);
httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); 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( httpServer.AddStreamHandler(
new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
@ -173,6 +184,7 @@ namespace OpenSim.Grid.UserServer
break; break;
case "shutdown": case "shutdown":
m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation;
m_console.Close(); m_console.Close();
Environment.Exit(0); Environment.Exit(0);
break; break;
@ -196,6 +208,10 @@ namespace OpenSim.Grid.UserServer
{ {
Console.WriteLine("response got"); 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) /*private void ConfigDB(IGenericConfig configData)
{ {

View File

@ -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<string, MessageServerInfo> MessageServers;
public MessageServersConnector(LogBase log)
{
m_log=log;
MessageServers = new Dictionary<string, MessageServerInfo>();
}
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");
}
}
}

View File

@ -43,8 +43,13 @@ using InventoryFolder=OpenSim.Framework.InventoryFolder;
namespace OpenSim.Grid.UserServer namespace OpenSim.Grid.UserServer
{ {
public delegate void UserLoggedInAtLocation(LLUUID agentID, LLUUID sessionID, LLUUID RegionID, ulong regionhandle, LLVector3 Position);
public class UserLoginService : LoginService public class UserLoginService : LoginService
{ {
public event UserLoggedInAtLocation OnUserLoggedInAtLocation;
public UserConfig m_config; public UserConfig m_config;
public UserLoginService( public UserLoginService(
@ -198,6 +203,10 @@ namespace OpenSim.Grid.UserServer
// Send // Send
XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); 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) catch (Exception e)