Deleted obsolete files in the Data layer. Compiles.

slimupdates
Diva Canto 2010-02-21 15:38:52 -08:00
parent bd5a4dab0c
commit bb171717ce
32 changed files with 103 additions and 9201 deletions

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenSim.Framework;
namespace OpenSim.Data
{
/// <summary>
/// A static class containing methods for obtaining handles to database
/// storage objects.
/// </summary>
public static class DataPluginFactory
{
/// <summary>
/// Based on <typeparam name="T" />, returns the appropriate
/// PluginInitialiserBase instance in <paramref name="init" /> and
/// extension point path in <paramref name="path" />.
/// </summary>
/// <param name="connect">
/// The DB connection string used when creating a new
/// PluginInitialiserBase, returned in <paramref name="init" />.
/// </param>
/// <param name="init">
/// A reference to a PluginInitialiserBase object in which the proper
/// initialiser will be returned.
/// </param>
/// <param name="path">
/// A string in which the proper extension point path will be returned.
/// </param>
/// <typeparam name="T">
/// The type of data plugin requested.
/// </typeparam>
/// <exception cref="NotImplementedException">
/// Thrown if <typeparamref name="T" /> is not one of the expected data
/// interfaces.
/// </exception>
private static void PluginLoaderParamFactory<T>(string connect, out PluginInitialiserBase init, out string path) where T : IPlugin
{
Type type = typeof(T);
if (type == typeof(IInventoryDataPlugin))
{
init = new InventoryDataInitialiser(connect);
path = "/OpenSim/InventoryData";
}
else if (type == typeof(IUserDataPlugin))
{
init = new UserDataInitialiser(connect);
path = "/OpenSim/UserData";
}
else if (type == typeof(IGridDataPlugin))
{
init = new GridDataInitialiser(connect);
path = "/OpenSim/GridData";
}
else if (type == typeof(ILogDataPlugin))
{
init = new LogDataInitialiser(connect);
path = "/OpenSim/LogData";
}
else if (type == typeof(IAssetDataPlugin))
{
init = new AssetDataInitialiser(connect);
path = "/OpenSim/AssetData";
}
else
{
// We don't support this data plugin.
throw new NotImplementedException(String.Format("The type '{0}' is not a valid data plugin.", type));
}
}
/// <summary>
/// Returns a list of new <typeparamref name="T" /> data plugins.
/// Plugins will be requested in the order they were added.
/// </summary>
/// <param name="provider">
/// The filename of the inventory server plugin DLL.
/// </param>
/// <param name="connect">
/// The connection string for the storage backend.
/// </param>
/// <typeparam name="T">
/// The type of data plugin requested.
/// </typeparam>
/// <returns>
/// A list of all loaded plugins matching <typeparamref name="T" />.
/// </returns>
public static List<T> LoadDataPlugins<T>(string provider, string connect) where T : IPlugin
{
PluginInitialiserBase pluginInitialiser;
string extensionPointPath;
PluginLoaderParamFactory<T>(connect, out pluginInitialiser, out extensionPointPath);
using (PluginLoader<T> loader = new PluginLoader<T>(pluginInitialiser))
{
// loader will try to load all providers (MySQL, MSSQL, etc)
// unless it is constrainted to the correct "Provider" entry in the addin.xml
loader.Add(extensionPointPath, new PluginProviderFilter(provider));
loader.Load();
return loader.Plugins;
}
}
/// <summary>
/// Returns a new <typeparamref name="T" /> data plugin instance if
/// only one was loaded, otherwise returns null (<c>default(T)</c>).
/// </summary>
/// <param name="provider">
/// The filename of the inventory server plugin DLL.
/// </param>
/// <param name="connect">
/// The connection string for the storage backend.
/// </param>
/// <typeparam name="T">
/// The type of data plugin requested.
/// </typeparam>
/// <returns>
/// A list of all loaded plugins matching <typeparamref name="T" />.
/// </returns>
public static T LoadDataPlugin<T>(string provider, string connect) where T : IPlugin
{
List<T> plugins = LoadDataPlugins<T>(provider, connect);
return (plugins.Count == 1) ? plugins[0] : default(T);
}
}
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using OpenMetaverse;
namespace OpenSim.Data
{
public abstract class GridDataBase : IGridDataPlugin
{
public abstract RegionProfileData GetProfileByHandle(ulong regionHandle);
public abstract RegionProfileData GetProfileByUUID(UUID UUID);
public abstract RegionProfileData GetProfileByString(string regionName);
public abstract RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax);
public abstract List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum);
public abstract bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey);
public abstract DataResponse StoreProfile(RegionProfileData profile);
public abstract ReservationData GetReservationAtPoint(uint x, uint y);
public abstract DataResponse DeleteProfile(string uuid);
public abstract void Initialise();
public abstract void Initialise(string connect);
public abstract void Dispose();
public abstract string Name { get; }
public abstract string Version { get; }
}
}

View File

@ -1,134 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data
{
public enum DataResponse
{
RESPONSE_OK,
RESPONSE_AUTHREQUIRED,
RESPONSE_INVALIDCREDENTIALS,
RESPONSE_ERROR
}
/// <summary>
/// A standard grid interface
/// </summary>
public interface IGridDataPlugin : IPlugin
{
/// <summary>
/// Initialises the interface
/// </summary>
void Initialise(string connect);
/// <summary>
/// Returns a sim profile from a regionHandle
/// </summary>
/// <param name="regionHandle">A 64bit Region Handle</param>
/// <returns>A simprofile</returns>
RegionProfileData GetProfileByHandle(ulong regionHandle);
/// <summary>
/// Returns a sim profile from a UUID
/// </summary>
/// <param name="UUID">A 128bit UUID</param>
/// <returns>A sim profile</returns>
RegionProfileData GetProfileByUUID(UUID UUID);
/// <summary>
/// Returns a sim profile from a string match
/// </summary>
/// <param name="regionName">A string for a partial region name match</param>
/// <returns>A sim profile</returns>
RegionProfileData GetProfileByString(string regionName);
/// <summary>
/// Returns all profiles within the specified range
/// </summary>
/// <param name="Xmin">Minimum sim coordinate (X)</param>
/// <param name="Ymin">Minimum sim coordinate (Y)</param>
/// <param name="Xmax">Maximum sim coordinate (X)</param>
/// <param name="Ymin">Maximum sim coordinate (Y)</param>
/// <returns>An array containing all the sim profiles in the specified range</returns>
RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax);
/// <summary>
/// Returns up to maxNum profiles of regions that have a name starting with namePrefix
/// </summary>
/// <param name="name">The name to match against</param>
/// <param name="maxNum">Maximum number of profiles to return</param>
/// <returns>A list of sim profiles</returns>
List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum);
/// <summary>
/// Authenticates a sim by use of its recv key.
/// WARNING: Insecure
/// </summary>
/// <param name="UUID">The UUID sent by the sim</param>
/// <param name="regionHandle">The regionhandle sent by the sim</param>
/// <param name="simrecvkey">The receiving key sent by the sim</param>
/// <returns>Whether the sim has been authenticated</returns>
bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey);
/// <summary>
/// Adds or updates a profile in the database
/// </summary>
/// <param name="profile">The profile to add</param>
/// <returns>RESPONSE_OK if successful, error if not.</returns>
DataResponse StoreProfile(RegionProfileData profile);
/// <summary>
/// Remove a profile from the database
/// </summary>
/// <param name="UUID">ID of profile to remove</param>
/// <returns></returns>
DataResponse DeleteProfile(string UUID);
/// <summary>
/// Function not used????
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
ReservationData GetReservationAtPoint(uint x, uint y);
}
public class GridDataInitialiser : PluginInitialiserBase
{
private string connect;
public GridDataInitialiser (string s) { connect = s; }
public override void Initialise (IPlugin plugin)
{
IGridDataPlugin p = plugin as IGridDataPlugin;
p.Initialise (connect);
}
}
}

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using OpenSim.Framework;
namespace OpenSim.Data
{
/// <summary>
/// The severity of an individual log message
/// </summary>
public enum LogSeverity : int
{
/// <summary>
/// Critical: systems failure
/// </summary>
CRITICAL = 1,
/// <summary>
/// Major: warning prior to systems failure
/// </summary>
MAJOR = 2,
/// <summary>
/// Medium: an individual non-critical task failed
/// </summary>
MEDIUM = 3,
/// <summary>
/// Low: Informational warning
/// </summary>
LOW = 4,
/// <summary>
/// Info: Information
/// </summary>
INFO = 5,
/// <summary>
/// Verbose: Debug Information
/// </summary>
VERBOSE = 6
}
/// <summary>
/// An interface to a LogData storage system
/// </summary>
public interface ILogDataPlugin : IPlugin
{
void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority,
string logMessage);
/// <summary>
/// Initialises the interface
/// </summary>
void Initialise(string connect);
}
public class LogDataInitialiser : PluginInitialiserBase
{
private string connect;
public LogDataInitialiser (string s) { connect = s; }
public override void Initialise (IPlugin plugin)
{
ILogDataPlugin p = plugin as ILogDataPlugin;
p.Initialise (connect);
}
}
}

View File

@ -1,100 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
namespace OpenSim.Data
{
public interface IRegionProfileService
{
/// <summary>
/// Returns a region by argument
/// </summary>
/// <param name="uuid">A UUID key of the region to return</param>
/// <returns>A SimProfileData for the region</returns>
RegionProfileData GetRegion(UUID uuid);
/// <summary>
/// Returns a region by argument
/// </summary>
/// <param name="uuid">A regionHandle of the region to return</param>
/// <returns>A SimProfileData for the region</returns>
RegionProfileData GetRegion(ulong handle);
/// <summary>
/// Returns a region by argument
/// </summary>
/// <param name="regionName">A partial regionName of the region to return</param>
/// <returns>A SimProfileData for the region</returns>
RegionProfileData GetRegion(string regionName);
List<RegionProfileData> GetRegions(uint xmin, uint ymin, uint xmax, uint ymax);
List<RegionProfileData> GetRegions(string name, int maxNum);
DataResponse AddUpdateRegion(RegionProfileData sim, RegionProfileData existingSim);
DataResponse DeleteRegion(string uuid);
}
public interface IRegionProfileRouter
{
/// <summary>
/// Request sim profile information from a grid server, by Region UUID
/// </summary>
/// <param name="regionId">The region UUID to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
/// <remarks>This method should be statics</remarks>
RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey);
/// <summary>
/// Request sim profile information from a grid server, by Region Handle
/// </summary>
/// <param name="regionHandle">the region handle to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey);
/// <summary>
/// Request sim profile information from a grid server, by Region Name
/// </summary>
/// <param name="regionName">the region name to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey);
}
}

View File

@ -1,209 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data
{
/// <summary>
/// An interface for connecting to user storage servers.
/// </summary>
public interface IUserDataPlugin : IPlugin
{
/// <summary>
/// Returns a user profile from a database via their UUID
/// </summary>
/// <param name="user">The user's UUID</param>
/// <returns>The user data profile. Returns null if no user is found</returns>
UserProfileData GetUserByUUID(UUID user);
/// <summary>
/// Returns a users profile by searching their username parts
/// </summary>
/// <param name="fname">Account firstname</param>
/// <param name="lname">Account lastname</param>
/// <returns>The user data profile. Null if no user is found</returns>
UserProfileData GetUserByName(string fname, string lname);
/// <summary>
/// Get a user from a given uri.
/// </summary>
/// <param name="uri"></param>
/// <returns>The user data profile. Null if no user is found.</returns>
UserProfileData GetUserByUri(Uri uri);
/// <summary>
/// Returns a list of UUIDs firstnames and lastnames that match string query entered into the avatar picker.
/// </summary>
/// <param name="queryID">ID associated with the user's query. This must match what the client sent</param>
/// <param name="query">The filtered contents of the search box when the user hit search.</param>
/// <returns>A list of user details. If there are no results than either an empty list or null</returns>
List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query);
/// <summary>
/// Returns the current agent for a user searching by it's UUID
/// </summary>
/// <param name="user">The users UUID</param>
/// <returns>The current agent session. Null if no session was found</returns>
UserAgentData GetAgentByUUID(UUID user);
/// <summary>
/// Returns the current session agent for a user searching by username
/// </summary>
/// <param name="name">The users account name</param>
/// <returns>The current agent session</returns>
UserAgentData GetAgentByName(string name);
/// <summary>
/// Returns the current session agent for a user searching by username parts
/// </summary>
/// <param name="fname">The users first account name</param>
/// <param name="lname">The users account surname</param>
/// <returns>The current agent session</returns>
UserAgentData GetAgentByName(string fname, string lname);
/// <summary>
/// Stores new web-login key for user during web page login
/// </summary>
/// <param name="webLoginKey"></param>
void StoreWebLoginKey(UUID agentID, UUID webLoginKey);
/// <summary>
/// Adds a new User profile to the database
/// </summary>
/// <param name="user">UserProfile to add</param>
void AddNewUserProfile(UserProfileData user);
/// <summary>
/// Adds a temporary user profile. A temporary userprofile is one that should exist only for the lifetime of
/// the process.
/// </summary>
/// <param name="userProfile"></param>
void AddTemporaryUserProfile(UserProfileData userProfile);
/// <summary>
/// Updates an existing user profile
/// </summary>
/// <param name="user">UserProfile to update</param>
bool UpdateUserProfile(UserProfileData user);
/// <summary>
/// Adds a new agent to the database
/// </summary>
/// <param name="agent">The agent to add</param>
void AddNewUserAgent(UserAgentData agent);
/// <summary>
/// Adds a new friend to the database for XUser
/// </summary>
/// <param name="friendlistowner">The agent that who's friends list is being added to</param>
/// <param name="friend">The agent that being added to the friends list of the friends list owner</param>
/// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms);
/// <summary>
/// Delete friend on friendlistowner's friendlist.
/// </summary>
/// <param name="friendlistowner">The agent that who's friends list is being updated</param>
/// <param name="friend">The Ex-friend agent</param>
void RemoveUserFriend(UUID friendlistowner, UUID friend);
/// <summary>
/// Update permissions for friend on friendlistowner's friendlist.
/// </summary>
/// <param name="friendlistowner">The agent that who's friends list is being updated</param>
/// <param name="friend">The agent that is getting or loosing permissions</param>
/// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param>
void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms);
/// <summary>
/// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner
/// </summary>
/// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param>
/// <returns>The user's friends. If there are no results than either an empty list or null</returns>
List<FriendListItem> GetUserFriendList(UUID friendlistowner);
/// <summary>
/// Returns a list of <see cref="FriendRegionInfo/>s for the specified UUIDs.
/// </summary>
/// <param name="uuids">
/// A <see cref="List"/> of <see cref="UUID/>s to fetch info for
/// </param>
/// <returns>
/// A <see cref="Dictionary"/>, mapping the <see cref="UUID"/>s to <see cref="FriendRegionInfo"/>s.
/// </returns>
Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids);
/// <summary>
/// Attempts to move currency units between accounts (NOT RELIABLE / TRUSTWORTHY. DONT TRY RUN YOUR OWN CURRENCY EXCHANGE WITH REAL VALUES)
/// </summary>
/// <param name="from">The account to transfer from</param>
/// <param name="to">The account to transfer to</param>
/// <param name="amount">The amount to transfer</param>
/// <returns>Successful?</returns>
bool MoneyTransferRequest(UUID from, UUID to, uint amount);
/// <summary>
/// Attempts to move inventory between accounts, if inventory is copyable it will be copied into the target account.
/// </summary>
/// <param name="from">User to transfer from</param>
/// <param name="to">User to transfer to</param>
/// <param name="inventory">Specified inventory item</param>
/// <returns>Successful?</returns>
bool InventoryTransferRequest(UUID from, UUID to, UUID inventory);
/// <summary>
/// Initialises the plugin (artificial constructor)
/// </summary>
void Initialise(string connect);
/// <summary>
/// Gets the user appearance
/// </summer>
AvatarAppearance GetUserAppearance(UUID user);
void UpdateUserAppearance(UUID user, AvatarAppearance appearance);
void ResetAttachments(UUID userID);
void LogoutUsers(UUID regionID);
}
public class UserDataInitialiser : PluginInitialiserBase
{
private string connect;
public UserDataInitialiser (string s) { connect = s; }
public override void Initialise (IPlugin plugin)
{
IUserDataPlugin p = plugin as IUserDataPlugin;
p.Initialise (connect);
}
}
}

