From 2a91f21d082aee4dc97b5b0d29e1739cfe409024 Mon Sep 17 00:00:00 2001 From: MW Date: Tue, 24 Feb 2009 13:33:57 +0000 Subject: More refactoring of the UserServer. --- OpenSim/Grid/UserServer/IUGAIMCore.cs | 43 +++++ OpenSim/Grid/UserServer/Main.cs | 179 ++++++++++++-------- OpenSim/Grid/UserServer/MessageServersConnector.cs | 26 +++ OpenSim/Grid/UserServer/UserLoginService.cs | 26 +++ OpenSim/Grid/UserServer/UserManager.cs | 187 ++++----------------- .../UserServer/UserServerAvatarAppearanceModule.cs | 124 ++++++++++++++ OpenSim/Grid/UserServer/UserServerFriendsModule.cs | 173 +++++++++++++++++++ 7 files changed, 529 insertions(+), 229 deletions(-) create mode 100644 OpenSim/Grid/UserServer/IUGAIMCore.cs create mode 100644 OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs create mode 100644 OpenSim/Grid/UserServer/UserServerFriendsModule.cs (limited to 'OpenSim') diff --git a/OpenSim/Grid/UserServer/IUGAIMCore.cs b/OpenSim/Grid/UserServer/IUGAIMCore.cs new file mode 100644 index 0000000..0783fe5 --- /dev/null +++ b/OpenSim/Grid/UserServer/IUGAIMCore.cs @@ -0,0 +1,43 @@ +/* + * 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 OpenSimulator 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; +using OpenSim.Framework.Servers; + +namespace OpenSim.Grid.UserServer +{ + public interface IUGAIMCore + { + T Get(); + void RegisterInterface(T iface); + bool TryGet(out T iface); + BaseHttpServer GetHttpServer(); + + } +} diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 1e6504d..efa090e 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -46,7 +46,7 @@ namespace OpenSim.Grid.UserServer /// /// Grid user server main class /// - public class OpenUser_Main : BaseOpenSimServer + public class OpenUser_Main : BaseOpenSimServer, IUGAIMCore { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -55,6 +55,10 @@ namespace OpenSim.Grid.UserServer protected UserDataBaseService m_userDataBaseService; public UserManager m_userManager; + + protected UserServerAvatarAppearanceModule m_avatarAppearanceModule; + protected UserServerFriendsModule m_friendsModule; + public UserLoginService m_loginService; public GridInfoService m_gridInfoService; public MessageServersConnector m_messagesService; @@ -99,17 +103,64 @@ namespace OpenSim.Grid.UserServer IInterServiceInventoryServices inventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl); + //setup database access service m_userDataBaseService = new UserDataBaseService(inventoryService); m_userDataBaseService.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect); - StartupUserManager(inventoryService); + //Register the database access service so modules can fetch it + // RegisterInterface(m_userDataBaseService); + + //setup services/modules + StartupUserServerModules(); m_gridInfoService = new GridInfoService(); StartupLoginService(inventoryService); + // + // Get the minimum defaultLevel to access to the grid + // + m_loginService.setloginlevel((int)Cfg.DefaultUserLevel); m_messagesService = new MessageServersConnector(); + //register event handlers + RegisterEventHandlers(); + + //register http handlers and start http server + m_log.Info("[STARTUP]: Starting HTTP process"); + m_httpServer = new BaseHttpServer(Cfg.HttpPort); + RegisterHttpHandlers(); + m_httpServer.Start(); + + base.StartupSpecific(); + + //register Console command handlers + RegisterConsoleCommands(); + } + + /// + /// Start up the user manager + /// + /// + protected virtual void StartupUserServerModules() + { + m_userManager = new UserManager(m_userDataBaseService); + m_avatarAppearanceModule = new UserServerAvatarAppearanceModule(m_userDataBaseService); + m_friendsModule = new UserServerFriendsModule(m_userDataBaseService); + } + + /// + /// Start up the login service + /// + /// + protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService) + { + m_loginService = new UserLoginService( + m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); + } + + protected virtual void RegisterEventHandlers() + { m_loginService.OnUserLoggedInAtLocation += NotifyMessageServersUserLoggedInToLocation; m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff; @@ -117,15 +168,10 @@ namespace OpenSim.Grid.UserServer m_messagesService.OnAgentLeaving += HandleAgentLeaving; m_messagesService.OnRegionStartup += HandleRegionStartup; m_messagesService.OnRegionShutdown += HandleRegionShutdown; + } - m_log.Info("[STARTUP]: Starting HTTP process"); - - m_httpServer = new BaseHttpServer(Cfg.HttpPort); - AddHttpHandlers(); - m_httpServer.Start(); - - base.StartupSpecific(); - + protected virtual void RegisterConsoleCommands() + { m_console.Commands.AddCommand("userserver", false, "create user", "create user [ [ [ [email]]]]", "Create a new user account", RunCommand); @@ -156,80 +202,67 @@ namespace OpenSim.Grid.UserServer "Log off a named user", RunCommand); } - /// - /// Start up the user manager - /// - /// - protected virtual void StartupUserManager(IInterServiceInventoryServices inventoryService) + protected virtual void RegisterHttpHandlers() { - m_userManager = new UserManager(inventoryService, m_userDataBaseService); + m_loginService.RegisterHandlers(m_httpServer, Cfg.EnableLLSDLogin, true); + + m_userManager.RegisterHandlers(m_httpServer); + m_friendsModule.RegisterHandlers(m_httpServer); + m_avatarAppearanceModule.RegisterHandlers(m_httpServer); + m_messagesService.RegisterHandlers(m_httpServer); + + m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", + m_gridInfoService.RestGetGridInfoMethod)); + m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod); } + public override void ShutdownSpecific() + { + m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation; + } + + #region IUGAIMCore + private readonly Dictionary m_moduleInterfaces = new Dictionary(); + /// - /// Start up the login service + /// Register an Module interface. /// - /// - protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService) + /// + /// + public void RegisterInterface(T iface) { - m_loginService = new UserLoginService( - m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy()); + lock (m_moduleInterfaces) + { + if (!m_moduleInterfaces.ContainsKey(typeof(T))) + { + m_moduleInterfaces.Add(typeof(T), iface); + } + } } - protected virtual void AddHttpHandlers() + public bool TryGet(out T iface) { - m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod); - - m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin); - // - // Get the minimum defaultLevel to access to the grid - // - m_loginService.setloginlevel((int)Cfg.DefaultUserLevel); - - if (Cfg.EnableLLSDLogin) + if (m_moduleInterfaces.ContainsKey(typeof(T))) { - m_httpServer.SetDefaultLLSDHandler(m_loginService.LLSDLoginMethod); + iface = (T)m_moduleInterfaces[typeof(T)]; + return true; } + iface = default(T); + return false; + } - m_httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); - m_httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); - m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar); - m_httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend); - m_httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend); - m_httpServer.AddXmlRPCHandler("update_user_friend_perms", - m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms); - m_httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); - m_httpServer.AddXmlRPCHandler("get_avatar_appearance", m_userManager.XmlRPCGetAvatarAppearance); - m_httpServer.AddXmlRPCHandler("update_avatar_appearance", m_userManager.XmlRPCUpdateAvatarAppearance); - m_httpServer.AddXmlRPCHandler("update_user_current_region", m_userManager.XmlRPCAtRegion); - m_httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID); - m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", m_userManager.XmlRPCGetAgentMethodUUID); - m_httpServer.AddXmlRPCHandler("check_auth_session", m_userManager.XmlRPCCheckAuthSession); - m_httpServer.AddXmlRPCHandler("set_login_params", m_loginService.XmlRPCSetLoginParams); - m_httpServer.AddXmlRPCHandler("region_startup", m_messagesService.RegionStartup); - m_httpServer.AddXmlRPCHandler("region_shutdown", m_messagesService.RegionShutdown); - m_httpServer.AddXmlRPCHandler("agent_location", m_messagesService.AgentLocation); - m_httpServer.AddXmlRPCHandler("agent_leaving", m_messagesService.AgentLeaving); - // Message Server ---> User Server - m_httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer); - m_httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion); - m_httpServer.AddXmlRPCHandler("deregister_messageserver", m_messagesService.XmlRPCDeRegisterMessageServer); - - m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", - m_gridInfoService.RestGetGridInfoMethod)); - m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod); - - m_httpServer.AddStreamHandler( - new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); - - m_httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile); + public T Get() + { + return (T)m_moduleInterfaces[typeof(T)]; + } - // Handler for OpenID avatar identity pages - m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", m_loginService)); - // Handlers for the OpenID endpoint server - m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", m_loginService)); - m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", m_loginService)); + public BaseHttpServer GetHttpServer() + { + return m_httpServer; } + #endregion + #region Console Command Handlers public void do_create(string[] args) { switch (args[0]) @@ -468,19 +501,16 @@ namespace OpenSim.Grid.UserServer m_console.Notice("login-level - Set the miminim userlevel allowed To login."); m_console.Notice("login-reset - reset the login level to its default value."); m_console.Notice("login-text "); - - } - public override void ShutdownSpecific() - { - m_loginService.OnUserLoggedInAtLocation -= NotifyMessageServersUserLoggedInToLocation; } + #endregion public void TestResponse(List resp) { m_console.Notice("response got"); } + #region Event Handlers public void NotifyMessageServersUserLoggOff(UUID agentID) { m_messagesService.TellMessageServersAboutUserLogoff(agentID); @@ -531,5 +561,6 @@ namespace OpenSim.Grid.UserServer m_userManager.HandleRegionShutdown(regionID); m_messagesService.TellMessageServersAboutRegionShutdown(regionID); } + #endregion } } diff --git a/OpenSim/Grid/UserServer/MessageServersConnector.cs b/OpenSim/Grid/UserServer/MessageServersConnector.cs index 8d16109..1d0649c 100644 --- a/OpenSim/Grid/UserServer/MessageServersConnector.cs +++ b/OpenSim/Grid/UserServer/MessageServersConnector.cs @@ -71,6 +71,8 @@ namespace OpenSim.Grid.UserServer public Dictionary MessageServers; + private BaseHttpServer m_httpServer; + private BlockingQueue m_NotifyQueue = new BlockingQueue(); @@ -88,6 +90,30 @@ namespace OpenSim.Grid.UserServer m_NotifyThread.Start(); } + public void Initialise() + { + + } + + public void PostInitialise() + { + + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + m_httpServer.AddXmlRPCHandler("region_startup", RegionStartup); + m_httpServer.AddXmlRPCHandler("region_shutdown", RegionShutdown); + m_httpServer.AddXmlRPCHandler("agent_location", AgentLocation); + m_httpServer.AddXmlRPCHandler("agent_leaving", AgentLeaving); + // Message Server ---> User Server + m_httpServer.AddXmlRPCHandler("register_messageserver", XmlRPCRegisterMessageServer); + m_httpServer.AddXmlRPCHandler("agent_change_region", XmlRPCUserMovedtoRegion); + m_httpServer.AddXmlRPCHandler("deregister_messageserver", XmlRPCDeRegisterMessageServer); + } + public void RegisterMessageServer(string URI, MessageServerInfo serverData) { lock (MessageServers) diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 0bec2a1..0cb4976 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -38,6 +38,7 @@ using OpenSim.Framework; using OpenSim.Framework.Communications; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Capabilities; +using OpenSim.Framework.Servers; namespace OpenSim.Grid.UserServer { @@ -61,6 +62,8 @@ namespace OpenSim.Grid.UserServer public UserConfig m_config; private readonly IRegionProfileService m_regionProfileService; + protected BaseHttpServer m_httpServer; + public UserLoginService( UserManagerBase userManager, IInterServiceInventoryServices inventoryService, LibraryRootFolder libraryRootFolder, @@ -71,6 +74,29 @@ namespace OpenSim.Grid.UserServer m_inventoryService = inventoryService; m_regionProfileService = regionProfileService; } + + public void RegisterHandlers(BaseHttpServer httpServer, bool registerLLSDHandler, bool registerOpenIDHandlers) + { + m_httpServer = httpServer; + + m_httpServer.AddXmlRPCHandler("login_to_simulator", XmlRpcLoginMethod); + m_httpServer.AddHTTPHandler("login", ProcessHTMLLogin); + m_httpServer.AddXmlRPCHandler("set_login_params", XmlRPCSetLoginParams); + + if (registerLLSDHandler) + { + m_httpServer.SetDefaultLLSDHandler(LLSDLoginMethod); + } + + if (registerOpenIDHandlers) + { + // Handler for OpenID avatar identity pages + m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", this)); + // Handlers for the OpenID endpoint server + m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", this)); + m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", this)); + } + } public void setloginlevel(int level) { diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index 6229dec..ca50421 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -48,16 +48,45 @@ namespace OpenSim.Grid.UserServer private logOffUser handlerLogOffUser; private UserDataBaseService m_userDataBaseService; + private BaseHttpServer m_httpServer; /// - /// Constructor + /// /// - /// - public UserManager(IInterServiceInventoryServices interServiceInventoryService, UserDataBaseService userDataBaseService) + /// + public UserManager( UserDataBaseService userDataBaseService) { m_userDataBaseService = userDataBaseService; } + public void Initialise() + { + + } + + public void PostInitialise() + { + + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + m_httpServer.AddXmlRPCHandler("get_user_by_name", XmlRPCGetUserMethodName); + m_httpServer.AddXmlRPCHandler("get_user_by_uuid", XmlRPCGetUserMethodUUID); + m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", XmlRPCGetAvatarPickerAvatar); + + m_httpServer.AddXmlRPCHandler("update_user_current_region", XmlRPCAtRegion); + m_httpServer.AddXmlRPCHandler("logout_of_simulator", XmlRPCLogOffUserMethodUUID); + m_httpServer.AddXmlRPCHandler("get_agent_by_uuid", XmlRPCGetAgentMethodUUID); + m_httpServer.AddXmlRPCHandler("check_auth_session", XmlRPCCheckAuthSession); + + m_httpServer.AddXmlRPCHandler("update_user_profile", XmlRpcResponseXmlRPCUpdateUserProfile); + + m_httpServer.AddStreamHandler(new RestStreamHandler("DELETE", "/usersessions/", RestDeleteUserSessionMethod)); + } + /// /// Deletes an active agent session /// @@ -109,26 +138,6 @@ namespace OpenSim.Grid.UserServer return response; } - public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List returnUsers) - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable responseData = new Hashtable(); - // Query Result Information - - responseData["avcount"] = returnUsers.Count.ToString(); - - for (int i = 0; i < returnUsers.Count; i++) - { - responseData["ownerID" + i] = returnUsers[i].FriendListOwner.ToString(); - responseData["friendID" + i] = returnUsers[i].Friend.ToString(); - responseData["ownerPerms" + i] = returnUsers[i].FriendListOwnerPerms.ToString(); - responseData["friendPerms" + i] = returnUsers[i].FriendPerms.ToString(); - } - response.Value = responseData; - - return response; - } - /// /// Converts a user profile to an XML element which can be returned /// @@ -230,138 +239,6 @@ namespace OpenSim.Grid.UserServer return response; } - 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 - m_userDataBaseService.AddNewUserFriend(new UUID((string)requestData["ownerID"]), - new UUID((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 - m_userDataBaseService.RemoveUserFriend(new UUID((string)requestData["ownerID"]), - new UUID((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")) - { - m_userDataBaseService.UpdateUserFriendPerms(new UUID((string)requestData["ownerID"]), - new UUID((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 returndata = new List(); - - if (requestData.Contains("ownerID")) - { - returndata = m_userDataBaseService.GetUserFriendList(new UUID((string)requestData["ownerID"])); - } - - return FriendListItemListtoXmlRPCResponse(returndata); - } - - public XmlRpcResponse XmlRPCGetAvatarAppearance(XmlRpcRequest request) - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable) request.Params[0]; - AvatarAppearance appearance; - Hashtable responseData; - if (requestData.Contains("owner")) - { - appearance = m_userDataBaseService.GetUserAppearance(new UUID((string)requestData["owner"])); - if (appearance == null) - { - responseData = new Hashtable(); - responseData["error_type"] = "no appearance"; - responseData["error_desc"] = "There was no appearance found for this avatar"; - } - else - { - responseData = appearance.ToHashTable(); - } - } - else - { - responseData = new Hashtable(); - responseData["error_type"] = "unknown_avatar"; - responseData["error_desc"] = "The avatar appearance requested is not in the database"; - } - - response.Value = responseData; - return response; - } - - public XmlRpcResponse XmlRPCUpdateAvatarAppearance(XmlRpcRequest request) - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable) request.Params[0]; - Hashtable responseData; - if (requestData.Contains("owner")) - { - AvatarAppearance appearance = new AvatarAppearance(requestData); - m_userDataBaseService.UpdateUserAppearance(new UUID((string)requestData["owner"]), appearance); - responseData = new Hashtable(); - responseData["returnString"] = "TRUE"; - } - else - { - responseData = new Hashtable(); - responseData["error_type"] = "unknown_avatar"; - responseData["error_desc"] = "The avatar appearance requested is not in the database"; - } - response.Value = responseData; - return response; - } - public XmlRpcResponse XmlRPCGetUserMethodName(XmlRpcRequest request) { // XmlRpcResponse response = new XmlRpcResponse(); diff --git a/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs b/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs new file mode 100644 index 0000000..28ac2dc --- /dev/null +++ b/OpenSim/Grid/UserServer/UserServerAvatarAppearanceModule.cs @@ -0,0 +1,124 @@ +/* + * 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.Reflection; +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Servers; + +namespace OpenSim.Grid.UserServer +{ + public class UserServerAvatarAppearanceModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private UserDataBaseService m_userDataBaseService; + private BaseHttpServer m_httpServer; + + public UserServerAvatarAppearanceModule(UserDataBaseService userDataBaseService) + { + m_userDataBaseService = userDataBaseService; + } + + public void Initialise() + { + + } + + public void PostInitialise() + { + + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + m_httpServer.AddXmlRPCHandler("get_avatar_appearance", XmlRPCGetAvatarAppearance); + m_httpServer.AddXmlRPCHandler("update_avatar_appearance", XmlRPCUpdateAvatarAppearance); + } + + public XmlRpcResponse XmlRPCGetAvatarAppearance(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + AvatarAppearance appearance; + Hashtable responseData; + if (requestData.Contains("owner")) + { + appearance = m_userDataBaseService.GetUserAppearance(new UUID((string)requestData["owner"])); + if (appearance == null) + { + responseData = new Hashtable(); + responseData["error_type"] = "no appearance"; + responseData["error_desc"] = "There was no appearance found for this avatar"; + } + else + { + responseData = appearance.ToHashTable(); + } + } + else + { + responseData = new Hashtable(); + responseData["error_type"] = "unknown_avatar"; + responseData["error_desc"] = "The avatar appearance requested is not in the database"; + } + + response.Value = responseData; + return response; + } + + public XmlRpcResponse XmlRPCUpdateAvatarAppearance(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable responseData; + if (requestData.Contains("owner")) + { + AvatarAppearance appearance = new AvatarAppearance(requestData); + m_userDataBaseService.UpdateUserAppearance(new UUID((string)requestData["owner"]), appearance); + responseData = new Hashtable(); + responseData["returnString"] = "TRUE"; + } + else + { + responseData = new Hashtable(); + responseData["error_type"] = "unknown_avatar"; + responseData["error_desc"] = "The avatar appearance requested is not in the database"; + } + response.Value = responseData; + return response; + } + } +} diff --git a/OpenSim/Grid/UserServer/UserServerFriendsModule.cs b/OpenSim/Grid/UserServer/UserServerFriendsModule.cs new file mode 100644 index 0000000..4a3efe0 --- /dev/null +++ b/OpenSim/Grid/UserServer/UserServerFriendsModule.cs @@ -0,0 +1,173 @@ +/* + * 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.Reflection; +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Servers; + +namespace OpenSim.Grid.UserServer +{ + public class UserServerFriendsModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private UserDataBaseService m_userDataBaseService; + + private BaseHttpServer m_httpServer; + + public UserServerFriendsModule(UserDataBaseService userDataBaseService) + { + m_userDataBaseService = userDataBaseService; + } + + public void Initialise() + { + + } + + public void PostInitialise() + { + + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + m_httpServer.AddXmlRPCHandler("add_new_user_friend", XmlRpcResponseXmlRPCAddUserFriend); + m_httpServer.AddXmlRPCHandler("remove_user_friend", XmlRpcResponseXmlRPCRemoveUserFriend); + m_httpServer.AddXmlRPCHandler("update_user_friend_perms", XmlRpcResponseXmlRPCUpdateUserFriendPerms); + m_httpServer.AddXmlRPCHandler("get_user_friend_list", XmlRpcResponseXmlRPCGetUserFriendList); + } + + public XmlRpcResponse FriendListItemListtoXmlRPCResponse(List returnUsers) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable responseData = new Hashtable(); + // Query Result Information + + responseData["avcount"] = returnUsers.Count.ToString(); + + for (int i = 0; i < returnUsers.Count; i++) + { + responseData["ownerID" + i] = returnUsers[i].FriendListOwner.ToString(); + responseData["friendID" + i] = returnUsers[i].Friend.ToString(); + responseData["ownerPerms" + i] = returnUsers[i].FriendListOwnerPerms.ToString(); + responseData["friendPerms" + i] = returnUsers[i].FriendPerms.ToString(); + } + response.Value = responseData; + + return response; + } + + 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 + m_userDataBaseService.AddNewUserFriend(new UUID((string)requestData["ownerID"]), + new UUID((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 + m_userDataBaseService.RemoveUserFriend(new UUID((string)requestData["ownerID"]), + new UUID((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")) + { + m_userDataBaseService.UpdateUserFriendPerms(new UUID((string)requestData["ownerID"]), + new UUID((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 returndata = new List(); + + if (requestData.Contains("ownerID")) + { + returndata = m_userDataBaseService.GetUserFriendList(new UUID((string)requestData["ownerID"])); + } + + return FriendListItemListtoXmlRPCResponse(returndata); + } + } +} -- cgit v1.1