diff options
author | Diva Canto | 2010-02-21 15:38:52 -0800 |
---|---|---|
committer | Diva Canto | 2010-02-21 15:38:52 -0800 |
commit | bb171717ceaef37b022a135209c2e0bf031d21f9 (patch) | |
tree | 2239ad031280027839b22c4f3c9df1a598a63228 /OpenSim | |
parent | Bug fixes on field names in order to make data import work from old users tab... (diff) | |
download | opensim-SC-bb171717ceaef37b022a135209c2e0bf031d21f9.zip opensim-SC-bb171717ceaef37b022a135209c2e0bf031d21f9.tar.gz opensim-SC-bb171717ceaef37b022a135209c2e0bf031d21f9.tar.bz2 opensim-SC-bb171717ceaef37b022a135209c2e0bf031d21f9.tar.xz |
Deleted obsolete files in the Data layer. Compiles.
Diffstat (limited to '')
32 files changed, 103 insertions, 9201 deletions
diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs deleted file mode 100644 index 841f71e..0000000 --- a/OpenSim/Data/DataPluginFactory.cs +++ /dev/null | |||
@@ -1,155 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | |||
32 | namespace OpenSim.Data | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// A static class containing methods for obtaining handles to database | ||
36 | /// storage objects. | ||
37 | /// </summary> | ||
38 | public static class DataPluginFactory | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Based on <typeparam name="T" />, returns the appropriate | ||
42 | /// PluginInitialiserBase instance in <paramref name="init" /> and | ||
43 | /// extension point path in <paramref name="path" />. | ||
44 | /// </summary> | ||
45 | /// <param name="connect"> | ||
46 | /// The DB connection string used when creating a new | ||
47 | /// PluginInitialiserBase, returned in <paramref name="init" />. | ||
48 | /// </param> | ||
49 | /// <param name="init"> | ||
50 | /// A reference to a PluginInitialiserBase object in which the proper | ||
51 | /// initialiser will be returned. | ||
52 | /// </param> | ||
53 | /// <param name="path"> | ||
54 | /// A string in which the proper extension point path will be returned. | ||
55 | /// </param> | ||
56 | /// <typeparam name="T"> | ||
57 | /// The type of data plugin requested. | ||
58 | /// </typeparam> | ||
59 | /// <exception cref="NotImplementedException"> | ||
60 | /// Thrown if <typeparamref name="T" /> is not one of the expected data | ||
61 | /// interfaces. | ||
62 | /// </exception> | ||
63 | private static void PluginLoaderParamFactory<T>(string connect, out PluginInitialiserBase init, out string path) where T : IPlugin | ||
64 | { | ||
65 | Type type = typeof(T); | ||
66 | |||
67 | if (type == typeof(IInventoryDataPlugin)) | ||
68 | { | ||
69 | init = new InventoryDataInitialiser(connect); | ||
70 | path = "/OpenSim/InventoryData"; | ||
71 | } | ||
72 | else if (type == typeof(IUserDataPlugin)) | ||
73 | { | ||
74 | init = new UserDataInitialiser(connect); | ||
75 | path = "/OpenSim/UserData"; | ||
76 | } | ||
77 | else if (type == typeof(IGridDataPlugin)) | ||
78 | { | ||
79 | init = new GridDataInitialiser(connect); | ||
80 | path = "/OpenSim/GridData"; | ||
81 | } | ||
82 | else if (type == typeof(ILogDataPlugin)) | ||
83 | { | ||
84 | init = new LogDataInitialiser(connect); | ||
85 | path = "/OpenSim/LogData"; | ||
86 | } | ||
87 | else if (type == typeof(IAssetDataPlugin)) | ||
88 | { | ||
89 | init = new AssetDataInitialiser(connect); | ||
90 | path = "/OpenSim/AssetData"; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | // We don't support this data plugin. | ||
95 | throw new NotImplementedException(String.Format("The type '{0}' is not a valid data plugin.", type)); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Returns a list of new <typeparamref name="T" /> data plugins. | ||
101 | /// Plugins will be requested in the order they were added. | ||
102 | /// </summary> | ||
103 | /// <param name="provider"> | ||
104 | /// The filename of the inventory server plugin DLL. | ||
105 | /// </param> | ||
106 | /// <param name="connect"> | ||
107 | /// The connection string for the storage backend. | ||
108 | /// </param> | ||
109 | /// <typeparam name="T"> | ||
110 | /// The type of data plugin requested. | ||
111 | /// </typeparam> | ||
112 | /// <returns> | ||
113 | /// A list of all loaded plugins matching <typeparamref name="T" />. | ||
114 | /// </returns> | ||
115 | public static List<T> LoadDataPlugins<T>(string provider, string connect) where T : IPlugin | ||
116 | { | ||
117 | PluginInitialiserBase pluginInitialiser; | ||
118 | string extensionPointPath; | ||
119 | |||
120 | PluginLoaderParamFactory<T>(connect, out pluginInitialiser, out extensionPointPath); | ||
121 | |||
122 | using (PluginLoader<T> loader = new PluginLoader<T>(pluginInitialiser)) | ||
123 | { | ||
124 | // loader will try to load all providers (MySQL, MSSQL, etc) | ||
125 | // unless it is constrainted to the correct "Provider" entry in the addin.xml | ||
126 | loader.Add(extensionPointPath, new PluginProviderFilter(provider)); | ||
127 | loader.Load(); | ||
128 | |||
129 | return loader.Plugins; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /// <summary> | ||
134 | /// Returns a new <typeparamref name="T" /> data plugin instance if | ||
135 | /// only one was loaded, otherwise returns null (<c>default(T)</c>). | ||
136 | /// </summary> | ||
137 | /// <param name="provider"> | ||
138 | /// The filename of the inventory server plugin DLL. | ||
139 | /// </param> | ||
140 | /// <param name="connect"> | ||
141 | /// The connection string for the storage backend. | ||
142 | /// </param> | ||
143 | /// <typeparam name="T"> | ||
144 | /// The type of data plugin requested. | ||
145 | /// </typeparam> | ||
146 | /// <returns> | ||
147 | /// A list of all loaded plugins matching <typeparamref name="T" />. | ||
148 | /// </returns> | ||
149 | public static T LoadDataPlugin<T>(string provider, string connect) where T : IPlugin | ||
150 | { | ||
151 | List<T> plugins = LoadDataPlugins<T>(provider, connect); | ||
152 | return (plugins.Count == 1) ? plugins[0] : default(T); | ||
153 | } | ||
154 | } | ||
155 | } | ||
diff --git a/OpenSim/Data/GridDataBase.cs b/OpenSim/Data/GridDataBase.cs deleted file mode 100644 index a03488b..0000000 --- a/OpenSim/Data/GridDataBase.cs +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Data | ||
32 | { | ||
33 | public abstract class GridDataBase : IGridDataPlugin | ||
34 | { | ||
35 | public abstract RegionProfileData GetProfileByHandle(ulong regionHandle); | ||
36 | public abstract RegionProfileData GetProfileByUUID(UUID UUID); | ||
37 | public abstract RegionProfileData GetProfileByString(string regionName); | ||
38 | public abstract RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); | ||
39 | public abstract List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum); | ||
40 | public abstract bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey); | ||
41 | public abstract DataResponse StoreProfile(RegionProfileData profile); | ||
42 | public abstract ReservationData GetReservationAtPoint(uint x, uint y); | ||
43 | public abstract DataResponse DeleteProfile(string uuid); | ||
44 | |||
45 | public abstract void Initialise(); | ||
46 | public abstract void Initialise(string connect); | ||
47 | public abstract void Dispose(); | ||
48 | |||
49 | public abstract string Name { get; } | ||
50 | public abstract string Version { get; } | ||
51 | } | ||
52 | } | ||
diff --git a/OpenSim/Data/IGridData.cs b/OpenSim/Data/IGridData.cs deleted file mode 100644 index 8bd3811..0000000 --- a/OpenSim/Data/IGridData.cs +++ /dev/null | |||
@@ -1,134 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | |||
32 | namespace OpenSim.Data | ||
33 | { | ||
34 | public enum DataResponse | ||
35 | { | ||
36 | RESPONSE_OK, | ||
37 | RESPONSE_AUTHREQUIRED, | ||
38 | RESPONSE_INVALIDCREDENTIALS, | ||
39 | RESPONSE_ERROR | ||
40 | } | ||
41 | |||
42 | /// <summary> | ||
43 | /// A standard grid interface | ||
44 | /// </summary> | ||
45 | public interface IGridDataPlugin : IPlugin | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// Initialises the interface | ||
49 | /// </summary> | ||
50 | void Initialise(string connect); | ||
51 | |||
52 | /// <summary> | ||
53 | /// Returns a sim profile from a regionHandle | ||
54 | /// </summary> | ||
55 | /// <param name="regionHandle">A 64bit Region Handle</param> | ||
56 | /// <returns>A simprofile</returns> | ||
57 | RegionProfileData GetProfileByHandle(ulong regionHandle); | ||
58 | |||
59 | /// <summary> | ||
60 | /// Returns a sim profile from a UUID | ||
61 | /// </summary> | ||
62 | /// <param name="UUID">A 128bit UUID</param> | ||
63 | /// <returns>A sim profile</returns> | ||
64 | RegionProfileData GetProfileByUUID(UUID UUID); | ||
65 | |||
66 | /// <summary> | ||
67 | /// Returns a sim profile from a string match | ||
68 | /// </summary> | ||
69 | /// <param name="regionName">A string for a partial region name match</param> | ||
70 | /// <returns>A sim profile</returns> | ||
71 | RegionProfileData GetProfileByString(string regionName); | ||
72 | |||
73 | /// <summary> | ||
74 | /// Returns all profiles within the specified range | ||
75 | /// </summary> | ||
76 | /// <param name="Xmin">Minimum sim coordinate (X)</param> | ||
77 | /// <param name="Ymin">Minimum sim coordinate (Y)</param> | ||
78 | /// <param name="Xmax">Maximum sim coordinate (X)</param> | ||
79 | /// <param name="Ymin">Maximum sim coordinate (Y)</param> | ||
80 | /// <returns>An array containing all the sim profiles in the specified range</returns> | ||
81 | RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax); | ||
82 | |||
83 | /// <summary> | ||
84 | /// Returns up to maxNum profiles of regions that have a name starting with namePrefix | ||
85 | /// </summary> | ||
86 | /// <param name="name">The name to match against</param> | ||
87 | /// <param name="maxNum">Maximum number of profiles to return</param> | ||
88 | /// <returns>A list of sim profiles</returns> | ||
89 | List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum); | ||
90 | |||
91 | /// <summary> | ||
92 | /// Authenticates a sim by use of its recv key. | ||
93 | /// WARNING: Insecure | ||
94 | /// </summary> | ||
95 | /// <param name="UUID">The UUID sent by the sim</param> | ||
96 | /// <param name="regionHandle">The regionhandle sent by the sim</param> | ||
97 | /// <param name="simrecvkey">The receiving key sent by the sim</param> | ||
98 | /// <returns>Whether the sim has been authenticated</returns> | ||
99 | bool AuthenticateSim(UUID UUID, ulong regionHandle, string simrecvkey); | ||
100 | |||
101 | /// <summary> | ||
102 | /// Adds or updates a profile in the database | ||
103 | /// </summary> | ||
104 | /// <param name="profile">The profile to add</param> | ||
105 | /// <returns>RESPONSE_OK if successful, error if not.</returns> | ||
106 | DataResponse StoreProfile(RegionProfileData profile); | ||
107 | |||
108 | /// <summary> | ||
109 | /// Remove a profile from the database | ||
110 | /// </summary> | ||
111 | /// <param name="UUID">ID of profile to remove</param> | ||
112 | /// <returns></returns> | ||
113 | DataResponse DeleteProfile(string UUID); | ||
114 | |||
115 | /// <summary> | ||
116 | /// Function not used???? | ||
117 | /// </summary> | ||
118 | /// <param name="x"></param> | ||
119 | /// <param name="y"></param> | ||
120 | /// <returns></returns> | ||
121 | ReservationData GetReservationAtPoint(uint x, uint y); | ||
122 | } | ||
123 | |||
124 | public class GridDataInitialiser : PluginInitialiserBase | ||
125 | { | ||
126 | private string connect; | ||
127 | public GridDataInitialiser (string s) { connect = s; } | ||
128 | public override void Initialise (IPlugin plugin) | ||
129 | { | ||
130 | IGridDataPlugin p = plugin as IGridDataPlugin; | ||
131 | p.Initialise (connect); | ||
132 | } | ||
133 | } | ||
134 | } | ||
diff --git a/OpenSim/Data/ILogData.cs b/OpenSim/Data/ILogData.cs deleted file mode 100644 index 97ca1cc..0000000 --- a/OpenSim/Data/ILogData.cs +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenSim.Framework; | ||
29 | |||
30 | namespace OpenSim.Data | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// The severity of an individual log message | ||
34 | /// </summary> | ||
35 | public enum LogSeverity : int | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Critical: systems failure | ||
39 | /// </summary> | ||
40 | CRITICAL = 1, | ||
41 | /// <summary> | ||
42 | /// Major: warning prior to systems failure | ||
43 | /// </summary> | ||
44 | MAJOR = 2, | ||
45 | /// <summary> | ||
46 | /// Medium: an individual non-critical task failed | ||
47 | /// </summary> | ||
48 | MEDIUM = 3, | ||
49 | /// <summary> | ||
50 | /// Low: Informational warning | ||
51 | /// </summary> | ||
52 | LOW = 4, | ||
53 | /// <summary> | ||
54 | /// Info: Information | ||
55 | /// </summary> | ||
56 | INFO = 5, | ||
57 | /// <summary> | ||
58 | /// Verbose: Debug Information | ||
59 | /// </summary> | ||
60 | VERBOSE = 6 | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// An interface to a LogData storage system | ||
65 | /// </summary> | ||
66 | public interface ILogDataPlugin : IPlugin | ||
67 | { | ||
68 | void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||
69 | string logMessage); | ||
70 | |||
71 | /// <summary> | ||
72 | /// Initialises the interface | ||
73 | /// </summary> | ||
74 | void Initialise(string connect); | ||
75 | } | ||
76 | |||
77 | public class LogDataInitialiser : PluginInitialiserBase | ||
78 | { | ||
79 | private string connect; | ||
80 | public LogDataInitialiser (string s) { connect = s; } | ||
81 | public override void Initialise (IPlugin plugin) | ||
82 | { | ||
83 | ILogDataPlugin p = plugin as ILogDataPlugin; | ||
84 | p.Initialise (connect); | ||
85 | } | ||
86 | } | ||
87 | } | ||
diff --git a/OpenSim/Data/IRegionProfileService.cs b/OpenSim/Data/IRegionProfileService.cs deleted file mode 100644 index b3acc52..0000000 --- a/OpenSim/Data/IRegionProfileService.cs +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Data | ||
34 | { | ||
35 | public interface IRegionProfileService | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Returns a region by argument | ||
39 | /// </summary> | ||
40 | /// <param name="uuid">A UUID key of the region to return</param> | ||
41 | /// <returns>A SimProfileData for the region</returns> | ||
42 | RegionProfileData GetRegion(UUID uuid); | ||
43 | |||
44 | /// <summary> | ||
45 | /// Returns a region by argument | ||
46 | /// </summary> | ||
47 | /// <param name="uuid">A regionHandle of the region to return</param> | ||
48 | /// <returns>A SimProfileData for the region</returns> | ||
49 | RegionProfileData GetRegion(ulong handle); | ||
50 | |||
51 | /// <summary> | ||
52 | /// Returns a region by argument | ||
53 | /// </summary> | ||
54 | /// <param name="regionName">A partial regionName of the region to return</param> | ||
55 | /// <returns>A SimProfileData for the region</returns> | ||
56 | RegionProfileData GetRegion(string regionName); | ||
57 | |||
58 | List<RegionProfileData> GetRegions(uint xmin, uint ymin, uint xmax, uint ymax); | ||
59 | List<RegionProfileData> GetRegions(string name, int maxNum); | ||
60 | DataResponse AddUpdateRegion(RegionProfileData sim, RegionProfileData existingSim); | ||
61 | DataResponse DeleteRegion(string uuid); | ||
62 | } | ||
63 | |||
64 | public interface IRegionProfileRouter | ||
65 | { | ||
66 | /// <summary> | ||
67 | /// Request sim profile information from a grid server, by Region UUID | ||
68 | /// </summary> | ||
69 | /// <param name="regionId">The region UUID to look for</param> | ||
70 | /// <param name="gridserverUrl"></param> | ||
71 | /// <param name="gridserverSendkey"></param> | ||
72 | /// <param name="gridserverRecvkey"></param> | ||
73 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
74 | /// <remarks>This method should be statics</remarks> | ||
75 | RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl, | ||
76 | string gridserverSendkey, string gridserverRecvkey); | ||
77 | |||
78 | /// <summary> | ||
79 | /// Request sim profile information from a grid server, by Region Handle | ||
80 | /// </summary> | ||
81 | /// <param name="regionHandle">the region handle to look for</param> | ||
82 | /// <param name="gridserverUrl"></param> | ||
83 | /// <param name="gridserverSendkey"></param> | ||
84 | /// <param name="gridserverRecvkey"></param> | ||
85 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
86 | RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl, | ||
87 | string gridserverSendkey, string gridserverRecvkey); | ||
88 | |||
89 | /// <summary> | ||
90 | /// Request sim profile information from a grid server, by Region Name | ||
91 | /// </summary> | ||
92 | /// <param name="regionName">the region name to look for</param> | ||
93 | /// <param name="gridserverUrl"></param> | ||
94 | /// <param name="gridserverSendkey"></param> | ||
95 | /// <param name="gridserverRecvkey"></param> | ||
96 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
97 | RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl, | ||
98 | string gridserverSendkey, string gridserverRecvkey); | ||
99 | } | ||
100 | } | ||
diff --git a/OpenSim/Data/IUserData.cs b/OpenSim/Data/IUserData.cs deleted file mode 100644 index e9a1e81..0000000 --- a/OpenSim/Data/IUserData.cs +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Data | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// An interface for connecting to user storage servers. | ||
37 | /// </summary> | ||
38 | public interface IUserDataPlugin : IPlugin | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Returns a user profile from a database via their UUID | ||
42 | /// </summary> | ||
43 | /// <param name="user">The user's UUID</param> | ||
44 | /// <returns>The user data profile. Returns null if no user is found</returns> | ||
45 | UserProfileData GetUserByUUID(UUID user); | ||
46 | |||
47 | /// <summary> | ||
48 | /// Returns a users profile by searching their username parts | ||
49 | /// </summary> | ||
50 | /// <param name="fname">Account firstname</param> | ||
51 | /// <param name="lname">Account lastname</param> | ||
52 | /// <returns>The user data profile. Null if no user is found</returns> | ||
53 | UserProfileData GetUserByName(string fname, string lname); | ||
54 | |||
55 | /// <summary> | ||
56 | /// Get a user from a given uri. | ||
57 | /// </summary> | ||
58 | /// <param name="uri"></param> | ||
59 | /// <returns>The user data profile. Null if no user is found.</returns> | ||
60 | UserProfileData GetUserByUri(Uri uri); | ||
61 | |||
62 | /// <summary> | ||
63 | /// Returns a list of UUIDs firstnames and lastnames that match string query entered into the avatar picker. | ||
64 | /// </summary> | ||
65 | /// <param name="queryID">ID associated with the user's query. This must match what the client sent</param> | ||
66 | /// <param name="query">The filtered contents of the search box when the user hit search.</param> | ||
67 | /// <returns>A list of user details. If there are no results than either an empty list or null</returns> | ||
68 | List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query); | ||
69 | |||
70 | /// <summary> | ||
71 | /// Returns the current agent for a user searching by it's UUID | ||
72 | /// </summary> | ||
73 | /// <param name="user">The users UUID</param> | ||
74 | /// <returns>The current agent session. Null if no session was found</returns> | ||
75 | UserAgentData GetAgentByUUID(UUID user); | ||
76 | |||
77 | /// <summary> | ||
78 | /// Returns the current session agent for a user searching by username | ||
79 | /// </summary> | ||
80 | /// <param name="name">The users account name</param> | ||
81 | /// <returns>The current agent session</returns> | ||
82 | UserAgentData GetAgentByName(string name); | ||
83 | |||
84 | /// <summary> | ||
85 | /// Returns the current session agent for a user searching by username parts | ||
86 | /// </summary> | ||
87 | /// <param name="fname">The users first account name</param> | ||
88 | /// <param name="lname">The users account surname</param> | ||
89 | /// <returns>The current agent session</returns> | ||
90 | UserAgentData GetAgentByName(string fname, string lname); | ||
91 | |||
92 | /// <summary> | ||
93 | /// Stores new web-login key for user during web page login | ||
94 | /// </summary> | ||
95 | /// <param name="webLoginKey"></param> | ||
96 | void StoreWebLoginKey(UUID agentID, UUID webLoginKey); | ||
97 | |||
98 | /// <summary> | ||
99 | /// Adds a new User profile to the database | ||
100 | /// </summary> | ||
101 | /// <param name="user">UserProfile to add</param> | ||
102 | void AddNewUserProfile(UserProfileData user); | ||
103 | |||
104 | /// <summary> | ||
105 | /// Adds a temporary user profile. A temporary userprofile is one that should exist only for the lifetime of | ||
106 | /// the process. | ||
107 | /// </summary> | ||
108 | /// <param name="userProfile"></param> | ||
109 | void AddTemporaryUserProfile(UserProfileData userProfile); | ||
110 | |||
111 | /// <summary> | ||
112 | /// Updates an existing user profile | ||
113 | /// </summary> | ||
114 | /// <param name="user">UserProfile to update</param> | ||
115 | bool UpdateUserProfile(UserProfileData user); | ||
116 | |||
117 | /// <summary> | ||
118 | /// Adds a new agent to the database | ||
119 | /// </summary> | ||
120 | /// <param name="agent">The agent to add</param> | ||
121 | void AddNewUserAgent(UserAgentData agent); | ||
122 | |||
123 | /// <summary> | ||
124 | /// Adds a new friend to the database for XUser | ||
125 | /// </summary> | ||
126 | /// <param name="friendlistowner">The agent that who's friends list is being added to</param> | ||
127 | /// <param name="friend">The agent that being added to the friends list of the friends list owner</param> | ||
128 | /// <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> | ||
129 | void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms); | ||
130 | |||
131 | /// <summary> | ||
132 | /// Delete friend on friendlistowner's friendlist. | ||
133 | /// </summary> | ||
134 | /// <param name="friendlistowner">The agent that who's friends list is being updated</param> | ||
135 | /// <param name="friend">The Ex-friend agent</param> | ||
136 | void RemoveUserFriend(UUID friendlistowner, UUID friend); | ||
137 | |||
138 | /// <summary> | ||
139 | /// Update permissions for friend on friendlistowner's friendlist. | ||
140 | /// </summary> | ||
141 | /// <param name="friendlistowner">The agent that who's friends list is being updated</param> | ||
142 | /// <param name="friend">The agent that is getting or loosing permissions</param> | ||
143 | /// <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> | ||
144 | void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms); | ||
145 | |||
146 | /// <summary> | ||
147 | /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for UUID friendslistowner | ||
148 | /// </summary> | ||
149 | /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param> | ||
150 | /// <returns>The user's friends. If there are no results than either an empty list or null</returns> | ||
151 | List<FriendListItem> GetUserFriendList(UUID friendlistowner); | ||
152 | |||
153 | /// <summary> | ||
154 | /// Returns a list of <see cref="FriendRegionInfo/>s for the specified UUIDs. | ||
155 | /// </summary> | ||
156 | /// <param name="uuids"> | ||
157 | /// A <see cref="List"/> of <see cref="UUID/>s to fetch info for | ||
158 | /// </param> | ||
159 | /// <returns> | ||
160 | /// A <see cref="Dictionary"/>, mapping the <see cref="UUID"/>s to <see cref="FriendRegionInfo"/>s. | ||
161 | /// </returns> | ||
162 | Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids); | ||
163 | |||
164 | /// <summary> | ||
165 | /// Attempts to move currency units between accounts (NOT RELIABLE / TRUSTWORTHY. DONT TRY RUN YOUR OWN CURRENCY EXCHANGE WITH REAL VALUES) | ||
166 | /// </summary> | ||
167 | /// <param name="from">The account to transfer from</param> | ||
168 | /// <param name="to">The account to transfer to</param> | ||
169 | /// <param name="amount">The amount to transfer</param> | ||
170 | /// <returns>Successful?</returns> | ||
171 | bool MoneyTransferRequest(UUID from, UUID to, uint amount); | ||
172 | |||
173 | /// <summary> | ||
174 | /// Attempts to move inventory between accounts, if inventory is copyable it will be copied into the target account. | ||
175 | /// </summary> | ||
176 | /// <param name="from">User to transfer from</param> | ||
177 | /// <param name="to">User to transfer to</param> | ||
178 | /// <param name="inventory">Specified inventory item</param> | ||
179 | /// <returns>Successful?</returns> | ||
180 | bool InventoryTransferRequest(UUID from, UUID to, UUID inventory); | ||
181 | |||
182 | /// <summary> | ||
183 | /// Initialises the plugin (artificial constructor) | ||
184 | /// </summary> | ||
185 | void Initialise(string connect); | ||
186 | |||
187 | /// <summary> | ||
188 | /// Gets the user appearance | ||
189 | /// </summer> | ||
190 | AvatarAppearance GetUserAppearance(UUID user); | ||
191 | |||
192 | void UpdateUserAppearance(UUID user, AvatarAppearance appearance); | ||
193 | |||
194 | void ResetAttachments(UUID userID); | ||
195 | |||
196 | void LogoutUsers(UUID regionID); | ||
197 | } | ||
198 | |||
199 | public class UserDataInitialiser : PluginInitialiserBase | ||
200 | { | ||
201 | private string connect; | ||
202 | public UserDataInitialiser (string s) { connect = s; } | ||
203 | public override void Initialise (IPlugin plugin) | ||
204 | { | ||
205 | IUserDataPlugin p = plugin as IUserDataPlugin; | ||
206 | p.Initialise (connect); | ||
207 | } | ||
208 | } | ||
209 | } | ||
diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs deleted file mode 100644 index 8a3d332..0000000 --- a/OpenSim/Data/MSSQL/MSSQLGridData.cs +++ /dev/null | |||
@@ -1,587 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Data.SqlClient; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Data.MSSQL | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A grid data interface for MSSQL Server | ||
41 | /// </summary> | ||
42 | public class MSSQLGridData : GridDataBase | ||
43 | { | ||
44 | private const string _migrationStore = "GridStore"; | ||
45 | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | /// <summary> | ||
49 | /// Database manager | ||
50 | /// </summary> | ||
51 | private MSSQLManager database; | ||
52 | |||
53 | private string m_regionsTableName = "regions"; | ||
54 | |||
55 | #region IPlugin Members | ||
56 | |||
57 | // [Obsolete("Cannot be default-initialized!")] | ||
58 | override public void Initialise() | ||
59 | { | ||
60 | m_log.Info("[GRID DB]: " + Name + " cannot be default-initialized!"); | ||
61 | throw new PluginNotInitialisedException(Name); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Initialises the Grid Interface | ||
66 | /// </summary> | ||
67 | /// <param name="connectionString">connect string</param> | ||
68 | /// <remarks>use mssql_connection.ini</remarks> | ||
69 | override public void Initialise(string connectionString) | ||
70 | { | ||
71 | if (!string.IsNullOrEmpty(connectionString)) | ||
72 | { | ||
73 | database = new MSSQLManager(connectionString); | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | // TODO: make the connect string actually do something | ||
78 | IniFile iniFile = new IniFile("mssql_connection.ini"); | ||
79 | |||
80 | string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||
81 | string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||
82 | string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||
83 | string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||
84 | string settingPassword = iniFile.ParseFileReadValue("password"); | ||
85 | |||
86 | m_regionsTableName = iniFile.ParseFileReadValue("regionstablename"); | ||
87 | if (m_regionsTableName == null) | ||
88 | { | ||
89 | m_regionsTableName = "regions"; | ||
90 | } | ||
91 | |||
92 | database = | ||
93 | new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||
94 | settingPassword); | ||
95 | } | ||
96 | |||
97 | //New migrations check of store | ||
98 | database.CheckMigration(_migrationStore); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Shuts down the grid interface | ||
103 | /// </summary> | ||
104 | override public void Dispose() | ||
105 | { | ||
106 | database = null; | ||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// The name of this DB provider. | ||
111 | /// </summary> | ||
112 | /// <returns>A string containing the storage system name</returns> | ||
113 | override public string Name | ||
114 | { | ||
115 | get { return "MSSQL OpenGridData"; } | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// Database provider version. | ||
120 | /// </summary> | ||
121 | /// <returns>A string containing the storage system version</returns> | ||
122 | override public string Version | ||
123 | { | ||
124 | get { return "0.1"; } | ||
125 | } | ||
126 | |||
127 | #endregion | ||
128 | |||
129 | #region Public override GridDataBase methods | ||
130 | |||
131 | /// <summary> | ||
132 | /// Returns a list of regions within the specified ranges | ||
133 | /// </summary> | ||
134 | /// <param name="xmin">minimum X coordinate</param> | ||
135 | /// <param name="ymin">minimum Y coordinate</param> | ||
136 | /// <param name="xmax">maximum X coordinate</param> | ||
137 | /// <param name="ymax">maximum Y coordinate</param> | ||
138 | /// <returns>null</returns> | ||
139 | /// <remarks>always return null</remarks> | ||
140 | override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) | ||
141 | { | ||
142 | using (AutoClosingSqlCommand command = database.Query("SELECT * FROM regions WHERE locX >= @xmin AND locX <= @xmax AND locY >= @ymin AND locY <= @ymax")) | ||
143 | { | ||
144 | command.Parameters.Add(database.CreateParameter("xmin", xmin)); | ||
145 | command.Parameters.Add(database.CreateParameter("ymin", ymin)); | ||
146 | command.Parameters.Add(database.CreateParameter("xmax", xmax)); | ||
147 | command.Parameters.Add(database.CreateParameter("ymax", ymax)); | ||
148 | |||
149 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
150 | |||
151 | using (SqlDataReader reader = command.ExecuteReader()) | ||
152 | { | ||
153 | while (reader.Read()) | ||
154 | { | ||
155 | rows.Add(ReadSimRow(reader)); | ||
156 | } | ||
157 | } | ||
158 | |||
159 | if (rows.Count > 0) | ||
160 | { | ||
161 | return rows.ToArray(); | ||
162 | } | ||
163 | } | ||
164 | m_log.Info("[GRID DB] : Found no regions within range."); | ||
165 | return null; | ||
166 | } | ||
167 | |||
168 | |||
169 | /// <summary> | ||
170 | /// Returns up to maxNum profiles of regions that have a name starting with namePrefix | ||
171 | /// </summary> | ||
172 | /// <param name="namePrefix">The name to match against</param> | ||
173 | /// <param name="maxNum">Maximum number of profiles to return</param> | ||
174 | /// <returns>A list of sim profiles</returns> | ||
175 | override public List<RegionProfileData> GetRegionsByName (string namePrefix, uint maxNum) | ||
176 | { | ||
177 | using (AutoClosingSqlCommand command = database.Query("SELECT * FROM regions WHERE regionName LIKE @name")) | ||
178 | { | ||
179 | command.Parameters.Add(database.CreateParameter("name", namePrefix + "%")); | ||
180 | |||
181 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
182 | |||
183 | using (SqlDataReader reader = command.ExecuteReader()) | ||
184 | { | ||
185 | while (rows.Count < maxNum && reader.Read()) | ||
186 | { | ||
187 | rows.Add(ReadSimRow(reader)); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | return rows; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | /// <summary> | ||
196 | /// Returns a sim profile from its location | ||
197 | /// </summary> | ||
198 | /// <param name="handle">Region location handle</param> | ||
199 | /// <returns>Sim profile</returns> | ||
200 | override public RegionProfileData GetProfileByHandle(ulong handle) | ||
201 | { | ||
202 | using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle")) | ||
203 | { | ||
204 | command.Parameters.Add(database.CreateParameter("handle", handle)); | ||
205 | |||
206 | using (SqlDataReader reader = command.ExecuteReader()) | ||
207 | { | ||
208 | if (reader.Read()) | ||
209 | { | ||
210 | return ReadSimRow(reader); | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | m_log.InfoFormat("[GRID DB] : No region found with handle : {0}", handle); | ||
215 | return null; | ||
216 | } | ||
217 | |||
218 | /// <summary> | ||
219 | /// Returns a sim profile from its UUID | ||
220 | /// </summary> | ||
221 | /// <param name="uuid">The region UUID</param> | ||
222 | /// <returns>The sim profile</returns> | ||
223 | override public RegionProfileData GetProfileByUUID(UUID uuid) | ||
224 | { | ||
225 | using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid")) | ||
226 | { | ||
227 | command.Parameters.Add(database.CreateParameter("uuid", uuid)); | ||
228 | |||
229 | using (SqlDataReader reader = command.ExecuteReader()) | ||
230 | { | ||
231 | if (reader.Read()) | ||
232 | { | ||
233 | return ReadSimRow(reader); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | m_log.InfoFormat("[GRID DB] : No region found with UUID : {0}", uuid); | ||
238 | return null; | ||
239 | } | ||
240 | |||
241 | /// <summary> | ||
242 | /// Returns a sim profile from it's Region name string | ||
243 | /// </summary> | ||
244 | /// <param name="regionName">The region name search query</param> | ||
245 | /// <returns>The sim profile</returns> | ||
246 | override public RegionProfileData GetProfileByString(string regionName) | ||
247 | { | ||
248 | if (regionName.Length > 2) | ||
249 | { | ||
250 | using (AutoClosingSqlCommand command = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like @regionName order by regionName")) | ||
251 | { | ||
252 | command.Parameters.Add(database.CreateParameter("regionName", regionName + "%")); | ||
253 | |||
254 | using (SqlDataReader reader = command.ExecuteReader()) | ||
255 | { | ||
256 | if (reader.Read()) | ||
257 | { | ||
258 | return ReadSimRow(reader); | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | m_log.InfoFormat("[GRID DB] : No region found with regionName : {0}", regionName); | ||
263 | return null; | ||
264 | } | ||
265 | |||
266 | m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters"); | ||
267 | return null; | ||
268 | } | ||
269 | |||
270 | /// <summary> | ||
271 | /// Adds a new specified region to the database | ||
272 | /// </summary> | ||
273 | /// <param name="profile">The profile to add</param> | ||
274 | /// <returns>A dataresponse enum indicating success</returns> | ||
275 | override public DataResponse StoreProfile(RegionProfileData profile) | ||
276 | { | ||
277 | if (GetProfileByUUID(profile.UUID) == null) | ||
278 | { | ||
279 | if (InsertRegionRow(profile)) | ||
280 | { | ||
281 | return DataResponse.RESPONSE_OK; | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | if (UpdateRegionRow(profile)) | ||
287 | { | ||
288 | return DataResponse.RESPONSE_OK; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | return DataResponse.RESPONSE_ERROR; | ||
293 | } | ||
294 | |||
295 | /// <summary> | ||
296 | /// Deletes a sim profile from the database | ||
297 | /// </summary> | ||
298 | /// <param name="uuid">the sim UUID</param> | ||
299 | /// <returns>Successful?</returns> | ||
300 | //public DataResponse DeleteProfile(RegionProfileData profile) | ||
301 | override public DataResponse DeleteProfile(string uuid) | ||
302 | { | ||
303 | using (AutoClosingSqlCommand command = database.Query("DELETE FROM regions WHERE uuid = @uuid;")) | ||
304 | { | ||
305 | command.Parameters.Add(database.CreateParameter("uuid", uuid)); | ||
306 | try | ||
307 | { | ||
308 | command.ExecuteNonQuery(); | ||
309 | return DataResponse.RESPONSE_OK; | ||
310 | } | ||
311 | catch (Exception e) | ||
312 | { | ||
313 | m_log.DebugFormat("[GRID DB] : Error deleting region info, error is : {0}", e.Message); | ||
314 | return DataResponse.RESPONSE_ERROR; | ||
315 | } | ||
316 | } | ||
317 | } | ||
318 | |||
319 | #endregion | ||
320 | |||
321 | #region Methods that are not used or deprecated (still needed because of base class) | ||
322 | |||
323 | /// <summary> | ||
324 | /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. | ||
325 | /// </summary> | ||
326 | /// <param name="uuid">The UUID of the challenger</param> | ||
327 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
328 | /// <param name="authkey">The secret</param> | ||
329 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
330 | override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey) | ||
331 | { | ||
332 | bool throwHissyFit = false; // Should be true by 1.0 | ||
333 | |||
334 | if (throwHissyFit) | ||
335 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
336 | |||
337 | RegionProfileData data = GetProfileByUUID(uuid); | ||
338 | |||
339 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
340 | } | ||
341 | |||
342 | /// <summary> | ||
343 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
344 | /// </summary> | ||
345 | /// <remarks>This requires a security audit.</remarks> | ||
346 | /// <param name="uuid"></param> | ||
347 | /// <param name="handle"></param> | ||
348 | /// <param name="authhash"></param> | ||
349 | /// <param name="challenge"></param> | ||
350 | /// <returns></returns> | ||
351 | public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge) | ||
352 | { | ||
353 | // SHA512Managed HashProvider = new SHA512Managed(); | ||
354 | // Encoding TextProvider = new UTF8Encoding(); | ||
355 | |||
356 | // byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge); | ||
357 | // byte[] hash = HashProvider.ComputeHash(stream); | ||
358 | return false; | ||
359 | } | ||
360 | |||
361 | /// <summary> | ||
362 | /// NOT IMPLEMENTED | ||
363 | /// WHEN IS THIS GONNA BE IMPLEMENTED. | ||
364 | /// </summary> | ||
365 | /// <param name="x"></param> | ||
366 | /// <param name="y"></param> | ||
367 | /// <returns>null</returns> | ||
368 | override public ReservationData GetReservationAtPoint(uint x, uint y) | ||
369 | { | ||
370 | return null; | ||
371 | } | ||
372 | |||
373 | #endregion | ||
374 | |||
375 | #region private methods | ||
376 | |||
377 | /// <summary> | ||
378 | /// Reads a region row from a database reader | ||
379 | /// </summary> | ||
380 | /// <param name="reader">An active database reader</param> | ||
381 | /// <returns>A region profile</returns> | ||
382 | private static RegionProfileData ReadSimRow(IDataRecord reader) | ||
383 | { | ||
384 | RegionProfileData retval = new RegionProfileData(); | ||
385 | |||
386 | // Region Main gotta-have-or-we-return-null parts | ||
387 | UInt64 tmp64; | ||
388 | if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64)) | ||
389 | { | ||
390 | return null; | ||
391 | } | ||
392 | |||
393 | retval.regionHandle = tmp64; | ||
394 | |||
395 | // UUID tmp_uuid; | ||
396 | // if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid)) | ||
397 | // { | ||
398 | // return null; | ||
399 | // } | ||
400 | |||
401 | retval.UUID = new UUID((Guid)reader["uuid"]); // tmp_uuid; | ||
402 | |||
403 | // non-critical parts | ||
404 | retval.regionName = reader["regionName"].ToString(); | ||
405 | retval.originUUID = new UUID((Guid)reader["originUUID"]); | ||
406 | |||
407 | // Secrets | ||
408 | retval.regionRecvKey = reader["regionRecvKey"].ToString(); | ||
409 | retval.regionSecret = reader["regionSecret"].ToString(); | ||
410 | retval.regionSendKey = reader["regionSendKey"].ToString(); | ||
411 | |||
412 | // Region Server | ||
413 | retval.regionDataURI = reader["regionDataURI"].ToString(); | ||
414 | retval.regionOnline = false; // Needs to be pinged before this can be set. | ||
415 | retval.serverIP = reader["serverIP"].ToString(); | ||
416 | retval.serverPort = Convert.ToUInt32(reader["serverPort"]); | ||
417 | retval.serverURI = reader["serverURI"].ToString(); | ||
418 | retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString()); | ||
419 | retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString()); | ||
420 | |||
421 | // Location | ||
422 | retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString()); | ||
423 | retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString()); | ||
424 | retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString()); | ||
425 | |||
426 | // Neighbours - 0 = No Override | ||
427 | retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString()); | ||
428 | retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString()); | ||
429 | retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString()); | ||
430 | retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString()); | ||
431 | |||
432 | // Assets | ||
433 | retval.regionAssetURI = reader["regionAssetURI"].ToString(); | ||
434 | retval.regionAssetRecvKey = reader["regionAssetRecvKey"].ToString(); | ||
435 | retval.regionAssetSendKey = reader["regionAssetSendKey"].ToString(); | ||
436 | |||
437 | // Userserver | ||
438 | retval.regionUserURI = reader["regionUserURI"].ToString(); | ||
439 | retval.regionUserRecvKey = reader["regionUserRecvKey"].ToString(); | ||
440 | retval.regionUserSendKey = reader["regionUserSendKey"].ToString(); | ||
441 | |||
442 | // World Map Addition | ||
443 | retval.regionMapTextureID = new UUID((Guid)reader["regionMapTexture"]); | ||
444 | retval.owner_uuid = new UUID((Guid)reader["owner_uuid"]); | ||
445 | retval.maturity = Convert.ToUInt32(reader["access"]); | ||
446 | return retval; | ||
447 | } | ||
448 | |||
449 | /// <summary> | ||
450 | /// Update the specified region in the database | ||
451 | /// </summary> | ||
452 | /// <param name="profile">The profile to update</param> | ||
453 | /// <returns>success ?</returns> | ||
454 | private bool UpdateRegionRow(RegionProfileData profile) | ||
455 | { | ||
456 | bool returnval = false; | ||
457 | |||
458 | //Insert new region | ||
459 | string sql = | ||
460 | "UPDATE " + m_regionsTableName + @" SET | ||
461 | [regionHandle]=@regionHandle, [regionName]=@regionName, | ||
462 | [regionRecvKey]=@regionRecvKey, [regionSecret]=@regionSecret, [regionSendKey]=@regionSendKey, | ||
463 | [regionDataURI]=@regionDataURI, [serverIP]=@serverIP, [serverPort]=@serverPort, [serverURI]=@serverURI, | ||
464 | [locX]=@locX, [locY]=@locY, [locZ]=@locZ, [eastOverrideHandle]=@eastOverrideHandle, | ||
465 | [westOverrideHandle]=@westOverrideHandle, [southOverrideHandle]=@southOverrideHandle, | ||
466 | [northOverrideHandle]=@northOverrideHandle, [regionAssetURI]=@regionAssetURI, | ||
467 | [regionAssetRecvKey]=@regionAssetRecvKey, [regionAssetSendKey]=@regionAssetSendKey, | ||
468 | [regionUserURI]=@regionUserURI, [regionUserRecvKey]=@regionUserRecvKey, [regionUserSendKey]=@regionUserSendKey, | ||
469 | [regionMapTexture]=@regionMapTexture, [serverHttpPort]=@serverHttpPort, | ||
470 | [serverRemotingPort]=@serverRemotingPort, [owner_uuid]=@owner_uuid , [originUUID]=@originUUID | ||
471 | where [uuid]=@uuid"; | ||
472 | |||
473 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
474 | { | ||
475 | command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle)); | ||
476 | command.Parameters.Add(database.CreateParameter("regionName", profile.regionName)); | ||
477 | command.Parameters.Add(database.CreateParameter("uuid", profile.UUID)); | ||
478 | command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey)); | ||
479 | command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret)); | ||
480 | command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey)); | ||
481 | command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI)); | ||
482 | command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP)); | ||
483 | command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort)); | ||
484 | command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI)); | ||
485 | command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX)); | ||
486 | command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY)); | ||
487 | command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ)); | ||
488 | command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle)); | ||
489 | command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle)); | ||
490 | command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle)); | ||
491 | command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle)); | ||
492 | command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI)); | ||
493 | command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey)); | ||
494 | command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey)); | ||
495 | command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI)); | ||
496 | command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey)); | ||
497 | command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey)); | ||
498 | command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID)); | ||
499 | command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort)); | ||
500 | command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort)); | ||
501 | command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid)); | ||
502 | command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID)); | ||
503 | |||
504 | try | ||
505 | { | ||
506 | command.ExecuteNonQuery(); | ||
507 | returnval = true; | ||
508 | } | ||
509 | catch (Exception e) | ||
510 | { | ||
511 | m_log.Error("[GRID DB] : Error updating region, error: " + e.Message); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | return returnval; | ||
516 | } | ||
517 | |||
518 | /// <summary> | ||
519 | /// Creates a new region in the database | ||
520 | /// </summary> | ||
521 | /// <param name="profile">The region profile to insert</param> | ||
522 | /// <returns>Successful?</returns> | ||
523 | private bool InsertRegionRow(RegionProfileData profile) | ||
524 | { | ||
525 | bool returnval = false; | ||
526 | |||
527 | //Insert new region | ||
528 | string sql = | ||
529 | "INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], | ||
530 | [serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], | ||
531 | [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey], | ||
532 | [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], | ||
533 | [serverRemotingPort], [owner_uuid], [originUUID], [access]) | ||
534 | VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, | ||
535 | @serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, | ||
536 | @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey, | ||
537 | @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid, @originUUID, @access);"; | ||
538 | |||
539 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
540 | { | ||
541 | command.Parameters.Add(database.CreateParameter("regionHandle", profile.regionHandle)); | ||
542 | command.Parameters.Add(database.CreateParameter("regionName", profile.regionName)); | ||
543 | command.Parameters.Add(database.CreateParameter("uuid", profile.UUID)); | ||
544 | command.Parameters.Add(database.CreateParameter("regionRecvKey", profile.regionRecvKey)); | ||
545 | command.Parameters.Add(database.CreateParameter("regionSecret", profile.regionSecret)); | ||
546 | command.Parameters.Add(database.CreateParameter("regionSendKey", profile.regionSendKey)); | ||
547 | command.Parameters.Add(database.CreateParameter("regionDataURI", profile.regionDataURI)); | ||
548 | command.Parameters.Add(database.CreateParameter("serverIP", profile.serverIP)); | ||
549 | command.Parameters.Add(database.CreateParameter("serverPort", profile.serverPort)); | ||
550 | command.Parameters.Add(database.CreateParameter("serverURI", profile.serverURI)); | ||
551 | command.Parameters.Add(database.CreateParameter("locX", profile.regionLocX)); | ||
552 | command.Parameters.Add(database.CreateParameter("locY", profile.regionLocY)); | ||
553 | command.Parameters.Add(database.CreateParameter("locZ", profile.regionLocZ)); | ||
554 | command.Parameters.Add(database.CreateParameter("eastOverrideHandle", profile.regionEastOverrideHandle)); | ||
555 | command.Parameters.Add(database.CreateParameter("westOverrideHandle", profile.regionWestOverrideHandle)); | ||
556 | command.Parameters.Add(database.CreateParameter("northOverrideHandle", profile.regionNorthOverrideHandle)); | ||
557 | command.Parameters.Add(database.CreateParameter("southOverrideHandle", profile.regionSouthOverrideHandle)); | ||
558 | command.Parameters.Add(database.CreateParameter("regionAssetURI", profile.regionAssetURI)); | ||
559 | command.Parameters.Add(database.CreateParameter("regionAssetRecvKey", profile.regionAssetRecvKey)); | ||
560 | command.Parameters.Add(database.CreateParameter("regionAssetSendKey", profile.regionAssetSendKey)); | ||
561 | command.Parameters.Add(database.CreateParameter("regionUserURI", profile.regionUserURI)); | ||
562 | command.Parameters.Add(database.CreateParameter("regionUserRecvKey", profile.regionUserRecvKey)); | ||
563 | command.Parameters.Add(database.CreateParameter("regionUserSendKey", profile.regionUserSendKey)); | ||
564 | command.Parameters.Add(database.CreateParameter("regionMapTexture", profile.regionMapTextureID)); | ||
565 | command.Parameters.Add(database.CreateParameter("serverHttpPort", profile.httpPort)); | ||
566 | command.Parameters.Add(database.CreateParameter("serverRemotingPort", profile.remotingPort)); | ||
567 | command.Parameters.Add(database.CreateParameter("owner_uuid", profile.owner_uuid)); | ||
568 | command.Parameters.Add(database.CreateParameter("originUUID", profile.originUUID)); | ||
569 | command.Parameters.Add(database.CreateParameter("access", profile.maturity)); | ||
570 | |||
571 | try | ||
572 | { | ||
573 | command.ExecuteNonQuery(); | ||
574 | returnval = true; | ||
575 | } | ||
576 | catch (Exception e) | ||
577 | { | ||
578 | m_log.Error("[GRID DB] : Error inserting region, error: " + e.Message); | ||
579 | } | ||
580 | } | ||
581 | |||
582 | return returnval; | ||
583 | } | ||
584 | |||
585 | #endregion | ||
586 | } | ||
587 | } | ||
diff --git a/OpenSim/Data/MSSQL/MSSQLLogData.cs b/OpenSim/Data/MSSQL/MSSQLLogData.cs deleted file mode 100644 index 72c50e6..0000000 --- a/OpenSim/Data/MSSQL/MSSQLLogData.cs +++ /dev/null | |||
@@ -1,146 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Data.MSSQL | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// An interface to the log database for MSSQL | ||
37 | /// </summary> | ||
38 | internal class MSSQLLogData : ILogDataPlugin | ||
39 | { | ||
40 | private const string _migrationStore = "LogStore"; | ||
41 | |||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | /// <summary> | ||
45 | /// The database manager | ||
46 | /// </summary> | ||
47 | public MSSQLManager database; | ||
48 | |||
49 | [Obsolete("Cannot be default-initialized!")] | ||
50 | public void Initialise() | ||
51 | { | ||
52 | m_log.Info("[LOG DB]: " + Name + " cannot be default-initialized!"); | ||
53 | throw new PluginNotInitialisedException (Name); | ||
54 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// Artificial constructor called when the plugin is loaded | ||
58 | /// </summary> | ||
59 | public void Initialise(string connect) | ||
60 | { | ||
61 | if (!string.IsNullOrEmpty(connect)) | ||
62 | { | ||
63 | database = new MSSQLManager(connect); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | // TODO: do something with the connect string | ||
68 | IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini"); | ||
69 | string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source"); | ||
70 | string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog"); | ||
71 | string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info"); | ||
72 | string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id"); | ||
73 | string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password"); | ||
74 | |||
75 | database = | ||
76 | new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||
77 | settingPassword); | ||
78 | } | ||
79 | |||
80 | //Updating mechanisme | ||
81 | database.CheckMigration(_migrationStore); | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// Saves a log item to the database | ||
86 | /// </summary> | ||
87 | /// <param name="serverDaemon">The daemon triggering the event</param> | ||
88 | /// <param name="target">The target of the action (region / agent UUID, etc)</param> | ||
89 | /// <param name="methodCall">The method call where the problem occured</param> | ||
90 | /// <param name="arguments">The arguments passed to the method</param> | ||
91 | /// <param name="priority">How critical is this?</param> | ||
92 | /// <param name="logMessage">The message to log</param> | ||
93 | public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||
94 | string logMessage) | ||
95 | { | ||
96 | string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES "; | ||
97 | sql += "(@target, @server, @method, @arguments, @priority, @message);"; | ||
98 | |||
99 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
100 | { | ||
101 | command.Parameters.Add(database.CreateParameter("server", serverDaemon)); | ||
102 | command.Parameters.Add(database.CreateParameter("target",target)); | ||
103 | command.Parameters.Add(database.CreateParameter("method", methodCall)); | ||
104 | command.Parameters.Add(database.CreateParameter("arguments", arguments)); | ||
105 | command.Parameters.Add(database.CreateParameter("priority", priority.ToString())); | ||
106 | command.Parameters.Add(database.CreateParameter("message", logMessage)); | ||
107 | |||
108 | try | ||
109 | { | ||
110 | command.ExecuteNonQuery(); | ||
111 | } | ||
112 | catch (Exception e) | ||
113 | { | ||
114 | //Are we not in a loop here | ||
115 | m_log.Error("[LOG DB] Error logging : " + e.Message); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Returns the name of this DB provider | ||
122 | /// </summary> | ||
123 | /// <returns>A string containing the DB provider name</returns> | ||
124 | public string Name | ||
125 | { | ||
126 | get { return "MSSQL Logdata Interface"; } | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// Closes the database provider | ||
131 | /// </summary> | ||
132 | public void Dispose() | ||
133 | { | ||
134 | database = null; | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Returns the version of this DB provider | ||
139 | /// </summary> | ||
140 | /// <returns>A string containing the provider version</returns> | ||
141 | public string Version | ||
142 | { | ||
143 | get { return "0.1"; } | ||
144 | } | ||
145 | } | ||
146 | } | ||
diff --git a/OpenSim/Data/MSSQL/MSSQLUserData.cs b/OpenSim/Data/MSSQL/MSSQLUserData.cs deleted file mode 100644 index 3ef1053..0000000 --- a/OpenSim/Data/MSSQL/MSSQLUserData.cs +++ /dev/null | |||
@@ -1,1214 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using System.Data.SqlClient; | ||
33 | using System.Reflection; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Data.MSSQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A database interface class to a user profile storage system | ||
42 | /// </summary> | ||
43 | public class MSSQLUserData : UserDataBase | ||
44 | { | ||
45 | private const string _migrationStore = "UserStore"; | ||
46 | |||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | /// <summary> | ||
50 | /// Database manager for MSSQL | ||
51 | /// </summary> | ||
52 | public MSSQLManager database; | ||
53 | |||
54 | private const string m_agentsTableName = "agents"; | ||
55 | private const string m_usersTableName = "users"; | ||
56 | private const string m_userFriendsTableName = "userfriends"; | ||
57 | |||
58 | // [Obsolete("Cannot be default-initialized!")] | ||
59 | override public void Initialise() | ||
60 | { | ||
61 | m_log.Info("[MSSQLUserData]: " + Name + " cannot be default-initialized!"); | ||
62 | throw new PluginNotInitialisedException(Name); | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Loads and initialises the MSSQL storage plugin | ||
67 | /// </summary> | ||
68 | /// <param name="connect">connectionstring</param> | ||
69 | /// <remarks>use mssql_connection.ini</remarks> | ||
70 | override public void Initialise(string connect) | ||
71 | { | ||
72 | if (!string.IsNullOrEmpty(connect)) | ||
73 | { | ||
74 | database = new MSSQLManager(connect); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | IniFile iniFile = new IniFile("mssql_connection.ini"); | ||
79 | |||
80 | string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||
81 | string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||
82 | string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||
83 | string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||
84 | string settingPassword = iniFile.ParseFileReadValue("password"); | ||
85 | |||
86 | database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword); | ||
87 | } | ||
88 | |||
89 | //Check migration on DB | ||
90 | database.CheckMigration(_migrationStore); | ||
91 | } | ||
92 | |||
93 | /// <summary> | ||
94 | /// Releases unmanaged and - optionally - managed resources | ||
95 | /// </summary> | ||
96 | override public void Dispose() { } | ||
97 | |||
98 | #region User table methods | ||
99 | |||
100 | /// <summary> | ||
101 | /// Searches the database for a specified user profile by name components | ||
102 | /// </summary> | ||
103 | /// <param name="user">The first part of the account name</param> | ||
104 | /// <param name="last">The second part of the account name</param> | ||
105 | /// <returns>A user profile</returns> | ||
106 | override public UserProfileData GetUserByName(string user, string last) | ||
107 | { | ||
108 | string sql = string.Format(@"SELECT * FROM {0} | ||
109 | WHERE username = @first AND lastname = @second", m_usersTableName); | ||
110 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
111 | { | ||
112 | command.Parameters.Add(database.CreateParameter("first", user)); | ||
113 | command.Parameters.Add(database.CreateParameter("second", last)); | ||
114 | try | ||
115 | { | ||
116 | using (SqlDataReader reader = command.ExecuteReader()) | ||
117 | { | ||
118 | return ReadUserRow(reader); | ||
119 | } | ||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | m_log.ErrorFormat("[USER DB] Error getting user profile for {0} {1}: {2}", user, last, e.Message); | ||
124 | return null; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// See IUserDataPlugin | ||
131 | /// </summary> | ||
132 | /// <param name="uuid"></param> | ||
133 | /// <returns></returns> | ||
134 | override public UserProfileData GetUserByUUID(UUID uuid) | ||
135 | { | ||
136 | string sql = string.Format("SELECT * FROM {0} WHERE UUID = @uuid", m_usersTableName); | ||
137 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
138 | { | ||
139 | command.Parameters.Add(database.CreateParameter("uuid", uuid)); | ||
140 | try | ||
141 | { | ||
142 | using (SqlDataReader reader = command.ExecuteReader()) | ||
143 | { | ||
144 | return ReadUserRow(reader); | ||
145 | } | ||
146 | } | ||
147 | catch (Exception e) | ||
148 | { | ||
149 | m_log.ErrorFormat("[USER DB] Error getting user profile by UUID {0}, error: {1}", uuid, e.Message); | ||
150 | return null; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | |||
155 | |||
156 | /// <summary> | ||
157 | /// Creates a new users profile | ||
158 | /// </summary> | ||
159 | /// <param name="user">The user profile to create</param> | ||
160 | override public void AddNewUserProfile(UserProfileData user) | ||
161 | { | ||
162 | try | ||
163 | { | ||
164 | InsertUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt, | ||
165 | user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y, | ||
166 | user.HomeLocation.Z, | ||
167 | user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created, | ||
168 | user.LastLogin, user.UserInventoryURI, user.UserAssetURI, | ||
169 | user.CanDoMask, user.WantDoMask, | ||
170 | user.AboutText, user.FirstLifeAboutText, user.Image, | ||
171 | user.FirstLifeImage, user.WebLoginKey, user.HomeRegionID, | ||
172 | user.GodLevel, user.UserFlags, user.CustomType, user.Partner); | ||
173 | } | ||
174 | catch (Exception e) | ||
175 | { | ||
176 | m_log.ErrorFormat("[USER DB] Error adding new profile, error: {0}", e.Message); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | /// <summary> | ||
181 | /// update a user profile | ||
182 | /// </summary> | ||
183 | /// <param name="user">the profile to update</param> | ||
184 | /// <returns></returns> | ||
185 | override public bool UpdateUserProfile(UserProfileData user) | ||
186 | { | ||
187 | string sql = string.Format(@"UPDATE {0} | ||
188 | SET UUID = @uuid, | ||
189 | username = @username, | ||
190 | lastname = @lastname, | ||
191 | email = @email, | ||
192 | passwordHash = @passwordHash, | ||
193 | passwordSalt = @passwordSalt, | ||
194 | homeRegion = @homeRegion, | ||
195 | homeLocationX = @homeLocationX, | ||
196 | homeLocationY = @homeLocationY, | ||
197 | homeLocationZ = @homeLocationZ, | ||
198 | homeLookAtX = @homeLookAtX, | ||
199 | homeLookAtY = @homeLookAtY, | ||
200 | homeLookAtZ = @homeLookAtZ, | ||
201 | created = @created, | ||
202 | lastLogin = @lastLogin, | ||
203 | userInventoryURI = @userInventoryURI, | ||
204 | userAssetURI = @userAssetURI, | ||
205 | profileCanDoMask = @profileCanDoMask, | ||
206 | profileWantDoMask = @profileWantDoMask, | ||
207 | profileAboutText = @profileAboutText, | ||
208 | profileFirstText = @profileFirstText, | ||
209 | profileImage = @profileImage, | ||
210 | profileFirstImage = @profileFirstImage, | ||
211 | webLoginKey = @webLoginKey, | ||
212 | homeRegionID = @homeRegionID, | ||
213 | userFlags = @userFlags, | ||
214 | godLevel = @godLevel, | ||
215 | customType = @customType, | ||
216 | partner = @partner WHERE UUID = @keyUUUID;",m_usersTableName); | ||
217 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
218 | { | ||
219 | command.Parameters.Add(database.CreateParameter("uuid", user.ID)); | ||
220 | command.Parameters.Add(database.CreateParameter("username", user.FirstName)); | ||
221 | command.Parameters.Add(database.CreateParameter("lastname", user.SurName)); | ||
222 | command.Parameters.Add(database.CreateParameter("email", user.Email)); | ||
223 | command.Parameters.Add(database.CreateParameter("passwordHash", user.PasswordHash)); | ||
224 | command.Parameters.Add(database.CreateParameter("passwordSalt", user.PasswordSalt)); | ||
225 | command.Parameters.Add(database.CreateParameter("homeRegion", user.HomeRegion)); | ||
226 | command.Parameters.Add(database.CreateParameter("homeLocationX", user.HomeLocation.X)); | ||
227 | command.Parameters.Add(database.CreateParameter("homeLocationY", user.HomeLocation.Y)); | ||
228 | command.Parameters.Add(database.CreateParameter("homeLocationZ", user.HomeLocation.Z)); | ||
229 | command.Parameters.Add(database.CreateParameter("homeLookAtX", user.HomeLookAt.X)); | ||
230 | command.Parameters.Add(database.CreateParameter("homeLookAtY", user.HomeLookAt.Y)); | ||
231 | command.Parameters.Add(database.CreateParameter("homeLookAtZ", user.HomeLookAt.Z)); | ||
232 | command.Parameters.Add(database.CreateParameter("created", user.Created)); | ||
233 | command.Parameters.Add(database.CreateParameter("lastLogin", user.LastLogin)); | ||
234 | command.Parameters.Add(database.CreateParameter("userInventoryURI", user.UserInventoryURI)); | ||
235 | command.Parameters.Add(database.CreateParameter("userAssetURI", user.UserAssetURI)); | ||
236 | command.Parameters.Add(database.CreateParameter("profileCanDoMask", user.CanDoMask)); | ||
237 | command.Parameters.Add(database.CreateParameter("profileWantDoMask", user.WantDoMask)); | ||
238 | command.Parameters.Add(database.CreateParameter("profileAboutText", user.AboutText)); | ||
239 | command.Parameters.Add(database.CreateParameter("profileFirstText", user.FirstLifeAboutText)); | ||
240 | command.Parameters.Add(database.CreateParameter("profileImage", user.Image)); | ||
241 | command.Parameters.Add(database.CreateParameter("profileFirstImage", user.FirstLifeImage)); | ||
242 | command.Parameters.Add(database.CreateParameter("webLoginKey", user.WebLoginKey)); | ||
243 | command.Parameters.Add(database.CreateParameter("homeRegionID", user.HomeRegionID)); | ||
244 | command.Parameters.Add(database.CreateParameter("userFlags", user.UserFlags)); | ||
245 | command.Parameters.Add(database.CreateParameter("godLevel", user.GodLevel)); | ||
246 | command.Parameters.Add(database.CreateParameter("customType", user.CustomType)); | ||
247 | command.Parameters.Add(database.CreateParameter("partner", user.Partner)); | ||
248 | command.Parameters.Add(database.CreateParameter("keyUUUID", user.ID)); | ||
249 | |||
250 | try | ||
251 | { | ||
252 | int affected = command.ExecuteNonQuery(); | ||
253 | return (affected != 0); | ||
254 | } | ||
255 | catch (Exception e) | ||
256 | { | ||
257 | m_log.ErrorFormat("[USER DB] Error updating profile, error: {0}", e.Message); | ||
258 | } | ||
259 | } | ||
260 | return false; | ||
261 | } | ||
262 | |||
263 | #endregion | ||
264 | |||
265 | #region Agent table methods | ||
266 | |||
267 | /// <summary> | ||
268 | /// Returns a user session searching by name | ||
269 | /// </summary> | ||
270 | /// <param name="name">The account name</param> | ||
271 | /// <returns>The users session</returns> | ||
272 | override public UserAgentData GetAgentByName(string name) | ||
273 | { | ||
274 | return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
275 | } | ||
276 | |||
277 | /// <summary> | ||
278 | /// Returns a user session by account name | ||
279 | /// </summary> | ||
280 | /// <param name="user">First part of the users account name</param> | ||
281 | /// <param name="last">Second part of the users account name</param> | ||
282 | /// <returns>The users session</returns> | ||
283 | override public UserAgentData GetAgentByName(string user, string last) | ||
284 | { | ||
285 | UserProfileData profile = GetUserByName(user, last); | ||
286 | return GetAgentByUUID(profile.ID); | ||
287 | } | ||
288 | |||
289 | /// <summary> | ||
290 | /// Returns an agent session by account UUID | ||
291 | /// </summary> | ||
292 | /// <param name="uuid">The accounts UUID</param> | ||
293 | /// <returns>The users session</returns> | ||
294 | override public UserAgentData GetAgentByUUID(UUID uuid) | ||
295 | { | ||
296 | string sql = string.Format("SELECT * FROM {0} WHERE UUID = @uuid", m_agentsTableName); | ||
297 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
298 | { | ||
299 | command.Parameters.Add(database.CreateParameter("uuid", uuid)); | ||
300 | try | ||
301 | { | ||
302 | using (SqlDataReader reader = command.ExecuteReader()) | ||
303 | { | ||
304 | return readAgentRow(reader); | ||
305 | } | ||
306 | } | ||
307 | catch (Exception e) | ||
308 | { | ||
309 | m_log.ErrorFormat("[USER DB] Error updating agentdata by UUID, error: {0}", e.Message); | ||
310 | return null; | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | |||
315 | /// <summary> | ||
316 | /// Creates a new agent | ||
317 | /// </summary> | ||
318 | /// <param name="agent">The agent to create</param> | ||
319 | override public void AddNewUserAgent(UserAgentData agent) | ||
320 | { | ||
321 | try | ||
322 | { | ||
323 | InsertUpdateAgentRow(agent); | ||
324 | } | ||
325 | catch (Exception e) | ||
326 | { | ||
327 | m_log.ErrorFormat("[USER DB] Error adding new agentdata, error: {0}", e.Message); | ||
328 | } | ||
329 | } | ||
330 | |||
331 | #endregion | ||
332 | |||
333 | #region User Friends List Data | ||
334 | |||
335 | /// <summary> | ||
336 | /// Add a new friend in the friendlist | ||
337 | /// </summary> | ||
338 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
339 | /// <param name="friend">Friend's UUID</param> | ||
340 | /// <param name="perms">Permission flag</param> | ||
341 | override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
342 | { | ||
343 | int dtvalue = Util.UnixTimeSinceEpoch(); | ||
344 | string sql = string.Format(@"INSERT INTO {0} | ||
345 | (ownerID,friendID,friendPerms,datetimestamp) | ||
346 | VALUES | ||
347 | (@ownerID,@friendID,@friendPerms,@datetimestamp)", m_userFriendsTableName); | ||
348 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
349 | { | ||
350 | command.Parameters.Add(database.CreateParameter("ownerID", friendlistowner)); | ||
351 | command.Parameters.Add(database.CreateParameter("friendID", friend)); | ||
352 | command.Parameters.Add(database.CreateParameter("friendPerms", perms)); | ||
353 | command.Parameters.Add(database.CreateParameter("datetimestamp", dtvalue)); | ||
354 | command.ExecuteNonQuery(); | ||
355 | |||
356 | try | ||
357 | { | ||
358 | sql = string.Format(@"INSERT INTO {0} | ||
359 | (ownerID,friendID,friendPerms,datetimestamp) | ||
360 | VALUES | ||
361 | (@friendID,@ownerID,@friendPerms,@datetimestamp)", m_userFriendsTableName); | ||
362 | command.CommandText = sql; | ||
363 | command.ExecuteNonQuery(); | ||
364 | } | ||
365 | catch (Exception e) | ||
366 | { | ||
367 | m_log.ErrorFormat("[USER DB] Error adding new userfriend, error: {0}", e.Message); | ||
368 | return; | ||
369 | } | ||
370 | } | ||
371 | } | ||
372 | |||
373 | /// <summary> | ||
374 | /// Remove an friend from the friendlist | ||
375 | /// </summary> | ||
376 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
377 | /// <param name="friend">UUID of the not-so-friendly user to remove from the list</param> | ||
378 | override public void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
379 | { | ||
380 | string sql = string.Format(@"DELETE from {0} | ||
381 | WHERE ownerID = @ownerID | ||
382 | AND friendID = @friendID", m_userFriendsTableName); | ||
383 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
384 | { | ||
385 | command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); | ||
386 | command.Parameters.Add(database.CreateParameter("@friendID", friend)); | ||
387 | command.ExecuteNonQuery(); | ||
388 | sql = string.Format(@"DELETE from {0} | ||
389 | WHERE ownerID = @friendID | ||
390 | AND friendID = @ownerID", m_userFriendsTableName); | ||
391 | command.CommandText = sql; | ||
392 | try | ||
393 | { | ||
394 | command.ExecuteNonQuery(); | ||
395 | } | ||
396 | catch (Exception e) | ||
397 | { | ||
398 | m_log.ErrorFormat("[USER DB] Error removing userfriend, error: {0}", e.Message); | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | |||
403 | /// <summary> | ||
404 | /// Update friendlist permission flag for a friend | ||
405 | /// </summary> | ||
406 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
407 | /// <param name="friend">UUID of the friend</param> | ||
408 | /// <param name="perms">new permission flag</param> | ||
409 | override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
410 | { | ||
411 | string sql = string.Format(@"UPDATE {0} SET friendPerms = @friendPerms | ||
412 | WHERE ownerID = @ownerID | ||
413 | AND friendID = @friendID", m_userFriendsTableName); | ||
414 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
415 | { | ||
416 | command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); | ||
417 | command.Parameters.Add(database.CreateParameter("@friendID", friend)); | ||
418 | command.Parameters.Add(database.CreateParameter("@friendPerms", perms)); | ||
419 | |||
420 | try | ||
421 | { | ||
422 | command.ExecuteNonQuery(); | ||
423 | } | ||
424 | catch (Exception e) | ||
425 | { | ||
426 | m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message); | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | |||
431 | /// <summary> | ||
432 | /// Get (fetch?) the user's friendlist | ||
433 | /// </summary> | ||
434 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
435 | /// <returns>Friendlist list</returns> | ||
436 | override public List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
437 | { | ||
438 | List<FriendListItem> friendList = new List<FriendListItem>(); | ||
439 | |||
440 | //Left Join userfriends to itself | ||
441 | string sql = string.Format(@"SELECT a.ownerID, a.friendID, a.friendPerms, b.friendPerms AS ownerperms | ||
442 | FROM {0} as a, {0} as b | ||
443 | WHERE a.ownerID = @ownerID | ||
444 | AND b.ownerID = a.friendID | ||
445 | AND b.friendID = a.ownerID", m_userFriendsTableName); | ||
446 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
447 | { | ||
448 | command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner)); | ||
449 | try | ||
450 | { | ||
451 | using (SqlDataReader reader = command.ExecuteReader()) | ||
452 | { | ||
453 | while (reader.Read()) | ||
454 | { | ||
455 | FriendListItem fli = new FriendListItem(); | ||
456 | fli.FriendListOwner = new UUID((Guid)reader["ownerID"]); | ||
457 | fli.Friend = new UUID((Guid)reader["friendID"]); | ||
458 | fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]); | ||
459 | |||
460 | // This is not a real column in the database table, it's a joined column from the opposite record | ||
461 | fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); | ||
462 | friendList.Add(fli); | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | catch (Exception e) | ||
467 | { | ||
468 | m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message); | ||
469 | } | ||
470 | } | ||
471 | return friendList; | ||
472 | } | ||
473 | |||
474 | override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids) | ||
475 | { | ||
476 | Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>(); | ||
477 | try | ||
478 | { | ||
479 | foreach (UUID uuid in uuids) | ||
480 | { | ||
481 | string sql = string.Format(@"SELECT agentOnline,currentHandle | ||
482 | FROM {0} WHERE UUID = @uuid", m_agentsTableName); | ||
483 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
484 | { | ||
485 | command.Parameters.Add(database.CreateParameter("@uuid", uuid)); | ||
486 | using (SqlDataReader reader = command.ExecuteReader()) | ||
487 | { | ||
488 | while (reader.Read()) | ||
489 | { | ||
490 | FriendRegionInfo fri = new FriendRegionInfo(); | ||
491 | fri.isOnline = (byte)reader["agentOnline"] != 0; | ||
492 | fri.regionHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||
493 | |||
494 | infos[uuid] = fri; | ||
495 | } | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | } | ||
500 | catch (Exception e) | ||
501 | { | ||
502 | m_log.Warn("[MSSQL]: Got exception on trying to find friends regions:", e); | ||
503 | } | ||
504 | |||
505 | return infos; | ||
506 | } | ||
507 | #endregion | ||
508 | |||
509 | #region Money functions (not used) | ||
510 | |||
511 | /// <summary> | ||
512 | /// Performs a money transfer request between two accounts | ||
513 | /// </summary> | ||
514 | /// <param name="from">The senders account ID</param> | ||
515 | /// <param name="to">The receivers account ID</param> | ||
516 | /// <param name="amount">The amount to transfer</param> | ||
517 | /// <returns>false</returns> | ||
518 | override public bool MoneyTransferRequest(UUID from, UUID to, uint amount) | ||
519 | { | ||
520 | return false; | ||
521 | } | ||
522 | |||
523 | /// <summary> | ||
524 | /// Performs an inventory transfer request between two accounts | ||
525 | /// </summary> | ||
526 | /// <remarks>TODO: Move to inventory server</remarks> | ||
527 | /// <param name="from">The senders account ID</param> | ||
528 | /// <param name="to">The receivers account ID</param> | ||
529 | /// <param name="item">The item to transfer</param> | ||
530 | /// <returns>false</returns> | ||
531 | override public bool InventoryTransferRequest(UUID from, UUID to, UUID item) | ||
532 | { | ||
533 | return false; | ||
534 | } | ||
535 | |||
536 | #endregion | ||
537 | |||
538 | #region Appearance methods | ||
539 | |||
540 | /// <summary> | ||
541 | /// Gets the user appearance. | ||
542 | /// </summary> | ||
543 | /// <param name="user">The user.</param> | ||
544 | /// <returns></returns> | ||
545 | override public AvatarAppearance GetUserAppearance(UUID user) | ||
546 | { | ||
547 | try | ||
548 | { | ||
549 | AvatarAppearance appearance = new AvatarAppearance(); | ||
550 | string sql = "SELECT * FROM avatarappearance WHERE owner = @UUID"; | ||
551 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
552 | { | ||
553 | command.Parameters.Add(database.CreateParameter("@UUID", user)); | ||
554 | using (SqlDataReader reader = command.ExecuteReader()) | ||
555 | { | ||
556 | if (reader.Read()) | ||
557 | appearance = readUserAppearance(reader); | ||
558 | else | ||
559 | { | ||
560 | m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString()); | ||
561 | return null; | ||
562 | } | ||
563 | |||
564 | } | ||
565 | } | ||
566 | |||
567 | appearance.SetAttachments(GetUserAttachments(user)); | ||
568 | |||
569 | return appearance; | ||
570 | } | ||
571 | catch (Exception e) | ||
572 | { | ||
573 | m_log.ErrorFormat("[USER DB] Error updating userfriend, error: {0}", e.Message); | ||
574 | } | ||
575 | return null; | ||
576 | } | ||
577 | |||
578 | /// <summary> | ||
579 | /// Update a user appearence into database | ||
580 | /// </summary> | ||
581 | /// <param name="user">the used UUID</param> | ||
582 | /// <param name="appearance">the appearence</param> | ||
583 | override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) | ||
584 | { | ||
585 | string sql = @"DELETE FROM avatarappearance WHERE owner=@owner; | ||
586 | INSERT INTO avatarappearance | ||
587 | (owner, serial, visual_params, texture, avatar_height, | ||
588 | body_item, body_asset, skin_item, skin_asset, hair_item, | ||
589 | hair_asset, eyes_item, eyes_asset, shirt_item, shirt_asset, | ||
590 | pants_item, pants_asset, shoes_item, shoes_asset, socks_item, | ||
591 | socks_asset, jacket_item, jacket_asset, gloves_item, gloves_asset, | ||
592 | undershirt_item, undershirt_asset, underpants_item, underpants_asset, | ||
593 | skirt_item, skirt_asset) | ||
594 | VALUES | ||
595 | (@owner, @serial, @visual_params, @texture, @avatar_height, | ||
596 | @body_item, @body_asset, @skin_item, @skin_asset, @hair_item, | ||
597 | @hair_asset, @eyes_item, @eyes_asset, @shirt_item, @shirt_asset, | ||
598 | @pants_item, @pants_asset, @shoes_item, @shoes_asset, @socks_item, | ||
599 | @socks_asset, @jacket_item, @jacket_asset, @gloves_item, @gloves_asset, | ||
600 | @undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset, | ||
601 | @skirt_item, @skirt_asset)"; | ||
602 | |||
603 | using (AutoClosingSqlCommand cmd = database.Query(sql)) | ||
604 | { | ||
605 | cmd.Parameters.Add(database.CreateParameter("@owner", appearance.Owner)); | ||
606 | cmd.Parameters.Add(database.CreateParameter("@serial", appearance.Serial)); | ||
607 | cmd.Parameters.Add(database.CreateParameter("@visual_params", appearance.VisualParams)); | ||
608 | cmd.Parameters.Add(database.CreateParameter("@texture", appearance.Texture.GetBytes())); | ||
609 | cmd.Parameters.Add(database.CreateParameter("@avatar_height", appearance.AvatarHeight)); | ||
610 | cmd.Parameters.Add(database.CreateParameter("@body_item", appearance.BodyItem)); | ||
611 | cmd.Parameters.Add(database.CreateParameter("@body_asset", appearance.BodyAsset)); | ||
612 | cmd.Parameters.Add(database.CreateParameter("@skin_item", appearance.SkinItem)); | ||
613 | cmd.Parameters.Add(database.CreateParameter("@skin_asset", appearance.SkinAsset)); | ||
614 | cmd.Parameters.Add(database.CreateParameter("@hair_item", appearance.HairItem)); | ||
615 | cmd.Parameters.Add(database.CreateParameter("@hair_asset", appearance.HairAsset)); | ||
616 | cmd.Parameters.Add(database.CreateParameter("@eyes_item", appearance.EyesItem)); | ||
617 | cmd.Parameters.Add(database.CreateParameter("@eyes_asset", appearance.EyesAsset)); | ||
618 | cmd.Parameters.Add(database.CreateParameter("@shirt_item", appearance.ShirtItem)); | ||
619 | cmd.Parameters.Add(database.CreateParameter("@shirt_asset", appearance.ShirtAsset)); | ||
620 | cmd.Parameters.Add(database.CreateParameter("@pants_item", appearance.PantsItem)); | ||
621 | cmd.Parameters.Add(database.CreateParameter("@pants_asset", appearance.PantsAsset)); | ||
622 | cmd.Parameters.Add(database.CreateParameter("@shoes_item", appearance.ShoesItem)); | ||
623 | cmd.Parameters.Add(database.CreateParameter("@shoes_asset", appearance.ShoesAsset)); | ||
624 | cmd.Parameters.Add(database.CreateParameter("@socks_item", appearance.SocksItem)); | ||
625 | cmd.Parameters.Add(database.CreateParameter("@socks_asset", appearance.SocksAsset)); | ||
626 | cmd.Parameters.Add(database.CreateParameter("@jacket_item", appearance.JacketItem)); | ||
627 | cmd.Parameters.Add(database.CreateParameter("@jacket_asset", appearance.JacketAsset)); | ||
628 | cmd.Parameters.Add(database.CreateParameter("@gloves_item", appearance.GlovesItem)); | ||
629 | cmd.Parameters.Add(database.CreateParameter("@gloves_asset", appearance.GlovesAsset)); | ||
630 | cmd.Parameters.Add(database.CreateParameter("@undershirt_item", appearance.UnderShirtItem)); | ||
631 | cmd.Parameters.Add(database.CreateParameter("@undershirt_asset", appearance.UnderShirtAsset)); | ||
632 | cmd.Parameters.Add(database.CreateParameter("@underpants_item", appearance.UnderPantsItem)); | ||
633 | cmd.Parameters.Add(database.CreateParameter("@underpants_asset", appearance.UnderPantsAsset)); | ||
634 | cmd.Parameters.Add(database.CreateParameter("@skirt_item", appearance.SkirtItem)); | ||
635 | cmd.Parameters.Add(database.CreateParameter("@skirt_asset", appearance.SkirtAsset)); | ||
636 | |||
637 | try | ||
638 | { | ||
639 | cmd.ExecuteNonQuery(); | ||
640 | } | ||
641 | catch (Exception e) | ||
642 | { | ||
643 | m_log.ErrorFormat("[USER DB] Error updating user appearance, error: {0}", e.Message); | ||
644 | } | ||
645 | } | ||
646 | UpdateUserAttachments(user, appearance.GetAttachments()); | ||
647 | } | ||
648 | |||
649 | #endregion | ||
650 | |||
651 | #region Attachment methods | ||
652 | |||
653 | /// <summary> | ||
654 | /// Gets all attachment of a agent. | ||
655 | /// </summary> | ||
656 | /// <param name="agentID">agent ID.</param> | ||
657 | /// <returns></returns> | ||
658 | public Hashtable GetUserAttachments(UUID agentID) | ||
659 | { | ||
660 | Hashtable returnTable = new Hashtable(); | ||
661 | string sql = "select attachpoint, item, asset from avatarattachments where UUID = @uuid"; | ||
662 | using (AutoClosingSqlCommand command = database.Query(sql, database.CreateParameter("@uuid", agentID))) | ||
663 | { | ||
664 | using (SqlDataReader reader = command.ExecuteReader()) | ||
665 | { | ||
666 | while (reader.Read()) | ||
667 | { | ||
668 | int attachpoint = Convert.ToInt32(reader["attachpoint"]); | ||
669 | if (returnTable.ContainsKey(attachpoint)) | ||
670 | continue; | ||
671 | Hashtable item = new Hashtable(); | ||
672 | item.Add("item", reader["item"].ToString()); | ||
673 | item.Add("asset", reader["asset"].ToString()); | ||
674 | |||
675 | returnTable.Add(attachpoint, item); | ||
676 | } | ||
677 | } | ||
678 | } | ||
679 | return returnTable; | ||
680 | } | ||
681 | |||
682 | /// <summary> | ||
683 | /// Updates all attachments of the agent. | ||
684 | /// </summary> | ||
685 | /// <param name="agentID">agentID.</param> | ||
686 | /// <param name="data">data with all items on attachmentpoints</param> | ||
687 | public void UpdateUserAttachments(UUID agentID, Hashtable data) | ||
688 | { | ||
689 | string sql = "DELETE FROM avatarattachments WHERE UUID = @uuid"; | ||
690 | |||
691 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
692 | { | ||
693 | command.Parameters.Add(database.CreateParameter("uuid", agentID)); | ||
694 | command.ExecuteNonQuery(); | ||
695 | } | ||
696 | if (data == null) | ||
697 | return; | ||
698 | |||
699 | sql = @"INSERT INTO avatarattachments (UUID, attachpoint, item, asset) | ||
700 | VALUES (@uuid, @attachpoint, @item, @asset)"; | ||
701 | |||
702 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
703 | { | ||
704 | bool firstTime = true; | ||
705 | foreach (DictionaryEntry e in data) | ||
706 | { | ||
707 | int attachpoint = Convert.ToInt32(e.Key); | ||
708 | |||
709 | Hashtable item = (Hashtable)e.Value; | ||
710 | |||
711 | if (firstTime) | ||
712 | { | ||
713 | command.Parameters.Add(database.CreateParameter("@uuid", agentID)); | ||
714 | command.Parameters.Add(database.CreateParameter("@attachpoint", attachpoint)); | ||
715 | command.Parameters.Add(database.CreateParameter("@item", new UUID(item["item"].ToString()))); | ||
716 | command.Parameters.Add(database.CreateParameter("@asset", new UUID(item["asset"].ToString()))); | ||
717 | firstTime = false; | ||
718 | } | ||
719 | command.Parameters["@uuid"].Value = agentID.Guid; //.ToString(); | ||
720 | command.Parameters["@attachpoint"].Value = attachpoint; | ||
721 | command.Parameters["@item"].Value = new Guid(item["item"].ToString()); | ||
722 | command.Parameters["@asset"].Value = new Guid(item["asset"].ToString()); | ||
723 | |||
724 | try | ||
725 | { | ||
726 | command.ExecuteNonQuery(); | ||
727 | } | ||
728 | catch (Exception ex) | ||
729 | { | ||
730 | m_log.DebugFormat("[USER DB] : Error adding user attachment. {0}", ex.Message); | ||
731 | } | ||
732 | } | ||
733 | } | ||
734 | } | ||
735 | |||
736 | /// <summary> | ||
737 | /// Resets all attachments of a agent in the database. | ||
738 | /// </summary> | ||
739 | /// <param name="agentID">agentID.</param> | ||
740 | override public void ResetAttachments(UUID agentID) | ||
741 | { | ||
742 | string sql = "UPDATE avatarattachments SET asset = '00000000-0000-0000-0000-000000000000' WHERE UUID = @uuid"; | ||
743 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
744 | { | ||
745 | command.Parameters.Add(database.CreateParameter("uuid", agentID)); | ||
746 | command.ExecuteNonQuery(); | ||
747 | } | ||
748 | } | ||
749 | |||
750 | override public void LogoutUsers(UUID regionID) | ||
751 | { | ||
752 | } | ||
753 | |||
754 | #endregion | ||
755 | |||
756 | #region Other public methods | ||
757 | |||
758 | /// <summary> | ||
759 | /// | ||
760 | /// </summary> | ||
761 | /// <param name="queryID"></param> | ||
762 | /// <param name="query"></param> | ||
763 | /// <returns></returns> | ||
764 | override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) | ||
765 | { | ||
766 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
767 | string[] querysplit = query.Split(' '); | ||
768 | if (querysplit.Length == 2) | ||
769 | { | ||
770 | try | ||
771 | { | ||
772 | string sql = string.Format(@"SELECT UUID,username,lastname FROM {0} | ||
773 | WHERE username LIKE @first AND lastname LIKE @second", m_usersTableName); | ||
774 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
775 | { | ||
776 | //Add wildcard to the search | ||
777 | command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%")); | ||
778 | command.Parameters.Add(database.CreateParameter("second", querysplit[1] + "%")); | ||
779 | using (SqlDataReader reader = command.ExecuteReader()) | ||
780 | { | ||
781 | while (reader.Read()) | ||
782 | { | ||
783 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
784 | user.AvatarID = new UUID((Guid)reader["UUID"]); | ||
785 | user.firstName = (string)reader["username"]; | ||
786 | user.lastName = (string)reader["lastname"]; | ||
787 | returnlist.Add(user); | ||
788 | } | ||
789 | } | ||
790 | } | ||
791 | } | ||
792 | catch (Exception e) | ||
793 | { | ||
794 | m_log.Error(e.ToString()); | ||
795 | } | ||
796 | } | ||
797 | else if (querysplit.Length == 1) | ||
798 | { | ||
799 | try | ||
800 | { | ||
801 | string sql = string.Format(@"SELECT UUID,username,lastname FROM {0} | ||
802 | WHERE username LIKE @first OR lastname LIKE @first", m_usersTableName); | ||
803 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
804 | { | ||
805 | command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%")); | ||
806 | |||
807 | using (SqlDataReader reader = command.ExecuteReader()) | ||
808 | { | ||
809 | while (reader.Read()) | ||
810 | { | ||
811 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
812 | user.AvatarID = new UUID((Guid)reader["UUID"]); | ||
813 | user.firstName = (string)reader["username"]; | ||
814 | user.lastName = (string)reader["lastname"]; | ||
815 | returnlist.Add(user); | ||
816 | } | ||
817 | } | ||
818 | } | ||
819 | } | ||
820 | catch (Exception e) | ||
821 | { | ||
822 | m_log.Error(e.ToString()); | ||
823 | } | ||
824 | } | ||
825 | return returnlist; | ||
826 | } | ||
827 | |||
828 | /// <summary> | ||
829 | /// Store a weblogin key | ||
830 | /// </summary> | ||
831 | /// <param name="AgentID">The agent UUID</param> | ||
832 | /// <param name="WebLoginKey">the WebLogin Key</param> | ||
833 | /// <remarks>unused ?</remarks> | ||
834 | override public void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey) | ||
835 | { | ||
836 | UserProfileData user = GetUserByUUID(AgentID); | ||
837 | user.WebLoginKey = WebLoginKey; | ||
838 | UpdateUserProfile(user); | ||
839 | } | ||
840 | |||
841 | /// <summary> | ||
842 | /// Database provider name | ||
843 | /// </summary> | ||
844 | /// <returns>Provider name</returns> | ||
845 | override public string Name | ||
846 | { | ||
847 | get { return "MSSQL Userdata Interface"; } | ||
848 | } | ||
849 | |||
850 | /// <summary> | ||
851 | /// Database provider version | ||
852 | /// </summary> | ||
853 | /// <returns>provider version</returns> | ||
854 | override public string Version | ||
855 | { | ||
856 | get { return database.getVersion(); } | ||
857 | } | ||
858 | |||
859 | #endregion | ||
860 | |||
861 | #region Private functions | ||
862 | |||
863 | /// <summary> | ||
864 | /// Reads a one item from an SQL result | ||
865 | /// </summary> | ||
866 | /// <param name="reader">The SQL Result</param> | ||
867 | /// <returns>the item read</returns> | ||
868 | private static AvatarAppearance readUserAppearance(SqlDataReader reader) | ||
869 | { | ||
870 | try | ||
871 | { | ||
872 | AvatarAppearance appearance = new AvatarAppearance(); | ||
873 | |||
874 | appearance.Owner = new UUID((Guid)reader["owner"]); | ||
875 | appearance.Serial = Convert.ToInt32(reader["serial"]); | ||
876 | appearance.VisualParams = (byte[])reader["visual_params"]; | ||
877 | appearance.Texture = new Primitive.TextureEntry((byte[])reader["texture"], 0, ((byte[])reader["texture"]).Length); | ||
878 | appearance.AvatarHeight = (float)Convert.ToDouble(reader["avatar_height"]); | ||
879 | appearance.BodyItem = new UUID((Guid)reader["body_item"]); | ||
880 | appearance.BodyAsset = new UUID((Guid)reader["body_asset"]); | ||
881 | appearance.SkinItem = new UUID((Guid)reader["skin_item"]); | ||
882 | appearance.SkinAsset = new UUID((Guid)reader["skin_asset"]); | ||
883 | appearance.HairItem = new UUID((Guid)reader["hair_item"]); | ||
884 | appearance.HairAsset = new UUID((Guid)reader["hair_asset"]); | ||
885 | appearance.EyesItem = new UUID((Guid)reader["eyes_item"]); | ||
886 | appearance.EyesAsset = new UUID((Guid)reader["eyes_asset"]); | ||
887 | appearance.ShirtItem = new UUID((Guid)reader["shirt_item"]); | ||
888 | appearance.ShirtAsset = new UUID((Guid)reader["shirt_asset"]); | ||
889 | appearance.PantsItem = new UUID((Guid)reader["pants_item"]); | ||
890 | appearance.PantsAsset = new UUID((Guid)reader["pants_asset"]); | ||
891 | appearance.ShoesItem = new UUID((Guid)reader["shoes_item"]); | ||
892 | appearance.ShoesAsset = new UUID((Guid)reader["shoes_asset"]); | ||
893 | appearance.SocksItem = new UUID((Guid)reader["socks_item"]); | ||
894 | appearance.SocksAsset = new UUID((Guid)reader["socks_asset"]); | ||
895 | appearance.JacketItem = new UUID((Guid)reader["jacket_item"]); | ||
896 | appearance.JacketAsset = new UUID((Guid)reader["jacket_asset"]); | ||
897 | appearance.GlovesItem = new UUID((Guid)reader["gloves_item"]); | ||
898 | appearance.GlovesAsset = new UUID((Guid)reader["gloves_asset"]); | ||
899 | appearance.UnderShirtItem = new UUID((Guid)reader["undershirt_item"]); | ||
900 | appearance.UnderShirtAsset = new UUID((Guid)reader["undershirt_asset"]); | ||
901 | appearance.UnderPantsItem = new UUID((Guid)reader["underpants_item"]); | ||
902 | appearance.UnderPantsAsset = new UUID((Guid)reader["underpants_asset"]); | ||
903 | appearance.SkirtItem = new UUID((Guid)reader["skirt_item"]); | ||
904 | appearance.SkirtAsset = new UUID((Guid)reader["skirt_asset"]); | ||
905 | |||
906 | return appearance; | ||
907 | } | ||
908 | catch (SqlException e) | ||
909 | { | ||
910 | m_log.Error(e.ToString()); | ||
911 | } | ||
912 | |||
913 | return null; | ||
914 | } | ||
915 | |||
916 | /// <summary> | ||
917 | /// Insert/Update a agent row in the DB. | ||
918 | /// </summary> | ||
919 | /// <param name="agentdata">agentdata.</param> | ||
920 | private void InsertUpdateAgentRow(UserAgentData agentdata) | ||
921 | { | ||
922 | string sql = @" | ||
923 | |||
924 | IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID) | ||
925 | BEGIN | ||
926 | UPDATE agents SET UUID = @UUID, sessionID = @sessionID, secureSessionID = @secureSessionID, agentIP = @agentIP, agentPort = @agentPort, agentOnline = @agentOnline, loginTime = @loginTime, logoutTime = @logoutTime, currentRegion = @currentRegion, currentHandle = @currentHandle, currentPos = @currentPos | ||
927 | WHERE UUID = @UUID | ||
928 | END | ||
929 | ELSE | ||
930 | BEGIN | ||
931 | INSERT INTO | ||
932 | agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES | ||
933 | (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos) | ||
934 | END | ||
935 | "; | ||
936 | |||
937 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
938 | { | ||
939 | command.Parameters.Add(database.CreateParameter("@UUID", agentdata.ProfileID)); | ||
940 | command.Parameters.Add(database.CreateParameter("@sessionID", agentdata.SessionID)); | ||
941 | command.Parameters.Add(database.CreateParameter("@secureSessionID", agentdata.SecureSessionID)); | ||
942 | command.Parameters.Add(database.CreateParameter("@agentIP", agentdata.AgentIP)); | ||
943 | command.Parameters.Add(database.CreateParameter("@agentPort", agentdata.AgentPort)); | ||
944 | command.Parameters.Add(database.CreateParameter("@agentOnline", agentdata.AgentOnline)); | ||
945 | command.Parameters.Add(database.CreateParameter("@loginTime", agentdata.LoginTime)); | ||
946 | command.Parameters.Add(database.CreateParameter("@logoutTime", agentdata.LogoutTime)); | ||
947 | command.Parameters.Add(database.CreateParameter("@currentRegion", agentdata.Region)); | ||
948 | command.Parameters.Add(database.CreateParameter("@currentHandle", agentdata.Handle)); | ||
949 | command.Parameters.Add(database.CreateParameter("@currentPos", "<" + ((int)agentdata.Position.X) + "," + ((int)agentdata.Position.Y) + "," + ((int)agentdata.Position.Z) + ">")); | ||
950 | |||
951 | command.Transaction = command.Connection.BeginTransaction(IsolationLevel.Serializable); | ||
952 | try | ||
953 | { | ||
954 | if (command.ExecuteNonQuery() > 0) | ||
955 | { | ||
956 | command.Transaction.Commit(); | ||
957 | return; | ||
958 | } | ||
959 | |||
960 | command.Transaction.Rollback(); | ||
961 | return; | ||
962 | } | ||
963 | catch (Exception e) | ||
964 | { | ||
965 | command.Transaction.Rollback(); | ||
966 | m_log.Error(e.ToString()); | ||
967 | return; | ||
968 | } | ||
969 | } | ||
970 | |||
971 | } | ||
972 | |||
973 | /// <summary> | ||
974 | /// Reads an agent row from a database reader | ||
975 | /// </summary> | ||
976 | /// <param name="reader">An active database reader</param> | ||
977 | /// <returns>A user session agent</returns> | ||
978 | private UserAgentData readAgentRow(SqlDataReader reader) | ||
979 | { | ||
980 | UserAgentData retval = new UserAgentData(); | ||
981 | |||
982 | if (reader.Read()) | ||
983 | { | ||
984 | // Agent IDs | ||
985 | retval.ProfileID = new UUID((Guid)reader["UUID"]); | ||
986 | retval.SessionID = new UUID((Guid)reader["sessionID"]); | ||
987 | retval.SecureSessionID = new UUID((Guid)reader["secureSessionID"]); | ||
988 | |||
989 | // Agent Who? | ||
990 | retval.AgentIP = (string)reader["agentIP"]; | ||
991 | retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString()); | ||
992 | retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0; | ||
993 | |||
994 | // Login/Logout times (UNIX Epoch) | ||
995 | retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString()); | ||
996 | retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); | ||
997 | |||
998 | // Current position | ||
999 | retval.Region = new UUID((Guid)reader["currentRegion"]); | ||
1000 | retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||
1001 | Vector3 tmp_v; | ||
1002 | Vector3.TryParse((string)reader["currentPos"], out tmp_v); | ||
1003 | retval.Position = tmp_v; | ||
1004 | |||
1005 | } | ||
1006 | else | ||
1007 | { | ||
1008 | return null; | ||
1009 | } | ||
1010 | return retval; | ||
1011 | } | ||
1012 | |||
1013 | /// <summary> | ||
1014 | /// Creates a new user and inserts it into the database | ||
1015 | /// </summary> | ||
1016 | /// <param name="uuid">User ID</param> | ||
1017 | /// <param name="username">First part of the login</param> | ||
1018 | /// <param name="lastname">Second part of the login</param> | ||
1019 | /// <param name="email">Email of person</param> | ||
1020 | /// <param name="passwordHash">A salted hash of the users password</param> | ||
1021 | /// <param name="passwordSalt">The salt used for the password hash</param> | ||
1022 | /// <param name="homeRegion">A regionHandle of the users home region</param> | ||
1023 | /// <param name="homeLocX">Home region position vector</param> | ||
1024 | /// <param name="homeLocY">Home region position vector</param> | ||
1025 | /// <param name="homeLocZ">Home region position vector</param> | ||
1026 | /// <param name="homeLookAtX">Home region 'look at' vector</param> | ||
1027 | /// <param name="homeLookAtY">Home region 'look at' vector</param> | ||
1028 | /// <param name="homeLookAtZ">Home region 'look at' vector</param> | ||
1029 | /// <param name="created">Account created (unix timestamp)</param> | ||
1030 | /// <param name="lastlogin">Last login (unix timestamp)</param> | ||
1031 | /// <param name="inventoryURI">Users inventory URI</param> | ||
1032 | /// <param name="assetURI">Users asset URI</param> | ||
1033 | /// <param name="canDoMask">I can do mask</param> | ||
1034 | /// <param name="wantDoMask">I want to do mask</param> | ||
1035 | /// <param name="aboutText">Profile text</param> | ||
1036 | /// <param name="firstText">Firstlife text</param> | ||
1037 | /// <param name="profileImage">UUID for profile image</param> | ||
1038 | /// <param name="firstImage">UUID for firstlife image</param> | ||
1039 | /// <param name="webLoginKey">web login key</param> | ||
1040 | /// <param name="homeRegionID">homeregion UUID</param> | ||
1041 | /// <param name="godLevel">has the user godlevel</param> | ||
1042 | /// <param name="userFlags">unknown</param> | ||
1043 | /// <param name="customType">unknown</param> | ||
1044 | /// <param name="partnerID">UUID of partner</param> | ||
1045 | /// <returns>Success?</returns> | ||
1046 | private void InsertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash, | ||
1047 | string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ, | ||
1048 | float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, | ||
1049 | string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, | ||
1050 | string aboutText, string firstText, | ||
1051 | UUID profileImage, UUID firstImage, UUID webLoginKey, UUID homeRegionID, | ||
1052 | int godLevel, int userFlags, string customType, UUID partnerID) | ||
1053 | { | ||
1054 | string sql = string.Format(@"INSERT INTO {0} | ||
1055 | ([UUID], [username], [lastname], [email], [passwordHash], [passwordSalt], | ||
1056 | [homeRegion], [homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], | ||
1057 | [homeLookAtY], [homeLookAtZ], [created], [lastLogin], [userInventoryURI], | ||
1058 | [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], | ||
1059 | [profileFirstText], [profileImage], [profileFirstImage], [webLoginKey], | ||
1060 | [homeRegionID], [userFlags], [godLevel], [customType], [partner]) | ||
1061 | VALUES | ||
1062 | (@UUID, @username, @lastname, @email, @passwordHash, @passwordSalt, | ||
1063 | @homeRegion, @homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, | ||
1064 | @homeLookAtY, @homeLookAtZ, @created, @lastLogin, @userInventoryURI, | ||
1065 | @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, | ||
1066 | @profileFirstText, @profileImage, @profileFirstImage, @webLoginKey, | ||
1067 | @homeRegionID, @userFlags, @godLevel, @customType, @partner)", m_usersTableName); | ||
1068 | |||
1069 | try | ||
1070 | { | ||
1071 | using (AutoClosingSqlCommand command = database.Query(sql)) | ||
1072 | { | ||
1073 | command.Parameters.Add(database.CreateParameter("UUID", uuid)); | ||
1074 | command.Parameters.Add(database.CreateParameter("username", username)); | ||
1075 | command.Parameters.Add(database.CreateParameter("lastname", lastname)); | ||
1076 | command.Parameters.Add(database.CreateParameter("email", email)); | ||
1077 | command.Parameters.Add(database.CreateParameter("passwordHash", passwordHash)); | ||
1078 | command.Parameters.Add(database.CreateParameter("passwordSalt", passwordSalt)); | ||
1079 | command.Parameters.Add(database.CreateParameter("homeRegion", homeRegion)); | ||
1080 | command.Parameters.Add(database.CreateParameter("homeLocationX", homeLocX)); | ||
1081 | command.Parameters.Add(database.CreateParameter("homeLocationY", homeLocY)); | ||
1082 | command.Parameters.Add(database.CreateParameter("homeLocationZ", homeLocZ)); | ||
1083 | command.Parameters.Add(database.CreateParameter("homeLookAtX", homeLookAtX)); | ||
1084 | command.Parameters.Add(database.CreateParameter("homeLookAtY", homeLookAtY)); | ||
1085 | command.Parameters.Add(database.CreateParameter("homeLookAtZ", homeLookAtZ)); | ||
1086 | command.Parameters.Add(database.CreateParameter("created", created)); | ||
1087 | command.Parameters.Add(database.CreateParameter("lastLogin", lastlogin)); | ||
1088 | command.Parameters.Add(database.CreateParameter("userInventoryURI", inventoryURI)); | ||
1089 | command.Parameters.Add(database.CreateParameter("userAssetURI", assetURI)); | ||
1090 | command.Parameters.Add(database.CreateParameter("profileCanDoMask", canDoMask)); | ||
1091 | command.Parameters.Add(database.CreateParameter("profileWantDoMask", wantDoMask)); | ||
1092 | command.Parameters.Add(database.CreateParameter("profileAboutText", aboutText)); | ||
1093 | command.Parameters.Add(database.CreateParameter("profileFirstText", firstText)); | ||
1094 | command.Parameters.Add(database.CreateParameter("profileImage", profileImage)); | ||
1095 | command.Parameters.Add(database.CreateParameter("profileFirstImage", firstImage)); | ||
1096 | command.Parameters.Add(database.CreateParameter("webLoginKey", webLoginKey)); | ||
1097 | command.Parameters.Add(database.CreateParameter("homeRegionID", homeRegionID)); | ||
1098 | command.Parameters.Add(database.CreateParameter("userFlags", userFlags)); | ||
1099 | command.Parameters.Add(database.CreateParameter("godLevel", godLevel)); | ||
1100 | command.Parameters.Add(database.CreateParameter("customType", customType)); | ||
1101 | command.Parameters.Add(database.CreateParameter("partner", partnerID)); | ||
1102 | |||
1103 | command.ExecuteNonQuery(); | ||
1104 | return; | ||
1105 | } | ||
1106 | } | ||
1107 | catch (Exception e) | ||
1108 | { | ||
1109 | m_log.Error(e.ToString()); | ||
1110 | return; | ||
1111 | } | ||
1112 | } | ||
1113 | |||
1114 | /// <summary> | ||
1115 | /// Reads a user profile from an active data reader | ||
1116 | /// </summary> | ||
1117 | /// <param name="reader">An active database reader</param> | ||
1118 | /// <returns>A user profile</returns> | ||
1119 | private static UserProfileData ReadUserRow(SqlDataReader reader) | ||
1120 | { | ||
1121 | UserProfileData retval = new UserProfileData(); | ||
1122 | |||
1123 | if (reader.Read()) | ||
1124 | { | ||
1125 | retval.ID = new UUID((Guid)reader["UUID"]); | ||
1126 | retval.FirstName = (string)reader["username"]; | ||
1127 | retval.SurName = (string)reader["lastname"]; | ||
1128 | if (reader.IsDBNull(reader.GetOrdinal("email"))) | ||
1129 | retval.Email = ""; | ||
1130 | else | ||
1131 | retval.Email = (string)reader["email"]; | ||
1132 | |||
1133 | retval.PasswordHash = (string)reader["passwordHash"]; | ||
1134 | retval.PasswordSalt = (string)reader["passwordSalt"]; | ||
1135 | |||
1136 | retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); | ||
1137 | retval.HomeLocation = new Vector3( | ||
1138 | Convert.ToSingle(reader["homeLocationX"].ToString()), | ||
1139 | Convert.ToSingle(reader["homeLocationY"].ToString()), | ||
1140 | Convert.ToSingle(reader["homeLocationZ"].ToString())); | ||
1141 | retval.HomeLookAt = new Vector3( | ||
1142 | Convert.ToSingle(reader["homeLookAtX"].ToString()), | ||
1143 | Convert.ToSingle(reader["homeLookAtY"].ToString()), | ||
1144 | Convert.ToSingle(reader["homeLookAtZ"].ToString())); | ||
1145 | |||
1146 | if (reader.IsDBNull(reader.GetOrdinal("homeRegionID"))) | ||
1147 | retval.HomeRegionID = UUID.Zero; | ||
1148 | else | ||
1149 | retval.HomeRegionID = new UUID((Guid)reader["homeRegionID"]); | ||
1150 | |||
1151 | retval.Created = Convert.ToInt32(reader["created"].ToString()); | ||
1152 | retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); | ||
1153 | |||
1154 | if (reader.IsDBNull(reader.GetOrdinal("userInventoryURI"))) | ||
1155 | retval.UserInventoryURI = ""; | ||
1156 | else | ||
1157 | retval.UserInventoryURI = (string)reader["userInventoryURI"]; | ||
1158 | |||
1159 | if (reader.IsDBNull(reader.GetOrdinal("userAssetURI"))) | ||
1160 | retval.UserAssetURI = ""; | ||
1161 | else | ||
1162 | retval.UserAssetURI = (string)reader["userAssetURI"]; | ||
1163 | |||
1164 | retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); | ||
1165 | retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); | ||
1166 | |||
1167 | |||
1168 | if (reader.IsDBNull(reader.GetOrdinal("profileAboutText"))) | ||
1169 | retval.AboutText = ""; | ||
1170 | else | ||
1171 | retval.AboutText = (string)reader["profileAboutText"]; | ||
1172 | |||
1173 | if (reader.IsDBNull(reader.GetOrdinal("profileFirstText"))) | ||
1174 | retval.FirstLifeAboutText = ""; | ||
1175 | else | ||
1176 | retval.FirstLifeAboutText = (string)reader["profileFirstText"]; | ||
1177 | |||
1178 | if (reader.IsDBNull(reader.GetOrdinal("profileImage"))) | ||
1179 | retval.Image = UUID.Zero; | ||
1180 | else | ||
1181 | retval.Image = new UUID((Guid)reader["profileImage"]); | ||
1182 | |||
1183 | if (reader.IsDBNull(reader.GetOrdinal("profileFirstImage"))) | ||
1184 | retval.Image = UUID.Zero; | ||
1185 | else | ||
1186 | retval.FirstLifeImage = new UUID((Guid)reader["profileFirstImage"]); | ||
1187 | |||
1188 | if (reader.IsDBNull(reader.GetOrdinal("webLoginKey"))) | ||
1189 | retval.WebLoginKey = UUID.Zero; | ||
1190 | else | ||
1191 | retval.WebLoginKey = new UUID((Guid)reader["webLoginKey"]); | ||
1192 | |||
1193 | retval.UserFlags = Convert.ToInt32(reader["userFlags"].ToString()); | ||
1194 | retval.GodLevel = Convert.ToInt32(reader["godLevel"].ToString()); | ||
1195 | if (reader.IsDBNull(reader.GetOrdinal("customType"))) | ||
1196 | retval.CustomType = ""; | ||
1197 | else | ||
1198 | retval.CustomType = reader["customType"].ToString(); | ||
1199 | |||
1200 | if (reader.IsDBNull(reader.GetOrdinal("partner"))) | ||
1201 | retval.Partner = UUID.Zero; | ||
1202 | else | ||
1203 | retval.Partner = new UUID((Guid)reader["partner"]); | ||
1204 | } | ||
1205 | else | ||
1206 | { | ||
1207 | return null; | ||
1208 | } | ||
1209 | return retval; | ||
1210 | } | ||
1211 | #endregion | ||
1212 | } | ||
1213 | |||
1214 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLGridData.cs b/OpenSim/Data/MySQL/MySQLGridData.cs deleted file mode 100644 index f4e7b85..0000000 --- a/OpenSim/Data/MySQL/MySQLGridData.cs +++ /dev/null | |||
@@ -1,422 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using MySql.Data.MySqlClient; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | |||
38 | namespace OpenSim.Data.MySQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A MySQL Interface for the Grid Server | ||
42 | /// </summary> | ||
43 | public class MySQLGridData : GridDataBase | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private MySQLManager m_database; | ||
48 | private object m_dbLock = new object(); | ||
49 | private string m_connectionString; | ||
50 | |||
51 | override public void Initialise() | ||
52 | { | ||
53 | m_log.Info("[MySQLGridData]: " + Name + " cannot be default-initialized!"); | ||
54 | throw new PluginNotInitialisedException (Name); | ||
55 | } | ||
56 | |||
57 | /// <summary> | ||
58 | /// <para>Initialises Grid interface</para> | ||
59 | /// <para> | ||
60 | /// <list type="bullet"> | ||
61 | /// <item>Loads and initialises the MySQL storage plugin</item> | ||
62 | /// <item>Warns and uses the obsolete mysql_connection.ini if connect string is empty.</item> | ||
63 | /// <item>Check for migration</item> | ||
64 | /// </list> | ||
65 | /// </para> | ||
66 | /// </summary> | ||
67 | /// <param name="connect">connect string.</param> | ||
68 | override public void Initialise(string connect) | ||
69 | { | ||
70 | m_connectionString = connect; | ||
71 | m_database = new MySQLManager(connect); | ||
72 | |||
73 | // This actually does the roll forward assembly stuff | ||
74 | Assembly assem = GetType().Assembly; | ||
75 | |||
76 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
77 | { | ||
78 | Migration m = new Migration(dbcon, assem, "GridStore"); | ||
79 | m.Update(); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Shuts down the grid interface | ||
85 | /// </summary> | ||
86 | override public void Dispose() | ||
87 | { | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Returns the plugin name | ||
92 | /// </summary> | ||
93 | /// <returns>Plugin name</returns> | ||
94 | override public string Name | ||
95 | { | ||
96 | get { return "MySql OpenGridData"; } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Returns the plugin version | ||
101 | /// </summary> | ||
102 | /// <returns>Plugin version</returns> | ||
103 | override public string Version | ||
104 | { | ||
105 | get { return "0.1"; } | ||
106 | } | ||
107 | |||
108 | /// <summary> | ||
109 | /// Returns all the specified region profiles within coordates -- coordinates are inclusive | ||
110 | /// </summary> | ||
111 | /// <param name="xmin">Minimum X coordinate</param> | ||
112 | /// <param name="ymin">Minimum Y coordinate</param> | ||
113 | /// <param name="xmax">Maximum X coordinate</param> | ||
114 | /// <param name="ymax">Maximum Y coordinate</param> | ||
115 | /// <returns>Array of sim profiles</returns> | ||
116 | override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) | ||
117 | { | ||
118 | try | ||
119 | { | ||
120 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
121 | param["?xmin"] = xmin.ToString(); | ||
122 | param["?ymin"] = ymin.ToString(); | ||
123 | param["?xmax"] = xmax.ToString(); | ||
124 | param["?ymax"] = ymax.ToString(); | ||
125 | |||
126 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
127 | { | ||
128 | dbcon.Open(); | ||
129 | |||
130 | using (IDbCommand result = m_database.Query(dbcon, | ||
131 | "SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", | ||
132 | param)) | ||
133 | { | ||
134 | using (IDataReader reader = result.ExecuteReader()) | ||
135 | { | ||
136 | RegionProfileData row; | ||
137 | |||
138 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
139 | |||
140 | while ((row = m_database.readSimRow(reader)) != null) | ||
141 | rows.Add(row); | ||
142 | |||
143 | return rows.ToArray(); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | } | ||
148 | catch (Exception e) | ||
149 | { | ||
150 | m_log.Error(e.Message, e); | ||
151 | return null; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /// <summary> | ||
156 | /// Returns up to maxNum profiles of regions that have a name starting with namePrefix | ||
157 | /// </summary> | ||
158 | /// <param name="name">The name to match against</param> | ||
159 | /// <param name="maxNum">Maximum number of profiles to return</param> | ||
160 | /// <returns>A list of sim profiles</returns> | ||
161 | override public List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum) | ||
162 | { | ||
163 | try | ||
164 | { | ||
165 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
166 | param["?name"] = namePrefix + "%"; | ||
167 | |||
168 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
169 | { | ||
170 | dbcon.Open(); | ||
171 | |||
172 | using (IDbCommand result = m_database.Query(dbcon, | ||
173 | "SELECT * FROM regions WHERE regionName LIKE ?name", | ||
174 | param)) | ||
175 | { | ||
176 | using (IDataReader reader = result.ExecuteReader()) | ||
177 | { | ||
178 | RegionProfileData row; | ||
179 | |||
180 | List<RegionProfileData> rows = new List<RegionProfileData>(); | ||
181 | |||
182 | while (rows.Count < maxNum && (row = m_database.readSimRow(reader)) != null) | ||
183 | rows.Add(row); | ||
184 | |||
185 | return rows; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | catch (Exception e) | ||
191 | { | ||
192 | m_log.Error(e.Message, e); | ||
193 | return null; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | /// <summary> | ||
198 | /// Returns a sim profile from it's location | ||
199 | /// </summary> | ||
200 | /// <param name="handle">Region location handle</param> | ||
201 | /// <returns>Sim profile</returns> | ||
202 | override public RegionProfileData GetProfileByHandle(ulong handle) | ||
203 | { | ||
204 | try | ||
205 | { | ||
206 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
207 | param["?handle"] = handle.ToString(); | ||
208 | |||
209 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
210 | { | ||
211 | dbcon.Open(); | ||
212 | |||
213 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE regionHandle = ?handle", param)) | ||
214 | { | ||
215 | using (IDataReader reader = result.ExecuteReader()) | ||
216 | { | ||
217 | RegionProfileData row = m_database.readSimRow(reader); | ||
218 | return row; | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
223 | catch (Exception e) | ||
224 | { | ||
225 | m_log.Error(e.Message, e); | ||
226 | return null; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /// <summary> | ||
231 | /// Returns a sim profile from it's UUID | ||
232 | /// </summary> | ||
233 | /// <param name="uuid">The region UUID</param> | ||
234 | /// <returns>The sim profile</returns> | ||
235 | override public RegionProfileData GetProfileByUUID(UUID uuid) | ||
236 | { | ||
237 | try | ||
238 | { | ||
239 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
240 | param["?uuid"] = uuid.ToString(); | ||
241 | |||
242 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
243 | { | ||
244 | dbcon.Open(); | ||
245 | |||
246 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM regions WHERE uuid = ?uuid", param)) | ||
247 | { | ||
248 | using (IDataReader reader = result.ExecuteReader()) | ||
249 | { | ||
250 | RegionProfileData row = m_database.readSimRow(reader); | ||
251 | return row; | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | catch (Exception e) | ||
257 | { | ||
258 | m_log.Error(e.Message, e); | ||
259 | return null; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /// <summary> | ||
264 | /// Returns a sim profile from it's Region name string | ||
265 | /// </summary> | ||
266 | /// <returns>The sim profile</returns> | ||
267 | override public RegionProfileData GetProfileByString(string regionName) | ||
268 | { | ||
269 | if (regionName.Length > 2) | ||
270 | { | ||
271 | try | ||
272 | { | ||
273 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
274 | // Add % because this is a like query. | ||
275 | param["?regionName"] = regionName + "%"; | ||
276 | |||
277 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
278 | { | ||
279 | dbcon.Open(); | ||
280 | |||
281 | // Order by statement will return shorter matches first. Only returns one record or no record. | ||
282 | using (IDbCommand result = m_database.Query(dbcon, | ||
283 | "SELECT * FROM regions WHERE regionName like ?regionName order by LENGTH(regionName) asc LIMIT 1", | ||
284 | param)) | ||
285 | { | ||
286 | using (IDataReader reader = result.ExecuteReader()) | ||
287 | { | ||
288 | RegionProfileData row = m_database.readSimRow(reader); | ||
289 | return row; | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | catch (Exception e) | ||
295 | { | ||
296 | m_log.Error(e.Message, e); | ||
297 | return null; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters"); | ||
302 | return null; | ||
303 | } | ||
304 | |||
305 | /// <summary> | ||
306 | /// Adds a new profile to the database | ||
307 | /// </summary> | ||
308 | /// <param name="profile">The profile to add</param> | ||
309 | /// <returns>Successful?</returns> | ||
310 | override public DataResponse StoreProfile(RegionProfileData profile) | ||
311 | { | ||
312 | try | ||
313 | { | ||
314 | if (m_database.insertRegion(profile)) | ||
315 | return DataResponse.RESPONSE_OK; | ||
316 | else | ||
317 | return DataResponse.RESPONSE_ERROR; | ||
318 | } | ||
319 | catch | ||
320 | { | ||
321 | return DataResponse.RESPONSE_ERROR; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | /// <summary> | ||
326 | /// Deletes a sim profile from the database | ||
327 | /// </summary> | ||
328 | /// <param name="uuid">the sim UUID</param> | ||
329 | /// <returns>Successful?</returns> | ||
330 | //public DataResponse DeleteProfile(RegionProfileData profile) | ||
331 | override public DataResponse DeleteProfile(string uuid) | ||
332 | { | ||
333 | try | ||
334 | { | ||
335 | if (m_database.deleteRegion(uuid)) | ||
336 | return DataResponse.RESPONSE_OK; | ||
337 | else | ||
338 | return DataResponse.RESPONSE_ERROR; | ||
339 | } | ||
340 | catch | ||
341 | { | ||
342 | return DataResponse.RESPONSE_ERROR; | ||
343 | } | ||
344 | } | ||
345 | |||
346 | /// <summary> | ||
347 | /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. | ||
348 | /// </summary> | ||
349 | /// <param name="uuid">The UUID of the challenger</param> | ||
350 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
351 | /// <param name="authkey">The secret</param> | ||
352 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
353 | override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey) | ||
354 | { | ||
355 | bool throwHissyFit = false; // Should be true by 1.0 | ||
356 | |||
357 | if (throwHissyFit) | ||
358 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
359 | |||
360 | RegionProfileData data = GetProfileByUUID(uuid); | ||
361 | |||
362 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
363 | } | ||
364 | |||
365 | /// <summary> | ||
366 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
367 | /// </summary> | ||
368 | /// <remarks>This requires a security audit.</remarks> | ||
369 | /// <param name="uuid"></param> | ||
370 | /// <param name="handle"></param> | ||
371 | /// <param name="authhash"></param> | ||
372 | /// <param name="challenge"></param> | ||
373 | /// <returns></returns> | ||
374 | public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge) | ||
375 | { | ||
376 | // SHA512Managed HashProvider = new SHA512Managed(); | ||
377 | // Encoding TextProvider = new UTF8Encoding(); | ||
378 | |||
379 | // byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge); | ||
380 | // byte[] hash = HashProvider.ComputeHash(stream); | ||
381 | |||
382 | return false; | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Adds a location reservation | ||
387 | /// </summary> | ||
388 | /// <param name="x">x coordinate</param> | ||
389 | /// <param name="y">y coordinate</param> | ||
390 | /// <returns></returns> | ||
391 | override public ReservationData GetReservationAtPoint(uint x, uint y) | ||
392 | { | ||
393 | try | ||
394 | { | ||
395 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
396 | param["?x"] = x.ToString(); | ||
397 | param["?y"] = y.ToString(); | ||
398 | |||
399 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
400 | { | ||
401 | dbcon.Open(); | ||
402 | |||
403 | using (IDbCommand result = m_database.Query(dbcon, | ||
404 | "SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y", | ||
405 | param)) | ||
406 | { | ||
407 | using (IDataReader reader = result.ExecuteReader()) | ||
408 | { | ||
409 | ReservationData row = m_database.readReservationRow(reader); | ||
410 | return row; | ||
411 | } | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | catch (Exception e) | ||
416 | { | ||
417 | m_log.Error(e.Message, e); | ||
418 | return null; | ||
419 | } | ||
420 | } | ||
421 | } | ||
422 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLLogData.cs b/OpenSim/Data/MySQL/MySQLLogData.cs deleted file mode 100644 index 304883c..0000000 --- a/OpenSim/Data/MySQL/MySQLLogData.cs +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Data.MySQL | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// An interface to the log database for MySQL | ||
37 | /// </summary> | ||
38 | internal class MySQLLogData : ILogDataPlugin | ||
39 | { | ||
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | |||
42 | /// <summary> | ||
43 | /// The database manager | ||
44 | /// </summary> | ||
45 | public MySQLManager database; | ||
46 | |||
47 | public void Initialise() | ||
48 | { | ||
49 | m_log.Info("[MySQLLogData]: " + Name + " cannot be default-initialized!"); | ||
50 | throw new PluginNotInitialisedException (Name); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Artificial constructor called when the plugin is loaded | ||
55 | /// Uses the obsolete mysql_connection.ini if connect string is empty. | ||
56 | /// </summary> | ||
57 | /// <param name="connect">connect string</param> | ||
58 | public void Initialise(string connect) | ||
59 | { | ||
60 | if (connect != String.Empty) | ||
61 | { | ||
62 | database = new MySQLManager(connect); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | m_log.Warn("Using deprecated mysql_connection.ini. Please update database_connect in GridServer_Config.xml and we'll use that instead"); | ||
67 | |||
68 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
69 | string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
70 | string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); | ||
71 | string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); | ||
72 | string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||
73 | string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
74 | string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); | ||
75 | |||
76 | database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, | ||
77 | settingPooling, settingPort); | ||
78 | } | ||
79 | |||
80 | // This actually does the roll forward assembly stuff | ||
81 | Assembly assem = GetType().Assembly; | ||
82 | |||
83 | using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(connect)) | ||
84 | { | ||
85 | dbcon.Open(); | ||
86 | |||
87 | Migration m = new Migration(dbcon, assem, "LogStore"); | ||
88 | |||
89 | // TODO: After rev 6000, remove this. People should have | ||
90 | // been rolled onto the new migration code by then. | ||
91 | TestTables(m); | ||
92 | |||
93 | m.Update(); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | /// <summary></summary> | ||
98 | /// <param name="m"></param> | ||
99 | private void TestTables(Migration m) | ||
100 | { | ||
101 | // under migrations, bail | ||
102 | if (m.Version > 0) | ||
103 | return; | ||
104 | |||
105 | Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||
106 | tableList["logs"] = null; | ||
107 | database.GetTableVersion(tableList); | ||
108 | |||
109 | // migrations will handle it | ||
110 | if (tableList["logs"] == null) | ||
111 | return; | ||
112 | |||
113 | // we have the table, so pretend like we did the first migration in the past | ||
114 | if (m.Version == 0) | ||
115 | m.Version = 1; | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// Saves a log item to the database | ||
120 | /// </summary> | ||
121 | /// <param name="serverDaemon">The daemon triggering the event</param> | ||
122 | /// <param name="target">The target of the action (region / agent UUID, etc)</param> | ||
123 | /// <param name="methodCall">The method call where the problem occured</param> | ||
124 | /// <param name="arguments">The arguments passed to the method</param> | ||
125 | /// <param name="priority">How critical is this?</param> | ||
126 | /// <param name="logMessage">The message to log</param> | ||
127 | public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||
128 | string logMessage) | ||
129 | { | ||
130 | try | ||
131 | { | ||
132 | database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage); | ||
133 | } | ||
134 | catch | ||
135 | { | ||
136 | } | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// Returns the name of this DB provider | ||
141 | /// </summary> | ||
142 | /// <returns>A string containing the DB provider name</returns> | ||
143 | public string Name | ||
144 | { | ||
145 | get { return "MySQL Logdata Interface";} | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Closes the database provider | ||
150 | /// </summary> | ||
151 | /// <remarks>do nothing</remarks> | ||
152 | public void Dispose() | ||
153 | { | ||
154 | // Do nothing. | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// Returns the version of this DB provider | ||
159 | /// </summary> | ||
160 | /// <returns>A string containing the provider version</returns> | ||
161 | public string Version | ||
162 | { | ||
163 | get { return "0.1"; } | ||
164 | } | ||
165 | } | ||
166 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs deleted file mode 100644 index ace2027..0000000 --- a/OpenSim/Data/MySQL/MySQLManager.cs +++ /dev/null | |||
@@ -1,1248 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using System.IO; | ||
33 | using System.Reflection; | ||
34 | using log4net; | ||
35 | using MySql.Data.MySqlClient; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | |||
39 | namespace OpenSim.Data.MySQL | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// A MySQL Database manager | ||
43 | /// </summary> | ||
44 | public class MySQLManager | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | /// <summary> | ||
49 | /// Connection string for ADO.net | ||
50 | /// </summary> | ||
51 | private string connectionString; | ||
52 | |||
53 | private object m_dbLock = new object(); | ||
54 | |||
55 | private const string m_waitTimeoutSelect = "select @@wait_timeout"; | ||
56 | |||
57 | /// <summary> | ||
58 | /// Wait timeout for our connection in ticks. | ||
59 | /// </summary> | ||
60 | private long m_waitTimeout; | ||
61 | |||
62 | /// <summary> | ||
63 | /// Make our storage of the timeout this amount smaller than it actually is, to give us a margin on long | ||
64 | /// running database operations. | ||
65 | /// </summary> | ||
66 | private long m_waitTimeoutLeeway = 60 * TimeSpan.TicksPerSecond; | ||
67 | |||
68 | /// <summary> | ||
69 | /// Holds the last tick time that the connection was used. | ||
70 | /// </summary> | ||
71 | private long m_lastConnectionUse; | ||
72 | |||
73 | /// <summary> | ||
74 | /// Initialises and creates a new MySQL connection and maintains it. | ||
75 | /// </summary> | ||
76 | /// <param name="hostname">The MySQL server being connected to</param> | ||
77 | /// <param name="database">The name of the MySQL database being used</param> | ||
78 | /// <param name="username">The username logging into the database</param> | ||
79 | /// <param name="password">The password for the user logging in</param> | ||
80 | /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param> | ||
81 | /// <param name="port">The MySQL server port</param> | ||
82 | public MySQLManager(string hostname, string database, string username, string password, string cpooling, | ||
83 | string port) | ||
84 | { | ||
85 | string s = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + | ||
86 | username + ";Password=" + password + ";Pooling=" + cpooling + ";"; | ||
87 | |||
88 | Initialise(s); | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Initialises and creates a new MySQL connection and maintains it. | ||
93 | /// </summary> | ||
94 | /// <param name="connect">connectionString</param> | ||
95 | public MySQLManager(String connect) | ||
96 | { | ||
97 | Initialise(connect); | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Initialises and creates a new MySQL connection and maintains it. | ||
102 | /// </summary> | ||
103 | /// <param name="connect">connectionString</param> | ||
104 | public void Initialise(String connect) | ||
105 | { | ||
106 | try | ||
107 | { | ||
108 | connectionString = connect; | ||
109 | //dbcon = new MySqlConnection(connectionString); | ||
110 | |||
111 | try | ||
112 | { | ||
113 | //dbcon.Open(); | ||
114 | } | ||
115 | catch(Exception e) | ||
116 | { | ||
117 | throw new Exception("Connection error while using connection string ["+connectionString+"]", e); | ||
118 | } | ||
119 | |||
120 | m_log.Info("[MYSQL]: Connection established"); | ||
121 | GetWaitTimeout(); | ||
122 | } | ||
123 | catch (Exception e) | ||
124 | { | ||
125 | throw new Exception("Error initialising MySql Database: " + e.ToString()); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// Get the wait_timeout value for our connection | ||
131 | /// </summary> | ||
132 | protected void GetWaitTimeout() | ||
133 | { | ||
134 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
135 | { | ||
136 | dbcon.Open(); | ||
137 | |||
138 | using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon)) | ||
139 | { | ||
140 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
141 | { | ||
142 | if (dbReader.Read()) | ||
143 | { | ||
144 | m_waitTimeout | ||
145 | = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway; | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | |||
151 | m_lastConnectionUse = DateTime.Now.Ticks; | ||
152 | |||
153 | m_log.DebugFormat( | ||
154 | "[REGION DB]: Connection wait timeout {0} seconds", m_waitTimeout / TimeSpan.TicksPerSecond); | ||
155 | } | ||
156 | |||
157 | public string ConnectionString | ||
158 | { | ||
159 | get { return connectionString; } | ||
160 | } | ||
161 | |||
162 | /// <summary> | ||
163 | /// Returns the version of this DB provider | ||
164 | /// </summary> | ||
165 | /// <returns>A string containing the DB provider</returns> | ||
166 | public string getVersion() | ||
167 | { | ||
168 | Module module = GetType().Module; | ||
169 | // string dllName = module.Assembly.ManifestModule.Name; | ||
170 | Version dllVersion = module.Assembly.GetName().Version; | ||
171 | |||
172 | return | ||
173 | string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, | ||
174 | dllVersion.Revision); | ||
175 | } | ||
176 | |||
177 | /// <summary> | ||
178 | /// Extract a named string resource from the embedded resources | ||
179 | /// </summary> | ||
180 | /// <param name="name">name of embedded resource</param> | ||
181 | /// <returns>string contained within the embedded resource</returns> | ||
182 | private string getResourceString(string name) | ||
183 | { | ||
184 | Assembly assem = GetType().Assembly; | ||
185 | string[] names = assem.GetManifestResourceNames(); | ||
186 | |||
187 | foreach (string s in names) | ||
188 | { | ||
189 | if (s.EndsWith(name)) | ||
190 | { | ||
191 | using (Stream resource = assem.GetManifestResourceStream(s)) | ||
192 | { | ||
193 | using (StreamReader resourceReader = new StreamReader(resource)) | ||
194 | { | ||
195 | string resourceString = resourceReader.ReadToEnd(); | ||
196 | return resourceString; | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | throw new Exception(string.Format("Resource '{0}' was not found", name)); | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Execute a SQL statement stored in a resource, as a string | ||
206 | /// </summary> | ||
207 | /// <param name="name">name of embedded resource</param> | ||
208 | public void ExecuteResourceSql(string name) | ||
209 | { | ||
210 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
211 | { | ||
212 | dbcon.Open(); | ||
213 | |||
214 | MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon); | ||
215 | cmd.ExecuteNonQuery(); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | /// <summary> | ||
220 | /// Execute a MySqlCommand | ||
221 | /// </summary> | ||
222 | /// <param name="sql">sql string to execute</param> | ||
223 | public void ExecuteSql(string sql) | ||
224 | { | ||
225 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
226 | { | ||
227 | dbcon.Open(); | ||
228 | |||
229 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); | ||
230 | cmd.ExecuteNonQuery(); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | public void ExecuteParameterizedSql(string sql, Dictionary<string, string> parameters) | ||
235 | { | ||
236 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
237 | { | ||
238 | dbcon.Open(); | ||
239 | |||
240 | MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
241 | cmd.CommandText = sql; | ||
242 | foreach (KeyValuePair<string, string> param in parameters) | ||
243 | { | ||
244 | cmd.Parameters.AddWithValue(param.Key, param.Value); | ||
245 | } | ||
246 | cmd.ExecuteNonQuery(); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | /// <summary> | ||
251 | /// Given a list of tables, return the version of the tables, as seen in the database | ||
252 | /// </summary> | ||
253 | /// <param name="tableList"></param> | ||
254 | public void GetTableVersion(Dictionary<string, string> tableList) | ||
255 | { | ||
256 | lock (m_dbLock) | ||
257 | { | ||
258 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
259 | { | ||
260 | dbcon.Open(); | ||
261 | |||
262 | using (MySqlCommand tablesCmd = new MySqlCommand( | ||
263 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon)) | ||
264 | { | ||
265 | tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database); | ||
266 | |||
267 | using (MySqlDataReader tables = tablesCmd.ExecuteReader()) | ||
268 | { | ||
269 | while (tables.Read()) | ||
270 | { | ||
271 | try | ||
272 | { | ||
273 | string tableName = (string)tables["TABLE_NAME"]; | ||
274 | string comment = (string)tables["TABLE_COMMENT"]; | ||
275 | if (tableList.ContainsKey(tableName)) | ||
276 | { | ||
277 | tableList[tableName] = comment; | ||
278 | } | ||
279 | } | ||
280 | catch (Exception e) | ||
281 | { | ||
282 | m_log.Error(e.Message, e); | ||
283 | } | ||
284 | } | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | // TODO: at some time this code should be cleaned up | ||
292 | |||
293 | /// <summary> | ||
294 | /// Runs a query with protection against SQL Injection by using parameterised input. | ||
295 | /// </summary> | ||
296 | /// <param name="dbcon">Database connection</param> | ||
297 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | ||
298 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | ||
299 | /// <returns>A MySQL DB Command</returns> | ||
300 | public IDbCommand Query(MySqlConnection dbcon, string sql, Dictionary<string, object> parameters) | ||
301 | { | ||
302 | try | ||
303 | { | ||
304 | MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); | ||
305 | dbcommand.CommandText = sql; | ||
306 | foreach (KeyValuePair<string, object> param in parameters) | ||
307 | { | ||
308 | dbcommand.Parameters.AddWithValue(param.Key, param.Value); | ||
309 | } | ||
310 | |||
311 | return (IDbCommand)dbcommand; | ||
312 | } | ||
313 | catch (Exception e) | ||
314 | { | ||
315 | // Return null if it fails. | ||
316 | m_log.Error("Failed during Query generation: " + e.Message, e); | ||
317 | return null; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | /// <summary> | ||
322 | /// Reads a region row from a database reader | ||
323 | /// </summary> | ||
324 | /// <param name="reader">An active database reader</param> | ||
325 | /// <returns>A region profile</returns> | ||
326 | public RegionProfileData readSimRow(IDataReader reader) | ||
327 | { | ||
328 | RegionProfileData retval = new RegionProfileData(); | ||
329 | |||
330 | if (reader.Read()) | ||
331 | { | ||
332 | // Region Main gotta-have-or-we-return-null parts | ||
333 | UInt64 tmp64; | ||
334 | if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64)) | ||
335 | { | ||
336 | return null; | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | retval.regionHandle = tmp64; | ||
341 | } | ||
342 | UUID tmp_uuid; | ||
343 | if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid)) | ||
344 | { | ||
345 | return null; | ||
346 | } | ||
347 | else | ||
348 | { | ||
349 | retval.UUID = tmp_uuid; | ||
350 | } | ||
351 | |||
352 | // non-critical parts | ||
353 | retval.regionName = (string)reader["regionName"]; | ||
354 | retval.originUUID = new UUID((string) reader["originUUID"]); | ||
355 | |||
356 | // Secrets | ||
357 | retval.regionRecvKey = (string) reader["regionRecvKey"]; | ||
358 | retval.regionSecret = (string) reader["regionSecret"]; | ||
359 | retval.regionSendKey = (string) reader["regionSendKey"]; | ||
360 | |||
361 | // Region Server | ||
362 | retval.regionDataURI = (string) reader["regionDataURI"]; | ||
363 | retval.regionOnline = false; // Needs to be pinged before this can be set. | ||
364 | retval.serverIP = (string) reader["serverIP"]; | ||
365 | retval.serverPort = (uint) reader["serverPort"]; | ||
366 | retval.serverURI = (string) reader["serverURI"]; | ||
367 | retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString()); | ||
368 | retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString()); | ||
369 | |||
370 | // Location | ||
371 | retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString()); | ||
372 | retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString()); | ||
373 | retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString()); | ||
374 | |||
375 | // Neighbours - 0 = No Override | ||
376 | retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString()); | ||
377 | retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString()); | ||
378 | retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString()); | ||
379 | retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString()); | ||
380 | |||
381 | // Assets | ||
382 | retval.regionAssetURI = (string) reader["regionAssetURI"]; | ||
383 | retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; | ||
384 | retval.regionAssetSendKey = (string) reader["regionAssetSendKey"]; | ||
385 | |||
386 | // Userserver | ||
387 | retval.regionUserURI = (string) reader["regionUserURI"]; | ||
388 | retval.regionUserRecvKey = (string) reader["regionUserRecvKey"]; | ||
389 | retval.regionUserSendKey = (string) reader["regionUserSendKey"]; | ||
390 | |||
391 | // World Map Addition | ||
392 | UUID.TryParse((string)reader["regionMapTexture"], out retval.regionMapTextureID); | ||
393 | UUID.TryParse((string)reader["owner_uuid"], out retval.owner_uuid); | ||
394 | retval.maturity = Convert.ToUInt32(reader["access"]); | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | return null; | ||
399 | } | ||
400 | return retval; | ||
401 | } | ||
402 | |||
403 | /// <summary> | ||
404 | /// Reads a reservation row from a database reader | ||
405 | /// </summary> | ||
406 | /// <param name="reader">An active database reader</param> | ||
407 | /// <returns>A reservation data object</returns> | ||
408 | public ReservationData readReservationRow(IDataReader reader) | ||
409 | { | ||
410 | ReservationData retval = new ReservationData(); | ||
411 | if (reader.Read()) | ||
412 | { | ||
413 | retval.gridRecvKey = (string) reader["gridRecvKey"]; | ||
414 | retval.gridSendKey = (string) reader["gridSendKey"]; | ||
415 | retval.reservationCompany = (string) reader["resCompany"]; | ||
416 | retval.reservationMaxX = Convert.ToInt32(reader["resXMax"].ToString()); | ||
417 | retval.reservationMaxY = Convert.ToInt32(reader["resYMax"].ToString()); | ||
418 | retval.reservationMinX = Convert.ToInt32(reader["resXMin"].ToString()); | ||
419 | retval.reservationMinY = Convert.ToInt32(reader["resYMin"].ToString()); | ||
420 | retval.reservationName = (string) reader["resName"]; | ||
421 | retval.status = Convert.ToInt32(reader["status"].ToString()) == 1; | ||
422 | UUID tmp; | ||
423 | UUID.TryParse((string) reader["userUUID"], out tmp); | ||
424 | retval.userUUID = tmp; | ||
425 | } | ||
426 | else | ||
427 | { | ||
428 | return null; | ||
429 | } | ||
430 | return retval; | ||
431 | } | ||
432 | |||
433 | /// <summary> | ||
434 | /// Reads an agent row from a database reader | ||
435 | /// </summary> | ||
436 | /// <param name="reader">An active database reader</param> | ||
437 | /// <returns>A user session agent</returns> | ||
438 | public UserAgentData readAgentRow(IDataReader reader) | ||
439 | { | ||
440 | UserAgentData retval = new UserAgentData(); | ||
441 | |||
442 | if (reader.Read()) | ||
443 | { | ||
444 | // Agent IDs | ||
445 | UUID tmp; | ||
446 | if (!UUID.TryParse((string)reader["UUID"], out tmp)) | ||
447 | return null; | ||
448 | retval.ProfileID = tmp; | ||
449 | |||
450 | UUID.TryParse((string) reader["sessionID"], out tmp); | ||
451 | retval.SessionID = tmp; | ||
452 | |||
453 | UUID.TryParse((string)reader["secureSessionID"], out tmp); | ||
454 | retval.SecureSessionID = tmp; | ||
455 | |||
456 | // Agent Who? | ||
457 | retval.AgentIP = (string) reader["agentIP"]; | ||
458 | retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString()); | ||
459 | retval.AgentOnline = Convert.ToBoolean(Convert.ToInt16(reader["agentOnline"].ToString())); | ||
460 | |||
461 | // Login/Logout times (UNIX Epoch) | ||
462 | retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString()); | ||
463 | retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); | ||
464 | |||
465 | // Current position | ||
466 | retval.Region = new UUID((string)reader["currentRegion"]); | ||
467 | retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||
468 | Vector3 tmp_v; | ||
469 | Vector3.TryParse((string) reader["currentPos"], out tmp_v); | ||
470 | retval.Position = tmp_v; | ||
471 | Vector3.TryParse((string)reader["currentLookAt"], out tmp_v); | ||
472 | retval.LookAt = tmp_v; | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | return null; | ||
477 | } | ||
478 | return retval; | ||
479 | } | ||
480 | |||
481 | /// <summary> | ||
482 | /// Reads a user profile from an active data reader | ||
483 | /// </summary> | ||
484 | /// <param name="reader">An active database reader</param> | ||
485 | /// <returns>A user profile</returns> | ||
486 | public UserProfileData readUserRow(IDataReader reader) | ||
487 | { | ||
488 | UserProfileData retval = new UserProfileData(); | ||
489 | |||
490 | if (reader.Read()) | ||
491 | { | ||
492 | UUID id; | ||
493 | if (!UUID.TryParse((string)reader["UUID"], out id)) | ||
494 | return null; | ||
495 | |||
496 | retval.ID = id; | ||
497 | retval.FirstName = (string) reader["username"]; | ||
498 | retval.SurName = (string) reader["lastname"]; | ||
499 | retval.Email = (reader.IsDBNull(reader.GetOrdinal("email"))) ? "" : (string) reader["email"]; | ||
500 | |||
501 | retval.PasswordHash = (string) reader["passwordHash"]; | ||
502 | retval.PasswordSalt = (string) reader["passwordSalt"]; | ||
503 | |||
504 | retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); | ||
505 | retval.HomeLocation = new Vector3( | ||
506 | Convert.ToSingle(reader["homeLocationX"].ToString()), | ||
507 | Convert.ToSingle(reader["homeLocationY"].ToString()), | ||
508 | Convert.ToSingle(reader["homeLocationZ"].ToString())); | ||
509 | retval.HomeLookAt = new Vector3( | ||
510 | Convert.ToSingle(reader["homeLookAtX"].ToString()), | ||
511 | Convert.ToSingle(reader["homeLookAtY"].ToString()), | ||
512 | Convert.ToSingle(reader["homeLookAtZ"].ToString())); | ||
513 | |||
514 | UUID regionID = UUID.Zero; | ||
515 | UUID.TryParse(reader["homeRegionID"].ToString(), out regionID); // it's ok if it doesn't work; just use UUID.Zero | ||
516 | retval.HomeRegionID = regionID; | ||
517 | |||
518 | retval.Created = Convert.ToInt32(reader["created"].ToString()); | ||
519 | retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); | ||
520 | |||
521 | retval.UserInventoryURI = (string) reader["userInventoryURI"]; | ||
522 | retval.UserAssetURI = (string) reader["userAssetURI"]; | ||
523 | |||
524 | retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); | ||
525 | retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); | ||
526 | |||
527 | if (reader.IsDBNull(reader.GetOrdinal("profileAboutText"))) | ||
528 | retval.AboutText = ""; | ||
529 | else | ||
530 | retval.AboutText = (string) reader["profileAboutText"]; | ||
531 | |||
532 | if (reader.IsDBNull(reader.GetOrdinal("profileFirstText"))) | ||
533 | retval.FirstLifeAboutText = ""; | ||
534 | else | ||
535 | retval.FirstLifeAboutText = (string)reader["profileFirstText"]; | ||
536 | |||
537 | if (reader.IsDBNull(reader.GetOrdinal("profileImage"))) | ||
538 | retval.Image = UUID.Zero; | ||
539 | else { | ||
540 | UUID tmp; | ||
541 | UUID.TryParse((string)reader["profileImage"], out tmp); | ||
542 | retval.Image = tmp; | ||
543 | } | ||
544 | |||
545 | if (reader.IsDBNull(reader.GetOrdinal("profileFirstImage"))) | ||
546 | retval.FirstLifeImage = UUID.Zero; | ||
547 | else { | ||
548 | UUID tmp; | ||
549 | UUID.TryParse((string)reader["profileFirstImage"], out tmp); | ||
550 | retval.FirstLifeImage = tmp; | ||
551 | } | ||
552 | |||
553 | if (reader.IsDBNull(reader.GetOrdinal("webLoginKey"))) | ||
554 | { | ||
555 | retval.WebLoginKey = UUID.Zero; | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | UUID tmp; | ||
560 | UUID.TryParse((string)reader["webLoginKey"], out tmp); | ||
561 | retval.WebLoginKey = tmp; | ||
562 | } | ||
563 | |||
564 | retval.UserFlags = Convert.ToInt32(reader["userFlags"].ToString()); | ||
565 | retval.GodLevel = Convert.ToInt32(reader["godLevel"].ToString()); | ||
566 | if (reader.IsDBNull(reader.GetOrdinal("customType"))) | ||
567 | retval.CustomType = ""; | ||
568 | else | ||
569 | retval.CustomType = reader["customType"].ToString(); | ||
570 | |||
571 | if (reader.IsDBNull(reader.GetOrdinal("partner"))) | ||
572 | { | ||
573 | retval.Partner = UUID.Zero; | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | UUID tmp; | ||
578 | UUID.TryParse((string)reader["partner"], out tmp); | ||
579 | retval.Partner = tmp; | ||
580 | } | ||
581 | } | ||
582 | else | ||
583 | { | ||
584 | return null; | ||
585 | } | ||
586 | return retval; | ||
587 | } | ||
588 | |||
589 | /// <summary> | ||
590 | /// Reads an avatar appearence from an active data reader | ||
591 | /// </summary> | ||
592 | /// <param name="reader">An active database reader</param> | ||
593 | /// <returns>An avatar appearence</returns> | ||
594 | public AvatarAppearance readAppearanceRow(IDataReader reader) | ||
595 | { | ||
596 | AvatarAppearance appearance = null; | ||
597 | if (reader.Read()) | ||
598 | { | ||
599 | appearance = new AvatarAppearance(); | ||
600 | appearance.Owner = new UUID((string)reader["owner"]); | ||
601 | appearance.Serial = Convert.ToInt32(reader["serial"]); | ||
602 | appearance.VisualParams = (byte[])reader["visual_params"]; | ||
603 | appearance.Texture = new Primitive.TextureEntry((byte[])reader["texture"], 0, ((byte[])reader["texture"]).Length); | ||
604 | appearance.AvatarHeight = (float)Convert.ToDouble(reader["avatar_height"]); | ||
605 | appearance.BodyItem = new UUID((string)reader["body_item"]); | ||
606 | appearance.BodyAsset = new UUID((string)reader["body_asset"]); | ||
607 | appearance.SkinItem = new UUID((string)reader["skin_item"]); | ||
608 | appearance.SkinAsset = new UUID((string)reader["skin_asset"]); | ||
609 | appearance.HairItem = new UUID((string)reader["hair_item"]); | ||
610 | appearance.HairAsset = new UUID((string)reader["hair_asset"]); | ||
611 | appearance.EyesItem = new UUID((string)reader["eyes_item"]); | ||
612 | appearance.EyesAsset = new UUID((string)reader["eyes_asset"]); | ||
613 | appearance.ShirtItem = new UUID((string)reader["shirt_item"]); | ||
614 | appearance.ShirtAsset = new UUID((string)reader["shirt_asset"]); | ||
615 | appearance.PantsItem = new UUID((string)reader["pants_item"]); | ||
616 | appearance.PantsAsset = new UUID((string)reader["pants_asset"]); | ||
617 | appearance.ShoesItem = new UUID((string)reader["shoes_item"]); | ||
618 | appearance.ShoesAsset = new UUID((string)reader["shoes_asset"]); | ||
619 | appearance.SocksItem = new UUID((string)reader["socks_item"]); | ||
620 | appearance.SocksAsset = new UUID((string)reader["socks_asset"]); | ||
621 | appearance.JacketItem = new UUID((string)reader["jacket_item"]); | ||
622 | appearance.JacketAsset = new UUID((string)reader["jacket_asset"]); | ||
623 | appearance.GlovesItem = new UUID((string)reader["gloves_item"]); | ||
624 | appearance.GlovesAsset = new UUID((string)reader["gloves_asset"]); | ||
625 | appearance.UnderShirtItem = new UUID((string)reader["undershirt_item"]); | ||
626 | appearance.UnderShirtAsset = new UUID((string)reader["undershirt_asset"]); | ||
627 | appearance.UnderPantsItem = new UUID((string)reader["underpants_item"]); | ||
628 | appearance.UnderPantsAsset = new UUID((string)reader["underpants_asset"]); | ||
629 | appearance.SkirtItem = new UUID((string)reader["skirt_item"]); | ||
630 | appearance.SkirtAsset = new UUID((string)reader["skirt_asset"]); | ||
631 | } | ||
632 | return appearance; | ||
633 | } | ||
634 | |||
635 | // Read attachment list from data reader | ||
636 | public Hashtable readAttachments(IDataReader r) | ||
637 | { | ||
638 | Hashtable ret = new Hashtable(); | ||
639 | |||
640 | while (r.Read()) | ||
641 | { | ||
642 | int attachpoint = Convert.ToInt32(r["attachpoint"]); | ||
643 | if (ret.ContainsKey(attachpoint)) | ||
644 | continue; | ||
645 | Hashtable item = new Hashtable(); | ||
646 | item.Add("item", r["item"].ToString()); | ||
647 | item.Add("asset", r["asset"].ToString()); | ||
648 | |||
649 | ret.Add(attachpoint, item); | ||
650 | } | ||
651 | |||
652 | return ret; | ||
653 | } | ||
654 | |||
655 | /// <summary> | ||
656 | /// Inserts a new row into the log database | ||
657 | /// </summary> | ||
658 | /// <param name="serverDaemon">The daemon which triggered this event</param> | ||
659 | /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param> | ||
660 | /// <param name="methodCall">The method call where the problem occured</param> | ||
661 | /// <param name="arguments">The arguments passed to the method</param> | ||
662 | /// <param name="priority">How critical is this?</param> | ||
663 | /// <param name="logMessage">Extra message info</param> | ||
664 | /// <returns>Saved successfully?</returns> | ||
665 | public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||
666 | string logMessage) | ||
667 | { | ||
668 | string sql = "INSERT INTO logs (`target`, `server`, `method`, `arguments`, `priority`, `message`) VALUES "; | ||
669 | sql += "(?target, ?server, ?method, ?arguments, ?priority, ?message)"; | ||
670 | |||
671 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
672 | parameters["?server"] = serverDaemon; | ||
673 | parameters["?target"] = target; | ||
674 | parameters["?method"] = methodCall; | ||
675 | parameters["?arguments"] = arguments; | ||
676 | parameters["?priority"] = priority.ToString(); | ||
677 | parameters["?message"] = logMessage; | ||
678 | |||
679 | bool returnval = false; | ||
680 | |||
681 | try | ||
682 | { | ||
683 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
684 | { | ||
685 | dbcon.Open(); | ||
686 | |||
687 | IDbCommand result = Query(dbcon, sql, parameters); | ||
688 | |||
689 | if (result.ExecuteNonQuery() == 1) | ||
690 | returnval = true; | ||
691 | |||
692 | result.Dispose(); | ||
693 | } | ||
694 | } | ||
695 | catch (Exception e) | ||
696 | { | ||
697 | m_log.Error(e.ToString()); | ||
698 | return false; | ||
699 | } | ||
700 | |||
701 | return returnval; | ||
702 | } | ||
703 | |||
704 | /// <summary> | ||
705 | /// Creates a new user and inserts it into the database | ||
706 | /// </summary> | ||
707 | /// <param name="uuid">User ID</param> | ||
708 | /// <param name="username">First part of the login</param> | ||
709 | /// <param name="lastname">Second part of the login</param> | ||
710 | /// <param name="passwordHash">A salted hash of the users password</param> | ||
711 | /// <param name="passwordSalt">The salt used for the password hash</param> | ||
712 | /// <param name="homeRegion">A regionHandle of the users home region</param> | ||
713 | /// <param name="homeRegionID"> The UUID of the user's home region</param> | ||
714 | /// <param name="homeLocX">Home region position vector</param> | ||
715 | /// <param name="homeLocY">Home region position vector</param> | ||
716 | /// <param name="homeLocZ">Home region position vector</param> | ||
717 | /// <param name="homeLookAtX">Home region 'look at' vector</param> | ||
718 | /// <param name="homeLookAtY">Home region 'look at' vector</param> | ||
719 | /// <param name="homeLookAtZ">Home region 'look at' vector</param> | ||
720 | /// <param name="created">Account created (unix timestamp)</param> | ||
721 | /// <param name="lastlogin">Last login (unix timestamp)</param> | ||
722 | /// <param name="inventoryURI">Users inventory URI</param> | ||
723 | /// <param name="assetURI">Users asset URI</param> | ||
724 | /// <param name="canDoMask">I can do mask</param> | ||
725 | /// <param name="wantDoMask">I want to do mask</param> | ||
726 | /// <param name="aboutText">Profile text</param> | ||
727 | /// <param name="firstText">Firstlife text</param> | ||
728 | /// <param name="profileImage">UUID for profile image</param> | ||
729 | /// <param name="firstImage">UUID for firstlife image</param> | ||
730 | /// <param name="webLoginKey">Ignored</param> | ||
731 | /// <returns>Success?</returns> | ||
732 | public bool insertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash, | ||
733 | string passwordSalt, UInt64 homeRegion, UUID homeRegionID, float homeLocX, float homeLocY, float homeLocZ, | ||
734 | float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, | ||
735 | string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, | ||
736 | string aboutText, string firstText, | ||
737 | UUID profileImage, UUID firstImage, UUID webLoginKey, int userFlags, int godLevel, string customType, UUID partner) | ||
738 | { | ||
739 | m_log.Debug("[MySQLManager]: Creating profile for \"" + username + " " + lastname + "\" (" + uuid + ")"); | ||
740 | string sql = | ||
741 | "INSERT INTO users (`UUID`, `username`, `lastname`, `email`, `passwordHash`, `passwordSalt`, `homeRegion`, `homeRegionID`, "; | ||
742 | sql += | ||
743 | "`homeLocationX`, `homeLocationY`, `homeLocationZ`, `homeLookAtX`, `homeLookAtY`, `homeLookAtZ`, `created`, "; | ||
744 | sql += | ||
745 | "`lastLogin`, `userInventoryURI`, `userAssetURI`, `profileCanDoMask`, `profileWantDoMask`, `profileAboutText`, "; | ||
746 | sql += "`profileFirstText`, `profileImage`, `profileFirstImage`, `webLoginKey`, `userFlags`, `godLevel`, `customType`, `partner`) VALUES "; | ||
747 | |||
748 | sql += "(?UUID, ?username, ?lastname, ?email, ?passwordHash, ?passwordSalt, ?homeRegion, ?homeRegionID, "; | ||
749 | sql += | ||
750 | "?homeLocationX, ?homeLocationY, ?homeLocationZ, ?homeLookAtX, ?homeLookAtY, ?homeLookAtZ, ?created, "; | ||
751 | sql += | ||
752 | "?lastLogin, ?userInventoryURI, ?userAssetURI, ?profileCanDoMask, ?profileWantDoMask, ?profileAboutText, "; | ||
753 | sql += "?profileFirstText, ?profileImage, ?profileFirstImage, ?webLoginKey, ?userFlags, ?godLevel, ?customType, ?partner)"; | ||
754 | |||
755 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
756 | parameters["?UUID"] = uuid.ToString(); | ||
757 | parameters["?username"] = username; | ||
758 | parameters["?lastname"] = lastname; | ||
759 | parameters["?email"] = email; | ||
760 | parameters["?passwordHash"] = passwordHash; | ||
761 | parameters["?passwordSalt"] = passwordSalt; | ||
762 | parameters["?homeRegion"] = homeRegion; | ||
763 | parameters["?homeRegionID"] = homeRegionID.ToString(); | ||
764 | parameters["?homeLocationX"] = homeLocX; | ||
765 | parameters["?homeLocationY"] = homeLocY; | ||
766 | parameters["?homeLocationZ"] = homeLocZ; | ||
767 | parameters["?homeLookAtX"] = homeLookAtX; | ||
768 | parameters["?homeLookAtY"] = homeLookAtY; | ||
769 | parameters["?homeLookAtZ"] = homeLookAtZ; | ||
770 | parameters["?created"] = created; | ||
771 | parameters["?lastLogin"] = lastlogin; | ||
772 | parameters["?userInventoryURI"] = inventoryURI; | ||
773 | parameters["?userAssetURI"] = assetURI; | ||
774 | parameters["?profileCanDoMask"] = canDoMask; | ||
775 | parameters["?profileWantDoMask"] = wantDoMask; | ||
776 | parameters["?profileAboutText"] = aboutText; | ||
777 | parameters["?profileFirstText"] = firstText; | ||
778 | parameters["?profileImage"] = profileImage.ToString(); | ||
779 | parameters["?profileFirstImage"] = firstImage.ToString(); | ||
780 | parameters["?webLoginKey"] = webLoginKey.ToString(); | ||
781 | parameters["?userFlags"] = userFlags; | ||
782 | parameters["?godLevel"] = godLevel; | ||
783 | parameters["?customType"] = customType == null ? "" : customType; | ||
784 | parameters["?partner"] = partner.ToString(); | ||
785 | bool returnval = false; | ||
786 | |||
787 | try | ||
788 | { | ||
789 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
790 | { | ||
791 | dbcon.Open(); | ||
792 | |||
793 | IDbCommand result = Query(dbcon, sql, parameters); | ||
794 | |||
795 | if (result.ExecuteNonQuery() == 1) | ||
796 | returnval = true; | ||
797 | |||
798 | result.Dispose(); | ||
799 | } | ||
800 | } | ||
801 | catch (Exception e) | ||
802 | { | ||
803 | m_log.Error(e.ToString()); | ||
804 | return false; | ||
805 | } | ||
806 | |||
807 | //m_log.Debug("[MySQLManager]: Fetch user retval == " + returnval.ToString()); | ||
808 | return returnval; | ||
809 | } | ||
810 | |||
811 | /// <summary> | ||
812 | /// Update user data into the database where User ID = uuid | ||
813 | /// </summary> | ||
814 | /// <param name="uuid">User ID</param> | ||
815 | /// <param name="username">First part of the login</param> | ||
816 | /// <param name="lastname">Second part of the login</param> | ||
817 | /// <param name="passwordHash">A salted hash of the users password</param> | ||
818 | /// <param name="passwordSalt">The salt used for the password hash</param> | ||
819 | /// <param name="homeRegion">A regionHandle of the users home region</param> | ||
820 | /// <param name="homeLocX">Home region position vector</param> | ||
821 | /// <param name="homeLocY">Home region position vector</param> | ||
822 | /// <param name="homeLocZ">Home region position vector</param> | ||
823 | /// <param name="homeLookAtX">Home region 'look at' vector</param> | ||
824 | /// <param name="homeLookAtY">Home region 'look at' vector</param> | ||
825 | /// <param name="homeLookAtZ">Home region 'look at' vector</param> | ||
826 | /// <param name="created">Account created (unix timestamp)</param> | ||
827 | /// <param name="lastlogin">Last login (unix timestamp)</param> | ||
828 | /// <param name="inventoryURI">Users inventory URI</param> | ||
829 | /// <param name="assetURI">Users asset URI</param> | ||
830 | /// <param name="canDoMask">I can do mask</param> | ||
831 | /// <param name="wantDoMask">I want to do mask</param> | ||
832 | /// <param name="aboutText">Profile text</param> | ||
833 | /// <param name="firstText">Firstlife text</param> | ||
834 | /// <param name="profileImage">UUID for profile image</param> | ||
835 | /// <param name="firstImage">UUID for firstlife image</param> | ||
836 | /// <param name="webLoginKey">UUID for weblogin Key</param> | ||
837 | /// <returns>Success?</returns> | ||
838 | public bool updateUserRow(UUID uuid, string username, string lastname, string email, string passwordHash, | ||
839 | string passwordSalt, UInt64 homeRegion, UUID homeRegionID, float homeLocX, float homeLocY, float homeLocZ, | ||
840 | float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, | ||
841 | string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, | ||
842 | string aboutText, string firstText, | ||
843 | UUID profileImage, UUID firstImage, UUID webLoginKey, int userFlags, int godLevel, string customType, UUID partner) | ||
844 | { | ||
845 | string sql = "UPDATE users SET `username` = ?username , `lastname` = ?lastname, `email` = ?email "; | ||
846 | sql += ", `passwordHash` = ?passwordHash , `passwordSalt` = ?passwordSalt , "; | ||
847 | sql += "`homeRegion` = ?homeRegion , `homeRegionID` = ?homeRegionID, `homeLocationX` = ?homeLocationX , "; | ||
848 | sql += "`homeLocationY` = ?homeLocationY , `homeLocationZ` = ?homeLocationZ , "; | ||
849 | sql += "`homeLookAtX` = ?homeLookAtX , `homeLookAtY` = ?homeLookAtY , "; | ||
850 | sql += "`homeLookAtZ` = ?homeLookAtZ , `created` = ?created , `lastLogin` = ?lastLogin , "; | ||
851 | sql += "`userInventoryURI` = ?userInventoryURI , `userAssetURI` = ?userAssetURI , "; | ||
852 | sql += "`profileCanDoMask` = ?profileCanDoMask , `profileWantDoMask` = ?profileWantDoMask , "; | ||
853 | sql += "`profileAboutText` = ?profileAboutText , `profileFirstText` = ?profileFirstText, "; | ||
854 | sql += "`profileImage` = ?profileImage , `profileFirstImage` = ?profileFirstImage , "; | ||
855 | sql += "`userFlags` = ?userFlags , `godLevel` = ?godLevel , "; | ||
856 | sql += "`customType` = ?customType , `partner` = ?partner , "; | ||
857 | sql += "`webLoginKey` = ?webLoginKey WHERE UUID = ?UUID"; | ||
858 | |||
859 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
860 | parameters["?UUID"] = uuid.ToString(); | ||
861 | parameters["?username"] = username; | ||
862 | parameters["?lastname"] = lastname; | ||
863 | parameters["?email"] = email; | ||
864 | parameters["?passwordHash"] = passwordHash; | ||
865 | parameters["?passwordSalt"] = passwordSalt; | ||
866 | parameters["?homeRegion"] = homeRegion; | ||
867 | parameters["?homeRegionID"] = homeRegionID.ToString(); | ||
868 | parameters["?homeLocationX"] = homeLocX; | ||
869 | parameters["?homeLocationY"] = homeLocY; | ||
870 | parameters["?homeLocationZ"] = homeLocZ; | ||
871 | parameters["?homeLookAtX"] = homeLookAtX; | ||
872 | parameters["?homeLookAtY"] = homeLookAtY; | ||
873 | parameters["?homeLookAtZ"] = homeLookAtZ; | ||
874 | parameters["?created"] = created; | ||
875 | parameters["?lastLogin"] = lastlogin; | ||
876 | parameters["?userInventoryURI"] = inventoryURI; | ||
877 | parameters["?userAssetURI"] = assetURI; | ||
878 | parameters["?profileCanDoMask"] = canDoMask; | ||
879 | parameters["?profileWantDoMask"] = wantDoMask; | ||
880 | parameters["?profileAboutText"] = aboutText; | ||
881 | parameters["?profileFirstText"] = firstText; | ||
882 | parameters["?profileImage"] = profileImage.ToString(); | ||
883 | parameters["?profileFirstImage"] = firstImage.ToString(); | ||
884 | parameters["?webLoginKey"] = webLoginKey.ToString(); | ||
885 | parameters["?userFlags"] = userFlags; | ||
886 | parameters["?godLevel"] = godLevel; | ||
887 | parameters["?customType"] = customType == null ? "" : customType; | ||
888 | parameters["?partner"] = partner.ToString(); | ||
889 | |||
890 | bool returnval = false; | ||
891 | try | ||
892 | { | ||
893 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
894 | { | ||
895 | dbcon.Open(); | ||
896 | |||
897 | IDbCommand result = Query(dbcon, sql, parameters); | ||
898 | |||
899 | if (result.ExecuteNonQuery() == 1) | ||
900 | returnval = true; | ||
901 | |||
902 | result.Dispose(); | ||
903 | } | ||
904 | } | ||
905 | catch (Exception e) | ||
906 | { | ||
907 | m_log.Error(e.ToString()); | ||
908 | return false; | ||
909 | } | ||
910 | |||
911 | //m_log.Debug("[MySQLManager]: update user retval == " + returnval.ToString()); | ||
912 | return returnval; | ||
913 | } | ||
914 | |||
915 | /// <summary> | ||
916 | /// Inserts a new region into the database | ||
917 | /// </summary> | ||
918 | /// <param name="regiondata">The region to insert</param> | ||
919 | /// <returns>Success?</returns> | ||
920 | public bool insertRegion(RegionProfileData regiondata) | ||
921 | { | ||
922 | bool GRID_ONLY_UPDATE_NECESSARY_DATA = false; | ||
923 | |||
924 | string sql = String.Empty; | ||
925 | if (GRID_ONLY_UPDATE_NECESSARY_DATA) | ||
926 | { | ||
927 | sql += "INSERT INTO "; | ||
928 | } | ||
929 | else | ||
930 | { | ||
931 | sql += "REPLACE INTO "; | ||
932 | } | ||
933 | |||
934 | sql += "regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | ||
935 | sql += | ||
936 | "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | ||
937 | |||
938 | // part of an initial brutish effort to provide accurate information (as per the xml region spec) | ||
939 | // wrt the ownership of a given region | ||
940 | // the (very bad) assumption is that this value is being read and handled inconsistently or | ||
941 | // not at all. Current strategy is to put the code in place to support the validity of this information | ||
942 | // and to roll forward debugging any issues from that point | ||
943 | // | ||
944 | // this particular section of the mod attempts to implement the commit of a supplied value | ||
945 | // server for the UUID of the region's owner (master avatar). It consists of the addition of the column and value to the relevant sql, | ||
946 | // as well as the related parameterization | ||
947 | sql += | ||
948 | "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture, serverHttpPort, serverRemotingPort, owner_uuid, originUUID, access) VALUES "; | ||
949 | |||
950 | sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, "; | ||
951 | sql += | ||
952 | "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, "; | ||
953 | sql += | ||
954 | "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture, ?serverHttpPort, ?serverRemotingPort, ?owner_uuid, ?originUUID, ?access)"; | ||
955 | |||
956 | if (GRID_ONLY_UPDATE_NECESSARY_DATA) | ||
957 | { | ||
958 | sql += "ON DUPLICATE KEY UPDATE serverIP = ?serverIP, serverPort = ?serverPort, serverURI = ?serverURI, owner_uuid - ?owner_uuid;"; | ||
959 | } | ||
960 | else | ||
961 | { | ||
962 | sql += ";"; | ||
963 | } | ||
964 | |||
965 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
966 | |||
967 | parameters["?regionHandle"] = regiondata.regionHandle.ToString(); | ||
968 | parameters["?regionName"] = regiondata.regionName.ToString(); | ||
969 | parameters["?uuid"] = regiondata.UUID.ToString(); | ||
970 | parameters["?regionRecvKey"] = regiondata.regionRecvKey.ToString(); | ||
971 | parameters["?regionSecret"] = regiondata.regionSecret.ToString(); | ||
972 | parameters["?regionSendKey"] = regiondata.regionSendKey.ToString(); | ||
973 | parameters["?regionDataURI"] = regiondata.regionDataURI.ToString(); | ||
974 | parameters["?serverIP"] = regiondata.serverIP.ToString(); | ||
975 | parameters["?serverPort"] = regiondata.serverPort.ToString(); | ||
976 | parameters["?serverURI"] = regiondata.serverURI.ToString(); | ||
977 | parameters["?locX"] = regiondata.regionLocX.ToString(); | ||
978 | parameters["?locY"] = regiondata.regionLocY.ToString(); | ||
979 | parameters["?locZ"] = regiondata.regionLocZ.ToString(); | ||
980 | parameters["?eastOverrideHandle"] = regiondata.regionEastOverrideHandle.ToString(); | ||
981 | parameters["?westOverrideHandle"] = regiondata.regionWestOverrideHandle.ToString(); | ||
982 | parameters["?northOverrideHandle"] = regiondata.regionNorthOverrideHandle.ToString(); | ||
983 | parameters["?southOverrideHandle"] = regiondata.regionSouthOverrideHandle.ToString(); | ||
984 | parameters["?regionAssetURI"] = regiondata.regionAssetURI.ToString(); | ||
985 | parameters["?regionAssetRecvKey"] = regiondata.regionAssetRecvKey.ToString(); | ||
986 | parameters["?regionAssetSendKey"] = regiondata.regionAssetSendKey.ToString(); | ||
987 | parameters["?regionUserURI"] = regiondata.regionUserURI.ToString(); | ||
988 | parameters["?regionUserRecvKey"] = regiondata.regionUserRecvKey.ToString(); | ||
989 | parameters["?regionUserSendKey"] = regiondata.regionUserSendKey.ToString(); | ||
990 | parameters["?regionMapTexture"] = regiondata.regionMapTextureID.ToString(); | ||
991 | parameters["?serverHttpPort"] = regiondata.httpPort.ToString(); | ||
992 | parameters["?serverRemotingPort"] = regiondata.remotingPort.ToString(); | ||
993 | parameters["?owner_uuid"] = regiondata.owner_uuid.ToString(); | ||
994 | parameters["?originUUID"] = regiondata.originUUID.ToString(); | ||
995 | parameters["?access"] = regiondata.maturity.ToString(); | ||
996 | |||
997 | bool returnval = false; | ||
998 | |||
999 | try | ||
1000 | { | ||
1001 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
1002 | { | ||
1003 | dbcon.Open(); | ||
1004 | |||
1005 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1006 | |||
1007 | // int x; | ||
1008 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1009 | // { | ||
1010 | // returnval = true; | ||
1011 | // } | ||
1012 | if (result.ExecuteNonQuery() > 0) | ||
1013 | { | ||
1014 | returnval = true; | ||
1015 | } | ||
1016 | result.Dispose(); | ||
1017 | } | ||
1018 | } | ||
1019 | catch (Exception e) | ||
1020 | { | ||
1021 | m_log.Error(e.ToString()); | ||
1022 | return false; | ||
1023 | } | ||
1024 | |||
1025 | return returnval; | ||
1026 | } | ||
1027 | |||
1028 | /// <summary> | ||
1029 | /// Delete a region from the database | ||
1030 | /// </summary> | ||
1031 | /// <param name="uuid">The region to delete</param> | ||
1032 | /// <returns>Success?</returns> | ||
1033 | //public bool deleteRegion(RegionProfileData regiondata) | ||
1034 | public bool deleteRegion(string uuid) | ||
1035 | { | ||
1036 | bool returnval = false; | ||
1037 | |||
1038 | string sql = "DELETE FROM regions WHERE uuid = ?uuid;"; | ||
1039 | |||
1040 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
1041 | |||
1042 | try | ||
1043 | { | ||
1044 | parameters["?uuid"] = uuid; | ||
1045 | |||
1046 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
1047 | { | ||
1048 | dbcon.Open(); | ||
1049 | |||
1050 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1051 | |||
1052 | // int x; | ||
1053 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1054 | // { | ||
1055 | // returnval = true; | ||
1056 | // } | ||
1057 | if (result.ExecuteNonQuery() > 0) | ||
1058 | { | ||
1059 | returnval = true; | ||
1060 | } | ||
1061 | result.Dispose(); | ||
1062 | } | ||
1063 | } | ||
1064 | catch (Exception e) | ||
1065 | { | ||
1066 | m_log.Error(e.ToString()); | ||
1067 | return false; | ||
1068 | } | ||
1069 | |||
1070 | return returnval; | ||
1071 | } | ||
1072 | |||
1073 | /// <summary> | ||
1074 | /// Creates a new agent and inserts it into the database | ||
1075 | /// </summary> | ||
1076 | /// <param name="agentdata">The agent data to be inserted</param> | ||
1077 | /// <returns>Success?</returns> | ||
1078 | public bool insertAgentRow(UserAgentData agentdata) | ||
1079 | { | ||
1080 | string sql = String.Empty; | ||
1081 | sql += "REPLACE INTO "; | ||
1082 | sql += "agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos, currentLookAt) VALUES "; | ||
1083 | sql += "(?UUID, ?sessionID, ?secureSessionID, ?agentIP, ?agentPort, ?agentOnline, ?loginTime, ?logoutTime, ?currentRegion, ?currentHandle, ?currentPos, ?currentLookAt);"; | ||
1084 | Dictionary<string, object> parameters = new Dictionary<string, object>(); | ||
1085 | |||
1086 | parameters["?UUID"] = agentdata.ProfileID.ToString(); | ||
1087 | parameters["?sessionID"] = agentdata.SessionID.ToString(); | ||
1088 | parameters["?secureSessionID"] = agentdata.SecureSessionID.ToString(); | ||
1089 | parameters["?agentIP"] = agentdata.AgentIP.ToString(); | ||
1090 | parameters["?agentPort"] = agentdata.AgentPort.ToString(); | ||
1091 | parameters["?agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0"; | ||
1092 | parameters["?loginTime"] = agentdata.LoginTime.ToString(); | ||
1093 | parameters["?logoutTime"] = agentdata.LogoutTime.ToString(); | ||
1094 | parameters["?currentRegion"] = agentdata.Region.ToString(); | ||
1095 | parameters["?currentHandle"] = agentdata.Handle.ToString(); | ||
1096 | parameters["?currentPos"] = "<" + (agentdata.Position.X).ToString().Replace(",", ".") + "," + (agentdata.Position.Y).ToString().Replace(",", ".") + "," + (agentdata.Position.Z).ToString().Replace(",", ".") + ">"; | ||
1097 | parameters["?currentLookAt"] = "<" + (agentdata.LookAt.X).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Y).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Z).ToString().Replace(",", ".") + ">"; | ||
1098 | |||
1099 | bool returnval = false; | ||
1100 | |||
1101 | try | ||
1102 | { | ||
1103 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
1104 | { | ||
1105 | dbcon.Open(); | ||
1106 | |||
1107 | IDbCommand result = Query(dbcon, sql, parameters); | ||
1108 | |||
1109 | // int x; | ||
1110 | // if ((x = result.ExecuteNonQuery()) > 0) | ||
1111 | // { | ||
1112 | // returnval = true; | ||
1113 | // } | ||
1114 | if (result.ExecuteNonQuery() > 0) | ||
1115 | { | ||
1116 | returnval = true; | ||
1117 | } | ||
1118 | result.Dispose(); | ||
1119 | } | ||
1120 | } | ||
1121 | catch (Exception e) | ||
1122 | { | ||
1123 | m_log.Error(e.ToString()); | ||
1124 | return false; | ||
1125 | } | ||
1126 | |||
1127 | return returnval; | ||
1128 | } | ||
1129 | |||
1130 | /// <summary> | ||
1131 | /// Create (or replace if existing) an avatar appearence | ||
1132 | /// </summary> | ||
1133 | /// <param name="appearance"></param> | ||
1134 | /// <returns>Succes?</returns> | ||
1135 | public bool insertAppearanceRow(AvatarAppearance appearance) | ||
1136 | { | ||
1137 | string sql = String.Empty; | ||
1138 | sql += "REPLACE INTO "; | ||
1139 | sql += "avatarappearance (owner, serial, visual_params, texture, avatar_height, "; | ||
1140 | sql += "body_item, body_asset, skin_item, skin_asset, hair_item, hair_asset, eyes_item, eyes_asset, "; | ||
1141 | sql += "shirt_item, shirt_asset, pants_item, pants_asset, shoes_item, shoes_asset, socks_item, socks_asset, "; | ||
1142 | sql += "jacket_item, jacket_asset, gloves_item, gloves_asset, undershirt_item, undershirt_asset, underpants_item, underpants_asset, "; | ||
1143 | sql += "skirt_item, skirt_asset) values ("; | ||
1144 | sql += "?owner, ?serial, ?visual_params, ?texture, ?avatar_height, "; | ||
1145 | sql += "?body_item, ?body_asset, ?skin_item, ?skin_asset, ?hair_item, ?hair_asset, ?eyes_item, ?eyes_asset, "; | ||
1146 | sql += "?shirt_item, ?shirt_asset, ?pants_item, ?pants_asset, ?shoes_item, ?shoes_asset, ?socks_item, ?socks_asset, "; | ||
1147 | sql += "?jacket_item, ?jacket_asset, ?gloves_item, ?gloves_asset, ?undershirt_item, ?undershirt_asset, ?underpants_item, ?underpants_asset, "; | ||
1148 | sql += "?skirt_item, ?skirt_asset)"; | ||
1149 | |||
1150 | bool returnval = false; | ||
1151 | |||
1152 | // we want to send in byte data, which means we can't just pass down strings | ||
1153 | try | ||
1154 | { | ||
1155 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
1156 | { | ||
1157 | dbcon.Open(); | ||
1158 | |||
1159 | using (MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand()) | ||
1160 | { | ||
1161 | cmd.CommandText = sql; | ||
1162 | cmd.Parameters.AddWithValue("?owner", appearance.Owner.ToString()); | ||
1163 | cmd.Parameters.AddWithValue("?serial", appearance.Serial); | ||
1164 | cmd.Parameters.AddWithValue("?visual_params", appearance.VisualParams); | ||
1165 | cmd.Parameters.AddWithValue("?texture", appearance.Texture.GetBytes()); | ||
1166 | cmd.Parameters.AddWithValue("?avatar_height", appearance.AvatarHeight); | ||
1167 | cmd.Parameters.AddWithValue("?body_item", appearance.BodyItem.ToString()); | ||
1168 | cmd.Parameters.AddWithValue("?body_asset", appearance.BodyAsset.ToString()); | ||
1169 | cmd.Parameters.AddWithValue("?skin_item", appearance.SkinItem.ToString()); | ||
1170 | cmd.Parameters.AddWithValue("?skin_asset", appearance.SkinAsset.ToString()); | ||
1171 | cmd.Parameters.AddWithValue("?hair_item", appearance.HairItem.ToString()); | ||
1172 | cmd.Parameters.AddWithValue("?hair_asset", appearance.HairAsset.ToString()); | ||
1173 | cmd.Parameters.AddWithValue("?eyes_item", appearance.EyesItem.ToString()); | ||
1174 | cmd.Parameters.AddWithValue("?eyes_asset", appearance.EyesAsset.ToString()); | ||
1175 | cmd.Parameters.AddWithValue("?shirt_item", appearance.ShirtItem.ToString()); | ||
1176 | cmd.Parameters.AddWithValue("?shirt_asset", appearance.ShirtAsset.ToString()); | ||
1177 | cmd.Parameters.AddWithValue("?pants_item", appearance.PantsItem.ToString()); | ||
1178 | cmd.Parameters.AddWithValue("?pants_asset", appearance.PantsAsset.ToString()); | ||
1179 | cmd.Parameters.AddWithValue("?shoes_item", appearance.ShoesItem.ToString()); | ||
1180 | cmd.Parameters.AddWithValue("?shoes_asset", appearance.ShoesAsset.ToString()); | ||
1181 | cmd.Parameters.AddWithValue("?socks_item", appearance.SocksItem.ToString()); | ||
1182 | cmd.Parameters.AddWithValue("?socks_asset", appearance.SocksAsset.ToString()); | ||
1183 | cmd.Parameters.AddWithValue("?jacket_item", appearance.JacketItem.ToString()); | ||
1184 | cmd.Parameters.AddWithValue("?jacket_asset", appearance.JacketAsset.ToString()); | ||
1185 | cmd.Parameters.AddWithValue("?gloves_item", appearance.GlovesItem.ToString()); | ||
1186 | cmd.Parameters.AddWithValue("?gloves_asset", appearance.GlovesAsset.ToString()); | ||
1187 | cmd.Parameters.AddWithValue("?undershirt_item", appearance.UnderShirtItem.ToString()); | ||
1188 | cmd.Parameters.AddWithValue("?undershirt_asset", appearance.UnderShirtAsset.ToString()); | ||
1189 | cmd.Parameters.AddWithValue("?underpants_item", appearance.UnderPantsItem.ToString()); | ||
1190 | cmd.Parameters.AddWithValue("?underpants_asset", appearance.UnderPantsAsset.ToString()); | ||
1191 | cmd.Parameters.AddWithValue("?skirt_item", appearance.SkirtItem.ToString()); | ||
1192 | cmd.Parameters.AddWithValue("?skirt_asset", appearance.SkirtAsset.ToString()); | ||
1193 | |||
1194 | if (cmd.ExecuteNonQuery() > 0) | ||
1195 | returnval = true; | ||
1196 | } | ||
1197 | } | ||
1198 | } | ||
1199 | catch (Exception e) | ||
1200 | { | ||
1201 | m_log.Error(e.ToString()); | ||
1202 | return false; | ||
1203 | } | ||
1204 | |||
1205 | return returnval; | ||
1206 | |||
1207 | } | ||
1208 | |||
1209 | public void writeAttachments(UUID agentID, Hashtable data) | ||
1210 | { | ||
1211 | string sql = "delete from avatarattachments where UUID = ?uuid"; | ||
1212 | |||
1213 | using (MySqlConnection dbcon = new MySqlConnection(connectionString)) | ||
1214 | { | ||
1215 | dbcon.Open(); | ||
1216 | |||
1217 | MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
1218 | cmd.CommandText = sql; | ||
1219 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); | ||
1220 | |||
1221 | cmd.ExecuteNonQuery(); | ||
1222 | |||
1223 | if (data == null) | ||
1224 | return; | ||
1225 | |||
1226 | sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attachpoint, ?item, ?asset)"; | ||
1227 | |||
1228 | cmd = (MySqlCommand)dbcon.CreateCommand(); | ||
1229 | cmd.CommandText = sql; | ||
1230 | |||
1231 | foreach (DictionaryEntry e in data) | ||
1232 | { | ||
1233 | int attachpoint = Convert.ToInt32(e.Key); | ||
1234 | |||
1235 | Hashtable item = (Hashtable)e.Value; | ||
1236 | |||
1237 | cmd.Parameters.Clear(); | ||
1238 | cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); | ||
1239 | cmd.Parameters.AddWithValue("?attachpoint", attachpoint); | ||
1240 | cmd.Parameters.AddWithValue("?item", item["item"]); | ||
1241 | cmd.Parameters.AddWithValue("?asset", item["asset"]); | ||
1242 | |||
1243 | cmd.ExecuteNonQuery(); | ||
1244 | } | ||
1245 | } | ||
1246 | } | ||
1247 | } | ||
1248 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLSuperManager.cs b/OpenSim/Data/MySQL/MySQLSuperManager.cs deleted file mode 100644 index c579432..0000000 --- a/OpenSim/Data/MySQL/MySQLSuperManager.cs +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Threading; | ||
29 | |||
30 | namespace OpenSim.Data.MySQL | ||
31 | { | ||
32 | public class MySQLSuperManager | ||
33 | { | ||
34 | public bool Locked; | ||
35 | private readonly Mutex m_lock = new Mutex(false); | ||
36 | public MySQLManager Manager; | ||
37 | public string Running; | ||
38 | |||
39 | public void GetLock() | ||
40 | { | ||
41 | Locked = true; | ||
42 | m_lock.WaitOne(); | ||
43 | } | ||
44 | |||
45 | public void Release() | ||
46 | { | ||
47 | m_lock.ReleaseMutex(); | ||
48 | Locked = false; | ||
49 | } | ||
50 | |||
51 | } | ||
52 | } | ||
diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs deleted file mode 100644 index 0a9d2e3..0000000 --- a/OpenSim/Data/MySQL/MySQLUserData.cs +++ /dev/null | |||
@@ -1,766 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using System.Reflection; | ||
33 | using System.Text.RegularExpressions; | ||
34 | using System.Threading; | ||
35 | using log4net; | ||
36 | using MySql.Data.MySqlClient; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | |||
40 | namespace OpenSim.Data.MySQL | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// A database interface class to a user profile storage system | ||
44 | /// </summary> | ||
45 | public class MySQLUserData : UserDataBase | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private MySQLManager m_database; | ||
50 | private string m_connectionString; | ||
51 | private object m_dbLock = new object(); | ||
52 | |||
53 | public int m_maxConnections = 10; | ||
54 | public int m_lastConnect; | ||
55 | |||
56 | private string m_agentsTableName = "agents"; | ||
57 | private string m_usersTableName = "users"; | ||
58 | private string m_userFriendsTableName = "userfriends"; | ||
59 | private string m_appearanceTableName = "avatarappearance"; | ||
60 | private string m_attachmentsTableName = "avatarattachments"; | ||
61 | |||
62 | public override void Initialise() | ||
63 | { | ||
64 | m_log.Info("[MySQLUserData]: " + Name + " cannot be default-initialized!"); | ||
65 | throw new PluginNotInitialisedException(Name); | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Initialise User Interface | ||
70 | /// Loads and initialises the MySQL storage plugin | ||
71 | /// Warns and uses the obsolete mysql_connection.ini if connect string is empty. | ||
72 | /// Checks for migration | ||
73 | /// </summary> | ||
74 | /// <param name="connect">connect string.</param> | ||
75 | public override void Initialise(string connect) | ||
76 | { | ||
77 | m_connectionString = connect; | ||
78 | m_database = new MySQLManager(connect); | ||
79 | |||
80 | // This actually does the roll forward assembly stuff | ||
81 | Assembly assem = GetType().Assembly; | ||
82 | |||
83 | using (MySql.Data.MySqlClient.MySqlConnection dbcon = new MySql.Data.MySqlClient.MySqlConnection(m_connectionString)) | ||
84 | { | ||
85 | dbcon.Open(); | ||
86 | Migration m = new Migration(dbcon, assem, "UserStore"); | ||
87 | m.Update(); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | public override void Dispose() | ||
92 | { | ||
93 | } | ||
94 | |||
95 | // see IUserDataPlugin | ||
96 | public override UserProfileData GetUserByName(string user, string last) | ||
97 | { | ||
98 | try | ||
99 | { | ||
100 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
101 | param["?first"] = user; | ||
102 | param["?second"] = last; | ||
103 | |||
104 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
105 | { | ||
106 | dbcon.Open(); | ||
107 | |||
108 | using (IDbCommand result = m_database.Query(dbcon, | ||
109 | "SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param)) | ||
110 | { | ||
111 | using (IDataReader reader = result.ExecuteReader()) | ||
112 | { | ||
113 | UserProfileData row = m_database.readUserRow(reader); | ||
114 | return row; | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | catch (Exception e) | ||
120 | { | ||
121 | m_log.Error(e.Message, e); | ||
122 | return null; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | #region User Friends List Data | ||
127 | |||
128 | public override void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
129 | { | ||
130 | int dtvalue = Util.UnixTimeSinceEpoch(); | ||
131 | |||
132 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
133 | param["?ownerID"] = friendlistowner.ToString(); | ||
134 | param["?friendID"] = friend.ToString(); | ||
135 | param["?friendPerms"] = perms.ToString(); | ||
136 | param["?datetimestamp"] = dtvalue.ToString(); | ||
137 | |||
138 | try | ||
139 | { | ||
140 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
141 | { | ||
142 | dbcon.Open(); | ||
143 | |||
144 | using (IDbCommand adder = m_database.Query(dbcon, | ||
145 | "INSERT INTO `" + m_userFriendsTableName + "` " + | ||
146 | "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " + | ||
147 | "VALUES " + | ||
148 | "(?ownerID,?friendID,?friendPerms,?datetimestamp)", | ||
149 | param)) | ||
150 | { | ||
151 | adder.ExecuteNonQuery(); | ||
152 | } | ||
153 | |||
154 | using (IDbCommand adder = m_database.Query(dbcon, | ||
155 | "INSERT INTO `" + m_userFriendsTableName + "` " + | ||
156 | "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " + | ||
157 | "VALUES " + | ||
158 | "(?friendID,?ownerID,?friendPerms,?datetimestamp)", | ||
159 | param)) | ||
160 | { | ||
161 | adder.ExecuteNonQuery(); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | catch (Exception e) | ||
166 | { | ||
167 | m_log.Error(e.Message, e); | ||
168 | return; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | public override void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
173 | { | ||
174 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
175 | param["?ownerID"] = friendlistowner.ToString(); | ||
176 | param["?friendID"] = friend.ToString(); | ||
177 | |||
178 | try | ||
179 | { | ||
180 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
181 | { | ||
182 | dbcon.Open(); | ||
183 | |||
184 | using (IDbCommand updater = m_database.Query(dbcon, | ||
185 | "delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID", | ||
186 | param)) | ||
187 | { | ||
188 | updater.ExecuteNonQuery(); | ||
189 | } | ||
190 | |||
191 | using (IDbCommand updater = m_database.Query(dbcon, | ||
192 | "delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID", | ||
193 | param)) | ||
194 | { | ||
195 | updater.ExecuteNonQuery(); | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | catch (Exception e) | ||
200 | { | ||
201 | m_log.Error(e.Message, e); | ||
202 | return; | ||
203 | } | ||
204 | } | ||
205 | |||
206 | public override void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
207 | { | ||
208 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
209 | param["?ownerID"] = friendlistowner.ToString(); | ||
210 | param["?friendID"] = friend.ToString(); | ||
211 | param["?friendPerms"] = perms.ToString(); | ||
212 | |||
213 | try | ||
214 | { | ||
215 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
216 | { | ||
217 | dbcon.Open(); | ||
218 | |||
219 | using (IDbCommand updater = m_database.Query(dbcon, | ||
220 | "update " + m_userFriendsTableName + | ||
221 | " SET friendPerms = ?friendPerms " + | ||
222 | "where ownerID = ?ownerID and friendID = ?friendID", | ||
223 | param)) | ||
224 | { | ||
225 | updater.ExecuteNonQuery(); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | catch (Exception e) | ||
230 | { | ||
231 | m_log.Error(e.Message, e); | ||
232 | return; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | public override List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
237 | { | ||
238 | List<FriendListItem> Lfli = new List<FriendListItem>(); | ||
239 | |||
240 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
241 | param["?ownerID"] = friendlistowner.ToString(); | ||
242 | |||
243 | try | ||
244 | { | ||
245 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
246 | { | ||
247 | dbcon.Open(); | ||
248 | |||
249 | //Left Join userfriends to itself | ||
250 | using (IDbCommand result = m_database.Query(dbcon, | ||
251 | "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + | ||
252 | m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" + | ||
253 | " where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID", | ||
254 | param)) | ||
255 | { | ||
256 | using (IDataReader reader = result.ExecuteReader()) | ||
257 | { | ||
258 | while (reader.Read()) | ||
259 | { | ||
260 | FriendListItem fli = new FriendListItem(); | ||
261 | fli.FriendListOwner = new UUID((string)reader["ownerID"]); | ||
262 | fli.Friend = new UUID((string)reader["friendID"]); | ||
263 | fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]); | ||
264 | |||
265 | // This is not a real column in the database table, it's a joined column from the opposite record | ||
266 | fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); | ||
267 | |||
268 | Lfli.Add(fli); | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | catch (Exception e) | ||
275 | { | ||
276 | m_log.Error(e.Message, e); | ||
277 | return Lfli; | ||
278 | } | ||
279 | |||
280 | return Lfli; | ||
281 | } | ||
282 | |||
283 | override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids) | ||
284 | { | ||
285 | Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>(); | ||
286 | |||
287 | try | ||
288 | { | ||
289 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
290 | { | ||
291 | dbcon.Open(); | ||
292 | |||
293 | foreach (UUID uuid in uuids) | ||
294 | { | ||
295 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
296 | param["?uuid"] = uuid.ToString(); | ||
297 | |||
298 | using (IDbCommand result = m_database.Query(dbcon, "select agentOnline,currentHandle from " + m_agentsTableName + | ||
299 | " where UUID = ?uuid", param)) | ||
300 | { | ||
301 | using (IDataReader reader = result.ExecuteReader()) | ||
302 | { | ||
303 | while (reader.Read()) | ||
304 | { | ||
305 | FriendRegionInfo fri = new FriendRegionInfo(); | ||
306 | fri.isOnline = (sbyte)reader["agentOnline"] != 0; | ||
307 | fri.regionHandle = (ulong)reader["currentHandle"]; | ||
308 | |||
309 | infos[uuid] = fri; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | catch (Exception e) | ||
317 | { | ||
318 | m_log.Warn("[MYSQL]: Got exception on trying to find friends regions:", e); | ||
319 | m_log.Error(e.Message, e); | ||
320 | } | ||
321 | |||
322 | return infos; | ||
323 | } | ||
324 | |||
325 | #endregion | ||
326 | |||
327 | public override List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) | ||
328 | { | ||
329 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
330 | |||
331 | Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]"); | ||
332 | |||
333 | string[] querysplit; | ||
334 | querysplit = query.Split(' '); | ||
335 | if (querysplit.Length > 1 && querysplit[1].Trim() != String.Empty) | ||
336 | { | ||
337 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
338 | param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%"; | ||
339 | param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], String.Empty) + "%"; | ||
340 | |||
341 | try | ||
342 | { | ||
343 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
344 | { | ||
345 | dbcon.Open(); | ||
346 | |||
347 | using (IDbCommand result = m_database.Query(dbcon, | ||
348 | "SELECT UUID,username,lastname FROM " + m_usersTableName + | ||
349 | " WHERE username like ?first AND lastname like ?second LIMIT 100", | ||
350 | param)) | ||
351 | { | ||
352 | using (IDataReader reader = result.ExecuteReader()) | ||
353 | { | ||
354 | while (reader.Read()) | ||
355 | { | ||
356 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
357 | user.AvatarID = new UUID((string)reader["UUID"]); | ||
358 | user.firstName = (string)reader["username"]; | ||
359 | user.lastName = (string)reader["lastname"]; | ||
360 | returnlist.Add(user); | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | } | ||
365 | } | ||
366 | catch (Exception e) | ||
367 | { | ||
368 | m_log.Error(e.Message, e); | ||
369 | return returnlist; | ||
370 | } | ||
371 | } | ||
372 | else | ||
373 | { | ||
374 | try | ||
375 | { | ||
376 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
377 | param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%"; | ||
378 | |||
379 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
380 | { | ||
381 | dbcon.Open(); | ||
382 | |||
383 | using (IDbCommand result = m_database.Query(dbcon, | ||
384 | "SELECT UUID,username,lastname FROM " + m_usersTableName + | ||
385 | " WHERE username like ?first OR lastname like ?first LIMIT 100", | ||
386 | param)) | ||
387 | { | ||
388 | using (IDataReader reader = result.ExecuteReader()) | ||
389 | { | ||
390 | while (reader.Read()) | ||
391 | { | ||
392 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
393 | user.AvatarID = new UUID((string)reader["UUID"]); | ||
394 | user.firstName = (string)reader["username"]; | ||
395 | user.lastName = (string)reader["lastname"]; | ||
396 | returnlist.Add(user); | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | } | ||
401 | } | ||
402 | catch (Exception e) | ||
403 | { | ||
404 | m_log.Error(e.Message, e); | ||
405 | return returnlist; | ||
406 | } | ||
407 | } | ||
408 | return returnlist; | ||
409 | } | ||
410 | |||
411 | /// <summary> | ||
412 | /// See IUserDataPlugin | ||
413 | /// </summary> | ||
414 | /// <param name="uuid">User UUID</param> | ||
415 | /// <returns>User profile data</returns> | ||
416 | public override UserProfileData GetUserByUUID(UUID uuid) | ||
417 | { | ||
418 | try | ||
419 | { | ||
420 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
421 | param["?uuid"] = uuid.ToString(); | ||
422 | |||
423 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
424 | { | ||
425 | dbcon.Open(); | ||
426 | |||
427 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param)) | ||
428 | { | ||
429 | using (IDataReader reader = result.ExecuteReader()) | ||
430 | { | ||
431 | UserProfileData row = m_database.readUserRow(reader); | ||
432 | return row; | ||
433 | } | ||
434 | } | ||
435 | } | ||
436 | } | ||
437 | catch (Exception e) | ||
438 | { | ||
439 | m_log.Error(e.Message, e); | ||
440 | return null; | ||
441 | } | ||
442 | } | ||
443 | |||
444 | /// <summary> | ||
445 | /// Returns a user session searching by name | ||
446 | /// </summary> | ||
447 | /// <param name="name">The account name : "Username Lastname"</param> | ||
448 | /// <returns>The users session</returns> | ||
449 | public override UserAgentData GetAgentByName(string name) | ||
450 | { | ||
451 | return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
452 | } | ||
453 | |||
454 | /// <summary> | ||
455 | /// Returns a user session by account name | ||
456 | /// </summary> | ||
457 | /// <param name="user">First part of the users account name</param> | ||
458 | /// <param name="last">Second part of the users account name</param> | ||
459 | /// <returns>The users session</returns> | ||
460 | public override UserAgentData GetAgentByName(string user, string last) | ||
461 | { | ||
462 | UserProfileData profile = GetUserByName(user, last); | ||
463 | return GetAgentByUUID(profile.ID); | ||
464 | } | ||
465 | |||
466 | /// <summary> | ||
467 | /// </summary> | ||
468 | /// <param name="AgentID"></param> | ||
469 | /// <param name="WebLoginKey"></param> | ||
470 | /// <remarks>is it still used ?</remarks> | ||
471 | public override void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey) | ||
472 | { | ||
473 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
474 | param["?UUID"] = AgentID.ToString(); | ||
475 | param["?webLoginKey"] = WebLoginKey.ToString(); | ||
476 | |||
477 | try | ||
478 | { | ||
479 | m_database.ExecuteParameterizedSql( | ||
480 | "update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " + | ||
481 | "where UUID = ?UUID", | ||
482 | param); | ||
483 | } | ||
484 | catch (Exception e) | ||
485 | { | ||
486 | m_log.Error(e.Message, e); | ||
487 | return; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | /// <summary> | ||
492 | /// Returns an agent session by account UUID | ||
493 | /// </summary> | ||
494 | /// <param name="uuid">The accounts UUID</param> | ||
495 | /// <returns>The users session</returns> | ||
496 | public override UserAgentData GetAgentByUUID(UUID uuid) | ||
497 | { | ||
498 | try | ||
499 | { | ||
500 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
501 | param["?uuid"] = uuid.ToString(); | ||
502 | |||
503 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
504 | { | ||
505 | dbcon.Open(); | ||
506 | |||
507 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid", param)) | ||
508 | { | ||
509 | using (IDataReader reader = result.ExecuteReader()) | ||
510 | { | ||
511 | UserAgentData row = m_database.readAgentRow(reader); | ||
512 | return row; | ||
513 | } | ||
514 | } | ||
515 | } | ||
516 | } | ||
517 | catch (Exception e) | ||
518 | { | ||
519 | m_log.Error(e.Message, e); | ||
520 | return null; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | /// <summary> | ||
525 | /// Creates a new users profile | ||
526 | /// </summary> | ||
527 | /// <param name="user">The user profile to create</param> | ||
528 | public override void AddNewUserProfile(UserProfileData user) | ||
529 | { | ||
530 | UUID zero = UUID.Zero; | ||
531 | if (user.ID == zero) | ||
532 | { | ||
533 | return; | ||
534 | } | ||
535 | |||
536 | try | ||
537 | { | ||
538 | m_database.insertUserRow( | ||
539 | user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt, | ||
540 | user.HomeRegion, user.HomeRegionID, user.HomeLocation.X, user.HomeLocation.Y, | ||
541 | user.HomeLocation.Z, | ||
542 | user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created, | ||
543 | user.LastLogin, user.UserInventoryURI, user.UserAssetURI, | ||
544 | user.CanDoMask, user.WantDoMask, | ||
545 | user.AboutText, user.FirstLifeAboutText, user.Image, | ||
546 | user.FirstLifeImage, user.WebLoginKey, user.UserFlags, user.GodLevel, user.CustomType, user.Partner); | ||
547 | } | ||
548 | catch (Exception e) | ||
549 | { | ||
550 | m_log.Error(e.Message, e); | ||
551 | } | ||
552 | } | ||
553 | |||
554 | /// <summary> | ||
555 | /// Creates a new agent | ||
556 | /// </summary> | ||
557 | /// <param name="agent">The agent to create</param> | ||
558 | public override void AddNewUserAgent(UserAgentData agent) | ||
559 | { | ||
560 | UUID zero = UUID.Zero; | ||
561 | if (agent.ProfileID == zero || agent.SessionID == zero) | ||
562 | return; | ||
563 | |||
564 | try | ||
565 | { | ||
566 | m_database.insertAgentRow(agent); | ||
567 | } | ||
568 | catch (Exception e) | ||
569 | { | ||
570 | m_log.Error(e.Message, e); | ||
571 | } | ||
572 | } | ||
573 | |||
574 | /// <summary> | ||
575 | /// Updates a user profile stored in the DB | ||
576 | /// </summary> | ||
577 | /// <param name="user">The profile data to use to update the DB</param> | ||
578 | public override bool UpdateUserProfile(UserProfileData user) | ||
579 | { | ||
580 | try | ||
581 | { | ||
582 | m_database.updateUserRow( | ||
583 | user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt, | ||
584 | user.HomeRegion, user.HomeRegionID, user.HomeLocation.X, user.HomeLocation.Y, | ||
585 | user.HomeLocation.Z, user.HomeLookAt.X, | ||
586 | user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created, user.LastLogin, | ||
587 | user.UserInventoryURI, | ||
588 | user.UserAssetURI, user.CanDoMask, user.WantDoMask, user.AboutText, | ||
589 | user.FirstLifeAboutText, user.Image, user.FirstLifeImage, user.WebLoginKey, | ||
590 | user.UserFlags, user.GodLevel, user.CustomType, user.Partner); | ||
591 | |||
592 | return true; | ||
593 | } | ||
594 | catch | ||
595 | { | ||
596 | return false; | ||
597 | } | ||
598 | } | ||
599 | |||
600 | /// <summary> | ||
601 | /// Performs a money transfer request between two accounts | ||
602 | /// </summary> | ||
603 | /// <param name="from">The senders account ID</param> | ||
604 | /// <param name="to">The receivers account ID</param> | ||
605 | /// <param name="amount">The amount to transfer</param> | ||
606 | /// <returns>Success?</returns> | ||
607 | public override bool MoneyTransferRequest(UUID from, UUID to, uint amount) | ||
608 | { | ||
609 | return false; | ||
610 | } | ||
611 | |||
612 | /// <summary> | ||
613 | /// Performs an inventory transfer request between two accounts | ||
614 | /// </summary> | ||
615 | /// <remarks>TODO: Move to inventory server</remarks> | ||
616 | /// <param name="from">The senders account ID</param> | ||
617 | /// <param name="to">The receivers account ID</param> | ||
618 | /// <param name="item">The item to transfer</param> | ||
619 | /// <returns>Success?</returns> | ||
620 | public override bool InventoryTransferRequest(UUID from, UUID to, UUID item) | ||
621 | { | ||
622 | return false; | ||
623 | } | ||
624 | |||
625 | public override AvatarAppearance GetUserAppearance(UUID user) | ||
626 | { | ||
627 | try | ||
628 | { | ||
629 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
630 | param["?owner"] = user.ToString(); | ||
631 | |||
632 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
633 | { | ||
634 | dbcon.Open(); | ||
635 | |||
636 | using (IDbCommand result = m_database.Query(dbcon, "SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param)) | ||
637 | { | ||
638 | using (IDataReader reader = result.ExecuteReader()) | ||
639 | { | ||
640 | AvatarAppearance appearance = m_database.readAppearanceRow(reader); | ||
641 | |||
642 | if (appearance == null) | ||
643 | { | ||
644 | m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString()); | ||
645 | return null; | ||
646 | } | ||
647 | else | ||
648 | { | ||
649 | appearance.SetAttachments(GetUserAttachments(user)); | ||
650 | return appearance; | ||
651 | } | ||
652 | } | ||
653 | } | ||
654 | } | ||
655 | } | ||
656 | catch (Exception e) | ||
657 | { | ||
658 | m_log.Error(e.Message, e); | ||
659 | return null; | ||
660 | } | ||
661 | } | ||
662 | |||
663 | /// <summary> | ||
664 | /// Updates an avatar appearence | ||
665 | /// </summary> | ||
666 | /// <param name="user">The user UUID</param> | ||
667 | /// <param name="appearance">The avatar appearance</param> | ||
668 | // override | ||
669 | public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance) | ||
670 | { | ||
671 | try | ||
672 | { | ||
673 | appearance.Owner = user; | ||
674 | m_database.insertAppearanceRow(appearance); | ||
675 | |||
676 | UpdateUserAttachments(user, appearance.GetAttachments()); | ||
677 | } | ||
678 | catch (Exception e) | ||
679 | { | ||
680 | m_log.Error(e.Message, e); | ||
681 | } | ||
682 | } | ||
683 | |||
684 | /// <summary> | ||
685 | /// Database provider name | ||
686 | /// </summary> | ||
687 | /// <returns>Provider name</returns> | ||
688 | public override string Name | ||
689 | { | ||
690 | get { return "MySQL Userdata Interface"; } | ||
691 | } | ||
692 | |||
693 | /// <summary> | ||
694 | /// Database provider version | ||
695 | /// </summary> | ||
696 | /// <returns>provider version</returns> | ||
697 | public override string Version | ||
698 | { | ||
699 | get { return "0.1"; } | ||
700 | } | ||
701 | |||
702 | public Hashtable GetUserAttachments(UUID agentID) | ||
703 | { | ||
704 | Dictionary<string, object> param = new Dictionary<string, object>(); | ||
705 | param["?uuid"] = agentID.ToString(); | ||
706 | |||
707 | try | ||
708 | { | ||
709 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | ||
710 | { | ||
711 | dbcon.Open(); | ||
712 | |||
713 | using (IDbCommand result = m_database.Query(dbcon, | ||
714 | "SELECT attachpoint, item, asset from " + m_attachmentsTableName + " WHERE UUID = ?uuid", param)) | ||
715 | { | ||
716 | using (IDataReader reader = result.ExecuteReader()) | ||
717 | { | ||
718 | Hashtable ret = m_database.readAttachments(reader); | ||
719 | return ret; | ||
720 | } | ||
721 | } | ||
722 | } | ||
723 | } | ||
724 | catch (Exception e) | ||
725 | { | ||
726 | m_log.Error(e.Message, e); | ||
727 | return null; | ||
728 | } | ||
729 | } | ||
730 | |||
731 | public void UpdateUserAttachments(UUID agentID, Hashtable data) | ||
732 | { | ||
733 | m_database.writeAttachments(agentID, data); | ||
734 | } | ||
735 | |||
736 | public override void ResetAttachments(UUID userID) | ||
737 | { | ||
738 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
739 | param["?uuid"] = userID.ToString(); | ||
740 | |||
741 | m_database.ExecuteParameterizedSql( | ||
742 | "UPDATE " + m_attachmentsTableName + | ||
743 | " SET asset = '00000000-0000-0000-0000-000000000000' WHERE UUID = ?uuid", | ||
744 | param); | ||
745 | } | ||
746 | |||
747 | public override void LogoutUsers(UUID regionID) | ||
748 | { | ||
749 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
750 | param["?regionID"] = regionID.ToString(); | ||
751 | |||
752 | try | ||
753 | { | ||
754 | m_database.ExecuteParameterizedSql( | ||
755 | "update " + m_agentsTableName + " SET agentOnline = 0 " + | ||
756 | "where currentRegion = ?regionID", | ||
757 | param); | ||
758 | } | ||
759 | catch (Exception e) | ||
760 | { | ||
761 | m_log.Error(e.Message, e); | ||
762 | return; | ||
763 | } | ||
764 | } | ||
765 | } | ||
766 | } | ||
diff --git a/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs b/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs index e1d3f81..a46fdf8 100644 --- a/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs +++ b/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs | |||
@@ -31,6 +31,7 @@ using OpenSim.Data.Tests; | |||
31 | using log4net; | 31 | using log4net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Tests.Common; | 33 | using OpenSim.Tests.Common; |
34 | using MySql.Data.MySqlClient; | ||
34 | 35 | ||
35 | namespace OpenSim.Data.MySQL.Tests | 36 | namespace OpenSim.Data.MySQL.Tests |
36 | { | 37 | { |
@@ -39,7 +40,7 @@ namespace OpenSim.Data.MySQL.Tests | |||
39 | { | 40 | { |
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | public string file; | 42 | public string file; |
42 | public MySQLManager database; | 43 | private string m_connectionString; |
43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | 44 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; |
44 | 45 | ||
45 | [TestFixtureSetUp] | 46 | [TestFixtureSetUp] |
@@ -52,7 +53,6 @@ namespace OpenSim.Data.MySQL.Tests | |||
52 | // tests. | 53 | // tests. |
53 | try | 54 | try |
54 | { | 55 | { |
55 | database = new MySQLManager(connect); | ||
56 | db = new MySQLAssetData(); | 56 | db = new MySQLAssetData(); |
57 | db.Initialise(connect); | 57 | db.Initialise(connect); |
58 | } | 58 | } |
@@ -70,10 +70,22 @@ namespace OpenSim.Data.MySQL.Tests | |||
70 | { | 70 | { |
71 | db.Dispose(); | 71 | db.Dispose(); |
72 | } | 72 | } |
73 | if (database != null) | 73 | ExecuteSql("drop table migrations"); |
74 | ExecuteSql("drop table assets"); | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// Execute a MySqlCommand | ||
79 | /// </summary> | ||
80 | /// <param name="sql">sql string to execute</param> | ||
81 | private void ExecuteSql(string sql) | ||
82 | { | ||
83 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | ||
74 | { | 84 | { |
75 | database.ExecuteSql("drop table migrations"); | 85 | dbcon.Open(); |
76 | database.ExecuteSql("drop table assets"); | 86 | |
87 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); | ||
88 | cmd.ExecuteNonQuery(); | ||
77 | } | 89 | } |
78 | } | 90 | } |
79 | } | 91 | } |
diff --git a/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs b/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs index 48486b1..01afcae 100644 --- a/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs +++ b/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs | |||
@@ -31,6 +31,8 @@ using OpenSim.Data.Tests; | |||
31 | using log4net; | 31 | using log4net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Tests.Common; | 33 | using OpenSim.Tests.Common; |
34 | using MySql.Data.MySqlClient; | ||
35 | |||
34 | 36 | ||
35 | namespace OpenSim.Data.MySQL.Tests | 37 | namespace OpenSim.Data.MySQL.Tests |
36 | { | 38 | { |
@@ -39,7 +41,6 @@ namespace OpenSim.Data.MySQL.Tests | |||
39 | { | 41 | { |
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | public string file; | 43 | public string file; |
42 | public MySQLManager database; | ||
43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | 44 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; |
44 | 45 | ||
45 | [TestFixtureSetUp] | 46 | [TestFixtureSetUp] |
@@ -52,9 +53,8 @@ namespace OpenSim.Data.MySQL.Tests | |||
52 | // tests. | 53 | // tests. |
53 | try | 54 | try |
54 | { | 55 | { |
55 | database = new MySQLManager(connect); | ||
56 | // clear db incase to ensure we are in a clean state | 56 | // clear db incase to ensure we are in a clean state |
57 | ClearDB(database); | 57 | ClearDB(); |
58 | 58 | ||
59 | regionDb = new MySQLDataStore(); | 59 | regionDb = new MySQLDataStore(); |
60 | regionDb.Initialise(connect); | 60 | regionDb.Initialise(connect); |
@@ -75,29 +75,41 @@ namespace OpenSim.Data.MySQL.Tests | |||
75 | { | 75 | { |
76 | regionDb.Dispose(); | 76 | regionDb.Dispose(); |
77 | } | 77 | } |
78 | ClearDB(database); | 78 | ClearDB(); |
79 | } | 79 | } |
80 | 80 | ||
81 | private void ClearDB(MySQLManager manager) | 81 | private void ClearDB() |
82 | { | 82 | { |
83 | // if a new table is added, it has to be dropped here | 83 | // if a new table is added, it has to be dropped here |
84 | if (manager != null) | 84 | ExecuteSql("drop table if exists migrations"); |
85 | ExecuteSql("drop table if exists prims"); | ||
86 | ExecuteSql("drop table if exists primshapes"); | ||
87 | ExecuteSql("drop table if exists primitems"); | ||
88 | ExecuteSql("drop table if exists terrain"); | ||
89 | ExecuteSql("drop table if exists land"); | ||
90 | ExecuteSql("drop table if exists landaccesslist"); | ||
91 | ExecuteSql("drop table if exists regionban"); | ||
92 | ExecuteSql("drop table if exists regionsettings"); | ||
93 | ExecuteSql("drop table if exists estate_managers"); | ||
94 | ExecuteSql("drop table if exists estate_groups"); | ||
95 | ExecuteSql("drop table if exists estate_users"); | ||
96 | ExecuteSql("drop table if exists estateban"); | ||
97 | ExecuteSql("drop table if exists estate_settings"); | ||
98 | ExecuteSql("drop table if exists estate_map"); | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Execute a MySqlCommand | ||
103 | /// </summary> | ||
104 | /// <param name="sql">sql string to execute</param> | ||
105 | private void ExecuteSql(string sql) | ||
106 | { | ||
107 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | ||
85 | { | 108 | { |
86 | manager.ExecuteSql("drop table if exists migrations"); | 109 | dbcon.Open(); |
87 | manager.ExecuteSql("drop table if exists prims"); | 110 | |
88 | manager.ExecuteSql("drop table if exists primshapes"); | 111 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); |
89 | manager.ExecuteSql("drop table if exists primitems"); | 112 | cmd.ExecuteNonQuery(); |
90 | manager.ExecuteSql("drop table if exists terrain"); | ||
91 | manager.ExecuteSql("drop table if exists land"); | ||
92 | manager.ExecuteSql("drop table if exists landaccesslist"); | ||
93 | manager.ExecuteSql("drop table if exists regionban"); | ||
94 | manager.ExecuteSql("drop table if exists regionsettings"); | ||
95 | manager.ExecuteSql("drop table if exists estate_managers"); | ||
96 | manager.ExecuteSql("drop table if exists estate_groups"); | ||
97 | manager.ExecuteSql("drop table if exists estate_users"); | ||
98 | manager.ExecuteSql("drop table if exists estateban"); | ||
99 | manager.ExecuteSql("drop table if exists estate_settings"); | ||
100 | manager.ExecuteSql("drop table if exists estate_map"); | ||
101 | } | 113 | } |
102 | } | 114 | } |
103 | } | 115 | } |
diff --git a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs b/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs deleted file mode 100644 index 8272316..0000000 --- a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Data.Tests; | ||
31 | using log4net; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Tests.Common; | ||
34 | using MySql.Data.MySqlClient; | ||
35 | |||
36 | namespace OpenSim.Data.MySQL.Tests | ||
37 | { | ||
38 | [TestFixture, DatabaseTest] | ||
39 | public class MySQLGridTest : BasicGridTest | ||
40 | { | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | public string file; | ||
44 | public MySQLManager database; | ||
45 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | ||
46 | |||
47 | [TestFixtureSetUp] | ||
48 | public void Init() | ||
49 | { | ||
50 | SuperInit(); | ||
51 | // If we manage to connect to the database with the user | ||
52 | // and password above it is our test database, and run | ||
53 | // these tests. If anything goes wrong, ignore these | ||
54 | // tests. | ||
55 | try | ||
56 | { | ||
57 | database = new MySQLManager(connect); | ||
58 | db = new MySQLGridData(); | ||
59 | db.Initialise(connect); | ||
60 | } | ||
61 | catch (Exception e) | ||
62 | { | ||
63 | m_log.Error("Exception {0}", e); | ||
64 | Assert.Ignore(); | ||
65 | } | ||
66 | |||
67 | // This actually does the roll forward assembly stuff | ||
68 | Assembly assem = GetType().Assembly; | ||
69 | |||
70 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | ||
71 | { | ||
72 | dbcon.Open(); | ||
73 | Migration m = new Migration(dbcon, assem, "AssetStore"); | ||
74 | m.Update(); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | [TestFixtureTearDown] | ||
79 | public void Cleanup() | ||
80 | { | ||
81 | m_log.Warn("Cleaning up."); | ||
82 | if (db != null) | ||
83 | { | ||
84 | db.Dispose(); | ||
85 | } | ||
86 | // if a new table is added, it has to be dropped here | ||
87 | if (database != null) | ||
88 | { | ||
89 | database.ExecuteSql("drop table migrations"); | ||
90 | database.ExecuteSql("drop table regions"); | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | } | ||
diff --git a/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs b/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs index a3a32dc..4575493 100644 --- a/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs +++ b/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs | |||
@@ -31,6 +31,8 @@ using OpenSim.Data.Tests; | |||
31 | using log4net; | 31 | using log4net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Tests.Common; | 33 | using OpenSim.Tests.Common; |
34 | using MySql.Data.MySqlClient; | ||
35 | |||
34 | 36 | ||
35 | namespace OpenSim.Data.MySQL.Tests | 37 | namespace OpenSim.Data.MySQL.Tests |
36 | { | 38 | { |
@@ -39,7 +41,6 @@ namespace OpenSim.Data.MySQL.Tests | |||
39 | { | 41 | { |
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | public string file; | 43 | public string file; |
42 | public MySQLManager database; | ||
43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | 44 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; |
44 | 45 | ||
45 | [TestFixtureSetUp] | 46 | [TestFixtureSetUp] |
@@ -52,7 +53,6 @@ namespace OpenSim.Data.MySQL.Tests | |||
52 | // tests. | 53 | // tests. |
53 | try | 54 | try |
54 | { | 55 | { |
55 | database = new MySQLManager(connect); | ||
56 | DropTables(); | 56 | DropTables(); |
57 | db = new MySQLInventoryData(); | 57 | db = new MySQLInventoryData(); |
58 | db.Initialise(connect); | 58 | db.Initialise(connect); |
@@ -71,17 +71,29 @@ namespace OpenSim.Data.MySQL.Tests | |||
71 | { | 71 | { |
72 | db.Dispose(); | 72 | db.Dispose(); |
73 | } | 73 | } |
74 | if (database != null) | 74 | DropTables(); |
75 | { | ||
76 | DropTables(); | ||
77 | } | ||
78 | } | 75 | } |
79 | 76 | ||
80 | private void DropTables() | 77 | private void DropTables() |
81 | { | 78 | { |
82 | database.ExecuteSql("drop table IF EXISTS inventoryitems"); | 79 | ExecuteSql("drop table IF EXISTS inventoryitems"); |
83 | database.ExecuteSql("drop table IF EXISTS inventoryfolders"); | 80 | ExecuteSql("drop table IF EXISTS inventoryfolders"); |
84 | database.ExecuteSql("drop table IF EXISTS migrations"); | 81 | ExecuteSql("drop table IF EXISTS migrations"); |
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// Execute a MySqlCommand | ||
86 | /// </summary> | ||
87 | /// <param name="sql">sql string to execute</param> | ||
88 | private void ExecuteSql(string sql) | ||
89 | { | ||
90 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | ||
91 | { | ||
92 | dbcon.Open(); | ||
93 | |||
94 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); | ||
95 | cmd.ExecuteNonQuery(); | ||
96 | } | ||
85 | } | 97 | } |
86 | } | 98 | } |
87 | } | 99 | } |
diff --git a/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs b/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs index 0dc8b7d..e7e57e4 100644 --- a/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs +++ b/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs | |||
@@ -31,6 +31,7 @@ using OpenSim.Data.Tests; | |||
31 | using log4net; | 31 | using log4net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using OpenSim.Tests.Common; | 33 | using OpenSim.Tests.Common; |
34 | using MySql.Data.MySqlClient; | ||
34 | 35 | ||
35 | namespace OpenSim.Data.MySQL.Tests | 36 | namespace OpenSim.Data.MySQL.Tests |
36 | { | 37 | { |
@@ -39,7 +40,6 @@ namespace OpenSim.Data.MySQL.Tests | |||
39 | { | 40 | { |
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
41 | public string file; | 42 | public string file; |
42 | public MySQLManager database; | ||
43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | 43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; |
44 | 44 | ||
45 | [TestFixtureSetUp] | 45 | [TestFixtureSetUp] |
@@ -52,9 +52,8 @@ namespace OpenSim.Data.MySQL.Tests | |||
52 | // tests. | 52 | // tests. |
53 | try | 53 | try |
54 | { | 54 | { |
55 | database = new MySQLManager(connect); | ||
56 | // this is important in case a previous run ended badly | 55 | // this is important in case a previous run ended badly |
57 | ClearDB(database); | 56 | ClearDB(); |
58 | 57 | ||
59 | db = new MySQLDataStore(); | 58 | db = new MySQLDataStore(); |
60 | db.Initialise(connect); | 59 | db.Initialise(connect); |
@@ -73,28 +72,40 @@ namespace OpenSim.Data.MySQL.Tests | |||
73 | { | 72 | { |
74 | db.Dispose(); | 73 | db.Dispose(); |
75 | } | 74 | } |
76 | ClearDB(database); | 75 | ClearDB(); |
77 | } | 76 | } |
78 | 77 | ||
79 | private void ClearDB(MySQLManager manager) | 78 | private void ClearDB() |
80 | { | 79 | { |
81 | if (manager != null) | 80 | ExecuteSql("drop table if exists migrations"); |
81 | ExecuteSql("drop table if exists prims"); | ||
82 | ExecuteSql("drop table if exists primshapes"); | ||
83 | ExecuteSql("drop table if exists primitems"); | ||
84 | ExecuteSql("drop table if exists terrain"); | ||
85 | ExecuteSql("drop table if exists land"); | ||
86 | ExecuteSql("drop table if exists landaccesslist"); | ||
87 | ExecuteSql("drop table if exists regionban"); | ||
88 | ExecuteSql("drop table if exists regionsettings"); | ||
89 | ExecuteSql("drop table if exists estate_managers"); | ||
90 | ExecuteSql("drop table if exists estate_groups"); | ||
91 | ExecuteSql("drop table if exists estate_users"); | ||
92 | ExecuteSql("drop table if exists estateban"); | ||
93 | ExecuteSql("drop table if exists estate_settings"); | ||
94 | ExecuteSql("drop table if exists estate_map"); | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Execute a MySqlCommand | ||
99 | /// </summary> | ||
100 | /// <param name="sql">sql string to execute</param> | ||
101 | private void ExecuteSql(string sql) | ||
102 | { | ||
103 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | ||
82 | { | 104 | { |
83 | manager.ExecuteSql("drop table if exists migrations"); | 105 | dbcon.Open(); |
84 | manager.ExecuteSql("drop table if exists prims"); | 106 | |
85 | manager.ExecuteSql("drop table if exists primshapes"); | 107 | MySqlCommand cmd = new MySqlCommand(sql, dbcon); |
86 | manager.ExecuteSql("drop table if exists primitems"); | 108 | cmd.ExecuteNonQuery(); |
87 | manager.ExecuteSql("drop table if exists terrain"); | ||
88 | manager.ExecuteSql("drop table if exists land"); | ||
89 | manager.ExecuteSql("drop table if exists landaccesslist"); | ||
90 | manager.ExecuteSql("drop table if exists regionban"); | ||
91 | manager.ExecuteSql("drop table if exists regionsettings"); | ||
92 | manager.ExecuteSql("drop table if exists estate_managers"); | ||
93 | manager.ExecuteSql("drop table if exists estate_groups"); | ||
94 | manager.ExecuteSql("drop table if exists estate_users"); | ||
95 | manager.ExecuteSql("drop table if exists estateban"); | ||
96 | manager.ExecuteSql("drop table if exists estate_settings"); | ||
97 | manager.ExecuteSql("drop table if exists estate_map"); | ||
98 | } | 109 | } |
99 | } | 110 | } |
100 | } | 111 | } |
diff --git a/OpenSim/Data/MySQL/Tests/MySQLUserTest.cs b/OpenSim/Data/MySQL/Tests/MySQLUserTest.cs deleted file mode 100644 index cf8139a..0000000 --- a/OpenSim/Data/MySQL/Tests/MySQLUserTest.cs +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Data.Tests; | ||
31 | using log4net; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Tests.Common; | ||
34 | |||
35 | namespace OpenSim.Data.MySQL.Tests | ||
36 | { | ||
37 | [TestFixture, DatabaseTest] | ||
38 | public class MySQLUserTest : BasicUserTest | ||
39 | { | ||
40 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | public string file; | ||
42 | public MySQLManager database; | ||
43 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | ||
44 | |||
45 | [TestFixtureSetUp] | ||
46 | public void Init() | ||
47 | { | ||
48 | SuperInit(); | ||
49 | // If we manage to connect to the database with the user | ||
50 | // and password above it is our test database, and run | ||
51 | // these tests. If anything goes wrong, ignore these | ||
52 | // tests. | ||
53 | try | ||
54 | { | ||
55 | database = new MySQLManager(connect); | ||
56 | db = new MySQLUserData(); | ||
57 | db.Initialise(connect); | ||
58 | } | ||
59 | catch (Exception e) | ||
60 | { | ||
61 | m_log.Error("Exception {0}", e); | ||
62 | Assert.Ignore(); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | [TestFixtureTearDown] | ||
67 | public void Cleanup() | ||
68 | { | ||
69 | if (db != null) | ||
70 | { | ||
71 | db.Dispose(); | ||
72 | } | ||
73 | // if a new table is added, it has to be dropped here | ||
74 | if (database != null) | ||
75 | { | ||
76 | database.ExecuteSql("drop table migrations"); | ||
77 | database.ExecuteSql("drop table users"); | ||
78 | database.ExecuteSql("drop table userfriends"); | ||
79 | database.ExecuteSql("drop table agents"); | ||
80 | database.ExecuteSql("drop table avatarappearance"); | ||
81 | database.ExecuteSql("drop table avatarattachments"); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } | ||
diff --git a/OpenSim/Data/RegionProfileData.cs b/OpenSim/Data/RegionProfileData.cs deleted file mode 100644 index 90713d2..0000000 --- a/OpenSim/Data/RegionProfileData.cs +++ /dev/null | |||
@@ -1,337 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using Nwc.XmlRpc; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | |||
34 | namespace OpenSim.Data | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// A class which contains information known to the grid server about a region | ||
38 | /// </summary> | ||
39 | [Serializable] | ||
40 | public class RegionProfileData | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// The name of the region | ||
44 | /// </summary> | ||
45 | public string regionName = String.Empty; | ||
46 | |||
47 | /// <summary> | ||
48 | /// A 64-bit number combining map position into a (mostly) unique ID | ||
49 | /// </summary> | ||
50 | public ulong regionHandle; | ||
51 | |||
52 | /// <summary> | ||
53 | /// OGS/OpenSim Specific ID for a region | ||
54 | /// </summary> | ||
55 | public UUID UUID; | ||
56 | |||
57 | /// <summary> | ||
58 | /// Coordinates of the region | ||
59 | /// </summary> | ||
60 | public uint regionLocX; | ||
61 | public uint regionLocY; | ||
62 | public uint regionLocZ; // Reserved (round-robin, layers, etc) | ||
63 | |||
64 | /// <summary> | ||
65 | /// Authentication secrets | ||
66 | /// </summary> | ||
67 | /// <remarks>Not very secure, needs improvement.</remarks> | ||
68 | public string regionSendKey = String.Empty; | ||
69 | public string regionRecvKey = String.Empty; | ||
70 | public string regionSecret = String.Empty; | ||
71 | |||
72 | /// <summary> | ||
73 | /// Whether the region is online | ||
74 | /// </summary> | ||
75 | public bool regionOnline; | ||
76 | |||
77 | /// <summary> | ||
78 | /// Information about the server that the region is currently hosted on | ||
79 | /// </summary> | ||
80 | public string serverIP = String.Empty; | ||
81 | public uint serverPort; | ||
82 | public string serverURI = String.Empty; | ||
83 | |||
84 | public uint httpPort; | ||
85 | public uint remotingPort; | ||
86 | public string httpServerURI = String.Empty; | ||
87 | |||
88 | /// <summary> | ||
89 | /// Set of optional overrides. Can be used to create non-eulicidean spaces. | ||
90 | /// </summary> | ||
91 | public ulong regionNorthOverrideHandle; | ||
92 | public ulong regionSouthOverrideHandle; | ||
93 | public ulong regionEastOverrideHandle; | ||
94 | public ulong regionWestOverrideHandle; | ||
95 | |||
96 | /// <summary> | ||
97 | /// Optional: URI Location of the region database | ||
98 | /// </summary> | ||
99 | /// <remarks>Used for floating sim pools where the region data is not nessecarily coupled to a specific server</remarks> | ||
100 | public string regionDataURI = String.Empty; | ||
101 | |||
102 | /// <summary> | ||
103 | /// Region Asset Details | ||
104 | /// </summary> | ||
105 | public string regionAssetURI = String.Empty; | ||
106 | |||
107 | public string regionAssetSendKey = String.Empty; | ||
108 | public string regionAssetRecvKey = String.Empty; | ||
109 | |||
110 | /// <summary> | ||
111 | /// Region Userserver Details | ||
112 | /// </summary> | ||
113 | public string regionUserURI = String.Empty; | ||
114 | |||
115 | public string regionUserSendKey = String.Empty; | ||
116 | public string regionUserRecvKey = String.Empty; | ||
117 | |||
118 | /// <summary> | ||
119 | /// Region Map Texture Asset | ||
120 | /// </summary> | ||
121 | public UUID regionMapTextureID = new UUID("00000000-0000-1111-9999-000000000006"); | ||
122 | |||
123 | /// <summary> | ||
124 | /// this particular mod to the file provides support within the spec for RegionProfileData for the | ||
125 | /// owner_uuid for the region | ||
126 | /// </summary> | ||
127 | public UUID owner_uuid = UUID.Zero; | ||
128 | |||
129 | /// <summary> | ||
130 | /// OGS/OpenSim Specific original ID for a region after move/split | ||
131 | /// </summary> | ||
132 | public UUID originUUID; | ||
133 | |||
134 | /// <summary> | ||
135 | /// The Maturity rating of the region | ||
136 | /// </summary> | ||
137 | public uint maturity; | ||
138 | |||
139 | //Data Wrappers | ||
140 | public string RegionName | ||
141 | { | ||
142 | get { return regionName; } | ||
143 | set { regionName = value; } | ||
144 | } | ||
145 | public ulong RegionHandle | ||
146 | { | ||
147 | get { return regionHandle; } | ||
148 | set { regionHandle = value; } | ||
149 | } | ||
150 | public UUID Uuid | ||
151 | { | ||
152 | get { return UUID; } | ||
153 | set { UUID = value; } | ||
154 | } | ||
155 | public uint RegionLocX | ||
156 | { | ||
157 | get { return regionLocX; } | ||
158 | set { regionLocX = value; } | ||
159 | } | ||
160 | public uint RegionLocY | ||
161 | { | ||
162 | get { return regionLocY; } | ||
163 | set { regionLocY = value; } | ||
164 | } | ||
165 | public uint RegionLocZ | ||
166 | { | ||
167 | get { return regionLocZ; } | ||
168 | set { regionLocZ = value; } | ||
169 | } | ||
170 | public string RegionSendKey | ||
171 | { | ||
172 | get { return regionSendKey; } | ||
173 | set { regionSendKey = value; } | ||
174 | } | ||
175 | public string RegionRecvKey | ||
176 | { | ||
177 | get { return regionRecvKey; } | ||
178 | set { regionRecvKey = value; } | ||
179 | } | ||
180 | public string RegionSecret | ||
181 | { | ||
182 | get { return regionSecret; } | ||
183 | set { regionSecret = value; } | ||
184 | } | ||
185 | public bool RegionOnline | ||
186 | { | ||
187 | get { return regionOnline; } | ||
188 | set { regionOnline = value; } | ||
189 | } | ||
190 | public string ServerIP | ||
191 | { | ||
192 | get { return serverIP; } | ||
193 | set { serverIP = value; } | ||
194 | } | ||
195 | public uint ServerPort | ||
196 | { | ||
197 | get { return serverPort; } | ||
198 | set { serverPort = value; } | ||
199 | } | ||
200 | public string ServerURI | ||
201 | { | ||
202 | get { return serverURI; } | ||
203 | set { serverURI = value; } | ||
204 | } | ||
205 | public uint ServerHttpPort | ||
206 | { | ||
207 | get { return httpPort; } | ||
208 | set { httpPort = value; } | ||
209 | } | ||
210 | public uint ServerRemotingPort | ||
211 | { | ||
212 | get { return remotingPort; } | ||
213 | set { remotingPort = value; } | ||
214 | } | ||
215 | |||
216 | public ulong NorthOverrideHandle | ||
217 | { | ||
218 | get { return regionNorthOverrideHandle; } | ||
219 | set { regionNorthOverrideHandle = value; } | ||
220 | } | ||
221 | public ulong SouthOverrideHandle | ||
222 | { | ||
223 | get { return regionSouthOverrideHandle; } | ||
224 | set { regionSouthOverrideHandle = value; } | ||
225 | } | ||
226 | public ulong EastOverrideHandle | ||
227 | { | ||
228 | get { return regionEastOverrideHandle; } | ||
229 | set { regionEastOverrideHandle = value; } | ||
230 | } | ||
231 | public ulong WestOverrideHandle | ||
232 | { | ||
233 | get { return regionWestOverrideHandle; } | ||
234 | set { regionWestOverrideHandle = value; } | ||
235 | } | ||
236 | public string RegionDataURI | ||
237 | { | ||
238 | get { return regionDataURI; } | ||
239 | set { regionDataURI = value; } | ||
240 | } | ||
241 | public string RegionAssetURI | ||
242 | { | ||
243 | get { return regionAssetURI; } | ||
244 | set { regionAssetURI = value; } | ||
245 | } | ||
246 | public string RegionAssetSendKey | ||
247 | { | ||
248 | get { return regionAssetSendKey; } | ||
249 | set { regionAssetSendKey = value; } | ||
250 | } | ||
251 | public string RegionAssetRecvKey | ||
252 | { | ||
253 | get { return regionAssetRecvKey; } | ||
254 | set { regionAssetRecvKey = value; } | ||
255 | } | ||
256 | public string RegionUserURI | ||
257 | { | ||
258 | get { return regionUserURI; } | ||
259 | set { regionUserURI = value; } | ||
260 | } | ||
261 | public string RegionUserSendKey | ||
262 | { | ||
263 | get { return regionUserSendKey; } | ||
264 | set { regionUserSendKey = value; } | ||
265 | } | ||
266 | public string RegionUserRecvKey | ||
267 | { | ||
268 | get { return regionUserRecvKey; } | ||
269 | set { regionUserRecvKey = value; } | ||
270 | } | ||
271 | public UUID RegionMapTextureID | ||
272 | { | ||
273 | get { return regionMapTextureID; } | ||
274 | set { regionMapTextureID = value; } | ||
275 | } | ||
276 | public UUID Owner_uuid | ||
277 | { | ||
278 | get { return owner_uuid; } | ||
279 | set { owner_uuid = value; } | ||
280 | } | ||
281 | public UUID OriginUUID | ||
282 | { | ||
283 | get { return originUUID; } | ||
284 | set { originUUID = value; } | ||
285 | } | ||
286 | public uint Maturity | ||
287 | { | ||
288 | get { return maturity; } | ||
289 | set { maturity = value; } | ||
290 | } | ||
291 | |||
292 | public byte AccessLevel | ||
293 | { | ||
294 | get { return Util.ConvertMaturityToAccessLevel(maturity); } | ||
295 | } | ||
296 | |||
297 | |||
298 | public RegionInfo ToRegionInfo() | ||
299 | { | ||
300 | return RegionInfo.Create(UUID, regionName, regionLocX, regionLocY, serverIP, httpPort, serverPort, remotingPort, serverURI); | ||
301 | } | ||
302 | |||
303 | public static RegionProfileData FromRegionInfo(RegionInfo regionInfo) | ||
304 | { | ||
305 | if (regionInfo == null) | ||
306 | { | ||
307 | return null; | ||
308 | } | ||
309 | |||
310 | return Create(regionInfo.RegionID, regionInfo.RegionName, regionInfo.RegionLocX, | ||
311 | regionInfo.RegionLocY, regionInfo.ExternalHostName, | ||
312 | (uint) regionInfo.ExternalEndPoint.Port, regionInfo.HttpPort, regionInfo.RemotingPort, | ||
313 | regionInfo.ServerURI, regionInfo.AccessLevel); | ||
314 | } | ||
315 | |||
316 | public static RegionProfileData Create(UUID regionID, string regionName, uint locX, uint locY, string externalHostName, uint regionPort, uint httpPort, uint remotingPort, string serverUri, byte access) | ||
317 | { | ||
318 | RegionProfileData regionProfile; | ||
319 | regionProfile = new RegionProfileData(); | ||
320 | regionProfile.regionLocX = locX; | ||
321 | regionProfile.regionLocY = locY; | ||
322 | regionProfile.regionHandle = | ||
323 | Utils.UIntsToLong((regionProfile.regionLocX * Constants.RegionSize), | ||
324 | (regionProfile.regionLocY*Constants.RegionSize)); | ||
325 | regionProfile.serverIP = externalHostName; | ||
326 | regionProfile.serverPort = regionPort; | ||
327 | regionProfile.httpPort = httpPort; | ||
328 | regionProfile.remotingPort = remotingPort; | ||
329 | regionProfile.serverURI = serverUri; | ||
330 | regionProfile.httpServerURI = "http://" + externalHostName + ":" + httpPort + "/"; | ||
331 | regionProfile.UUID = regionID; | ||
332 | regionProfile.regionName = regionName; | ||
333 | regionProfile.maturity = access; | ||
334 | return regionProfile; | ||
335 | } | ||
336 | } | ||
337 | } | ||
diff --git a/OpenSim/Data/RegionProfileServiceProxy.cs b/OpenSim/Data/RegionProfileServiceProxy.cs deleted file mode 100644 index 20d7df0..0000000 --- a/OpenSim/Data/RegionProfileServiceProxy.cs +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using Nwc.XmlRpc; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | namespace OpenSim.Data | ||
37 | { | ||
38 | public class RegionProfileServiceProxy : IRegionProfileRouter | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Request sim data based on arbitrary key/value | ||
42 | /// </summary> | ||
43 | private RegionProfileData RequestSimData(Uri gridserverUrl, string gridserverSendkey, string keyField, string keyValue) | ||
44 | { | ||
45 | Hashtable requestData = new Hashtable(); | ||
46 | requestData[keyField] = keyValue; | ||
47 | requestData["authkey"] = gridserverSendkey; | ||
48 | ArrayList SendParams = new ArrayList(); | ||
49 | SendParams.Add(requestData); | ||
50 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | ||
51 | XmlRpcResponse GridResp = GridReq.Send(gridserverUrl.ToString(), 3000); | ||
52 | |||
53 | Hashtable responseData = (Hashtable) GridResp.Value; | ||
54 | |||
55 | RegionProfileData simData = null; | ||
56 | |||
57 | if (!responseData.ContainsKey("error")) | ||
58 | { | ||
59 | uint locX = Convert.ToUInt32((string)responseData["region_locx"]); | ||
60 | uint locY = Convert.ToUInt32((string)responseData["region_locy"]); | ||
61 | string externalHostName = (string)responseData["sim_ip"]; | ||
62 | uint simPort = Convert.ToUInt32((string)responseData["sim_port"]); | ||
63 | uint httpPort = Convert.ToUInt32((string)responseData["http_port"]); | ||
64 | uint remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | ||
65 | string serverUri = (string)responseData["server_uri"]; | ||
66 | UUID regionID = new UUID((string)responseData["region_UUID"]); | ||
67 | string regionName = (string)responseData["region_name"]; | ||
68 | byte access = Convert.ToByte((string)responseData["access"]); | ||
69 | |||
70 | simData = RegionProfileData.Create(regionID, regionName, locX, locY, externalHostName, simPort, httpPort, remotingPort, serverUri, access); | ||
71 | } | ||
72 | |||
73 | return simData; | ||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// Request sim profile information from a grid server, by Region UUID | ||
78 | /// </summary> | ||
79 | /// <param name="regionId">The region UUID to look for</param> | ||
80 | /// <param name="gridserverUrl"></param> | ||
81 | /// <param name="gridserverSendkey"></param> | ||
82 | /// <param name="gridserverRecvkey"></param> | ||
83 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
84 | /// <remarks>This method should be statics</remarks> | ||
85 | public RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl, | ||
86 | string gridserverSendkey, string gridserverRecvkey) | ||
87 | { | ||
88 | return RequestSimData(gridserverUrl, gridserverSendkey, "region_UUID", regionId.Guid.ToString()); | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Request sim profile information from a grid server, by Region Handle | ||
93 | /// </summary> | ||
94 | /// <param name="regionHandle">the region handle to look for</param> | ||
95 | /// <param name="gridserverUrl"></param> | ||
96 | /// <param name="gridserverSendkey"></param> | ||
97 | /// <param name="gridserverRecvkey"></param> | ||
98 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
99 | public RegionProfileData RequestSimProfileData(ulong regionHandle, Uri gridserverUrl, | ||
100 | string gridserverSendkey, string gridserverRecvkey) | ||
101 | { | ||
102 | return RequestSimData(gridserverUrl, gridserverSendkey, "region_handle", regionHandle.ToString()); | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// Request sim profile information from a grid server, by Region Name | ||
107 | /// </summary> | ||
108 | /// <param name="regionName">the region name to look for</param> | ||
109 | /// <param name="gridserverUrl"></param> | ||
110 | /// <param name="gridserverSendkey"></param> | ||
111 | /// <param name="gridserverRecvkey"></param> | ||
112 | /// <returns>The sim profile. Null if there was a request failure</returns> | ||
113 | public RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl, | ||
114 | string gridserverSendkey, string gridserverRecvkey) | ||
115 | { | ||
116 | return RequestSimData(gridserverUrl, gridserverSendkey, "region_name_search", regionName); | ||
117 | } | ||
118 | } | ||
119 | } | ||
diff --git a/OpenSim/Data/ReservationData.cs b/OpenSim/Data/ReservationData.cs deleted file mode 100644 index 3956fe6..0000000 --- a/OpenSim/Data/ReservationData.cs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Data | ||
32 | { | ||
33 | public class ReservationData | ||
34 | { | ||
35 | public UUID userUUID = UUID.Zero; | ||
36 | public int reservationMinX = 0; | ||
37 | public int reservationMinY = 0; | ||
38 | public int reservationMaxX = 65536; | ||
39 | public int reservationMaxY = 65536; | ||
40 | |||
41 | public string reservationName = String.Empty; | ||
42 | public string reservationCompany = String.Empty; | ||
43 | public bool status = true; | ||
44 | |||
45 | public string gridSendKey = String.Empty; | ||
46 | public string gridRecvKey = String.Empty; | ||
47 | } | ||
48 | } | ||
diff --git a/OpenSim/Data/SQLite/SQLiteGridData.cs b/OpenSim/Data/SQLite/SQLiteGridData.cs deleted file mode 100644 index 18abb88..0000000 --- a/OpenSim/Data/SQLite/SQLiteGridData.cs +++ /dev/null | |||
@@ -1,286 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | namespace OpenSim.Data.SQLite | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// A Grid Interface to the SQLite database | ||
40 | /// </summary> | ||
41 | public class SQLiteGridData : GridDataBase | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | /// <summary> | ||
46 | /// SQLite database manager | ||
47 | /// </summary> | ||
48 | private SQLiteManager database; | ||
49 | |||
50 | override public void Initialise() | ||
51 | { | ||
52 | m_log.Info("[SQLite]: " + Name + " cannot be default-initialized!"); | ||
53 | throw new PluginNotInitialisedException (Name); | ||
54 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// <list type="bullet"> | ||
58 | /// <item>Initialises Inventory interface</item> | ||
59 | /// <item>Loads and initialises a new SQLite connection and maintains it.</item> | ||
60 | /// <item>use default URI if connect string is empty.</item> | ||
61 | /// </list> | ||
62 | /// </summary> | ||
63 | /// <param name="dbconnect">connect string</param> | ||
64 | override public void Initialise(string connect) | ||
65 | { | ||
66 | database = new SQLiteManager(connect); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Shuts down the grid interface | ||
71 | /// </summary> | ||
72 | override public void Dispose() | ||
73 | { | ||
74 | database.Close(); | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// Returns the name of this grid interface | ||
79 | /// </summary> | ||
80 | /// <returns>A string containing the grid interface</returns> | ||
81 | override public string Name | ||
82 | { | ||
83 | get { return "SQLite OpenGridData"; } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Returns the version of this grid interface | ||
88 | /// </summary> | ||
89 | /// <returns>A string containing the version</returns> | ||
90 | override public string Version | ||
91 | { | ||
92 | get { return "0.1"; } | ||
93 | } | ||
94 | |||
95 | /// <summary> | ||
96 | /// Returns a list of regions within the specified ranges | ||
97 | /// </summary> | ||
98 | /// <param name="a">minimum X coordinate</param> | ||
99 | /// <param name="b">minimum Y coordinate</param> | ||
100 | /// <param name="c">maximum X coordinate</param> | ||
101 | /// <param name="d">maximum Y coordinate</param> | ||
102 | /// <returns>An array of region profiles</returns> | ||
103 | /// <remarks>NOT IMPLEMENTED ? always return null</remarks> | ||
104 | override public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | ||
105 | { | ||
106 | return null; | ||
107 | } | ||
108 | |||
109 | |||
110 | /// <summary> | ||
111 | /// Returns up to maxNum profiles of regions that have a name starting with namePrefix | ||
112 | /// </summary> | ||
113 | /// <param name="name">The name to match against</param> | ||
114 | /// <param name="maxNum">Maximum number of profiles to return</param> | ||
115 | /// <returns>A list of sim profiles</returns> | ||
116 | override public List<RegionProfileData> GetRegionsByName (string namePrefix, uint maxNum) | ||
117 | { | ||
118 | return null; | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// Returns a sim profile from it's handle | ||
123 | /// </summary> | ||
124 | /// <param name="handle">Region location handle</param> | ||
125 | /// <returns>Sim profile</returns> | ||
126 | override public RegionProfileData GetProfileByHandle(ulong handle) | ||
127 | { | ||
128 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
129 | param["handle"] = handle.ToString(); | ||
130 | |||
131 | IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param); | ||
132 | IDataReader reader = result.ExecuteReader(); | ||
133 | |||
134 | RegionProfileData row = database.getRow(reader); | ||
135 | reader.Close(); | ||
136 | result.Dispose(); | ||
137 | |||
138 | return row; | ||
139 | } | ||
140 | |||
141 | /// <summary> | ||
142 | /// Returns a sim profile from it's Region name string | ||
143 | /// </summary> | ||
144 | /// <param name="regionName">The region name search query</param> | ||
145 | /// <returns>The sim profile</returns> | ||
146 | override public RegionProfileData GetProfileByString(string regionName) | ||
147 | { | ||
148 | if (regionName.Length > 2) | ||
149 | { | ||
150 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
151 | // Add % because this is a like query. | ||
152 | param["?regionName"] = regionName + "%"; | ||
153 | // Only returns one record or no record. | ||
154 | IDbCommand result = database.Query("SELECT * FROM regions WHERE regionName like ?regionName LIMIT 1", param); | ||
155 | IDataReader reader = result.ExecuteReader(); | ||
156 | |||
157 | RegionProfileData row = database.getRow(reader); | ||
158 | reader.Close(); | ||
159 | result.Dispose(); | ||
160 | |||
161 | return row; | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | //m_log.Error("[DATABASE]: Searched for a Region Name shorter then 3 characters"); | ||
166 | return null; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Returns a sim profile from it's UUID | ||
172 | /// </summary> | ||
173 | /// <param name="uuid">The region UUID</param> | ||
174 | /// <returns>The sim profile</returns> | ||
175 | override public RegionProfileData GetProfileByUUID(UUID uuid) | ||
176 | { | ||
177 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
178 | param["uuid"] = uuid.ToString(); | ||
179 | |||
180 | IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param); | ||
181 | IDataReader reader = result.ExecuteReader(); | ||
182 | |||
183 | RegionProfileData row = database.getRow(reader); | ||
184 | reader.Close(); | ||
185 | result.Dispose(); | ||
186 | |||
187 | return row; | ||
188 | } | ||
189 | |||
190 | /// <summary> | ||
191 | /// Returns a list of avatar and UUIDs that match the query | ||
192 | /// </summary> | ||
193 | /// <remarks>do nothing yet</remarks> | ||
194 | public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) | ||
195 | { | ||
196 | //Do nothing yet | ||
197 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
198 | return returnlist; | ||
199 | } | ||
200 | |||
201 | /// <summary> | ||
202 | /// Adds a new specified region to the database | ||
203 | /// </summary> | ||
204 | /// <param name="profile">The profile to add</param> | ||
205 | /// <returns>A dataresponse enum indicating success</returns> | ||
206 | override public DataResponse StoreProfile(RegionProfileData profile) | ||
207 | { | ||
208 | if (database.insertRow(profile)) | ||
209 | { | ||
210 | return DataResponse.RESPONSE_OK; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | return DataResponse.RESPONSE_ERROR; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /// <summary> | ||
219 | /// Deletes a sim profile from the database | ||
220 | /// </summary> | ||
221 | /// <param name="uuid">the sim UUID</param> | ||
222 | /// <returns>Successful?</returns> | ||
223 | override public DataResponse DeleteProfile(string uuid) | ||
224 | { | ||
225 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
226 | param["uuid"] = uuid; | ||
227 | |||
228 | IDbCommand result = database.Query("DELETE FROM regions WHERE uuid = @uuid", param); | ||
229 | if (result.ExecuteNonQuery() > 0) | ||
230 | { | ||
231 | return DataResponse.RESPONSE_OK; | ||
232 | } | ||
233 | return DataResponse.RESPONSE_ERROR; | ||
234 | } | ||
235 | |||
236 | /// <summary> | ||
237 | /// DEPRECATED. Attempts to authenticate a region by comparing a shared secret. | ||
238 | /// </summary> | ||
239 | /// <param name="uuid">The UUID of the challenger</param> | ||
240 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
241 | /// <param name="authkey">The secret</param> | ||
242 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
243 | override public bool AuthenticateSim(UUID uuid, ulong handle, string authkey) | ||
244 | { | ||
245 | bool throwHissyFit = false; // Should be true by 1.0 | ||
246 | |||
247 | if (throwHissyFit) | ||
248 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
249 | |||
250 | RegionProfileData data = GetProfileByUUID(uuid); | ||
251 | |||
252 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
253 | } | ||
254 | |||
255 | /// <summary> | ||
256 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
257 | /// </summary> | ||
258 | /// <remarks>This requires a security audit.</remarks> | ||
259 | /// <param name="uuid"></param> | ||
260 | /// <param name="handle"></param> | ||
261 | /// <param name="authhash"></param> | ||
262 | /// <param name="challenge"></param> | ||
263 | /// <returns></returns> | ||
264 | public bool AuthenticateSim(UUID uuid, ulong handle, string authhash, string challenge) | ||
265 | { | ||
266 | // SHA512Managed HashProvider = new SHA512Managed(); | ||
267 | // Encoding TextProvider = new UTF8Encoding(); | ||
268 | |||
269 | // byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge); | ||
270 | // byte[] hash = HashProvider.ComputeHash(stream); | ||
271 | |||
272 | return false; | ||
273 | } | ||
274 | |||
275 | /// <summary> | ||
276 | /// NOT IMPLEMENTED | ||
277 | /// </summary> | ||
278 | /// <param name="x">x coordinate</param> | ||
279 | /// <param name="y">y coordinate</param> | ||
280 | /// <returns>always return null</returns> | ||
281 | override public ReservationData GetReservationAtPoint(uint x, uint y) | ||
282 | { | ||
283 | return null; | ||
284 | } | ||
285 | } | ||
286 | } | ||
diff --git a/OpenSim/Data/SQLite/SQLiteManager.cs b/OpenSim/Data/SQLite/SQLiteManager.cs deleted file mode 100644 index b6d4a1c..0000000 --- a/OpenSim/Data/SQLite/SQLiteManager.cs +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Data.SQLite; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Data.SQLite | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// SQLite Manager | ||
40 | /// </summary> | ||
41 | internal class SQLiteManager : SQLiteUtil | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private IDbConnection dbcon; | ||
46 | |||
47 | /// <summary> | ||
48 | /// <list type="bullet"> | ||
49 | /// <item>Initialises and creates a new SQLite connection and maintains it.</item> | ||
50 | /// <item>use default URI if connect string is empty.</item> | ||
51 | /// </list> | ||
52 | /// </summary> | ||
53 | /// <param name="connect">connect string</param> | ||
54 | public SQLiteManager(string connect) | ||
55 | { | ||
56 | try | ||
57 | { | ||
58 | string connectionString = String.Empty; | ||
59 | if (connect != String.Empty) | ||
60 | { | ||
61 | connectionString = connect; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | m_log.Warn("[SQLITE] grid db not specified, using default"); | ||
66 | connectionString = "URI=file:GridServerSqlite.db;"; | ||
67 | } | ||
68 | |||
69 | dbcon = new SQLiteConnection(connectionString); | ||
70 | |||
71 | dbcon.Open(); | ||
72 | } | ||
73 | catch (Exception e) | ||
74 | { | ||
75 | throw new Exception("Error initialising SQLite Database: " + e.ToString()); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /// <summary> | ||
80 | /// Shuts down the database connection | ||
81 | /// </summary> | ||
82 | public void Close() | ||
83 | { | ||
84 | dbcon.Close(); | ||
85 | dbcon = null; | ||
86 | } | ||
87 | |||
88 | /// <summary> | ||
89 | /// Runs a query with protection against SQL Injection by using parameterised input. | ||
90 | /// </summary> | ||
91 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | ||
92 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | ||
93 | /// <returns>A SQLite DB Command</returns> | ||
94 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) | ||
95 | { | ||
96 | SQLiteCommand dbcommand = (SQLiteCommand) dbcon.CreateCommand(); | ||
97 | dbcommand.CommandText = sql; | ||
98 | foreach (KeyValuePair<string, string> param in parameters) | ||
99 | { | ||
100 | SQLiteParameter paramx = new SQLiteParameter(param.Key, param.Value); | ||
101 | dbcommand.Parameters.Add(paramx); | ||
102 | } | ||
103 | |||
104 | return (IDbCommand) dbcommand; | ||
105 | } | ||
106 | |||
107 | /// <summary> | ||
108 | /// Reads a region row from a database reader | ||
109 | /// </summary> | ||
110 | /// <param name="reader">An active database reader</param> | ||
111 | /// <returns>A region profile</returns> | ||
112 | public RegionProfileData getRow(IDataReader reader) | ||
113 | { | ||
114 | RegionProfileData retval = new RegionProfileData(); | ||
115 | |||
116 | if (reader.Read()) | ||
117 | { | ||
118 | // Region Main | ||
119 | retval.regionHandle = (ulong) reader["regionHandle"]; | ||
120 | retval.regionName = (string) reader["regionName"]; | ||
121 | retval.UUID = new UUID((string) reader["uuid"]); | ||
122 | |||
123 | // Secrets | ||
124 | retval.regionRecvKey = (string) reader["regionRecvKey"]; | ||
125 | retval.regionSecret = (string) reader["regionSecret"]; | ||
126 | retval.regionSendKey = (string) reader["regionSendKey"]; | ||
127 | |||
128 | // Region Server | ||
129 | retval.regionDataURI = (string) reader["regionDataURI"]; | ||
130 | retval.regionOnline = false; // Needs to be pinged before this can be set. | ||
131 | retval.serverIP = (string) reader["serverIP"]; | ||
132 | retval.serverPort = (uint) reader["serverPort"]; | ||
133 | retval.serverURI = (string) reader["serverURI"]; | ||
134 | |||
135 | // Location | ||
136 | retval.regionLocX = (uint) ((int) reader["locX"]); | ||
137 | retval.regionLocY = (uint) ((int) reader["locY"]); | ||
138 | retval.regionLocZ = (uint) ((int) reader["locZ"]); | ||
139 | |||
140 | // Neighbours - 0 = No Override | ||
141 | retval.regionEastOverrideHandle = (ulong) reader["eastOverrideHandle"]; | ||
142 | retval.regionWestOverrideHandle = (ulong) reader["westOverrideHandle"]; | ||
143 | retval.regionSouthOverrideHandle = (ulong) reader["southOverrideHandle"]; | ||
144 | retval.regionNorthOverrideHandle = (ulong) reader["northOverrideHandle"]; | ||
145 | |||
146 | // Assets | ||
147 | retval.regionAssetURI = (string) reader["regionAssetURI"]; | ||
148 | retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"]; | ||
149 | retval.regionAssetSendKey = (string) reader["regionAssetSendKey"]; | ||
150 | |||
151 | // Userserver | ||
152 | retval.regionUserURI = (string) reader["regionUserURI"]; | ||
153 | retval.regionUserRecvKey = (string) reader["regionUserRecvKey"]; | ||
154 | retval.regionUserSendKey = (string) reader["regionUserSendKey"]; | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | throw new Exception("No rows to return"); | ||
159 | } | ||
160 | return retval; | ||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// Inserts a new region into the database | ||
165 | /// </summary> | ||
166 | /// <param name="profile">The region to insert</param> | ||
167 | /// <returns>Success?</returns> | ||
168 | public bool insertRow(RegionProfileData profile) | ||
169 | { | ||
170 | string sql = | ||
171 | "REPLACE INTO regions VALUES (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | ||
172 | sql += | ||
173 | "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | ||
174 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey) VALUES "; | ||
175 | |||
176 | sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; | ||
177 | sql += | ||
178 | "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; | ||
179 | sql += "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey);"; | ||
180 | |||
181 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
182 | |||
183 | parameters["regionHandle"] = profile.regionHandle.ToString(); | ||
184 | parameters["regionName"] = profile.regionName; | ||
185 | parameters["uuid"] = profile.UUID.ToString(); | ||
186 | parameters["regionRecvKey"] = profile.regionRecvKey; | ||
187 | parameters["regionSendKey"] = profile.regionSendKey; | ||
188 | parameters["regionDataURI"] = profile.regionDataURI; | ||
189 | parameters["serverIP"] = profile.serverIP; | ||
190 | parameters["serverPort"] = profile.serverPort.ToString(); | ||
191 | parameters["serverURI"] = profile.serverURI; | ||
192 | parameters["locX"] = profile.regionLocX.ToString(); | ||
193 | parameters["locY"] = profile.regionLocY.ToString(); | ||
194 | parameters["locZ"] = profile.regionLocZ.ToString(); | ||
195 | parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | ||
196 | parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | ||
197 | parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | ||
198 | parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | ||
199 | parameters["regionAssetURI"] = profile.regionAssetURI; | ||
200 | parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; | ||
201 | parameters["regionAssetSendKey"] = profile.regionAssetSendKey; | ||
202 | parameters["regionUserURI"] = profile.regionUserURI; | ||
203 | parameters["regionUserRecvKey"] = profile.regionUserRecvKey; | ||
204 | parameters["regionUserSendKey"] = profile.regionUserSendKey; | ||
205 | |||
206 | bool returnval = false; | ||
207 | |||
208 | try | ||
209 | { | ||
210 | IDbCommand result = Query(sql, parameters); | ||
211 | |||
212 | if (result.ExecuteNonQuery() == 1) | ||
213 | returnval = true; | ||
214 | |||
215 | result.Dispose(); | ||
216 | } | ||
217 | catch (Exception) | ||
218 | { | ||
219 | return false; | ||
220 | } | ||
221 | |||
222 | return returnval; | ||
223 | } | ||
224 | } | ||
225 | } | ||
diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs deleted file mode 100644 index caddcf8..0000000 --- a/OpenSim/Data/SQLite/SQLiteUserData.cs +++ /dev/null | |||
@@ -1,1262 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Mono.Data.SqliteClient; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Data.SQLite | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A User storage interface for the SQLite database system | ||
41 | /// </summary> | ||
42 | public class SQLiteUserData : UserDataBase | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | /// <summary> | ||
47 | /// The database manager | ||
48 | /// </summary> | ||
49 | /// <summary> | ||
50 | /// Artificial constructor called upon plugin load | ||
51 | /// </summary> | ||
52 | private const string SelectUserByUUID = "select * from users where UUID=:UUID"; | ||
53 | private const string SelectUserByName = "select * from users where username=:username and surname=:surname"; | ||
54 | private const string SelectFriendsByUUID = "select a.friendID, a.friendPerms, b.friendPerms from userfriends as a, userfriends as b where a.ownerID=:ownerID and b.ownerID=a.friendID and b.friendID=a.ownerID"; | ||
55 | |||
56 | private const string userSelect = "select * from users"; | ||
57 | private const string userFriendsSelect = "select a.ownerID as ownerID,a.friendID as friendID,a.friendPerms as friendPerms,b.friendPerms as ownerperms, b.ownerID as fownerID, b.friendID as ffriendID from userfriends as a, userfriends as b"; | ||
58 | private const string userAgentSelect = "select * from useragents"; | ||
59 | private const string AvatarAppearanceSelect = "select * from avatarappearance"; | ||
60 | |||
61 | private const string AvatarPickerAndSQL = "select * from users where username like :username and surname like :surname"; | ||
62 | private const string AvatarPickerOrSQL = "select * from users where username like :username or surname like :surname"; | ||
63 | |||
64 | private DataSet ds; | ||
65 | private SqliteDataAdapter da; | ||
66 | private SqliteDataAdapter daf; | ||
67 | private SqliteDataAdapter dua; | ||
68 | private SqliteDataAdapter daa; | ||
69 | SqliteConnection g_conn; | ||
70 | |||
71 | public override void Initialise() | ||
72 | { | ||
73 | m_log.Info("[SQLiteUserData]: " + Name + " cannot be default-initialized!"); | ||
74 | throw new PluginNotInitialisedException (Name); | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// <list type="bullet"> | ||
79 | /// <item>Initialises User Interface</item> | ||
80 | /// <item>Loads and initialises a new SQLite connection and maintains it.</item> | ||
81 | /// <item>use default URI if connect string string is empty.</item> | ||
82 | /// </list> | ||
83 | /// </summary> | ||
84 | /// <param name="connect">connect string</param> | ||
85 | override public void Initialise(string connect) | ||
86 | { | ||
87 | // default to something sensible | ||
88 | if (connect == "") | ||
89 | connect = "URI=file:userprofiles.db,version=3"; | ||
90 | |||
91 | SqliteConnection conn = new SqliteConnection(connect); | ||
92 | |||
93 | // This sucks, but It doesn't seem to work with the dataset Syncing :P | ||
94 | g_conn = conn; | ||
95 | g_conn.Open(); | ||
96 | |||
97 | Assembly assem = GetType().Assembly; | ||
98 | Migration m = new Migration(g_conn, assem, "UserStore"); | ||
99 | m.Update(); | ||
100 | |||
101 | |||
102 | ds = new DataSet(); | ||
103 | da = new SqliteDataAdapter(new SqliteCommand(userSelect, conn)); | ||
104 | dua = new SqliteDataAdapter(new SqliteCommand(userAgentSelect, conn)); | ||
105 | daf = new SqliteDataAdapter(new SqliteCommand(userFriendsSelect, conn)); | ||
106 | daa = new SqliteDataAdapter(new SqliteCommand(AvatarAppearanceSelect, conn)); | ||
107 | //if (daa == null) m_log.Info("[SQLiteUserData]: daa = null"); | ||
108 | |||
109 | lock (ds) | ||
110 | { | ||
111 | ds.Tables.Add(createUsersTable()); | ||
112 | ds.Tables.Add(createUserAgentsTable()); | ||
113 | ds.Tables.Add(createUserFriendsTable()); | ||
114 | ds.Tables.Add(createAvatarAppearanceTable()); | ||
115 | |||
116 | setupUserCommands(da, conn); | ||
117 | da.Fill(ds.Tables["users"]); | ||
118 | |||
119 | setupAgentCommands(dua, conn); | ||
120 | dua.Fill(ds.Tables["useragents"]); | ||
121 | |||
122 | setupUserFriendsCommands(daf, conn); | ||
123 | daf.Fill(ds.Tables["userfriends"]); | ||
124 | |||
125 | setupAvatarAppearanceCommands(daa, conn); | ||
126 | daa.Fill(ds.Tables["avatarappearance"]); | ||
127 | } | ||
128 | |||
129 | return; | ||
130 | } | ||
131 | |||
132 | public override void Dispose () | ||
133 | { | ||
134 | if (g_conn != null) | ||
135 | { | ||
136 | g_conn.Close(); | ||
137 | g_conn = null; | ||
138 | } | ||
139 | if (ds != null) | ||
140 | { | ||
141 | ds.Dispose(); | ||
142 | ds = null; | ||
143 | } | ||
144 | if (da != null) | ||
145 | { | ||
146 | da.Dispose(); | ||
147 | da = null; | ||
148 | } | ||
149 | if (daf != null) | ||
150 | { | ||
151 | daf.Dispose(); | ||
152 | daf = null; | ||
153 | } | ||
154 | if (dua != null) | ||
155 | { | ||
156 | dua.Dispose(); | ||
157 | dua = null; | ||
158 | } | ||
159 | if (daa != null) | ||
160 | { | ||
161 | daa.Dispose(); | ||
162 | daa = null; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /// <summary> | ||
167 | /// see IUserDataPlugin, | ||
168 | /// Get user data profile by UUID | ||
169 | /// </summary> | ||
170 | /// <param name="uuid">User UUID</param> | ||
171 | /// <returns>user profile data</returns> | ||
172 | override public UserProfileData GetUserByUUID(UUID uuid) | ||
173 | { | ||
174 | lock (ds) | ||
175 | { | ||
176 | DataRow row = ds.Tables["users"].Rows.Find(uuid.ToString()); | ||
177 | if (row != null) | ||
178 | { | ||
179 | UserProfileData user = buildUserProfile(row); | ||
180 | return user; | ||
181 | } | ||
182 | else | ||
183 | { | ||
184 | return null; | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | |||
189 | /// <summary> | ||
190 | /// see IUserDataPlugin, | ||
191 | /// Get user data profile by name | ||
192 | /// </summary> | ||
193 | /// <param name="fname">first name</param> | ||
194 | /// <param name="lname">last name</param> | ||
195 | /// <returns>user profile data</returns> | ||
196 | override public UserProfileData GetUserByName(string fname, string lname) | ||
197 | { | ||
198 | string select = "surname = '" + lname + "' and username = '" + fname + "'"; | ||
199 | lock (ds) | ||
200 | { | ||
201 | DataRow[] rows = ds.Tables["users"].Select(select); | ||
202 | if (rows.Length > 0) | ||
203 | { | ||
204 | UserProfileData user = buildUserProfile(rows[0]); | ||
205 | return user; | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | return null; | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | #region User Friends List Data | ||
215 | |||
216 | private bool ExistsFriend(UUID owner, UUID friend) | ||
217 | { | ||
218 | string FindFriends = "select * from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)"; | ||
219 | using (SqliteCommand cmd = new SqliteCommand(FindFriends, g_conn)) | ||
220 | { | ||
221 | cmd.Parameters.Add(new SqliteParameter(":ownerID", owner.ToString())); | ||
222 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString())); | ||
223 | try | ||
224 | { | ||
225 | using (IDataReader reader = cmd.ExecuteReader()) | ||
226 | { | ||
227 | if (reader.Read()) | ||
228 | { | ||
229 | reader.Close(); | ||
230 | return true; | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | reader.Close(); | ||
235 | return false; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | catch (Exception ex) | ||
240 | { | ||
241 | m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString()); | ||
242 | return false; | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | /// <summary> | ||
247 | /// Add a new friend in the friendlist | ||
248 | /// </summary> | ||
249 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
250 | /// <param name="friend">UUID of the friend to add</param> | ||
251 | /// <param name="perms">permission flag</param> | ||
252 | override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
253 | { | ||
254 | if (ExistsFriend(friendlistowner, friend)) | ||
255 | return; | ||
256 | |||
257 | string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)"; | ||
258 | using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn)) | ||
259 | { | ||
260 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString())); | ||
261 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString())); | ||
262 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); | ||
263 | cmd.ExecuteNonQuery(); | ||
264 | } | ||
265 | using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn)) | ||
266 | { | ||
267 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friend.ToString())); | ||
268 | cmd.Parameters.Add(new SqliteParameter(":friendID", friendlistowner.ToString())); | ||
269 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); | ||
270 | cmd.ExecuteNonQuery(); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | /// <summary> | ||
275 | /// Remove a user from the friendlist | ||
276 | /// </summary> | ||
277 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
278 | /// <param name="friend">UUID of the friend to remove</param> | ||
279 | override public void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
280 | { | ||
281 | string DeletePerms = "delete from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)"; | ||
282 | using (SqliteCommand cmd = new SqliteCommand(DeletePerms, g_conn)) | ||
283 | { | ||
284 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString())); | ||
285 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString())); | ||
286 | cmd.ExecuteNonQuery(); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Update the friendlist permission | ||
292 | /// </summary> | ||
293 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
294 | /// <param name="friend">UUID of the friend to modify</param> | ||
295 | /// <param name="perms">updated permission flag</param> | ||
296 | override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
297 | { | ||
298 | string UpdatePerms = "update userfriends set friendPerms=:perms where ownerID=:ownerID and friendID=:friendID"; | ||
299 | using (SqliteCommand cmd = new SqliteCommand(UpdatePerms, g_conn)) | ||
300 | { | ||
301 | cmd.Parameters.Add(new SqliteParameter(":perms", perms)); | ||
302 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString())); | ||
303 | cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString())); | ||
304 | cmd.ExecuteNonQuery(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | /// <summary> | ||
309 | /// Get (fetch?) the friendlist for a user | ||
310 | /// </summary> | ||
311 | /// <param name="friendlistowner">UUID of the friendlist owner</param> | ||
312 | /// <returns>The friendlist list</returns> | ||
313 | override public List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
314 | { | ||
315 | List<FriendListItem> returnlist = new List<FriendListItem>(); | ||
316 | |||
317 | using (SqliteCommand cmd = new SqliteCommand(SelectFriendsByUUID, g_conn)) | ||
318 | { | ||
319 | cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString())); | ||
320 | |||
321 | try | ||
322 | { | ||
323 | using (IDataReader reader = cmd.ExecuteReader()) | ||
324 | { | ||
325 | while (reader.Read()) | ||
326 | { | ||
327 | FriendListItem user = new FriendListItem(); | ||
328 | user.FriendListOwner = friendlistowner; | ||
329 | user.Friend = new UUID((string)reader[0]); | ||
330 | user.FriendPerms = Convert.ToUInt32(reader[1]); | ||
331 | user.FriendListOwnerPerms = Convert.ToUInt32(reader[2]); | ||
332 | returnlist.Add(user); | ||
333 | } | ||
334 | reader.Close(); | ||
335 | } | ||
336 | } | ||
337 | catch (Exception ex) | ||
338 | { | ||
339 | m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString()); | ||
340 | } | ||
341 | } | ||
342 | |||
343 | return returnlist; | ||
344 | } | ||
345 | |||
346 | override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids) | ||
347 | { | ||
348 | Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>(); | ||
349 | |||
350 | DataTable agents = ds.Tables["useragents"]; | ||
351 | foreach (UUID uuid in uuids) | ||
352 | { | ||
353 | lock (ds) | ||
354 | { | ||
355 | DataRow row = agents.Rows.Find(uuid.ToString()); | ||
356 | if (row == null) infos[uuid] = null; | ||
357 | else | ||
358 | { | ||
359 | FriendRegionInfo fri = new FriendRegionInfo(); | ||
360 | fri.isOnline = (bool)row["agentOnline"]; | ||
361 | fri.regionHandle = Convert.ToUInt64(row["currentHandle"]); | ||
362 | infos[uuid] = fri; | ||
363 | } | ||
364 | } | ||
365 | } | ||
366 | return infos; | ||
367 | } | ||
368 | |||
369 | #endregion | ||
370 | |||
371 | /// <summary> | ||
372 | /// | ||
373 | /// </summary> | ||
374 | /// <param name="queryID"></param> | ||
375 | /// <param name="query"></param> | ||
376 | /// <returns></returns> | ||
377 | override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) | ||
378 | { | ||
379 | List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||
380 | string[] querysplit; | ||
381 | querysplit = query.Split(' '); | ||
382 | if (querysplit.Length == 2) | ||
383 | { | ||
384 | using (SqliteCommand cmd = new SqliteCommand(AvatarPickerAndSQL, g_conn)) | ||
385 | { | ||
386 | cmd.Parameters.Add(new SqliteParameter(":username", querysplit[0] + "%")); | ||
387 | cmd.Parameters.Add(new SqliteParameter(":surname", querysplit[1] + "%")); | ||
388 | |||
389 | using (IDataReader reader = cmd.ExecuteReader()) | ||
390 | { | ||
391 | while (reader.Read()) | ||
392 | { | ||
393 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
394 | user.AvatarID = new UUID((string) reader["UUID"]); | ||
395 | user.firstName = (string) reader["username"]; | ||
396 | user.lastName = (string) reader["surname"]; | ||
397 | returnlist.Add(user); | ||
398 | } | ||
399 | reader.Close(); | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | else if (querysplit.Length == 1) | ||
404 | { | ||
405 | using (SqliteCommand cmd = new SqliteCommand(AvatarPickerOrSQL, g_conn)) | ||
406 | { | ||
407 | cmd.Parameters.Add(new SqliteParameter(":username", querysplit[0] + "%")); | ||
408 | cmd.Parameters.Add(new SqliteParameter(":surname", querysplit[0] + "%")); | ||
409 | |||
410 | using (IDataReader reader = cmd.ExecuteReader()) | ||
411 | { | ||
412 | while (reader.Read()) | ||
413 | { | ||
414 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
415 | user.AvatarID = new UUID((string) reader["UUID"]); | ||
416 | user.firstName = (string) reader["username"]; | ||
417 | user.lastName = (string) reader["surname"]; | ||
418 | returnlist.Add(user); | ||
419 | } | ||
420 | reader.Close(); | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | return returnlist; | ||
425 | } | ||
426 | |||
427 | /// <summary> | ||
428 | /// Returns a user by UUID direct | ||
429 | /// </summary> | ||
430 | /// <param name="uuid">The user's account ID</param> | ||
431 | /// <returns>A matching user profile</returns> | ||
432 | override public UserAgentData GetAgentByUUID(UUID uuid) | ||
433 | { | ||
434 | lock (ds) | ||
435 | { | ||
436 | DataRow row = ds.Tables["useragents"].Rows.Find(uuid.ToString()); | ||
437 | if (row != null) | ||
438 | { | ||
439 | return buildUserAgent(row); | ||
440 | } | ||
441 | else | ||
442 | { | ||
443 | return null; | ||
444 | } | ||
445 | } | ||
446 | } | ||
447 | |||
448 | /// <summary> | ||
449 | /// Returns a session by account name | ||
450 | /// </summary> | ||
451 | /// <param name="name">The account name</param> | ||
452 | /// <returns>The user's session agent</returns> | ||
453 | override public UserAgentData GetAgentByName(string name) | ||
454 | { | ||
455 | return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
456 | } | ||
457 | |||
458 | /// <summary> | ||
459 | /// Returns a session by account name | ||
460 | /// </summary> | ||
461 | /// <param name="fname">The first part of the user's account name</param> | ||
462 | /// <param name="lname">The second part of the user's account name</param> | ||
463 | /// <returns>A user agent</returns> | ||
464 | override public UserAgentData GetAgentByName(string fname, string lname) | ||
465 | { | ||
466 | UserAgentData agent = null; | ||
467 | |||
468 | UserProfileData profile = GetUserByName(fname, lname); | ||
469 | if (profile != null) | ||
470 | { | ||
471 | agent = GetAgentByUUID(profile.ID); | ||
472 | } | ||
473 | return agent; | ||
474 | } | ||
475 | |||
476 | /// <summary> | ||
477 | /// DEPRECATED? Store the weblogin key | ||
478 | /// </summary> | ||
479 | /// <param name="AgentID">UUID of the user</param> | ||
480 | /// <param name="WebLoginKey">UUID of the weblogin</param> | ||
481 | override public void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey) | ||
482 | { | ||
483 | DataTable users = ds.Tables["users"]; | ||
484 | lock (ds) | ||
485 | { | ||
486 | DataRow row = users.Rows.Find(AgentID.ToString()); | ||
487 | if (row == null) | ||
488 | { | ||
489 | m_log.Warn("[USER DB]: Unable to store new web login key for non-existant user"); | ||
490 | } | ||
491 | else | ||
492 | { | ||
493 | UserProfileData user = GetUserByUUID(AgentID); | ||
494 | user.WebLoginKey = WebLoginKey; | ||
495 | fillUserRow(row, user); | ||
496 | da.Update(ds, "users"); | ||
497 | } | ||
498 | } | ||
499 | } | ||
500 | |||
501 | private bool ExistsFirstLastName(String fname, String lname) | ||
502 | { | ||
503 | string FindUser = "select * from users where (username=:username and surname=:surname)"; | ||
504 | using (SqliteCommand cmd = new SqliteCommand(FindUser, g_conn)) | ||
505 | { | ||
506 | cmd.Parameters.Add(new SqliteParameter(":username", fname)); | ||
507 | cmd.Parameters.Add(new SqliteParameter(":surname", lname)); | ||
508 | try | ||
509 | { | ||
510 | using (IDataReader reader = cmd.ExecuteReader()) | ||
511 | { | ||
512 | if (reader.Read()) | ||
513 | { | ||
514 | reader.Close(); | ||
515 | return true; | ||
516 | } | ||
517 | else | ||
518 | { | ||
519 | reader.Close(); | ||
520 | return false; | ||
521 | } | ||
522 | } | ||
523 | } | ||
524 | catch (Exception ex) | ||
525 | { | ||
526 | m_log.Error("[USER DB]: Exception searching for user's first and last name: " + ex.ToString()); | ||
527 | return false; | ||
528 | } | ||
529 | } | ||
530 | } | ||
531 | |||
532 | /// <summary> | ||
533 | /// Creates a new user profile | ||
534 | /// </summary> | ||
535 | /// <param name="user">The profile to add to the database</param> | ||
536 | override public void AddNewUserProfile(UserProfileData user) | ||
537 | { | ||
538 | DataTable users = ds.Tables["users"]; | ||
539 | UUID zero = UUID.Zero; | ||
540 | if (ExistsFirstLastName(user.FirstName, user.SurName) || user.ID == zero) | ||
541 | return; | ||
542 | |||
543 | lock (ds) | ||
544 | { | ||
545 | DataRow row = users.Rows.Find(user.ID.ToString()); | ||
546 | if (row == null) | ||
547 | { | ||
548 | row = users.NewRow(); | ||
549 | fillUserRow(row, user); | ||
550 | users.Rows.Add(row); | ||
551 | |||
552 | m_log.Debug("[USER DB]: Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored"); | ||
553 | |||
554 | // save changes off to disk | ||
555 | da.Update(ds, "users"); | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | m_log.WarnFormat("[USER DB]: Ignoring add since user with id {0} already exists", user.ID); | ||
560 | } | ||
561 | } | ||
562 | } | ||
563 | |||
564 | /// <summary> | ||
565 | /// Creates a new user profile | ||
566 | /// </summary> | ||
567 | /// <param name="user">The profile to add to the database</param> | ||
568 | /// <returns>True on success, false on error</returns> | ||
569 | override public bool UpdateUserProfile(UserProfileData user) | ||
570 | { | ||
571 | DataTable users = ds.Tables["users"]; | ||
572 | lock (ds) | ||
573 | { | ||
574 | DataRow row = users.Rows.Find(user.ID.ToString()); | ||
575 | if (row == null) | ||
576 | { | ||
577 | return false; | ||
578 | } | ||
579 | else | ||
580 | { | ||
581 | fillUserRow(row, user); | ||
582 | da.Update(ds, "users"); | ||
583 | } | ||
584 | } | ||
585 | |||
586 | //AddNewUserProfile(user); | ||
587 | return true; | ||
588 | } | ||
589 | |||
590 | /// <summary> | ||
591 | /// Creates a new user agent | ||
592 | /// </summary> | ||
593 | /// <param name="agent">The agent to add to the database</param> | ||
594 | override public void AddNewUserAgent(UserAgentData agent) | ||
595 | { | ||
596 | UUID zero = UUID.Zero; | ||
597 | if (agent.SessionID == zero || agent.ProfileID == zero) | ||
598 | return; | ||
599 | |||
600 | DataTable agents = ds.Tables["useragents"]; | ||
601 | lock (ds) | ||
602 | { | ||
603 | DataRow row = agents.Rows.Find(agent.ProfileID.ToString()); | ||
604 | if (row == null) | ||
605 | { | ||
606 | row = agents.NewRow(); | ||
607 | fillUserAgentRow(row, agent); | ||
608 | agents.Rows.Add(row); | ||
609 | } | ||
610 | else | ||
611 | { | ||
612 | fillUserAgentRow(row, agent); | ||
613 | |||
614 | } | ||
615 | m_log.Info("[USER DB]: Syncing useragent database: " + ds.Tables["useragents"].Rows.Count + " agents stored"); | ||
616 | // save changes off to disk | ||
617 | dua.Update(ds, "useragents"); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | /// <summary> | ||
622 | /// Transfers money between two user accounts | ||
623 | /// </summary> | ||
624 | /// <param name="from">Starting account</param> | ||
625 | /// <param name="to">End account</param> | ||
626 | /// <param name="amount">The amount to move</param> | ||
627 | /// <returns>Success?</returns> | ||
628 | override public bool MoneyTransferRequest(UUID from, UUID to, uint amount) | ||
629 | { | ||
630 | return false; // for consistency with the MySQL impl | ||
631 | } | ||
632 | |||
633 | /// <summary> | ||
634 | /// Transfers inventory between two accounts | ||
635 | /// </summary> | ||
636 | /// <remarks>Move to inventory server</remarks> | ||
637 | /// <param name="from">Senders account</param> | ||
638 | /// <param name="to">Receivers account</param> | ||
639 | /// <param name="item">Inventory item</param> | ||
640 | /// <returns>Success?</returns> | ||
641 | override public bool InventoryTransferRequest(UUID from, UUID to, UUID item) | ||
642 | { | ||
643 | return false; //for consistency with the MySQL impl | ||
644 | } | ||
645 | |||
646 | |||
647 | /// <summary> | ||
648 | /// Appearance. | ||
649 | /// TODO: stubs for now to do in memory appearance. | ||
650 | /// </summary> | ||
651 | /// <param name="user">The user UUID</param> | ||
652 | /// <returns>Avatar Appearence</returns> | ||
653 | override public AvatarAppearance GetUserAppearance(UUID user) | ||
654 | { | ||
655 | m_log.Info("[APPEARANCE] GetUserAppearance " + user.ToString()); | ||
656 | |||
657 | AvatarAppearance aa = new AvatarAppearance(user); | ||
658 | //try { | ||
659 | aa.Owner = user; | ||
660 | |||
661 | DataTable aap = ds.Tables["avatarappearance"]; | ||
662 | lock (ds) | ||
663 | { | ||
664 | DataRow row = aap.Rows.Find(Util.ToRawUuidString(user)); | ||
665 | if (row == null) | ||
666 | { | ||
667 | m_log.Info("[APPEARANCE] Could not find appearance for " + user.ToString()); | ||
668 | |||
669 | //m_log.Debug("[USER DB]: Creating avatarappearance For: " + user.ToString()); | ||
670 | |||
671 | //row = aap.NewRow(); | ||
672 | //fillAvatarAppearanceRow(row, user, appearance); | ||
673 | //aap.Rows.Add(row); | ||
674 | // m_log.Debug("[USER DB]: Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored"); | ||
675 | // save changes off to disk | ||
676 | //daa.Update(ds, "avatarappearance"); | ||
677 | } | ||
678 | else | ||
679 | { | ||
680 | m_log.InfoFormat("[APPEARANCE] appearance found for {0}", user.ToString()); | ||
681 | |||
682 | aa.BodyAsset = new UUID((String)row["BodyAsset"]); | ||
683 | aa.BodyItem = new UUID((String)row["BodyItem"]); | ||
684 | aa.SkinItem = new UUID((String)row["SkinItem"]); | ||
685 | aa.SkinAsset = new UUID((String)row["SkinAsset"]); | ||
686 | aa.HairItem = new UUID((String)row["HairItem"]); | ||
687 | aa.HairAsset = new UUID((String)row["HairAsset"]); | ||
688 | aa.EyesItem = new UUID((String)row["EyesItem"]); | ||
689 | aa.EyesAsset = new UUID((String)row["EyesAsset"]); | ||
690 | aa.ShirtItem = new UUID((String)row["ShirtItem"]); | ||
691 | aa.ShirtAsset = new UUID((String)row["ShirtAsset"]); | ||
692 | aa.PantsItem = new UUID((String)row["PantsItem"]); | ||
693 | aa.PantsAsset = new UUID((String)row["PantsAsset"]); | ||
694 | aa.ShoesItem = new UUID((String)row["ShoesItem"]); | ||
695 | aa.ShoesAsset = new UUID((String)row["ShoesAsset"]); | ||
696 | aa.SocksItem = new UUID((String)row["SocksItem"]); | ||
697 | aa.SocksAsset = new UUID((String)row["SocksAsset"]); | ||
698 | aa.JacketItem = new UUID((String)row["JacketItem"]); | ||
699 | aa.JacketAsset = new UUID((String)row["JacketAsset"]); | ||
700 | aa.GlovesItem = new UUID((String)row["GlovesItem"]); | ||
701 | aa.GlovesAsset = new UUID((String)row["GlovesAsset"]); | ||
702 | aa.UnderShirtItem = new UUID((String)row["UnderShirtItem"]); | ||
703 | aa.UnderShirtAsset = new UUID((String)row["UnderShirtAsset"]); | ||
704 | aa.UnderPantsItem = new UUID((String)row["UnderPantsItem"]); | ||
705 | aa.UnderPantsAsset = new UUID((String)row["UnderPantsAsset"]); | ||
706 | aa.SkirtItem = new UUID((String)row["SkirtItem"]); | ||
707 | aa.SkirtAsset = new UUID((String)row["SkirtAsset"]); | ||
708 | |||
709 | // Ewe Loon | ||
710 | // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) | ||
711 | |||
712 | String str = (String)row["Texture"]; | ||
713 | byte[] texture = Convert.FromBase64String(str); | ||
714 | aa.Texture = new Primitive.TextureEntry(texture, 0, texture.Length); | ||
715 | |||
716 | str = (String)row["VisualParams"]; | ||
717 | byte[] VisualParams = Convert.FromBase64String(str); | ||
718 | aa.VisualParams = VisualParams; | ||
719 | |||
720 | aa.Serial = Convert.ToInt32(row["Serial"]); | ||
721 | aa.AvatarHeight = Convert.ToSingle(row["AvatarHeight"]); | ||
722 | m_log.InfoFormat("[APPEARANCE] appearance set for {0}", user.ToString()); | ||
723 | } | ||
724 | } | ||
725 | |||
726 | // m_log.Info("[APPEARANCE] Found appearance for " + user.ToString() + aa.ToString()); | ||
727 | // } catch (KeyNotFoundException) { | ||
728 | // m_log.InfoFormat("[APPEARANCE] No appearance found for {0}", user.ToString()); | ||
729 | // } | ||
730 | return aa; | ||
731 | } | ||
732 | |||
733 | /// <summary> | ||
734 | /// Update a user appearence | ||
735 | /// </summary> | ||
736 | /// <param name="user">the user UUID</param> | ||
737 | /// <param name="appearance">appearence</param> | ||
738 | override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) | ||
739 | { | ||
740 | appearance.Owner = user; | ||
741 | DataTable aap = ds.Tables["avatarappearance"]; | ||
742 | lock (ds) | ||
743 | { | ||
744 | DataRow row = aap.Rows.Find(Util.ToRawUuidString(user)); | ||
745 | if (row == null) | ||
746 | { | ||
747 | m_log.Debug("[USER DB]: Creating UserAppearance For: " + user.ToString()); | ||
748 | |||
749 | row = aap.NewRow(); | ||
750 | fillAvatarAppearanceRow(row, user, appearance); | ||
751 | aap.Rows.Add(row); | ||
752 | // m_log.Debug("[USER DB]: Syncing user database: " + ds.Tables["users"].Rows.Count + " users stored"); | ||
753 | // save changes off to disk | ||
754 | daa.Update(ds, "avatarappearance"); | ||
755 | } | ||
756 | else | ||
757 | { | ||
758 | m_log.Debug("[USER DB]: Updating UserAppearance For: " + user.ToString()); | ||
759 | fillAvatarAppearanceRow(row, user, appearance); | ||
760 | daa.Update(ds, "avatarappearance"); | ||
761 | } | ||
762 | } | ||
763 | } | ||
764 | |||
765 | /// <summary> | ||
766 | /// Returns the name of the storage provider | ||
767 | /// </summary> | ||
768 | /// <returns>Storage provider name</returns> | ||
769 | override public string Name | ||
770 | { | ||
771 | get {return "Sqlite Userdata";} | ||
772 | } | ||
773 | |||
774 | /// <summary> | ||
775 | /// Returns the version of the storage provider | ||
776 | /// </summary> | ||
777 | /// <returns>Storage provider version</returns> | ||
778 | override public string Version | ||
779 | { | ||
780 | get {return "0.1";} | ||
781 | } | ||
782 | |||
783 | /*********************************************************************** | ||
784 | * | ||
785 | * DataTable creation | ||
786 | * | ||
787 | **********************************************************************/ | ||
788 | /*********************************************************************** | ||
789 | * | ||
790 | * Database Definition Functions | ||
791 | * | ||
792 | * This should be db agnostic as we define them in ADO.NET terms | ||
793 | * | ||
794 | **********************************************************************/ | ||
795 | |||
796 | /// <summary> | ||
797 | /// Create the "users" table | ||
798 | /// </summary> | ||
799 | /// <returns>DataTable</returns> | ||
800 | private static DataTable createUsersTable() | ||
801 | { | ||
802 | DataTable users = new DataTable("users"); | ||
803 | |||
804 | SQLiteUtil.createCol(users, "UUID", typeof (String)); | ||
805 | SQLiteUtil.createCol(users, "username", typeof (String)); | ||
806 | SQLiteUtil.createCol(users, "surname", typeof (String)); | ||
807 | SQLiteUtil.createCol(users, "email", typeof (String)); | ||
808 | SQLiteUtil.createCol(users, "passwordHash", typeof (String)); | ||
809 | SQLiteUtil.createCol(users, "passwordSalt", typeof (String)); | ||
810 | |||
811 | SQLiteUtil.createCol(users, "homeRegionX", typeof (Int32)); | ||
812 | SQLiteUtil.createCol(users, "homeRegionY", typeof (Int32)); | ||
813 | SQLiteUtil.createCol(users, "homeRegionID", typeof (String)); | ||
814 | SQLiteUtil.createCol(users, "homeLocationX", typeof (Double)); | ||
815 | SQLiteUtil.createCol(users, "homeLocationY", typeof (Double)); | ||
816 | SQLiteUtil.createCol(users, "homeLocationZ", typeof (Double)); | ||
817 | SQLiteUtil.createCol(users, "homeLookAtX", typeof (Double)); | ||
818 | SQLiteUtil.createCol(users, "homeLookAtY", typeof (Double)); | ||
819 | SQLiteUtil.createCol(users, "homeLookAtZ", typeof (Double)); | ||
820 | SQLiteUtil.createCol(users, "created", typeof (Int32)); | ||
821 | SQLiteUtil.createCol(users, "lastLogin", typeof (Int32)); | ||
822 | |||
823 | //TODO: Please delete this column. It's now a brick | ||
824 | SQLiteUtil.createCol(users, "rootInventoryFolderID", typeof (String)); | ||
825 | |||
826 | SQLiteUtil.createCol(users, "userInventoryURI", typeof (String)); | ||
827 | SQLiteUtil.createCol(users, "userAssetURI", typeof (String)); | ||
828 | SQLiteUtil.createCol(users, "profileCanDoMask", typeof (Int32)); | ||
829 | SQLiteUtil.createCol(users, "profileWantDoMask", typeof (Int32)); | ||
830 | SQLiteUtil.createCol(users, "profileAboutText", typeof (String)); | ||
831 | SQLiteUtil.createCol(users, "profileFirstText", typeof (String)); | ||
832 | SQLiteUtil.createCol(users, "profileImage", typeof (String)); | ||
833 | SQLiteUtil.createCol(users, "profileFirstImage", typeof (String)); | ||
834 | SQLiteUtil.createCol(users, "webLoginKey", typeof(String)); | ||
835 | SQLiteUtil.createCol(users, "userFlags", typeof (Int32)); | ||
836 | SQLiteUtil.createCol(users, "godLevel", typeof (Int32)); | ||
837 | SQLiteUtil.createCol(users, "customType", typeof (String)); | ||
838 | SQLiteUtil.createCol(users, "partner", typeof (String)); | ||
839 | // Add in contraints | ||
840 | users.PrimaryKey = new DataColumn[] {users.Columns["UUID"]}; | ||
841 | return users; | ||
842 | } | ||
843 | |||
844 | /// <summary> | ||
845 | /// Create the "useragents" table | ||
846 | /// </summary> | ||
847 | /// <returns>Data Table</returns> | ||
848 | private static DataTable createUserAgentsTable() | ||
849 | { | ||
850 | DataTable ua = new DataTable("useragents"); | ||
851 | // this is the UUID of the user | ||
852 | SQLiteUtil.createCol(ua, "UUID", typeof (String)); | ||
853 | SQLiteUtil.createCol(ua, "agentIP", typeof (String)); | ||
854 | SQLiteUtil.createCol(ua, "agentPort", typeof (Int32)); | ||
855 | SQLiteUtil.createCol(ua, "agentOnline", typeof (Boolean)); | ||
856 | SQLiteUtil.createCol(ua, "sessionID", typeof (String)); | ||
857 | SQLiteUtil.createCol(ua, "secureSessionID", typeof (String)); | ||
858 | SQLiteUtil.createCol(ua, "regionID", typeof (String)); | ||
859 | SQLiteUtil.createCol(ua, "loginTime", typeof (Int32)); | ||
860 | SQLiteUtil.createCol(ua, "logoutTime", typeof (Int32)); | ||
861 | SQLiteUtil.createCol(ua, "currentRegion", typeof (String)); | ||
862 | SQLiteUtil.createCol(ua, "currentHandle", typeof (String)); | ||
863 | // vectors | ||
864 | SQLiteUtil.createCol(ua, "currentPosX", typeof (Double)); | ||
865 | SQLiteUtil.createCol(ua, "currentPosY", typeof (Double)); | ||
866 | SQLiteUtil.createCol(ua, "currentPosZ", typeof (Double)); | ||
867 | // constraints | ||
868 | ua.PrimaryKey = new DataColumn[] {ua.Columns["UUID"]}; | ||
869 | |||
870 | return ua; | ||
871 | } | ||
872 | |||
873 | /// <summary> | ||
874 | /// Create the "userfriends" table | ||
875 | /// </summary> | ||
876 | /// <returns>Data Table</returns> | ||
877 | private static DataTable createUserFriendsTable() | ||
878 | { | ||
879 | DataTable ua = new DataTable("userfriends"); | ||
880 | // table contains user <----> user relationship with perms | ||
881 | SQLiteUtil.createCol(ua, "ownerID", typeof(String)); | ||
882 | SQLiteUtil.createCol(ua, "friendID", typeof(String)); | ||
883 | SQLiteUtil.createCol(ua, "friendPerms", typeof(Int32)); | ||
884 | SQLiteUtil.createCol(ua, "ownerPerms", typeof(Int32)); | ||
885 | SQLiteUtil.createCol(ua, "datetimestamp", typeof(Int32)); | ||
886 | |||
887 | return ua; | ||
888 | } | ||
889 | |||
890 | /// <summary> | ||
891 | /// Create the "avatarappearance" table | ||
892 | /// </summary> | ||
893 | /// <returns>Data Table</returns> | ||
894 | private static DataTable createAvatarAppearanceTable() | ||
895 | { | ||
896 | DataTable aa = new DataTable("avatarappearance"); | ||
897 | // table contains user appearance items | ||
898 | |||
899 | SQLiteUtil.createCol(aa, "Owner", typeof(String)); | ||
900 | SQLiteUtil.createCol(aa, "BodyItem", typeof(String)); | ||
901 | SQLiteUtil.createCol(aa, "BodyAsset", typeof(String)); | ||
902 | SQLiteUtil.createCol(aa, "SkinItem", typeof(String)); | ||
903 | SQLiteUtil.createCol(aa, "SkinAsset", typeof(String)); | ||
904 | SQLiteUtil.createCol(aa, "HairItem", typeof(String)); | ||
905 | SQLiteUtil.createCol(aa, "HairAsset", typeof(String)); | ||
906 | SQLiteUtil.createCol(aa, "EyesItem", typeof(String)); | ||
907 | SQLiteUtil.createCol(aa, "EyesAsset", typeof(String)); | ||
908 | SQLiteUtil.createCol(aa, "ShirtItem", typeof(String)); | ||
909 | SQLiteUtil.createCol(aa, "ShirtAsset", typeof(String)); | ||
910 | SQLiteUtil.createCol(aa, "PantsItem", typeof(String)); | ||
911 | SQLiteUtil.createCol(aa, "PantsAsset", typeof(String)); | ||
912 | SQLiteUtil.createCol(aa, "ShoesItem", typeof(String)); | ||
913 | SQLiteUtil.createCol(aa, "ShoesAsset", typeof(String)); | ||
914 | SQLiteUtil.createCol(aa, "SocksItem", typeof(String)); | ||
915 | SQLiteUtil.createCol(aa, "SocksAsset", typeof(String)); | ||
916 | SQLiteUtil.createCol(aa, "JacketItem", typeof(String)); | ||
917 | SQLiteUtil.createCol(aa, "JacketAsset", typeof(String)); | ||
918 | SQLiteUtil.createCol(aa, "GlovesItem", typeof(String)); | ||
919 | SQLiteUtil.createCol(aa, "GlovesAsset", typeof(String)); | ||
920 | SQLiteUtil.createCol(aa, "UnderShirtItem", typeof(String)); | ||
921 | SQLiteUtil.createCol(aa, "UnderShirtAsset", typeof(String)); | ||
922 | SQLiteUtil.createCol(aa, "UnderPantsItem", typeof(String)); | ||
923 | SQLiteUtil.createCol(aa, "UnderPantsAsset", typeof(String)); | ||
924 | SQLiteUtil.createCol(aa, "SkirtItem", typeof(String)); | ||
925 | SQLiteUtil.createCol(aa, "SkirtAsset", typeof(String)); | ||
926 | |||
927 | // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) | ||
928 | SQLiteUtil.createCol(aa, "Texture", typeof (String)); | ||
929 | SQLiteUtil.createCol(aa, "VisualParams", typeof (String)); | ||
930 | |||
931 | SQLiteUtil.createCol(aa, "Serial", typeof(Int32)); | ||
932 | SQLiteUtil.createCol(aa, "AvatarHeight", typeof(Double)); | ||
933 | |||
934 | aa.PrimaryKey = new DataColumn[] { aa.Columns["Owner"] }; | ||
935 | |||
936 | return aa; | ||
937 | } | ||
938 | |||
939 | /*********************************************************************** | ||
940 | * | ||
941 | * Convert between ADO.NET <=> OpenSim Objects | ||
942 | * | ||
943 | * These should be database independant | ||
944 | * | ||
945 | **********************************************************************/ | ||
946 | |||
947 | /// <summary> | ||
948 | /// TODO: this doesn't work yet because something more | ||
949 | /// interesting has to be done to actually get these values | ||
950 | /// back out. Not enough time to figure it out yet. | ||
951 | /// </summary> | ||
952 | /// <param name="row"></param> | ||
953 | /// <returns></returns> | ||
954 | private static UserProfileData buildUserProfile(DataRow row) | ||
955 | { | ||
956 | UserProfileData user = new UserProfileData(); | ||
957 | UUID tmp; | ||
958 | UUID.TryParse((String)row["UUID"], out tmp); | ||
959 | user.ID = tmp; | ||
960 | user.FirstName = (String) row["username"]; | ||
961 | user.SurName = (String) row["surname"]; | ||
962 | user.Email = (row.IsNull("email")) ? "" : (String) row["email"]; | ||
963 | |||
964 | user.PasswordHash = (String) row["passwordHash"]; | ||
965 | user.PasswordSalt = (String) row["passwordSalt"]; | ||
966 | |||
967 | user.HomeRegionX = Convert.ToUInt32(row["homeRegionX"]); | ||
968 | user.HomeRegionY = Convert.ToUInt32(row["homeRegionY"]); | ||
969 | user.HomeLocation = new Vector3( | ||
970 | Convert.ToSingle(row["homeLocationX"]), | ||
971 | Convert.ToSingle(row["homeLocationY"]), | ||
972 | Convert.ToSingle(row["homeLocationZ"]) | ||
973 | ); | ||
974 | user.HomeLookAt = new Vector3( | ||
975 | Convert.ToSingle(row["homeLookAtX"]), | ||
976 | Convert.ToSingle(row["homeLookAtY"]), | ||
977 | Convert.ToSingle(row["homeLookAtZ"]) | ||
978 | ); | ||
979 | |||
980 | UUID regionID = UUID.Zero; | ||
981 | UUID.TryParse(row["homeRegionID"].ToString(), out regionID); // it's ok if it doesn't work; just use UUID.Zero | ||
982 | user.HomeRegionID = regionID; | ||
983 | |||
984 | user.Created = Convert.ToInt32(row["created"]); | ||
985 | user.LastLogin = Convert.ToInt32(row["lastLogin"]); | ||
986 | user.UserInventoryURI = (String) row["userInventoryURI"]; | ||
987 | user.UserAssetURI = (String) row["userAssetURI"]; | ||
988 | user.CanDoMask = Convert.ToUInt32(row["profileCanDoMask"]); | ||
989 | user.WantDoMask = Convert.ToUInt32(row["profileWantDoMask"]); | ||
990 | user.AboutText = (String) row["profileAboutText"]; | ||
991 | user.FirstLifeAboutText = (String) row["profileFirstText"]; | ||
992 | UUID.TryParse((String)row["profileImage"], out tmp); | ||
993 | user.Image = tmp; | ||
994 | UUID.TryParse((String)row["profileFirstImage"], out tmp); | ||
995 | user.FirstLifeImage = tmp; | ||
996 | user.WebLoginKey = new UUID((String) row["webLoginKey"]); | ||
997 | user.UserFlags = Convert.ToInt32(row["userFlags"]); | ||
998 | user.GodLevel = Convert.ToInt32(row["godLevel"]); | ||
999 | user.CustomType = row["customType"].ToString(); | ||
1000 | user.Partner = new UUID((String) row["partner"]); | ||
1001 | |||
1002 | return user; | ||
1003 | } | ||
1004 | |||
1005 | /// <summary> | ||
1006 | /// Persist user profile data | ||
1007 | /// </summary> | ||
1008 | /// <param name="row"></param> | ||
1009 | /// <param name="user"></param> | ||
1010 | private void fillUserRow(DataRow row, UserProfileData user) | ||
1011 | { | ||
1012 | row["UUID"] = user.ID.ToString(); | ||
1013 | row["username"] = user.FirstName; | ||
1014 | row["surname"] = user.SurName; | ||
1015 | row["email"] = user.Email; | ||
1016 | row["passwordHash"] = user.PasswordHash; | ||
1017 | row["passwordSalt"] = user.PasswordSalt; | ||
1018 | |||
1019 | row["homeRegionX"] = user.HomeRegionX; | ||
1020 | row["homeRegionY"] = user.HomeRegionY; | ||
1021 | row["homeRegionID"] = user.HomeRegionID.ToString(); | ||
1022 | row["homeLocationX"] = user.HomeLocation.X; | ||
1023 | row["homeLocationY"] = user.HomeLocation.Y; | ||
1024 | row["homeLocationZ"] = user.HomeLocation.Z; | ||
1025 | row["homeLookAtX"] = user.HomeLookAt.X; | ||
1026 | row["homeLookAtY"] = user.HomeLookAt.Y; | ||
1027 | row["homeLookAtZ"] = user.HomeLookAt.Z; | ||
1028 | |||
1029 | row["created"] = user.Created; | ||
1030 | row["lastLogin"] = user.LastLogin; | ||
1031 | //TODO: Get rid of rootInventoryFolderID in a safe way. | ||
1032 | row["rootInventoryFolderID"] = UUID.Zero.ToString(); | ||
1033 | row["userInventoryURI"] = user.UserInventoryURI; | ||
1034 | row["userAssetURI"] = user.UserAssetURI; | ||
1035 | row["profileCanDoMask"] = user.CanDoMask; | ||
1036 | row["profileWantDoMask"] = user.WantDoMask; | ||
1037 | row["profileAboutText"] = user.AboutText; | ||
1038 | row["profileFirstText"] = user.FirstLifeAboutText; | ||
1039 | row["profileImage"] = user.Image.ToString(); | ||
1040 | row["profileFirstImage"] = user.FirstLifeImage.ToString(); | ||
1041 | row["webLoginKey"] = user.WebLoginKey.ToString(); | ||
1042 | row["userFlags"] = user.UserFlags; | ||
1043 | row["godLevel"] = user.GodLevel; | ||
1044 | row["customType"] = user.CustomType == null ? "" : user.CustomType; | ||
1045 | row["partner"] = user.Partner.ToString(); | ||
1046 | |||
1047 | // ADO.NET doesn't handle NULL very well | ||
1048 | foreach (DataColumn col in ds.Tables["users"].Columns) | ||
1049 | { | ||
1050 | if (row[col] == null) | ||
1051 | { | ||
1052 | row[col] = String.Empty; | ||
1053 | } | ||
1054 | } | ||
1055 | } | ||
1056 | |||
1057 | /// <summary> | ||
1058 | /// | ||
1059 | /// </summary> | ||
1060 | /// <param name="row"></param> | ||
1061 | /// <param name="user"></param> | ||
1062 | private void fillAvatarAppearanceRow(DataRow row, UUID user, AvatarAppearance appearance) | ||
1063 | { | ||
1064 | row["Owner"] = Util.ToRawUuidString(user); | ||
1065 | row["BodyItem"] = appearance.BodyItem.ToString(); | ||
1066 | row["BodyAsset"] = appearance.BodyAsset.ToString(); | ||
1067 | row["SkinItem"] = appearance.SkinItem.ToString(); | ||
1068 | row["SkinAsset"] = appearance.SkinAsset.ToString(); | ||
1069 | row["HairItem"] = appearance.HairItem.ToString(); | ||
1070 | row["HairAsset"] = appearance.HairAsset.ToString(); | ||
1071 | row["EyesItem"] = appearance.EyesItem.ToString(); | ||
1072 | row["EyesAsset"] = appearance.EyesAsset.ToString(); | ||
1073 | row["ShirtItem"] = appearance.ShirtItem.ToString(); | ||
1074 | row["ShirtAsset"] = appearance.ShirtAsset.ToString(); | ||
1075 | row["PantsItem"] = appearance.PantsItem.ToString(); | ||
1076 | row["PantsAsset"] = appearance.PantsAsset.ToString(); | ||
1077 | row["ShoesItem"] = appearance.ShoesItem.ToString(); | ||
1078 | row["ShoesAsset"] = appearance.ShoesAsset.ToString(); | ||
1079 | row["SocksItem"] = appearance.SocksItem.ToString(); | ||
1080 | row["SocksAsset"] = appearance.SocksAsset.ToString(); | ||
1081 | row["JacketItem"] = appearance.JacketItem.ToString(); | ||
1082 | row["JacketAsset"] = appearance.JacketAsset.ToString(); | ||
1083 | row["GlovesItem"] = appearance.GlovesItem.ToString(); | ||
1084 | row["GlovesAsset"] = appearance.GlovesAsset.ToString(); | ||
1085 | row["UnderShirtItem"] = appearance.UnderShirtItem.ToString(); | ||
1086 | row["UnderShirtAsset"] = appearance.UnderShirtAsset.ToString(); | ||
1087 | row["UnderPantsItem"] = appearance.UnderPantsItem.ToString(); | ||
1088 | row["UnderPantsAsset"] = appearance.UnderPantsAsset.ToString(); | ||
1089 | row["SkirtItem"] = appearance.SkirtItem.ToString(); | ||
1090 | row["SkirtAsset"] = appearance.SkirtAsset.ToString(); | ||
1091 | |||
1092 | // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) | ||
1093 | row["Texture"] = Convert.ToBase64String(appearance.Texture.GetBytes()); | ||
1094 | row["VisualParams"] = Convert.ToBase64String(appearance.VisualParams); | ||
1095 | |||
1096 | row["Serial"] = appearance.Serial; | ||
1097 | row["AvatarHeight"] = appearance.AvatarHeight; | ||
1098 | |||
1099 | // ADO.NET doesn't handle NULL very well | ||
1100 | foreach (DataColumn col in ds.Tables["avatarappearance"].Columns) | ||
1101 | { | ||
1102 | if (row[col] == null) | ||
1103 | { | ||
1104 | row[col] = String.Empty; | ||
1105 | } | ||
1106 | } | ||
1107 | } | ||
1108 | |||
1109 | /// <summary> | ||
1110 | /// | ||
1111 | /// </summary> | ||
1112 | /// <param name="row"></param> | ||
1113 | /// <returns></returns> | ||
1114 | private static UserAgentData buildUserAgent(DataRow row) | ||
1115 | { | ||
1116 | UserAgentData ua = new UserAgentData(); | ||
1117 | |||
1118 | UUID tmp; | ||
1119 | UUID.TryParse((String)row["UUID"], out tmp); | ||
1120 | ua.ProfileID = tmp; | ||
1121 | ua.AgentIP = (String)row["agentIP"]; | ||
1122 | ua.AgentPort = Convert.ToUInt32(row["agentPort"]); | ||
1123 | ua.AgentOnline = Convert.ToBoolean(row["agentOnline"]); | ||
1124 | ua.SessionID = new UUID((String) row["sessionID"]); | ||
1125 | ua.SecureSessionID = new UUID((String) row["secureSessionID"]); | ||
1126 | ua.InitialRegion = new UUID((String) row["regionID"]); | ||
1127 | ua.LoginTime = Convert.ToInt32(row["loginTime"]); | ||
1128 | ua.LogoutTime = Convert.ToInt32(row["logoutTime"]); | ||
1129 | ua.Region = new UUID((String) row["currentRegion"]); | ||
1130 | ua.Handle = Convert.ToUInt64(row["currentHandle"]); | ||
1131 | ua.Position = new Vector3( | ||
1132 | Convert.ToSingle(row["currentPosX"]), | ||
1133 | Convert.ToSingle(row["currentPosY"]), | ||
1134 | Convert.ToSingle(row["currentPosZ"]) | ||
1135 | ); | ||
1136 | ua.LookAt = new Vector3( | ||
1137 | Convert.ToSingle(row["currentLookAtX"]), | ||
1138 | Convert.ToSingle(row["currentLookAtY"]), | ||
1139 | Convert.ToSingle(row["currentLookAtZ"]) | ||
1140 | ); | ||
1141 | return ua; | ||
1142 | } | ||
1143 | |||
1144 | /// <summary> | ||
1145 | /// | ||
1146 | /// </summary> | ||
1147 | /// <param name="row"></param> | ||
1148 | /// <param name="ua"></param> | ||
1149 | private static void fillUserAgentRow(DataRow row, UserAgentData ua) | ||
1150 | { | ||
1151 | row["UUID"] = ua.ProfileID.ToString(); | ||
1152 | row["agentIP"] = ua.AgentIP; | ||
1153 | row["agentPort"] = ua.AgentPort; | ||
1154 | row["agentOnline"] = ua.AgentOnline; | ||
1155 | row["sessionID"] = ua.SessionID.ToString(); | ||
1156 | row["secureSessionID"] = ua.SecureSessionID.ToString(); | ||
1157 | row["regionID"] = ua.InitialRegion.ToString(); | ||
1158 | row["loginTime"] = ua.LoginTime; | ||
1159 | row["logoutTime"] = ua.LogoutTime; | ||
1160 | row["currentRegion"] = ua.Region.ToString(); | ||
1161 | row["currentHandle"] = ua.Handle.ToString(); | ||
1162 | // vectors | ||
1163 | row["currentPosX"] = ua.Position.X; | ||
1164 | row["currentPosY"] = ua.Position.Y; | ||
1165 | row["currentPosZ"] = ua.Position.Z; | ||
1166 | row["currentLookAtX"] = ua.LookAt.X; | ||
1167 | row["currentLookAtY"] = ua.LookAt.Y; | ||
1168 | row["currentLookAtZ"] = ua.LookAt.Z; | ||
1169 | } | ||
1170 | |||
1171 | /*********************************************************************** | ||
1172 | * | ||
1173 | * Database Binding functions | ||
1174 | * | ||
1175 | * These will be db specific due to typing, and minor differences | ||
1176 | * in databases. | ||
1177 | * | ||
1178 | **********************************************************************/ | ||
1179 | |||
1180 | /// <summary> | ||
1181 | /// | ||
1182 | /// </summary> | ||
1183 | /// <param name="da"></param> | ||
1184 | /// <param name="conn"></param> | ||
1185 | private void setupUserCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
1186 | { | ||
1187 | da.InsertCommand = SQLiteUtil.createInsertCommand("users", ds.Tables["users"]); | ||
1188 | da.InsertCommand.Connection = conn; | ||
1189 | |||
1190 | da.UpdateCommand = SQLiteUtil.createUpdateCommand("users", "UUID=:UUID", ds.Tables["users"]); | ||
1191 | da.UpdateCommand.Connection = conn; | ||
1192 | |||
1193 | SqliteCommand delete = new SqliteCommand("delete from users where UUID = :UUID"); | ||
1194 | delete.Parameters.Add(SQLiteUtil.createSqliteParameter("UUID", typeof(String))); | ||
1195 | delete.Connection = conn; | ||
1196 | da.DeleteCommand = delete; | ||
1197 | } | ||
1198 | |||
1199 | private void setupAgentCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
1200 | { | ||
1201 | da.InsertCommand = SQLiteUtil.createInsertCommand("useragents", ds.Tables["useragents"]); | ||
1202 | da.InsertCommand.Connection = conn; | ||
1203 | |||
1204 | da.UpdateCommand = SQLiteUtil.createUpdateCommand("useragents", "UUID=:UUID", ds.Tables["useragents"]); | ||
1205 | da.UpdateCommand.Connection = conn; | ||
1206 | |||
1207 | SqliteCommand delete = new SqliteCommand("delete from useragents where UUID = :ProfileID"); | ||
1208 | delete.Parameters.Add(SQLiteUtil.createSqliteParameter("ProfileID", typeof(String))); | ||
1209 | delete.Connection = conn; | ||
1210 | da.DeleteCommand = delete; | ||
1211 | } | ||
1212 | |||
1213 | /// <summary> | ||
1214 | /// | ||
1215 | /// </summary> | ||
1216 | /// <param name="daf"></param> | ||
1217 | /// <param name="conn"></param> | ||
1218 | private void setupUserFriendsCommands(SqliteDataAdapter daf, SqliteConnection conn) | ||
1219 | { | ||
1220 | daf.InsertCommand = SQLiteUtil.createInsertCommand("userfriends", ds.Tables["userfriends"]); | ||
1221 | daf.InsertCommand.Connection = conn; | ||
1222 | |||
1223 | daf.UpdateCommand = SQLiteUtil.createUpdateCommand("userfriends", "ownerID=:ownerID and friendID=:friendID", ds.Tables["userfriends"]); | ||
1224 | daf.UpdateCommand.Connection = conn; | ||
1225 | |||
1226 | SqliteCommand delete = new SqliteCommand("delete from userfriends where ownerID=:ownerID and friendID=:friendID"); | ||
1227 | delete.Parameters.Add(SQLiteUtil.createSqliteParameter("ownerID", typeof(String))); | ||
1228 | delete.Parameters.Add(SQLiteUtil.createSqliteParameter("friendID", typeof(String))); | ||
1229 | delete.Connection = conn; | ||
1230 | daf.DeleteCommand = delete; | ||
1231 | |||
1232 | } | ||
1233 | |||
1234 | /// <summary> | ||
1235 | /// | ||
1236 | /// </summary> | ||
1237 | /// <param name="daf"></param> | ||
1238 | /// <param name="conn"></param> | ||
1239 | private void setupAvatarAppearanceCommands(SqliteDataAdapter daa, SqliteConnection conn) | ||
1240 | { | ||
1241 | daa.InsertCommand = SQLiteUtil.createInsertCommand("avatarappearance", ds.Tables["avatarappearance"]); | ||
1242 | daa.InsertCommand.Connection = conn; | ||
1243 | |||
1244 | daa.UpdateCommand = SQLiteUtil.createUpdateCommand("avatarappearance", "Owner=:Owner", ds.Tables["avatarappearance"]); | ||
1245 | daa.UpdateCommand.Connection = conn; | ||
1246 | |||
1247 | SqliteCommand delete = new SqliteCommand("delete from avatarappearance where Owner=:Owner"); | ||
1248 | delete.Parameters.Add(SQLiteUtil.createSqliteParameter("Owner", typeof(String))); | ||
1249 | delete.Connection = conn; | ||
1250 | daa.DeleteCommand = delete; | ||
1251 | } | ||
1252 | |||
1253 | |||
1254 | override public void ResetAttachments(UUID userID) | ||
1255 | { | ||
1256 | } | ||
1257 | |||
1258 | override public void LogoutUsers(UUID regionID) | ||
1259 | { | ||
1260 | } | ||
1261 | } | ||
1262 | } | ||
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteUserTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteUserTest.cs deleted file mode 100644 index c9953c5..0000000 --- a/OpenSim/Data/SQLite/Tests/SQLiteUserTest.cs +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using NUnit.Framework; | ||
30 | using OpenSim.Data.Tests; | ||
31 | using OpenSim.Tests.Common; | ||
32 | |||
33 | namespace OpenSim.Data.SQLite.Tests | ||
34 | { | ||
35 | [TestFixture, DatabaseTest] | ||
36 | public class SQLiteUserTest : BasicUserTest | ||
37 | { | ||
38 | public string file; | ||
39 | public string connect; | ||
40 | |||
41 | [TestFixtureSetUp] | ||
42 | public void Init() | ||
43 | { | ||
44 | // SQLite doesn't work on power or z linux | ||
45 | if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd")) | ||
46 | { | ||
47 | Assert.Ignore(); | ||
48 | } | ||
49 | |||
50 | SuperInit(); | ||
51 | file = Path.GetTempFileName() + ".db"; | ||
52 | connect = "URI=file:" + file + ",version=3"; | ||
53 | db = new SQLiteUserData(); | ||
54 | db.Initialise(connect); | ||
55 | } | ||
56 | |||
57 | [TestFixtureTearDown] | ||
58 | public void Cleanup() | ||
59 | { | ||
60 | db.Dispose(); | ||
61 | File.Delete(file); | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs deleted file mode 100644 index df6c669..0000000 --- a/OpenSim/Data/Tests/BasicGridTest.cs +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using NUnit.Framework; | ||
32 | using NUnit.Framework.SyntaxHelpers; | ||
33 | using OpenMetaverse; | ||
34 | |||
35 | namespace OpenSim.Data.Tests | ||
36 | { | ||
37 | public class BasicGridTest | ||
38 | { | ||
39 | public IGridDataPlugin db; | ||
40 | public UUID region1, region2, region3; | ||
41 | public UUID zero = UUID.Zero; | ||
42 | public static Random random = new Random(); | ||
43 | |||
44 | [TearDown] | ||
45 | public void removeAllRegions() | ||
46 | { | ||
47 | // Clean up all the regions. | ||
48 | List<RegionProfileData> regions = db.GetRegionsByName("", 100); | ||
49 | if (regions != null) | ||
50 | { | ||
51 | foreach (RegionProfileData region in regions) | ||
52 | { | ||
53 | db.DeleteProfile(region.Uuid.ToString()); | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | public void SuperInit() | ||
59 | { | ||
60 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | ||
61 | region1 = UUID.Random(); | ||
62 | region2 = UUID.Random(); | ||
63 | region3 = UUID.Random(); | ||
64 | } | ||
65 | |||
66 | protected RegionProfileData createRegion(UUID regionUUID, string regionName) | ||
67 | { | ||
68 | RegionProfileData reg = new RegionProfileData(); | ||
69 | new PropertyScrambler<RegionProfileData>().Scramble(reg); | ||
70 | reg.Uuid = regionUUID; | ||
71 | reg.RegionName = regionName; | ||
72 | |||
73 | db.StoreProfile(reg); | ||
74 | |||
75 | return reg; | ||
76 | } | ||
77 | |||
78 | [Test] | ||
79 | public void T001_LoadEmpty() | ||
80 | { | ||
81 | Assert.That(db.GetProfileByUUID(region1),Is.Null); | ||
82 | Assert.That(db.GetProfileByUUID(region2),Is.Null); | ||
83 | Assert.That(db.GetProfileByUUID(region3),Is.Null); | ||
84 | Assert.That(db.GetProfileByUUID(zero),Is.Null); | ||
85 | } | ||
86 | |||
87 | [Test] | ||
88 | public void T011_AddRetrieveCompleteTest() | ||
89 | { | ||
90 | RegionProfileData newreg = createRegion(region2, "|<Goth@m Ci1y>|"); | ||
91 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
92 | |||
93 | Assert.That(retreg, Constraints.PropertyCompareConstraint(newreg).IgnoreProperty(x => x.RegionOnline)); | ||
94 | |||
95 | retreg = db.GetProfileByHandle(newreg.RegionHandle); | ||
96 | Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))"); | ||
97 | |||
98 | retreg = db.GetProfileByString(newreg.RegionName); | ||
99 | Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))"); | ||
100 | |||
101 | RegionProfileData[] retregs = db.GetProfilesInRange(newreg.RegionLocX,newreg.RegionLocY,newreg.RegionLocX,newreg.RegionLocY); | ||
102 | Assert.That(retregs[0].Uuid, Is.EqualTo(region2), "Assert.That(retregs[0].Uuid, Is.EqualTo(region2))"); | ||
103 | } | ||
104 | |||
105 | [Test] | ||
106 | public void T012_DeleteProfile() | ||
107 | { | ||
108 | createRegion(region1, "doesn't matter"); | ||
109 | |||
110 | db.DeleteProfile(region1.ToString()); | ||
111 | RegionProfileData retreg = db.GetProfileByUUID(region1); | ||
112 | Assert.That(retreg,Is.Null); | ||
113 | } | ||
114 | |||
115 | [Test] | ||
116 | public void T013_UpdateProfile() | ||
117 | { | ||
118 | createRegion(region2, "|<Goth@m Ci1y>|"); | ||
119 | |||
120 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
121 | retreg.regionName = "Gotham City"; | ||
122 | |||
123 | db.StoreProfile(retreg); | ||
124 | |||
125 | retreg = db.GetProfileByUUID(region2); | ||
126 | Assert.That(retreg.RegionName, Is.EqualTo("Gotham City"), "Assert.That(retreg.RegionName, Is.EqualTo(\"Gotham City\"))"); | ||
127 | } | ||
128 | |||
129 | [Test] | ||
130 | public void T014_RegionList() | ||
131 | { | ||
132 | createRegion(region2, "Gotham City"); | ||
133 | |||
134 | RegionProfileData retreg = db.GetProfileByUUID(region2); | ||
135 | retreg.RegionName = "Gotham Town"; | ||
136 | retreg.Uuid = region1; | ||
137 | |||
138 | db.StoreProfile(retreg); | ||
139 | |||
140 | retreg = db.GetProfileByUUID(region2); | ||
141 | retreg.RegionName = "Gothan Town"; | ||
142 | retreg.Uuid = region3; | ||
143 | |||
144 | db.StoreProfile(retreg); | ||
145 | |||
146 | List<RegionProfileData> listreg = db.GetRegionsByName("Gotham",10); | ||
147 | |||
148 | Assert.That(listreg.Count,Is.EqualTo(2), "Assert.That(listreg.Count,Is.EqualTo(2))"); | ||
149 | Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid), "Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid))"); | ||
150 | Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))"); | ||
151 | Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))"); | ||
152 | } | ||
153 | |||
154 | [Test] | ||
155 | public void T999_StillNull() | ||
156 | { | ||
157 | Assert.That(db.GetProfileByUUID(zero), Is.Null); | ||
158 | } | ||
159 | |||
160 | protected static string RandomName() | ||
161 | { | ||
162 | StringBuilder name = new StringBuilder(); | ||
163 | int size = random.Next(5,12); | ||
164 | char ch ; | ||
165 | for (int i=0; i<size; i++) | ||
166 | { | ||
167 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
168 | name.Append(ch); | ||
169 | } | ||
170 | return name.ToString(); | ||
171 | } | ||
172 | } | ||
173 | } | ||
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs deleted file mode 100644 index d3b6041..0000000 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ /dev/null | |||
@@ -1,703 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | // TODO: Money Transfer, Inventory Transfer and UpdateUserRegion once they exist | ||
29 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | using log4net.Config; | ||
34 | using NUnit.Framework; | ||
35 | using NUnit.Framework.SyntaxHelpers; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using log4net; | ||
39 | using System.Reflection; | ||
40 | |||
41 | namespace OpenSim.Data.Tests | ||
42 | { | ||
43 | public class BasicUserTest | ||
44 | { | ||
45 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | public IUserDataPlugin db; | ||
47 | public UUID user1; | ||
48 | public UUID user2; | ||
49 | public UUID user3; | ||
50 | public UUID user4; | ||
51 | public UUID user5; | ||
52 | public UUID webkey; | ||
53 | public UUID zero = UUID.Zero; | ||
54 | public static Random random; | ||
55 | |||
56 | public UUID agent1; | ||
57 | public UUID agent2; | ||
58 | public UUID agent3; | ||
59 | public UUID agent4; | ||
60 | |||
61 | public UUID region1; | ||
62 | |||
63 | public string fname0; | ||
64 | public string lname0; | ||
65 | public string fname1; | ||
66 | public string lname1; | ||
67 | public string fname2; | ||
68 | public string lname2; | ||
69 | public string fname3; | ||
70 | public string lname3; | ||
71 | |||
72 | public void SuperInit() | ||
73 | { | ||
74 | OpenSim.Tests.Common.TestLogging.LogToConsole(); | ||
75 | random = new Random(); | ||
76 | user1 = UUID.Random(); | ||
77 | user2 = UUID.Random(); | ||
78 | user3 = UUID.Random(); | ||
79 | user4 = UUID.Random(); | ||
80 | user5 = UUID.Random(); | ||
81 | agent1 = UUID.Random(); | ||
82 | agent2 = UUID.Random(); | ||
83 | agent3 = UUID.Random(); | ||
84 | agent4 = UUID.Random(); | ||
85 | webkey = UUID.Random(); | ||
86 | region1 = UUID.Random(); | ||
87 | fname0 = RandomName(); | ||
88 | lname0 = RandomName(); | ||
89 | fname1 = RandomName(); | ||
90 | lname1 = RandomName(); | ||
91 | fname2 = RandomName(); | ||
92 | lname2 = RandomName(); | ||
93 | fname3 = RandomName(); | ||
94 | lname3 = RandomName(); | ||
95 | } | ||
96 | |||
97 | [Test] | ||
98 | public void T001_LoadEmpty() | ||
99 | { | ||
100 | Assert.That(db.GetUserByUUID(zero), Is.Null); | ||
101 | Assert.That(db.GetUserByUUID(user1), Is.Null); | ||
102 | Assert.That(db.GetUserByUUID(user2), Is.Null); | ||
103 | Assert.That(db.GetUserByUUID(user3), Is.Null); | ||
104 | Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null); | ||
105 | |||
106 | Assert.That(db.GetAgentByUUID(zero), Is.Null); | ||
107 | Assert.That(db.GetAgentByUUID(agent1), Is.Null); | ||
108 | Assert.That(db.GetAgentByUUID(agent2), Is.Null); | ||
109 | Assert.That(db.GetAgentByUUID(agent3), Is.Null); | ||
110 | Assert.That(db.GetAgentByUUID(UUID.Random()), Is.Null); | ||
111 | } | ||
112 | |||
113 | [Test] | ||
114 | public void T010_CreateUser() | ||
115 | { | ||
116 | UserProfileData u1 = NewUser(user1,fname1,lname1); | ||
117 | UserProfileData u2 = NewUser(user2,fname2,lname2); | ||
118 | UserProfileData u3 = NewUser(user3,fname3,lname3); | ||
119 | // this is used to check whether null works here | ||
120 | u3.Email = null; | ||
121 | |||
122 | db.AddNewUserProfile(u1); | ||
123 | db.AddNewUserProfile(u2); | ||
124 | db.AddNewUserProfile(u3); | ||
125 | UserProfileData u1a = db.GetUserByUUID(user1); | ||
126 | UserProfileData u2a = db.GetUserByUUID(user2); | ||
127 | UserProfileData u3a = db.GetUserByUUID(user3); | ||
128 | Assert.That(user1,Is.EqualTo(u1a.ID), "Assert.That(user1,Is.EqualTo(u1a.ID))"); | ||
129 | Assert.That(user2,Is.EqualTo(u2a.ID), "Assert.That(user2,Is.EqualTo(u2a.ID))"); | ||
130 | Assert.That(user3,Is.EqualTo(u3a.ID), "Assert.That(user3,Is.EqualTo(u3a.ID))"); | ||
131 | |||
132 | // and one email test | ||
133 | Assert.That(u3.Email, Is.Null); | ||
134 | } | ||
135 | |||
136 | [Test] | ||
137 | public void T011_FetchUserByName() | ||
138 | { | ||
139 | UserProfileData u1 = db.GetUserByName(fname1,lname1); | ||
140 | UserProfileData u2 = db.GetUserByName(fname2,lname2); | ||
141 | UserProfileData u3 = db.GetUserByName(fname3,lname3); | ||
142 | Assert.That(user1,Is.EqualTo(u1.ID), "Assert.That(user1,Is.EqualTo(u1.ID))"); | ||
143 | Assert.That(user2,Is.EqualTo(u2.ID), "Assert.That(user2,Is.EqualTo(u2.ID))"); | ||
144 | Assert.That(user3,Is.EqualTo(u3.ID), "Assert.That(user3,Is.EqualTo(u3.ID))"); | ||
145 | } | ||
146 | |||
147 | [Test] | ||
148 | public void T012_UpdateUserProfile() | ||
149 | { | ||
150 | UserProfileData u1 = db.GetUserByUUID(user1); | ||
151 | Assert.That(fname1,Is.EqualTo(u1.FirstName), "Assert.That(fname1,Is.EqualTo(u1.FirstName))"); | ||
152 | u1.FirstName = "Ugly"; | ||
153 | |||
154 | db.UpdateUserProfile(u1); | ||
155 | Assert.That("Ugly",Is.EqualTo(u1.FirstName), "Assert.That(\"Ugly\",Is.EqualTo(u1.FirstName))"); | ||
156 | } | ||
157 | |||
158 | [Test] | ||
159 | public void T013_StoreUserWebKey() | ||
160 | { | ||
161 | UserProfileData u1 = db.GetUserByUUID(user1); | ||
162 | Assert.That(u1.WebLoginKey,Is.EqualTo(zero), "Assert.That(u1.WebLoginKey,Is.EqualTo(zero))"); | ||
163 | db.StoreWebLoginKey(user1, webkey); | ||
164 | u1 = db.GetUserByUUID(user1); | ||
165 | Assert.That(u1.WebLoginKey,Is.EqualTo(webkey), "Assert.That(u1.WebLoginKey,Is.EqualTo(webkey))"); | ||
166 | } | ||
167 | |||
168 | [Test] | ||
169 | public void T014_ExpectedNullReferenceReturns() | ||
170 | { | ||
171 | UserProfileData u0 = NewUser(zero,fname0,lname0); | ||
172 | UserProfileData u4 = NewUser(user4,fname2,lname2); | ||
173 | db.AddNewUserProfile(u0); //UserID 0 should fail to save. | ||
174 | db.AddNewUserProfile(u4); //The first name and last name are already in use (from T010), so this should fail too | ||
175 | Assert.That(db.GetUserByUUID(zero),Is.Null); | ||
176 | Assert.That(db.GetUserByUUID(user4),Is.Null); | ||
177 | } | ||
178 | |||
179 | [Test] | ||
180 | public void T015_UserPersistency() | ||
181 | { | ||
182 | UserProfileData u = new UserProfileData(); | ||
183 | UUID id = user5; | ||
184 | string fname = RandomName(); | ||
185 | string lname = RandomName(); | ||
186 | string email = RandomName(); | ||
187 | string passhash = RandomName(); | ||
188 | string passsalt = RandomName(); | ||
189 | UUID homeregion = UUID.Random(); | ||
190 | UUID webloginkey = UUID.Random(); | ||
191 | uint homeregx = (uint) random.Next(); | ||
192 | uint homeregy = (uint) random.Next(); | ||
193 | Vector3 homeloc | ||
194 | = new Vector3( | ||
195 | (float)Math.Round(random.NextDouble(), 5), | ||
196 | (float)Math.Round(random.NextDouble(), 5), | ||
197 | (float)Math.Round(random.NextDouble(), 5)); | ||
198 | Vector3 homelookat | ||
199 | = new Vector3( | ||
200 | (float)Math.Round(random.NextDouble(), 5), | ||
201 | (float)Math.Round(random.NextDouble(), 5), | ||
202 | (float)Math.Round(random.NextDouble(), 5)); | ||
203 | int created = random.Next(); | ||
204 | int lastlogin = random.Next(); | ||
205 | string userinvuri = RandomName(); | ||
206 | string userasseturi = RandomName(); | ||
207 | uint candomask = (uint) random.Next(); | ||
208 | uint wantdomask = (uint) random.Next(); | ||
209 | string abouttext = RandomName(); | ||
210 | string flabouttext = RandomName(); | ||
211 | UUID image = UUID.Random(); | ||
212 | UUID firstimage = UUID.Random(); | ||
213 | UserAgentData agent = NewAgent(id,UUID.Random()); | ||
214 | int userflags = random.Next(); | ||
215 | int godlevel = random.Next(); | ||
216 | string customtype = RandomName(); | ||
217 | UUID partner = UUID.Random(); | ||
218 | |||
219 | //HomeRegionX and HomeRegionY must only use 24 bits | ||
220 | homeregx = ((homeregx << 8) >> 8); | ||
221 | homeregy = ((homeregy << 8) >> 8); | ||
222 | |||
223 | u.ID = id; | ||
224 | u.WebLoginKey = webloginkey; | ||
225 | u.HomeRegionID = homeregion; | ||
226 | u.FirstName = fname; | ||
227 | u.SurName = lname; | ||
228 | u.Email = email; | ||
229 | u.PasswordHash = passhash; | ||
230 | u.PasswordSalt = passsalt; | ||
231 | u.HomeRegionX = homeregx; | ||
232 | u.HomeRegionY = homeregy; | ||
233 | ulong homereg = u.HomeRegion; | ||
234 | u.HomeLocation = homeloc; | ||
235 | u.HomeLookAt = homelookat; | ||
236 | u.Created = created; | ||
237 | u.LastLogin = lastlogin; | ||
238 | u.UserInventoryURI = userinvuri; | ||
239 | u.UserAssetURI = userasseturi; | ||
240 | u.CanDoMask = candomask; | ||
241 | u.WantDoMask = wantdomask; | ||
242 | u.AboutText = abouttext; | ||
243 | u.FirstLifeAboutText = flabouttext; | ||
244 | u.Image = image; | ||
245 | u.FirstLifeImage = firstimage; | ||
246 | u.CurrentAgent = agent; | ||
247 | u.UserFlags = userflags; | ||
248 | u.GodLevel = godlevel; | ||
249 | u.CustomType = customtype; | ||
250 | u.Partner = partner; | ||
251 | |||
252 | db.AddNewUserProfile(u); | ||
253 | UserProfileData u1a = db.GetUserByUUID(id); | ||
254 | Assert.That(u1a,Is.Not.Null); | ||
255 | Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))"); | ||
256 | Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID))"); | ||
257 | Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))"); | ||
258 | Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))"); | ||
259 | Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))"); | ||
260 | Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))"); | ||
261 | Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))"); | ||
262 | Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))"); | ||
263 | Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))"); | ||
264 | Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))"); | ||
265 | Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))"); | ||
266 | Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))"); | ||
267 | Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))"); | ||
268 | Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))"); | ||
269 | Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))"); | ||
270 | Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI), "Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI))"); | ||
271 | Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))"); | ||
272 | Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))"); | ||
273 | Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))"); | ||
274 | Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))"); | ||
275 | Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))"); | ||
276 | Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))"); | ||
277 | Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))"); | ||
278 | Assert.That(u1a.CurrentAgent,Is.Null); | ||
279 | Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))"); | ||
280 | Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))"); | ||
281 | Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))"); | ||
282 | Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))"); | ||
283 | } | ||
284 | |||
285 | [Test] | ||
286 | public void T016_UserUpdatePersistency() | ||
287 | { | ||
288 | UUID id = user5; | ||
289 | UserProfileData u = db.GetUserByUUID(id); | ||
290 | string fname = RandomName(); | ||
291 | string lname = RandomName(); | ||
292 | string email = RandomName(); | ||
293 | string passhash = RandomName(); | ||
294 | string passsalt = RandomName(); | ||
295 | UUID homeregionid = UUID.Random(); | ||
296 | UUID webloginkey = UUID.Random(); | ||
297 | uint homeregx = (uint) random.Next(); | ||
298 | uint homeregy = (uint) random.Next(); | ||
299 | Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); | ||
300 | Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); | ||
301 | int created = random.Next(); | ||
302 | int lastlogin = random.Next(); | ||
303 | string userinvuri = RandomName(); | ||
304 | string userasseturi = RandomName(); | ||
305 | uint candomask = (uint) random.Next(); | ||
306 | uint wantdomask = (uint) random.Next(); | ||
307 | string abouttext = RandomName(); | ||
308 | string flabouttext = RandomName(); | ||
309 | UUID image = UUID.Random(); | ||
310 | UUID firstimage = UUID.Random(); | ||
311 | UserAgentData agent = NewAgent(id,UUID.Random()); | ||
312 | int userflags = random.Next(); | ||
313 | int godlevel = random.Next(); | ||
314 | string customtype = RandomName(); | ||
315 | UUID partner = UUID.Random(); | ||
316 | |||
317 | //HomeRegionX and HomeRegionY must only use 24 bits | ||
318 | homeregx = ((homeregx << 8) >> 8); | ||
319 | homeregy = ((homeregy << 8) >> 8); | ||
320 | |||
321 | u.WebLoginKey = webloginkey; | ||
322 | u.HomeRegionID = homeregionid; | ||
323 | u.FirstName = fname; | ||
324 | u.SurName = lname; | ||
325 | u.Email = email; | ||
326 | u.PasswordHash = passhash; | ||
327 | u.PasswordSalt = passsalt; | ||
328 | u.HomeRegionX = homeregx; | ||
329 | u.HomeRegionY = homeregy; | ||
330 | ulong homereg = u.HomeRegion; | ||
331 | u.HomeLocation = homeloc; | ||
332 | u.HomeLookAt = homelookat; | ||
333 | u.Created = created; | ||
334 | u.LastLogin = lastlogin; | ||
335 | u.UserInventoryURI = userinvuri; | ||
336 | u.UserAssetURI = userasseturi; | ||
337 | u.CanDoMask = candomask; | ||
338 | u.WantDoMask = wantdomask; | ||
339 | u.AboutText = abouttext; | ||
340 | u.FirstLifeAboutText = flabouttext; | ||
341 | u.Image = image; | ||
342 | u.FirstLifeImage = firstimage; | ||
343 | u.CurrentAgent = agent; | ||
344 | u.UserFlags = userflags; | ||
345 | u.GodLevel = godlevel; | ||
346 | u.CustomType = customtype; | ||
347 | u.Partner = partner; | ||
348 | |||
349 | db.UpdateUserProfile(u); | ||
350 | UserProfileData u1a = db.GetUserByUUID(id); | ||
351 | Assert.That(u1a,Is.Not.Null); | ||
352 | Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))"); | ||
353 | Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID))"); | ||
354 | Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))"); | ||
355 | Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))"); | ||
356 | Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))"); | ||
357 | Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))"); | ||
358 | Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))"); | ||
359 | Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))"); | ||
360 | Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))"); | ||
361 | Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))"); | ||
362 | Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))"); | ||
363 | Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))"); | ||
364 | Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))"); | ||
365 | Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))"); | ||
366 | Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))"); | ||
367 | Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))"); | ||
368 | Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))"); | ||
369 | Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))"); | ||
370 | Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))"); | ||
371 | Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))"); | ||
372 | Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))"); | ||
373 | Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))"); | ||
374 | Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))"); | ||
375 | Assert.That(u1a.CurrentAgent,Is.Null); | ||
376 | Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))"); | ||
377 | Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))"); | ||
378 | Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))"); | ||
379 | Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))"); | ||
380 | } | ||
381 | |||
382 | [Test] | ||
383 | public void T017_UserUpdateRandomPersistency() | ||
384 | { | ||
385 | UUID id = user5; | ||
386 | UserProfileData u = db.GetUserByUUID(id); | ||
387 | new PropertyScrambler<UserProfileData>().DontScramble(x=>x.ID).Scramble(u); | ||
388 | |||
389 | db.UpdateUserProfile(u); | ||
390 | UserProfileData u1a = db.GetUserByUUID(id); | ||
391 | Assert.That(u1a, Constraints.PropertyCompareConstraint(u) | ||
392 | .IgnoreProperty(x=>x.HomeRegionX) | ||
393 | .IgnoreProperty(x=>x.HomeRegionY) | ||
394 | ); | ||
395 | } | ||
396 | |||
397 | [Test] | ||
398 | public void T020_CreateAgent() | ||
399 | { | ||
400 | UserAgentData a1 = NewAgent(user1,agent1); | ||
401 | UserAgentData a2 = NewAgent(user2,agent2); | ||
402 | UserAgentData a3 = NewAgent(user3,agent3); | ||
403 | db.AddNewUserAgent(a1); | ||
404 | db.AddNewUserAgent(a2); | ||
405 | db.AddNewUserAgent(a3); | ||
406 | UserAgentData a1a = db.GetAgentByUUID(user1); | ||
407 | UserAgentData a2a = db.GetAgentByUUID(user2); | ||
408 | UserAgentData a3a = db.GetAgentByUUID(user3); | ||
409 | Assert.That(agent1,Is.EqualTo(a1a.SessionID), "Assert.That(agent1,Is.EqualTo(a1a.SessionID))"); | ||
410 | Assert.That(user1,Is.EqualTo(a1a.ProfileID), "Assert.That(user1,Is.EqualTo(a1a.ProfileID))"); | ||
411 | Assert.That(agent2,Is.EqualTo(a2a.SessionID), "Assert.That(agent2,Is.EqualTo(a2a.SessionID))"); | ||
412 | Assert.That(user2,Is.EqualTo(a2a.ProfileID), "Assert.That(user2,Is.EqualTo(a2a.ProfileID))"); | ||
413 | Assert.That(agent3,Is.EqualTo(a3a.SessionID), "Assert.That(agent3,Is.EqualTo(a3a.SessionID))"); | ||
414 | Assert.That(user3,Is.EqualTo(a3a.ProfileID), "Assert.That(user3,Is.EqualTo(a3a.ProfileID))"); | ||
415 | } | ||
416 | |||
417 | [Test] | ||
418 | public void T021_FetchAgentByName() | ||
419 | { | ||
420 | String name3 = fname3 + " " + lname3; | ||
421 | UserAgentData a2 = db.GetAgentByName(fname2,lname2); | ||
422 | UserAgentData a3 = db.GetAgentByName(name3); | ||
423 | Assert.That(user2,Is.EqualTo(a2.ProfileID), "Assert.That(user2,Is.EqualTo(a2.ProfileID))"); | ||
424 | Assert.That(user3,Is.EqualTo(a3.ProfileID), "Assert.That(user3,Is.EqualTo(a3.ProfileID))"); | ||
425 | } | ||
426 | |||
427 | [Test] | ||
428 | public void T022_ExceptionalCases() | ||
429 | { | ||
430 | UserAgentData a0 = NewAgent(user4,zero); | ||
431 | UserAgentData a4 = NewAgent(zero,agent4); | ||
432 | db.AddNewUserAgent(a0); | ||
433 | db.AddNewUserAgent(a4); | ||
434 | |||
435 | Assert.That(db.GetAgentByUUID(user4),Is.Null); | ||
436 | Assert.That(db.GetAgentByUUID(zero),Is.Null); | ||
437 | } | ||
438 | |||
439 | [Test] | ||
440 | public void T023_AgentPersistency() | ||
441 | { | ||
442 | UUID user = user4; | ||
443 | UUID agent = agent4; | ||
444 | UUID secureagent = UUID.Random(); | ||
445 | string agentip = RandomName(); | ||
446 | uint agentport = (uint)random.Next(); | ||
447 | bool agentonline = (random.NextDouble() > 0.5); | ||
448 | int logintime = random.Next(); | ||
449 | int logouttime = random.Next(); | ||
450 | UUID regionid = UUID.Random(); | ||
451 | ulong regionhandle = (ulong) random.Next(); | ||
452 | Vector3 currentpos = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); | ||
453 | Vector3 currentlookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5)); | ||
454 | UUID orgregionid = UUID.Random(); | ||
455 | |||
456 | UserAgentData a = new UserAgentData(); | ||
457 | a.ProfileID = user; | ||
458 | a.SessionID = agent; | ||
459 | a.SecureSessionID = secureagent; | ||
460 | a.AgentIP = agentip; | ||
461 | a.AgentPort = agentport; | ||
462 | a.AgentOnline = agentonline; | ||
463 | a.LoginTime = logintime; | ||
464 | a.LogoutTime = logouttime; | ||
465 | a.Region = regionid; | ||
466 | a.Handle = regionhandle; | ||
467 | a.Position = currentpos; | ||
468 | a.LookAt = currentlookat; | ||
469 | a.InitialRegion = orgregionid; | ||
470 | |||
471 | db.AddNewUserAgent(a); | ||
472 | |||
473 | UserAgentData a1 = db.GetAgentByUUID(user4); | ||
474 | Assert.That(user,Is.EqualTo(a1.ProfileID), "Assert.That(user,Is.EqualTo(a1.ProfileID))"); | ||
475 | Assert.That(agent,Is.EqualTo(a1.SessionID), "Assert.That(agent,Is.EqualTo(a1.SessionID))"); | ||
476 | Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID), "Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID))"); | ||
477 | Assert.That(agentip,Is.EqualTo(a1.AgentIP), "Assert.That(agentip,Is.EqualTo(a1.AgentIP))"); | ||
478 | Assert.That(agentport,Is.EqualTo(a1.AgentPort), "Assert.That(agentport,Is.EqualTo(a1.AgentPort))"); | ||
479 | Assert.That(agentonline,Is.EqualTo(a1.AgentOnline), "Assert.That(agentonline,Is.EqualTo(a1.AgentOnline))"); | ||
480 | Assert.That(logintime,Is.EqualTo(a1.LoginTime), "Assert.That(logintime,Is.EqualTo(a1.LoginTime))"); | ||
481 | Assert.That(logouttime,Is.EqualTo(a1.LogoutTime), "Assert.That(logouttime,Is.EqualTo(a1.LogoutTime))"); | ||
482 | Assert.That(regionid,Is.EqualTo(a1.Region), "Assert.That(regionid,Is.EqualTo(a1.Region))"); | ||
483 | Assert.That(regionhandle,Is.EqualTo(a1.Handle), "Assert.That(regionhandle,Is.EqualTo(a1.Handle))"); | ||
484 | Assert.That(currentpos,Is.EqualTo(a1.Position), "Assert.That(currentpos,Is.EqualTo(a1.Position))"); | ||
485 | Assert.That(currentlookat,Is.EqualTo(a1.LookAt), "Assert.That(currentlookat,Is.EqualTo(a1.LookAt))"); | ||
486 | } | ||
487 | |||
488 | [Test] | ||
489 | public void T030_CreateFriendList() | ||
490 | { | ||
491 | Dictionary<UUID, uint> perms = new Dictionary<UUID,uint>(); | ||
492 | Dictionary<UUID, int> friends = new Dictionary<UUID,int>(); | ||
493 | uint temp; | ||
494 | int tempu1, tempu2; | ||
495 | db.AddNewUserFriend(user1,user2, 1); | ||
496 | db.AddNewUserFriend(user1,user3, 2); | ||
497 | db.AddNewUserFriend(user1,user2, 4); | ||
498 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
499 | Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))"); | ||
500 | perms.Add(user2,1); | ||
501 | perms.Add(user3,2); | ||
502 | for (int i = 0; i < fl1.Count; i++) | ||
503 | { | ||
504 | Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner), "Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner))"); | ||
505 | friends.Add(fl1[i].Friend,1); | ||
506 | temp = perms[fl1[i].Friend]; | ||
507 | Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms), "Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms))"); | ||
508 | } | ||
509 | tempu1 = friends[user2]; | ||
510 | tempu2 = friends[user3]; | ||
511 | Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2), "Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2))"); | ||
512 | } | ||
513 | |||
514 | [Test] | ||
515 | public void T031_RemoveUserFriend() | ||
516 | // user1 has 2 friends, user2 and user3. | ||
517 | { | ||
518 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
519 | List<FriendListItem> fl2 = db.GetUserFriendList(user2); | ||
520 | |||
521 | Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))"); | ||
522 | Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3), "Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3))"); | ||
523 | Assert.That(fl2[0].Friend,Is.EqualTo(user1), "Assert.That(fl2[0].Friend,Is.EqualTo(user1))"); | ||
524 | db.RemoveUserFriend(user2, user1); | ||
525 | |||
526 | fl1 = db.GetUserFriendList(user1); | ||
527 | fl2 = db.GetUserFriendList(user2); | ||
528 | Assert.That(fl1.Count,Is.EqualTo(1), "Assert.That(fl1.Count,Is.EqualTo(1))"); | ||
529 | Assert.That(fl1[0].Friend, Is.EqualTo(user3), "Assert.That(fl1[0].Friend, Is.EqualTo(user3))"); | ||
530 | Assert.That(fl2, Is.Empty); | ||
531 | } | ||
532 | |||
533 | [Test] | ||
534 | public void T032_UpdateFriendPerms() | ||
535 | // user1 has 1 friend, user3, who has permission 2 in T030. | ||
536 | { | ||
537 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
538 | Assert.That(fl1[0].FriendPerms,Is.EqualTo(2), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(2))"); | ||
539 | db.UpdateUserFriendPerms(user1, user3, 4); | ||
540 | |||
541 | fl1 = db.GetUserFriendList(user1); | ||
542 | Assert.That(fl1[0].FriendPerms,Is.EqualTo(4), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(4))"); | ||
543 | } | ||
544 | |||
545 | [Test] | ||
546 | public void T040_UserAppearance() | ||
547 | { | ||
548 | AvatarAppearance appear = new AvatarAppearance(); | ||
549 | appear.Owner = user1; | ||
550 | db.UpdateUserAppearance(user1, appear); | ||
551 | AvatarAppearance user1app = db.GetUserAppearance(user1); | ||
552 | Assert.That(user1,Is.EqualTo(user1app.Owner), "Assert.That(user1,Is.EqualTo(user1app.Owner))"); | ||
553 | } | ||
554 | |||
555 | [Test] | ||
556 | public void T041_UserAppearancePersistency() | ||
557 | { | ||
558 | AvatarAppearance appear = new AvatarAppearance(); | ||
559 | UUID owner = UUID.Random(); | ||
560 | int serial = random.Next(); | ||
561 | byte[] visualp = new byte[218]; | ||
562 | random.NextBytes(visualp); | ||
563 | UUID bodyitem = UUID.Random(); | ||
564 | UUID bodyasset = UUID.Random(); | ||
565 | UUID skinitem = UUID.Random(); | ||
566 | UUID skinasset = UUID.Random(); | ||
567 | UUID hairitem = UUID.Random(); | ||
568 | UUID hairasset = UUID.Random(); | ||
569 | UUID eyesitem = UUID.Random(); | ||
570 | UUID eyesasset = UUID.Random(); | ||
571 | UUID shirtitem = UUID.Random(); | ||
572 | UUID shirtasset = UUID.Random(); | ||
573 | UUID pantsitem = UUID.Random(); | ||
574 | UUID pantsasset = UUID.Random(); | ||
575 | UUID shoesitem = UUID.Random(); | ||
576 | UUID shoesasset = UUID.Random(); | ||
577 | UUID socksitem = UUID.Random(); | ||
578 | UUID socksasset = UUID.Random(); | ||
579 | UUID jacketitem = UUID.Random(); | ||
580 | UUID jacketasset = UUID.Random(); | ||
581 | UUID glovesitem = UUID.Random(); | ||
582 | UUID glovesasset = UUID.Random(); | ||
583 | UUID ushirtitem = UUID.Random(); | ||
584 | UUID ushirtasset = UUID.Random(); | ||
585 | UUID upantsitem = UUID.Random(); | ||
586 | UUID upantsasset = UUID.Random(); | ||
587 | UUID skirtitem = UUID.Random(); | ||
588 | UUID skirtasset = UUID.Random(); | ||
589 | Primitive.TextureEntry texture = AvatarAppearance.GetDefaultTexture(); | ||
590 | float avatarheight = (float) (Math.Round(random.NextDouble(),5)); | ||
591 | |||
592 | appear.Owner = owner; | ||
593 | appear.Serial = serial; | ||
594 | appear.VisualParams = visualp; | ||
595 | appear.BodyItem = bodyitem; | ||
596 | appear.BodyAsset = bodyasset; | ||
597 | appear.SkinItem = skinitem; | ||
598 | appear.SkinAsset = skinasset; | ||
599 | appear.HairItem = hairitem; | ||
600 | appear.HairAsset = hairasset; | ||
601 | appear.EyesItem = eyesitem; | ||
602 | appear.EyesAsset = eyesasset; | ||
603 | appear.ShirtItem = shirtitem; | ||
604 | appear.ShirtAsset = shirtasset; | ||
605 | appear.PantsItem = pantsitem; | ||
606 | appear.PantsAsset = pantsasset; | ||
607 | appear.ShoesItem = shoesitem; | ||
608 | appear.ShoesAsset = shoesasset; | ||
609 | appear.SocksItem = socksitem; | ||
610 | appear.SocksAsset = socksasset; | ||
611 | appear.JacketItem = jacketitem; | ||
612 | appear.JacketAsset = jacketasset; | ||
613 | appear.GlovesItem = glovesitem; | ||
614 | appear.GlovesAsset = glovesasset; | ||
615 | appear.UnderShirtItem = ushirtitem; | ||
616 | appear.UnderShirtAsset = ushirtasset; | ||
617 | appear.UnderPantsItem = upantsitem; | ||
618 | appear.UnderPantsAsset = upantsasset; | ||
619 | appear.SkirtItem = skirtitem; | ||
620 | appear.SkirtAsset = skirtasset; | ||
621 | appear.Texture = texture; | ||
622 | appear.AvatarHeight = avatarheight; | ||
623 | |||
624 | db.UpdateUserAppearance(owner, appear); | ||
625 | AvatarAppearance app = db.GetUserAppearance(owner); | ||
626 | |||
627 | Assert.That(owner,Is.EqualTo(app.Owner), "Assert.That(owner,Is.EqualTo(app.Owner))"); | ||
628 | Assert.That(serial,Is.EqualTo(app.Serial), "Assert.That(serial,Is.EqualTo(app.Serial))"); | ||
629 | Assert.That(visualp,Is.EqualTo(app.VisualParams), "Assert.That(visualp,Is.EqualTo(app.VisualParams))"); | ||
630 | Assert.That(bodyitem,Is.EqualTo(app.BodyItem), "Assert.That(bodyitem,Is.EqualTo(app.BodyItem))"); | ||
631 | Assert.That(bodyasset,Is.EqualTo(app.BodyAsset), "Assert.That(bodyasset,Is.EqualTo(app.BodyAsset))"); | ||
632 | Assert.That(skinitem,Is.EqualTo(app.SkinItem), "Assert.That(skinitem,Is.EqualTo(app.SkinItem))"); | ||
633 | Assert.That(skinasset,Is.EqualTo(app.SkinAsset), "Assert.That(skinasset,Is.EqualTo(app.SkinAsset))"); | ||
634 | Assert.That(hairitem,Is.EqualTo(app.HairItem), "Assert.That(hairitem,Is.EqualTo(app.HairItem))"); | ||
635 | Assert.That(hairasset,Is.EqualTo(app.HairAsset), "Assert.That(hairasset,Is.EqualTo(app.HairAsset))"); | ||
636 | Assert.That(eyesitem,Is.EqualTo(app.EyesItem), "Assert.That(eyesitem,Is.EqualTo(app.EyesItem))"); | ||
637 | Assert.That(eyesasset,Is.EqualTo(app.EyesAsset), "Assert.That(eyesasset,Is.EqualTo(app.EyesAsset))"); | ||
638 | Assert.That(shirtitem,Is.EqualTo(app.ShirtItem), "Assert.That(shirtitem,Is.EqualTo(app.ShirtItem))"); | ||
639 | Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset), "Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset))"); | ||
640 | Assert.That(pantsitem,Is.EqualTo(app.PantsItem), "Assert.That(pantsitem,Is.EqualTo(app.PantsItem))"); | ||
641 | Assert.That(pantsasset,Is.EqualTo(app.PantsAsset), "Assert.That(pantsasset,Is.EqualTo(app.PantsAsset))"); | ||
642 | Assert.That(shoesitem,Is.EqualTo(app.ShoesItem), "Assert.That(shoesitem,Is.EqualTo(app.ShoesItem))"); | ||
643 | Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset), "Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset))"); | ||
644 | Assert.That(socksitem,Is.EqualTo(app.SocksItem), "Assert.That(socksitem,Is.EqualTo(app.SocksItem))"); | ||
645 | Assert.That(socksasset,Is.EqualTo(app.SocksAsset), "Assert.That(socksasset,Is.EqualTo(app.SocksAsset))"); | ||
646 | Assert.That(jacketitem,Is.EqualTo(app.JacketItem), "Assert.That(jacketitem,Is.EqualTo(app.JacketItem))"); | ||
647 | Assert.That(jacketasset,Is.EqualTo(app.JacketAsset), "Assert.That(jacketasset,Is.EqualTo(app.JacketAsset))"); | ||
648 | Assert.That(glovesitem,Is.EqualTo(app.GlovesItem), "Assert.That(glovesitem,Is.EqualTo(app.GlovesItem))"); | ||
649 | Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset), "Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset))"); | ||
650 | Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem), "Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem))"); | ||
651 | Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset), "Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset))"); | ||
652 | Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem), "Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem))"); | ||
653 | Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset), "Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset))"); | ||
654 | Assert.That(skirtitem,Is.EqualTo(app.SkirtItem), "Assert.That(skirtitem,Is.EqualTo(app.SkirtItem))"); | ||
655 | Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset), "Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset))"); | ||
656 | Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()), "Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()))"); | ||
657 | Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))"); | ||
658 | } | ||
659 | |||
660 | [Test] | ||
661 | public void T999_StillNull() | ||
662 | { | ||
663 | Assert.That(db.GetUserByUUID(zero), Is.Null); | ||
664 | Assert.That(db.GetAgentByUUID(zero), Is.Null); | ||
665 | } | ||
666 | |||
667 | public UserProfileData NewUser(UUID id,string fname,string lname) | ||
668 | { | ||
669 | UserProfileData u = new UserProfileData(); | ||
670 | u.ID = id; | ||
671 | u.FirstName = fname; | ||
672 | u.SurName = lname; | ||
673 | u.PasswordHash = "NOTAHASH"; | ||
674 | u.PasswordSalt = "NOTSALT"; | ||
675 | // MUST specify at least these 5 parameters or an exception is raised | ||
676 | |||
677 | return u; | ||
678 | } | ||
679 | |||
680 | public UserAgentData NewAgent(UUID user_profile, UUID agent) | ||
681 | { | ||
682 | UserAgentData a = new UserAgentData(); | ||
683 | a.ProfileID = user_profile; | ||
684 | a.SessionID = agent; | ||
685 | a.SecureSessionID = UUID.Random(); | ||
686 | a.AgentIP = RandomName(); | ||
687 | return a; | ||
688 | } | ||
689 | |||
690 | public static string RandomName() | ||
691 | { | ||
692 | StringBuilder name = new StringBuilder(); | ||
693 | int size = random.Next(5,12); | ||
694 | char ch ; | ||
695 | for (int i=0; i<size; i++) | ||
696 | { | ||
697 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
698 | name.Append(ch); | ||
699 | } | ||
700 | return name.ToString(); | ||
701 | } | ||
702 | } | ||
703 | } | ||
diff --git a/OpenSim/Data/UserDataBase.cs b/OpenSim/Data/UserDataBase.cs deleted file mode 100644 index 3d370da..0000000 --- a/OpenSim/Data/UserDataBase.cs +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | |||
33 | namespace OpenSim.Data | ||
34 | { | ||
35 | public abstract class UserDataBase : IUserDataPlugin | ||
36 | { | ||
37 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
38 | |||
39 | // private Dictionary<UUID, AvatarAppearance> aplist = new Dictionary<UUID, AvatarAppearance>(); | ||
40 | |||
41 | public abstract UserProfileData GetUserByUUID(UUID user); | ||
42 | public abstract UserProfileData GetUserByName(string fname, string lname); | ||
43 | public abstract UserAgentData GetAgentByUUID(UUID user); | ||
44 | public abstract UserAgentData GetAgentByName(string name); | ||
45 | public abstract UserAgentData GetAgentByName(string fname, string lname); | ||
46 | public UserProfileData GetUserByUri(Uri uri) { return null; } | ||
47 | public abstract void StoreWebLoginKey(UUID agentID, UUID webLoginKey); | ||
48 | public abstract void AddNewUserProfile(UserProfileData user); | ||
49 | |||
50 | public virtual void AddTemporaryUserProfile(UserProfileData userProfile) | ||
51 | { | ||
52 | // Deliberately blank - database plugins shouldn't store temporary profiles. | ||
53 | } | ||
54 | |||
55 | public abstract bool UpdateUserProfile(UserProfileData user); | ||
56 | public abstract void AddNewUserAgent(UserAgentData agent); | ||
57 | public abstract void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms); | ||
58 | public abstract void RemoveUserFriend(UUID friendlistowner, UUID friend); | ||
59 | public abstract void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms); | ||
60 | public abstract List<FriendListItem> GetUserFriendList(UUID friendlistowner); | ||
61 | public abstract Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids); | ||
62 | public abstract bool MoneyTransferRequest(UUID from, UUID to, uint amount); | ||
63 | public abstract bool InventoryTransferRequest(UUID from, UUID to, UUID inventory); | ||
64 | public abstract List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query); | ||
65 | public abstract AvatarAppearance GetUserAppearance(UUID user); | ||
66 | public abstract void UpdateUserAppearance(UUID user, AvatarAppearance appearance); | ||
67 | // public virtual AvatarAppearance GetUserAppearance(UUID user) { | ||
68 | // AvatarAppearance aa = null; | ||
69 | // try { | ||
70 | // aa = aplist[user]; | ||
71 | // m_log.Info("[APPEARANCE] Found appearance for " + user.ToString() + aa.ToString()); | ||
72 | // } catch (System.Collections.Generic.KeyNotFoundException e) { | ||
73 | // m_log.Info("[APPEARANCE] No appearance found for " + user.ToString()); | ||
74 | // } | ||
75 | // return aa; | ||
76 | // } | ||
77 | // public virtual void UpdateUserAppearance(UUID user, AvatarAppearance appearance) { | ||
78 | // aplist[user] = appearance; | ||
79 | // m_log.Info("[APPEARANCE] Setting appearance for " + user.ToString() + appearance.ToString()); | ||
80 | // } | ||
81 | public abstract void ResetAttachments(UUID userID); | ||
82 | |||
83 | public abstract void LogoutUsers(UUID regionID); | ||
84 | |||
85 | public abstract string Version {get;} | ||
86 | public abstract string Name {get;} | ||
87 | public abstract void Initialise(string connect); | ||
88 | public abstract void Initialise(); | ||
89 | public abstract void Dispose(); | ||
90 | } | ||
91 | } | ||
diff --git a/OpenSim/Framework/Communications/TemporaryUserProfilePlugin.cs b/OpenSim/Framework/Communications/TemporaryUserProfilePlugin.cs deleted file mode 100644 index 2413055..0000000 --- a/OpenSim/Framework/Communications/TemporaryUserProfilePlugin.cs +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Data; | ||
34 | |||
35 | namespace OpenSim.Framework.Communications | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Plugin for managing temporary user profiles. | ||
39 | /// </summary> | ||
40 | public class TemporaryUserProfilePlugin : IUserDataPlugin | ||
41 | { | ||
42 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | protected Dictionary<UUID, UserProfileData> m_profiles = new Dictionary<UUID, UserProfileData>(); | ||
45 | |||
46 | public string Name { get { return "TemporaryUserProfilePlugin"; } } | ||
47 | public string Version { get { return "0.1"; } } | ||
48 | public void Initialise() {} | ||
49 | public void Initialise(string connect) {} | ||
50 | public void Dispose() {} | ||
51 | |||
52 | public UserProfileData GetUserByUUID(UUID user) | ||
53 | { | ||
54 | //m_log.DebugFormat("[TEMP USER PROFILE]: Received request for {0}", user); | ||
55 | |||
56 | lock (m_profiles) | ||
57 | { | ||
58 | if (m_profiles.ContainsKey(user)) | ||
59 | return m_profiles[user]; | ||
60 | else | ||
61 | return null; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | public UserProfileData GetUserByName(string fname, string lname) | ||
66 | { | ||
67 | // We deliberately don't look up a temporary profile by name so that we don't obscure non-temporary | ||
68 | // profiles. | ||
69 | |||
70 | return null; | ||
71 | } | ||
72 | |||
73 | public virtual void AddTemporaryUserProfile(UserProfileData userProfile) | ||
74 | { | ||
75 | //m_log.DebugFormat("[TEMP USER PROFILE]: Adding {0} {1}", userProfile.Name, userProfile.ID); | ||
76 | |||
77 | lock (m_profiles) | ||
78 | { | ||
79 | m_profiles[userProfile.ID] = userProfile; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public UserProfileData GetUserByUri(Uri uri) { return null; } | ||
84 | public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; } | ||
85 | public UserAgentData GetAgentByUUID(UUID user) { return null; } | ||
86 | public UserAgentData GetAgentByName(string name) { return null; } | ||
87 | public UserAgentData GetAgentByName(string fname, string lname) { return null; } | ||
88 | public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {} | ||
89 | public void AddNewUserProfile(UserProfileData user) {} | ||
90 | public bool UpdateUserProfile(UserProfileData user) { return false; } | ||
91 | public void AddNewUserAgent(UserAgentData agent) {} | ||
92 | public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) {} | ||
93 | public void RemoveUserFriend(UUID friendlistowner, UUID friend) {} | ||
94 | public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) {} | ||
95 | public List<FriendListItem> GetUserFriendList(UUID friendlistowner) { return null; } | ||
96 | public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; } | ||
97 | public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; } | ||
98 | public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; } | ||
99 | public AvatarAppearance GetUserAppearance(UUID user) { return null; } | ||
100 | public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {} | ||
101 | public void ResetAttachments(UUID userID) {} | ||
102 | public void LogoutUsers(UUID regionID) {} | ||
103 | } | ||
104 | } | ||
diff --git a/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs deleted file mode 100644 index 5188cf6..0000000 --- a/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | |||
34 | namespace OpenSim.Tests.Common.Mock | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// In memory user data provider. Might be quite useful as a proper user data plugin, though getting mono addins | ||
38 | /// to load any plugins when running unit tests has proven impossible so far. Currently no locking since unit | ||
39 | /// tests are single threaded. | ||
40 | /// </summary> | ||
41 | public class TestUserDataPlugin : IUserDataPlugin | ||
42 | { | ||
43 | public string Version { get { return "0"; } } | ||
44 | public string Name { get { return "TestUserDataPlugin"; } } | ||
45 | |||
46 | /// <summary> | ||
47 | /// User profiles keyed by name | ||
48 | /// </summary> | ||
49 | private Dictionary<string, UserProfileData> m_userProfilesByName = new Dictionary<string, UserProfileData>(); | ||
50 | |||
51 | /// <summary> | ||
52 | /// User profiles keyed by uuid | ||
53 | /// </summary> | ||
54 | private Dictionary<UUID, UserProfileData> m_userProfilesByUuid = new Dictionary<UUID, UserProfileData>(); | ||
55 | |||
56 | /// <summary> | ||
57 | /// User profiles and their agents | ||
58 | /// </summary> | ||
59 | private Dictionary<UUID, UserAgentData> m_agentByProfileUuid = new Dictionary<UUID, UserAgentData>(); | ||
60 | |||
61 | /// <summary> | ||
62 | /// Friends list by uuid | ||
63 | /// </summary> | ||
64 | private Dictionary<UUID, List<FriendListItem>> m_friendsListByUuid = new Dictionary<UUID, List<FriendListItem>>(); | ||
65 | |||
66 | public void Initialise() {} | ||
67 | public void Dispose() {} | ||
68 | |||
69 | public void AddTemporaryUserProfile(UserProfileData userProfile) | ||
70 | { | ||
71 | // Not interested | ||
72 | } | ||
73 | |||
74 | public void AddNewUserProfile(UserProfileData user) | ||
75 | { | ||
76 | UpdateUserProfile(user); | ||
77 | } | ||
78 | |||
79 | public UserProfileData GetUserByUUID(UUID user) | ||
80 | { | ||
81 | UserProfileData userProfile = null; | ||
82 | m_userProfilesByUuid.TryGetValue(user, out userProfile); | ||
83 | |||
84 | return userProfile; | ||
85 | } | ||
86 | |||
87 | public UserProfileData GetUserByName(string fname, string lname) | ||
88 | { | ||
89 | UserProfileData userProfile = null; | ||
90 | m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile); | ||
91 | |||
92 | return userProfile; | ||
93 | } | ||
94 | |||
95 | public UserProfileData GetUserByUri(Uri uri) { return null; } | ||
96 | |||
97 | public bool UpdateUserProfile(UserProfileData user) | ||
98 | { | ||
99 | m_userProfilesByUuid[user.ID] = user; | ||
100 | m_userProfilesByName[user.FirstName + " " + user.SurName] = user; | ||
101 | |||
102 | return true; | ||
103 | } | ||
104 | |||
105 | public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; } | ||
106 | |||
107 | public UserAgentData GetAgentByUUID(UUID user) | ||
108 | { | ||
109 | UserAgentData userAgent = null; | ||
110 | m_agentByProfileUuid.TryGetValue(user, out userAgent); | ||
111 | |||
112 | return userAgent; | ||
113 | } | ||
114 | |||
115 | public UserAgentData GetAgentByName(string name) | ||
116 | { | ||
117 | UserProfileData userProfile = null; | ||
118 | m_userProfilesByName.TryGetValue(name, out userProfile); | ||
119 | UserAgentData userAgent = null; | ||
120 | m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent); | ||
121 | |||
122 | return userAgent; | ||
123 | } | ||
124 | |||
125 | public UserAgentData GetAgentByName(string fname, string lname) | ||
126 | { | ||
127 | UserProfileData userProfile = GetUserByName(fname,lname); | ||
128 | UserAgentData userAgent = null; | ||
129 | m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent); | ||
130 | |||
131 | return userAgent; | ||
132 | } | ||
133 | |||
134 | public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {} | ||
135 | |||
136 | public void AddNewUserAgent(UserAgentData agent) | ||
137 | { | ||
138 | m_agentByProfileUuid[agent.ProfileID] = agent; | ||
139 | } | ||
140 | public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) | ||
141 | { | ||
142 | FriendListItem newfriend = new FriendListItem(); | ||
143 | newfriend.FriendPerms = perms; | ||
144 | newfriend.Friend = friend; | ||
145 | newfriend.FriendListOwner = friendlistowner; | ||
146 | |||
147 | if (!m_friendsListByUuid.ContainsKey(friendlistowner)) | ||
148 | { | ||
149 | List<FriendListItem> friendslist = new List<FriendListItem>(); | ||
150 | m_friendsListByUuid[friendlistowner] = friendslist; | ||
151 | |||
152 | } | ||
153 | m_friendsListByUuid[friendlistowner].Add(newfriend); | ||
154 | } | ||
155 | |||
156 | public void RemoveUserFriend(UUID friendlistowner, UUID friend) | ||
157 | { | ||
158 | if (m_friendsListByUuid.ContainsKey(friendlistowner)) | ||
159 | { | ||
160 | List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner]; | ||
161 | foreach (FriendListItem frienditem in friendslist) | ||
162 | { | ||
163 | if (frienditem.Friend == friend) | ||
164 | { | ||
165 | friendslist.Remove(frienditem); | ||
166 | break; | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) | ||
173 | { | ||
174 | if (m_friendsListByUuid.ContainsKey(friendlistowner)) | ||
175 | { | ||
176 | List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner]; | ||
177 | foreach (FriendListItem frienditem in friendslist) | ||
178 | { | ||
179 | if (frienditem.Friend == friend) | ||
180 | { | ||
181 | frienditem.FriendPerms = perms; | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | public List<FriendListItem> GetUserFriendList(UUID friendlistowner) | ||
189 | { | ||
190 | if (m_friendsListByUuid.ContainsKey(friendlistowner)) | ||
191 | { | ||
192 | return m_friendsListByUuid[friendlistowner]; | ||
193 | } | ||
194 | else | ||
195 | return new List<FriendListItem>(); | ||
196 | |||
197 | |||
198 | } | ||
199 | |||
200 | public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; } | ||
201 | |||
202 | public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; } | ||
203 | |||
204 | public bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return false; } | ||
205 | |||
206 | public void Initialise(string connect) { return; } | ||
207 | |||
208 | public AvatarAppearance GetUserAppearance(UUID user) { return null; } | ||
209 | |||
210 | public void UpdateUserAppearance(UUID user, AvatarAppearance appearance) {} | ||
211 | |||
212 | public void ResetAttachments(UUID userID) {} | ||
213 | |||
214 | public void LogoutUsers(UUID regionID) {} | ||
215 | } | ||
216 | } | ||