View File

@ -1,587 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data.MSSQL
{
/// <summary>
/// A grid data interface for MSSQL Server
/// </summary>
public class MSSQLGridData : GridDataBase
{
private const string _migrationStore = "GridStore";
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Database manager
/// </summary>
private MSSQLManager database;
private string m_regionsTableName = "regions";
#region IPlugin Members
// [Obsolete("Cannot be default-initialized!")]
override public void Initialise()
{
m_log.Info("[GRID DB]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException(Name);
}
/// <summary>
/// Initialises the Grid Interface
/// </summary>
/// <param name="connectionString">connect string</param>
/// <remarks>use mssql_connection.ini</remarks>
override public void Initialise(string connectionString)
{
if (!string.IsNullOrEmpty(connectionString))
{
database = new MSSQLManager(connectionString);
}
else
{
// TODO: make the connect string actually do something
IniFile iniFile = new IniFile("mssql_connection.ini");
string settingDataSource = iniFile.ParseFileReadValue("data_source");
string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
string settingUserId = iniFile.ParseFileReadValue("user_id");
string settingPassword = iniFile.ParseFileReadValue("password");
m_regionsTableName = iniFile.ParseFileReadValue("regionstablename");
if (m_regionsTableName == null)
{
m_regionsTableName = "regions";
}
database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword);
}
//New migrations check of store
database.CheckMigration(_migrationStore);
}
/// <summary>
/// Shuts down the grid interface
/// </summary>
override public void Dispose()
{
database = null;
}
/// <summary>
/// The name of this DB provider.
/// </summary>
/// <returns>A string containing the storage system name</returns>
override public string Name
{
get { return "MSSQL OpenGridData"; }
}
/// <summary>
/// Database provider version.
/// </summary>
/// <returns>A string containing the storage system version</returns>
override public string Version
{
get { return "0.1"; }
}
#endregion
#region Public override GridDataBase methods
/// <summary>
/// Returns a list of regions within the specified ranges
/// </summary>
/// <param name="xmin">minimum X coordinate</param>
/// <param name="ymin">minimum Y coordinate</param>
/// <param name="xmax">maximum X coordinate</param>
/// <param name="ymax">maximum Y coordinate</param>
/// <returns>null</returns>
/// <remarks>always return null</remarks>
override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
{
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM regions WHERE locX >= @xmin AND locX <= @xmax AND locY >= @ymin AND locY <= @ymax"))
{
command.Parameters.Add(database.CreateParameter("xmin", xmin));
command.Parameters.Add(database.CreateParameter("ymin", ymin));
command.Parameters.Add(database.CreateParameter("xmax", xmax));
command.Parameters.Add(database.CreateParameter("ymax", ymax));
List<RegionProfileData> rows = new List<RegionProfileData>();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
rows.Add(ReadSimRow(reader));
}
}
if (rows.Count > 0)
{
return rows.ToArray();
}
}
m_log.Info("[GRID DB] : Found no regions within range.");
return null;
}
/// <summary>
/// Returns up to maxNum profiles of regions that have a name starting with namePrefix
/// </summary>
/// <param name="namePrefix">The name to match against</param>
/// <param name="maxNum">Maximum number of profiles to return</param>
/// <returns>A list of sim profiles</returns>
override public List<RegionProfileData> GetRegionsByName (string namePrefix, uint maxNum)
{
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM regions WHERE regionName LIKE @name"))
{
command.Parameters.Add(database.CreateParameter("name", namePrefix + "%"));
List<RegionProfileData> rows = new List<RegionProfileData>();
using (SqlDataReader reader = command.ExecuteReader())
{
while (rows.Count < maxNum && reader.Read())
{
rows.Add(ReadSimRow(reader));
}
}
return rows;
}
}
/// <summary>
/// Returns a sim profile from its location
/// </summary>
/// <param name="handle">Region location handle</param>
/// <returns>Sim profile</returns>
override public RegionProfileData GetProfileByHandle(ulong handle)
{
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle"))
{
command.Parameters.Add(database.CreateParameter("handle", handle));
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return ReadSimRow(reader);
}
}
}
m_log.InfoFormat("[GRID DB] : No region found with handle : {0}", handle);
return null;
}
/// <summary>
/// Returns a sim profile from its UUID
/// </summary>
/// <param name="uuid">The region UUID</param>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByUUID(UUID uuid)
{
using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid"))
{
command.Parameters.Add(database.CreateParameter("uuid", uuid));
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return ReadSimRow(reader);
}
}
}
m_log.InfoFormat("[GRID DB] : No region found with UUID : {0}", uuid);
return null;
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <param name="regionName">The region name search query</param>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
using (AutoClosingSqlCommand command = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like @regionName order by regionName"))
{
command.Parameters.Add(database.CreateParameter("regionName", regionName + "%"));
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return ReadSimRow(reader);
}
}
}
m_log.InfoFormat("[GRID DB] : No region found with regionName : {0}", regionName);
return null;
}
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
return null;
}
/// <summary>
/// Adds a new specified region to the database
/// </summary>
/// <param name="profile">The profile to add</param>
/// <returns>A dataresponse enum indicating success</returns>
override public DataResponse StoreProfile(RegionProfileData profile)
{
if (GetProfileByUUID(profile.UUID) == null)
{
if (InsertRegionRow(profile))
{
return DataResponse.RESPONSE_OK;
}
}
else
{
if (UpdateRegionRow(profile))
{
return DataResponse.RESPONSE_OK;
}
}
return DataResponse.RESPONSE_ERROR;
}
/// <summary>
/// Deletes a sim profile from the database
/// </summary>
/// <param name="uuid">the sim UUID</param>
/// <returns>Successful?</returns>
//public DataResponse DeleteProfile(RegionProfileData profile)
override public DataResponse DeleteProfile(string uuid)
{
using (AutoClosingSqlCommand command = database.Query("DELETE FROM regions WHERE uuid = @uuid;"))
{
command.Parameters.Add(database.CreateParameter("uuid", uuid));
try
{
command.ExecuteNonQuery();
return DataResponse.RESPONSE_OK;
}
catch (Exception e)
{
m_log.DebugFormat("[GRID DB] : Error deleting region info, error is : {0}", e.Message);
return DataResponse.RESPONSE_ERROR;
}
}
}
#endregion
#region Methods that are not used or deprecated (still needed because of base class)
/// <summary>
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary>
/// <param name="uuid">The UUID of the challenger</param>
/// <param name="handle">The attempted regionHandle of the challenger</param>
/// <param name="authkey">The secret</param>
/// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey)
{
bool throwHissyFit = false; // Should be true by 1.0
if (throwHissyFit)
throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
RegionProfileData data = GetProfileByUUID(uuid);
return (handle == data.regionHandle && authkey == data.regionSecret);
}
/// <summary>
/// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
/// </summary>
/// <remarks>This requires a security audit.</remarks>
/// <param name="uuid"></param>
/// <param name="handle"></param>
/// <param name="authhash"></param>
/// <param name="challenge"></param>
/// <returns></returns>
public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge)
{
// SHA512Managed HashProvider = new SHA512Managed();
// Encoding TextProvider = new UTF8Encoding();
// byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge);
// byte[] hash = HashProvider.ComputeHash(stream);
return false;
}
/// <summary>
/// NOT IMPLEMENTED
/// WHEN IS THIS GONNA BE IMPLEMENTED.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>null</returns>
override public ReservationData GetReservationAtPoint(uint x, uint y)
{
return null;
}
#endregion
#region private methods
/// <summary>
/// Reads a region row from a database reader
/// </summary>
/// <param name="reader">An active database reader</param>
/// <returns>A region profile</returns>
private static RegionProfileData ReadSimRow(IDataRecord reader)
{
RegionProfileData retval = new RegionProfileData();
// Region Main gotta-have-or-we-return-null parts
UInt64 tmp64;
if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64))
{
return null;
}
retval.regionHandle = tmp64;
// UUID tmp_uuid;
// if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid))
// {
// return null;
// }
retval.UUID = new UUID((Guid)reader["uuid"]); // tmp_uuid;
// non-critical parts
retval.regionName = reader["regionName"].ToString();
retval.originUUID = new UUID((Guid)reader["originUUID"]);
// Secrets
retval.regionRecvKey = reader["regionRecvKey"].ToString();
retval.regionSecret = reader["regionSecret"].ToString();
retval.regionSendKey = reader["regionSendKey"].ToString();
// Region Server
retval.regionDataURI = reader["regionDataURI"].ToString();
retval.regionOnline = false; // Needs to be pinged before this can be set.
retval.serverIP = reader["serverIP"].ToString();
retval.serverPort = Convert.ToUInt32(reader["serverPort"]);
retval.serverURI = reader["serverURI"].ToString();
retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString());
retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString());
// Location
retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
// Neighbours - 0 = No Override
retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
// Assets
retval.regionAssetURI = reader["regionAssetURI"].ToString();
retval.regionAssetRecvKey = reader["regionAssetRecvKey"].ToString();
retval.regionAssetSendKey = reader["regionAssetSendKey"].ToString();
// Userserver
retval.regionUserURI = reader["regionUserURI"].ToString();
retval.regionUserRecvKey = reader["regionUserRecvKey"].ToString();
retval.regionUserSendKey = reader["regionUserSendKey"].ToString();
// World Map Addition
retval.regionMapTextureID = new UUID((Guid)reader["regionMapTexture"]);
retval.owner_uuid = new UUID((Guid)reader["owner_uuid"]);
retval.maturity = Convert.ToUInt32(reader["access"]);
return retval;
}
/// <summary>
/// Update the specified region in the database
/// </summary>
/// <param name="profile">The profile to update</param>
/// <returns>success ?</returns>
private bool UpdateRegionRow(RegionProfileData profile)
{
bool returnval = false;
//Insert new region
string sql =
"UPDATE " + m_regionsTableName + @" SET
[regionHandle]=@regionHandle, [regionName]=@regionName,
[regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey,
[regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI,
[locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle,
[westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle,
[northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI,
[regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey,
[regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey,
[regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort,
[serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid , [originUUID]=@originUUID
where [uuid]=@uuid";
using (AutoClosingSqlCommand command = database.Query(sql))
{
command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
try
{
command.ExecuteNonQuery();
returnval = true;
}
catch (Exception e)
{
m_log.Error("[GRID DB] : Error updating region, error: " + e.Message);
}
}
return returnval;
}
/// <summary>
/// Creates a new region in the database
/// </summary>
/// <param name="profile">The region profile to insert</param>
/// <returns>Successful?</returns>
private bool InsertRegionRow(RegionProfileData profile)
{
bool returnval = false;
//Insert new region
string sql =
"INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI],
[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
[southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
[regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
[serverRemotingPort], [owner_uuid], [originUUID], [access])
VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
@southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
@regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID, @access);";
using (AutoClosingSqlCommand command = database.Query(sql))
{
command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle));
command.Parameters.Add(database.CreateParameter("regionName", profile.regionName));
command.Parameters.Add(database.CreateParameter("uuid", profile.UUID));
command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey));
command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret));
command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey));
command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI));
command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP));
command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort));
command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI));
command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX));
command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY));
command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ));
command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle));
command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle));
command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle));
command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle));
command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI));
command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey));
command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey));
command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI));
command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey));
command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey));
command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID));
command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort));
command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort));
command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid));
command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID));
command.Parameters.Add(database.CreateParameter("access", profile.maturity));
try
{
command.ExecuteNonQuery();
returnval = true;
}
catch (Exception e)
{
m_log.Error("[GRID DB] : Error inserting region, error: " + e.Message);
}
}
return returnval;
}
#endregion
}
}

View File

