2007-06-01 23:48:52 +00:00
|
|
|
/*
|
2007-06-05 20:40:37 +00:00
|
|
|
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
2007-06-01 23:48:52 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2007-06-05 20:40:37 +00:00
|
|
|
* * Neither the name of the OpenSim Project nor the
|
2007-06-01 23:48:52 +00:00
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
2007-06-05 20:40:37 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
2007-06-01 23:48:52 +00:00
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2007-06-05 20:40:37 +00:00
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
2007-06-01 23:48:52 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2007-05-07 16:53:22 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using OpenGrid.Framework.Data;
|
|
|
|
using libsecondlife;
|
|
|
|
|
|
|
|
namespace OpenGrid.Framework.Data.DB4o
|
|
|
|
{
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A User storage interface for the DB4o database system
|
|
|
|
/// </summary>
|
2007-05-07 16:53:22 +00:00
|
|
|
public class DB4oUserData : IUserData
|
|
|
|
{
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The database manager
|
|
|
|
/// </summary>
|
2007-05-16 21:10:45 +00:00
|
|
|
DB4oUserManager manager;
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Artificial constructor called upon plugin load
|
|
|
|
/// </summary>
|
2007-05-16 21:10:45 +00:00
|
|
|
public void Initialise()
|
|
|
|
{
|
|
|
|
manager = new DB4oUserManager("userprofiles.yap");
|
|
|
|
}
|
2007-05-07 16:53:22 +00:00
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Loads a specified user profile from a UUID
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="uuid">The users UUID</param>
|
|
|
|
/// <returns>A user profile</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserProfileData getUserByUUID(LLUUID uuid)
|
|
|
|
{
|
|
|
|
if(manager.userProfiles.ContainsKey(uuid))
|
|
|
|
return manager.userProfiles[uuid];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a user by searching for its name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The users account name</param>
|
|
|
|
/// <returns>A matching users profile</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserProfileData getUserByName(string name)
|
|
|
|
{
|
|
|
|
return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a user by searching for its name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fname">The first part of the users account name</param>
|
|
|
|
/// <param name="lname">The second part of the users account name</param>
|
|
|
|
/// <returns>A matching users profile</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserProfileData getUserByName(string fname, string lname)
|
|
|
|
{
|
|
|
|
foreach (UserProfileData profile in manager.userProfiles.Values)
|
|
|
|
{
|
|
|
|
if (profile.username == fname && profile.surname == lname)
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a user by UUID direct
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="uuid">The users account ID</param>
|
|
|
|
/// <returns>A matching users profile</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserAgentData getAgentByUUID(LLUUID uuid)
|
2007-05-16 21:10:45 +00:00
|
|
|
{
|
2007-05-07 16:53:22 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return getUserByUUID(uuid).currentAgent;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a session by account name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The account name</param>
|
|
|
|
/// <returns>The users session agent</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserAgentData getAgentByName(string name)
|
|
|
|
{
|
|
|
|
return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a session by account name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fname">The first part of the users account name</param>
|
|
|
|
/// <param name="lname">The second part of the users account name</param>
|
|
|
|
/// <returns>A user agent</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public UserAgentData getAgentByName(string fname, string lname)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return getUserByName(fname,lname).currentAgent;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new user profile
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The profile to add to the database</param>
|
2007-05-25 16:27:07 +00:00
|
|
|
public void addNewUserProfile(UserProfileData user)
|
|
|
|
{
|
2007-06-01 23:48:52 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
manager.AddRow(user);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
}
|
2007-05-25 16:27:07 +00:00
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new user agent
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="agent">The agent to add to the database</param>
|
2007-05-26 06:29:22 +00:00
|
|
|
public void addNewUserAgent(UserAgentData agent)
|
|
|
|
{
|
|
|
|
// Do nothing. yet.
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Transfers money between two user accounts
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="from">Starting account</param>
|
|
|
|
/// <param name="to">End account</param>
|
|
|
|
/// <param name="amount">The amount to move</param>
|
|
|
|
/// <returns>Success?</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Transfers inventory between two accounts
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Move to inventory server</remarks>
|
|
|
|
/// <param name="from">Senders account</param>
|
|
|
|
/// <param name="to">Recievers account</param>
|
|
|
|
/// <param name="item">Inventory item</param>
|
|
|
|
/// <returns>Success?</returns>
|
2007-05-07 16:53:22 +00:00
|
|
|
public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the name of the storage provider
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Storage provider name</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public string getName()
|
|
|
|
{
|
|
|
|
return "DB4o Userdata";
|
|
|
|
}
|
|
|
|
|
2007-06-01 23:48:52 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the version of the storage provider
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Storage provider version</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public string getVersion()
|
|
|
|
{
|
|
|
|
return "0.1";
|
|
|
|
}
|
2007-05-07 16:53:22 +00:00
|
|
|
}
|
|
|
|
}
|