diff options
Switched in NameSpaceChanges
Diffstat (limited to 'OpenSim/Framework/Data.MySQL/MySQLUserData.cs')
-rw-r--r-- | OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 257 |
1 files changed, 257 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..0304452 --- /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 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Framework.Data; | ||
32 | using libsecondlife; | ||
33 | |||
34 | namespace OpenSim.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 | } | ||