@ -1,146 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Reflection;
using log4net;
using OpenSim.Framework;
namespace OpenSim.Data.MSSQL
{
/// <summary>
/// An interface to the log database for MSSQL
/// </summary>
internal class MSSQLLogData : ILogDataPlugin
{
private const string _migrationStore = "LogStore";
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// The database manager
/// </summary>
public MSSQLManager database;
[Obsolete("Cannot be default-initialized!")]
public void Initialise()
{
m_log.Info("[LOG DB]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException (Name);
}
/// <summary>
/// Artificial constructor called when the plugin is loaded
/// </summary>
public void Initialise(string connect)
{
if (!string.IsNullOrEmpty(connect))
{
database = new MSSQLManager(connect);
}
else
{
// TODO: do something with the connect string
IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword);
}
//Updating mechanisme
database.CheckMigration(_migrationStore);
}
/// <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)
{
string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES ";
sql += "(@target, @server, @method, @arguments, @priority, @message);";
using (AutoClosingSqlCommand command = database.Query(sql))
{
command.Parameters.Add(database.CreateParameter("server", serverDaemon));
command.Parameters.Add(database.CreateParameter("target",target));
command.Parameters.Add(database.CreateParameter("method", methodCall));
command.Parameters.Add(database.CreateParameter("arguments", arguments));
command.Parameters.Add(database.CreateParameter("priority", priority.ToString()));
command.Parameters.Add(database.CreateParameter("message", logMessage));
try
{
command.ExecuteNonQuery();
}
catch (Exception e)
{
//Are we not in a loop here
m_log.Error("[LOG DB] Error logging : " + e.Message);
}
}
}
/// <summary>
/// Returns the name of this DB provider
/// </summary>
/// <returns>A string containing the DB provider name</returns>
public string Name
{
get { return "MSSQL Logdata Interface"; }
}
/// <summary>
/// Closes the database provider
/// </summary>
public void Dispose()
{
database = null;
}
/// <summary>
/// Returns the version of this DB provider
/// </summary>
/// <returns>A string containing the provider version</returns>
public string Version
{
get { return "0.1"; }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,422 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Threading;
using log4net;
using MySql.Data.MySqlClient;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data.MySQL
{
/// <summary>
/// A MySQL Interface for the Grid Server
/// </summary>
public class MySQLGridData : GridDataBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MySQLManager m_database;
private object m_dbLock = new object();
private string m_connectionString;
override public void Initialise()
{
m_log.Info("[MySQLGridData]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException (Name);
}
/// <summary>
/// <para>Initialises Grid interface</para>
/// <para>
/// <list type="bullet">
/// <item>Loads and initialises the MySQL storage plugin</item>
/// <item>Warns and uses the obsolete mysql_connection.ini if connect string is empty.</item>
/// <item>Check for migration</item>
/// </list>
/// </para>
/// </summary>
/// <param name="connect">connect string.</param>
override public void Initialise(string connect)
{
m_connectionString = connect;
m_database = new MySQLManager(connect);
// This actually does the roll forward assembly stuff
Assembly assem = GetType().Assembly;
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
Migration m = new Migration(dbcon, assem, "GridStore");
m.Update();
}
}
/// <summary>
/// Shuts down the grid interface
/// </summary>
override public void Dispose()
{
}
/// <summary>
/// Returns the plugin name
/// </summary>
/// <returns>Plugin name</returns>
override public string Name
{
get { return "MySql OpenGridData"; }
}
/// <summary>
/// Returns the plugin version
/// </summary>
/// <returns>Plugin version</returns>
override public string Version
{
get { return "0.1"; }
}
/// <summary>
/// Returns all the specified region profiles within coordates -- coordinates are inclusive
/// </summary>
/// <param name="xmin">Minimum X coordinate</param>
/// <param name="ymin">Minimum Y coordinate</param>
/// <param name="xmax">Maximum X coordinate</param>
/// <param name="ymax">Maximum Y coordinate</param>
/// <returns>Array of sim profiles</returns>
override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?xmin"] = xmin.ToString();
param["?ymin"] = ymin.ToString();
param["?xmax"] = xmax.ToString();
param["?ymax"] = ymax.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while ((row = m_database.readSimRow(reader)) != null)
rows.Add(row);
return rows.ToArray();
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Returns up to maxNum profiles of regions that have a name starting with namePrefix
/// </summary>
/// <param name="name">The name to match against</param>
/// <param name="maxNum">Maximum number of profiles to return</param>
/// <returns>A list of sim profiles</returns>
override public List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?name"] = namePrefix + "%";
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT * FROM regions WHERE regionName LIKE ?name",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row;
List<RegionProfileData> rows = new List<RegionProfileData>();
while (rows.Count < maxNum && (row = m_database.readSimRow(reader)) != null)
rows.Add(row);
return rows;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Returns a sim profile from it's location
/// </summary>
/// <param name="handle">Region location handle</param>
/// <returns>Sim profile</returns>
override public RegionProfileData GetProfileByHandle(ulong handle)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?handle"] = handle.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE regionHandle = ?handle", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = m_database.readSimRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Returns a sim profile from it's UUID
/// </summary>
/// <param name="uuid">The region UUID</param>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByUUID(UUID uuid)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE uuid = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = m_database.readSimRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
// Add % because this is a like query.
param["?regionName"] = regionName + "%";
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
// Order by statement will return shorter matches first. Only returns one record or no record.
using (IDbCommand result = m_database.Query(dbcon,
"SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
RegionProfileData row = m_database.readSimRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters");
return null;
}
/// <summary>
/// Adds a new profile to the database
/// </summary>
/// <param name="profile">The profile to add</param>
/// <returns>Successful?</returns>
override public DataResponse StoreProfile(RegionProfileData profile)
{
try
{
if (m_database.insertRegion(profile))
return DataResponse.RESPONSE_OK;
else
return DataResponse.RESPONSE_ERROR;
}
catch
{
return DataResponse.RESPONSE_ERROR;
}
}
/// <summary>
/// Deletes a sim profile from the database
/// </summary>
/// <param name="uuid">the sim UUID</param>
/// <returns>Successful?</returns>
//public DataResponse DeleteProfile(RegionProfileData profile)
override public DataResponse DeleteProfile(string uuid)
{
try
{
if (m_database.deleteRegion(uuid))
return DataResponse.RESPONSE_OK;
else
return DataResponse.RESPONSE_ERROR;
}
catch
{
return DataResponse.RESPONSE_ERROR;
}
}
/// <summary>
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary>
/// <param name="uuid">The UUID of the challenger</param>
/// <param name="handle">The attempted regionHandle of the challenger</param>
/// <param name="authkey">The secret</param>
/// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey)
{
bool throwHissyFit = false; // Should be true by 1.0
if (throwHissyFit)
throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
RegionProfileData data = GetProfileByUUID(uuid);
return (handle == data.regionHandle && authkey == data.regionSecret);
}
/// <summary>
/// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
/// </summary>
/// <remarks>This requires a security audit.</remarks>
/// <param name="uuid"></param>
/// <param name="handle"></param>
/// <param name="authhash"></param>
/// <param name="challenge"></param>
/// <returns></returns>
public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge)
{
// SHA512Managed HashProvider = new SHA512Managed();
// Encoding TextProvider = new UTF8Encoding();
// byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge);
// byte[] hash = HashProvider.ComputeHash(stream);
return false;
}
/// <summary>
/// Adds a location reservation
/// </summary>
/// <param name="x">x coordinate</param>
/// <param name="y">y coordinate</param>
/// <returns></returns>
override public ReservationData GetReservationAtPoint(uint x, uint y)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?x"] = x.ToString();
param["?y"] = y.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
ReservationData row = m_database.readReservationRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
}
}

View File

@ -1,166 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
using OpenSim.Framework;
namespace OpenSim.Data.MySQL
{
/// <summary>
/// An interface to the log database for MySQL
/// </summary>
internal class MySQLLogData : ILogDataPlugin
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// The database manager
/// </summary>
public MySQLManager database;
public void Initialise()
{
m_log.Info("[MySQLLogData]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException (Name);
}
/// <summary>
/// Artificial constructor called when the plugin is loaded
/// Uses the obsolete mysql_connection.ini if connect string is empty.
/// </summary>
/// <param name="connect">connect string</param>
public void Initialise(string connect)
{
if (connect != String.Empty)
{
database = new MySQLManager(connect);
}
else
{
m_log.Warn("Using deprecated mysql_connection.ini. Please update database_connect in GridServer_Config.xml and we'll use that instead");
IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword,
settingPooling, settingPort);
}
// This actually does the roll forward assembly stuff
Assembly assem = GetType().Assembly;
using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(connect))
{
dbcon.Open();
Migration m = new Migration(dbcon, assem, "LogStore");
// TODO: After rev 6000, remove this. People should have
// been rolled onto the new migration code by then.
TestTables(m);
m.Update();
}
}
/// <summary></summary>
/// <param name="m"></param>
private void TestTables(Migration m)
{
// under migrations, bail
if (m.Version > 0)
return;
Dictionary<string, string> tableList = new Dictionary<string, string>();
tableList["logs"] = null;
database.GetTableVersion(tableList);
// migrations will handle it
if (tableList["logs"] == null)
return;
// we have the table, so pretend like we did the first migration in the past
if (m.Version == 0)
m.Version = 1;
}
/// <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
{
}
}
/// <summary>
/// Returns the name of this DB provider
/// </summary>
/// <returns>A string containing the DB provider name</returns>
public string Name
{
get { return "MySQL Logdata Interface";}
}
/// <summary>
/// Closes the database provider
/// </summary>
/// <remarks>do nothing</remarks>
public void Dispose()
{
// Do nothing.
}
/// <summary>
/// Returns the version of this DB provider
/// </summary>
/// <returns>A string containing the provider version</returns>
public string Version
{
get { return "0.1"; }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Threading;
namespace OpenSim.Data.MySQL
{
public class MySQLSuperManager
{
public bool Locked;
private readonly Mutex m_lock = new Mutex(false);
public MySQLManager Manager;
public string Running;
public void GetLock()
{
Locked = true;
m_lock.WaitOne();
}
public void Release()
{
m_lock.ReleaseMutex();
Locked = false;
}
}
}

View File

@ -1,766 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using log4net;
using MySql.Data.MySqlClient;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data.MySQL
{
/// <summary>
/// A database interface class to a user profile storage system
/// </summary>
public class MySQLUserData : UserDataBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MySQLManager m_database;
private string m_connectionString;
private object m_dbLock = new object();
public int m_maxConnections = 10;
public int m_lastConnect;
private string m_agentsTableName = "agents";
private string m_usersTableName = "users";
private string m_userFriendsTableName = "userfriends";
private string m_appearanceTableName = "avatarappearance";
private string m_attachmentsTableName = "avatarattachments";
public override void Initialise()
{
m_log.Info("[MySQLUserData]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException(Name);
}
/// <summary>
/// Initialise User Interface
/// Loads and initialises the MySQL storage plugin
/// Warns and uses the obsolete mysql_connection.ini if connect string is empty.
/// Checks for migration
/// </summary>
/// <param name="connect">connect string.</param>
public override void Initialise(string connect)
{
m_connectionString = connect;
m_database = new MySQLManager(connect);
// This actually does the roll forward assembly stuff
Assembly assem = GetType().Assembly;
using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(m_connectionString))
{
dbcon.Open();
Migration m = new Migration(dbcon, assem, "UserStore");
m.Update();
}
}
public override void Dispose()
{
}
// see IUserDataPlugin
public override UserProfileData GetUserByName(string user, string last)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?first"] = user;
param["?second"] = last;
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserProfileData row = m_database.readUserRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
#region User Friends List Data
public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
{
int dtvalue = Util.UnixTimeSinceEpoch();
Dictionary<string, object> param = new Dictionary<string, object>();
param["?ownerID"] = friendlistowner.ToString();
param["?friendID"] = friend.ToString();
param["?friendPerms"] = perms.ToString();
param["?datetimestamp"] = dtvalue.ToString();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand adder = m_database.Query(dbcon,
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?ownerID,?friendID,?friendPerms,?datetimestamp)",
param))
{
adder.ExecuteNonQuery();
}
using (IDbCommand adder = m_database.Query(dbcon,
"INSERT INTO `" + m_userFriendsTableName + "` " +
"(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
"VALUES " +
"(?friendID,?ownerID,?friendPerms,?datetimestamp)",
param))
{
adder.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return;
}
}
public override void RemoveUserFriend(UUID friendlistowner, UUID friend)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?ownerID"] = friendlistowner.ToString();
param["?friendID"] = friend.ToString();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand updater = m_database.Query(dbcon,
"delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
param))
{
updater.ExecuteNonQuery();
}
using (IDbCommand updater = m_database.Query(dbcon,
"delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
param))
{
updater.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return;
}
}
public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?ownerID"] = friendlistowner.ToString();
param["?friendID"] = friend.ToString();
param["?friendPerms"] = perms.ToString();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand updater = m_database.Query(dbcon,
"update " + m_userFriendsTableName +
" SET friendPerms = ?friendPerms " +
"where ownerID = ?ownerID and friendID = ?friendID",
param))
{
updater.ExecuteNonQuery();
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return;
}
}
public override List<FriendListItem> GetUserFriendList(UUID friendlistowner)
{
List<FriendListItem> Lfli = new List<FriendListItem>();
Dictionary<string, object> param = new Dictionary<string, object>();
param["?ownerID"] = friendlistowner.ToString();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
//Left Join userfriends to itself
using (IDbCommand result = m_database.Query(dbcon,
"select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " +
m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
" where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendListItem fli = new FriendListItem();
fli.FriendListOwner = new UUID((string)reader["ownerID"]);
fli.Friend = new UUID((string)reader["friendID"]);
fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);
// This is not a real column in the database table, it's a joined column from the opposite record
fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
Lfli.Add(fli);
}
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return Lfli;
}
return Lfli;
}
override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids)
{
Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
foreach (UUID uuid in uuids)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
using (IDbCommand result = m_database.Query(dbcon, "select agentOnline,currentHandle from " + m_agentsTableName +
" where UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
FriendRegionInfo fri = new FriendRegionInfo();
fri.isOnline = (sbyte)reader["agentOnline"] != 0;
fri.regionHandle = (ulong)reader["currentHandle"];
infos[uuid] = fri;
}
}
}
}
}
}
catch (Exception e)
{
m_log.Warn("[MYSQL]: Got exception on trying to find friends regions:", e);
m_log.Error(e.Message, e);
}
return infos;
}
#endregion
public override List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query)
{
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
string[] querysplit;
querysplit = query.Split(' ');
if (querysplit.Length > 1 && querysplit[1].Trim() != String.Empty)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], String.Empty) + "%";
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first AND lastname like ?second LIMIT 100",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return returnlist;
}
}
else
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT UUID,username,lastname FROM " + m_usersTableName +
" WHERE username like ?first OR lastname like ?first LIMIT 100",
param))
{
using (IDataReader reader = result.ExecuteReader())
{
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
user.AvatarID = new UUID((string)reader["UUID"]);
user.firstName = (string)reader["username"];
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return returnlist;
}
}
return returnlist;
}
/// <summary>
/// See IUserDataPlugin
/// </summary>
/// <param name="uuid">User UUID</param>
/// <returns>User profile data</returns>
public override UserProfileData GetUserByUUID(UUID uuid)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserProfileData row = m_database.readUserRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Returns a user session searching by name
/// </summary>
/// <param name="name">The account name : "Username Lastname"</param>
/// <returns>The users session</returns>
public override 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 override UserAgentData GetAgentByName(string user, string last)
{
UserProfileData profile = GetUserByName(user, last);
return GetAgentByUUID(profile.ID);
}
/// <summary>
/// </summary>
/// <param name="AgentID"></param>
/// <param name="WebLoginKey"></param>
/// <remarks>is it still used ?</remarks>
public override void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["?UUID"] = AgentID.ToString();
param["?webLoginKey"] = WebLoginKey.ToString();
try
{
m_database.ExecuteParameterizedSql(
"update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " +
"where UUID = ?UUID",
param);
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return;
}
}
/// <summary>
/// Returns an agent session by account UUID
/// </summary>
/// <param name="uuid">The accounts UUID</param>
/// <returns>The users session</returns>
public override UserAgentData GetAgentByUUID(UUID uuid)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = uuid.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
UserAgentData row = m_database.readAgentRow(reader);
return row;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Creates a new users profile
/// </summary>
/// <param name="user">The user profile to create</param>
public override void AddNewUserProfile(UserProfileData user)
{
UUID zero = UUID.Zero;
if (user.ID == zero)
{
return;
}
try
{
m_database.insertUserRow(
user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
user.HomeRegion, user.HomeRegionID, 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.CanDoMask, user.WantDoMask,
user.AboutText, user.FirstLifeAboutText, user.Image,
user.FirstLifeImage, user.WebLoginKey, user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
}
catch (Exception e)
{
m_log.Error(e.Message, e);
}
}
/// <summary>
/// Creates a new agent
/// </summary>
/// <param name="agent">The agent to create</param>
public override void AddNewUserAgent(UserAgentData agent)
{
UUID zero = UUID.Zero;
if (agent.ProfileID == zero || agent.SessionID == zero)
return;
try
{
m_database.insertAgentRow(agent);
}
catch (Exception e)
{
m_log.Error(e.Message, e);
}
}
/// <summary>
/// Updates a user profile stored in the DB
/// </summary>
/// <param name="user">The profile data to use to update the DB</param>
public override bool UpdateUserProfile(UserProfileData user)
{
try
{
m_database.updateUserRow(
user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
user.HomeRegion, user.HomeRegionID, 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.CanDoMask, user.WantDoMask, user.AboutText,
user.FirstLifeAboutText, user.Image, user.FirstLifeImage, user.WebLoginKey,
user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
return true;
}
catch
{
return false;
}
}
/// <summary>
/// Performs a money transfer request between two accounts
/// </summary>
/// <param name="from">The senders account ID</param>
/// <param name="to">The receivers account ID</param>
/// <param name="amount">The amount to transfer</param>
/// <returns>Success?</returns>
public override bool MoneyTransferRequest(UUID from, UUID 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 receivers account ID</param>
/// <param name="item">The item to transfer</param>
/// <returns>Success?</returns>
public override bool InventoryTransferRequest(UUID from, UUID to, UUID item)
{
return false;
}
public override AvatarAppearance GetUserAppearance(UUID user)
{
try
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?owner"] = user.ToString();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param))
{
using (IDataReader reader = result.ExecuteReader())
{
AvatarAppearance appearance = m_database.readAppearanceRow(reader);
if (appearance == null)
{
m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString());
return null;
}
else
{
appearance.SetAttachments(GetUserAttachments(user));
return appearance;
}
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
/// <summary>
/// Updates an avatar appearence
/// </summary>
/// <param name="user">The user UUID</param>
/// <param name="appearance">The avatar appearance</param>
// override
public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
{
try
{
appearance.Owner = user;
m_database.insertAppearanceRow(appearance);
UpdateUserAttachments(user, appearance.GetAttachments());
}
catch (Exception e)
{
m_log.Error(e.Message, e);
}
}
/// <summary>
/// Database provider name
/// </summary>
/// <returns>Provider name</returns>
public override string Name
{
get { return "MySQL Userdata Interface"; }
}
/// <summary>
/// Database provider version
/// </summary>
/// <returns>provider version</returns>
public override string Version
{
get { return "0.1"; }
}
public Hashtable GetUserAttachments(UUID agentID)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param["?uuid"] = agentID.ToString();
try
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (IDbCommand result = m_database.Query(dbcon,
"SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param))
{
using (IDataReader reader = result.ExecuteReader())
{
Hashtable ret = m_database.readAttachments(reader);
return ret;
}
}
}
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return null;
}
}
public void UpdateUserAttachments(UUID agentID, Hashtable data)
{
m_database.writeAttachments(agentID, data);
}
public override void ResetAttachments(UUID userID)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["?uuid"] = userID.ToString();
m_database.ExecuteParameterizedSql(
"UPDATE " + m_attachmentsTableName +
" SET asset = '00000000-0000-0000-0000-000000000000' WHERE UUID = ?uuid",
param);
}
public override void LogoutUsers(UUID regionID)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["?regionID"] = regionID.ToString();
try
{
m_database.ExecuteParameterizedSql(
"update " + m_agentsTableName + " SET agentOnline = 0 " +
"where currentRegion = ?regionID",
param);
}
catch (Exception e)
{
m_log.Error(e.Message, e);
return;
}
}
}
}

