Part 1 of refactoring the userserver. Changed it so instead of subclassing the User dataBase access class (UserManagerBase) and then adding the http handlers to that. There is now a UserDataBaseService that is passed to the other classes so they can access the db. This should make it easier to have multiple "modules" that can register http handlers and access the db.

GenericGridServerConcept
MW 2009-02-22 11:01:26 +00:00
parent 88d3ce5c64
commit 9b0b0b5e28
3 changed files with 107 additions and 46 deletions

View File

@ -52,6 +52,8 @@ namespace OpenSim.Grid.UserServer
protected UserConfig Cfg;
protected UserDataBaseService m_userDataBaseService;
public UserManager m_userManager;
public UserLoginService m_loginService;
public GridInfoService m_gridInfoService;
@ -97,8 +99,10 @@ namespace OpenSim.Grid.UserServer
IInterServiceInventoryServices inventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl);
m_userDataBaseService = new UserDataBaseService(inventoryService);
m_userDataBaseService.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect);
StartupUserManager(inventoryService);
m_userManager.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect);
m_gridInfoService = new GridInfoService();
@ -158,7 +162,7 @@ namespace OpenSim.Grid.UserServer
/// <param name="inventoryService"></param>
protected virtual void StartupUserManager(IInterServiceInventoryServices inventoryService)
{
m_userManager = new UserManager(new OGS1InterServiceInventoryService(Cfg.InventoryUrl));
m_userManager = new UserManager(inventoryService, m_userDataBaseService);
}
/// <summary>
@ -168,7 +172,7 @@ namespace OpenSim.Grid.UserServer
protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService)
{
m_loginService = new UserLoginService(
m_userManager, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy());
m_userDataBaseService, inventoryService, new LibraryRootFolder(Cfg.LibraryXmlfile), Cfg, Cfg.DefaultStartupMsg, new RegionProfileServiceProxy());
}
protected virtual void AddHttpHandlers()
@ -297,9 +301,9 @@ namespace OpenSim.Grid.UserServer
email = MainConsole.Instance.CmdPrompt("Email", "");
else email = cmdparams[6];
if (null == m_userManager.GetUserProfile(firstName, lastName))
if (null == m_userDataBaseService.GetUserProfile(firstName, lastName))
{
m_lastCreatedUser = m_userManager.AddUser(firstName, lastName, password, email, regX, regY);
m_lastCreatedUser = m_userDataBaseService.AddUser(firstName, lastName, password, email, regX, regY);
}
else
{
@ -329,7 +333,7 @@ namespace OpenSim.Grid.UserServer
newPassword = MainConsole.Instance.PasswdPrompt("New password");
else newPassword = cmdparams[4];
m_userManager.ResetUserPassword(firstName, lastName, newPassword);
m_userDataBaseService.ResetUserPassword(firstName, lastName, newPassword);
}
private void HandleLoginCommand(string module, string[] cmd)

View File

