aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:10:25 +0000
committerAdam Frisby2007-07-11 08:10:25 +0000
commite2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch)
tree8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Framework/Data.MySQL/MySQLUserData.cs
parent* Wiping trunk in prep for Sugilite (diff)
parent* Applying dalien's patches from bug#177 and #179 (diff)
downloadopensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLUserData.cs')
-rw-r--r--OpenSim/Framework/Data.MySQL/MySQLUserData.cs256
1 files changed, 256 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
new file mode 100644
index 0000000..c116536
--- /dev/null
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -0,0 +1,256 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Data;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.MySQL
34{
35 /// <summary>
36 /// A database interface class to a user profile storage system
37 /// </summary>
38 class MySQLUserData : IUserData
39 {
40 /// <summary>
41 /// Database manager for MySQL
42 /// </summary>
43 public MySQLManager database;
44
45 /// <summary>
46 /// Loads and initialises the MySQL storage plugin
47 /// </summary>
48 public void Initialise()
49 {
50 // Load from an INI file connection details
51 // TODO: move this to XML?
52 IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini");
53 string settingHostname = GridDataMySqlFile.ParseFileReadValue("hostname");
54 string settingDatabase = GridDataMySqlFile.ParseFileReadValue("database");
55 string settingUsername = GridDataMySqlFile.ParseFileReadValue("username");
56 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
57 string settingPooling = GridDataMySqlFile.ParseFileReadValue("pooling");
58 string settingPort = GridDataMySqlFile.ParseFileReadValue("port");
59
60 database = new MySQLManager(settingHostname, settingDatabase, settingUsername, settingPassword, settingPooling, settingPort);
61 }
62
63 /// <summary>
64 /// Searches the database for a specified user profile
65 /// </summary>
66 /// <param name="name">The account name of the user</param>
67 /// <returns>A user profile</returns>
68 public UserProfileData getUserByName(string name)
69 {
70 return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
71 }
72
73 /// <summary>
74 /// Searches the database for a specified user profile by name components
75 /// </summary>
76 /// <param name="user">The first part of the account name</param>
77 /// <param name="last">The second part of the account name</param>
78 /// <returns>A user profile</returns>
79 public UserProfileData getUserByName(string user, string last)
80 {
81 try
82 {
83 lock (database)
84 {
85 Dictionary<string, string> param = new Dictionary<string, string>();
86 param["?first"] = user;
87 param["?second"] = last;
88
89 IDbCommand result = database.Query("SELECT * FROM users WHERE username = ?first AND lastname = ?second", param);
90 IDataReader reader = result.ExecuteReader();
91
92 UserProfileData row = database.readUserRow(reader);
93
94 reader.Close();
95 result.Dispose();
96
97 return row;
98 }
99 }
100 catch (Exception e)
101 {
102 database.Reconnect();
103 Console.WriteLine(e.ToString());
104 return null;
105 }
106 }
107
108 /// <summary>
109 /// Searches the database for a specified user profile by UUID
110 /// </summary>
111 /// <param name="uuid">The account ID</param>
112 /// <returns>The users profile</returns>
113 public UserProfileData getUserByUUID(LLUUID uuid)
114 {
115 try
116 {
117 lock (database)
118 {
119 Dictionary<string, string> param = new Dictionary<string, string>();
120 param["?uuid"] = uuid.ToStringHyphenated();
121
122 IDbCommand result = database.Query("SELECT * FROM users WHERE UUID = ?uuid", param);
123 IDataReader reader = result.ExecuteReader();
124
125 UserProfileData row = database.readUserRow(reader);
126
127 reader.Close();
128 result.Dispose();
129
130 return row;
131 }
132 }
133 catch (Exception e)
134 {
135 database.Reconnect();
136 Console.WriteLine(e.ToString());
137 return null;
138 }
139 }
140
141 /// <summary>
142 /// Returns a user session searching by name
143 /// </summary>
144 /// <param name="name">The account name</param>
145 /// <returns>The users session</returns>
146 public UserAgentData getAgentByName(string name)
147 {
148 return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
149 }
150
151 /// <summary>
152 /// Returns a user session by account name
153 /// </summary>
154 /// <param name="user">First part of the users account name</param>
155 /// <param name="last">Second part of the users account name</param>
156 /// <returns>The users session</returns>
157 public UserAgentData getAgentByName(string user, string last)
158 {
159 UserProfileData profile = getUserByName(user, last);
160 return getAgentByUUID(profile.UUID);
161 }
162
163 /// <summary>
164 /// Returns an agent session by account UUID
165 /// </summary>
166 /// <param name="uuid">The accounts UUID</param>
167 /// <returns>The users session</returns>
168 public UserAgentData getAgentByUUID(LLUUID uuid)
169 {
170 try
171 {
172 lock (database)
173 {
174 Dictionary<string, string> param = new Dictionary<string, string>();
175 param["?uuid"] = uuid.ToStringHyphenated();
176
177 IDbCommand result = database.Query("SELECT * FROM agents WHERE UUID = ?uuid", param);
178 IDataReader reader = result.ExecuteReader();
179
180 UserAgentData row = database.readAgentRow(reader);
181
182 reader.Close();
183 result.Dispose();
184
185 return row;
186 }
187 }
188 catch (Exception e)
189 {
190 database.Reconnect();
191 Console.WriteLine(e.ToString());
192 return null;
193 }
194 }
195
196 /// <summary>
197 /// Creates a new users profile
198 /// </summary>
199 /// <param name="user">The user profile to create</param>
200 public void addNewUserProfile(UserProfileData user)
201 {
202 }
203
204 /// <summary>
205 /// Creates a new agent
206 /// </summary>
207 /// <param name="agent">The agent to create</param>
208 public void addNewUserAgent(UserAgentData agent)
209 {
210 // Do nothing.
211 }
212
213 /// <summary>
214 /// Performs a money transfer request between two accounts
215 /// </summary>
216 /// <param name="from">The senders account ID</param>
217 /// <param name="to">The recievers account ID</param>
218 /// <param name="amount">The amount to transfer</param>
219 /// <returns>Success?</returns>
220 public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
221 {
222 return false;
223 }
224
225 /// <summary>
226 /// Performs an inventory transfer request between two accounts
227 /// </summary>
228 /// <remarks>TODO: Move to inventory server</remarks>
229 /// <param name="from">The senders account ID</param>
230 /// <param name="to">The recievers account ID</param>
231 /// <param name="item">The item to transfer</param>
232 /// <returns>Success?</returns>
233 public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
234 {
235 return false;
236 }
237
238 /// <summary>
239 /// Database provider name
240 /// </summary>
241 /// <returns>Provider name</returns>
242 public string getName()
243 {
244 return "MySQL Userdata Interface";
245 }
246
247 /// <summary>
248 /// Database provider version
249 /// </summary>
250 /// <returns>provider version</returns>
251 public string getVersion()
252 {
253 return "0.1";
254 }
255 }
256}