View File

@ -31,6 +31,7 @@ using OpenSim.Data.Tests;
using log4net; using log4net;
using System.Reflection; using System.Reflection;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL.Tests namespace OpenSim.Data.MySQL.Tests
{ {
@ -39,7 +40,7 @@ namespace OpenSim.Data.MySQL.Tests
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file; public string file;
public MySQLManager database; private string m_connectionString;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp] [TestFixtureSetUp]
@ -52,7 +53,6 @@ namespace OpenSim.Data.MySQL.Tests
// tests. // tests.
try try
{ {
database = new MySQLManager(connect);
db = new MySQLAssetData(); db = new MySQLAssetData();
db.Initialise(connect); db.Initialise(connect);
} }
@ -70,10 +70,22 @@ namespace OpenSim.Data.MySQL.Tests
{ {
db.Dispose(); db.Dispose();
} }
if (database != null) ExecuteSql("drop table migrations");
ExecuteSql("drop table assets");
}
/// <summary>
/// Execute a MySqlCommand
/// </summary>
/// <param name="sql">sql string to execute</param>
private void ExecuteSql(string sql)
{
using (MySqlConnection dbcon = new MySqlConnection(connect))
{ {
database.ExecuteSql("drop table migrations"); dbcon.Open();
database.ExecuteSql("drop table assets");
MySqlCommand cmd = new MySqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
} }
} }
} }

View File

@ -31,6 +31,8 @@ using OpenSim.Data.Tests;
using log4net; using log4net;
using System.Reflection; using System.Reflection;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL.Tests namespace OpenSim.Data.MySQL.Tests
{ {
@ -39,7 +41,6 @@ namespace OpenSim.Data.MySQL.Tests
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file; public string file;
public MySQLManager database;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp] [TestFixtureSetUp]
@ -52,9 +53,8 @@ namespace OpenSim.Data.MySQL.Tests
// tests. // tests.
try try
{ {
database = new MySQLManager(connect);
// clear db incase to ensure we are in a clean state // clear db incase to ensure we are in a clean state
ClearDB(database); ClearDB();
regionDb = new MySQLDataStore(); regionDb = new MySQLDataStore();
regionDb.Initialise(connect); regionDb.Initialise(connect);
@ -75,29 +75,41 @@ namespace OpenSim.Data.MySQL.Tests
{ {
regionDb.Dispose(); regionDb.Dispose();
} }
ClearDB(database); ClearDB();
} }
private void ClearDB(MySQLManager manager) private void ClearDB()
{ {
// if a new table is added, it has to be dropped here // if a new table is added, it has to be dropped here
if (manager != null) ExecuteSql("drop table if exists migrations");
ExecuteSql("drop table if exists prims");
ExecuteSql("drop table if exists primshapes");
ExecuteSql("drop table if exists primitems");
ExecuteSql("drop table if exists terrain");
ExecuteSql("drop table if exists land");
ExecuteSql("drop table if exists landaccesslist");
ExecuteSql("drop table if exists regionban");
ExecuteSql("drop table if exists regionsettings");
ExecuteSql("drop table if exists estate_managers");
ExecuteSql("drop table if exists estate_groups");
ExecuteSql("drop table if exists estate_users");
ExecuteSql("drop table if exists estateban");
ExecuteSql("drop table if exists estate_settings");
ExecuteSql("drop table if exists estate_map");
}
/// <summary>
/// Execute a MySqlCommand
/// </summary>
/// <param name="sql">sql string to execute</param>
private void ExecuteSql(string sql)
{
using (MySqlConnection dbcon = new MySqlConnection(connect))
{ {
manager.ExecuteSql("drop table if exists migrations"); dbcon.Open();
manager.ExecuteSql("drop table if exists prims");
manager.ExecuteSql("drop table if exists primshapes"); MySqlCommand cmd = new MySqlCommand(sql, dbcon);
manager.ExecuteSql("drop table if exists primitems"); cmd.ExecuteNonQuery();
manager.ExecuteSql("drop table if exists terrain");
manager.ExecuteSql("drop table if exists land");
manager.ExecuteSql("drop table if exists landaccesslist");
manager.ExecuteSql("drop table if exists regionban");
manager.ExecuteSql("drop table if exists regionsettings");
manager.ExecuteSql("drop table if exists estate_managers");
manager.ExecuteSql("drop table if exists estate_groups");
manager.ExecuteSql("drop table if exists estate_users");
manager.ExecuteSql("drop table if exists estateban");
manager.ExecuteSql("drop table if exists estate_settings");
manager.ExecuteSql("drop table if exists estate_map");
} }
} }
} }

View File

@ -1,94 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using NUnit.Framework;
using OpenSim.Data.Tests;
using log4net;
using System.Reflection;
using OpenSim.Tests.Common;
using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL.Tests
{
[TestFixture, DatabaseTest]
public class MySQLGridTest : BasicGridTest
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file;
public MySQLManager database;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp]
public void Init()
{
SuperInit();
// If we manage to connect to the database with the user
// and password above it is our test database, and run
// these tests. If anything goes wrong, ignore these
// tests.
try
{
database = new MySQLManager(connect);
db = new MySQLGridData();
db.Initialise(connect);
}
catch (Exception e)
{
m_log.Error("Exception {0}", e);
Assert.Ignore();
}
// This actually does the roll forward assembly stuff
Assembly assem = GetType().Assembly;
using (MySqlConnection dbcon = new MySqlConnection(connect))
{
dbcon.Open();
Migration m = new Migration(dbcon, assem, "AssetStore");
m.Update();
}
}
[TestFixtureTearDown]
public void Cleanup()
{
m_log.Warn("Cleaning up.");
if (db != null)
{
db.Dispose();
}
// if a new table is added, it has to be dropped here
if (database != null)
{
database.ExecuteSql("drop table migrations");
database.ExecuteSql("drop table regions");
}
}
}
}

View File

@ -31,6 +31,8 @@ using OpenSim.Data.Tests;
using log4net; using log4net;
using System.Reflection; using System.Reflection;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL.Tests namespace OpenSim.Data.MySQL.Tests
{ {
@ -39,7 +41,6 @@ namespace OpenSim.Data.MySQL.Tests
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file; public string file;
public MySQLManager database;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp] [TestFixtureSetUp]
@ -52,7 +53,6 @@ namespace OpenSim.Data.MySQL.Tests
// tests. // tests.
try try
{ {
database = new MySQLManager(connect);
DropTables(); DropTables();
db = new MySQLInventoryData(); db = new MySQLInventoryData();
db.Initialise(connect); db.Initialise(connect);
@ -71,17 +71,29 @@ namespace OpenSim.Data.MySQL.Tests
{ {
db.Dispose(); db.Dispose();
} }
if (database != null) DropTables();
{
DropTables();
}
} }
private void DropTables() private void DropTables()
{ {
database.ExecuteSql("drop table IF EXISTS inventoryitems"); ExecuteSql("drop table IF EXISTS inventoryitems");
database.ExecuteSql("drop table IF EXISTS inventoryfolders"); ExecuteSql("drop table IF EXISTS inventoryfolders");
database.ExecuteSql("drop table IF EXISTS migrations"); ExecuteSql("drop table IF EXISTS migrations");
}
/// <summary>
/// Execute a MySqlCommand
/// </summary>
/// <param name="sql">sql string to execute</param>
private void ExecuteSql(string sql)
{
using (MySqlConnection dbcon = new MySqlConnection(connect))
{
dbcon.Open();
MySqlCommand cmd = new MySqlCommand(sql, dbcon);
cmd.ExecuteNonQuery();
}
} }
} }
} }

View File

@ -31,6 +31,7 @@ using OpenSim.Data.Tests;
using log4net; using log4net;
using System.Reflection; using System.Reflection;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
using MySql.Data.MySqlClient;
namespace OpenSim.Data.MySQL.Tests namespace OpenSim.Data.MySQL.Tests
{ {
@ -39,7 +40,6 @@ namespace OpenSim.Data.MySQL.Tests
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file; public string file;
public MySQLManager database;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp] [TestFixtureSetUp]
@ -52,9 +52,8 @@ namespace OpenSim.Data.MySQL.Tests
// tests. // tests.
try try
{ {
database = new MySQLManager(connect);
// this is important in case a previous run ended badly // this is important in case a previous run ended badly
ClearDB(database); ClearDB();
db = new MySQLDataStore(); db = new MySQLDataStore();
db.Initialise(connect); db.Initialise(connect);
@ -73,28 +72,40 @@ namespace OpenSim.Data.MySQL.Tests
{ {
db.Dispose(); db.Dispose();
} }
ClearDB(database); ClearDB();
} }
private void ClearDB(MySQLManager manager) private void ClearDB()
{ {
if (manager != null) ExecuteSql("drop table if exists migrations");
ExecuteSql("drop table if exists prims");
ExecuteSql("drop table if exists primshapes");
ExecuteSql("drop table if exists primitems");
ExecuteSql("drop table if exists terrain");
ExecuteSql("drop table if exists land");
ExecuteSql("drop table if exists landaccesslist");
ExecuteSql("drop table if exists regionban");
ExecuteSql("drop table if exists regionsettings");
ExecuteSql("drop table if exists estate_managers");
ExecuteSql("drop table if exists estate_groups");
ExecuteSql("drop table if exists estate_users");
ExecuteSql("drop table if exists estateban");
ExecuteSql("drop table if exists estate_settings");
ExecuteSql("drop table if exists estate_map");
}
/// <summary>
/// Execute a MySqlCommand
/// </summary>
/// <param name="sql">sql string to execute</param>
private void ExecuteSql(string sql)
{
using (MySqlConnection dbcon = new MySqlConnection(connect))
{ {
manager.ExecuteSql("drop table if exists migrations"); dbcon.Open();
manager.ExecuteSql("drop table if exists prims");
manager.ExecuteSql("drop table if exists primshapes"); MySqlCommand cmd = new MySqlCommand(sql, dbcon);
manager.ExecuteSql("drop table if exists primitems"); cmd.ExecuteNonQuery();
manager.ExecuteSql("drop table if exists terrain");
manager.ExecuteSql("drop table if exists land");
manager.ExecuteSql("drop table if exists landaccesslist");
manager.ExecuteSql("drop table if exists regionban");
manager.ExecuteSql("drop table if exists regionsettings");
manager.ExecuteSql("drop table if exists estate_managers");
manager.ExecuteSql("drop table if exists estate_groups");
manager.ExecuteSql("drop table if exists estate_users");
manager.ExecuteSql("drop table if exists estateban");
manager.ExecuteSql("drop table if exists estate_settings");
manager.ExecuteSql("drop table if exists estate_map");
} }
} }
} }

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using NUnit.Framework;
using OpenSim.Data.Tests;
using log4net;
using System.Reflection;
using OpenSim.Tests.Common;
namespace OpenSim.Data.MySQL.Tests
{
[TestFixture, DatabaseTest]
public class MySQLUserTest : BasicUserTest
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public string file;
public MySQLManager database;
public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
[TestFixtureSetUp]
public void Init()
{
SuperInit();
// If we manage to connect to the database with the user
// and password above it is our test database, and run
// these tests. If anything goes wrong, ignore these
// tests.
try
{
database = new MySQLManager(connect);
db = new MySQLUserData();
db.Initialise(connect);
}
catch (Exception e)
{
m_log.Error("Exception {0}", e);
Assert.Ignore();
}
}
[TestFixtureTearDown]
public void Cleanup()
{
if (db != null)
{
db.Dispose();
}
// if a new table is added, it has to be dropped here
if (database != null)
{
database.ExecuteSql("drop table migrations");
database.ExecuteSql("drop table users");
database.ExecuteSql("drop table userfriends");
database.ExecuteSql("drop table agents");
database.ExecuteSql("drop table avatarappearance");
database.ExecuteSql("drop table avatarattachments");
}
}
}
}

View File

