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