* Applied MSSQL Patch from akokko, Thanks! akokko

* This hasn't been tested in MSSQL mode, however it's been checked to make sure it doesn't cause any issues with mySQL/SQLlite
afrisby
Teravus Ovares 2007-12-05 15:53:58 +00:00
parent be93de1257
commit 71fd737a66
22 changed files with 3630 additions and 74 deletions

View File

@ -0,0 +1,227 @@
/*
* 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.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using libsecondlife;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Data.MSSQL
{
class MSSQLAssetData : IAssetProvider
{
MSSQLManager database;
#region IAssetProvider Members
private void UpgradeAssetsTable(string tableName)
{
// null as the version, indicates that the table didn't exist
if (tableName == null)
{
MainLog.Instance.Notice("ASSETS", "Creating new database tables");
database.ExecuteResourceSql("CreateAssetsTable.sql");
return;
}
}
/// <summary>
/// Ensure that the assets related tables exists and are at the latest version
/// </summary>
private void TestTables()
{
Dictionary<string, string> tableList = new Dictionary<string, string>();
tableList["assets"] = null;
database.GetTableVersion(tableList);
UpgradeAssetsTable(tableList["assets"]);
}
public AssetBase FetchAsset(LLUUID assetID)
{
AssetBase asset = null;
Dictionary<string, string> param = new Dictionary<string, string>();
param["id"] = assetID.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param);
IDataReader reader = result.ExecuteReader();
asset = database.getAssetRow(reader);
reader.Close();
result.Dispose();
return asset;
}
public void CreateAsset(AssetBase asset)
{
if (ExistsAsset((LLUUID)asset.FullID))
{
return;
}
SqlCommand cmd =
new SqlCommand(
"INSERT INTO assets ([id], [name], [description], [assetType], [invType], [local], [temporary], [data])"+
" VALUES "+
"(@id, @name, @description, @assetType, @invType, @local, @temporary, @data)",
database.getConnection());
using (cmd)
{
//SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar);
//p.Value = asset.FullID.ToStringHyphenated();
cmd.Parameters.AddWithValue("id", asset.FullID.ToStringHyphenated());
cmd.Parameters.AddWithValue("name", asset.Name);
cmd.Parameters.AddWithValue("description", asset.Description);
SqlParameter e = cmd.Parameters.Add("assetType", SqlDbType.TinyInt);
e.Value = asset.Type;
SqlParameter f = cmd.Parameters.Add("invType", SqlDbType.TinyInt);
f.Value = asset.InvType;
SqlParameter g = cmd.Parameters.Add("local", SqlDbType.TinyInt);
g.Value = asset.Local;
SqlParameter h = cmd.Parameters.Add("temporary", SqlDbType.TinyInt);
h.Value = asset.Temporary;
SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image);
i.Value = asset.Data;
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
cmd.Dispose();
}
}
public void UpdateAsset(AssetBase asset)
{
SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " +
"name = @name, " +
"description = @description," +
"assetType = @assetType," +
"invType = @invType," +
"local = @local,"+
"temporary = @temporary," +
"data = @data where " +
"id = @keyId;", database.getConnection());
SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToStringHyphenated());
SqlParameter param2 = new SqlParameter("@name", asset.Name);
SqlParameter param3 = new SqlParameter("@description", asset.Description);
SqlParameter param4 = new SqlParameter("@assetType", asset.Type);
SqlParameter param5 = new SqlParameter("@invType", asset.InvType);
SqlParameter param6 = new SqlParameter("@local", asset.Local);
SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary);
SqlParameter param8 = new SqlParameter("@data", asset.Data);
SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToStringHyphenated());
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
command.Parameters.Add(param4);
command.Parameters.Add(param5);
command.Parameters.Add(param6);
command.Parameters.Add(param7);
command.Parameters.Add(param8);
command.Parameters.Add(param9);
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
public bool ExistsAsset(LLUUID uuid)
{
if (FetchAsset(uuid) != null) {
return true;
}
return false;
}
/// <summary>
/// All writes are immediately commited to the database, so this is a no-op
/// </summary>
public void CommitAssets()
{
}
#endregion
#region IPlugin Members
public void Initialise()
{
IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
this.database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
TestTables();
}
public string Version
{
// get { return database.getVersion(); }
get { return database.getVersion(); }
}
public string Name
{
get { return "MSSQL Asset storage engine"; }
}
#endregion
}
}

View File

@ -28,11 +28,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using OpenSim.Framework;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using libsecondlife; using libsecondlife;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Data.MSSQL namespace OpenSim.Framework.Data.MSSQL
{ {
@ -44,14 +43,22 @@ namespace OpenSim.Framework.Data.MSSQL
/// <summary> /// <summary>
/// Database manager /// Database manager
/// </summary> /// </summary>
private MSSqlManager database; private MSSQLManager database;
/// <summary> /// <summary>
/// Initialises the Grid Interface /// Initialises the Grid Interface
/// </summary> /// </summary>
public void Initialise() public void Initialise()
{ {
database = new MSSqlManager("localhost", "db", "user", "password", "false"); IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
} }
/// <summary> /// <summary>
@ -99,18 +106,116 @@ namespace OpenSim.Framework.Data.MSSQL
/// <param name="handle">Region location handle</param> /// <param name="handle">Region location handle</param>
/// <returns>Sim profile</returns> /// <returns>Sim profile</returns>
public RegionProfileData GetProfileByHandle(ulong handle) public RegionProfileData GetProfileByHandle(ulong handle)
{
IDataReader reader = null;
try
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["handle"] = handle.ToString(); param["handle"] = handle.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = @handle", param);
reader = result.ExecuteReader();
IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); RegionProfileData row = database.getRegionRow(reader);
IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRow(reader);
reader.Close(); reader.Close();
result.Dispose(); result.Dispose();
return row; return row;
}
catch (Exception)
{
if (reader != null) {
reader.Close();
}
}
return null;
}
/// <summary>
/// // Returns a list of avatar and UUIDs that match the query
/// </summary>
public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
{
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return returnlist;
}
}
else if (querysplit.Length == 1)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new LLUUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return returnlist;
}
}
return returnlist;
} }
/// <summary> /// <summary>
@ -121,27 +226,17 @@ namespace OpenSim.Framework.Data.MSSQL
public RegionProfileData GetProfileByLLUUID(LLUUID uuid) public RegionProfileData GetProfileByLLUUID(LLUUID uuid)
{ {
Dictionary<string, string> param = new Dictionary<string, string>(); Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToStringHyphenated(); param["uuid"] = uuid.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param);
IDataReader reader = result.ExecuteReader(); IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRow(reader); RegionProfileData row = database.getRegionRow(reader);
reader.Close(); reader.Close();
result.Dispose(); result.Dispose();
return row; return row;
} }
/// <summary>
/// // Returns a list of avatar and UUIDs that match the query
/// </summary>
public List<OpenSim.Framework.Data.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
{
//Do nothing yet
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
return returnlist;
}
/// <summary> /// <summary>
/// Adds a new specified region to the database /// Adds a new specified region to the database
/// </summary> /// </summary>
@ -149,7 +244,20 @@ namespace OpenSim.Framework.Data.MSSQL
/// <returns>A dataresponse enum indicating success</returns> /// <returns>A dataresponse enum indicating success</returns>
public DataResponse AddProfile(RegionProfileData profile) public DataResponse AddProfile(RegionProfileData profile)
{ {
if (database.insertRow(profile))
try
{
if (GetProfileByLLUUID(profile.UUID) != null)
{
return DataResponse.RESPONSE_OK;
}
}
catch (Exception)
{
System.Console.WriteLine("No regions found. Create new one.");
}
if (database.insertRegionRow(profile))
{ {
return DataResponse.RESPONSE_OK; return DataResponse.RESPONSE_OK;
} }
@ -201,7 +309,5 @@ namespace OpenSim.Framework.Data.MSSQL
{ {
return null; return null;
} }
// This is here because MSSQL GridData only seems to know about itself o.O
} }
} }

View File

@ -0,0 +1,697 @@
/*
* 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.IO;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using libsecondlife;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Data.MSSQL
{
/// <summary>
/// A MySQL interface for the inventory server
/// </summary>
public class MSSQLInventoryData : IInventoryData
{
/// <summary>
/// The database manager
/// </summary>
private MSSQLManager database;
/// <summary>
/// Loads and initialises this database plugin
/// </summary>
public void Initialise()
{
IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
TestTables();
}
#region Test and initialization code
private void UpgradeFoldersTable(string tableName)
{
// null as the version, indicates that the table didn't exist
if (tableName == null)
{
database.ExecuteResourceSql("CreateFoldersTable.sql");
//database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql");
return;
}
}
private void UpgradeItemsTable(string tableName)
{
// null as the version, indicates that the table didn't exist
if (tableName == null)
{
database.ExecuteResourceSql("CreateItemsTable.sql");
//database.ExecuteResourceSql("UpgradeItemsTableToVersion2.sql");
return;
}
}
private void TestTables()
{
Dictionary<string, string> tableList = new Dictionary<string, string>();
tableList["inventoryfolders"] = null;
tableList["inventoryitems"] = null;
database.GetTableVersion(tableList);
UpgradeFoldersTable(tableList["inventoryfolders"]);
UpgradeItemsTable(tableList["inventoryitems"]);
}
#endregion
/// <summary>
/// The name of this DB provider
/// </summary>
/// <returns>Name of DB provider</returns>
public string getName()
{
return "MSSQL Inventory Data Interface";
}
/// <summary>
/// Closes this DB provider
/// </summary>
public void Close()
{
// Do nothing.
}
/// <summary>
/// Returns the version of this DB provider
/// </summary>
/// <returns>A string containing the DB provider</returns>
public string getVersion()
{
return database.getVersion();
}
/// <summary>
/// Returns a list of items in a specified folder
/// </summary>
/// <param name="folderID">The folder to search</param>
/// <returns>A list containing inventory items</returns>
public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
{
try
{
lock (database)
{
List<InventoryItemBase> items = new List<InventoryItemBase>();
Dictionary<string, string> param = new Dictionary<string, string>();
param["parentFolderID"] = folderID.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param);
IDataReader reader = result.ExecuteReader();
while(reader.Read())
items.Add(readInventoryItem(reader));
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Returns a list of the root folders within a users inventory
/// </summary>
/// <param name="user">The user whos inventory is to be searched</param>
/// <returns>A list of folder objects</returns>
public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = user.ToStringHyphenated();
param["zero"] = LLUUID.Zero.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param);
IDataReader reader = result.ExecuteReader();
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while(reader.Read())
items.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Returns the users inventory root folder.
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public InventoryFolderBase getUserRootFolder(LLUUID user)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = user.ToStringHyphenated();
param["zero"] = LLUUID.Zero.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param);
IDataReader reader = result.ExecuteReader();
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while(reader.Read())
items.Add(readInventoryFolder(reader));
InventoryFolderBase rootFolder = null;
if (items.Count > 0) {
rootFolder = items[0]; //should only be one folder with parent set to zero (the root one).
}
reader.Close();
result.Dispose();
return rootFolder;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Returns a list of folders in a users inventory contained within the specified folder
/// </summary>
/// <param name="parentID">The folder to search</param>
/// <returns>A list of inventory folders</returns>
public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["parentFolderID"] = parentID.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param);
IDataReader reader = result.ExecuteReader();
List<InventoryFolderBase> items = new List<InventoryFolderBase>();
while(reader.Read())
items.Add(readInventoryFolder(reader));
reader.Close();
result.Dispose();
return items;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Reads a one item from an SQL result
/// </summary>
/// <param name="reader">The SQL Result</param>
/// <returns>the item read</returns>
public InventoryItemBase readInventoryItem(IDataReader reader)
{
try
{
InventoryItemBase item = new InventoryItemBase();
item.inventoryID = new LLUUID((string)reader["inventoryID"]);
item.assetID = new LLUUID((string)reader["assetID"]);
item.assetType = (int)reader["assetType"];
item.parentFolderID = new LLUUID((string)reader["parentFolderID"]);
item.avatarID = new LLUUID((string)reader["avatarID"]);
item.inventoryName = (string)reader["inventoryName"];
item.inventoryDescription = (string)reader["inventoryDescription"];
item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]);
item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]);
item.invType = (int)reader["invType"];
item.creatorsID = new LLUUID((string)reader["creatorID"]);
item.inventoryBasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]);
item.inventoryEveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]);
return item;
}
catch (SqlException e)
{
MainLog.Instance.Error(e.ToString());
}
return null;
}
/// <summary>
/// Returns a specified inventory item
/// </summary>
/// <param name="item">The item to return</param>
/// <returns>An inventory item</returns>
public InventoryItemBase getInventoryItem(LLUUID itemID)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["inventoryID"] = itemID.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param);
IDataReader reader = result.ExecuteReader();
InventoryItemBase item = null;
if(reader.Read())
item = readInventoryItem(reader);
reader.Close();
result.Dispose();
return item;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
}
return null;
}
/// <summary>
/// Reads a list of inventory folders returned by a query.
/// </summary>
/// <param name="reader">A MySQL Data Reader</param>
/// <returns>A List containing inventory folders</returns>
protected InventoryFolderBase readInventoryFolder(IDataReader reader)
{
try
{
InventoryFolderBase folder = new InventoryFolderBase();
folder.agentID = new LLUUID((string)reader["agentID"]);
folder.parentID = new LLUUID((string)reader["parentFolderID"]);
folder.folderID = new LLUUID((string)reader["folderID"]);
folder.name = (string)reader["folderName"];
folder.type = (short)reader["type"];
folder.version = (ushort)((int)reader["version"]);
return folder;
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
return null;
}
/// <summary>
/// Returns a specified inventory folder
/// </summary>
/// <param name="folder">The folder to return</param>
/// <returns>A folder class</returns>
public InventoryFolderBase getInventoryFolder(LLUUID folderID)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string,string>();
param["uuid"] = folderID.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param);
IDataReader reader = result.ExecuteReader();
reader.Read();
InventoryFolderBase folder = readInventoryFolder(reader);
reader.Close();
result.Dispose();
return folder;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Adds a specified item to the database
/// </summary>
/// <param name="item">The inventory item</param>
public void addInventoryItem(InventoryItemBase item)
{
string sql = "INSERT INTO inventoryitems";
sql += "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName], [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions], [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]) VALUES ";
sql += "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription, @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID, @inventoryBasePermissions, @inventoryEveryOnePermissions);";
try
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["inventoryID"] = item.inventoryID.ToStringHyphenated();
param["assetID"] = item.assetID.ToStringHyphenated();
param["assetType"] = item.assetType.ToString();
param["parentFolderID"] = item.parentFolderID.ToStringHyphenated();
param["avatarID"] = item.avatarID.ToStringHyphenated();
param["inventoryName"] = item.inventoryName;
param["inventoryDescription"] = item.inventoryDescription;
param["inventoryNextPermissions"] = item.inventoryNextPermissions.ToString();
param["inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString();
param["invType"] = Convert.ToString(item.invType);
param["creatorID"] = item.creatorsID.ToStringHyphenated();
param["inventoryBasePermissions"] = Convert.ToString(item.inventoryBasePermissions);
param["inventoryEveryOnePermissions"] = Convert.ToString(item.inventoryEveryOnePermissions);
IDbCommand result = database.Query(sql, param);
result.ExecuteNonQuery();
result.Dispose();
}
catch (SqlException e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Updates the specified inventory item
/// </summary>
/// <param name="item">Inventory item to update</param>
public void updateInventoryItem(InventoryItemBase item)
{
SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " +
"assetID = @assetID, " +
"assetType = @assetType" +
"parentFolderID = @parentFolderID" +
"avatarID = @avatarID" +
"inventoryName = @inventoryName"+
"inventoryDescription = @inventoryDescription" +
"inventoryNextPermissions = @inventoryNextPermissions" +
"inventoryCurrentPermissions = @inventoryCurrentPermissions" +
"invType = @invType" +
"creatorID = @creatorID" +
"inventoryBasePermissions = @inventoryBasePermissions" +
"inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " +
"invenoryID = @keyInventoryID;", database.getConnection());
SqlParameter param1 = new SqlParameter("@inventoryID", item.inventoryID.ToStringHyphenated());
SqlParameter param2 = new SqlParameter("@assetID", item.assetID);
SqlParameter param3 = new SqlParameter("@assetType", item.assetType);
SqlParameter param4 = new SqlParameter("@parentFolderID", item.parentFolderID);
SqlParameter param5 = new SqlParameter("@avatarID", item.avatarID);
SqlParameter param6 = new SqlParameter("@inventoryName", item.inventoryName);
SqlParameter param7 = new SqlParameter("@inventoryDescription", item.inventoryDescription);
SqlParameter param8 = new SqlParameter("@inventoryNextPermissions", item.inventoryNextPermissions);
SqlParameter param9 = new SqlParameter("@inventoryCurrentPermissions", item.inventoryCurrentPermissions);
SqlParameter param10 = new SqlParameter("@invType", item.invType);
SqlParameter param11 = new SqlParameter("@creatorID", item.creatorsID);
SqlParameter param12 = new SqlParameter("@inventoryBasePermissions", item.inventoryBasePermissions);
SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.inventoryEveryOnePermissions);
SqlParameter param14 = new SqlParameter("@keyInventoryID", item.inventoryID.ToStringHyphenated());
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
command.Parameters.Add(param4);
command.Parameters.Add(param5);
command.Parameters.Add(param6);
command.Parameters.Add(param7);
command.Parameters.Add(param8);
command.Parameters.Add(param9);
command.Parameters.Add(param10);
command.Parameters.Add(param11);
command.Parameters.Add(param12);
command.Parameters.Add(param13);
command.Parameters.Add(param14);
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
public void deleteInventoryItem(LLUUID itemID)
{
try
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = itemID.ToStringHyphenated();
IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (SqlException e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Creates a new inventory folder
/// </summary>
/// <param name="folder">Folder to create</param>
public void addInventoryFolder(InventoryFolderBase folder)
{
string sql = "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES ";
sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
Dictionary<string, string> param = new Dictionary<string, string>();
param["folderID"] = folder.folderID.ToStringHyphenated();
param["agentID"] = folder.agentID.ToStringHyphenated();
param["parentFolderID"] = folder.parentID.ToStringHyphenated();
param["folderName"] = folder.name;
param["type"] = Convert.ToString(folder.type);
param["version"] = Convert.ToString(folder.version);
try
{
IDbCommand result = database.Query(sql, param);
result.ExecuteNonQuery();
result.Dispose();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Updates an inventory folder
/// </summary>
/// <param name="folder">Folder to update</param>
public void updateInventoryFolder(InventoryFolderBase folder)
{
SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " +
"agentID = @agentID, " +
"parentFolderID = @parentFolderID," +
"folderName = @folderName," +
"type = @type," +
"version = @version where " +
"folderID = @keyFolderID;", database.getConnection());
SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToStringHyphenated());
SqlParameter param2 = new SqlParameter("@agentID", folder.agentID.ToStringHyphenated());
SqlParameter param3 = new SqlParameter("@parentFolderID", folder.parentID.ToStringHyphenated());
SqlParameter param4 = new SqlParameter("@folderName", folder.name);
SqlParameter param5 = new SqlParameter("@type", folder.type);
SqlParameter param6 = new SqlParameter("@version", folder.version);
SqlParameter param7 = new SqlParameter("@keyFolderID", folder.folderID.ToStringHyphenated());
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
command.Parameters.Add(param4);
command.Parameters.Add(param5);
command.Parameters.Add(param6);
command.Parameters.Add(param7);
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Append a list of all the child folders of a parent folder
/// </summary>
/// <param name="folders">list where folders will be appended</param>
/// <param name="parentID">ID of parent</param>
protected void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID)
{
List<InventoryFolderBase> subfolderList = getInventoryFolders(parentID);
foreach (InventoryFolderBase f in subfolderList)
folders.Add(f);
}
/// <summary>
/// Returns all child folders in the hierarchy from the parent folder and down
/// </summary>
/// <param name="parentID">The folder to get subfolders for</param>
/// <returns>A list of inventory folders</returns>
protected List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID)
{
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
getInventoryFolders(ref folders, parentID);
for (int i = 0; i < folders.Count; i++)
getInventoryFolders(ref folders, folders[i].folderID);
return folders;
}
protected void deleteOneFolder(LLUUID folderID)
{
try
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["folderID"] = folderID.ToStringHyphenated();
IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (SqlException e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
}
}
protected void deleteItemsInFolder(LLUUID folderID)
{
try
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["parentFolderID"] = folderID.ToStringHyphenated();
IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (SqlException e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Delete an inventory folder
/// </summary>
/// <param name="folderId">Id of folder to delete</param>
public void deleteInventoryFolder(LLUUID folderID)
{
lock (database)
{
List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
//Delete all sub-folders
foreach (InventoryFolderBase f in subFolders)
{
deleteOneFolder(f.folderID);
deleteItemsInFolder(f.folderID);
}
//Delete the actual row
deleteOneFolder(folderID);
deleteItemsInFolder(folderID);
}
}
}
}

View File

@ -0,0 +1,104 @@
/*
* 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;
namespace OpenSim.Framework.Data.MSSQL
{
/// <summary>
/// An interface to the log database for MySQL
/// </summary>
class MSSQLLogData : ILogData
{
/// <summary>
/// The database manager
/// </summary>
public MSSQLManager database;
/// <summary>
/// Artificial constructor called when the plugin is loaded
/// </summary>
public void Initialise()
{
IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
}
/// <summary>
/// Saves a log item to the database
/// </summary>
/// <param name="serverDaemon">The daemon triggering the event</param>
/// <param name="target">The target of the action (region / agent UUID, etc)</param>
/// <param name="methodCall">The method call where the problem occured</param>
/// <param name="arguments">The arguments passed to the method</param>
/// <param name="priority">How critical is this?</param>
/// <param name="logMessage">The message to log</param>
public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage)
{
try
{
database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage);
}
catch
{
database.Reconnect();
}
}
/// <summary>
/// Returns the name of this DB provider
/// </summary>
/// <returns>A string containing the DB provider name</returns>
public string getName()
{
return "MSSQL Logdata Interface";
}
/// <summary>
/// Closes the database provider
/// </summary>
public void Close()
{
// Do nothing.
}
/// <summary>
/// Returns the version of this DB provider
/// </summary>
/// <returns>A string containing the provider version</returns>
public string getVersion()
{
return "0.1";
}
}
}

View File

@ -29,19 +29,28 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.IO;
using System.Reflection;
using libsecondlife; using libsecondlife;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Data.MSSQL namespace OpenSim.Framework.Data.MSSQL
{ {
/// <summary> /// <summary>
/// A management class for the MS SQL Storage Engine /// A management class for the MS SQL Storage Engine
/// </summary> /// </summary>
internal class MSSqlManager class MSSQLManager
{ {
/// <summary> /// <summary>
/// The database connection object /// The database connection object
/// </summary> /// </summary>
private IDbConnection dbcon; IDbConnection dbcon;
/// <summary>
/// Connection string for ADO.net
/// </summary>
private string connectionString;
/// <summary> /// <summary>
/// Initialises and creates a new Sql connection and maintains it. /// Initialises and creates a new Sql connection and maintains it.
@ -51,14 +60,14 @@ namespace OpenSim.Framework.Data.MSSQL
/// <param name="username">The username logging into the database</param> /// <param name="username">The username logging into the database</param>
/// <param name="password">The password for the user logging in</param> /// <param name="password">The password for the user logging in</param>
/// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param>
public MSSqlManager(string hostname, string database, string username, string password, string cpooling) public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, string password)
{ {
try try
{ {
string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username +
";Password=" + password + ";Pooling=" + cpooling + ";";
dbcon = new SqlConnection(connectionString);
connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog + ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + password+";";
dbcon = new SqlConnection(connectionString);
TestTables(dbcon);
dbcon.Open(); dbcon.Open();
} }
catch (Exception e) catch (Exception e)
@ -67,6 +76,144 @@ namespace OpenSim.Framework.Data.MSSQL
} }
} }
private bool TestTables(IDbConnection conn)
{
IDbCommand cmd = this.Query("SELECT * FROM regions", new Dictionary<string, string>());
//SqlCommand cmd = (SqlCommand)dbcon.CreateCommand();
//cmd.CommandText = "SELECT * FROM regions";
try
{
conn.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
catch (Exception)
{
MainLog.Instance.Verbose("DATASTORE", "MSSQL Database doesn't exist... creating");
InitDB(conn);
}
return true;
}
private void InitDB(IDbConnection conn)
{
string createRegions = defineTable(createRegionsTable());
Dictionary<string, string> param = new Dictionary<string, string>();
IDbCommand pcmd = this.Query(createRegions, param);
if (conn.State == ConnectionState.Closed) {
conn.Open();
}
pcmd.ExecuteNonQuery();
pcmd.Dispose();
this.ExecuteResourceSql("Mssql-users.sql");
this.ExecuteResourceSql("Mssql-agents.sql");
this.ExecuteResourceSql("Mssql-logs.sql");
conn.Close();
}
private DataTable createRegionsTable()
{
DataTable regions = new DataTable("regions");
createCol(regions, "regionHandle", typeof(ulong));
createCol(regions, "regionName", typeof(System.String));
createCol(regions, "uuid", typeof(System.String));
createCol(regions, "regionRecvKey", typeof(System.String));
createCol(regions, "regionSecret", typeof(System.String));
createCol(regions, "regionSendKey", typeof(System.String));
createCol(regions, "regionDataURI", typeof(System.String));
createCol(regions, "serverIP", typeof(System.String));
createCol(regions, "serverPort", typeof(System.String));
createCol(regions, "serverURI", typeof(System.String));
createCol(regions, "locX", typeof(uint));
createCol(regions, "locY", typeof(uint));
createCol(regions, "locZ", typeof(uint));
createCol(regions, "eastOverrideHandle", typeof(ulong));
createCol(regions, "westOverrideHandle", typeof(ulong));
createCol(regions, "southOverrideHandle", typeof(ulong));
createCol(regions, "northOverrideHandle", typeof(ulong));
createCol(regions, "regionAssetURI", typeof(System.String));
createCol(regions, "regionAssetRecvKey", typeof(System.String));
createCol(regions, "regionAssetSendKey", typeof(System.String));
createCol(regions, "regionUserURI", typeof(System.String));
createCol(regions, "regionUserRecvKey", typeof(System.String));
createCol(regions, "regionUserSendKey", typeof(System.String));
createCol(regions, "regionMapTexture", typeof(System.String));
createCol(regions, "serverHttpPort", typeof(System.String));
createCol(regions, "serverRemotingPort", typeof(uint));
// Add in contraints
regions.PrimaryKey = new DataColumn[] { regions.Columns["UUID"] };
return regions;
}
protected static void createCol(DataTable dt, string name, System.Type type)
{
DataColumn col = new DataColumn(name, type);
dt.Columns.Add(col);
}
protected static string defineTable(DataTable dt)
{
string sql = "create table " + dt.TableName + "(";
string subsql = "";
foreach (DataColumn col in dt.Columns)
{
if (subsql.Length > 0)
{ // a map function would rock so much here
subsql += ",\n";
}
subsql += col.ColumnName + " " + SqlType(col.DataType);
if (col == dt.PrimaryKey[0])
{
subsql += " primary key";
}
}
sql += subsql;
sql += ")";
return sql;
}
// this is something we'll need to implement for each db
// slightly differently.
private static string SqlType(Type type)
{
if (type == typeof(System.String))
{
return "varchar(255)";
}
else if (type == typeof(System.Int32))
{
return "integer";
}
else if (type == typeof(System.Double))
{
return "float";
}
else if (type == typeof(System.Byte[]))
{
return "image";
}
else
{
return "varchar(255)";
}
}
/// <summary> /// <summary>
/// Shuts down the database connection /// Shuts down the database connection
/// </summary> /// </summary>
@ -76,6 +223,29 @@ namespace OpenSim.Framework.Data.MSSQL
dbcon = null; dbcon = null;
} }
/// <summary>
/// Reconnects to the database
/// </summary>
public void Reconnect()
{
lock (dbcon)
{
try
{
//string connectionString = "Data Source=WRK-OU-738\\SQLEXPRESS;Initial Catalog=rex;Persist Security Info=True;User ID=sa;Password=rex";
// Close the DB connection
dbcon.Close();
// Try reopen it
dbcon = new SqlConnection(connectionString);
dbcon.Open();
}
catch (Exception e)
{
MainLog.Instance.Error("Unable to reconnect to database " + e.ToString());
}
}
}
/// <summary> /// <summary>
/// Runs a query with protection against SQL Injection by using parameterised input. /// Runs a query with protection against SQL Injection by using parameterised input.
/// </summary> /// </summary>
@ -84,14 +254,14 @@ namespace OpenSim.Framework.Data.MSSQL
/// <returns>A Sql DB Command</returns> /// <returns>A Sql DB Command</returns>
public IDbCommand Query(string sql, Dictionary<string, string> parameters) public IDbCommand Query(string sql, Dictionary<string, string> parameters)
{ {
SqlCommand dbcommand = (SqlCommand) dbcon.CreateCommand(); SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand();
dbcommand.CommandText = sql; dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters) foreach (KeyValuePair<string, string> param in parameters)
{ {
dbcommand.Parameters.AddWithValue(param.Key, param.Value); dbcommand.Parameters.AddWithValue(param.Key, param.Value);
} }
return (IDbCommand) dbcommand; return (IDbCommand)dbcommand;
} }
/// <summary> /// <summary>
@ -99,74 +269,201 @@ namespace OpenSim.Framework.Data.MSSQL
/// </summary> /// </summary>
/// <param name="reader">An active database reader</param> /// <param name="reader">An active database reader</param>
/// <returns>A region row</returns> /// <returns>A region row</returns>
public RegionProfileData getRow(IDataReader reader) public RegionProfileData getRegionRow(IDataReader reader)
{ {
RegionProfileData regionprofile = new RegionProfileData(); RegionProfileData regionprofile = new RegionProfileData();
if (reader.Read()) if (reader.Read())
{ {
// Region Main // Region Main
regionprofile.regionHandle = (ulong) reader["regionHandle"]; regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]);
regionprofile.regionName = (string) reader["regionName"]; regionprofile.regionName = (string)reader["regionName"];
regionprofile.UUID = new LLUUID((string) reader["uuid"]); regionprofile.UUID = new LLUUID((string)reader["uuid"]);
// Secrets // Secrets
regionprofile.regionRecvKey = (string) reader["regionRecvKey"]; regionprofile.regionRecvKey = (string)reader["regionRecvKey"];
regionprofile.regionSecret = (string) reader["regionSecret"]; regionprofile.regionSecret = (string)reader["regionSecret"];
regionprofile.regionSendKey = (string) reader["regionSendKey"]; regionprofile.regionSendKey = (string)reader["regionSendKey"];
// Region Server // Region Server
regionprofile.regionDataURI = (string) reader["regionDataURI"]; regionprofile.regionDataURI = (string)reader["regionDataURI"];
regionprofile.regionOnline = false; // Needs to be pinged before this can be set. regionprofile.regionOnline = false; // Needs to be pinged before this can be set.
regionprofile.serverIP = (string) reader["serverIP"]; regionprofile.serverIP = (string)reader["serverIP"];
regionprofile.serverPort = (uint) reader["serverPort"]; regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]);
regionprofile.serverURI = (string) reader["serverURI"]; regionprofile.serverURI = (string)reader["serverURI"];
regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]);
regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]);
// Location // Location
regionprofile.regionLocX = (uint) ((int) reader["locX"]); regionprofile.regionLocX = Convert.ToUInt32(reader["locX"]);
regionprofile.regionLocY = (uint) ((int) reader["locY"]); regionprofile.regionLocY = Convert.ToUInt32(reader["locY"]);
regionprofile.regionLocZ = (uint) ((int) reader["locZ"]); regionprofile.regionLocZ = Convert.ToUInt32(reader["locZ"]);
// Neighbours - 0 = No Override // Neighbours - 0 = No Override
regionprofile.regionEastOverrideHandle = (ulong) reader["eastOverrideHandle"]; regionprofile.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"]);
regionprofile.regionWestOverrideHandle = (ulong) reader["westOverrideHandle"]; regionprofile.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"]);
regionprofile.regionSouthOverrideHandle = (ulong) reader["southOverrideHandle"]; regionprofile.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"]);
regionprofile.regionNorthOverrideHandle = (ulong) reader["northOverrideHandle"]; regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]);
// Assets // Assets
regionprofile.regionAssetURI = (string) reader["regionAssetURI"]; regionprofile.regionAssetURI = (string)reader["regionAssetURI"];
regionprofile.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"];
regionprofile.regionAssetSendKey = (string) reader["regionAssetSendKey"]; regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"];
// Userserver // Userserver
regionprofile.regionUserURI = (string) reader["regionUserURI"]; regionprofile.regionUserURI = (string)reader["regionUserURI"];
regionprofile.regionUserRecvKey = (string) reader["regionUserRecvKey"]; regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"];
regionprofile.regionUserSendKey = (string) reader["regionUserSendKey"]; regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"];
// World Map Addition
string tempRegionMap = reader["regionMapTexture"].ToString();
if (tempRegionMap != "")
{
regionprofile.regionMapTextureID = new LLUUID(tempRegionMap);
} }
else else
{ {
regionprofile.regionMapTextureID = new LLUUID();
}
}
else
{
reader.Close();
throw new Exception("No rows to return"); throw new Exception("No rows to return");
} }
return regionprofile; return regionprofile;
} }
/// <summary>
/// Reads a user profile from an active data reader
/// </summary>
/// <param name="reader">An active database reader</param>
/// <returns>A user profile</returns>
public UserProfileData readUserRow(IDataReader reader)
{
UserProfileData retval = new UserProfileData();
if (reader.Read())
{
retval.UUID = new LLUUID((string)reader["UUID"]);
retval.username = (string)reader["username"];
retval.surname = (string)reader["lastname"];
retval.passwordHash = (string)reader["passwordHash"];
retval.passwordSalt = (string)reader["passwordSalt"];
retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
retval.homeLocation = new LLVector3(
Convert.ToSingle(reader["homeLocationX"].ToString()),
Convert.ToSingle(reader["homeLocationY"].ToString()),
Convert.ToSingle(reader["homeLocationZ"].ToString()));
retval.homeLookAt = new LLVector3(
Convert.ToSingle(reader["homeLookAtX"].ToString()),
Convert.ToSingle(reader["homeLookAtY"].ToString()),
Convert.ToSingle(reader["homeLookAtZ"].ToString()));
retval.created = Convert.ToInt32(reader["created"].ToString());
retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
retval.userInventoryURI = (string)reader["userInventoryURI"];
retval.userAssetURI = (string)reader["userAssetURI"];
retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
retval.profileAboutText = (string)reader["profileAboutText"];
retval.profileFirstText = (string)reader["profileFirstText"];
retval.profileImage = new LLUUID((string)reader["profileImage"]);
retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]);
}
else
{
return null;
}
return retval;
}
/// <summary>
/// Reads an agent row from a database reader
/// </summary>
/// <param name="reader">An active database reader</param>
/// <returns>A user session agent</returns>
public UserAgentData readAgentRow(IDataReader reader)
{
UserAgentData retval = new UserAgentData();
if (reader.Read())
{
// Agent IDs
retval.UUID = new LLUUID((string)reader["UUID"]);
retval.sessionID = new LLUUID((string)reader["sessionID"]);
retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]);
// Agent Who?
retval.agentIP = (string)reader["agentIP"];
retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString());
retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString());
// Login/Logout times (UNIX Epoch)
retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString());
retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
// Current position
retval.currentRegion = (string)reader["currentRegion"];
retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos);
}
else
{
return null;
}
return retval;
}
public AssetBase getAssetRow(IDataReader reader)
{
AssetBase asset = new AssetBase();
if (reader.Read())
{
// Region Main
asset = new AssetBase();
asset.Data = (byte[])reader["data"];
asset.Description = (string)reader["description"];
asset.FullID = new LLUUID((string)reader["id"]);
asset.InvType = Convert.ToSByte(reader["invType"]);
asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false;
asset.Name = (string)reader["name"];
asset.Type = Convert.ToSByte(reader["assetType"]);
}
else
{
return null; // throw new Exception("No rows to return");
}
return asset;
}
/// <summary> /// <summary>
/// Creates a new region in the database /// Creates a new region in the database
/// </summary> /// </summary>
/// <param name="profile">The region profile to insert</param> /// <param name="profile">The region profile to insert</param>
/// <returns>Successful?</returns> /// <returns>Successful?</returns>
public bool insertRow(RegionProfileData profile) public bool insertRegionRow(RegionProfileData profile)
{ {
string sql =
"REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; //Insert new region
sql += string sql = "INSERT INTO regions ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], ";
"serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; sql += "[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], ";
sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; sql += "[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES ";
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
sql += sql += "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
"@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);";
sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);";
Dictionary<string, string> parameters = new Dictionary<string, string>(); Dictionary<string, string> parameters = new Dictionary<string, string>();
@ -174,6 +471,7 @@ namespace OpenSim.Framework.Data.MSSQL
parameters["regionName"] = profile.regionName; parameters["regionName"] = profile.regionName;
parameters["uuid"] = profile.UUID.ToString(); parameters["uuid"] = profile.UUID.ToString();
parameters["regionRecvKey"] = profile.regionRecvKey; parameters["regionRecvKey"] = profile.regionRecvKey;
parameters["regionSecret"] = profile.regionSecret;
parameters["regionSendKey"] = profile.regionSendKey; parameters["regionSendKey"] = profile.regionSendKey;
parameters["regionDataURI"] = profile.regionDataURI; parameters["regionDataURI"] = profile.regionDataURI;
parameters["serverIP"] = profile.serverIP; parameters["serverIP"] = profile.serverIP;
@ -192,6 +490,10 @@ namespace OpenSim.Framework.Data.MSSQL
parameters["regionUserURI"] = profile.regionUserURI; parameters["regionUserURI"] = profile.regionUserURI;
parameters["regionUserRecvKey"] = profile.regionUserRecvKey; parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
parameters["regionUserSendKey"] = profile.regionUserSendKey; parameters["regionUserSendKey"] = profile.regionUserSendKey;
parameters["regionMapTexture"] = profile.regionMapTextureID.ToStringHyphenated();
parameters["serverHttpPort"] = profile.httpPort.ToString();
parameters["serverRemotingPort"] = profile.remotingPort.ToString();
bool returnval = false; bool returnval = false;
@ -204,12 +506,236 @@ namespace OpenSim.Framework.Data.MSSQL
result.Dispose(); result.Dispose();
} }
catch (Exception) catch (Exception e)
{ {
MainLog.Instance.Error("MSSQLManager : " + e.ToString());
}
return returnval;
}
/// <summary>
/// Inserts a new row into the log database
/// </summary>
/// <param name="serverDaemon">The daemon which triggered this event</param>
/// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param>
/// <param name="methodCall">The method call where the problem occured</param>
/// <param name="arguments">The arguments passed to the method</param>
/// <param name="priority">How critical is this?</param>
/// <param name="logMessage">Extra message info</param>
/// <returns>Saved successfully?</returns>
public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage)
{
string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES ";
sql += "(@target, @server, @method, @arguments, @priority, @message);";
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["server"] = serverDaemon;
parameters["target"] = target;
parameters["method"] = methodCall;
parameters["arguments"] = arguments;
parameters["priority"] = priority.ToString();
parameters["message"] = logMessage;
bool returnval = false;
try
{
IDbCommand result = Query(sql, parameters);
if (result.ExecuteNonQuery() == 1)
returnval = true;
result.Dispose();
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
return false; return false;
} }
return returnval; return returnval;
} }
/// <summary>
/// Creates a new user and inserts it into the database
/// </summary>
/// <param name="uuid">User ID</param>
/// <param name="username">First part of the login</param>
/// <param name="lastname">Second part of the login</param>
/// <param name="passwordHash">A salted hash of the users password</param>
/// <param name="passwordSalt">The salt used for the password hash</param>
/// <param name="homeRegion">A regionHandle of the users home region</param>
/// <param name="homeLocX">Home region position vector</param>
/// <param name="homeLocY">Home region position vector</param>
/// <param name="homeLocZ">Home region position vector</param>
/// <param name="homeLookAtX">Home region 'look at' vector</param>
/// <param name="homeLookAtY">Home region 'look at' vector</param>
/// <param name="homeLookAtZ">Home region 'look at' vector</param>
/// <param name="created">Account created (unix timestamp)</param>
/// <param name="lastlogin">Last login (unix timestamp)</param>
/// <param name="inventoryURI">Users inventory URI</param>
/// <param name="assetURI">Users asset URI</param>
/// <param name="canDoMask">I can do mask</param>
/// <param name="wantDoMask">I want to do mask</param>
/// <param name="aboutText">Profile text</param>
/// <param name="firstText">Firstlife text</param>
/// <param name="profileImage">UUID for profile image</param>
/// <param name="firstImage">UUID for firstlife image</param>
/// <returns>Success?</returns>
public bool insertUserRow(libsecondlife.LLUUID uuid, string username, string lastname, string passwordHash, string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, string aboutText, string firstText,
libsecondlife.LLUUID profileImage, libsecondlife.LLUUID firstImage)
{
string sql = "INSERT INTO users ";
sql += "([UUID], [username], [lastname], [passwordHash], [passwordSalt], [homeRegion], ";
sql += "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], ";
sql += "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], ";
sql += "[profileFirstText], [profileImage], [profileFirstImage]) VALUES ";
sql += "(@UUID, @username, @lastname, @passwordHash, @passwordSalt, @homeRegion, ";
sql += "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, ";
sql += "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, ";
sql += "@profileFirstText, @profileImage, @profileFirstImage);";
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["UUID"] = uuid.ToStringHyphenated();
parameters["username"] = username.ToString();
parameters["lastname"] = lastname.ToString();
parameters["passwordHash"] = passwordHash.ToString();
parameters["passwordSalt"] = passwordSalt.ToString();
parameters["homeRegion"] = homeRegion.ToString();
parameters["homeLocationX"] = homeLocX.ToString();
parameters["homeLocationY"] = homeLocY.ToString();
parameters["homeLocationZ"] = homeLocZ.ToString();
parameters["homeLookAtX"] = homeLookAtX.ToString();
parameters["homeLookAtY"] = homeLookAtY.ToString();
parameters["homeLookAtZ"] = homeLookAtZ.ToString();
parameters["created"] = created.ToString();
parameters["lastLogin"] = lastlogin.ToString();
parameters["userInventoryURI"] = "";
parameters["userAssetURI"] = "";
parameters["profileCanDoMask"] = "0";
parameters["profileWantDoMask"] = "0";
parameters["profileAboutText"] = "";
parameters["profileFirstText"] = "";
parameters["profileImage"] = libsecondlife.LLUUID.Zero.ToStringHyphenated();
parameters["profileFirstImage"] = libsecondlife.LLUUID.Zero.ToStringHyphenated();
bool returnval = false;
try
{
IDbCommand result = Query(sql, parameters);
if (result.ExecuteNonQuery() == 1)
returnval = true;
result.Dispose();
} }
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
return false;
}
return returnval;
}
/// <summary>
/// Execute a SQL statement stored in a resource, as a string
/// </summary>
/// <param name="name"></param>
public void ExecuteResourceSql(string name)
{
try
{
SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon);
cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch (Exception e)
{
MainLog.Instance.Error("Unable to execute query " + e.ToString());
}
}
public SqlConnection getConnection()
{
return (SqlConnection)dbcon;
}
/// <summary>
/// Given a list of tables, return the version of the tables, as seen in the database
/// </summary>
/// <param name="tableList"></param>
public void GetTableVersion(Dictionary<string, string> tableList)
{
lock (dbcon)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["dbname"] = dbcon.Database;
IDbCommand tablesCmd = this.Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param);
using (IDataReader tables = tablesCmd.ExecuteReader())
{
while (tables.Read())
{
try
{
string tableName = (string)tables["TABLE_NAME"];
if (tableList.ContainsKey(tableName))
tableList[tableName] = tableName;
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
}
tables.Close();
}
}
}
private string getResourceString(string name)
{
Assembly assem = this.GetType().Assembly;
string[] names = assem.GetManifestResourceNames();
foreach (string s in names)
if (s.EndsWith(name))
using (Stream resource = assem.GetManifestResourceStream(s))
{
using (StreamReader resourceReader = new StreamReader(resource))
{
string resourceString = resourceReader.ReadToEnd();
return resourceString;
}
}
throw new Exception(string.Format("Resource '{0}' was not found", name));
}
/// <summary>
/// Returns the version of this DB provider
/// </summary>
/// <returns>A string containing the DB provider</returns>
public string getVersion()
{
System.Reflection.Module module = this.GetType().Module;
string dllName = module.Assembly.ManifestModule.Name;
Version dllVersion = module.Assembly.GetName().Version;
return string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
}
}
} }

View File

@ -0,0 +1,452 @@
/*
* 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.Data;
using System.Data.SqlClient;
using libsecondlife;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.Data.MSSQL
{
/// <summary>
/// A database interface class to a user profile storage system
/// </summary>
class MSSQLUserData : IUserData
{
/// <summary>
/// Database manager for MySQL
/// </summary>
public MSSQLManager database;
/// <summary>
/// Loads and initialises the MySQL storage plugin
/// </summary>
public void Initialise()
{
// Load from an INI file connection details
// TODO: move this to XML?
IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
}
/// <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>
public UserProfileData GetUserByName(string name)
{
return GetUserByName(name.Split(' ')[0], name.Split(' ')[1]);
}
/// <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>
public UserProfileData GetUserByName(string user, string last)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = user;
param["second"] = last;
IDbCommand result = database.Query("SELECT * FROM users WHERE username = @first AND lastname = @second", param);
IDataReader reader = result.ExecuteReader();
UserProfileData row = database.readUserRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
public List<OpenSim.Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
{
List<OpenSim.Framework.AvatarPickerAvatar> returnlist = new List<OpenSim.Framework.AvatarPickerAvatar>();
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length == 2)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query("SELECT UUID,username,surname FROM users WHERE username = @first AND lastname = @second", param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar();
user.AvatarID = new LLUUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return returnlist;
}
}
else if (querysplit.Length == 1)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["first"] = querysplit[0];
param["second"] = querysplit[1];
IDbCommand result =
database.Query("SELECT UUID,username,surname FROM users WHERE username = @first OR lastname = @second", param);
IDataReader reader = result.ExecuteReader();
while (reader.Read())
{
OpenSim.Framework.AvatarPickerAvatar user = new OpenSim.Framework.AvatarPickerAvatar();
user.AvatarID = new LLUUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["surname"];
returnlist.Add(user);
}
reader.Close();
result.Dispose();
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return returnlist;
}
}
return returnlist;
}
/// <summary>
/// Searches the database for a specified user profile by UUID
/// </summary>
/// <param name="uuid">The account ID</param>
/// <returns>The users profile</returns>
public UserProfileData GetUserByUUID(LLUUID uuid)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = @uuid", param);
IDataReader reader = result.ExecuteReader();
UserProfileData row = database.readUserRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Returns a user session searching by name
/// </summary>
/// <param name="name">The account name</param>
/// <returns>The users session</returns>
public UserAgentData GetAgentByName(string name)
{
return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
}
/// <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>
public UserAgentData GetAgentByName(string user, string last)
{
UserProfileData profile = GetUserByName(user, last);
return GetAgentByUUID(profile.UUID);
}
/// <summary>
/// Returns an agent session by account UUID
/// </summary>
/// <param name="uuid">The accounts UUID</param>
/// <returns>The users session</returns>
public UserAgentData GetAgentByUUID(LLUUID uuid)
{
try
{
lock (database)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToStringHyphenated();
IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = @uuid", param);
IDataReader reader = result.ExecuteReader();
UserAgentData row = database.readAgentRow(reader);
reader.Close();
result.Dispose();
return row;
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
return null;
}
}
/// <summary>
/// Creates a new users profile
/// </summary>
/// <param name="user">The user profile to create</param>
public void AddNewUserProfile(UserProfileData user)
{
try
{
lock (database)
{
database.insertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, user.homeRegion, user.homeLocation.X, user.homeLocation.Y, user.homeLocation.Z,
user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, user.lastLogin, user.userInventoryURI, user.userAssetURI, user.profileCanDoMask, user.profileWantDoMask,
user.profileAboutText, user.profileFirstText, user.profileImage, user.profileFirstImage);
}
}
catch (Exception e)
{
database.Reconnect();
MainLog.Instance.Error(e.ToString());
}
}
/// <summary>
/// Creates a new agent
/// </summary>
/// <param name="agent">The agent to create</param>
public void AddNewUserAgent(UserAgentData agent)
{
// Do nothing.
}
public bool UpdateUserProfile(UserProfileData user)
{
SqlCommand command = new SqlCommand("UPDATE users set UUID = @uuid, " +
"username = @username, " +
"lastname = @lastname," +
"passwordHash = @passwordHash," +
"passwordSalt = @passwordSalt," +
"homeRegion = @homeRegion," +
"homeLocationX = @homeLocationX," +
"homeLocationY = @homeLocationY," +
"homeLocationZ = @homeLocationZ," +
"homeLookAtX = @homeLookAtX," +
"homeLookAtY = @homeLookAtY," +
"homeLookAtZ = @homeLookAtZ," +
"created = @created," +
"lastLogin = @lastLogin," +
"userInventoryURI = @userInventoryURI," +
"userAssetURI = @userAssetURI," +
"profileCanDoMask = @profileCanDoMask," +
"profileWantDoMask = @profileWantDoMask," +
"profileAboutText = @profileAboutText," +
"profileFirstText = @profileFirstText," +
"profileImage = @profileImage," +
"profileFirstImage = @profileFirstImage where " +
"UUID = @keyUUUID;", database.getConnection());
SqlParameter param1 = new SqlParameter("@uuid", user.UUID.ToStringHyphenated());
SqlParameter param2 = new SqlParameter("@username", user.username);
SqlParameter param3 = new SqlParameter("@lastname", user.surname);
SqlParameter param4 = new SqlParameter("@passwordHash", user.passwordHash);
SqlParameter param5 = new SqlParameter("@passwordSalt", user.passwordSalt);
SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.homeRegion));
SqlParameter param7 = new SqlParameter("@homeLocationX", user.homeLocation.X);
SqlParameter param8 = new SqlParameter("@homeLocationY", user.homeLocation.Y);
SqlParameter param9 = new SqlParameter("@homeLocationZ", user.homeLocation.Y);
SqlParameter param10 = new SqlParameter("@homeLookAtX", user.homeLookAt.X);
SqlParameter param11 = new SqlParameter("@homeLookAtY", user.homeLookAt.Y);
SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.homeLookAt.Z);
SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.created));
SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.lastLogin));
SqlParameter param15 = new SqlParameter("@userInventoryURI", user.userInventoryURI);
SqlParameter param16 = new SqlParameter("@userAssetURI", user.userAssetURI);
SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.profileCanDoMask));
SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask));
SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText);
SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText);
SqlParameter param21 = new SqlParameter("@profileImage", libsecondlife.LLUUID.Zero.ToStringHyphenated());
SqlParameter param22 = new SqlParameter("@profileFirstImage", libsecondlife.LLUUID.Zero.ToStringHyphenated());
SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToStringHyphenated());
command.Parameters.Add(param1);
command.Parameters.Add(param2);
command.Parameters.Add(param3);
command.Parameters.Add(param4);
command.Parameters.Add(param5);
command.Parameters.Add(param6);
command.Parameters.Add(param7);
command.Parameters.Add(param8);
command.Parameters.Add(param9);
command.Parameters.Add(param10);
command.Parameters.Add(param11);
command.Parameters.Add(param12);
command.Parameters.Add(param13);
command.Parameters.Add(param14);
command.Parameters.Add(param15);
command.Parameters.Add(param16);
command.Parameters.Add(param17);
command.Parameters.Add(param18);
command.Parameters.Add(param19);
command.Parameters.Add(param20);
command.Parameters.Add(param21);
command.Parameters.Add(param22);
command.Parameters.Add(param23);
try
{
int affected = command.ExecuteNonQuery();
if (affected != 0) {
return true;
} else {
return false;
}
}
catch (Exception e)
{
MainLog.Instance.Error(e.ToString());
}
return false;
}
/// <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>
public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
{
return false;
}
/// <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>
public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
{
return false;
}
/// <summary>
/// Database provider name
/// </summary>
/// <returns>Provider name</returns>
public string getName()
{
return "MSSQL Userdata Interface";
}
/// <summary>
/// Database provider version
/// </summary>
/// <returns>provider version</returns>
public string GetVersion()
{
return database.getVersion();
}
/// <summary>
/// Not implemented
/// </summary>
/// <param name="query"></param>
public void runQuery(string query)
{
}
}
}

View File

@ -0,0 +1,19 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [assets] (
[id] [varchar](36) NOT NULL,
[name] [varchar](64) NOT NULL,
[description] [varchar](64) NOT NULL,
[assetType] [tinyint] NOT NULL,
[invType] [tinyint] NOT NULL,
[local] [tinyint] NOT NULL,
[temporary] [tinyint] NOT NULL,
[data] [image] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,27 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [inventoryfolders] (
[folderID] [varchar](36) NOT NULL default '',
[agentID] [varchar](36) default NULL,
[parentFolderID] [varchar](36) default NULL,
[folderName] [varchar](64) default NULL,
[type] [smallint] NOT NULL default 0,
[version] [int] NOT NULL default 0,
PRIMARY KEY CLUSTERED
(
[folderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [owner] ON [inventoryfolders]
(
[agentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [parent] ON [inventoryfolders]
(
[parentFolderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,39 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [inventoryitems] (
[inventoryID] [varchar](36) NOT NULL default '',
[assetID] [varchar](36) default NULL,
[assetType] [int] default NULL,
[parentFolderID] [varchar](36) default NULL,
[avatarID] [varchar](36) default NULL,
[inventoryName] [varchar](64) default NULL,
[inventoryDescription] [varchar](64) default NULL,
[inventoryNextPermissions] [int] default NULL,
[inventoryCurrentPermissions] [int] default NULL,
[invType] [int] default NULL,
[creatorID] [varchar](36) default NULL,
[inventoryBasePermissions] [int] NOT NULL default 0,
[inventoryEveryOnePermissions] [int] NOT NULL default 0,
PRIMARY KEY CLUSTERED
(
[inventoryID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [owner] ON [inventoryitems]
(
[avatarID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [folder] ON [inventoryitems]
(
[parentFolderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,37 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [agents] (
[UUID] [varchar](36) NOT NULL,
[sessionID] [varchar](36) NOT NULL,
[secureSessionID] [varchar](36) NOT NULL,
[agentIP] [varchar](16) NOT NULL,
[agentPort] [int] NOT NULL,
[agentOnline] [tinyint] NOT NULL,
[loginTime] [int] NOT NULL,
[logoutTime] [int] NOT NULL,
[currentRegion] [varchar](36) NOT NULL,
[currentHandle] [bigint] NOT NULL,
[currentPos] [varchar](64) NOT NULL,
PRIMARY KEY CLUSTERED
(
[UUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [session] ON [agents]
(
[sessionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [ssession] ON [agents]
(
[secureSessionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,20 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [logs] (
[logID] [int] NOT NULL,
[target] [varchar](36) default NULL,
[server] [varchar](64) default NULL,
[method] [varchar](64) default NULL,
[arguments] [varchar](255) default NULL,
[priority] [int] default NULL,
[message] [ntext],
PRIMARY KEY CLUSTERED
(
[logID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

View File

@ -0,0 +1,41 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [users] (
[UUID] [varchar](36) NOT NULL default '',
[username] [varchar](32) NOT NULL,
[lastname] [varchar](32) NOT NULL,
[passwordHash] [varchar](32) NOT NULL,
[passwordSalt] [varchar](32) NOT NULL,
[homeRegion] [bigint] default NULL,
[homeLocationX] [float] default NULL,
[homeLocationY] [float] default NULL,
[homeLocationZ] [float] default NULL,
[homeLookAtX] [float] default NULL,
[homeLookAtY] [float] default NULL,
[homeLookAtZ] [float] default NULL,
[created] [int] NOT NULL,
[lastLogin] [int] NOT NULL,
[userInventoryURI] [varchar](255) default NULL,
[userAssetURI] [varchar](255) default NULL,
[profileCanDoMask] [int] default NULL,
[profileWantDoMask] [int] default NULL,
[profileAboutText] [ntext],
[profileFirstText] [ntext],
[profileImage] [varchar](36) default NULL,
[profileFirstImage] [varchar](36) default NULL,
PRIMARY KEY CLUSTERED
(
[UUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [usernames] ON [users]
(
[username] ASC,
[lastname] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

View File

@ -426,6 +426,13 @@ namespace OpenSim
{ {
assetServer = new GridAssetClient(m_networkServersInfo.AssetURL); assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
} }
else if (m_assetStorage == "mssql")
{
SQLAssetServer sqlAssetServer = new SQLAssetServer("OpenSim.Framework.Data.MSSQL.dll");
sqlAssetServer.LoadDefaultAssets();
assetServer = sqlAssetServer;
//assetServer = new GridAssetClient("");
}
else else
{ {
SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin); SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin);

File diff suppressed because it is too large Load Diff

6
bin/mssql_connection.ini Normal file
View File

@ -0,0 +1,6 @@
[mssqlconnection]
data_source=\SQLEXPRESS
initial_catalog=database
persist_security_info=True
user_id=username
password=password

View File

@ -672,6 +672,33 @@
</Files> </Files>
</Project> </Project>
<Project name="OpenSim.DataStore.MSSQL" path="OpenSim/Region/Storage/OpenSim.DataStore.MSSQL" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../../bin/</ReferencePath>
<Reference name="System" localCopy="false"/>
<Reference name="System.Xml"/>
<Reference name="System.Data"/>
<Reference name="libsecondlife.dll"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Data"/>
<Reference name="OpenSim.Region.Environment"/>
<Reference name="OpenSim.Framework.Console"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Region.ExtensionsScriptModule" path="OpenSim/Region/ExtensionsScriptModule" type="Library"> <Project name="OpenSim.Region.ExtensionsScriptModule" path="OpenSim/Region/ExtensionsScriptModule" type="Library">
<Configuration name="Debug"> <Configuration name="Debug">
<Options> <Options>
@ -883,10 +910,14 @@
<Reference name="System" localCopy="false"/> <Reference name="System" localCopy="false"/>
<Reference name="System.Xml"/> <Reference name="System.Xml"/>
<Reference name="System.Data"/> <Reference name="System.Data"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Data"/> <Reference name="OpenSim.Framework.Data"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="libsecondlife.dll"/> <Reference name="libsecondlife.dll"/>
<Files> <Files>
<Match pattern="*.cs" recurse="true"/> <Match pattern="*.cs" recurse="true"/>
<Match path="Resources" pattern="*.sql" buildAction="EmbeddedResource"/>
</Files> </Files>
</Project> </Project>
@ -1191,3 +1222,5 @@

View File

@ -0,0 +1,19 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [assets] (
[id] [varchar](36) NOT NULL,
[name] [varchar](64) NOT NULL,
[description] [varchar](64) NOT NULL,
[assetType] [tinyint] NOT NULL,
[invType] [tinyint] NOT NULL,
[local] [tinyint] NOT NULL,
[temporary] [tinyint] NOT NULL,
[data] [image] NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,27 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [inventoryfolders] (
[folderID] [varchar](36) NOT NULL default '',
[agentID] [varchar](36) default NULL,
[parentFolderID] [varchar](36) default NULL,
[folderName] [varchar](64) default NULL,
[type] [smallint] NOT NULL default 0,
[version] [int] NOT NULL default 0,
PRIMARY KEY CLUSTERED
(
[folderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [owner] ON [inventoryfolders]
(
[agentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [parent] ON [inventoryfolders]
(
[parentFolderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,39 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [inventoryitems] (
[inventoryID] [varchar](36) NOT NULL default '',
[assetID] [varchar](36) default NULL,
[assetType] [int] default NULL,
[parentFolderID] [varchar](36) default NULL,
[avatarID] [varchar](36) default NULL,
[inventoryName] [varchar](64) default NULL,
[inventoryDescription] [varchar](64) default NULL,
[inventoryNextPermissions] [int] default NULL,
[inventoryCurrentPermissions] [int] default NULL,
[invType] [int] default NULL,
[creatorID] [varchar](36) default NULL,
[inventoryBasePermissions] [int] NOT NULL default 0,
[inventoryEveryOnePermissions] [int] NOT NULL default 0,
PRIMARY KEY CLUSTERED
(
[inventoryID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [owner] ON [inventoryitems]
(
[avatarID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [folder] ON [inventoryitems]
(
[parentFolderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

View File

@ -0,0 +1,37 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [agents] (
[UUID] [varchar](36) NOT NULL,
[sessionID] [varchar](36) NOT NULL,
[secureSessionID] [varchar](36) NOT NULL,
[agentIP] [varchar](16) NOT NULL,
[agentPort] [int] NOT NULL,
[agentOnline] [tinyint] NOT NULL,
[loginTime] [int] NOT NULL,
[logoutTime] [int] NOT NULL,
[currentRegion] [varchar](36) NOT NULL,
[currentHandle] [bigint] NOT NULL,
[currentPos] [varchar](64) NOT NULL,
PRIMARY KEY CLUSTERED
(
[UUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [session] ON [agents]
(
[sessionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [ssession] ON [agents]
(
[secureSessionID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
SET ANSI_PADDING OFF

20
share/sql/mssql-logs.sql Normal file
View File

@ -0,0 +1,20 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [logs] (
[logID] [int] NOT NULL,
[target] [varchar](36) default NULL,
[server] [varchar](64) default NULL,
[method] [varchar](64) default NULL,
[arguments] [varchar](255) default NULL,
[priority] [int] default NULL,
[message] [ntext],
PRIMARY KEY CLUSTERED
(
[logID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

41
share/sql/mssql-users.sql Normal file
View File

@ -0,0 +1,41 @@
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
CREATE TABLE [users] (
[UUID] [varchar](36) NOT NULL default '',
[username] [varchar](32) NOT NULL,
[lastname] [varchar](32) NOT NULL,
[passwordHash] [varchar](32) NOT NULL,
[passwordSalt] [varchar](32) NOT NULL,
[homeRegion] [bigint] default NULL,
[homeLocationX] [float] default NULL,
[homeLocationY] [float] default NULL,
[homeLocationZ] [float] default NULL,
[homeLookAtX] [float] default NULL,
[homeLookAtY] [float] default NULL,
[homeLookAtZ] [float] default NULL,
[created] [int] NOT NULL,
[lastLogin] [int] NOT NULL,
[userInventoryURI] [varchar](255) default NULL,
[userAssetURI] [varchar](255) default NULL,
[profileCanDoMask] [int] default NULL,
[profileWantDoMask] [int] default NULL,
[profileAboutText] [ntext],
[profileFirstText] [ntext],
[profileImage] [varchar](36) default NULL,
[profileFirstImage] [varchar](36) default NULL,
PRIMARY KEY CLUSTERED
(
[UUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [usernames] ON [users]
(
[username] ASC,
[lastname] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]