@ -1,337 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data
{
/// <summary>
/// A class which contains information known to the grid server about a region
/// </summary>
[Serializable]
public class RegionProfileData
{
/// <summary>
/// The name of the region
/// </summary>
public string regionName = String.Empty;
/// <summary>
/// A 64-bit number combining map position into a (mostly) unique ID
/// </summary>
public ulong regionHandle;
/// <summary>
/// OGS/OpenSim Specific ID for a region
/// </summary>
public UUID UUID;
/// <summary>
/// Coordinates of the region
/// </summary>
public uint regionLocX;
public uint regionLocY;
public uint regionLocZ; // Reserved (round-robin, layers, etc)
/// <summary>
/// Authentication secrets
/// </summary>
/// <remarks>Not very secure, needs improvement.</remarks>
public string regionSendKey = String.Empty;
public string regionRecvKey = String.Empty;
public string regionSecret = String.Empty;
/// <summary>
/// Whether the region is online
/// </summary>
public bool regionOnline;
/// <summary>
/// Information about the server that the region is currently hosted on
/// </summary>
public string serverIP = String.Empty;
public uint serverPort;
public string serverURI = String.Empty;
public uint httpPort;
public uint remotingPort;
public string httpServerURI = String.Empty;
/// <summary>
/// Set of optional overrides. Can be used to create non-eulicidean spaces.
/// </summary>
public ulong regionNorthOverrideHandle;
public ulong regionSouthOverrideHandle;
public ulong regionEastOverrideHandle;
public ulong regionWestOverrideHandle;
/// <summary>
/// Optional: URI Location of the region database
/// </summary>
/// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks>
public string regionDataURI = String.Empty;
/// <summary>
/// Region Asset Details
/// </summary>
public string regionAssetURI = String.Empty;
public string regionAssetSendKey = String.Empty;
public string regionAssetRecvKey = String.Empty;
/// <summary>
/// Region Userserver Details
/// </summary>
public string regionUserURI = String.Empty;
public string regionUserSendKey = String.Empty;
public string regionUserRecvKey = String.Empty;
/// <summary>
/// Region Map Texture Asset
/// </summary>
public UUID regionMapTextureID = new UUID("00000000-0000-1111-9999-000000000006");
/// <summary>
/// this particular mod to the file provides support within the spec for RegionProfileData for the
/// owner_uuid for the region
/// </summary>
public UUID owner_uuid = UUID.Zero;
/// <summary>
/// OGS/OpenSim Specific original ID for a region after move/split
/// </summary>
public UUID originUUID;
/// <summary>
/// The Maturity rating of the region
/// </summary>
public uint maturity;
//Data Wrappers
public string RegionName
{
get { return regionName; }
set { regionName = value; }
}
public ulong RegionHandle
{
get { return regionHandle; }
set { regionHandle = value; }
}
public UUID Uuid
{
get { return UUID; }
set { UUID = value; }
}
public uint RegionLocX
{
get { return regionLocX; }
set { regionLocX = value; }
}
public uint RegionLocY
{
get { return regionLocY; }
set { regionLocY = value; }
}
public uint RegionLocZ
{
get { return regionLocZ; }
set { regionLocZ = value; }
}
public string RegionSendKey
{
get { return regionSendKey; }
set { regionSendKey = value; }
}
public string RegionRecvKey
{
get { return regionRecvKey; }
set { regionRecvKey = value; }
}
public string RegionSecret
{
get { return regionSecret; }
set { regionSecret = value; }
}
public bool RegionOnline
{
get { return regionOnline; }
set { regionOnline = value; }
}
public string ServerIP
{
get { return serverIP; }
set { serverIP = value; }
}
public uint ServerPort
{
get { return serverPort; }
set { serverPort = value; }
}
public string ServerURI
{
get { return serverURI; }
set { serverURI = value; }
}
public uint ServerHttpPort
{
get { return httpPort; }
set { httpPort = value; }
}
public uint ServerRemotingPort
{
get { return remotingPort; }
set { remotingPort = value; }
}
public ulong NorthOverrideHandle
{
get { return regionNorthOverrideHandle; }
set { regionNorthOverrideHandle = value; }
}
public ulong SouthOverrideHandle
{
get { return regionSouthOverrideHandle; }
set { regionSouthOverrideHandle = value; }
}
public ulong EastOverrideHandle
{
get { return regionEastOverrideHandle; }
set { regionEastOverrideHandle = value; }
}
public ulong WestOverrideHandle
{
get { return regionWestOverrideHandle; }
set { regionWestOverrideHandle = value; }
}
public string RegionDataURI
{
get { return regionDataURI; }
set { regionDataURI = value; }
}
public string RegionAssetURI
{
get { return regionAssetURI; }
set { regionAssetURI = value; }
}
public string RegionAssetSendKey
{
get { return regionAssetSendKey; }
set { regionAssetSendKey = value; }
}
public string RegionAssetRecvKey
{
get { return regionAssetRecvKey; }
set { regionAssetRecvKey = value; }
}
public string RegionUserURI
{
get { return regionUserURI; }
set { regionUserURI = value; }
}
public string RegionUserSendKey
{
get { return regionUserSendKey; }
set { regionUserSendKey = value; }
}
public string RegionUserRecvKey
{
get { return regionUserRecvKey; }
set { regionUserRecvKey = value; }
}
public UUID RegionMapTextureID
{
get { return regionMapTextureID; }
set { regionMapTextureID = value; }
}
public UUID Owner_uuid
{
get { return owner_uuid; }
set { owner_uuid = value; }
}
public UUID OriginUUID
{
get { return originUUID; }
set { originUUID = value; }
}
public uint Maturity
{
get { return maturity; }
set { maturity = value; }
}
public byte AccessLevel
{
get { return Util.ConvertMaturityToAccessLevel(maturity); }
}
public RegionInfo ToRegionInfo()
{
return RegionInfo.Create(UUID, regionName, regionLocX, regionLocY, serverIP, httpPort, serverPort, remotingPort, serverURI);
}
public static RegionProfileData FromRegionInfo(RegionInfo regionInfo)
{
if (regionInfo == null)
{
return null;
}
return Create(regionInfo.RegionID, regionInfo.RegionName, regionInfo.RegionLocX,
regionInfo.RegionLocY, regionInfo.ExternalHostName,
(uint) regionInfo.ExternalEndPoint.Port, regionInfo.HttpPort, regionInfo.RemotingPort,
regionInfo.ServerURI, regionInfo.AccessLevel);
}
public static RegionProfileData Create(UUID regionID, string regionName, uint locX, uint locY, string externalHostName, uint regionPort, uint httpPort, uint remotingPort, string serverUri, byte access)
{
RegionProfileData regionProfile;
regionProfile = new RegionProfileData();
regionProfile.regionLocX = locX;
regionProfile.regionLocY = locY;
regionProfile.regionHandle =
Utils.UIntsToLong((regionProfile.regionLocX * Constants.RegionSize),
(regionProfile.regionLocY*Constants.RegionSize));
regionProfile.serverIP = externalHostName;
regionProfile.serverPort = regionPort;
regionProfile.httpPort = httpPort;
regionProfile.remotingPort = remotingPort;
regionProfile.serverURI = serverUri;
regionProfile.httpServerURI = "http://" + externalHostName + ":" + httpPort + "/";
regionProfile.UUID = regionID;
regionProfile.regionName = regionName;
regionProfile.maturity = access;
return regionProfile;
}
}
}

View File

@ -1,119 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data
{
public class RegionProfileServiceProxy : IRegionProfileRouter
{
/// <summary>
/// Request sim data based on arbitrary key/value
/// </summary>
private RegionProfileData RequestSimData(Uri gridserverUrl, string gridserverSendkey, string keyField, string keyValue)
{
Hashtable requestData = new Hashtable();
requestData[keyField] = keyValue;
requestData["authkey"] = gridserverSendkey;
ArrayList SendParams = new ArrayList();
SendParams.Add(requestData);
XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
XmlRpcResponse GridResp = GridReq.Send(gridserverUrl.ToString(), 3000);
Hashtable responseData = (Hashtable) GridResp.Value;
RegionProfileData simData = null;
if (!responseData.ContainsKey("error"))
{
uint locX = Convert.ToUInt32((string)responseData["region_locx"]);
uint locY = Convert.ToUInt32((string)responseData["region_locy"]);
string externalHostName = (string)responseData["sim_ip"];
uint simPort = Convert.ToUInt32((string)responseData["sim_port"]);
uint httpPort = Convert.ToUInt32((string)responseData["http_port"]);
uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
string serverUri = (string)responseData["server_uri"];
UUID regionID = new UUID((string)responseData["region_UUID"]);
string regionName = (string)responseData["region_name"];
byte access = Convert.ToByte((string)responseData["access"]);
simData = RegionProfileData.Create(regionID, regionName, locX, locY, externalHostName, simPort, httpPort, remotingPort, serverUri, access);
}
return simData;
}
/// <summary>
/// Request sim profile information from a grid server, by Region UUID
/// </summary>
/// <param name="regionId">The region UUID to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
/// <remarks>This method should be statics</remarks>
public RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey)
{
return RequestSimData(gridserverUrl, gridserverSendkey, "region_UUID", regionId.Guid.ToString());
}
/// <summary>
/// Request sim profile information from a grid server, by Region Handle
/// </summary>
/// <param name="regionHandle">the region handle to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
public RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey)
{
return RequestSimData(gridserverUrl, gridserverSendkey, "region_handle", regionHandle.ToString());
}
/// <summary>
/// Request sim profile information from a grid server, by Region Name
/// </summary>
/// <param name="regionName">the region name to look for</param>
/// <param name="gridserverUrl"></param>
/// <param name="gridserverSendkey"></param>
/// <param name="gridserverRecvkey"></param>
/// <returns>The sim profile. Null if there was a request failure</returns>
public RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl,
string gridserverSendkey, string gridserverRecvkey)
{
return RequestSimData(gridserverUrl, gridserverSendkey, "region_name_search", regionName);
}
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using OpenMetaverse;
namespace OpenSim.Data
{
public class ReservationData
{
public UUID userUUID = UUID.Zero;
public int reservationMinX = 0;
public int reservationMinY = 0;
public int reservationMaxX = 65536;
public int reservationMaxY = 65536;
public string reservationName = String.Empty;
public string reservationCompany = String.Empty;
public bool status = true;
public string gridSendKey = String.Empty;
public string gridRecvKey = String.Empty;
}
}

View File

@ -1,286 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data.SQLite
{
/// <summary>
/// A Grid Interface to the SQLite database
/// </summary>
public class SQLiteGridData : GridDataBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// SQLite database manager
/// </summary>
private SQLiteManager database;
override public void Initialise()
{
m_log.Info("[SQLite]: " + Name + " cannot be default-initialized!");
throw new PluginNotInitialisedException (Name);
}
/// <summary>
/// <list type="bullet">
/// <item>Initialises Inventory interface</item>
/// <item>Loads and initialises a new SQLite connection and maintains it.</item>
/// <item>use default URI if connect string is empty.</item>
/// </list>
/// </summary>
/// <param name="dbconnect">connect string</param>
override public void Initialise(string connect)
{
database = new SQLiteManager(connect);
}
/// <summary>
/// Shuts down the grid interface
/// </summary>
override public void Dispose()
{
database.Close();
}
/// <summary>
/// Returns the name of this grid interface
/// </summary>
/// <returns>A string containing the grid interface</returns>
override public string Name
{
get { return "SQLite OpenGridData"; }
}
/// <summary>
/// Returns the version of this grid interface
/// </summary>
/// <returns>A string containing the version</returns>
override public string Version
{
get { return "0.1"; }
}
/// <summary>
/// Returns a list of regions within the specified ranges
/// </summary>
/// <param name="a">minimum X coordinate</param>
/// <param name="b">minimum Y coordinate</param>
/// <param name="c">maximum X coordinate</param>
/// <param name="d">maximum Y coordinate</param>
/// <returns>An array of region profiles</returns>
/// <remarks>NOT IMPLEMENTED ? always return null</remarks>
override public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d)
{
return null;
}
/// <summary>
/// Returns up to maxNum profiles of regions that have a name starting with namePrefix
/// </summary>
/// <param name="name">The name to match against</param>
/// <param name="maxNum">Maximum number of profiles to return</param>
/// <returns>A list of sim profiles</returns>
override public List<RegionProfileData> GetRegionsByName (string namePrefix, uint maxNum)
{
return null;
}
/// <summary>
/// Returns a sim profile from it's handle
/// </summary>
/// <param name="handle">Region location handle</param>
/// <returns>Sim profile</returns>
override public RegionProfileData GetProfileByHandle(ulong handle)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["handle"] = handle.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param);
IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRow(reader);
reader.Close();
result.Dispose();
return row;
}
/// <summary>
/// Returns a sim profile from it's Region name string
/// </summary>
/// <param name="regionName">The region name search query</param>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByString(string regionName)
{
if (regionName.Length > 2)
{
Dictionary<string, string> param = new Dictionary<string, string>();
// Add % because this is a like query.
param["?regionName"] = regionName + "%";
// Only returns one record or no record.
IDbCommand result = database.Query("SELECT * FROM regions WHERE regionName like ?regionName LIMIT 1", param);
IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRow(reader);
reader.Close();
result.Dispose();
return row;
}
else
{
//m_log.Error("[DATABASE]: Searched for a Region Name shorter then 3 characters");
return null;
}
}
/// <summary>
/// Returns a sim profile from it's UUID
/// </summary>
/// <param name="uuid">The region UUID</param>
/// <returns>The sim profile</returns>
override public RegionProfileData GetProfileByUUID(UUID uuid)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid.ToString();
IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param);
IDataReader reader = result.ExecuteReader();
RegionProfileData row = database.getRow(reader);
reader.Close();
result.Dispose();
return row;
}
/// <summary>
/// Returns a list of avatar and UUIDs that match the query
/// </summary>
/// <remarks>do nothing yet</remarks>
public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query)
{
//Do nothing yet
List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
return returnlist;
}
/// <summary>
/// Adds a new specified region to the database
/// </summary>
/// <param name="profile">The profile to add</param>
/// <returns>A dataresponse enum indicating success</returns>
override public DataResponse StoreProfile(RegionProfileData profile)
{
if (database.insertRow(profile))
{
return DataResponse.RESPONSE_OK;
}
else
{
return DataResponse.RESPONSE_ERROR;
}
}
/// <summary>
/// Deletes a sim profile from the database
/// </summary>
/// <param name="uuid">the sim UUID</param>
/// <returns>Successful?</returns>
override public DataResponse DeleteProfile(string uuid)
{
Dictionary<string, string> param = new Dictionary<string, string>();
param["uuid"] = uuid;
IDbCommand result = database.Query("DELETE FROM regions WHERE uuid = @uuid", param);
if (result.ExecuteNonQuery() > 0)
{
return DataResponse.RESPONSE_OK;
}
return DataResponse.RESPONSE_ERROR;
}
/// <summary>
/// DEPRECATED. Attempts to authenticate a region by comparing a shared secret.
/// </summary>
/// <param name="uuid">The UUID of the challenger</param>
/// <param name="handle">The attempted regionHandle of the challenger</param>
/// <param name="authkey">The secret</param>
/// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey)
{
bool throwHissyFit = false; // Should be true by 1.0
if (throwHissyFit)
throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
RegionProfileData data = GetProfileByUUID(uuid);
return (handle == data.regionHandle && authkey == data.regionSecret);
}
/// <summary>
/// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
/// </summary>
/// <remarks>This requires a security audit.</remarks>
/// <param name="uuid"></param>
/// <param name="handle"></param>
/// <param name="authhash"></param>
/// <param name="challenge"></param>
/// <returns></returns>
public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge)
{
// SHA512Managed HashProvider = new SHA512Managed();
// Encoding TextProvider = new UTF8Encoding();
// byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge);
// byte[] hash = HashProvider.ComputeHash(stream);
return false;
}
/// <summary>
/// NOT IMPLEMENTED
/// </summary>
/// <param name="x">x coordinate</param>
/// <param name="y">y coordinate</param>
/// <returns>always return null</returns>
override public ReservationData GetReservationAtPoint(uint x, uint y)
{
return null;
}
}
}

