diff options
author | MW | 2007-05-26 13:40:19 +0000 |
---|---|---|
committer | MW | 2007-05-26 13:40:19 +0000 |
commit | 3436961bb5c01d659d09be134368f4f69460cef9 (patch) | |
tree | 3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenGridServices/OpenGrid.Framework.Data.MySQL | |
download | opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.zip opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2 opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz |
Start of rewrite 5279!
Diffstat (limited to 'OpenGridServices/OpenGrid.Framework.Data.MySQL')
7 files changed, 829 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs new file mode 100644 index 0000000..6ac8cc3 --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs | |||
@@ -0,0 +1,201 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenGrid.Framework.Data; | ||
5 | |||
6 | namespace OpenGrid.Framework.Data.MySQL | ||
7 | { | ||
8 | public class MySQLGridData : IGridData | ||
9 | { | ||
10 | private MySQLManager database; | ||
11 | |||
12 | /// <summary> | ||
13 | /// Initialises the Grid Interface | ||
14 | /// </summary> | ||
15 | public void Initialise() | ||
16 | { | ||
17 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
18 | string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
19 | string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); | ||
20 | string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); | ||
21 | string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||
22 | string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
23 | string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); | ||
24 | |||
25 | database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort); | ||
26 | } | ||
27 | |||
28 | /// <summary> | ||
29 | /// Shuts down the grid interface | ||
30 | /// </summary> | ||
31 | public void Close() | ||
32 | { | ||
33 | database.Close(); | ||
34 | } | ||
35 | |||
36 | public string getName() | ||
37 | { | ||
38 | return "MySql OpenGridData"; | ||
39 | } | ||
40 | |||
41 | public string getVersion() | ||
42 | { | ||
43 | return "0.1"; | ||
44 | } | ||
45 | |||
46 | public SimProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) | ||
47 | { | ||
48 | try | ||
49 | { | ||
50 | lock (database) | ||
51 | { | ||
52 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
53 | param["?xmin"] = xmin.ToString(); | ||
54 | param["?ymin"] = ymin.ToString(); | ||
55 | param["?xmax"] = xmax.ToString(); | ||
56 | param["?ymax"] = ymax.ToString(); | ||
57 | |||
58 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", param); | ||
59 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
60 | |||
61 | SimProfileData row; | ||
62 | |||
63 | List<SimProfileData> rows = new List<SimProfileData>(); | ||
64 | |||
65 | while ((row = database.getSimRow(reader)) != null) | ||
66 | { | ||
67 | rows.Add(row); | ||
68 | } | ||
69 | reader.Close(); | ||
70 | result.Dispose(); | ||
71 | |||
72 | return rows.ToArray(); | ||
73 | |||
74 | } | ||
75 | } | ||
76 | catch (Exception e) | ||
77 | { | ||
78 | Console.WriteLine(e.ToString()); | ||
79 | return null; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Returns a sim profile from it's location | ||
85 | /// </summary> | ||
86 | /// <param name="handle">Region location handle</param> | ||
87 | /// <returns>Sim profile</returns> | ||
88 | public SimProfileData GetProfileByHandle(ulong handle) | ||
89 | { | ||
90 | try | ||
91 | { | ||
92 | lock (database) | ||
93 | { | ||
94 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
95 | param["?handle"] = handle.ToString(); | ||
96 | |||
97 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param); | ||
98 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
99 | |||
100 | SimProfileData row = database.getSimRow(reader); | ||
101 | reader.Close(); | ||
102 | result.Dispose(); | ||
103 | |||
104 | return row; | ||
105 | } | ||
106 | } | ||
107 | catch (Exception e) | ||
108 | { | ||
109 | Console.WriteLine(e.ToString()); | ||
110 | return null; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | /// <summary> | ||
115 | /// Returns a sim profile from it's UUID | ||
116 | /// </summary> | ||
117 | /// <param name="uuid">The region UUID</param> | ||
118 | /// <returns>The sim profile</returns> | ||
119 | public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) | ||
120 | { | ||
121 | try | ||
122 | { | ||
123 | lock (database) | ||
124 | { | ||
125 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
126 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
127 | |||
128 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param); | ||
129 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
130 | |||
131 | SimProfileData row = database.getSimRow(reader); | ||
132 | reader.Close(); | ||
133 | result.Dispose(); | ||
134 | |||
135 | return row; | ||
136 | } | ||
137 | } | ||
138 | catch (Exception e) | ||
139 | { | ||
140 | Console.WriteLine(e.ToString()); | ||
141 | return null; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | public DataResponse AddProfile(SimProfileData profile) | ||
146 | { | ||
147 | lock (database) | ||
148 | { | ||
149 | if (database.insertRow(profile)) | ||
150 | { | ||
151 | return DataResponse.RESPONSE_OK; | ||
152 | } | ||
153 | else | ||
154 | { | ||
155 | return DataResponse.RESPONSE_ERROR; | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | ||
162 | /// </summary> | ||
163 | /// <param name="uuid">The UUID of the challenger</param> | ||
164 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
165 | /// <param name="authkey">The secret</param> | ||
166 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
167 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey) | ||
168 | { | ||
169 | bool throwHissyFit = false; // Should be true by 1.0 | ||
170 | |||
171 | if (throwHissyFit) | ||
172 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
173 | |||
174 | SimProfileData data = GetProfileByLLUUID(uuid); | ||
175 | |||
176 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
177 | } | ||
178 | |||
179 | /// <summary> | ||
180 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
181 | /// </summary> | ||
182 | /// <remarks>This requires a security audit.</remarks> | ||
183 | /// <param name="uuid"></param> | ||
184 | /// <param name="handle"></param> | ||
185 | /// <param name="authhash"></param> | ||
186 | /// <param name="challenge"></param> | ||
187 | /// <returns></returns> | ||
188 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge) | ||
189 | { | ||
190 | System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed(); | ||
191 | System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding(); | ||
192 | |||
193 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); | ||
194 | byte[] hash = HashProvider.ComputeHash(stream); | ||
195 | |||
196 | return false; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | |||
201 | } | ||
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs new file mode 100644 index 0000000..ea7e2ac --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLManager.cs | |||
@@ -0,0 +1,270 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.Data; | ||
5 | |||
6 | // MySQL Native | ||
7 | using MySql; | ||
8 | using MySql.Data; | ||
9 | using MySql.Data.Types; | ||
10 | using MySql.Data.MySqlClient; | ||
11 | |||
12 | using OpenGrid.Framework.Data; | ||
13 | |||
14 | namespace OpenGrid.Framework.Data.MySQL | ||
15 | { | ||
16 | class MySQLManager | ||
17 | { | ||
18 | IDbConnection dbcon; | ||
19 | |||
20 | /// <summary> | ||
21 | /// Initialises and creates a new MySQL connection and maintains it. | ||
22 | /// </summary> | ||
23 | /// <param name="hostname">The MySQL server being connected to</param> | ||
24 | /// <param name="database">The name of the MySQL database being used</param> | ||
25 | /// <param name="username">The username logging into the database</param> | ||
26 | /// <param name="password">The password for the user logging in</param> | ||
27 | /// <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> | ||
28 | public MySQLManager(string hostname, string database, string username, string password, string cpooling, string port) | ||
29 | { | ||
30 | try | ||
31 | { | ||
32 | string connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";"; | ||
33 | dbcon = new MySqlConnection(connectionString); | ||
34 | |||
35 | dbcon.Open(); | ||
36 | } | ||
37 | catch (Exception e) | ||
38 | { | ||
39 | throw new Exception("Error initialising MySql Database: " + e.ToString()); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /// <summary> | ||
44 | /// Shuts down the database connection | ||
45 | /// </summary> | ||
46 | public void Close() | ||
47 | { | ||
48 | dbcon.Close(); | ||
49 | dbcon = null; | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Runs a query with protection against SQL Injection by using parameterised input. | ||
54 | /// </summary> | ||
55 | /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | ||
56 | /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | ||
57 | /// <returns>A MySQL DB Command</returns> | ||
58 | public IDbCommand Query(string sql, Dictionary<string, string> parameters) | ||
59 | { | ||
60 | try | ||
61 | { | ||
62 | MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand(); | ||
63 | dbcommand.CommandText = sql; | ||
64 | foreach (KeyValuePair<string, string> param in parameters) | ||
65 | { | ||
66 | dbcommand.Parameters.Add(param.Key, param.Value); | ||
67 | } | ||
68 | |||
69 | return (IDbCommand)dbcommand; | ||
70 | } | ||
71 | catch (Exception e) | ||
72 | { | ||
73 | Console.WriteLine("Failed during Query generation: " + e.ToString()); | ||
74 | return null; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public SimProfileData getSimRow(IDataReader reader) | ||
79 | { | ||
80 | SimProfileData retval = new SimProfileData(); | ||
81 | |||
82 | if (reader.Read()) | ||
83 | { | ||
84 | // Region Main | ||
85 | retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString()); | ||
86 | retval.regionName = (string)reader["regionName"]; | ||
87 | retval.UUID = new libsecondlife.LLUUID((string)reader["uuid"]); | ||
88 | |||
89 | // Secrets | ||
90 | retval.regionRecvKey = (string)reader["regionRecvKey"]; | ||
91 | retval.regionSecret = (string)reader["regionSecret"]; | ||
92 | retval.regionSendKey = (string)reader["regionSendKey"]; | ||
93 | |||
94 | // Region Server | ||
95 | retval.regionDataURI = (string)reader["regionDataURI"]; | ||
96 | retval.regionOnline = false; // Needs to be pinged before this can be set. | ||
97 | retval.serverIP = (string)reader["serverIP"]; | ||
98 | retval.serverPort = (uint)reader["serverPort"]; | ||
99 | retval.serverURI = (string)reader["serverURI"]; | ||
100 | |||
101 | // Location | ||
102 | retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString()); | ||
103 | retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString()); | ||
104 | retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString()); | ||
105 | |||
106 | // Neighbours - 0 = No Override | ||
107 | retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString()); | ||
108 | retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString()); | ||
109 | retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString()); | ||
110 | retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString()); | ||
111 | |||
112 | // Assets | ||
113 | retval.regionAssetURI = (string)reader["regionAssetURI"]; | ||
114 | retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | ||
115 | retval.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | ||
116 | |||
117 | // Userserver | ||
118 | retval.regionUserURI = (string)reader["regionUserURI"]; | ||
119 | retval.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | ||
120 | retval.regionUserSendKey = (string)reader["regionUserSendKey"]; | ||
121 | |||
122 | // World Map Addition | ||
123 | retval.regionMapTextureID = new libsecondlife.LLUUID((string)reader["regionMapTexture"]); | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | return null; | ||
128 | } | ||
129 | return retval; | ||
130 | } | ||
131 | |||
132 | public UserAgentData getAgentRow(IDataReader reader) | ||
133 | { | ||
134 | UserAgentData retval = new UserAgentData(); | ||
135 | |||
136 | if (reader.Read()) | ||
137 | { | ||
138 | // Agent IDs | ||
139 | retval.UUID = new libsecondlife.LLUUID((string)reader["UUID"]); | ||
140 | retval.sessionID = new libsecondlife.LLUUID((string)reader["sessionID"]); | ||
141 | retval.secureSessionID = new libsecondlife.LLUUID((string)reader["secureSessionID"]); | ||
142 | |||
143 | // Agent Who? | ||
144 | retval.agentIP = (string)reader["agentIP"]; | ||
145 | retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); | ||
146 | retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); | ||
147 | |||
148 | // Login/Logout times (UNIX Epoch) | ||
149 | retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString()); | ||
150 | retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); | ||
151 | |||
152 | // Current position | ||
153 | retval.currentRegion = (string)reader["currentRegion"]; | ||
154 | retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||
155 | libsecondlife.LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos); | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | return null; | ||
160 | } | ||
161 | return retval; | ||
162 | } | ||
163 | |||
164 | public UserProfileData getUserRow(IDataReader reader) | ||
165 | { | ||
166 | UserProfileData retval = new UserProfileData(); | ||
167 | |||
168 | if (reader.Read()) | ||
169 | { | ||
170 | retval.UUID = new libsecondlife.LLUUID((string)reader["UUID"]); | ||
171 | retval.username = (string)reader["username"]; | ||
172 | retval.surname = (string)reader["lastname"]; | ||
173 | |||
174 | retval.passwordHash = (string)reader["passwordHash"]; | ||
175 | retval.passwordSalt = (string)reader["passwordSalt"]; | ||
176 | |||
177 | retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); | ||
178 | retval.homeLocation = new libsecondlife.LLVector3( | ||
179 | Convert.ToSingle(reader["homeLocationX"].ToString()), | ||
180 | Convert.ToSingle(reader["homeLocationY"].ToString()), | ||
181 | Convert.ToSingle(reader["homeLocationZ"].ToString())); | ||
182 | retval.homeLookAt = new libsecondlife.LLVector3( | ||
183 | Convert.ToSingle(reader["homeLookAtX"].ToString()), | ||
184 | Convert.ToSingle(reader["homeLookAtY"].ToString()), | ||
185 | Convert.ToSingle(reader["homeLookAtZ"].ToString())); | ||
186 | |||
187 | retval.created = Convert.ToInt32(reader["created"].ToString()); | ||
188 | retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); | ||
189 | |||
190 | retval.userInventoryURI = (string)reader["userInventoryURI"]; | ||
191 | retval.userAssetURI = (string)reader["userAssetURI"]; | ||
192 | |||
193 | retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); | ||
194 | retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); | ||
195 | |||
196 | retval.profileAboutText = (string)reader["profileAboutText"]; | ||
197 | retval.profileFirstText = (string)reader["profileFirstText"]; | ||
198 | |||
199 | retval.profileImage = new libsecondlife.LLUUID((string)reader["profileImage"]); | ||
200 | retval.profileFirstImage = new libsecondlife.LLUUID((string)reader["profileFirstImage"]); | ||
201 | |||
202 | } | ||
203 | else | ||
204 | { | ||
205 | return null; | ||
206 | } | ||
207 | return retval; | ||
208 | } | ||
209 | |||
210 | public bool insertRow(SimProfileData profile) | ||
211 | { | ||
212 | string sql = "REPLACE INTO regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, "; | ||
213 | sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, "; | ||
214 | sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture) VALUES "; | ||
215 | |||
216 | sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, "; | ||
217 | sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, "; | ||
218 | sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture);"; | ||
219 | |||
220 | Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
221 | |||
222 | parameters["?regionHandle"] = profile.regionHandle.ToString(); | ||
223 | parameters["?regionName"] = profile.regionName.ToString(); | ||
224 | parameters["?uuid"] = profile.UUID.ToStringHyphenated(); | ||
225 | parameters["?regionRecvKey"] = profile.regionRecvKey.ToString(); | ||
226 | parameters["?regionSecret"] = profile.regionSecret.ToString(); | ||
227 | parameters["?regionSendKey"] = profile.regionSendKey.ToString(); | ||
228 | parameters["?regionDataURI"] = profile.regionDataURI.ToString(); | ||
229 | parameters["?serverIP"] = profile.serverIP.ToString(); | ||
230 | parameters["?serverPort"] = profile.serverPort.ToString(); | ||
231 | parameters["?serverURI"] = profile.serverURI.ToString(); | ||
232 | parameters["?locX"] = profile.regionLocX.ToString(); | ||
233 | parameters["?locY"] = profile.regionLocY.ToString(); | ||
234 | parameters["?locZ"] = profile.regionLocZ.ToString(); | ||
235 | parameters["?eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | ||
236 | parameters["?westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | ||
237 | parameters["?northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | ||
238 | parameters["?southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | ||
239 | parameters["?regionAssetURI"] = profile.regionAssetURI.ToString(); | ||
240 | parameters["?regionAssetRecvKey"] = profile.regionAssetRecvKey.ToString(); | ||
241 | parameters["?regionAssetSendKey"] = profile.regionAssetSendKey.ToString(); | ||
242 | parameters["?regionUserURI"] = profile.regionUserURI.ToString(); | ||
243 | parameters["?regionUserRecvKey"] = profile.regionUserRecvKey.ToString(); | ||
244 | parameters["?regionUserSendKey"] = profile.regionUserSendKey.ToString(); | ||
245 | parameters["?regionMapTexture"] = profile.regionMapTextureID.ToStringHyphenated(); | ||
246 | |||
247 | bool returnval = false; | ||
248 | |||
249 | try | ||
250 | { | ||
251 | |||
252 | IDbCommand result = Query(sql, parameters); | ||
253 | |||
254 | //Console.WriteLine(result.CommandText); | ||
255 | |||
256 | if (result.ExecuteNonQuery() == 1) | ||
257 | returnval = true; | ||
258 | |||
259 | result.Dispose(); | ||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | Console.WriteLine(e.ToString()); | ||
264 | return false; | ||
265 | } | ||
266 | |||
267 | return returnval; | ||
268 | } | ||
269 | } | ||
270 | } | ||
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs new file mode 100644 index 0000000..57dbfc6 --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs | |||
@@ -0,0 +1,153 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenGrid.Framework.Data; | ||
5 | using libsecondlife; | ||
6 | |||
7 | namespace OpenGrid.Framework.Data.MySQL | ||
8 | { | ||
9 | class MySQLUserData : IUserData | ||
10 | { | ||
11 | public MySQLManager database; | ||
12 | |||
13 | public void Initialise() | ||
14 | { | ||
15 | IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||
16 | string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||
17 | string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database"); | ||
18 | string settingUsername = GridDataMySqlFile.ParseFileReadValue("username"); | ||
19 | string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||
20 | string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||
21 | string settingPort = GridDataMySqlFile.ParseFileReadValue("port"); | ||
22 | |||
23 | database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort); | ||
24 | } | ||
25 | |||
26 | public UserProfileData getUserByName(string name) | ||
27 | { | ||
28 | return getUserByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
29 | } | ||
30 | |||
31 | public UserProfileData getUserByName(string user, string last) | ||
32 | { | ||
33 | try | ||
34 | { | ||
35 | lock (database) | ||
36 | { | ||
37 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
38 | param["?first"] = user; | ||
39 | param["?second"] = last; | ||
40 | |||
41 | System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param); | ||
42 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
43 | |||
44 | UserProfileData row = database.getUserRow(reader); | ||
45 | |||
46 | reader.Close(); | ||
47 | result.Dispose(); | ||
48 | |||
49 | return row; | ||
50 | } | ||
51 | } | ||
52 | catch (Exception e) | ||
53 | { | ||
54 | Console.WriteLine(e.ToString()); | ||
55 | return null; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | public UserProfileData getUserByUUID(LLUUID uuid) | ||
60 | { | ||
61 | try | ||
62 | { | ||
63 | lock (database) | ||
64 | { | ||
65 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
66 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
67 | |||
68 | System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param); | ||
69 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
70 | |||
71 | UserProfileData row = database.getUserRow(reader); | ||
72 | |||
73 | reader.Close(); | ||
74 | result.Dispose(); | ||
75 | |||
76 | return row; | ||
77 | } | ||
78 | } | ||
79 | catch (Exception e) | ||
80 | { | ||
81 | Console.WriteLine(e.ToString()); | ||
82 | return null; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | public UserAgentData getAgentByName(string name) | ||
87 | { | ||
88 | return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
89 | } | ||
90 | |||
91 | public UserAgentData getAgentByName(string user, string last) | ||
92 | { | ||
93 | UserProfileData profile = getUserByName(user, last); | ||
94 | return getAgentByUUID(profile.UUID); | ||
95 | } | ||
96 | |||
97 | public UserAgentData getAgentByUUID(LLUUID uuid) | ||
98 | { | ||
99 | try | ||
100 | { | ||
101 | lock (database) | ||
102 | { | ||
103 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
104 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
105 | |||
106 | System.Data.IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param); | ||
107 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
108 | |||
109 | UserAgentData row = database.getAgentRow(reader); | ||
110 | |||
111 | reader.Close(); | ||
112 | result.Dispose(); | ||
113 | |||
114 | return row; | ||
115 | } | ||
116 | } | ||
117 | catch (Exception e) | ||
118 | { | ||
119 | Console.WriteLine(e.ToString()); | ||
120 | return null; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public void addNewUserProfile(UserProfileData user) | ||
125 | { | ||
126 | } | ||
127 | |||
128 | public void addNewUserAgent(UserAgentData agent) | ||
129 | { | ||
130 | // Do nothing. | ||
131 | } | ||
132 | |||
133 | public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||
134 | { | ||
135 | return false; | ||
136 | } | ||
137 | |||
138 | public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||
139 | { | ||
140 | return false; | ||
141 | } | ||
142 | |||
143 | public string getName() | ||
144 | { | ||
145 | return "MySQL Userdata Interface"; | ||
146 | } | ||
147 | |||
148 | public string getVersion() | ||
149 | { | ||
150 | return "0.1"; | ||
151 | } | ||
152 | } | ||
153 | } | ||
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj new file mode 100644 index 0000000..9a1703a --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj | |||
@@ -0,0 +1,111 @@ | |||
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>{0F3C3AC1-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>OpenGrid.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>OpenGrid.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="System" > | ||
62 | <HintPath>System.dll</HintPath> | ||
63 | <Private>False</Private> | ||
64 | </Reference> | ||
65 | <Reference Include="System.Xml" > | ||
66 | <HintPath>System.Xml.dll</HintPath> | ||
67 | <Private>False</Private> | ||
68 | </Reference> | ||
69 | <Reference Include="System.Data" > | ||
70 | <HintPath>System.Data.dll</HintPath> | ||
71 | <Private>False</Private> | ||
72 | </Reference> | ||
73 | <Reference Include="libsecondlife.dll" > | ||
74 | <HintPath>..\..\bin\libsecondlife.dll</HintPath> | ||
75 | <Private>False</Private> | ||
76 | </Reference> | ||
77 | <Reference Include="MySql.Data.dll" > | ||
78 | <HintPath>..\..\bin\MySql.Data.dll</HintPath> | ||
79 | <Private>False</Private> | ||
80 | </Reference> | ||
81 | </ItemGroup> | ||
82 | <ItemGroup> | ||
83 | <ProjectReference Include="..\OpenGrid.Framework.Data\OpenGrid.Framework.Data.csproj"> | ||
84 | <Name>OpenGrid.Framework.Data</Name> | ||
85 | <Project>{62CDF671-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="MySQLManager.cs"> | ||
95 | <SubType>Code</SubType> | ||
96 | </Compile> | ||
97 | <Compile Include="MySQLUserData.cs"> | ||
98 | <SubType>Code</SubType> | ||
99 | </Compile> | ||
100 | <Compile Include="Properties\AssemblyInfo.cs"> | ||
101 | <SubType>Code</SubType> | ||
102 | </Compile> | ||
103 | </ItemGroup> | ||
104 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | ||
105 | <PropertyGroup> | ||
106 | <PreBuildEvent> | ||
107 | </PreBuildEvent> | ||
108 | <PostBuildEvent> | ||
109 | </PostBuildEvent> | ||
110 | </PropertyGroup> | ||
111 | </Project> | ||
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj.user b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj.user new file mode 100644 index 0000000..d47d65d --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.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-07\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/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.dll.build b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.dll.build new file mode 100644 index 0000000..2d425b4 --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.dll.build | |||
@@ -0,0 +1,47 @@ | |||
1 | <?xml version="1.0" ?> | ||
2 | <project name="OpenGrid.Framework.Data.MySQL" default="build"> | ||
3 | <target name="build"> | ||
4 | <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" /> | ||
5 | <mkdir dir="${project::get-base-directory()}/${build.dir}" /> | ||
6 | <copy todir="${project::get-base-directory()}/${build.dir}"> | ||
7 | <fileset basedir="${project::get-base-directory()}"> | ||
8 | </fileset> | ||
9 | </copy> | ||
10 | <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll"> | ||
11 | <resources prefix="OpenGrid.Framework.Data.MySQL" dynamicprefix="true" > | ||
12 | </resources> | ||
13 | <sources failonempty="true"> | ||
14 | <include name="MySQLGridData.cs" /> | ||
15 | <include name="MySQLManager.cs" /> | ||
16 | <include name="MySQLUserData.cs" /> | ||
17 | <include name="Properties/AssemblyInfo.cs" /> | ||
18 | </sources> | ||
19 | <references basedir="${project::get-base-directory()}"> | ||
20 | <lib> | ||
21 | <include name="${project::get-base-directory()}" /> | ||
22 | <include name="${project::get-base-directory()}/${build.dir}" /> | ||
23 | </lib> | ||
24 | <include name="System.dll" /> | ||
25 | <include name="System.Xml.dll" /> | ||
26 | <include name="System.Data.dll" /> | ||
27 | <include name="../../bin/OpenGrid.Framework.Data.dll" /> | ||
28 | <include name="../../bin/libsecondlife.dll" /> | ||
29 | <include name="../../bin/MySql.Data.dll" /> | ||
30 | </references> | ||
31 | </csc> | ||
32 | <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../bin/" /> | ||
33 | <mkdir dir="${project::get-base-directory()}/../../bin/"/> | ||
34 | <copy todir="${project::get-base-directory()}/../../bin/"> | ||
35 | <fileset basedir="${project::get-base-directory()}/${build.dir}/" > | ||
36 | <include name="*.dll"/> | ||
37 | <include name="*.exe"/> | ||
38 | </fileset> | ||
39 | </copy> | ||
40 | </target> | ||
41 | <target name="clean"> | ||
42 | <delete dir="${bin.dir}" failonerror="false" /> | ||
43 | <delete dir="${obj.dir}" failonerror="false" /> | ||
44 | </target> | ||
45 | <target name="doc" description="Creates documentation."> | ||
46 | </target> | ||
47 | </project> | ||
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0bfd1d6 --- /dev/null +++ b/OpenGridServices/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,35 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using 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")] | ||