diff options
Some more code refactoring, plus a restructuring of the directories so that the Grid servers can be a separate solution to the region server.
Diffstat (limited to 'OpenGridServices-Source/OpenGrid.Framework.Data.MySQL')
7 files changed, 803 insertions, 0 deletions
diff --git a/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs new file mode 100644 index 0000000..46183b4 --- /dev/null +++ b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs | |||
@@ -0,0 +1,193 @@ | |||
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 | database = new MySQLManager("localhost", "database", "username", "password", "false"); | ||
18 | } | ||
19 | |||
20 | /// <summary> | ||
21 | /// Shuts down the grid interface | ||
22 | /// </summary> | ||
23 | public void Close() | ||
24 | { | ||
25 | database.Close(); | ||
26 | } | ||
27 | |||
28 | public string getName() | ||
29 | { | ||
30 | return "MySql OpenGridData"; | ||
31 | } | ||
32 | |||
33 | public string getVersion() | ||
34 | { | ||
35 | return "0.1"; | ||
36 | } | ||
37 | |||
38 | public SimProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) | ||
39 | { | ||
40 | try | ||
41 | { | ||
42 | lock (database) | ||
43 | { | ||
44 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
45 | param["?xmin"] = xmin.ToString(); | ||
46 | param["?ymin"] = ymin.ToString(); | ||
47 | param["?xmax"] = xmax.ToString(); | ||
48 | param["?ymax"] = ymax.ToString(); | ||
49 | |||
50 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", param); | ||
51 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
52 | |||
53 | SimProfileData row; | ||
54 | |||
55 | List<SimProfileData> rows = new List<SimProfileData>(); | ||
56 | |||
57 | while ((row = database.getSimRow(reader)) != null) | ||
58 | { | ||
59 | rows.Add(row); | ||
60 | } | ||
61 | reader.Close(); | ||
62 | result.Dispose(); | ||
63 | |||
64 | return rows.ToArray(); | ||
65 | |||
66 | } | ||
67 | } | ||
68 | catch (Exception e) | ||
69 | { | ||
70 | Console.WriteLine(e.ToString()); | ||
71 | return null; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | /// <summary> | ||
76 | /// Returns a sim profile from it's location | ||
77 | /// </summary> | ||
78 | /// <param name="handle">Region location handle</param> | ||
79 | /// <returns>Sim profile</returns> | ||
80 | public SimProfileData GetProfileByHandle(ulong handle) | ||
81 | { | ||
82 | try | ||
83 | { | ||
84 | lock (database) | ||
85 | { | ||
86 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
87 | param["?handle"] = handle.ToString(); | ||
88 | |||
89 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE regionHandle = ?handle", param); | ||
90 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
91 | |||
92 | SimProfileData row = database.getSimRow(reader); | ||
93 | reader.Close(); | ||
94 | result.Dispose(); | ||
95 | |||
96 | return row; | ||
97 | } | ||
98 | } | ||
99 | catch (Exception e) | ||
100 | { | ||
101 | Console.WriteLine(e.ToString()); | ||
102 | return null; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Returns a sim profile from it's UUID | ||
108 | /// </summary> | ||
109 | /// <param name="uuid">The region UUID</param> | ||
110 | /// <returns>The sim profile</returns> | ||
111 | public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid) | ||
112 | { | ||
113 | try | ||
114 | { | ||
115 | lock (database) | ||
116 | { | ||
117 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
118 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
119 | |||
120 | System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = ?uuid", param); | ||
121 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
122 | |||
123 | SimProfileData row = database.getSimRow(reader); | ||
124 | reader.Close(); | ||
125 | result.Dispose(); | ||
126 | |||
127 | return row; | ||
128 | } | ||
129 | } | ||
130 | catch (Exception e) | ||
131 | { | ||
132 | Console.WriteLine(e.ToString()); | ||
133 | return null; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | public DataResponse AddProfile(SimProfileData profile) | ||
138 | { | ||
139 | lock (database) | ||
140 | { | ||
141 | if (database.insertRow(profile)) | ||
142 | { | ||
143 | return DataResponse.RESPONSE_OK; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | return DataResponse.RESPONSE_ERROR; | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /// <summary> | ||
153 | /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | ||
154 | /// </summary> | ||
155 | /// <param name="uuid">The UUID of the challenger</param> | ||
156 | /// <param name="handle">The attempted regionHandle of the challenger</param> | ||
157 | /// <param name="authkey">The secret</param> | ||
158 | /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||
159 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey) | ||
160 | { | ||
161 | bool throwHissyFit = false; // Should be true by 1.0 | ||
162 | |||
163 | if (throwHissyFit) | ||
164 | throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||
165 | |||
166 | SimProfileData data = GetProfileByLLUUID(uuid); | ||
167 | |||
168 | return (handle == data.regionHandle && authkey == data.regionSecret); | ||
169 | } | ||
170 | |||
171 | /// <summary> | ||
172 | /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||
173 | /// </summary> | ||
174 | /// <remarks>This requires a security audit.</remarks> | ||
175 | /// <param name="uuid"></param> | ||
176 | /// <param name="handle"></param> | ||
177 | /// <param name="authhash"></param> | ||
178 | /// <param name="challenge"></param> | ||
179 | /// <returns></returns> | ||
180 | public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge) | ||
181 | { | ||
182 | System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed(); | ||
183 | System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding(); | ||
184 | |||
185 | byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge); | ||
186 | byte[] hash = HashProvider.ComputeHash(stream); | ||
187 | |||
188 | return false; | ||
189 | } | ||
190 | } | ||
191 | |||
192 | |||
193 | } | ||
diff --git a/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLManager.cs new file mode 100644 index 0000000..a476e97 --- /dev/null +++ b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLManager.cs | |||
@@ -0,0 +1,269 @@ | |||
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) | ||
29 | { | ||
30 | try | ||
31 | { | ||
32 | string connectionString = "Server=" + hostname + ";Port=13306;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) 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);"; | ||
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 | |||
246 | bool returnval = false; | ||
247 | |||
248 | try | ||
249 | { | ||
250 | |||
251 | IDbCommand result = Query(sql, parameters); | ||
252 | |||
253 | //Console.WriteLine(result.CommandText); | ||
254 | |||
255 | if (result.ExecuteNonQuery() == 1) | ||
256 | returnval = true; | ||
257 | |||
258 | result.Dispose(); | ||
259 | } | ||
260 | catch (Exception e) | ||
261 | { | ||
262 | Console.WriteLine(e.ToString()); | ||
263 | return false; | ||
264 | } | ||
265 | |||
266 | return returnval; | ||
267 | } | ||
268 | } | ||
269 | } | ||
diff --git a/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs new file mode 100644 index 0000000..0741272 --- /dev/null +++ b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs | |||
@@ -0,0 +1,136 @@ | |||
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 | database = new MySQLManager("host", "database", "user", "password", "false"); | ||
16 | } | ||
17 | |||
18 | public UserProfileData getUserByName(string name) | ||
19 | { | ||
20 | return getUserByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
21 | } | ||
22 | |||
23 | public UserProfileData getUserByName(string user, string last) | ||
24 | { | ||
25 | try | ||
26 | { | ||
27 | lock (database) | ||
28 | { | ||
29 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
30 | param["?first"] = user; | ||
31 | param["?second"] = last; | ||
32 | |||
33 | System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param); | ||
34 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
35 | |||
36 | UserProfileData row = database.getUserRow(reader); | ||
37 | |||
38 | reader.Close(); | ||
39 | result.Dispose(); | ||
40 | |||
41 | return row; | ||
42 | } | ||
43 | } | ||
44 | catch (Exception e) | ||
45 | { | ||
46 | Console.WriteLine(e.ToString()); | ||
47 | return null; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | public UserProfileData getUserByUUID(LLUUID uuid) | ||
52 | { | ||
53 | try | ||
54 | { | ||
55 | lock (database) | ||
56 | { | ||
57 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
58 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
59 | |||
60 | System.Data.IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param); | ||
61 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
62 | |||
63 | UserProfileData row = database.getUserRow(reader); | ||
64 | |||
65 | reader.Close(); | ||
66 | result.Dispose(); | ||
67 | |||
68 | return row; | ||
69 | } | ||
70 | } | ||
71 | catch (Exception e) | ||
72 | { | ||
73 | Console.WriteLine(e.ToString()); | ||
74 | return null; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public UserAgentData getAgentByName(string name) | ||
79 | { | ||
80 | return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
81 | } | ||
82 | |||
83 | public UserAgentData getAgentByName(string user, string last) | ||
84 | { | ||
85 | UserProfileData profile = getUserByName(user, last); | ||
86 | return getAgentByUUID(profile.UUID); | ||
87 | } | ||
88 | |||
89 | public UserAgentData getAgentByUUID(LLUUID uuid) | ||
90 | { | ||
91 | try | ||
92 | { | ||
93 | lock (database) | ||
94 | { | ||
95 | Dictionary<string, string> param = new Dictionary<string, string>(); | ||
96 | param["?uuid"] = uuid.ToStringHyphenated(); | ||
97 | |||
98 | System.Data.IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param); | ||
99 | System.Data.IDataReader reader = result.ExecuteReader(); | ||
100 | |||
101 | UserAgentData row = database.getAgentRow(reader); | ||
102 | |||
103 | reader.Close(); | ||
104 | result.Dispose(); | ||
105 | |||
106 | return row; | ||
107 | } | ||
108 | } | ||
109 | catch (Exception e) | ||
110 | { | ||
111 | Console.WriteLine(e.ToString()); | ||
112 | return null; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||
117 | { | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||
122 | { | ||
123 | return false; | ||
124 | } | ||
125 | |||
126 | public string getName() | ||
127 | { | ||
128 | return "MySQL Userdata Interface"; | ||
129 | } | ||
130 | |||
131 | public string getVersion() | ||
132 | { | ||
133 | return "0.1"; | ||
134 | } | ||
135 | } | ||
136 | } | ||
diff --git a/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj new file mode 100644 index 0000000..ae3d5c5 --- /dev/null +++ b/OpenGridServices-Source/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-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj.user b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj.user new file mode 100644 index 0000000..d47d65d --- /dev/null +++ b/OpenGridServices-Source/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-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.dll.build b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.dll.build new file mode 100644 index 0000000..a390324 --- /dev/null +++ b/OpenGridServices-Source/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-Source/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs b/OpenGridServices-Source/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0bfd1d6 --- /dev/null +++ b/OpenGridServices-Source/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")] | ||