View File

@ -1,225 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Reflection;
using log4net;
using OpenMetaverse;
namespace OpenSim.Data.SQLite
{
/// <summary>
/// SQLite Manager
/// </summary>
internal class SQLiteManager : SQLiteUtil
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private IDbConnection dbcon;
/// <summary>
/// <list type="bullet">
/// <item>Initialises and creates a new SQLite connection and maintains it.</item>
/// <item>use default URI if connect string is empty.</item>
/// </list>
/// </summary>
/// <param name="connect">connect string</param>
public SQLiteManager(string connect)
{
try
{
string connectionString = String.Empty;
if (connect != String.Empty)
{
connectionString = connect;
}
else
{
m_log.Warn("[SQLITE] grid db not specified, using default");
connectionString = "URI=file:GridServerSqlite.db;";
}
dbcon = new SQLiteConnection(connectionString);
dbcon.Open();
}
catch (Exception e)
{
throw new Exception("Error initialising SQLite Database: " + e.ToString());
}
}
/// <summary>
/// Shuts down the database connection
/// </summary>
public void Close()
{
dbcon.Close();
dbcon = null;
}
/// <summary>
/// Runs a query with protection against SQL Injection by using parameterised input.
/// </summary>
/// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
/// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
/// <returns>A SQLite DB Command</returns>
public IDbCommand Query(string sql, Dictionary<string, string> parameters)
{
SQLiteCommand dbcommand = (SQLiteCommand) dbcon.CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair<string, string> param in parameters)
{
SQLiteParameter paramx = new SQLiteParameter(param.Key, param.Value);
dbcommand.Parameters.Add(paramx);
}
return (IDbCommand) dbcommand;
}
/// <summary>
/// Reads a region row from a database reader
/// </summary>
/// <param name="reader">An active database reader</param>
/// <returns>A region profile</returns>
public RegionProfileData getRow(IDataReader reader)
{
RegionProfileData retval = new RegionProfileData();
if (reader.Read())
{
// Region Main
retval.regionHandle = (ulong) reader["regionHandle"];
retval.regionName = (string) reader["regionName"];
retval.UUID = new UUID((string) reader["uuid"]);
// Secrets
retval.regionRecvKey = (string) reader["regionRecvKey"];
retval.regionSecret = (string) reader["regionSecret"];
retval.regionSendKey = (string) reader["regionSendKey"];
// Region Server
retval.regionDataURI = (string) reader["regionDataURI"];
retval.regionOnline = false; // Needs to be pinged before this can be set.
retval.serverIP = (string) reader["serverIP"];
retval.serverPort = (uint) reader["serverPort"];
retval.serverURI = (string) reader["serverURI"];
// Location
retval.regionLocX = (uint) ((int) reader["locX"]);
retval.regionLocY = (uint) ((int) reader["locY"]);
retval.regionLocZ = (uint) ((int) reader["locZ"]);
// Neighbours - 0 = No Override
retval.regionEastOverrideHandle = (ulong) reader["eastOverrideHandle"];
retval.regionWestOverrideHandle = (ulong) reader["westOverrideHandle"];
retval.regionSouthOverrideHandle = (ulong) reader["southOverrideHandle"];
retval.regionNorthOverrideHandle = (ulong) reader["northOverrideHandle"];
// Assets
retval.regionAssetURI = (string) reader["regionAssetURI"];
retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"];
retval.regionAssetSendKey = (string) reader["regionAssetSendKey"];
// Userserver
retval.regionUserURI = (string) reader["regionUserURI"];
retval.regionUserRecvKey = (string) reader["regionUserRecvKey"];
retval.regionUserSendKey = (string) reader["regionUserSendKey"];
}
else
{
throw new Exception("No rows to return");
}
return retval;
}
/// <summary>
/// Inserts a new region into the database
/// </summary>
/// <param name="profile">The region to insert</param>
/// <returns>Success?</returns>
public bool insertRow(RegionProfileData profile)
{
string sql =
"REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
sql +=
"serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES ";
sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
sql +=
"@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);";
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["regionHandle"] = profile.regionHandle.ToString();
parameters["regionName"] = profile.regionName;
parameters["uuid"] = profile.UUID.ToString();
parameters["regionRecvKey"] = profile.regionRecvKey;
parameters["regionSendKey"] = profile.regionSendKey;
parameters["regionDataURI"] = profile.regionDataURI;
parameters["serverIP"] = profile.serverIP;
parameters["serverPort"] = profile.serverPort.ToString();
parameters["serverURI"] = profile.serverURI;
parameters["locX"] = profile.regionLocX.ToString();
parameters["locY"] = profile.regionLocY.ToString();
parameters["locZ"] = profile.regionLocZ.ToString();
parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString();
parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString();
parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString();
parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString();
parameters["regionAssetURI"] = profile.regionAssetURI;
parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey;
parameters["regionAssetSendKey"] = profile.regionAssetSendKey;
parameters["regionUserURI"] = profile.regionUserURI;
parameters["regionUserRecvKey"] = profile.regionUserRecvKey;
parameters["regionUserSendKey"] = profile.regionUserSendKey;
bool returnval = false;
try
{
IDbCommand result = Query(sql, parameters);
if (result.ExecuteNonQuery() == 1)
returnval = true;
result.Dispose();
}
catch (Exception)
{
return false;
}
return returnval;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,64 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.IO;
using NUnit.Framework;
using OpenSim.Data.Tests;
using OpenSim.Tests.Common;
namespace OpenSim.Data.SQLite.Tests
{
[TestFixture, DatabaseTest]
public class SQLiteUserTest : BasicUserTest
{
public string file;
public string connect;
[TestFixtureSetUp]
public void Init()
{
// SQLite doesn't work on power or z linux
if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
{
Assert.Ignore();
}
SuperInit();
file = Path.GetTempFileName() + ".db";
connect = "URI=file:" + file + ",version=3";
db = new SQLiteUserData();
db.Initialise(connect);
}
[TestFixtureTearDown]
public void Cleanup()
{
db.Dispose();
File.Delete(file);
}
}
}

View File

@ -1,173 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse;
namespace OpenSim.Data.Tests
{
public class BasicGridTest
{
public IGridDataPlugin db;
public UUID region1, region2, region3;
public UUID zero = UUID.Zero;
public static Random random = new Random();
[TearDown]
public void removeAllRegions()
{
// Clean up all the regions.
List<RegionProfileData> regions = db.GetRegionsByName("", 100);
if (regions != null)
{
foreach (RegionProfileData region in regions)
{
db.DeleteProfile(region.Uuid.ToString());
}
}
}
public void SuperInit()
{
OpenSim.Tests.Common.TestLogging.LogToConsole();
region1 = UUID.Random();
region2 = UUID.Random();
region3 = UUID.Random();
}
protected RegionProfileData createRegion(UUID regionUUID, string regionName)
{
RegionProfileData reg = new RegionProfileData();
new PropertyScrambler<RegionProfileData>().Scramble(reg);
reg.Uuid = regionUUID;
reg.RegionName = regionName;
db.StoreProfile(reg);
return reg;
}
[Test]
public void T001_LoadEmpty()
{
Assert.That(db.GetProfileByUUID(region1),Is.Null);
Assert.That(db.GetProfileByUUID(region2),Is.Null);
Assert.That(db.GetProfileByUUID(region3),Is.Null);
Assert.That(db.GetProfileByUUID(zero),Is.Null);
}
[Test]
public void T011_AddRetrieveCompleteTest()
{
RegionProfileData newreg = createRegion(region2, "|<Goth@m Ci1y>|");
RegionProfileData retreg = db.GetProfileByUUID(region2);
Assert.That(retreg, Constraints.PropertyCompareConstraint(newreg).IgnoreProperty(x => x.RegionOnline));
retreg = db.GetProfileByHandle(newreg.RegionHandle);
Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
retreg = db.GetProfileByString(newreg.RegionName);
Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
RegionProfileData[] retregs = db.GetProfilesInRange(newreg.RegionLocX,newreg.RegionLocY,newreg.RegionLocX,newreg.RegionLocY);
Assert.That(retregs[0].Uuid, Is.EqualTo(region2), "Assert.That(retregs[0].Uuid, Is.EqualTo(region2))");
}
[Test]
public void T012_DeleteProfile()
{
createRegion(region1, "doesn't matter");
db.DeleteProfile(region1.ToString());
RegionProfileData retreg = db.GetProfileByUUID(region1);
Assert.That(retreg,Is.Null);
}
[Test]
public void T013_UpdateProfile()
{
createRegion(region2, "|<Goth@m Ci1y>|");
RegionProfileData retreg = db.GetProfileByUUID(region2);
retreg.regionName = "Gotham City";
db.StoreProfile(retreg);
retreg = db.GetProfileByUUID(region2);
Assert.That(retreg.RegionName, Is.EqualTo("Gotham City"), "Assert.That(retreg.RegionName, Is.EqualTo(\"Gotham City\"))");
}
[Test]
public void T014_RegionList()
{
createRegion(region2, "Gotham City");
RegionProfileData retreg = db.GetProfileByUUID(region2);
retreg.RegionName = "Gotham Town";
retreg.Uuid = region1;
db.StoreProfile(retreg);
retreg = db.GetProfileByUUID(region2);
retreg.RegionName = "Gothan Town";
retreg.Uuid = region3;
db.StoreProfile(retreg);
List<RegionProfileData> listreg = db.GetRegionsByName("Gotham",10);
Assert.That(listreg.Count,Is.EqualTo(2), "Assert.That(listreg.Count,Is.EqualTo(2))");
Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid), "Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid))");
Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))");
Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))");
}
[Test]
public void T999_StillNull()
{
Assert.That(db.GetProfileByUUID(zero), Is.Null);
}
protected static string RandomName()
{
StringBuilder name = new StringBuilder();
int size = random.Next(5,12);
char ch ;
for (int i=0; i<size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
name.Append(ch);
}
return name.ToString();
}
}
}

View File

