aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs271
1 files changed, 0 insertions, 271 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs b/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs
deleted file mode 100644
index e988c94..0000000
--- a/OpenGridServices/OpenGrid.Framework.Data.MySQL/MySQLUserData.cs
+++ /dev/null
@@ -1,271 +0,0 @@
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 try
204 {
205 lock (database)
206 {
207 database.insertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, user.homeRegion, user.homeLocation.X, user.homeLocation.Y, user.homeLocation.Z,
208 user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, user.lastLogin, user.userInventoryURI, user.userAssetURI, user.profileCanDoMask, user.profileWantDoMask,
209 user.profileAboutText, user.profileFirstText, user.profileImage, user.profileFirstImage);
210 }
211 }
212 catch (Exception e)
213 {
214 database.Reconnect();
215 Console.WriteLine(e.ToString());
216 }
217 }
218
219 /// <summary>
220 /// Creates a new agent
221 /// </summary>
222 /// <param name="agent">The agent to create</param>
223 public void addNewUserAgent(UserAgentData agent)
224 {
225 // Do nothing.
226 }
227
228 /// <summary>
229 /// Performs a money transfer request between two accounts
230 /// </summary>
231 /// <param name="from">The senders account ID</param>
232 /// <param name="to">The recievers account ID</param>
233 /// <param name="amount">The amount to transfer</param>
234 /// <returns>Success?</returns>
235 public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
236 {
237 return false;
238 }
239
240 /// <summary>
241 /// Performs an inventory transfer request between two accounts
242 /// </summary>
243 /// <remarks>TODO: Move to inventory server</remarks>
244 /// <param name="from">The senders account ID</param>
245 /// <param name="to">The recievers account ID</param>
246 /// <param name="item">The item to transfer</param>
247 /// <returns>Success?</returns>
248 public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
249 {
250 return false;
251 }
252
253 /// <summary>
254 /// Database provider name
255 /// </summary>
256 /// <returns>Provider name</returns>
257 public string getName()
258 {
259 return "MySQL Userdata Interface";
260 }
261
262 /// <summary>
263 /// Database provider version
264 /// </summary>
265 /// <returns>provider version</returns>
266 public string getVersion()
267 {
268 return "0.1";
269 }
270 }
271}