aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:10:25 +0000
committerAdam Frisby2007-07-11 08:10:25 +0000
commite2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch)
tree8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Framework/Data.MySQL
parent* Wiping trunk in prep for Sugilite (diff)
parent* Applying dalien's patches from bug#177 and #179 (diff)
downloadopensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip
opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz
opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2
opensim-SC_OLD-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Framework/Data.MySQL')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLGridData.cs287
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs309
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLLogData.cs105
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLManager.cs602
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLUserData.cs256
-rw-r--r--OpenSim/Framework/Data.MySQL/Properties/AssemblyInfo.cs33
6 files changed, 1592 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLGridData.cs b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs
new file mode 100644
index 0000000..ef643d2
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLGridData.cs
@@ -0,0 +1,287 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Security.Cryptography;
32using System.Text;
33using libsecondlife;
34
35namespace OpenSim.Framework.Data.MySQL
36{
37 /// <summary>
38 /// A MySQL Interface for the Grid Server
39 /// </summary>
40 public class MySQLGridData : IGridData
41 {
42 /// <summary>
43 /// MySQL Database Manager
44 /// </summary>
45 private MySQLManager database;
46
47 /// <summary>
48 /// Initialises the Grid Interface
49 /// </summary>
50 public void Initialise()
51 {
52 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
53 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
54 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
55 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
56 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
57 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
58 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
59
60 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
61 }
62
63 /// <summary>
64 /// Shuts down the grid interface
65 /// </summary>
66 public void Close()
67 {
68 database.Close();
69 }
70
71 /// <summary>
72 /// Returns the plugin name
73 /// </summary>
74 /// <returns>Plugin name</returns>
75 public string getName()
76 {
77 return "MySql OpenGridData";
78 }
79
80 /// <summary>
81 /// Returns the plugin version
82 /// </summary>
83 /// <returns>Plugin version</returns>
84 public string getVersion()
85 {
86 return "0.1";
87 }
88
89 /// <summary>
90 /// Returns all the specified region profiles within coordates -- coordinates are inclusive
91 /// </summary>
92 /// <param name="xmin">Minimum X coordinate</param>
93 /// <param name="ymin">Minimum Y coordinate</param>
94 /// <param name="xmax">Maximum X coordinate</param>
95 /// <param name="ymax">Maximum Y coordinate</param>
96 /// <returns></returns>
97 public SimProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax)
98 {
99 try
100 {
101 lock (database)
102 {
103 Dictionary<string, string> param = new Dictionary<string, string>();
104 param["?xmin"] = xmin.ToString();
105 param["?ymin"] = ymin.ToString();
106 param["?xmax"] = xmax.ToString();
107 param["?ymax"] = ymax.ToString();
108
109 IDbCommand result = database.Query("SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", param);
110 IDataReader reader = result.ExecuteReader();
111
112 SimProfileData row;
113
114 List<SimProfileData> rows = new List<SimProfileData>();
115
116 while ((row = database.readSimRow(reader)) != null)
117 {
118 rows.Add(row);
119 }
120 reader.Close();
121 result.Dispose();
122
123 return rows.ToArray();
124
125 }
126 }
127 catch (Exception e)
128 {
129 database.Reconnect();
130 Console.WriteLine(e.ToString());
131 return null;
132 }
133 }
134
135 /// <summary>
136 /// Returns a sim profile from it's location
137 /// </summary>
138 /// <param name="handle">Region location handle</param>
139 /// <returns>Sim profile</returns>
140 public SimProfileData GetProfileByHandle(ulong handle)
141 {
142 try
143 {
144 lock (database)
145 {
146 Dictionary<string, string> param = new Dictionary<string, string>();
147 param["?handle"] = handle.ToString();
148
149 IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param);
150 IDataReader reader = result.ExecuteReader();
151
152 SimProfileData row = database.readSimRow(reader);
153 reader.Close();
154 result.Dispose();
155
156 return row;
157 }
158 }
159 catch (Exception e)
160 {
161 database.Reconnect();
162 Console.WriteLine(e.ToString());
163 return null;
164 }
165 }
166
167 /// <summary>
168 /// Returns a sim profile from it's UUID
169 /// </summary>
170 /// <param name="uuid">The region UUID</param>
171 /// <returns>The sim profile</returns>
172 public SimProfileData GetProfileByLLUUID(LLUUID uuid)
173 {
174 try
175 {
176 lock (database)
177 {
178 Dictionary<string, string> param = new Dictionary<string, string>();
179 param["?uuid"] = uuid.ToStringHyphenated();
180
181 IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param);
182 IDataReader reader = result.ExecuteReader();
183
184 SimProfileData row = database.readSimRow(reader);
185 reader.Close();
186 result.Dispose();
187
188 return row;
189 }
190 }
191 catch (Exception e)
192 {
193 database.Reconnect();
194 Console.WriteLine(e.ToString());
195 return null;
196 }
197 }
198
199 /// <summary>
200 /// Adds a new profile to the database
201 /// </summary>
202 /// <param name="profile">The profile to add</param>
203 /// <returns>Successful?</returns>
204 public DataResponse AddProfile(SimProfileData profile)
205 {
206 lock (database)
207 {
208 if (database.insertRegion(profile))
209 {
210 return DataResponse.RESPONSE_OK;
211 }
212 else
213 {
214 return DataResponse.RESPONSE_ERROR;
215 }
216 }
217 }
218
219 /// <summary>
220 /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
221 /// </summary>
222 /// <param name="uuid">The UUID of the challenger</param>
223 /// <param name="handle">The attempted regionHandle of the challenger</param>
224 /// <param name="authkey">The secret</param>
225 /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
226 public bool AuthenticateSim(LLUUID uuid, ulong handle, string authkey)
227 {
228 bool throwHissyFit = false; // Should be true by 1.0
229
230 if (throwHissyFit)
231 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
232
233 SimProfileData data = GetProfileByLLUUID(uuid);
234
235 return (handle == data.regionHandle && authkey == data.regionSecret);
236 }
237
238 /// <summary>
239 /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
240 /// </summary>
241 /// <remarks>This requires a security audit.</remarks>
242 /// <param name="uuid"></param>
243 /// <param name="handle"></param>
244 /// <param name="authhash"></param>
245 /// <param name="challenge"></param>
246 /// <returns></returns>
247 public bool AuthenticateSim(LLUUID uuid, ulong handle, string authhash, string challenge)
248 {
249 SHA512Managed HashProvider = new SHA512Managed();
250 ASCIIEncoding TextProvider = new ASCIIEncoding();
251
252 byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge);
253 byte[] hash = HashProvider.ComputeHash(stream);
254
255 return false;
256 }
257
258 public ReservationData GetReservationAtPoint(uint x, uint y)
259 {
260 try
261 {
262 lock (database)
263 {
264 Dictionary<string, string> param = new Dictionary<string, string>();
265 param["?x"] = x.ToString();
266 param["?y"] = y.ToString();
267 IDbCommand result = database.Query("SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y", param);
268 IDataReader reader = result.ExecuteReader();
269
270 ReservationData row = database.readReservationRow(reader);
271 reader.Close();
272 result.Dispose();
273
274 return row;
275 }
276 }
277 catch (Exception e)
278 {
279 database.Reconnect();
280 Console.WriteLine(e.ToString());
281 return null;
282 }
283 }
284 }
285
286
287}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
new file mode 100644
index 0000000..790759a
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLInventoryData.cs
@@ -0,0 +1,309 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using System.Collections.Generic;
30using System.Data;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.MySQL
34{
35 /// <summary>
36 /// A MySQL interface for the inventory server
37 /// </summary>
38 class MySQLInventoryData : IInventoryData
39 {
40 /// <summary>
41 /// The database manager
42 /// </summary>
43 public MySQLManager database;
44
45 /// <summary>
46 /// Loads and initialises this database plugin
47 /// </summary>
48 public void Initialise()
49 {
50 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
51 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
52 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
53 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
54 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
55 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
56 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
57
58 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
59 }
60
61 /// <summary>
62 /// The name of this DB provider
63 /// </summary>
64 /// <returns>Name of DB provider</returns>
65 public string getName()
66 {
67 return "MySQL Inventory Data Interface";
68 }
69
70 /// <summary>
71 /// Closes this DB provider
72 /// </summary>
73 public void Close()
74 {
75 // Do nothing.
76 }
77
78 /// <summary>
79 /// Returns the version of this DB provider
80 /// </summary>
81 /// <returns>A string containing the DB provider</returns>
82 public string getVersion()
83 {
84 return "0.1";
85 }
86
87 /// <summary>
88 /// Returns a list of items in a specified folder
89 /// </summary>
90 /// <param name="folderID">The folder to search</param>
91 /// <returns>A list containing inventory items</returns>
92 public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID)
93 {
94 try
95 {
96 lock (database)
97 {
98 Dictionary<string, string> param = new Dictionary<string, string>();
99 param["?uuid"] = folderID.ToStringHyphenated();
100
101 IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", param);
102 IDataReader reader = result.ExecuteReader();
103
104 List<InventoryItemBase> items = database.readInventoryItems(reader);
105
106 reader.Close();
107 result.Dispose();
108
109 return items;
110 }
111 }
112 catch (Exception e)
113 {
114 database.Reconnect();
115 Console.WriteLine(e.ToString());
116 return null;
117 }
118 }
119
120 /// <summary>
121 /// Returns a list of the root folders within a users inventory
122 /// </summary>
123 /// <param name="user">The user whos inventory is to be searched</param>
124 /// <returns>A list of folder objects</returns>
125 public List<InventoryFolderBase> getUserRootFolders(LLUUID user)
126 {
127 try
128 {
129 lock (database)
130 {
131 Dictionary<string, string> param = new Dictionary<string, string>();
132 param["?uuid"] = user.ToStringHyphenated();
133 param["?zero"] = LLUUID.Zero.ToStringHyphenated();
134
135 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid", param);
136 IDataReader reader = result.ExecuteReader();
137
138 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
139
140 reader.Close();
141 result.Dispose();
142
143 return items;
144 }
145 }
146 catch (Exception e)
147 {
148 database.Reconnect();
149 Console.WriteLine(e.ToString());
150 return null;
151 }
152 }
153
154 /// <summary>
155 /// Returns a list of folders in a users inventory contained within the specified folder
156 /// </summary>
157 /// <param name="parentID">The folder to search</param>
158 /// <returns>A list of inventory folders</returns>
159 public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID)
160 {
161 try
162 {
163 lock (database)
164 {
165 Dictionary<string, string> param = new Dictionary<string, string>();
166 param["?uuid"] = parentID.ToStringHyphenated();
167
168 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid", param);
169 IDataReader reader = result.ExecuteReader();
170
171 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
172
173 reader.Close();
174 result.Dispose();
175
176 return items;
177 }
178 }
179 catch (Exception e)
180 {
181 database.Reconnect();
182 Console.WriteLine(e.ToString());
183 return null;
184 }
185 }
186
187 /// <summary>
188 /// Returns a specified inventory item
189 /// </summary>
190 /// <param name="item">The item to return</param>
191 /// <returns>An inventory item</returns>
192 public InventoryItemBase getInventoryItem(LLUUID item)
193 {
194 try
195 {
196 lock (database)
197 {
198 Dictionary<string, string> param = new Dictionary<string, string>();
199 param["?uuid"] = item.ToStringHyphenated();
200
201 IDbCommand result = database.Query("SELECT * FROM inventoryitems WHERE inventoryID = ?uuid", param);
202 IDataReader reader = result.ExecuteReader();
203
204 List<InventoryItemBase> items = database.readInventoryItems(reader);
205
206 reader.Close();
207 result.Dispose();
208
209 if (items.Count > 0)
210 {
211 return items[0];
212 }
213 else
214 {
215 return null;
216 }
217 }
218 }
219 catch (Exception e)
220 {
221 database.Reconnect();
222 Console.WriteLine(e.ToString());
223 return null;
224 }
225 }
226
227 /// <summary>
228 /// Returns a specified inventory folder
229 /// </summary>
230 /// <param name="folder">The folder to return</param>
231 /// <returns>A folder class</returns>
232 public InventoryFolderBase getInventoryFolder(LLUUID folder)
233 {
234 try
235 {
236 lock (database)
237 {
238 Dictionary<string, string> param = new Dictionary<string, string>();
239 param["?uuid"] = folder.ToStringHyphenated();
240
241 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = ?uuid", param);
242 IDataReader reader = result.ExecuteReader();
243
244 List<InventoryFolderBase> items = database.readInventoryFolders(reader);
245
246 reader.Close();
247 result.Dispose();
248
249 if (items.Count > 0)
250 {
251 return items[0];
252 }
253 else
254 {
255 return null;
256 }
257 }
258 }
259 catch (Exception e)
260 {
261 database.Reconnect();
262 Console.WriteLine(e.ToString());
263 return null;
264 }
265 }
266
267 /// <summary>
268 /// Adds a specified item to the database
269 /// </summary>
270 /// <param name="item">The inventory item</param>
271 public void addInventoryItem(InventoryItemBase item)
272 {
273 lock (database)
274 {
275 database.insertItem(item);
276 }
277 }
278
279 /// <summary>
280 /// Updates the specified inventory item
281 /// </summary>
282 /// <param name="item">Inventory item to update</param>
283 public void updateInventoryItem(InventoryItemBase item)
284 {
285 addInventoryItem(item);
286 }
287
288 /// <summary>
289 /// Creates a new inventory folder
290 /// </summary>
291 /// <param name="folder">Folder to create</param>
292 public void addInventoryFolder(InventoryFolderBase folder)
293 {
294 lock (database)
295 {
296 database.insertFolder(folder);
297 }
298 }
299
300 /// <summary>
301 /// Updates an inventory folder
302 /// </summary>
303 /// <param name="folder">Folder to update</param>
304 public void updateInventoryFolder(InventoryFolderBase folder)
305 {
306 addInventoryFolder(folder);
307 }
308 }
309}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLLogData.cs b/OpenSim/Framework/Data.MySQL/MySQLLogData.cs
new file mode 100644
index 0000000..38f9fd3
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLLogData.cs
@@ -0,0 +1,105 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29
30namespace OpenSim.Framework.Data.MySQL
31{
32 /// <summary>
33 /// An interface to the log database for MySQL
34 /// </summary>
35 class MySQLLogData : ILogData
36 {
37 /// <summary>
38 /// The database manager
39 /// </summary>
40 public MySQLManager database;
41
42 /// <summary>
43 /// Artificial constructor called when the plugin is loaded
44 /// </summary>
45 public void Initialise()
46 {
47 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
48 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
49 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
50 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
51 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
52 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
53 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
54
55 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
56 }
57
58 /// <summary>
59 /// Saves a log item to the database
60 /// </summary>
61 /// <param name="serverDaemon">The daemon triggering the event</param>
62 /// <param name="target">The target of the action (region / agent UUID, etc)</param>
63 /// <param name="methodCall">The method call where the problem occured</param>
64 /// <param name="arguments">The arguments passed to the method</param>
65 /// <param name="priority">How critical is this?</param>
66 /// <param name="logMessage">The message to log</param>
67 public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage)
68 {
69 try
70 {
71 database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage);
72 }
73 catch
74 {
75 database.Reconnect();
76 }
77 }
78
79 /// <summary>
80 /// Returns the name of this DB provider
81 /// </summary>
82 /// <returns>A string containing the DB provider name</returns>
83 public string getName()
84 {
85 return "MySQL Logdata Interface";
86 }
87
88 /// <summary>
89 /// Closes the database provider
90 /// </summary>
91 public void Close()
92 {
93 // Do nothing.
94 }
95
96 /// <summary>
97 /// Returns the version of this DB provider
98 /// </summary>
99 /// <returns>A string containing the provider version</returns>
100 public string getVersion()
101 {
102 return "0.1";
103 }
104 }
105}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
new file mode 100644
index 0000000..88365a3
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
@@ -0,0 +1,602 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using System.Collections.Generic;
30using System.Data;
31using libsecondlife;
32using MySql.Data.MySqlClient;
33
34namespace OpenSim.Framework.Data.MySQL
35{
36 /// <summary>
37 /// A MySQL Database manager
38 /// </summary>
39 class MySQLManager
40 {
41 /// <summary>
42 /// The database connection object
43 /// </summary>
44 IDbConnection dbcon;
45 /// <summary>
46 /// Connection string for ADO.net
47 /// </summary>
48 string connectionString;
49
50 /// <summary>
51 /// Initialises and creates a new MySQL connection and maintains it.
52 /// </summary>
53 /// <param name="hostname">The MySQL server being connected to</param>
54 /// <param name="database">The name of the MySQL database being used</param>
55 /// <param name="username">The username logging into the database</param>
56 /// <param name="password">The password for the user logging in</param>
57 /// <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>
58 public MySQLManager(string hostname, string database, string username, string password, string cpooling, string port)
59 {
60 try
61 {
62 connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
63 dbcon = new MySqlConnection(connectionString);
64
65 dbcon.Open();
66
67 Console.WriteLine("MySQL connection established");
68 }
69 catch (Exception e)
70 {
71 throw new Exception("Error initialising MySql Database: " + e.ToString());
72 }
73 }
74
75 /// <summary>
76 /// Shuts down the database connection
77 /// </summary>
78 public void Close()
79 {
80 dbcon.Close();
81 dbcon = null;
82 }
83
84 /// <summary>
85 /// Reconnects to the database
86 /// </summary>
87 public void Reconnect()
88 {
89 lock (dbcon)
90 {
91 try
92 {
93 // Close the DB connection
94 dbcon.Close();
95 // Try reopen it
96 dbcon = new MySqlConnection(connectionString);
97 dbcon.Open();
98 }
99 catch (Exception e)
100 {
101 Console.WriteLine("Unable to reconnect to database " + e.ToString());
102 }
103 }
104 }
105
106 /// <summary>
107 /// Runs a query with protection against SQL Injection by using parameterised input.
108 /// </summary>
109 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
110 /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
111 /// <returns>A MySQL DB Command</returns>
112 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
113 {
114 try
115 {
116 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
117 dbcommand.CommandText = sql;
118 foreach (KeyValuePair<string, string> param in parameters)
119 {
120 dbcommand.Parameters.Add(param.Key, param.Value);
121 }
122
123 return (IDbCommand)dbcommand;
124 }
125 catch
126 {
127 lock (dbcon)
128 {
129 // Close the DB connection
130 try
131 {
132 dbcon.Close();
133 }
134 catch { }
135
136 // Try reopen it
137 try
138 {
139 dbcon = new MySqlConnection(connectionString);
140 dbcon.Open();
141 }
142 catch (Exception e)
143 {
144 Console.WriteLine("Unable to reconnect to database " + e.ToString());
145 }
146
147 // Run the query again
148 try
149 {
150 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
151 dbcommand.CommandText = sql;
152 foreach (KeyValuePair<string, string> param in parameters)
153 {
154 dbcommand.Parameters.Add(param.Key, param.Value);
155 }
156
157 return (IDbCommand)dbcommand;
158 }
159 catch (Exception e)
160 {
161 // Return null if it fails.
162 Console.WriteLine("Failed during Query generation: " + e.ToString());
163 return null;
164 }
165 }
166 }
167 }
168
169 /// <summary>
170 /// Reads a region row from a database reader
171 /// </summary>
172 /// <param name="reader">An active database reader</param>
173 /// <returns>A region profile</returns>
174 public SimProfileData readSimRow(IDataReader reader)
175 {
176 SimProfileData retval = new SimProfileData();
177
178 if (reader.Read())
179 {
180 // Region Main
181 retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString());
182 retval.regionName = (string)reader["regionName"];
183 retval.UUID = new LLUUID((string)reader["uuid"]);
184
185 // Secrets
186 retval.regionRecvKey = (string)reader["regionRecvKey"];
187 retval.regionSecret = (string)reader["regionSecret"];
188 retval.regionSendKey = (string)reader["regionSendKey"];
189
190 // Region Server
191 retval.regionDataURI = (string)reader["regionDataURI"];
192 retval.regionOnline = false; // Needs to be pinged before this can be set.
193 retval.serverIP = (string)reader["serverIP"];
194 retval.serverPort = (uint)reader["serverPort"];
195 retval.serverURI = (string)reader["serverURI"];
196
197 // Location
198 retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
199 retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
200 retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
201
202 // Neighbours - 0 = No Override
203 retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
204 retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
205 retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
206 retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
207
208 // Assets
209 retval.regionAssetURI = (string)reader["regionAssetURI"];
210 retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"];
211 retval.regionAssetSendKey = (string)reader["regionAssetSendKey"];
212
213 // Userserver
214 retval.regionUserURI = (string)reader["regionUserURI"];
215 retval.regionUserRecvKey = (string)reader["regionUserRecvKey"];
216 retval.regionUserSendKey = (string)reader["regionUserSendKey"];
217
218 // World Map Addition
219 string tempRegionMap = reader["regionMapTexture"].ToString();
220 if (tempRegionMap != "")
221 {
222 retval.regionMapTextureID = new LLUUID(tempRegionMap);
223 }
224 else
225 {
226 retval.regionMapTextureID = new LLUUID();
227 }
228 }
229 else
230 {
231 return null;
232 }
233 return retval;
234 }
235
236 /// <summary>
237 /// Reads a reservation row from a database reader
238 /// </summary>
239 /// <param name="reader">An active database reader</param>
240 /// <returns>A reservation data object</returns>
241 public ReservationData readReservationRow(IDataReader reader)
242 {
243 ReservationData retval = new ReservationData();
244 if (reader.Read())
245 {
246 retval.gridRecvKey = (string)reader["gridRecvKey"];
247 retval.gridSendKey = (string)reader["gridSendKey"];
248 retval.reservationCompany = (string)reader["resCompany"];
249 retval.reservationMaxX = Convert.ToInt32(reader["resXMax"].ToString());
250 retval.reservationMaxY = Convert.ToInt32(reader["resYMax"].ToString());
251 retval.reservationMinX = Convert.ToInt32(reader["resXMin"].ToString());
252 retval.reservationMinY = Convert.ToInt32(reader["resYMin"].ToString());
253 retval.reservationName = (string)reader["resName"];
254 retval.status = Convert.ToInt32(reader["status"].ToString()) == 1;
255 retval.userUUID = new LLUUID((string)reader["userUUID"]);
256
257 }
258 else
259 {
260 return null;
261 }
262 return retval;
263 }
264 /// <summary>
265 /// Reads an agent row from a database reader
266 /// </summary>
267 /// <param name="reader">An active database reader</param>
268 /// <returns>A user session agent</returns>
269 public UserAgentData readAgentRow(IDataReader reader)
270 {
271 UserAgentData retval = new UserAgentData();
272
273 if (reader.Read())
274 {
275 // Agent IDs
276 retval.UUID = new LLUUID((string)reader["UUID"]);
277 retval.sessionID = new LLUUID((string)reader["sessionID"]);
278 retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]);
279
280 // Agent Who?
281 retval.agentIP = (string)reader["agentIP"];
282 retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString());
283 retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString());
284
285 // Login/Logout times (UNIX Epoch)
286 retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString());
287 retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
288
289 // Current position
290 retval.currentRegion = (string)reader["currentRegion"];
291 retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
292 LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos);
293 }
294 else
295 {
296 return null;
297 }
298 return retval;
299 }
300
301 /// <summary>
302 /// Reads a user profile from an active data reader
303 /// </summary>
304 /// <param name="reader">An active database reader</param>
305 /// <returns>A user profile</returns>
306 public UserProfileData readUserRow(IDataReader reader)
307 {
308 UserProfileData retval = new UserProfileData();
309
310 if (reader.Read())
311 {
312 retval.UUID = new LLUUID((string)reader["UUID"]);
313 retval.username = (string)reader["username"];
314 retval.surname = (string)reader["lastname"];
315
316 retval.passwordHash = (string)reader["passwordHash"];
317 retval.passwordSalt = (string)reader["passwordSalt"];
318
319 retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
320 retval.homeLocation = new LLVector3(
321 Convert.ToSingle(reader["homeLocationX"].ToString()),
322 Convert.ToSingle(reader["homeLocationY"].ToString()),
323 Convert.ToSingle(reader["homeLocationZ"].ToString()));
324 retval.homeLookAt = new LLVector3(
325 Convert.ToSingle(reader["homeLookAtX"].ToString()),
326 Convert.ToSingle(reader["homeLookAtY"].ToString()),
327 Convert.ToSingle(reader["homeLookAtZ"].ToString()));
328
329 retval.created = Convert.ToInt32(reader["created"].ToString());
330 retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
331
332 retval.userInventoryURI = (string)reader["userInventoryURI"];
333 retval.userAssetURI = (string)reader["userAssetURI"];
334
335 retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
336 retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
337
338 retval.profileAboutText = (string)reader["profileAboutText"];
339 retval.profileFirstText = (string)reader["profileFirstText"];
340
341 retval.profileImage = new LLUUID((string)reader["profileImage"]);
342 retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]);
343
344 }
345 else
346 {
347 return null;
348 }
349 return retval;
350 }
351
352 /// <summary>
353 /// Reads a list of inventory folders returned by a query.
354 /// </summary>
355 /// <param name="reader">A MySQL Data Reader</param>
356 /// <returns>A List containing inventory folders</returns>
357 public List<InventoryFolderBase> readInventoryFolders(IDataReader reader)
358 {
359 List<InventoryFolderBase> rows = new List<InventoryFolderBase>();
360
361 while(reader.Read())
362 {
363 try
364 {
365 InventoryFolderBase folder = new InventoryFolderBase();
366
367 folder.agentID = new LLUUID((string)reader["agentID"]);
368 folder.parentID = new LLUUID((string)reader["parentFolderID"]);
369 folder.folderID = new LLUUID((string)reader["folderID"]);
370 folder.name = (string)reader["folderName"];
371
372 rows.Add(folder);
373 }
374 catch (Exception e)
375 {
376 Console.WriteLine(e.ToString());
377 }
378 }
379
380 return rows;
381 }
382
383 /// <summary>
384 /// Reads a collection of items from an SQL result
385 /// </summary>
386 /// <param name="reader">The SQL Result</param>
387 /// <returns>A List containing Inventory Items</returns>
388 public List<InventoryItemBase> readInventoryItems(IDataReader reader)
389 {
390 List<InventoryItemBase> rows = new List<InventoryItemBase>();
391
392 while (reader.Read())
393 {
394 try
395 {
396 InventoryItemBase item = new InventoryItemBase();
397
398 item.assetID = new LLUUID((string)reader["assetID"]);
399 item.avatarID = new LLUUID((string)reader["avatarID"]);
400 item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"].ToString());
401 item.inventoryDescription = (string)reader["inventoryDescription"];
402 item.inventoryID = new LLUUID((string)reader["inventoryID"]);
403 item.inventoryName = (string)reader["inventoryName"];
404 item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"].ToString());
405 item.parentFolderID = new LLUUID((string)reader["parentFolderID"]);
406 item.type = Convert.ToInt32(reader["type"].ToString());
407
408 rows.Add(item);
409 }
410 catch (Exception e)
411 {
412 Console.WriteLine(e.ToString());
413 }
414 }
415
416 return rows;
417 }
418
419 /// <summary>
420 /// Inserts a new row into the log database
421 /// </summary>
422 /// <param name="serverDaemon">The daemon which triggered this event</param>
423 /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param>
424 /// <param name="methodCall">The method call where the problem occured</param>
425 /// <param name="arguments">The arguments passed to the method</param>
426 /// <param name="priority">How critical is this?</param>
427 /// <param name="logMessage">Extra message info</param>
428 /// <returns>Saved successfully?</returns>
429 public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage)
430 {
431 string sql = "INSERT INTO logs (`target`, `server`, `method`, `arguments`, `priority`, `message`) VALUES ";
432 sql += "(?target, ?server, ?method, ?arguments, ?priority, ?message)";
433
434 Dictionary<string, string> parameters = new Dictionary<string, string>();
435 parameters["?server"] = serverDaemon;
436 parameters["?target"] = target;
437 parameters["?method"] = methodCall;
438 parameters["?arguments"] = arguments;
439 parameters["?priority"] = priority.ToString();
440 parameters["?message"] = logMessage;
441
442 bool returnval = false;
443
444 try
445 {
446 IDbCommand result = Query(sql, parameters);
447
448 if (result.ExecuteNonQuery() == 1)
449 returnval = true;
450
451 result.Dispose();
452 }
453 catch (Exception e)
454 {
455 Console.WriteLine(e.ToString());
456 return false;
457 }
458
459 return returnval;
460 }
461
462 /// <summary>
463 /// Inserts a new item into the database
464 /// </summary>
465 /// <param name="item">The item</param>
466 /// <returns>Success?</returns>
467 public bool insertItem(InventoryItemBase item)
468 {
469 string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, type, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions) VALUES ";
470 sql += "(?inventoryID, ?assetID, ?type, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions)";
471
472 Dictionary<string, string> parameters = new Dictionary<string, string>();
473 parameters["?inventoryID"] = item.inventoryID.ToStringHyphenated();
474 parameters["?assetID"] = item.assetID.ToStringHyphenated();
475 parameters["?type"] = item.type.ToString();
476 parameters["?parentFolderID"] = item.parentFolderID.ToStringHyphenated();
477 parameters["?avatarID"] = item.avatarID.ToStringHyphenated();
478 parameters["?inventoryName"] = item.inventoryName;
479 parameters["?inventoryDescription"] = item.inventoryDescription;
480 parameters["?inventoryNextPermissions"] = item.inventoryNextPermissions.ToString();
481 parameters["?inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString();
482
483 bool returnval = false;
484
485 try
486 {
487 IDbCommand result = Query(sql, parameters);
488
489 if (result.ExecuteNonQuery() == 1)
490 returnval = true;
491
492 result.Dispose();
493 }
494 catch (Exception e)
495 {
496 Console.WriteLine(e.ToString());
497 return false;
498 }
499
500 return returnval;
501 }
502
503 /// <summary>
504 /// Inserts a new folder into the database
505 /// </summary>
506 /// <param name="folder">The folder</param>
507 /// <returns>Success?</returns>
508 public bool insertFolder(InventoryFolderBase folder)
509 {
510 string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName) VALUES ";
511 sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName)";
512
513 Dictionary<string, string> parameters = new Dictionary<string, string>();
514 parameters["?folderID"] = folder.folderID.ToStringHyphenated();
515 parameters["?agentID"] = folder.agentID.ToStringHyphenated();
516 parameters["?parentFolderID"] = folder.parentID.ToStringHyphenated();
517 parameters["?folderName"] = folder.name;
518
519 bool returnval = false;
520 try
521 {
522 IDbCommand result = Query(sql, parameters);
523
524 if (result.ExecuteNonQuery() == 1)
525 returnval = true;
526
527 result.Dispose();
528 }
529 catch (Exception e)
530 {
531 Console.WriteLine(e.ToString());
532 return false;
533 }
534 return returnval;
535 }
536
537 /// <summary>
538 /// Inserts a new region into the database
539 /// </summary>
540 /// <param name="profile">The region to insert</param>
541 /// <returns>Success?</returns>
542 public bool insertRegion(SimProfileData regiondata)
543 {
544 string sql = "REPLACE INTO regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
545 sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
546 sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture) VALUES ";
547
548 sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
549 sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
550 sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture);";
551
552 Dictionary<string, string> parameters = new Dictionary<string, string>();
553
554 parameters["?regionHandle"] = regiondata.regionHandle.ToString();
555 parameters["?regionName"] = regiondata.regionName.ToString();
556 parameters["?uuid"] = regiondata.UUID.ToStringHyphenated();
557 parameters["?regionRecvKey"] = regiondata.regionRecvKey.ToString();
558 parameters["?regionSecret"] = regiondata.regionSecret.ToString();
559 parameters["?regionSendKey"] = regiondata.regionSendKey.ToString();
560 parameters["?regionDataURI"] = regiondata.regionDataURI.ToString();
561 parameters["?serverIP"] = regiondata.serverIP.ToString();
562 parameters["?serverPort"] = regiondata.serverPort.ToString();
563 parameters["?serverURI"] = regiondata.serverURI.ToString();
564 parameters["?locX"] = regiondata.regionLocX.ToString();
565 parameters["?locY"] = regiondata.regionLocY.ToString();
566 parameters["?locZ"] = regiondata.regionLocZ.ToString();
567 parameters["?eastOverrideHandle"] = regiondata.regionEastOverrideHandle.ToString();
568 parameters["?westOverrideHandle"] = regiondata.regionWestOverrideHandle.ToString();
569 parameters["?northOverrideHandle"] = regiondata.regionNorthOverrideHandle.ToString();
570 parameters["?southOverrideHandle"] = regiondata.regionSouthOverrideHandle.ToString();
571 parameters["?regionAssetURI"] = regiondata.regionAssetURI.ToString();
572 parameters["?regionAssetRecvKey"] = regiondata.regionAssetRecvKey.ToString();
573 parameters["?regionAssetSendKey"] = regiondata.regionAssetSendKey.ToString();
574 parameters["?regionUserURI"] = regiondata.regionUserURI.ToString();
575 parameters["?regionUserRecvKey"] = regiondata.regionUserRecvKey.ToString();
576 parameters["?regionUserSendKey"] = regiondata.regionUserSendKey.ToString();
577 parameters["?regionMapTexture"] = regiondata.regionMapTextureID.ToStringHyphenated();
578
579 bool returnval = false;
580
581 try
582 {
583
584 IDbCommand result = Query(sql, parameters);
585
586 //Console.WriteLine(result.CommandText);
587
588 if (result.ExecuteNonQuery() == 1)
589 returnval = true;
590
591 result.Dispose();
592 }
593 catch (Exception e)
594 {
595 Console.WriteLine(e.ToString());
596 return false;
597 }
598
599 return returnval;
600 }
601 }
602}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
new file mode 100644
index 0000000..c116536
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -0,0 +1,256 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using System.Collections.Generic;
30using System.Data;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.MySQL
34{
35 /// <summary>
36 /// A database interface class to a user profile storage system
37 /// </summary>
38 class MySQLUserData : IUserData
39 {
40 /// <summary>
41 /// Database manager for MySQL
42 /// </summary>
43 public MySQLManager database;
44
45 /// <summary>
46 /// Loads and initialises the MySQL storage plugin
47 /// </summary>
48 public void Initialise()
49 {
50 // Load from an INI file connection details
51 // TODO: move this to XML?
52 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
53 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
54 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
55 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
56 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
57 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
58 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
59
60 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
61 }
62
63 /// <summary>
64 /// Searches the database for a specified user profile
65 /// </summary>
66 /// <param name="name">The account name of the user</param>
67 /// <returns>A user profile</returns>
68 public UserProfileData getUserByName(string name)
69 {
70 return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
71 }
72
73 /// <summary>
74 /// Searches the database for a specified user profile by name components
75 /// </summary>
76 /// <param name="user">The first part of the account name</param>
77 /// <param name="last">The second part of the account name</param>
78 /// <returns>A user profile</returns>
79 public UserProfileData getUserByName(string user, string last)
80 {
81 try
82 {
83 lock (database)
84 {
85 Dictionary<string, string> param = new Dictionary<string, string>();
86 param["?first"] = user;
87 param["?second"] = last;
88
89 IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param);
90 IDataReader reader = result.ExecuteReader();
91
92 UserProfileData row = database.readUserRow(reader);
93
94 reader.Close();
95 result.Dispose();
96
97 return row;
98 }
99 }
100 catch (Exception e)
101 {
102 database.Reconnect();
103 Console.WriteLine(e.ToString());
104 return null;
105 }
106 }
107
108 /// <summary>
109 /// Searches the database for a specified user profile by UUID
110 /// </summary>
111 /// <param name="uuid">The account ID</param>
112 /// <returns>The users profile</returns>
113 public UserProfileData getUserByUUID(LLUUID uuid)
114 {
115 try
116 {
117 lock (database)
118 {
119 Dictionary<string, string> param = new Dictionary<string, string>();
120 param["?uuid"] = uuid.ToStringHyphenated();
121
122 IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param);
123 IDataReader reader = result.ExecuteReader();
124
125 UserProfileData row = database.readUserRow(reader);
126
127 reader.Close();
128 result.Dispose();
129
130 return row;
131 }
132 }
133 catch (Exception e)
134 {
135 database.Reconnect();
136 Console.WriteLine(e.ToString());
137 return null;
138 }
139 }
140
141 /// <summary>
142 /// Returns a user session searching by name
143 /// </summary>
144 /// <param name="name">The account name</param>
145 /// <returns>The users session</returns>
146 public UserAgentData getAgentByName(string name)
147 {
148 return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
149 }
150
151 /// <summary>
152 /// Returns a user session by account name
153 /// </summary>
154 /// <param name="user">First part of the users account name</param>
155 /// <param name="last">Second part of the users account name</param>
156 /// <returns>The users session</returns>
157 public UserAgentData getAgentByName(string user, string last)
158 {
159 UserProfileData profile = getUserByName(user, last);
160 return getAgentByUUID(profile.UUID);
161 }
162
163 /// <summary>
164 /// Returns an agent session by account UUID
165 /// </summary>
166 /// <param name="uuid">The accounts UUID</param>
167 /// <returns>The users session</returns>
168 public UserAgentData getAgentByUUID(LLUUID uuid)
169 {
170 try
171 {
172 lock (database)
173 {
174 Dictionary<string, string> param = new Dictionary<string, string>();
175 param["?uuid"] = uuid.ToStringHyphenated();
176
177 IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param);
178 IDataReader reader = result.ExecuteReader();
179
180 UserAgentData row = database.readAgentRow(reader);
181
182 reader.Close();
183 result.Dispose();
184
185 return row;
186 }
187 }
188 catch (Exception e)
189 {
190 database.Reconnect();
191 Console.WriteLine(e.ToString());
192 return null;
193 }
194 }
195
196 /// <summary>
197 /// Creates a new users profile
198 /// </summary>
199 /// <param name="user">The user profile to create</param>
200 public void addNewUserProfile(UserProfileData user)
201 {
202 }
203
204 /// <summary>
205 /// Creates a new agent
206 /// </summary>
207 /// <param name="agent">The agent to create</param>
208 public void addNewUserAgent(UserAgentData agent)
209 {
210 // Do nothing.
211 }
212
213 /// <summary>
214 /// Performs a money transfer request between two accounts
215 /// </summary>
216 /// <param name="from">The senders account ID</param>
217 /// <param name="to">The recievers account ID</param>
218 /// <param name="amount">The amount to transfer</param>
219 /// <returns>Success?</returns>
220 public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
221 {
222 return false;
223 }
224
225 /// <summary>
226 /// Performs an inventory transfer request between two accounts
227 /// </summary>
228 /// <remarks>TODO: Move to inventory server</remarks>
229 /// <param name="from">The senders account ID</param>
230 /// <param name="to">The recievers account ID</param>
231 /// <param name="item">The item to transfer</param>
232 /// <returns>Success?</returns>
233 public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
234 {
235 return false;
236 }
237
238 /// <summary>
239 /// Database provider name
240 /// </summary>
241 /// <returns>Provider name</returns>
242 public string getName()
243 {
244 return "MySQL Userdata Interface";
245 }
246
247 /// <summary>
248 /// Database provider version
249 /// </summary>
250 /// <returns>provider version</returns>
251 public string getVersion()
252 {
253 return "0.1";
254 }
255 }
256}
diff --git a/OpenSim/Framework/Data.MySQL/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.MySQL/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..52d6a54
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.InteropServices;
3// General Information about an assembly is controlled through the following
4// set of attributes. Change these attribute values to modify the information
5// associated with an assembly.
6[assembly: AssemblyTitle("OpenSim.Framework.Data.MySQL")]
7[assembly: AssemblyDescription("")]
8[assembly: AssemblyConfiguration("")]
9[assembly: AssemblyCompany("")]
10[assembly: AssemblyProduct("OpenSim.Framework.Data.MySQL")]
11[assembly: AssemblyCopyright("Copyright © 2007")]
12[assembly: AssemblyTrademark("")]
13[assembly: AssemblyCulture("")]
14
15// Setting ComVisible to false makes the types in this assembly not visible
16// to COM components. If you need to access a type in this assembly from
17// COM, set the ComVisible attribute to true on that type.
18[assembly: ComVisible(false)]
19
20// The following GUID is for the ID of the typelib if this project is exposed to COM
21[assembly: Guid("e49826b2-dcef-41be-a5bd-596733fa3304")]
22
23// Version information for an assembly consists of the following four values:
24//
25// Major Version
26// Minor Version
27// Build Number
28// Revision
29//
30// You can specify all the values or you can default the Revision and Build Numbers
31// by using the '*' as shown below:
32[assembly: AssemblyVersion("1.0.0.0")]
33[assembly: AssemblyFileVersion("1.0.0.0")]