* Rex merges, user server.

afrisby-3
Adam Frisby 2008-02-23 02:57:50 +00:00
parent 7caa40e301
commit b526c42d06
5 changed files with 1268 additions and 1188 deletions

View File

@ -1,315 +1,331 @@
/*
* 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.Collections;
using System.IO;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
using Nwc.XmlRpc;
namespace OpenSim.Grid.UserServer
{
/// <summary>
/// </summary>
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();
private Boolean m_rexMode;
[STAThread]
public static void Main(string[] args)
{
Console.WriteLine("Launching UserServer...");
OpenUser_Main userserver = new OpenUser_Main();
userserver.Startup();
userserver.Work();
}
private OpenUser_Main()
{
if (!Directory.Exists(Util.logDir()))
{
Directory.CreateDirectory(Util.logDir());
}
m_console =
new LogBase((Path.Combine(Util.logDir(), "opengrid-userserver-console.log")), "OpenUser", this, true);
MainLog.Instance = m_console;
}
private void Work()
{
m_console.Notice("Enter help for a list of commands\n");
while (true)
{
m_console.MainLogPrompt();
}
}
public void Startup()
{
Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), "UserServer_Config.xml")));
MainLog.Instance.Verbose("REGION", "Establishing data connection");
m_userManager = new UserManager();
m_userManager._config = Cfg;
m_userManager.AddPlugin(Cfg.DatabaseProvider);
m_loginService = new UserLoginService(
m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
m_rexMode = Cfg.RexMode;
m_messagesService = new MessageServersConnector(MainLog.Instance);
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
MainLog.Instance.Verbose("REGION", "Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
if (!m_rexMode) {
httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar);
httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend);
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);
}
else {
httpServer.AddXmlRPCHandler("get_user_by_name", new RexRemoteHandler("get_user_by_name").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_user_by_uuid", new RexRemoteHandler("get_user_by_uuid").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", new RexRemoteHandler("get_avatar_picker_avatar").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("add_new_user_friend", new RexRemoteHandler("add_new_user_friend").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("remove_user_friend", new RexRemoteHandler("remove_user_friend").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("update_user_friend_perms", new RexRemoteHandler("update_user_friend_perms").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_user_friend_list", new RexRemoteHandler("get_user_friend_list").rexRemoteXmlRPCHandler);
// Message Server ---> User Server
httpServer.AddXmlRPCHandler("register_messageserver", new RexRemoteHandler("register_messageserver").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("agent_change_region", new RexRemoteHandler("agent_change_region").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("deregister_messageserver", new RexRemoteHandler("deregister_messageserver").rexRemoteXmlRPCHandler);
}
httpServer.AddStreamHandler(
new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
httpServer.Start();
m_console.Status("SERVER", "Userserver 0.4 - Startup complete");
}
public void do_create(string what)
{
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 =
m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
} catch (Exception ex)
{
m_console.Error("SERVER", "Error creating user: {0}", ex.ToString());
}
try
{
RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
userID.UUID);
}
catch (Exception ex)
{
m_console.Error("SERVER", "Error creating inventory for user: {0}", ex.ToString());
}
m_lastCreatedUser = userID;
break;
}
}
public void RunCmd(string cmd, string[] cmdparams)
{
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]);
break;
case "shutdown":
m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation;
m_console.Close();
Environment.Exit(0);
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");
}
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)
{
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)
{
}
}
/// <summary>
/// for forwarding some requests to authentication server
/// </summary>
class RexRemoteHandler
{
private string methodName;
public RexRemoteHandler(String method)
{
methodName = method;
}
public XmlRpcResponse rexRemoteXmlRPCHandler(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
string authAddr;
if (requestData.Contains("AuthenticationAddress") && requestData["AuthenticationAddress"] != null)
{
authAddr = (string)requestData["AuthenticationAddress"];
}
else
{
return CreateErrorResponse("unknown_authentication",
"Request did not contain authentication address");
}
ArrayList SendParams = new ArrayList();
foreach (Object obj in request.Params)
{
SendParams.Add(obj);
}
XmlRpcRequest req = new XmlRpcRequest(methodName, SendParams);
if(!authAddr.StartsWith("http://"))
authAddr = "http://"+ authAddr;
XmlRpcResponse res = req.Send(authAddr, 30000);
return res;
}
public XmlRpcResponse CreateErrorResponse(string type, string desc)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
responseData["error_type"] = type;
responseData["error_desc"] = desc;
response.Value = responseData;
return response;
}
}
}
/*
* 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.Collections;
using System.IO;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
using Nwc.XmlRpc;
using OpenSim.Framework.Statistics;
namespace OpenSim.Grid.UserServer
{
/// <summary>
/// </summary>
public class OpenUser_Main : BaseOpenSimServer, conscmd_callback
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private UserConfig Cfg;
public UserManager m_userManager;
public UserLoginService m_loginService;
public MessageServersConnector m_messagesService;
private LLUUID m_lastCreatedUser = LLUUID.Random();
private Boolean m_rexMode;
[STAThread]
public static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
m_log.Info("Launching UserServer...");
OpenUser_Main userserver = new OpenUser_Main();
userserver.Startup();
userserver.Work();
}
private OpenUser_Main()
{
m_console = new ConsoleBase("OpenUser", this);
MainConsole.Instance = m_console;
}
private void Work()
{
m_console.Notice("Enter help for a list of commands\n");
while (true)
{
m_console.Prompt();
}
}
public void Startup()
{
Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), "UserServer_Config.xml")));
StatsManager.StartCollectingUserStats();
m_log.Info("[REGION]: Establishing data connection");
m_userManager = new UserManager();
m_userManager._config = Cfg;
m_userManager.AddPlugin(Cfg.DatabaseProvider);
m_loginService = new UserLoginService(
m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
m_rexMode = Cfg.RexMode;
m_messagesService = new MessageServersConnector();
m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation;
m_log.Info("[REGION]: Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort);
httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName);
httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID);
httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar);
httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend);
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);
httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID);
// 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);
// 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);
}
else {
httpServer.AddXmlRPCHandler("get_user_by_name", new RexRemoteHandler("get_user_by_name").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_user_by_uuid", new RexRemoteHandler("get_user_by_uuid").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", new RexRemoteHandler("get_avatar_picker_avatar").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("add_new_user_friend", new RexRemoteHandler("add_new_user_friend").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("remove_user_friend", new RexRemoteHandler("remove_user_friend").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("update_user_friend_perms", new RexRemoteHandler("update_user_friend_perms").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("get_user_friend_list", new RexRemoteHandler("get_user_friend_list").rexRemoteXmlRPCHandler);
// Message Server ---> User Server
httpServer.AddXmlRPCHandler("register_messageserver", new RexRemoteHandler("register_messageserver").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("agent_change_region", new RexRemoteHandler("agent_change_region").rexRemoteXmlRPCHandler);
httpServer.AddXmlRPCHandler("deregister_messageserver", new RexRemoteHandler("deregister_messageserver").rexRemoteXmlRPCHandler);
}
httpServer.AddStreamHandler(
new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
httpServer.Start();
m_log.Info("[SERVER]: Userserver 0.5 - Startup complete");
}
public void do_create(string what)
{
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");
tempMD5Passwd = m_console.CmdPrompt("Password");
regX = Convert.ToUInt32(m_console.CmdPrompt("Start Region X"));
regY = Convert.ToUInt32(m_console.CmdPrompt("Start Region Y"));
if (null != m_userManager.GetUserProfile(tempfirstname, templastname))
{
m_log.ErrorFormat("[USERS]: A user with the name {0} {1} already exists!", tempfirstname, templastname);
break;
}
tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + String.Empty);
LLUUID userID = new LLUUID();
try
{
userID =
m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
} catch (Exception ex)
{
m_log.ErrorFormat("[USERS]: Error creating user: {0}", ex.ToString());
}
try
{
RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
userID.UUID);
}
catch (Exception ex)
{
m_log.ErrorFormat("[USERS]: Error creating inventory for user: {0}", ex.ToString());
}
m_lastCreatedUser = userID;
break;
}
}
public override void RunCmd(string cmd, string[] cmdparams)
{
base.RunCmd(cmd, cmdparams);
switch (cmd)
{
case "help":
m_console.Notice("create user - create a new user");
m_console.Notice("stats - statistical information for this server");
m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
break;
case "create":
do_create(cmdparams[0]);
break;
case "shutdown":
m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation;
m_console.Close();
Environment.Exit(0);
break;
case "stats":
m_console.Notice(StatsManager.UserStats.Report());
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);
SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>("POST",
m_userManager.
_config.
InventoryUrl +
"RootFolders/",
m_lastCreatedUser);
break;
}
}
public void TestResponse(List<InventoryFolderBase> resp)
{
m_console.Notice("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)
{
try
{
string attri = String.Empty;
attri = configData.GetAttribute("DataBaseProvider");
if (attri == String.Empty)
{
StorageDll = "OpenSim.Framework.Data.DB4o.dll";
configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll");
}
else
{
StorageDll = attri;
}
configData.Commit();
}
catch
{
}
}*/
}
/// <summary>
/// for forwarding some requests to authentication server
/// </summary>
class RexRemoteHandler
{
private string methodName;
public RexRemoteHandler(String method)
{
methodName = method;
}
public XmlRpcResponse rexRemoteXmlRPCHandler(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
string authAddr;
if (requestData.Contains("AuthenticationAddress") && requestData["AuthenticationAddress"] != null)
{
authAddr = (string)requestData["AuthenticationAddress"];
}
else
{
return CreateErrorResponse("unknown_authentication",
"Request did not contain authentication address");
}
ArrayList SendParams = new ArrayList();
foreach (Object obj in request.Params)
{
SendParams.Add(obj);
}
XmlRpcRequest req = new XmlRpcRequest(methodName, SendParams);
if(!authAddr.StartsWith("http://"))
authAddr = "http://"+ authAddr;
XmlRpcResponse res = req.Send(authAddr, 30000);
return res;
}
public XmlRpcResponse CreateErrorResponse(string type, string desc)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
responseData["error_type"] = type;
responseData["error_desc"] = desc;
response.Value = responseData;
return response;
}
}
}

