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