@ -1,703 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// TODO: Money Transfer, Inventory Transfer and UpdateUserRegion once they exist
using System;
using System.Collections.Generic;
using System.Text;
using log4net.Config;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse;
using OpenSim.Framework;
using log4net;
using System.Reflection;
namespace OpenSim.Data.Tests
{
public class BasicUserTest
{
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public IUserDataPlugin db;
public UUID user1;
public UUID user2;
public UUID user3;
public UUID user4;
public UUID user5;
public UUID webkey;
public UUID zero = UUID.Zero;
public static Random random;
public UUID agent1;
public UUID agent2;
public UUID agent3;
public UUID agent4;
public UUID region1;
public string fname0;
public string lname0;
public string fname1;
public string lname1;
public string fname2;
public string lname2;
public string fname3;
public string lname3;
public void SuperInit()
{
OpenSim.Tests.Common.TestLogging.LogToConsole();
random = new Random();
user1 = UUID.Random();
user2 = UUID.Random();
user3 = UUID.Random();
user4 = UUID.Random();
user5 = UUID.Random();
agent1 = UUID.Random();
agent2 = UUID.Random();
agent3 = UUID.Random();
agent4 = UUID.Random();
webkey = UUID.Random();
region1 = UUID.Random();
fname0 = RandomName();
lname0 = RandomName();
fname1 = RandomName();
lname1 = RandomName();
fname2 = RandomName();
lname2 = RandomName();
fname3 = RandomName();
lname3 = RandomName();
}
[Test]
public void T001_LoadEmpty()
{
Assert.That(db.GetUserByUUID(zero), Is.Null);
Assert.That(db.GetUserByUUID(user1), Is.Null);
Assert.That(db.GetUserByUUID(user2), Is.Null);
Assert.That(db.GetUserByUUID(user3), Is.Null);
Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null);
Assert.That(db.GetAgentByUUID(zero), Is.Null);
Assert.That(db.GetAgentByUUID(agent1), Is.Null);
Assert.That(db.GetAgentByUUID(agent2), Is.Null);
Assert.That(db.GetAgentByUUID(agent3), Is.Null);
Assert.That(db.GetAgentByUUID(UUID.Random()), Is.Null);
}
[Test]
public void T010_CreateUser()
{
UserProfileData u1 = NewUser(user1,fname1,lname1);
UserProfileData u2 = NewUser(user2,fname2,lname2);
UserProfileData u3 = NewUser(user3,fname3,lname3);
// this is used to check whether null works here
u3.Email = null;
db.AddNewUserProfile(u1);
db.AddNewUserProfile(u2);
db.AddNewUserProfile(u3);
UserProfileData u1a = db.GetUserByUUID(user1);
UserProfileData u2a = db.GetUserByUUID(user2);
UserProfileData u3a = db.GetUserByUUID(user3);
Assert.That(user1,Is.EqualTo(u1a.ID), "Assert.That(user1,Is.EqualTo(u1a.ID))");
Assert.That(user2,Is.EqualTo(u2a.ID), "Assert.That(user2,Is.EqualTo(u2a.ID))");
Assert.That(user3,Is.EqualTo(u3a.ID), "Assert.That(user3,Is.EqualTo(u3a.ID))");
// and one email test
Assert.That(u3.Email, Is.Null);
}
[Test]
public void T011_FetchUserByName()
{
UserProfileData u1 = db.GetUserByName(fname1,lname1);
UserProfileData u2 = db.GetUserByName(fname2,lname2);
UserProfileData u3 = db.GetUserByName(fname3,lname3);
Assert.That(user1,Is.EqualTo(u1.ID), "Assert.That(user1,Is.EqualTo(u1.ID))");
Assert.That(user2,Is.EqualTo(u2.ID), "Assert.That(user2,Is.EqualTo(u2.ID))");
Assert.That(user3,Is.EqualTo(u3.ID), "Assert.That(user3,Is.EqualTo(u3.ID))");
}
[Test]
public void T012_UpdateUserProfile()
{
UserProfileData u1 = db.GetUserByUUID(user1);
Assert.That(fname1,Is.EqualTo(u1.FirstName), "Assert.That(fname1,Is.EqualTo(u1.FirstName))");
u1.FirstName = "Ugly";
db.UpdateUserProfile(u1);
Assert.That("Ugly",Is.EqualTo(u1.FirstName), "Assert.That(\"Ugly\",Is.EqualTo(u1.FirstName))");
}
[Test]
public void T013_StoreUserWebKey()
{
UserProfileData u1 = db.GetUserByUUID(user1);
Assert.That(u1.WebLoginKey,Is.EqualTo(zero), "Assert.That(u1.WebLoginKey,Is.EqualTo(zero))");
db.StoreWebLoginKey(user1, webkey);
u1 = db.GetUserByUUID(user1);
Assert.That(u1.WebLoginKey,Is.EqualTo(webkey), "Assert.That(u1.WebLoginKey,Is.EqualTo(webkey))");
}
[Test]
public void T014_ExpectedNullReferenceReturns()
{
UserProfileData u0 = NewUser(zero,fname0,lname0);
UserProfileData u4 = NewUser(user4,fname2,lname2);
db.AddNewUserProfile(u0); //UserID 0 should fail to save.
db.AddNewUserProfile(u4); //The first name and last name are already in use (from T010), so this should fail too
Assert.That(db.GetUserByUUID(zero),Is.Null);
Assert.That(db.GetUserByUUID(user4),Is.Null);
}
[Test]
public void T015_UserPersistency()
{
UserProfileData u = new UserProfileData();
UUID id = user5;
string fname = RandomName();
string lname = RandomName();
string email = RandomName();
string passhash = RandomName();
string passsalt = RandomName();
UUID homeregion = UUID.Random();
UUID webloginkey = UUID.Random();
uint homeregx = (uint) random.Next();
uint homeregy = (uint) random.Next();
Vector3 homeloc
= new Vector3(
(float)Math.Round(random.NextDouble(), 5),
(float)Math.Round(random.NextDouble(), 5),
(float)Math.Round(random.NextDouble(), 5));
Vector3 homelookat
= new Vector3(
(float)Math.Round(random.NextDouble(), 5),
(float)Math.Round(random.NextDouble(), 5),
(float)Math.Round(random.NextDouble(), 5));
int created = random.Next();
int lastlogin = random.Next();
string userinvuri = RandomName();
string userasseturi = RandomName();
uint candomask = (uint) random.Next();
uint wantdomask = (uint) random.Next();
string abouttext = RandomName();
string flabouttext = RandomName();
UUID image = UUID.Random();
UUID firstimage = UUID.Random();
UserAgentData agent = NewAgent(id,UUID.Random());
int userflags = random.Next();
int godlevel = random.Next();
string customtype = RandomName();
UUID partner = UUID.Random();
//HomeRegionX and HomeRegionY must only use 24 bits
homeregx = ((homeregx << 8) >> 8);
homeregy = ((homeregy << 8) >> 8);
u.ID = id;
u.WebLoginKey = webloginkey;
u.HomeRegionID = homeregion;
u.FirstName = fname;
u.SurName = lname;
u.Email = email;
u.PasswordHash = passhash;
u.PasswordSalt = passsalt;
u.HomeRegionX = homeregx;
u.HomeRegionY = homeregy;
ulong homereg = u.HomeRegion;
u.HomeLocation = homeloc;
u.HomeLookAt = homelookat;
u.Created = created;
u.LastLogin = lastlogin;
u.UserInventoryURI = userinvuri;
u.UserAssetURI = userasseturi;
u.CanDoMask = candomask;
u.WantDoMask = wantdomask;
u.AboutText = abouttext;
u.FirstLifeAboutText = flabouttext;
u.Image = image;
u.FirstLifeImage = firstimage;
u.CurrentAgent = agent;
u.UserFlags = userflags;
u.GodLevel = godlevel;
u.CustomType = customtype;
u.Partner = partner;
db.AddNewUserProfile(u);
UserProfileData u1a = db.GetUserByUUID(id);
Assert.That(u1a,Is.Not.Null);
Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))");
Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID))");
Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))");
Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))");
Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))");
Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))");
Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))");
Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))");
Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))");
Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))");
Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))");
Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))");
Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))");
Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))");
Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI), "Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI))");
Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
Assert.That(u1a.CurrentAgent,Is.Null);
Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
}
[Test]
public void T016_UserUpdatePersistency()
{
UUID id = user5;
UserProfileData u = db.GetUserByUUID(id);
string fname = RandomName();
string lname = RandomName();
string email = RandomName();
string passhash = RandomName();
string passsalt = RandomName();
UUID homeregionid = UUID.Random();
UUID webloginkey = UUID.Random();
uint homeregx = (uint) random.Next();
uint homeregy = (uint) random.Next();
Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
int created = random.Next();
int lastlogin = random.Next();
string userinvuri = RandomName();
string userasseturi = RandomName();
uint candomask = (uint) random.Next();
uint wantdomask = (uint) random.Next();
string abouttext = RandomName();
string flabouttext = RandomName();
UUID image = UUID.Random();
UUID firstimage = UUID.Random();
UserAgentData agent = NewAgent(id,UUID.Random());
int userflags = random.Next();
int godlevel = random.Next();
string customtype = RandomName();
UUID partner = UUID.Random();
//HomeRegionX and HomeRegionY must only use 24 bits
homeregx = ((homeregx << 8) >> 8);
homeregy = ((homeregy << 8) >> 8);
u.WebLoginKey = webloginkey;
u.HomeRegionID = homeregionid;
u.FirstName = fname;
u.SurName = lname;
u.Email = email;
u.PasswordHash = passhash;
u.PasswordSalt = passsalt;
u.HomeRegionX = homeregx;
u.HomeRegionY = homeregy;
ulong homereg = u.HomeRegion;
u.HomeLocation = homeloc;
u.HomeLookAt = homelookat;
u.Created = created;
u.LastLogin = lastlogin;
u.UserInventoryURI = userinvuri;
u.UserAssetURI = userasseturi;
u.CanDoMask = candomask;
u.WantDoMask = wantdomask;
u.AboutText = abouttext;
u.FirstLifeAboutText = flabouttext;
u.Image = image;
u.FirstLifeImage = firstimage;
u.CurrentAgent = agent;
u.UserFlags = userflags;
u.GodLevel = godlevel;
u.CustomType = customtype;
u.Partner = partner;
db.UpdateUserProfile(u);
UserProfileData u1a = db.GetUserByUUID(id);
Assert.That(u1a,Is.Not.Null);
Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))");
Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID))");
Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))");
Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))");
Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))");
Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))");
Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))");
Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))");
Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))");
Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))");
Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))");
Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))");
Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))");
Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))");
Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
Assert.That(u1a.CurrentAgent,Is.Null);
Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
}
[Test]
public void T017_UserUpdateRandomPersistency()
{
UUID id = user5;
UserProfileData u = db.GetUserByUUID(id);
new PropertyScrambler<UserProfileData>().DontScramble(x=>x.ID).Scramble(u);
db.UpdateUserProfile(u);
UserProfileData u1a = db.GetUserByUUID(id);
Assert.That(u1a, Constraints.PropertyCompareConstraint(u)
.IgnoreProperty(x=>x.HomeRegionX)
.IgnoreProperty(x=>x.HomeRegionY)
);
}
[Test]
public void T020_CreateAgent()
{
UserAgentData a1 = NewAgent(user1,agent1);
UserAgentData a2 = NewAgent(user2,agent2);
UserAgentData a3 = NewAgent(user3,agent3);
db.AddNewUserAgent(a1);
db.AddNewUserAgent(a2);
db.AddNewUserAgent(a3);
UserAgentData a1a = db.GetAgentByUUID(user1);
UserAgentData a2a = db.GetAgentByUUID(user2);
UserAgentData a3a = db.GetAgentByUUID(user3);
Assert.That(agent1,Is.EqualTo(a1a.SessionID), "Assert.That(agent1,Is.EqualTo(a1a.SessionID))");
Assert.That(user1,Is.EqualTo(a1a.ProfileID), "Assert.That(user1,Is.EqualTo(a1a.ProfileID))");
Assert.That(agent2,Is.EqualTo(a2a.SessionID), "Assert.That(agent2,Is.EqualTo(a2a.SessionID))");
Assert.That(user2,Is.EqualTo(a2a.ProfileID), "Assert.That(user2,Is.EqualTo(a2a.ProfileID))");
Assert.That(agent3,Is.EqualTo(a3a.SessionID), "Assert.That(agent3,Is.EqualTo(a3a.SessionID))");
Assert.That(user3,Is.EqualTo(a3a.ProfileID), "Assert.That(user3,Is.EqualTo(a3a.ProfileID))");
}
[Test]
public void T021_FetchAgentByName()
{
String name3 = fname3 + " " + lname3;
UserAgentData a2 = db.GetAgentByName(fname2,lname2);
UserAgentData a3 = db.GetAgentByName(name3);
Assert.That(user2,Is.EqualTo(a2.ProfileID), "Assert.That(user2,Is.EqualTo(a2.ProfileID))");
Assert.That(user3,Is.EqualTo(a3.ProfileID), "Assert.That(user3,Is.EqualTo(a3.ProfileID))");
}
[Test]
public void T022_ExceptionalCases()
{
UserAgentData a0 = NewAgent(user4,zero);
UserAgentData a4 = NewAgent(zero,agent4);
db.AddNewUserAgent(a0);
db.AddNewUserAgent(a4);
Assert.That(db.GetAgentByUUID(user4),Is.Null);
Assert.That(db.GetAgentByUUID(zero),Is.Null);
}
[Test]
public void T023_AgentPersistency()
{
UUID user = user4;
UUID agent = agent4;
UUID secureagent = UUID.Random();
string agentip = RandomName();
uint agentport = (uint)random.Next();
bool agentonline = (random.NextDouble() > 0.5);
int logintime = random.Next();
int logouttime = random.Next();
UUID regionid = UUID.Random();
ulong regionhandle = (ulong) random.Next();
Vector3 currentpos = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
Vector3 currentlookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
UUID orgregionid = UUID.Random();
UserAgentData a = new UserAgentData();
a.ProfileID = user;
a.SessionID = agent;
a.SecureSessionID = secureagent;
a.AgentIP = agentip;
a.AgentPort = agentport;
a.AgentOnline = agentonline;
a.LoginTime = logintime;
a.LogoutTime = logouttime;
a.Region = regionid;
a.Handle = regionhandle;
a.Position = currentpos;
a.LookAt = currentlookat;
a.InitialRegion = orgregionid;
db.AddNewUserAgent(a);
UserAgentData a1 = db.GetAgentByUUID(user4);
Assert.That(user,Is.EqualTo(a1.ProfileID), "Assert.That(user,Is.EqualTo(a1.ProfileID))");
Assert.That(agent,Is.EqualTo(a1.SessionID), "Assert.That(agent,Is.EqualTo(a1.SessionID))");
Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID), "Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID))");
Assert.That(agentip,Is.EqualTo(a1.AgentIP), "Assert.That(agentip,Is.EqualTo(a1.AgentIP))");
Assert.That(agentport,Is.EqualTo(a1.AgentPort), "Assert.That(agentport,Is.EqualTo(a1.AgentPort))");
Assert.That(agentonline,Is.EqualTo(a1.AgentOnline), "Assert.That(agentonline,Is.EqualTo(a1.AgentOnline))");
Assert.That(logintime,Is.EqualTo(a1.LoginTime), "Assert.That(logintime,Is.EqualTo(a1.LoginTime))");
Assert.That(logouttime,Is.EqualTo(a1.LogoutTime), "Assert.That(logouttime,Is.EqualTo(a1.LogoutTime))");
Assert.That(regionid,Is.EqualTo(a1.Region), "Assert.That(regionid,Is.EqualTo(a1.Region))");
Assert.That(regionhandle,Is.EqualTo(a1.Handle), "Assert.That(regionhandle,Is.EqualTo(a1.Handle))");
Assert.That(currentpos,Is.EqualTo(a1.Position), "Assert.That(currentpos,Is.EqualTo(a1.Position))");
Assert.That(currentlookat,Is.EqualTo(a1.LookAt), "Assert.That(currentlookat,Is.EqualTo(a1.LookAt))");
}
[Test]
public void T030_CreateFriendList()
{
Dictionary<UUID, uint> perms = new Dictionary<UUID,uint>();
Dictionary<UUID, int> friends = new Dictionary<UUID,int>();
uint temp;
int tempu1, tempu2;
db.AddNewUserFriend(user1,user2, 1);
db.AddNewUserFriend(user1,user3, 2);
db.AddNewUserFriend(user1,user2, 4);
List<FriendListItem> fl1 = db.GetUserFriendList(user1);
Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
perms.Add(user2,1);
perms.Add(user3,2);
for (int i = 0; i < fl1.Count; i++)
{
Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner), "Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner))");
friends.Add(fl1[i].Friend,1);
temp = perms[fl1[i].Friend];
Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms), "Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms))");
}
tempu1 = friends[user2];
tempu2 = friends[user3];
Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2), "Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2))");
}
[Test]
public void T031_RemoveUserFriend()
// user1 has 2 friends, user2 and user3.
{
List<FriendListItem> fl1 = db.GetUserFriendList(user1);
List<FriendListItem> fl2 = db.GetUserFriendList(user2);
Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3), "Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3))");
Assert.That(fl2[0].Friend,Is.EqualTo(user1), "Assert.That(fl2[0].Friend,Is.EqualTo(user1))");
db.RemoveUserFriend(user2, user1);
fl1 = db.GetUserFriendList(user1);
fl2 = db.GetUserFriendList(user2);
Assert.That(fl1.Count,Is.EqualTo(1), "Assert.That(fl1.Count,Is.EqualTo(1))");
Assert.That(fl1[0].Friend, Is.EqualTo(user3), "Assert.That(fl1[0].Friend, Is.EqualTo(user3))");
Assert.That(fl2, Is.Empty);
}
[Test]
public void T032_UpdateFriendPerms()
// user1 has 1 friend, user3, who has permission 2 in T030.
{
List<FriendListItem> fl1 = db.GetUserFriendList(user1);
Assert.That(fl1[0].FriendPerms,Is.EqualTo(2), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(2))");
db.UpdateUserFriendPerms(user1, user3, 4);
fl1 = db.GetUserFriendList(user1);
Assert.That(fl1[0].FriendPerms,Is.EqualTo(4), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(4))");
}
[Test]
public void T040_UserAppearance()
{
AvatarAppearance appear = new AvatarAppearance();
appear.Owner = user1;
db.UpdateUserAppearance(user1, appear);
AvatarAppearance user1app = db.GetUserAppearance(user1);
Assert.That(user1,Is.EqualTo(user1app.Owner), "Assert.That(user1,Is.EqualTo(user1app.Owner))");
}
[Test]
public void T041_UserAppearancePersistency()
{
AvatarAppearance appear = new AvatarAppearance();
UUID owner = UUID.Random();
int serial = random.Next();
byte[] visualp = new byte[218];
random.NextBytes(visualp);
UUID bodyitem = UUID.Random();
UUID bodyasset = UUID.Random();
UUID skinitem = UUID.Random();
UUID skinasset = UUID.Random();
UUID hairitem = UUID.Random();
UUID hairasset = UUID.Random();
UUID eyesitem = UUID.Random();
UUID eyesasset = UUID.Random();
UUID shirtitem = UUID.Random();
UUID shirtasset = UUID.Random();
UUID pantsitem = UUID.Random();
UUID pantsasset = UUID.Random();
UUID shoesitem = UUID.Random();
UUID shoesasset = UUID.Random();
UUID socksitem = UUID.Random();
UUID socksasset = UUID.Random();
UUID jacketitem = UUID.Random();
UUID jacketasset = UUID.Random();
UUID glovesitem = UUID.Random();
UUID glovesasset = UUID.Random();
UUID ushirtitem = UUID.Random();
UUID ushirtasset = UUID.Random();
UUID upantsitem = UUID.Random();
UUID upantsasset = UUID.Random();
UUID skirtitem = UUID.Random();
UUID skirtasset = UUID.Random();
Primitive.TextureEntry texture = AvatarAppearance.GetDefaultTexture();
float avatarheight = (float) (Math.Round(random.NextDouble(),5));
appear.Owner = owner;
appear.Serial = serial;
appear.VisualParams = visualp;
appear.BodyItem = bodyitem;
appear.BodyAsset = bodyasset;
appear.SkinItem = skinitem;
appear.SkinAsset = skinasset;
appear.HairItem = hairitem;
appear.HairAsset = hairasset;
appear.EyesItem = eyesitem;
appear.EyesAsset = eyesasset;
appear.ShirtItem = shirtitem;
appear.ShirtAsset = shirtasset;
appear.PantsItem = pantsitem;
appear.PantsAsset = pantsasset;
appear.ShoesItem = shoesitem;
appear.ShoesAsset = shoesasset;
appear.SocksItem = socksitem;
appear.SocksAsset = socksasset;
appear.JacketItem = jacketitem;
appear.JacketAsset = jacketasset;
appear.GlovesItem = glovesitem;
appear.GlovesAsset = glovesasset;
appear.UnderShirtItem = ushirtitem;
appear.UnderShirtAsset = ushirtasset;
appear.UnderPantsItem = upantsitem;
appear.UnderPantsAsset = upantsasset;
appear.SkirtItem = skirtitem;
appear.SkirtAsset = skirtasset;
appear.Texture = texture;
appear.AvatarHeight = avatarheight;
db.UpdateUserAppearance(owner, appear);
AvatarAppearance app = db.GetUserAppearance(owner);
Assert.That(owner,Is.EqualTo(app.Owner), "Assert.That(owner,Is.EqualTo(app.Owner))");
Assert.That(serial,Is.EqualTo(app.Serial), "Assert.That(serial,Is.EqualTo(app.Serial))");
Assert.That(visualp,Is.EqualTo(app.VisualParams), "Assert.That(visualp,Is.EqualTo(app.VisualParams))");
Assert.That(bodyitem,Is.EqualTo(app.BodyItem), "Assert.That(bodyitem,Is.EqualTo(app.BodyItem))");
Assert.That(bodyasset,Is.EqualTo(app.BodyAsset), "Assert.That(bodyasset,Is.EqualTo(app.BodyAsset))");
Assert.That(skinitem,Is.EqualTo(app.SkinItem), "Assert.That(skinitem,Is.EqualTo(app.SkinItem))");
Assert.That(skinasset,Is.EqualTo(app.SkinAsset), "Assert.That(skinasset,Is.EqualTo(app.SkinAsset))");
Assert.That(hairitem,Is.EqualTo(app.HairItem), "Assert.That(hairitem,Is.EqualTo(app.HairItem))");
Assert.That(hairasset,Is.EqualTo(app.HairAsset), "Assert.That(hairasset,Is.EqualTo(app.HairAsset))");
Assert.That(eyesitem,Is.EqualTo(app.EyesItem), "Assert.That(eyesitem,Is.EqualTo(app.EyesItem))");
Assert.That(eyesasset,Is.EqualTo(app.EyesAsset), "Assert.That(eyesasset,Is.EqualTo(app.EyesAsset))");
Assert.That(shirtitem,Is.EqualTo(app.ShirtItem), "Assert.That(shirtitem,Is.EqualTo(app.ShirtItem))");
Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset), "Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset))");
Assert.That(pantsitem,Is.EqualTo(app.PantsItem), "Assert.That(pantsitem,Is.EqualTo(app.PantsItem))");
Assert.That(pantsasset,Is.EqualTo(app.PantsAsset), "Assert.That(pantsasset,Is.EqualTo(app.PantsAsset))");
Assert.That(shoesitem,Is.EqualTo(app.ShoesItem), "Assert.That(shoesitem,Is.EqualTo(app.ShoesItem))");
Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset), "Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset))");
Assert.That(socksitem,Is.EqualTo(app.SocksItem), "Assert.That(socksitem,Is.EqualTo(app.SocksItem))");
Assert.That(socksasset,Is.EqualTo(app.SocksAsset), "Assert.That(socksasset,Is.EqualTo(app.SocksAsset))");
Assert.That(jacketitem,Is.EqualTo(app.JacketItem), "Assert.That(jacketitem,Is.EqualTo(app.JacketItem))");
Assert.That(jacketasset,Is.EqualTo(app.JacketAsset), "Assert.That(jacketasset,Is.EqualTo(app.JacketAsset))");
Assert.That(glovesitem,Is.EqualTo(app.GlovesItem), "Assert.That(glovesitem,Is.EqualTo(app.GlovesItem))");
Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset), "Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset))");
Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem), "Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem))");
Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset), "Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset))");
Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem), "Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem))");
Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset), "Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset))");
Assert.That(skirtitem,Is.EqualTo(app.SkirtItem), "Assert.That(skirtitem,Is.EqualTo(app.SkirtItem))");
Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset), "Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset))");
Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()), "Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()))");
Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))");
}
[Test]
public void T999_StillNull()
{
Assert.That(db.GetUserByUUID(zero), Is.Null);
Assert.That(db.GetAgentByUUID(zero), Is.Null);
}
public UserProfileData NewUser(UUID id,string fname,string lname)
{
UserProfileData u = new UserProfileData();
u.ID = id;
u.FirstName = fname;
u.SurName = lname;
u.PasswordHash = "NOTAHASH";
u.PasswordSalt = "NOTSALT";
// MUST specify at least these 5 parameters or an exception is raised
return u;
}
public UserAgentData NewAgent(UUID user_profile, UUID agent)
{
UserAgentData a = new UserAgentData();
a.ProfileID = user_profile;
a.SessionID = agent;
a.SecureSessionID = UUID.Random();
a.AgentIP = RandomName();
return a;
}
public static string RandomName()
{
StringBuilder name = new StringBuilder();
int size = random.Next(5,12);
char ch ;
for (int i=0; i<size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
name.Append(ch);
}
return name.ToString();
}
}
}

