2007-06-02 00:37:31 +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-02 00:37:31 +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-02 00:37:31 +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-02 00:37:31 +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-02 00:37:31 +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-16 21:10:45 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using OpenGrid.Framework.Data;
|
|
|
|
using libsecondlife;
|
|
|
|
|
|
|
|
namespace OpenGrid.Framework.Data.MySQL
|
|
|
|
{
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A database interface class to a user profile storage system
|
|
|
|
/// </summary>
|
2007-05-16 21:10:45 +00:00
|
|
|
class MySQLUserData : IUserData
|
|
|
|
{
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Database manager for MySQL
|
|
|
|
/// </summary>
|
2007-05-20 14:29:08 +00:00
|
|
|
public MySQLManager database;
|
2007-05-16 21:10:45 +00:00
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Loads and initialises the MySQL storage plugin
|
|
|
|
/// </summary>
|
2007-05-16 21:10:45 +00:00
|
|
|
public void Initialise()
|
|
|
|
{
|
2007-06-02 00:37:31 +00:00
|
|
|
// Load from an INI file connection details
|
|
|
|
// TODO: move this to XML?
|
2007-05-25 08:21:16 +00:00
|
|
|
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
|
|
|
|
string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
|
|
|
|
string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
|
|
|
|
string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
|
|
|
|
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
|
|
|
|
string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
|
|
|
|
string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
|
|
|
|
|
|
|
|
database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
|
2007-05-16 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Searches the database for a specified user profile
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The account name of the user</param>
|
|
|
|
/// <returns>A user profile</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserProfileData getUserByName(string name)
|
|
|
|
{
|
|
|
|
return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Searches the database for a specified user profile by name components
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The first part of the account name</param>
|
|
|
|
/// <param name="last">The second part of the account name</param>
|
|
|
|
/// <returns>A user profile</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserProfileData getUserByName(string user, string last)
|
|
|
|
{
|
2007-05-20 14:29:08 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> param = new Dictionary<string, string>();
|
|
|
|
param["?first"] = user;
|
|
|
|
param["?second"] = last;
|
|
|
|
|
|
|
|
System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param);
|
|
|
|
System.Data.IDataReader reader = result.ExecuteReader();
|
|
|
|
|
2007-05-31 14:05:19 +00:00
|
|
|
UserProfileData row = database.readUserRow(reader);
|
2007-05-20 14:29:08 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2007-05-30 02:36:48 +00:00
|
|
|
database.Reconnect();
|
2007-05-20 14:29:08 +00:00
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
return null;
|
|
|
|
}
|
2007-05-16 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Searches the database for a specified user profile by UUID
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="uuid">The account ID</param>
|
|
|
|
/// <returns>The users profile</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserProfileData getUserByUUID(LLUUID uuid)
|
|
|
|
{
|
2007-05-20 14:29:08 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> param = new Dictionary<string, string>();
|
|
|
|
param["?uuid"] = uuid.ToStringHyphenated();
|
|
|
|
|
|
|
|
System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param);
|
|
|
|
System.Data.IDataReader reader = result.ExecuteReader();
|
|
|
|
|
2007-05-31 14:05:19 +00:00
|
|
|
UserProfileData row = database.readUserRow(reader);
|
2007-05-20 14:29:08 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2007-05-30 02:36:48 +00:00
|
|
|
database.Reconnect();
|
2007-05-20 14:29:08 +00:00
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
return null;
|
|
|
|
}
|
2007-05-16 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a user session searching by name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The account name</param>
|
|
|
|
/// <returns>The users session</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserAgentData getAgentByName(string name)
|
|
|
|
{
|
|
|
|
return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a user session by account name
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">First part of the users account name</param>
|
|
|
|
/// <param name="last">Second part of the users account name</param>
|
|
|
|
/// <returns>The users session</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserAgentData getAgentByName(string user, string last)
|
|
|
|
{
|
2007-05-20 14:33:53 +00:00
|
|
|
UserProfileData profile = getUserByName(user, last);
|
|
|
|
return getAgentByUUID(profile.UUID);
|
2007-05-16 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Returns an agent session by account UUID
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="uuid">The accounts UUID</param>
|
|
|
|
/// <returns>The users session</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public UserAgentData getAgentByUUID(LLUUID uuid)
|
|
|
|
{
|
2007-05-20 14:33:53 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
lock (database)
|
|
|
|
{
|
|
|
|
Dictionary<string, string> param = new Dictionary<string, string>();
|
|
|
|
param["?uuid"] = uuid.ToStringHyphenated();
|
|
|
|
|
|
|
|
System.Data.IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param);
|
|
|
|
System.Data.IDataReader reader = result.ExecuteReader();
|
|
|
|
|
2007-05-31 14:05:19 +00:00
|
|
|
UserAgentData row = database.readAgentRow(reader);
|
2007-05-20 14:33:53 +00:00
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
result.Dispose();
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2007-05-30 02:36:48 +00:00
|
|
|
database.Reconnect();
|
2007-05-20 14:33:53 +00:00
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
return null;
|
|
|
|
}
|
2007-05-16 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new users profile
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The user profile to create</param>
|
2007-05-25 16:27:07 +00:00
|
|
|
public void addNewUserProfile(UserProfileData user)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new agent
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="agent">The agent to create</param>
|
2007-05-26 06:29:22 +00:00
|
|
|
public void addNewUserAgent(UserAgentData agent)
|
|
|
|
{
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Performs a money transfer request between two accounts
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="from">The senders account ID</param>
|
|
|
|
/// <param name="to">The recievers account ID</param>
|
|
|
|
/// <param name="amount">The amount to transfer</param>
|
|
|
|
/// <returns>Success?</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Performs an inventory transfer request between two accounts
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>TODO: Move to inventory server</remarks>
|
|
|
|
/// <param name="from">The senders account ID</param>
|
|
|
|
/// <param name="to">The recievers account ID</param>
|
|
|
|
/// <param name="item">The item to transfer</param>
|
|
|
|
/// <returns>Success?</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Database provider name
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Provider name</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public string getName()
|
|
|
|
{
|
|
|
|
return "MySQL Userdata Interface";
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:37:31 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Database provider version
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>provider version</returns>
|
2007-05-16 21:10:45 +00:00
|
|
|
public string getVersion()
|
|
|
|
{
|
|
|
|
return "0.1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|