@ -0,0 +1,68 @@
/*
* 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 UserDataBaseService : UserManagerBase
{
public UserDataBaseService()
: base(null)
{
}
public UserDataBaseService(IInterServiceInventoryServices interServiceInventoryService)
: base(interServiceInventoryService)
{
}
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(UUID uuid)
{
throw new Exception("The method or operation is not implemented.");
}
}
}

View File

@ -40,20 +40,23 @@ namespace OpenSim.Grid.UserServer
{
public delegate void logOffUser(UUID AgentID);
public class UserManager : UserManagerBase
public class UserManager
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public event logOffUser OnLogOffUser;
private logOffUser handlerLogOffUser;
private UserDataBaseService m_userDataBaseService;
/// <summary>
/// Constructor
/// </summary>
/// <param name="interServiceInventoryService"></param>
public UserManager(IInterServiceInventoryServices interServiceInventoryService)
: base(interServiceInventoryService)
{}
public UserManager(IInterServiceInventoryServices interServiceInventoryService, UserDataBaseService userDataBaseService)
{
m_userDataBaseService = userDataBaseService;
}
/// <summary>
/// Deletes an active agent session
@ -185,7 +188,7 @@ namespace OpenSim.Grid.UserServer
if (requestData.Contains("avquery") && requestData.Contains("queryid"))
{
queryID = new UUID((string) requestData["queryid"]);
returnAvatar = GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
returnAvatar = m_userDataBaseService.GenerateAgentPickerRequestResponse(queryID, (string) requestData["avquery"]);
}
m_log.InfoFormat("[AVATARINFO]: Servicing Avatar Query: " + (string) requestData["avquery"]);
@ -211,11 +214,11 @@ namespace OpenSim.Grid.UserServer
if (avatarUUID != UUID.Zero)
{
UserProfileData userProfile = GetUserProfile(avatarUUID);
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(avatarUUID);
userProfile.CurrentAgent.Region = regionUUID;
userProfile.CurrentAgent.Handle = (ulong) Convert.ToInt64((string) requestData["region_handle"]);
//userProfile.CurrentAgent.
CommitAgent(ref userProfile);
m_userDataBaseService.CommitAgent(ref userProfile);
//setUserProfile(userProfile);
@ -239,7 +242,7 @@ namespace OpenSim.Grid.UserServer
requestData.Contains("friendPerms"))
{
// UserManagerBase.AddNewuserFriend
AddNewUserFriend(new UUID((string) requestData["ownerID"]),
m_userDataBaseService.AddNewUserFriend(new UUID((string)requestData["ownerID"]),
new UUID((string) requestData["friendID"]),
(uint) Convert.ToInt32((string) requestData["friendPerms"]));
returnString = "TRUE";
@ -260,7 +263,7 @@ namespace OpenSim.Grid.UserServer
if (requestData.Contains("ownerID") && requestData.Contains("friendID"))
{
// UserManagerBase.AddNewuserFriend
RemoveUserFriend(new UUID((string) requestData["ownerID"]),
m_userDataBaseService.RemoveUserFriend(new UUID((string)requestData["ownerID"]),
new UUID((string) requestData["friendID"]));
returnString = "TRUE";
}
@ -279,7 +282,7 @@ namespace OpenSim.Grid.UserServer
if (requestData.Contains("ownerID") && requestData.Contains("friendID") &&
requestData.Contains("friendPerms"))
{
UpdateUserFriendPerms(new UUID((string) requestData["ownerID"]),
m_userDataBaseService.UpdateUserFriendPerms(new UUID((string)requestData["ownerID"]),
new UUID((string) requestData["friendID"]),
(uint) Convert.ToInt32((string) requestData["friendPerms"]));
// UserManagerBase.
@ -300,7 +303,7 @@ namespace OpenSim.Grid.UserServer
if (requestData.Contains("ownerID"))
{
returndata = GetUserFriendList(new UUID((string) requestData["ownerID"]));
returndata = m_userDataBaseService.GetUserFriendList(new UUID((string)requestData["ownerID"]));
}
return FriendListItemListtoXmlRPCResponse(returndata);
@ -314,7 +317,7 @@ namespace OpenSim.Grid.UserServer
Hashtable responseData;
if (requestData.Contains("owner"))
{
appearance = GetUserAppearance(new UUID((string) requestData["owner"]));
appearance = m_userDataBaseService.GetUserAppearance(new UUID((string)requestData["owner"]));
if (appearance == null)
{
responseData = new Hashtable();
@ -345,7 +348,7 @@ namespace OpenSim.Grid.UserServer
if (requestData.Contains("owner"))
{
AvatarAppearance appearance = new AvatarAppearance(requestData);
UpdateUserAppearance(new UUID((string) requestData["owner"]), appearance);
m_userDataBaseService.UpdateUserAppearance(new UUID((string)requestData["owner"]), appearance);
responseData = new Hashtable();
responseData["returnString"] = "TRUE";
}
@ -374,7 +377,7 @@ namespace OpenSim.Grid.UserServer
if (querysplit.Length == 2)
{
userProfile = GetUserProfile(querysplit[0], querysplit[1]);
userProfile = m_userDataBaseService.GetUserProfile(querysplit[0], querysplit[1]);
if (userProfile == null)
{
return CreateUnknownUserErrorResponse();
@ -406,7 +409,7 @@ namespace OpenSim.Grid.UserServer
{
UUID guess = new UUID((string) requestData["avatar_uuid"]);
userProfile = GetUserProfile(guess);
userProfile = m_userDataBaseService.GetUserProfile(guess);
}
catch (FormatException)
{
@ -444,7 +447,7 @@ namespace OpenSim.Grid.UserServer
return CreateUnknownUserErrorResponse();
}
userProfile = GetUserProfile(guess);
userProfile = m_userDataBaseService.GetUserProfile(guess);
if (userProfile == null)
{
@ -497,7 +500,7 @@ namespace OpenSim.Grid.UserServer
{
return CreateUnknownUserErrorResponse();
}
userProfile = GetUserProfile(guess_aid);
userProfile = m_userDataBaseService.GetUserProfile(guess_aid);
if (userProfile != null && userProfile.CurrentAgent != null &&
userProfile.CurrentAgent.SessionID == guess_sid)
{
@ -529,7 +532,7 @@ namespace OpenSim.Grid.UserServer
}
UUID UserUUID = new UUID((string) requestData["avatar_uuid"]);
UserProfileData userProfile = GetUserProfile(UserUUID);
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(UserUUID);
if (null == userProfile)
{
return CreateUnknownUserErrorResponse();
@ -703,7 +706,7 @@ namespace OpenSim.Grid.UserServer
}
// call plugin!
bool ret = UpdateUserProfile(userProfile);
bool ret = m_userDataBaseService.UpdateUserProfile(userProfile);
responseData["returnString"] = ret.ToString();
response.Value = responseData;
return response;
@ -734,7 +737,7 @@ namespace OpenSim.Grid.UserServer
if (handlerLogOffUser != null)
handlerLogOffUser(userUUID);
LogOffUser(userUUID, RegionID, regionhandle, position, lookat);
m_userDataBaseService.LogOffUser(userUUID, RegionID, regionhandle, position, lookat);
}
catch (FormatException)
{
@ -752,35 +755,21 @@ namespace OpenSim.Grid.UserServer
#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(UUID uuid)
{
throw new Exception("The method or operation is not implemented.");
}
public void HandleAgentLocation(UUID agentID, UUID regionID, ulong regionHandle)
{
UserProfileData userProfile = GetUserProfile(agentID);
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
if (userProfile != null)
{
userProfile.CurrentAgent.Region = regionID;
userProfile.CurrentAgent.Handle = regionHandle;
CommitAgent(ref userProfile);
m_userDataBaseService.CommitAgent(ref userProfile);
}
}
public void HandleAgentLeaving(UUID agentID, UUID regionID, ulong regionHandle)
{
UserProfileData userProfile = GetUserProfile(agentID);
UserProfileData userProfile = m_userDataBaseService.GetUserProfile(agentID);
if (userProfile != null)
{
if (userProfile.CurrentAgent.Region == regionID)
@ -797,7 +786,7 @@ namespace OpenSim.Grid.UserServer
userAgent.Handle = regionHandle;
userProfile.LastLogin = userAgent.LogoutTime;
CommitAgent(ref userProfile);
m_userDataBaseService.CommitAgent(ref userProfile);
handlerLogOffUser = OnLogOffUser;
if (handlerLogOffUser != null)
@ -809,12 +798,12 @@ namespace OpenSim.Grid.UserServer
public void HandleRegionStartup(UUID regionID)
{
LogoutUsers(regionID);
m_userDataBaseService.LogoutUsers(regionID);
}
public void HandleRegionShutdown(UUID regionID)
{
LogoutUsers(regionID);
m_userDataBaseService.LogoutUsers(regionID);
}
}
}