View File

@ -1,91 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
namespace OpenSim.Data
{
public abstract class UserDataBase : IUserDataPlugin
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// private Dictionary<UUID, AvatarAppearance> aplist = new Dictionary<UUID, AvatarAppearance>();
public abstract UserProfileData GetUserByUUID(UUID user);
public abstract UserProfileData GetUserByName(string fname, string lname);
public abstract UserAgentData GetAgentByUUID(UUID user);
public abstract UserAgentData GetAgentByName(string name);
public abstract UserAgentData GetAgentByName(string fname, string lname);
public UserProfileData GetUserByUri(Uri uri) { return null; }
public abstract void StoreWebLoginKey(UUID agentID, UUID webLoginKey);
public abstract void AddNewUserProfile(UserProfileData user);
public virtual void AddTemporaryUserProfile(UserProfileData userProfile)
{
// Deliberately blank - database plugins shouldn't store temporary profiles.
}
public abstract bool UpdateUserProfile(UserProfileData user);
public abstract void AddNewUserAgent(UserAgentData agent);
public abstract void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms);
public abstract void RemoveUserFriend(UUID friendlistowner, UUID friend);
public abstract void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms);
public abstract List<FriendListItem> GetUserFriendList(UUID friendlistowner);
public abstract Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids);
public abstract bool MoneyTransferRequest(UUID from, UUID to, uint amount);
public abstract bool InventoryTransferRequest(UUID from, UUID to, UUID inventory);
public abstract List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query);
public abstract AvatarAppearance GetUserAppearance(UUID user);
public abstract void UpdateUserAppearance(UUID user, AvatarAppearance appearance);
// public virtual AvatarAppearance GetUserAppearance(UUID user) {
// AvatarAppearance aa = null;
// try {
// aa = aplist[user];
// m_log.Info("[APPEARANCE] Found appearance for " + user.ToString() + aa.ToString());
// } catch (System.Collections.Generic.KeyNotFoundException e) {
// m_log.Info("[APPEARANCE] No appearance found for " + user.ToString());
// }
// return aa;
// }
// public virtual void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {
// aplist[user] = appearance;
// m_log.Info("[APPEARANCE] Setting appearance for " + user.ToString() + appearance.ToString());
// }
public abstract void ResetAttachments(UUID userID);
public abstract void LogoutUsers(UUID regionID);
public abstract string Version {get;}
public abstract string Name {get;}
public abstract void Initialise(string connect);
public abstract void Initialise();
public abstract void Dispose();
}
}

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
using OpenMetaverse;
using OpenSim.Data;
namespace OpenSim.Framework.Communications
{
/// <summary>
/// Plugin for managing temporary user profiles.
/// </summary>
public class TemporaryUserProfilePlugin : IUserDataPlugin
{
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected Dictionary<UUID, UserProfileData> m_profiles = new Dictionary<UUID, UserProfileData>();
public string Name { get { return "TemporaryUserProfilePlugin"; } }
public string Version { get { return "0.1"; } }
public void Initialise() {}
public void Initialise(string connect) {}
public void Dispose() {}
public UserProfileData GetUserByUUID(UUID user)
{
//m_log.DebugFormat("[TEMP USER PROFILE]: Received request for {0}", user);
lock (m_profiles)
{
if (m_profiles.ContainsKey(user))
return m_profiles[user];
else
return null;
}
}
public UserProfileData GetUserByName(string fname, string lname)
{
// We deliberately don't look up a temporary profile by name so that we don't obscure non-temporary
// profiles.
return null;
}
public virtual void AddTemporaryUserProfile(UserProfileData userProfile)
{
//m_log.DebugFormat("[TEMP USER PROFILE]: Adding {0} {1}", userProfile.Name, userProfile.ID);
lock (m_profiles)
{
m_profiles[userProfile.ID] = userProfile;
}
}
public UserProfileData GetUserByUri(Uri uri) { return null; }
public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; }
public UserAgentData GetAgentByUUID(UUID user) { return null; }
public UserAgentData GetAgentByName(string name) { return null; }
public UserAgentData GetAgentByName(string fname, string lname) { return null; }
public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {}
public void AddNewUserProfile(UserProfileData user) {}
public bool UpdateUserProfile(UserProfileData user) { return false; }
public void AddNewUserAgent(UserAgentData agent) {}
public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) {}
public void RemoveUserFriend(UUID friendlistowner, UUID friend) {}
public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) {}
public List<FriendListItem> GetUserFriendList(UUID friendlistowner) { return null; }
public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; }
public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; }
public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; }
public AvatarAppearance GetUserAppearance(UUID user) { return null; }
public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
public void ResetAttachments(UUID userID) {}
public void LogoutUsers(UUID regionID) {}
}
}

View File

@ -1,216 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Data;
namespace OpenSim.Tests.Common.Mock
{
/// <summary>
/// In memory user data provider. Might be quite useful as a proper user data plugin, though getting mono addins
/// to load any plugins when running unit tests has proven impossible so far. Currently no locking since unit
/// tests are single threaded.
/// </summary>
public class TestUserDataPlugin : IUserDataPlugin
{
public string Version { get { return "0"; } }
public string Name { get { return "TestUserDataPlugin"; } }
/// <summary>
/// User profiles keyed by name
/// </summary>
private Dictionary<string, UserProfileData> m_userProfilesByName = new Dictionary<string, UserProfileData>();
/// <summary>
/// User profiles keyed by uuid
/// </summary>
private Dictionary<UUID, UserProfileData> m_userProfilesByUuid = new Dictionary<UUID, UserProfileData>();
/// <summary>
/// User profiles and their agents
/// </summary>
private Dictionary<UUID, UserAgentData> m_agentByProfileUuid = new Dictionary<UUID, UserAgentData>();
/// <summary>
/// Friends list by uuid
/// </summary>
private Dictionary<UUID, List<FriendListItem>> m_friendsListByUuid = new Dictionary<UUID, List<FriendListItem>>();
public void Initialise() {}
public void Dispose() {}
public void AddTemporaryUserProfile(UserProfileData userProfile)
{
// Not interested
}
public void AddNewUserProfile(UserProfileData user)
{
UpdateUserProfile(user);
}
public UserProfileData GetUserByUUID(UUID user)
{
UserProfileData userProfile = null;
m_userProfilesByUuid.TryGetValue(user, out userProfile);
return userProfile;
}
public UserProfileData GetUserByName(string fname, string lname)
{
UserProfileData userProfile = null;
m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile);
return userProfile;
}
public UserProfileData GetUserByUri(Uri uri) { return null; }
public bool UpdateUserProfile(UserProfileData user)
{
m_userProfilesByUuid[user.ID] = user;
m_userProfilesByName[user.FirstName + " " + user.SurName] = user;
return true;
}
public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; }
public UserAgentData GetAgentByUUID(UUID user)
{
UserAgentData userAgent = null;
m_agentByProfileUuid.TryGetValue(user, out userAgent);
return userAgent;
}
public UserAgentData GetAgentByName(string name)
{
UserProfileData userProfile = null;
m_userProfilesByName.TryGetValue(name, out userProfile);
UserAgentData userAgent = null;
m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
return userAgent;
}
public UserAgentData GetAgentByName(string fname, string lname)
{
UserProfileData userProfile = GetUserByName(fname,lname);
UserAgentData userAgent = null;
m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
return userAgent;
}
public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {}
public void AddNewUserAgent(UserAgentData agent)
{
m_agentByProfileUuid[agent.ProfileID] = agent;
}
public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
{
FriendListItem newfriend = new FriendListItem();
newfriend.FriendPerms = perms;
newfriend.Friend = friend;
newfriend.FriendListOwner = friendlistowner;
if (!m_friendsListByUuid.ContainsKey(friendlistowner))
{
List<FriendListItem> friendslist = new List<FriendListItem>();
m_friendsListByUuid[friendlistowner] = friendslist;
}
m_friendsListByUuid[friendlistowner].Add(newfriend);
}
public void RemoveUserFriend(UUID friendlistowner, UUID friend)
{
if (m_friendsListByUuid.ContainsKey(friendlistowner))
{
List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
foreach (FriendListItem frienditem in friendslist)
{
if (frienditem.Friend == friend)
{
friendslist.Remove(frienditem);
break;
}
}
}
}
public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
{
if (m_friendsListByUuid.ContainsKey(friendlistowner))
{
List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
foreach (FriendListItem frienditem in friendslist)
{
if (frienditem.Friend == friend)
{
frienditem.FriendPerms = perms;
break;
}
}
}
}
public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
{
if (m_friendsListByUuid.ContainsKey(friendlistowner))
{
return m_friendsListByUuid[friendlistowner];
}
else
return new List<FriendListItem>();
}
public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; }
public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; }
public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; }
public void Initialise(string connect) { return; }
public AvatarAppearance GetUserAppearance(UUID user) { return null; }
public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {}
public void ResetAttachments(UUID userID) {}
public void LogoutUsers(UUID regionID) {}
}
}