View File

@ -1,184 +1,180 @@
/*
* 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;
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("login_to_simulator", SendParams);
XmlRpcResponse GridResp = GridReq.Send(serv.URI, 6000);
m_log.Verbose("LOGIN","Notified : " + serv.URI + " about user login");
}
}
}
/*
* 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;
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 static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public Dictionary<string, MessageServerInfo> MessageServers;
public MessageServersConnector()
{
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("login_to_simulator", SendParams);
XmlRpcResponse GridResp = GridReq.Send(serv.URI, 6000);
m_log.Info("[LOGIN]: Notified : " + serv.URI + " about user login");
}
}
}

View File

@ -1,36 +1,64 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly : AssemblyTitle("OGS-UserServer")]
[assembly : AssemblyDescription("")]
[assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("")]
[assembly : AssemblyProduct("OGS-UserServer")]
[assembly : AssemblyCopyright("Copyright © 2007")]
[assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly : ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly : Guid("e266513a-090b-4d38-80f6-8599eef68c8c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")]
/*
* 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.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly : AssemblyTitle("OGS-UserServer")]
[assembly : AssemblyDescription("")]
[assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("")]
[assembly : AssemblyProduct("OGS-UserServer")]
[assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")]
[assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly : ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly : Guid("e266513a-090b-4d38-80f6-8599eef68c8c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")]

View File

@ -1,305 +1,318 @@
/*
* 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;
using System.Collections.Generic;
using System.Threading;
using libsecondlife;
using Nwc.XmlRpc;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console;
using OpenSim.Framework.Data;
using OpenSim.Framework.Servers;
using OpenSim.Framework.UserManagement;
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(
UserManagerBase userManager, LibraryRootFolder libraryRootFolder, UserConfig config, string welcomeMess)
: base(userManager, libraryRootFolder, welcomeMess, config.RexMode)
{
m_config = config;
}
/// <summary>
/// Customises the login response and fills in missing values.
/// </summary>
/// <param name="response">The existing response</param>
/// <param name="theUser">The user profile</param>
public override void CustomiseResponse(LoginResponse response, UserProfileData theUser, string ASaddress)
{
bool tryDefault = false;
//CFK: Since the try is always "tried", the "Home Location" message should always appear, so comment this one.
//CFK: MainLog.Instance.Verbose("LOGIN", "Load information from the gridserver");
RegionProfileData SimInfo = new RegionProfileData();
try
{
SimInfo =
SimInfo.RequestSimProfileData(theUser.currentAgent.currentHandle, m_config.GridServerURL,
m_config.GridSendKey, m_config.GridRecvKey);
// Customise the response
//CFK: This is redundant and the next message should always appear.
//CFK: MainLog.Instance.Verbose("LOGIN", "Home Location");
response.Home = "{'region_handle':[r" + (SimInfo.regionLocX*256).ToString() + ",r" +
(SimInfo.regionLocY*256).ToString() + "], " +
"'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
"'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
// Destination
//CFK: The "Notifying" message always seems to appear, so subsume the data from this message into
//CFK: the next one for X & Y and comment this one.
//CFK: MainLog.Instance.Verbose("LOGIN", "CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX +
//CFK: "; Region Y: " + SimInfo.regionLocY);
response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
response.SimPort = (uint) SimInfo.serverPort;
response.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY;
//Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
string capsPath = Util.GetRandomCapsPath();
response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
// Notify the target of an incoming user
//CFK: The "Notifying" message always seems to appear, so subsume the data from this message into
//CFK: the next one for X & Y and comment this one.
//CFK: MainLog.Instance.Verbose("LOGIN", SimInfo.regionName + " (" + SimInfo.serverURI + ") " +
//CFK: SimInfo.regionLocX + "," + SimInfo.regionLocY);
// Prepare notification
Hashtable SimParams = new Hashtable();
SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
SimParams["firstname"] = theUser.username;
SimParams["lastname"] = theUser.surname;
SimParams["agent_id"] = theUser.UUID.ToString();
SimParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode);
SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
SimParams["caps_path"] = capsPath;
if (m_rexMode)
{
SimParams["auth_addr"] = theUser.authenticationAddr;
SimParams["as_addr"] = ASaddress;
}
ArrayList SendParams = new ArrayList();
SendParams.Add(SimParams);
// Update agent with target sim
theUser.currentAgent.currentRegion = SimInfo.UUID;
theUser.currentAgent.currentHandle = SimInfo.regionHandle;
MainLog.Instance.Verbose("LOGIN", SimInfo.regionName + " @ " + SimInfo.httpServerURI + " " +
SimInfo.regionLocX + "," + SimInfo.regionLocY);
XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
}
catch (Exception)
{
tryDefault = true;
}
if (tryDefault)
{
// Send him to default region instead
// Load information from the gridserver
ulong defaultHandle = (((ulong) m_config.DefaultX*256) << 32) | ((ulong) m_config.DefaultY*256);
MainLog.Instance.Warn(
"LOGIN",
"Home region not available: sending to default " + defaultHandle.ToString());
SimInfo = new RegionProfileData();
try
{
SimInfo =
SimInfo.RequestSimProfileData(defaultHandle, m_config.GridServerURL,
m_config.GridSendKey, m_config.GridRecvKey);
// Customise the response
MainLog.Instance.Verbose("LOGIN", "Home Location");
response.Home = "{'region_handle':[r" + (SimInfo.regionLocX*256).ToString() + ",r" +
(SimInfo.regionLocY*256).ToString() + "], " +
"'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
"'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
// Destination
MainLog.Instance.Verbose("LOGIN",
"CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
SimInfo.regionLocY);
response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
response.SimPort = (uint) SimInfo.serverPort;
response.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY;
//Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
string capsPath = Util.GetRandomCapsPath();
response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
// Notify the target of an incoming user
MainLog.Instance.Verbose("LOGIN", "Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
// Update agent with target sim
theUser.currentAgent.currentRegion = SimInfo.UUID;
theUser.currentAgent.currentHandle = SimInfo.regionHandle;
// Prepare notification
Hashtable SimParams = new Hashtable();
SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
SimParams["firstname"] = theUser.username;
SimParams["lastname"] = theUser.surname;
SimParams["agent_id"] = theUser.UUID.ToString();
SimParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode);
SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
SimParams["caps_path"] = capsPath;
if (m_rexMode)
{
SimParams["auth_addr"] = theUser.authenticationAddr;
SimParams["as_addr"] = ASaddress;
}
ArrayList SendParams = new ArrayList();
SendParams.Add(SimParams);
MainLog.Instance.Verbose("LOGIN", "Informing region at " + SimInfo.httpServerURI);
// 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)
{
MainLog.Instance.Warn("LOGIN", "Default region also not available");
MainLog.Instance.Warn("LOGIN", e.ToString());
}
}
}
protected override InventoryData CreateInventoryData(LLUUID userID)
{
List<InventoryFolderBase> folders
= SynchronousRestObjectPoster.BeginPostObject<Guid, List<InventoryFolderBase>>(
"POST", m_config.InventoryUrl + "RootFolders/", userID.UUID);
// In theory, the user will only ever be missing a root folder in situations where a grid
// which didn't previously run a grid wide inventory server is being transitioned to one
// which does.
if (null == folders | folders.Count == 0)
{
MainLog.Instance.Warn(
"LOGIN",
"A root inventory folder for user ID " + userID + " was not found. A new set"
+ " of empty inventory folders is being created.");
RestObjectPoster.BeginPostObject<Guid>(
m_config.InventoryUrl + "CreateInventory/", userID.UUID);
// A big delay should be okay here since the recreation of the user's root folders should
// only ever happen once. We need to sleep to let the inventory server do its work -
// previously 1000ms has been found to be too short.
Thread.Sleep(10000);
folders = SynchronousRestObjectPoster.BeginPostObject<Guid, List<InventoryFolderBase>>(
"POST", m_config.InventoryUrl + "RootFolders/", userID.UUID);
}
if (folders.Count > 0)
{
LLUUID rootID = LLUUID.Zero;
ArrayList AgentInventoryArray = new ArrayList();
Hashtable TempHash;
foreach (InventoryFolderBase InvFolder in folders)
{
if (InvFolder.parentID == LLUUID.Zero)
{
rootID = InvFolder.folderID;
}
TempHash = new Hashtable();
TempHash["name"] = InvFolder.name;
TempHash["parent_id"] = InvFolder.parentID.ToString();
TempHash["version"] = (Int32) InvFolder.version;
TempHash["type_default"] = (Int32) InvFolder.type;
TempHash["folder_id"] = InvFolder.folderID.ToString();
AgentInventoryArray.Add(TempHash);
}
return new InventoryData(AgentInventoryArray, rootID);
}
else
{
MainLog.Instance.Warn("LOGIN", "The root inventory folder could still not be retrieved" +
" for user ID " + userID);
AgentInventory userInventory = new AgentInventory();
userInventory.CreateRootFolder(userID, false);
ArrayList AgentInventoryArray = new ArrayList();
Hashtable TempHash;
foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values)
{
TempHash = new Hashtable();
TempHash["name"] = InvFolder.FolderName;
TempHash["parent_id"] = InvFolder.ParentID.ToString();
TempHash["version"] = (Int32) InvFolder.Version;
TempHash["type_default"] = (Int32) InvFolder.DefaultType;
TempHash["folder_id"] = InvFolder.FolderID.ToString();
AgentInventoryArray.Add(TempHash);
}
return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID);
}
}
}
}
/*
* 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;
using System.Collections.Generic;
using System.Threading;
using libsecondlife;
using Nwc.XmlRpc;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console;
using OpenSim.Framework.Data;
using OpenSim.Framework.Servers;
using OpenSim.Framework.Statistics;
using OpenSim.Framework.UserManagement;
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
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public event UserLoggedInAtLocation OnUserLoggedInAtLocation;
private UserLoggedInAtLocation handler001 = null;
public UserConfig m_config;
public UserLoginService(
UserManagerBase userManager, LibraryRootFolder libraryRootFolder,
UserConfig config, string welcomeMess)
: base(userManager, libraryRootFolder, welcomeMess, config.RexMode)
{
m_config = config;
}
/// <summary>
/// Customises the login response and fills in missing values.
/// </summary>
/// <param name="response">The existing response</param>
/// <param name="theUser">The user profile</param>
public override void CustomiseResponse(LoginResponse response, UserProfileData theUser, string ASaddress)
{
bool tryDefault = false;
//CFK: Since the try is always "tried", the "Home Location" message should always appear, so comment this one.
//CFK: m_log.Info("[LOGIN]: Load information from the gridserver");
try
{
RegionProfileData SimInfo =
RegionProfileData.RequestSimProfileData(
theUser.currentAgent.currentHandle, m_config.GridServerURL,
m_config.GridSendKey, m_config.GridRecvKey);
// Customise the response
//CFK: This is redundant and the next message should always appear.
//CFK: m_log.Info("[LOGIN]: Home Location");
response.Home = "{'region_handle':[r" + (SimInfo.regionLocX * Constants.RegionSize).ToString() + ",r" +
(SimInfo.regionLocY * Constants.RegionSize).ToString() + "], " +
"'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
"'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
// Destination
//CFK: The "Notifying" message always seems to appear, so subsume the data from this message into
//CFK: the next one for X & Y and comment this one.
//CFK: m_log.Info("[LOGIN]: CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX +
//CFK: "; Region Y: " + SimInfo.regionLocY);
response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
response.SimPort = (uint) SimInfo.serverPort;
response.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY;
//Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
string capsPath = Util.GetRandomCapsPath();
response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
// Notify the target of an incoming user
//CFK: The "Notifying" message always seems to appear, so subsume the data from this message into
//CFK: the next one for X & Y and comment this one.
//CFK: m_log.Info("[LOGIN]: " + SimInfo.regionName + " (" + SimInfo.serverURI + ") " +
//CFK: SimInfo.regionLocX + "," + SimInfo.regionLocY);
// Prepare notification
Hashtable SimParams = new Hashtable();
SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
SimParams["firstname"] = theUser.username;
SimParams["lastname"] = theUser.surname;
SimParams["agent_id"] = theUser.UUID.ToString();
SimParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode);
SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
SimParams["caps_path"] = capsPath;
if (m_rexMode)
{
SimParams["auth_addr"] = theUser.authenticationAddr;
SimParams["as_addr"] = ASaddress;
}
ArrayList SendParams = new ArrayList();
SendParams.Add(SimParams);
// Update agent with target sim
theUser.currentAgent.currentRegion = SimInfo.UUID;
theUser.currentAgent.currentHandle = SimInfo.regionHandle;
m_log.Info("[LOGIN]: Telling "
+ SimInfo.regionName + " @ " + SimInfo.httpServerURI + " " +
SimInfo.regionLocX + "," + SimInfo.regionLocY + " to expect user connection");
XmlRpcRequest GridReq = new XmlRpcRequest("expect_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}",
SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString);
}
}
catch (Exception)
{
tryDefault = true;
}
if (tryDefault)
{
// Send him to default region instead
// Load information from the gridserver
ulong defaultHandle = (((ulong)m_config.DefaultX * Constants.RegionSize) << 32) | ((ulong)m_config.DefaultY * Constants.RegionSize);
m_log.Warn(
"[LOGIN]: Home region not available: sending to default " + defaultHandle.ToString());
try
{
RegionProfileData SimInfo = RegionProfileData.RequestSimProfileData(
defaultHandle, m_config.GridServerURL,
m_config.GridSendKey, m_config.GridRecvKey);
// Customise the response
m_log.Info("[LOGIN]: Home Location");
response.Home = "{'region_handle':[r" + (SimInfo.regionLocX * Constants.RegionSize).ToString() + ",r" +
(SimInfo.regionLocY * Constants.RegionSize).ToString() + "], " +
"'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
"'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
// Destination
m_log.Info("[LOGIN]: " +
"CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
SimInfo.regionLocY);
response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
response.SimPort = (uint) SimInfo.serverPort;
response.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY;
//Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
string capsPath = Util.GetRandomCapsPath();
response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
// Notify the target of an incoming user
m_log.Info("[LOGIN]: Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
// Update agent with target sim
theUser.currentAgent.currentRegion = SimInfo.UUID;
theUser.currentAgent.currentHandle = SimInfo.regionHandle;
// Prepare notification
Hashtable SimParams = new Hashtable();
SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
SimParams["firstname"] = theUser.username;
SimParams["lastname"] = theUser.surname;
SimParams["agent_id"] = theUser.UUID.ToString();
SimParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode);
SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
SimParams["caps_path"] = capsPath;
if (m_rexMode)
{
SimParams["auth_addr"] = theUser.authenticationAddr;
SimParams["as_addr"] = ASaddress;
}
ArrayList SendParams = new ArrayList();
SendParams.Add(SimParams);
m_log.Info("[LOGIN]: Informing region at " + SimInfo.httpServerURI);
// Send
XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
handler001 = OnUserLoggedInAtLocation;
if (handler001 != null)
{
handler001(theUser.UUID, theUser.currentAgent.sessionID, theUser.currentAgent.currentRegion, theUser.currentAgent.currentHandle, theUser.currentAgent.currentPos);
}
}
catch (Exception e)
{
m_log.Warn("[LOGIN]: Default region also not available");
m_log.Warn("[LOGIN]: " + e.ToString());
}
}
}
protected override InventoryData CreateInventoryData(LLUUID userID)
{
List<InventoryFolderBase> folders
= SynchronousRestObjectPoster.BeginPostObject<Guid, List<InventoryFolderBase>>(
"POST", m_config.InventoryUrl + "RootFolders/", userID.UUID);
// In theory, the user will only ever be missing a root folder in situations where a grid
// which didn't previously run a grid wide inventory server is being transitioned to one
// which does.
if (null == folders | folders.Count == 0)
{
m_log.Warn(
"[LOGIN]: " +
"root inventory folder user " + userID + " not found. Creating.");
RestObjectPoster.BeginPostObject<Guid>(
m_config.InventoryUrl + "CreateInventory/", userID.UUID);
// A big delay should be okay here since the recreation of the user's root folders should
// only ever happen once. We need to sleep to let the inventory server do its work -
// previously 1000ms has been found to be too short.
Thread.Sleep(10000);
folders = SynchronousRestObjectPoster.BeginPostObject<Guid, List<InventoryFolderBase>>(
"POST", m_config.InventoryUrl + "RootFolders/", userID.UUID);
}
if (folders.Count > 0)
{
LLUUID rootID = LLUUID.Zero;
ArrayList AgentInventoryArray = new ArrayList();
Hashtable TempHash;
foreach (InventoryFolderBase InvFolder in folders)
{
if (InvFolder.parentID == LLUUID.Zero)
{
rootID = InvFolder.folderID;
}
TempHash = new Hashtable();
TempHash["name"] = InvFolder.name;
TempHash["parent_id"] = InvFolder.parentID.ToString();
TempHash["version"] = (Int32) InvFolder.version;
TempHash["type_default"] = (Int32) InvFolder.type;
TempHash["folder_id"] = InvFolder.folderID.ToString();
AgentInventoryArray.Add(TempHash);
}
return new InventoryData(AgentInventoryArray, rootID);
}
else
{
m_log.Warn("[LOGIN]: The root inventory folder could still not be retrieved" +
" for user ID " + userID);
AgentInventory userInventory = new AgentInventory();
userInventory.CreateRootFolder(userID, false);
ArrayList AgentInventoryArray = new ArrayList();
Hashtable TempHash;
foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values)
{
TempHash = new Hashtable();
TempHash["name"] = InvFolder.FolderName;
TempHash["parent_id"] = InvFolder.ParentID.ToString();
TempHash["version"] = (Int32) InvFolder.Version;
TempHash["type_default"] = (Int32) InvFolder.DefaultType;
TempHash["folder_id"] = InvFolder.FolderID.ToString();
AgentInventoryArray.Add(TempHash);
}
return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID);
}
}
}
}

View File

@ -1,348 +1,375 @@
/*
* 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;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using libsecondlife;
using Nwc.XmlRpc;
using OpenSim.Framework;
using OpenSim.Framework.UserManagement;
namespace OpenSim.Grid.UserServer
{
public class UserManager : UserManagerBase
{
public UserManager()
{
}
/// <summary>
/// Deletes an active agent session
/// </summary>
/// <param name="request">The request</param>
/// <param name="path">The path (eg /bork/narf/test)</param>
/// <param name="param">Parameters sent</param>
/// <returns>Success "OK" else error</returns>
public string RestDeleteUserSessionMethod(string request, string path, string param)
{
// TODO! Important!
return "OK";
}
/// <summary>
/// Returns an error message that the user could not be found in the database
/// </summary>
/// <returns>XML string consisting of a error element containing individual error(s)</returns>
public XmlRpcResponse CreateUnknownUserErrorResponse()
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
responseData["error_type"] = "unknown_user";
responseData["error_desc"] = "The user requested is not in the database";
response.Value = responseData;
return response;
}
public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(LLUUID queryID, List<AvatarPickerAvatar> returnUsers)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Query Result Information
responseData["queryid"] = (string) queryID.ToString();
responseData["avcount"] = (string) returnUsers.Count.ToString();
for (int i = 0; i < returnUsers.Count; i++)
{
responseData["avatarid" + i.ToString()] = returnUsers[i].AvatarID.ToString();
responseData["firstname" + i.ToString()] = returnUsers[i].firstName;
responseData["lastname" + i.ToString()] = returnUsers[i].lastName;
}
response.Value = responseData;
return response;
}
public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Query Result Information
responseData["avcount"] = (string)returnUsers.Count.ToString();
for (int i = 0; i < returnUsers.Count; i++)
{
responseData["ownerID" + i.ToString()] = returnUsers[i].FriendListOwner.UUID.ToString();
responseData["friendID" + i.ToString()] = returnUsers[i].Friend.UUID.ToString();
responseData["ownerPerms" + i.ToString()] = returnUsers[i].FriendListOwnerPerms.ToString();
responseData["friendPerms" + i.ToString()] = returnUsers[i].FriendPerms.ToString();
}
response.Value = responseData;
return response;
}
/// <summary>
/// Converts a user profile to an XML element which can be returned
/// </summary>
/// <param name="profile">The user profile</param>
/// <returns>A string containing an XML Document of the user profile</returns>
public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Account information
responseData["firstname"] = profile.username;
responseData["lastname"] = profile.surname;
responseData["uuid"] = profile.UUID.ToString();
// Server Information
responseData["server_inventory"] = profile.userInventoryURI;
responseData["server_asset"] = profile.userAssetURI;
// Profile Information
responseData["profile_about"] = profile.profileAboutText;
responseData["profile_firstlife_about"] = profile.profileFirstText;
responseData["profile_firstlife_image"] = profile.profileFirstImage.ToString();
responseData["profile_can_do"] = profile.profileCanDoMask.ToString();
responseData["profile_want_do"] = profile.profileWantDoMask.ToString();
responseData["profile_image"] = profile.profileImage.ToString();
responseData["profile_created"] = profile.created.ToString();
responseData["profile_lastlogin"] = profile.lastLogin.ToString();
// Home region information
responseData["home_coordinates_x"] = profile.homeLocation.X.ToString();
responseData["home_coordinates_y"] = profile.homeLocation.Y.ToString();
responseData["home_coordinates_z"] = profile.homeLocation.Z.ToString();
responseData["home_region"] = profile.homeRegion.ToString();
responseData["home_look_x"] = profile.homeLookAt.X.ToString();
responseData["home_look_y"] = profile.homeLookAt.Y.ToString();
responseData["home_look_z"] = profile.homeLookAt.Z.ToString();
response.Value = responseData;
return response;
}
#region XMLRPC User Methods
public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
LLUUID queryID = new LLUUID(LLUUID.Zero.ToString());
if (requestData.Contains("avquery") && requestData.Contains("queryid"))
{
queryID = new LLUUID((string) requestData["queryid"]);
returnAvatar = GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
}
Console.WriteLine("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
}
public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
// Query Result Information
if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
{
// UserManagerBase.AddNewuserFriend
AddNewUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
// Query Result Information
if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
{
// UserManagerBase.AddNewuserFriend
RemoveUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]));
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
{
UpdateUserFriendPerms(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
// UserManagerBase.
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
List<FriendListItem> returndata = new List<FriendListItem>();
if (requestData.Contains("ownerID"))
{
returndata = this.GetUserFriendList(new LLUUID((string)requestData["ownerID"]));
}
return FriendListItemListtoXmlRPCResponse(returndata);
}
public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
UserProfileData userProfile;
if (requestData.Contains("avatar_name"))
{
string query = (string) requestData["avatar_name"];
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
userProfile = GetUserProfile(querysplit[0], querysplit[1], "");
if (userProfile == null)
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
return ProfileToXmlRPCResponse(userProfile);
}
public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
UserProfileData userProfile;
//CFK: this clogs the UserServer log and is not necessary at this time.
//CFK: Console.WriteLine("METHOD BY UUID CALLED");
if (requestData.Contains("avatar_uuid"))
{
LLUUID guess = new LLUUID();
try
{
guess = new LLUUID((string)requestData["avatar_uuid"]);
//userProfile = GetUserProfile(guess);
string authAddr;
if (requestData["AuthenticationAddress"] == null)
authAddr = "";
else
authAddr = requestData["AuthenticationAddress"].ToString();
userProfile = GetUserProfile(guess, authAddr);
}
catch (FormatException)
{
return CreateUnknownUserErrorResponse();
}
catch (NullReferenceException)
{
Console.WriteLine("NullReferenceException occured");
return CreateUnknownUserErrorResponse();
}
if (userProfile == null)
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
return ProfileToXmlRPCResponse(userProfile);
}
#endregion
public override UserProfileData SetupMasterUser(string firstName, string lastName)
{
throw new Exception("The method or operation is not implemented.");
}
public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
{
throw new Exception("The method or operation is not implemented.");
}
public override UserProfileData SetupMasterUser(LLUUID uuid)
{
throw new Exception("The method or operation is not implemented.");
}
}
}
/*
* 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;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using libsecondlife;
using Nwc.XmlRpc;
using OpenSim.Framework;
using OpenSim.Framework.Statistics;
using OpenSim.Framework.UserManagement;
namespace OpenSim.Grid.UserServer
{
public class UserManager : UserManagerBase
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Deletes an active agent session
/// </summary>
/// <param name="request">The request</param>
/// <param name="path">The path (eg /bork/narf/test)</param>
/// <param name="param">Parameters sent</param>
/// <returns>Success "OK" else error</returns>
public string RestDeleteUserSessionMethod(string request, string path, string param)
{
// TODO! Important!
return "OK";
}
/// <summary>
/// Returns an error message that the user could not be found in the database
/// </summary>
/// <returns>XML string consisting of a error element containing individual error(s)</returns>
public XmlRpcResponse CreateUnknownUserErrorResponse()
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
responseData["error_type"] = "unknown_user";
responseData["error_desc"] = "The user requested is not in the database";
response.Value = responseData;
return response;
}
public XmlRpcResponse AvatarPickerListtoXmlRPCResponse(LLUUID queryID, List<AvatarPickerAvatar> returnUsers)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Query Result Information
responseData["queryid"] = (string) queryID.ToString();
responseData["avcount"] = (string) returnUsers.Count.ToString();
for (int i = 0; i < returnUsers.Count; i++)
{
responseData["avatarid" + i.ToString()] = returnUsers[i].AvatarID.ToString();
responseData["firstname" + i.ToString()] = returnUsers[i].firstName;
responseData["lastname" + i.ToString()] = returnUsers[i].lastName;
}
response.Value = responseData;
return response;
}
public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List<FriendListItem> returnUsers)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Query Result Information
responseData["avcount"] = (string)returnUsers.Count.ToString();
for (int i = 0; i < returnUsers.Count; i++)
{
responseData["ownerID" + i.ToString()] = returnUsers[i].FriendListOwner.UUID.ToString();
responseData["friendID" + i.ToString()] = returnUsers[i].Friend.UUID.ToString();
responseData["ownerPerms" + i.ToString()] = returnUsers[i].FriendListOwnerPerms.ToString();
responseData["friendPerms" + i.ToString()] = returnUsers[i].FriendPerms.ToString();
}
response.Value = responseData;
return response;
}
/// <summary>
/// Converts a user profile to an XML element which can be returned
/// </summary>
/// <param name="profile">The user profile</param>
/// <returns>A string containing an XML Document of the user profile</returns>
public XmlRpcResponse ProfileToXmlRPCResponse(UserProfileData profile)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable responseData = new Hashtable();
// Account information
responseData["firstname"] = profile.username;
responseData["lastname"] = profile.surname;
responseData["uuid"] = profile.UUID.ToString();
// Server Information
responseData["server_inventory"] = profile.userInventoryURI;
responseData["server_asset"] = profile.userAssetURI;
// Profile Information
responseData["profile_about"] = profile.profileAboutText;
responseData["profile_firstlife_about"] = profile.profileFirstText;
responseData["profile_firstlife_image"] = profile.profileFirstImage.ToString();
responseData["profile_can_do"] = profile.profileCanDoMask.ToString();
responseData["profile_want_do"] = profile.profileWantDoMask.ToString();
responseData["profile_image"] = profile.profileImage.ToString();
responseData["profile_created"] = profile.created.ToString();
responseData["profile_lastlogin"] = profile.lastLogin.ToString();
// Home region information
responseData["home_coordinates_x"] = profile.homeLocation.X.ToString();
responseData["home_coordinates_y"] = profile.homeLocation.Y.ToString();
responseData["home_coordinates_z"] = profile.homeLocation.Z.ToString();
responseData["home_region"] = profile.homeRegion.ToString();
responseData["home_look_x"] = profile.homeLookAt.X.ToString();
responseData["home_look_y"] = profile.homeLookAt.Y.ToString();
responseData["home_look_z"] = profile.homeLookAt.Z.ToString();
response.Value = responseData;
return response;
}
#region XMLRPC User Methods
public XmlRpcResponse XmlRPCGetAvatarPickerAvatar(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
List<AvatarPickerAvatar> returnAvatar = new List<AvatarPickerAvatar>();
LLUUID queryID = new LLUUID(LLUUID.Zero.ToString());
if (requestData.Contains("avquery") && requestData.Contains("queryid"))
{
queryID = new LLUUID((string) requestData["queryid"]);
returnAvatar = GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
}
Console.WriteLine("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
return AvatarPickerListtoXmlRPCResponse(queryID, returnAvatar);
}
public XmlRpcResponse XmlRpcResponseXmlRPCAddUserFriend(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
// Query Result Information
if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
{
// UserManagerBase.AddNewuserFriend
AddNewUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCRemoveUserFriend(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
// Query Result Information
if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
{
// UserManagerBase.AddNewuserFriend
RemoveUserFriend(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]));
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCUpdateUserFriendPerms(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
string returnString = "FALSE";
if (requestData.Contains("ownerID") && requestData.Contains("friendID") && requestData.Contains("friendPerms"))
{
UpdateUserFriendPerms(new LLUUID((string)requestData["ownerID"]), new LLUUID((string)requestData["friendID"]), (uint)Convert.ToInt32((string)requestData["friendPerms"]));
// UserManagerBase.
returnString = "TRUE";
}
responseData["returnString"] = returnString;
response.Value = responseData;
return response;
}
public XmlRpcResponse XmlRpcResponseXmlRPCGetUserFriendList(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable responseData = new Hashtable();
List<FriendListItem> returndata = new List<FriendListItem>();
if (requestData.Contains("ownerID"))
{
returndata = this.GetUserFriendList(new LLUUID((string)requestData["ownerID"]));
}
return FriendListItemListtoXmlRPCResponse(returndata);
}
public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
UserProfileData userProfile;
if (requestData.Contains("avatar_name"))
{
string query = (string) requestData["avatar_name"];
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
userProfile = GetUserProfile(querysplit[0], querysplit[1], "");
if (userProfile == null)
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
return ProfileToXmlRPCResponse(userProfile);
}
public XmlRpcResponse XmlRPCGetUserMethodUUID(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable) request.Params[0];
UserProfileData userProfile;
//CFK: this clogs the UserServer log and is not necessary at this time.
//CFK: Console.WriteLine("METHOD BY UUID CALLED");
if (requestData.Contains("avatar_uuid"))
{
LLUUID guess = new LLUUID();
try
{
guess = new LLUUID((string)requestData["avatar_uuid"]);
//userProfile = GetUserProfile(guess);
string authAddr;
if (requestData["AuthenticationAddress"] == null)
authAddr = "";
else
authAddr = requestData["AuthenticationAddress"].ToString();
userProfile = GetUserProfile(guess, authAddr);
}
catch (FormatException)
{
return CreateUnknownUserErrorResponse();
}
catch (NullReferenceException)
{
Console.WriteLine("NullReferenceException occured");
return CreateUnknownUserErrorResponse();
}
if (userProfile == null)
{
return CreateUnknownUserErrorResponse();
}
}
else
{
return CreateUnknownUserErrorResponse();
}
return ProfileToXmlRPCResponse(userProfile);
}
public XmlRpcResponse XmlRPCLogOffUserMethodUUID(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
UserProfileData userProfile;
if (requestData.Contains("avatar_uuid"))
{
try
{
LLUUID userUUID = new LLUUID((string)requestData["avatar_uuid"]);
LLUUID RegionID = new LLUUID((string)requestData["region_uuid"]);
ulong regionhandle = (ulong)Convert.ToInt64((string)requestData["region_handle"]);
float posx = (float)Convert.ToDecimal((string)requestData["region_pos_x"]);
float posy = (float)Convert.ToDecimal((string)requestData["region_pos_y"]);
float posz = (float)Convert.ToDecimal((string)requestData["region_pos_z"]);
LogOffUser(userUUID, RegionID, regionhandle, posx, posy, posz);
}
catch (FormatException)
{
m_log.Warn("[LOGOUT]: Error in Logout XMLRPC Params");
return response;
}
}
else
{
return CreateUnknownUserErrorResponse();
}
return response;
}
#endregion
public override UserProfileData SetupMasterUser(string firstName, string lastName)
{
throw new Exception("The method or operation is not implemented.");
}
public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
{
throw new Exception("The method or operation is not implemented.");
}
public override UserProfileData SetupMasterUser(LLUUID uuid)
{
throw new Exception("The method or operation is not implemented.");
}
}
}