aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLManager.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLManager.cs1248
1 files changed, 0 insertions, 1248 deletions
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs
deleted file mode 100644
index ace2027..0000000
--- a/OpenSim/Data/MySQL/MySQLManager.cs
+++ /dev/null
@@ -1,1248 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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;
30using System.Collections.Generic;
31using System.Data;
32using System.IO;
33using System.Reflection;
34using log4net;
35using MySql.Data.MySqlClient;
36using OpenMetaverse;
37using OpenSim.Framework;
38
39namespace OpenSim.Data.MySQL
40{
41 /// <summary>
42 /// A MySQL Database manager
43 /// </summary>
44 public class MySQLManager
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 /// <summary>
49 /// Connection string for ADO.net
50 /// </summary>
51 private string connectionString;
52
53 private object m_dbLock = new object();
54
55 private const string m_waitTimeoutSelect = "select @@wait_timeout";
56
57 /// <summary>
58 /// Wait timeout for our connection in ticks.
59 /// </summary>
60 private long m_waitTimeout;
61
62 /// <summary>
63 /// Make our storage of the timeout this amount smaller than it actually is, to give us a margin on long
64 /// running database operations.
65 /// </summary>
66 private long m_waitTimeoutLeeway = 60 * TimeSpan.TicksPerSecond;
67
68 /// <summary>
69 /// Holds the last tick time that the connection was used.
70 /// </summary>
71 private long m_lastConnectionUse;
72
73 /// <summary>
74 /// Initialises and creates a new MySQL connection and maintains it.
75 /// </summary>
76 /// <param name="hostname">The MySQL server being connected to</param>
77 /// <param name="database">The name of the MySQL database being used</param>
78 /// <param name="username">The username logging into the database</param>
79 /// <param name="password">The password for the user logging in</param>
80 /// <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>
81 /// <param name="port">The MySQL server port</param>
82 public MySQLManager(string hostname, string database, string username, string password, string cpooling,
83 string port)
84 {
85 string s = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" +
86 username + ";Password=" + password + ";Pooling=" + cpooling + ";";
87
88 Initialise(s);
89 }
90
91 /// <summary>
92 /// Initialises and creates a new MySQL connection and maintains it.
93 /// </summary>
94 /// <param name="connect">connectionString</param>
95 public MySQLManager(String connect)
96 {
97 Initialise(connect);
98 }
99
100 /// <summary>
101 /// Initialises and creates a new MySQL connection and maintains it.
102 /// </summary>
103 /// <param name="connect">connectionString</param>
104 public void Initialise(String connect)
105 {
106 try
107 {
108 connectionString = connect;
109 //dbcon = new MySqlConnection(connectionString);
110
111 try
112 {
113 //dbcon.Open();
114 }
115 catch(Exception e)
116 {
117 throw new Exception("Connection error while using connection string ["+connectionString+"]", e);
118 }
119
120 m_log.Info("[MYSQL]: Connection established");
121 GetWaitTimeout();
122 }
123 catch (Exception e)
124 {
125 throw new Exception("Error initialising MySql Database: " + e.ToString());
126 }
127 }
128
129 /// <summary>
130 /// Get the wait_timeout value for our connection
131 /// </summary>
132 protected void GetWaitTimeout()
133 {
134 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
135 {
136 dbcon.Open();
137
138 using (MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect, dbcon))
139 {
140 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
141 {
142 if (dbReader.Read())
143 {
144 m_waitTimeout
145 = Convert.ToInt32(dbReader["@@wait_timeout"]) * TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
146 }
147 }
148 }
149 }
150
151 m_lastConnectionUse = DateTime.Now.Ticks;
152
153 m_log.DebugFormat(
154 "[REGION DB]: Connection wait timeout {0} seconds", m_waitTimeout / TimeSpan.TicksPerSecond);
155 }
156
157 public string ConnectionString
158 {
159 get { return connectionString; }
160 }
161
162 /// <summary>
163 /// Returns the version of this DB provider
164 /// </summary>
165 /// <returns>A string containing the DB provider</returns>
166 public string getVersion()
167 {
168 Module module = GetType().Module;
169 // string dllName = module.Assembly.ManifestModule.Name;
170 Version dllVersion = module.Assembly.GetName().Version;
171
172 return
173 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
174 dllVersion.Revision);
175 }
176
177 /// <summary>
178 /// Extract a named string resource from the embedded resources
179 /// </summary>
180 /// <param name="name">name of embedded resource</param>
181 /// <returns>string contained within the embedded resource</returns>
182 private string getResourceString(string name)
183 {
184 Assembly assem = GetType().Assembly;
185 string[] names = assem.GetManifestResourceNames();
186
187 foreach (string s in names)
188 {
189 if (s.EndsWith(name))
190 {
191 using (Stream resource = assem.GetManifestResourceStream(s))
192 {
193 using (StreamReader resourceReader = new StreamReader(resource))
194 {
195 string resourceString = resourceReader.ReadToEnd();
196 return resourceString;
197 }
198 }
199 }
200 }
201 throw new Exception(string.Format("Resource '{0}' was not found", name));
202 }
203
204 /// <summary>
205 /// Execute a SQL statement stored in a resource, as a string
206 /// </summary>
207 /// <param name="name">name of embedded resource</param>
208 public void ExecuteResourceSql(string name)
209 {
210 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
211 {
212 dbcon.Open();
213
214 MySqlCommand cmd = new MySqlCommand(getResourceString(name), dbcon);
215 cmd.ExecuteNonQuery();
216 }
217 }
218
219 /// <summary>
220 /// Execute a MySqlCommand
221 /// </summary>
222 /// <param name="sql">sql string to execute</param>
223 public void ExecuteSql(string sql)
224 {
225 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
226 {
227 dbcon.Open();
228
229 MySqlCommand cmd = new MySqlCommand(sql, dbcon);
230 cmd.ExecuteNonQuery();
231 }
232 }
233
234 public void ExecuteParameterizedSql(string sql, Dictionary<string, string> parameters)
235 {
236 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
237 {
238 dbcon.Open();
239
240 MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand();
241 cmd.CommandText = sql;
242 foreach (KeyValuePair<string, string> param in parameters)
243 {
244 cmd.Parameters.AddWithValue(param.Key, param.Value);
245 }
246 cmd.ExecuteNonQuery();
247 }
248 }
249
250 /// <summary>
251 /// Given a list of tables, return the version of the tables, as seen in the database
252 /// </summary>
253 /// <param name="tableList"></param>
254 public void GetTableVersion(Dictionary<string, string> tableList)
255 {
256 lock (m_dbLock)
257 {
258 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
259 {
260 dbcon.Open();
261
262 using (MySqlCommand tablesCmd = new MySqlCommand(
263 "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?dbname", dbcon))
264 {
265 tablesCmd.Parameters.AddWithValue("?dbname", dbcon.Database);
266
267 using (MySqlDataReader tables = tablesCmd.ExecuteReader())
268 {
269 while (tables.Read())
270 {
271 try
272 {
273 string tableName = (string)tables["TABLE_NAME"];
274 string comment = (string)tables["TABLE_COMMENT"];
275 if (tableList.ContainsKey(tableName))
276 {
277 tableList[tableName] = comment;
278 }
279 }
280 catch (Exception e)
281 {
282 m_log.Error(e.Message, e);
283 }
284 }
285 }
286 }
287 }
288 }
289 }
290
291 // TODO: at some time this code should be cleaned up
292
293 /// <summary>
294 /// Runs a query with protection against SQL Injection by using parameterised input.
295 /// </summary>
296 /// <param name="dbcon">Database connection</param>
297 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
298 /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
299 /// <returns>A MySQL DB Command</returns>
300 public IDbCommand Query(MySqlConnection dbcon, string sql, Dictionary<string, object> parameters)
301 {
302 try
303 {
304 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
305 dbcommand.CommandText = sql;
306 foreach (KeyValuePair<string, object> param in parameters)
307 {
308 dbcommand.Parameters.AddWithValue(param.Key, param.Value);
309 }
310
311 return (IDbCommand)dbcommand;
312 }
313 catch (Exception e)
314 {
315 // Return null if it fails.
316 m_log.Error("Failed during Query generation: " + e.Message, e);
317 return null;
318 }
319 }
320
321 /// <summary>
322 /// Reads a region row from a database reader
323 /// </summary>
324 /// <param name="reader">An active database reader</param>
325 /// <returns>A region profile</returns>
326 public RegionProfileData readSimRow(IDataReader reader)
327 {
328 RegionProfileData retval = new RegionProfileData();
329
330 if (reader.Read())
331 {
332 // Region Main gotta-have-or-we-return-null parts
333 UInt64 tmp64;
334 if (!UInt64.TryParse(reader["regionHandle"].ToString(), out tmp64))
335 {
336 return null;
337 }
338 else
339 {
340 retval.regionHandle = tmp64;
341 }
342 UUID tmp_uuid;
343 if (!UUID.TryParse((string)reader["uuid"], out tmp_uuid))
344 {
345 return null;
346 }
347 else
348 {
349 retval.UUID = tmp_uuid;
350 }
351
352 // non-critical parts
353 retval.regionName = (string)reader["regionName"];
354 retval.originUUID = new UUID((string) reader["originUUID"]);
355
356 // Secrets
357 retval.regionRecvKey = (string) reader["regionRecvKey"];
358 retval.regionSecret = (string) reader["regionSecret"];
359 retval.regionSendKey = (string) reader["regionSendKey"];
360
361 // Region Server
362 retval.regionDataURI = (string) reader["regionDataURI"];
363 retval.regionOnline = false; // Needs to be pinged before this can be set.
364 retval.serverIP = (string) reader["serverIP"];
365 retval.serverPort = (uint) reader["serverPort"];
366 retval.serverURI = (string) reader["serverURI"];
367 retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString());
368 retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString());
369
370 // Location
371 retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
372 retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
373 retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
374
375 // Neighbours - 0 = No Override
376 retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
377 retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
378 retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
379 retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
380
381 // Assets
382 retval.regionAssetURI = (string) reader["regionAssetURI"];
383 retval.regionAssetRecvKey = (string) reader["regionAssetRecvKey"];
384 retval.regionAssetSendKey = (string) reader["regionAssetSendKey"];
385
386 // Userserver
387 retval.regionUserURI = (string) reader["regionUserURI"];
388 retval.regionUserRecvKey = (string) reader["regionUserRecvKey"];
389 retval.regionUserSendKey = (string) reader["regionUserSendKey"];
390
391 // World Map Addition
392 UUID.TryParse((string)reader["regionMapTexture"], out retval.regionMapTextureID);
393 UUID.TryParse((string)reader["owner_uuid"], out retval.owner_uuid);
394 retval.maturity = Convert.ToUInt32(reader["access"]);
395 }
396 else
397 {
398 return null;
399 }
400 return retval;
401 }
402
403 /// <summary>
404 /// Reads a reservation row from a database reader
405 /// </summary>
406 /// <param name="reader">An active database reader</param>
407 /// <returns>A reservation data object</returns>
408 public ReservationData readReservationRow(IDataReader reader)
409 {
410 ReservationData retval = new ReservationData();
411 if (reader.Read())
412 {
413 retval.gridRecvKey = (string) reader["gridRecvKey"];
414 retval.gridSendKey = (string) reader["gridSendKey"];
415 retval.reservationCompany = (string) reader["resCompany"];
416 retval.reservationMaxX = Convert.ToInt32(reader["resXMax"].ToString());
417 retval.reservationMaxY = Convert.ToInt32(reader["resYMax"].ToString());
418 retval.reservationMinX = Convert.ToInt32(reader["resXMin"].ToString());
419 retval.reservationMinY = Convert.ToInt32(reader["resYMin"].ToString());
420 retval.reservationName = (string) reader["resName"];
421 retval.status = Convert.ToInt32(reader["status"].ToString()) == 1;
422 UUID tmp;
423 UUID.TryParse((string) reader["userUUID"], out tmp);
424 retval.userUUID = tmp;
425 }
426 else
427 {
428 return null;
429 }
430 return retval;
431 }
432
433 /// <summary>
434 /// Reads an agent row from a database reader
435 /// </summary>
436 /// <param name="reader">An active database reader</param>
437 /// <returns>A user session agent</returns>
438 public UserAgentData readAgentRow(IDataReader reader)
439 {
440 UserAgentData retval = new UserAgentData();
441
442 if (reader.Read())
443 {
444 // Agent IDs
445 UUID tmp;
446 if (!UUID.TryParse((string)reader["UUID"], out tmp))
447 return null;
448 retval.ProfileID = tmp;
449
450 UUID.TryParse((string) reader["sessionID"], out tmp);
451 retval.SessionID = tmp;
452
453 UUID.TryParse((string)reader["secureSessionID"], out tmp);
454 retval.SecureSessionID = tmp;
455
456 // Agent Who?
457 retval.AgentIP = (string) reader["agentIP"];
458 retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString());
459 retval.AgentOnline = Convert.ToBoolean(Convert.ToInt16(reader["agentOnline"].ToString()));
460
461 // Login/Logout times (UNIX Epoch)
462 retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString());
463 retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
464
465 // Current position
466 retval.Region = new UUID((string)reader["currentRegion"]);
467 retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString());
468 Vector3 tmp_v;
469 Vector3.TryParse((string) reader["currentPos"], out tmp_v);
470 retval.Position = tmp_v;
471 Vector3.TryParse((string)reader["currentLookAt"], out tmp_v);
472 retval.LookAt = tmp_v;
473 }
474 else
475 {
476 return null;
477 }
478 return retval;
479 }
480
481 /// <summary>
482 /// Reads a user profile from an active data reader
483 /// </summary>
484 /// <param name="reader">An active database reader</param>
485 /// <returns>A user profile</returns>
486 public UserProfileData readUserRow(IDataReader reader)
487 {
488 UserProfileData retval = new UserProfileData();
489
490 if (reader.Read())
491 {
492 UUID id;
493 if (!UUID.TryParse((string)reader["UUID"], out id))
494 return null;
495
496 retval.ID = id;
497 retval.FirstName = (string) reader["username"];
498 retval.SurName = (string) reader["lastname"];
499 retval.Email = (reader.IsDBNull(reader.GetOrdinal("email"))) ? "" : (string) reader["email"];
500
501 retval.PasswordHash = (string) reader["passwordHash"];
502 retval.PasswordSalt = (string) reader["passwordSalt"];
503
504 retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
505 retval.HomeLocation = new Vector3(
506 Convert.ToSingle(reader["homeLocationX"].ToString()),
507 Convert.ToSingle(reader["homeLocationY"].ToString()),
508 Convert.ToSingle(reader["homeLocationZ"].ToString()));
509 retval.HomeLookAt = new Vector3(
510 Convert.ToSingle(reader["homeLookAtX"].ToString()),
511 Convert.ToSingle(reader["homeLookAtY"].ToString()),
512 Convert.ToSingle(reader["homeLookAtZ"].ToString()));
513
514 UUID regionID = UUID.Zero;
515 UUID.TryParse(reader["homeRegionID"].ToString(), out regionID); // it's ok if it doesn't work; just use UUID.Zero
516 retval.HomeRegionID = regionID;
517
518 retval.Created = Convert.ToInt32(reader["created"].ToString());
519 retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
520
521 retval.UserInventoryURI = (string) reader["userInventoryURI"];
522 retval.UserAssetURI = (string) reader["userAssetURI"];
523
524 retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
525 retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
526
527 if (reader.IsDBNull(reader.GetOrdinal("profileAboutText")))
528 retval.AboutText = "";
529 else
530 retval.AboutText = (string) reader["profileAboutText"];
531
532 if (reader.IsDBNull(reader.GetOrdinal("profileFirstText")))
533 retval.FirstLifeAboutText = "";
534 else
535 retval.FirstLifeAboutText = (string)reader["profileFirstText"];
536
537 if (reader.IsDBNull(reader.GetOrdinal("profileImage")))
538 retval.Image = UUID.Zero;
539 else {
540 UUID tmp;
541 UUID.TryParse((string)reader["profileImage"], out tmp);
542 retval.Image = tmp;
543 }
544
545 if (reader.IsDBNull(reader.GetOrdinal("profileFirstImage")))
546 retval.FirstLifeImage = UUID.Zero;
547 else {
548 UUID tmp;
549 UUID.TryParse((string)reader["profileFirstImage"], out tmp);
550 retval.FirstLifeImage = tmp;
551 }
552
553 if (reader.IsDBNull(reader.GetOrdinal("webLoginKey")))
554 {
555 retval.WebLoginKey = UUID.Zero;
556 }
557 else
558 {
559 UUID tmp;
560 UUID.TryParse((string)reader["webLoginKey"], out tmp);
561 retval.WebLoginKey = tmp;
562 }
563
564 retval.UserFlags = Convert.ToInt32(reader["userFlags"].ToString());
565 retval.GodLevel = Convert.ToInt32(reader["godLevel"].ToString());
566 if (reader.IsDBNull(reader.GetOrdinal("customType")))
567 retval.CustomType = "";
568 else
569 retval.CustomType = reader["customType"].ToString();
570
571 if (reader.IsDBNull(reader.GetOrdinal("partner")))
572 {
573 retval.Partner = UUID.Zero;
574 }
575 else
576 {
577 UUID tmp;
578 UUID.TryParse((string)reader["partner"], out tmp);
579 retval.Partner = tmp;
580 }
581 }
582 else
583 {
584 return null;
585 }
586 return retval;
587 }
588
589 /// <summary>
590 /// Reads an avatar appearence from an active data reader
591 /// </summary>
592 /// <param name="reader">An active database reader</param>
593 /// <returns>An avatar appearence</returns>
594 public AvatarAppearance readAppearanceRow(IDataReader reader)
595 {
596 AvatarAppearance appearance = null;
597 if (reader.Read())
598 {
599 appearance = new AvatarAppearance();
600 appearance.Owner = new UUID((string)reader["owner"]);
601 appearance.Serial = Convert.ToInt32(reader["serial"]);
602 appearance.VisualParams = (byte[])reader["visual_params"];
603 appearance.Texture = new Primitive.TextureEntry((byte[])reader["texture"], 0, ((byte[])reader["texture"]).Length);
604 appearance.AvatarHeight = (float)Convert.ToDouble(reader["avatar_height"]);
605 appearance.BodyItem = new UUID((string)reader["body_item"]);
606 appearance.BodyAsset = new UUID((string)reader["body_asset"]);
607 appearance.SkinItem = new UUID((string)reader["skin_item"]);
608 appearance.SkinAsset = new UUID((string)reader["skin_asset"]);
609 appearance.HairItem = new UUID((string)reader["hair_item"]);
610 appearance.HairAsset = new UUID((string)reader["hair_asset"]);
611 appearance.EyesItem = new UUID((string)reader["eyes_item"]);
612 appearance.EyesAsset = new UUID((string)reader["eyes_asset"]);
613 appearance.ShirtItem = new UUID((string)reader["shirt_item"]);
614 appearance.ShirtAsset = new UUID((string)reader["shirt_asset"]);
615 appearance.PantsItem = new UUID((string)reader["pants_item"]);
616 appearance.PantsAsset = new UUID((string)reader["pants_asset"]);
617 appearance.ShoesItem = new UUID((string)reader["shoes_item"]);
618 appearance.ShoesAsset = new UUID((string)reader["shoes_asset"]);
619 appearance.SocksItem = new UUID((string)reader["socks_item"]);
620 appearance.SocksAsset = new UUID((string)reader["socks_asset"]);
621 appearance.JacketItem = new UUID((string)reader["jacket_item"]);
622 appearance.JacketAsset = new UUID((string)reader["jacket_asset"]);
623 appearance.GlovesItem = new UUID((string)reader["gloves_item"]);
624 appearance.GlovesAsset = new UUID((string)reader["gloves_asset"]);
625 appearance.UnderShirtItem = new UUID((string)reader["undershirt_item"]);
626 appearance.UnderShirtAsset = new UUID((string)reader["undershirt_asset"]);
627 appearance.UnderPantsItem = new UUID((string)reader["underpants_item"]);
628 appearance.UnderPantsAsset = new UUID((string)reader["underpants_asset"]);
629 appearance.SkirtItem = new UUID((string)reader["skirt_item"]);
630 appearance.SkirtAsset = new UUID((string)reader["skirt_asset"]);
631 }
632 return appearance;
633 }
634
635 // Read attachment list from data reader
636 public Hashtable readAttachments(IDataReader r)
637 {
638 Hashtable ret = new Hashtable();
639
640 while (r.Read())
641 {
642 int attachpoint = Convert.ToInt32(r["attachpoint"]);
643 if (ret.ContainsKey(attachpoint))
644 continue;
645 Hashtable item = new Hashtable();
646 item.Add("item", r["item"].ToString());
647 item.Add("asset", r["asset"].ToString());
648
649 ret.Add(attachpoint, item);
650 }
651
652 return ret;
653 }
654
655 /// <summary>
656 /// Inserts a new row into the log database
657 /// </summary>
658 /// <param name="serverDaemon">The daemon which triggered this event</param>
659 /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param>
660 /// <param name="methodCall">The method call where the problem occured</param>
661 /// <param name="arguments">The arguments passed to the method</param>
662 /// <param name="priority">How critical is this?</param>
663 /// <param name="logMessage">Extra message info</param>
664 /// <returns>Saved successfully?</returns>
665 public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority,
666 string logMessage)
667 {
668 string sql = "INSERT INTO logs (`target`, `server`, `method`, `arguments`, `priority`, `message`) VALUES ";
669 sql += "(?target, ?server, ?method, ?arguments, ?priority, ?message)";
670
671 Dictionary<string, object> parameters = new Dictionary<string, object>();
672 parameters["?server"] = serverDaemon;
673 parameters["?target"] = target;
674 parameters["?method"] = methodCall;
675 parameters["?arguments"] = arguments;
676 parameters["?priority"] = priority.ToString();
677 parameters["?message"] = logMessage;
678
679 bool returnval = false;
680
681 try
682 {
683 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
684 {
685 dbcon.Open();
686
687 IDbCommand result = Query(dbcon, sql, parameters);
688
689 if (result.ExecuteNonQuery() == 1)
690 returnval = true;
691
692 result.Dispose();
693 }
694 }
695 catch (Exception e)
696 {
697 m_log.Error(e.ToString());
698 return false;
699 }
700
701 return returnval;
702 }
703
704 /// <summary>
705 /// Creates a new user and inserts it into the database
706 /// </summary>
707 /// <param name="uuid">User ID</param>
708 /// <param name="username">First part of the login</param>
709 /// <param name="lastname">Second part of the login</param>
710 /// <param name="passwordHash">A salted hash of the users password</param>
711 /// <param name="passwordSalt">The salt used for the password hash</param>
712 /// <param name="homeRegion">A regionHandle of the users home region</param>
713 /// <param name="homeRegionID"> The UUID of the user's home region</param>
714 /// <param name="homeLocX">Home region position vector</param>
715 /// <param name="homeLocY">Home region position vector</param>
716 /// <param name="homeLocZ">Home region position vector</param>
717 /// <param name="homeLookAtX">Home region 'look at' vector</param>
718 /// <param name="homeLookAtY">Home region 'look at' vector</param>
719 /// <param name="homeLookAtZ">Home region 'look at' vector</param>
720 /// <param name="created">Account created (unix timestamp)</param>
721 /// <param name="lastlogin">Last login (unix timestamp)</param>
722 /// <param name="inventoryURI">Users inventory URI</param>
723 /// <param name="assetURI">Users asset URI</param>
724 /// <param name="canDoMask">I can do mask</param>
725 /// <param name="wantDoMask">I want to do mask</param>
726 /// <param name="aboutText">Profile text</param>
727 /// <param name="firstText">Firstlife text</param>
728 /// <param name="profileImage">UUID for profile image</param>
729 /// <param name="firstImage">UUID for firstlife image</param>
730 /// <param name="webLoginKey">Ignored</param>
731 /// <returns>Success?</returns>
732 public bool insertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash,
733 string passwordSalt, UInt64 homeRegion, UUID homeRegionID, float homeLocX, float homeLocY, float homeLocZ,
734 float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
735 string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
736 string aboutText, string firstText,
737 UUID profileImage, UUID firstImage, UUID webLoginKey, int userFlags, int godLevel, string customType, UUID partner)
738 {
739 m_log.Debug("[MySQLManager]: Creating profile for \"" + username + " " + lastname + "\" (" + uuid + ")");
740 string sql =
741 "INSERT INTO users (`UUID`, `username`, `lastname`, `email`, `passwordHash`, `passwordSalt`, `homeRegion`, `homeRegionID`, ";
742 sql +=
743 "`homeLocationX`, `homeLocationY`, `homeLocationZ`, `homeLookAtX`, `homeLookAtY`, `homeLookAtZ`, `created`, ";
744 sql +=
745 "`lastLogin`, `userInventoryURI`, `userAssetURI`, `profileCanDoMask`, `profileWantDoMask`, `profileAboutText`, ";
746 sql += "`profileFirstText`, `profileImage`, `profileFirstImage`, `webLoginKey`, `userFlags`, `godLevel`, `customType`, `partner`) VALUES ";
747
748 sql += "(?UUID, ?username, ?lastname, ?email, ?passwordHash, ?passwordSalt, ?homeRegion, ?homeRegionID, ";
749 sql +=
750 "?homeLocationX, ?homeLocationY, ?homeLocationZ, ?homeLookAtX, ?homeLookAtY, ?homeLookAtZ, ?created, ";
751 sql +=
752 "?lastLogin, ?userInventoryURI, ?userAssetURI, ?profileCanDoMask, ?profileWantDoMask, ?profileAboutText, ";
753 sql += "?profileFirstText, ?profileImage, ?profileFirstImage, ?webLoginKey, ?userFlags, ?godLevel, ?customType, ?partner)";
754
755 Dictionary<string, object> parameters = new Dictionary<string, object>();
756 parameters["?UUID"] = uuid.ToString();
757 parameters["?username"] = username;
758 parameters["?lastname"] = lastname;
759 parameters["?email"] = email;
760 parameters["?passwordHash"] = passwordHash;
761 parameters["?passwordSalt"] = passwordSalt;
762 parameters["?homeRegion"] = homeRegion;
763 parameters["?homeRegionID"] = homeRegionID.ToString();
764 parameters["?homeLocationX"] = homeLocX;
765 parameters["?homeLocationY"] = homeLocY;
766 parameters["?homeLocationZ"] = homeLocZ;
767 parameters["?homeLookAtX"] = homeLookAtX;
768 parameters["?homeLookAtY"] = homeLookAtY;
769 parameters["?homeLookAtZ"] = homeLookAtZ;
770 parameters["?created"] = created;
771 parameters["?lastLogin"] = lastlogin;
772 parameters["?userInventoryURI"] = inventoryURI;
773 parameters["?userAssetURI"] = assetURI;
774 parameters["?profileCanDoMask"] = canDoMask;
775 parameters["?profileWantDoMask"] = wantDoMask;
776 parameters["?profileAboutText"] = aboutText;
777 parameters["?profileFirstText"] = firstText;
778 parameters["?profileImage"] = profileImage.ToString();
779 parameters["?profileFirstImage"] = firstImage.ToString();
780 parameters["?webLoginKey"] = webLoginKey.ToString();
781 parameters["?userFlags"] = userFlags;
782 parameters["?godLevel"] = godLevel;
783 parameters["?customType"] = customType == null ? "" : customType;
784 parameters["?partner"] = partner.ToString();
785 bool returnval = false;
786
787 try
788 {
789 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
790 {
791 dbcon.Open();
792
793 IDbCommand result = Query(dbcon, sql, parameters);
794
795 if (result.ExecuteNonQuery() == 1)
796 returnval = true;
797
798 result.Dispose();
799 }
800 }
801 catch (Exception e)
802 {
803 m_log.Error(e.ToString());
804 return false;
805 }
806
807 //m_log.Debug("[MySQLManager]: Fetch user retval == " + returnval.ToString());
808 return returnval;
809 }
810
811 /// <summary>
812 /// Update user data into the database where User ID = uuid
813 /// </summary>
814 /// <param name="uuid">User ID</param>
815 /// <param name="username">First part of the login</param>
816 /// <param name="lastname">Second part of the login</param>
817 /// <param name="passwordHash">A salted hash of the users password</param>
818 /// <param name="passwordSalt">The salt used for the password hash</param>
819 /// <param name="homeRegion">A regionHandle of the users home region</param>
820 /// <param name="homeLocX">Home region position vector</param>
821 /// <param name="homeLocY">Home region position vector</param>
822 /// <param name="homeLocZ">Home region position vector</param>
823 /// <param name="homeLookAtX">Home region 'look at' vector</param>
824 /// <param name="homeLookAtY">Home region 'look at' vector</param>
825 /// <param name="homeLookAtZ">Home region 'look at' vector</param>
826 /// <param name="created">Account created (unix timestamp)</param>
827 /// <param name="lastlogin">Last login (unix timestamp)</param>
828 /// <param name="inventoryURI">Users inventory URI</param>
829 /// <param name="assetURI">Users asset URI</param>
830 /// <param name="canDoMask">I can do mask</param>
831 /// <param name="wantDoMask">I want to do mask</param>
832 /// <param name="aboutText">Profile text</param>
833 /// <param name="firstText">Firstlife text</param>
834 /// <param name="profileImage">UUID for profile image</param>
835 /// <param name="firstImage">UUID for firstlife image</param>
836 /// <param name="webLoginKey">UUID for weblogin Key</param>
837 /// <returns>Success?</returns>
838 public bool updateUserRow(UUID uuid, string username, string lastname, string email, string passwordHash,
839 string passwordSalt, UInt64 homeRegion, UUID homeRegionID, float homeLocX, float homeLocY, float homeLocZ,
840 float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
841 string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
842 string aboutText, string firstText,
843 UUID profileImage, UUID firstImage, UUID webLoginKey, int userFlags, int godLevel, string customType, UUID partner)
844 {
845 string sql = "UPDATE users SET `username` = ?username , `lastname` = ?lastname, `email` = ?email ";
846 sql += ", `passwordHash` = ?passwordHash , `passwordSalt` = ?passwordSalt , ";
847 sql += "`homeRegion` = ?homeRegion , `homeRegionID` = ?homeRegionID, `homeLocationX` = ?homeLocationX , ";
848 sql += "`homeLocationY` = ?homeLocationY , `homeLocationZ` = ?homeLocationZ , ";
849 sql += "`homeLookAtX` = ?homeLookAtX , `homeLookAtY` = ?homeLookAtY , ";
850 sql += "`homeLookAtZ` = ?homeLookAtZ , `created` = ?created , `lastLogin` = ?lastLogin , ";
851 sql += "`userInventoryURI` = ?userInventoryURI , `userAssetURI` = ?userAssetURI , ";
852 sql += "`profileCanDoMask` = ?profileCanDoMask , `profileWantDoMask` = ?profileWantDoMask , ";
853 sql += "`profileAboutText` = ?profileAboutText , `profileFirstText` = ?profileFirstText, ";
854 sql += "`profileImage` = ?profileImage , `profileFirstImage` = ?profileFirstImage , ";
855 sql += "`userFlags` = ?userFlags , `godLevel` = ?godLevel , ";
856 sql += "`customType` = ?customType , `partner` = ?partner , ";
857 sql += "`webLoginKey` = ?webLoginKey WHERE UUID = ?UUID";
858
859 Dictionary<string, object> parameters = new Dictionary<string, object>();
860 parameters["?UUID"] = uuid.ToString();
861 parameters["?username"] = username;
862 parameters["?lastname"] = lastname;
863 parameters["?email"] = email;
864 parameters["?passwordHash"] = passwordHash;
865 parameters["?passwordSalt"] = passwordSalt;
866 parameters["?homeRegion"] = homeRegion;
867 parameters["?homeRegionID"] = homeRegionID.ToString();
868 parameters["?homeLocationX"] = homeLocX;
869 parameters["?homeLocationY"] = homeLocY;
870 parameters["?homeLocationZ"] = homeLocZ;
871 parameters["?homeLookAtX"] = homeLookAtX;
872 parameters["?homeLookAtY"] = homeLookAtY;
873 parameters["?homeLookAtZ"] = homeLookAtZ;
874 parameters["?created"] = created;
875 parameters["?lastLogin"] = lastlogin;
876 parameters["?userInventoryURI"] = inventoryURI;
877 parameters["?userAssetURI"] = assetURI;
878 parameters["?profileCanDoMask"] = canDoMask;
879 parameters["?profileWantDoMask"] = wantDoMask;
880 parameters["?profileAboutText"] = aboutText;
881 parameters["?profileFirstText"] = firstText;
882 parameters["?profileImage"] = profileImage.ToString();
883 parameters["?profileFirstImage"] = firstImage.ToString();
884 parameters["?webLoginKey"] = webLoginKey.ToString();
885 parameters["?userFlags"] = userFlags;
886 parameters["?godLevel"] = godLevel;
887 parameters["?customType"] = customType == null ? "" : customType;
888 parameters["?partner"] = partner.ToString();
889
890 bool returnval = false;
891 try
892 {
893 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
894 {
895 dbcon.Open();
896
897 IDbCommand result = Query(dbcon, sql, parameters);
898
899 if (result.ExecuteNonQuery() == 1)
900 returnval = true;
901
902 result.Dispose();
903 }
904 }
905 catch (Exception e)
906 {
907 m_log.Error(e.ToString());
908 return false;
909 }
910
911 //m_log.Debug("[MySQLManager]: update user retval == " + returnval.ToString());
912 return returnval;
913 }
914
915 /// <summary>
916 /// Inserts a new region into the database
917 /// </summary>
918 /// <param name="regiondata">The region to insert</param>
919 /// <returns>Success?</returns>
920 public bool insertRegion(RegionProfileData regiondata)
921 {
922 bool GRID_ONLY_UPDATE_NECESSARY_DATA = false;
923
924 string sql = String.Empty;
925 if (GRID_ONLY_UPDATE_NECESSARY_DATA)
926 {
927 sql += "INSERT INTO ";
928 }
929 else
930 {
931 sql += "REPLACE INTO ";
932 }
933
934 sql += "regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
935 sql +=
936 "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
937
938 // part of an initial brutish effort to provide accurate information (as per the xml region spec)
939 // wrt the ownership of a given region
940 // the (very bad) assumption is that this value is being read and handled inconsistently or
941 // not at all. Current strategy is to put the code in place to support the validity of this information
942 // and to roll forward debugging any issues from that point
943 //
944 // this particular section of the mod attempts to implement the commit of a supplied value
945 // server for the UUID of the region's owner (master avatar). It consists of the addition of the column and value to the relevant sql,
946 // as well as the related parameterization
947 sql +=
948 "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture, serverHttpPort, serverRemotingPort, owner_uuid, originUUID, access) VALUES ";
949
950 sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
951 sql +=
952 "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
953 sql +=
954 "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture, ?serverHttpPort, ?serverRemotingPort, ?owner_uuid, ?originUUID, ?access)";
955
956 if (GRID_ONLY_UPDATE_NECESSARY_DATA)
957 {
958 sql += "ON DUPLICATE KEY UPDATE serverIP = ?serverIP, serverPort = ?serverPort, serverURI = ?serverURI, owner_uuid - ?owner_uuid;";
959 }
960 else
961 {
962 sql += ";";
963 }
964
965 Dictionary<string, object> parameters = new Dictionary<string, object>();
966
967 parameters["?regionHandle"] = regiondata.regionHandle.ToString();
968 parameters["?regionName"] = regiondata.regionName.ToString();
969 parameters["?uuid"] = regiondata.UUID.ToString();
970 parameters["?regionRecvKey"] = regiondata.regionRecvKey.ToString();
971 parameters["?regionSecret"] = regiondata.regionSecret.ToString();
972 parameters["?regionSendKey"] = regiondata.regionSendKey.ToString();
973 parameters["?regionDataURI"] = regiondata.regionDataURI.ToString();
974 parameters["?serverIP"] = regiondata.serverIP.ToString();
975 parameters["?serverPort"] = regiondata.serverPort.ToString();
976 parameters["?serverURI"] = regiondata.serverURI.ToString();
977 parameters["?locX"] = regiondata.regionLocX.ToString();
978 parameters["?locY"] = regiondata.regionLocY.ToString();
979 parameters["?locZ"] = regiondata.regionLocZ.ToString();
980 parameters["?eastOverrideHandle"] = regiondata.regionEastOverrideHandle.ToString();
981 parameters["?westOverrideHandle"] = regiondata.regionWestOverrideHandle.ToString();
982 parameters["?northOverrideHandle"] = regiondata.regionNorthOverrideHandle.ToString();
983 parameters["?southOverrideHandle"] = regiondata.regionSouthOverrideHandle.ToString();
984 parameters["?regionAssetURI"] = regiondata.regionAssetURI.ToString();
985 parameters["?regionAssetRecvKey"] = regiondata.regionAssetRecvKey.ToString();
986 parameters["?regionAssetSendKey"] = regiondata.regionAssetSendKey.ToString();
987 parameters["?regionUserURI"] = regiondata.regionUserURI.ToString();
988 parameters["?regionUserRecvKey"] = regiondata.regionUserRecvKey.ToString();
989 parameters["?regionUserSendKey"] = regiondata.regionUserSendKey.ToString();
990 parameters["?regionMapTexture"] = regiondata.regionMapTextureID.ToString();
991 parameters["?serverHttpPort"] = regiondata.httpPort.ToString();
992 parameters["?serverRemotingPort"] = regiondata.remotingPort.ToString();
993 parameters["?owner_uuid"] = regiondata.owner_uuid.ToString();
994 parameters["?originUUID"] = regiondata.originUUID.ToString();
995 parameters["?access"] = regiondata.maturity.ToString();
996
997 bool returnval = false;
998
999 try
1000 {
1001 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
1002 {
1003 dbcon.Open();
1004
1005 IDbCommand result = Query(dbcon, sql, parameters);
1006
1007 // int x;
1008 // if ((x = result.ExecuteNonQuery()) > 0)
1009 // {
1010 // returnval = true;
1011 // }
1012 if (result.ExecuteNonQuery() > 0)
1013 {
1014 returnval = true;
1015 }
1016 result.Dispose();
1017 }
1018 }
1019 catch (Exception e)
1020 {
1021 m_log.Error(e.ToString());
1022 return false;
1023 }
1024
1025 return returnval;
1026 }
1027
1028 /// <summary>
1029 /// Delete a region from the database
1030 /// </summary>
1031 /// <param name="uuid">The region to delete</param>
1032 /// <returns>Success?</returns>
1033 //public bool deleteRegion(RegionProfileData regiondata)
1034 public bool deleteRegion(string uuid)
1035 {
1036 bool returnval = false;
1037
1038 string sql = "DELETE FROM regions WHERE uuid = ?uuid;";
1039
1040 Dictionary<string, object> parameters = new Dictionary<string, object>();
1041
1042 try
1043 {
1044 parameters["?uuid"] = uuid;
1045
1046 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
1047 {
1048 dbcon.Open();
1049
1050 IDbCommand result = Query(dbcon, sql, parameters);
1051
1052 // int x;
1053 // if ((x = result.ExecuteNonQuery()) > 0)
1054 // {
1055 // returnval = true;
1056 // }
1057 if (result.ExecuteNonQuery() > 0)
1058 {
1059 returnval = true;
1060 }
1061 result.Dispose();
1062 }
1063 }
1064 catch (Exception e)
1065 {
1066 m_log.Error(e.ToString());
1067 return false;
1068 }
1069
1070 return returnval;
1071 }
1072
1073 /// <summary>
1074 /// Creates a new agent and inserts it into the database
1075 /// </summary>
1076 /// <param name="agentdata">The agent data to be inserted</param>
1077 /// <returns>Success?</returns>
1078 public bool insertAgentRow(UserAgentData agentdata)
1079 {
1080 string sql = String.Empty;
1081 sql += "REPLACE INTO ";
1082 sql += "agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos, currentLookAt) VALUES ";
1083 sql += "(?UUID, ?sessionID, ?secureSessionID, ?agentIP, ?agentPort, ?agentOnline, ?loginTime, ?logoutTime, ?currentRegion, ?currentHandle, ?currentPos, ?currentLookAt);";
1084 Dictionary<string, object> parameters = new Dictionary<string, object>();
1085
1086 parameters["?UUID"] = agentdata.ProfileID.ToString();
1087 parameters["?sessionID"] = agentdata.SessionID.ToString();
1088 parameters["?secureSessionID"] = agentdata.SecureSessionID.ToString();
1089 parameters["?agentIP"] = agentdata.AgentIP.ToString();
1090 parameters["?agentPort"] = agentdata.AgentPort.ToString();
1091 parameters["?agentOnline"] = (agentdata.AgentOnline == true) ? "1" : "0";
1092 parameters["?loginTime"] = agentdata.LoginTime.ToString();
1093 parameters["?logoutTime"] = agentdata.LogoutTime.ToString();
1094 parameters["?currentRegion"] = agentdata.Region.ToString();
1095 parameters["?currentHandle"] = agentdata.Handle.ToString();
1096 parameters["?currentPos"] = "<" + (agentdata.Position.X).ToString().Replace(",", ".") + "," + (agentdata.Position.Y).ToString().Replace(",", ".") + "," + (agentdata.Position.Z).ToString().Replace(",", ".") + ">";
1097 parameters["?currentLookAt"] = "<" + (agentdata.LookAt.X).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Y).ToString().Replace(",", ".") + "," + (agentdata.LookAt.Z).ToString().Replace(",", ".") + ">";
1098
1099 bool returnval = false;
1100
1101 try
1102 {
1103 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
1104 {
1105 dbcon.Open();
1106
1107 IDbCommand result = Query(dbcon, sql, parameters);
1108
1109 // int x;
1110 // if ((x = result.ExecuteNonQuery()) > 0)
1111 // {
1112 // returnval = true;
1113 // }
1114 if (result.ExecuteNonQuery() > 0)
1115 {
1116 returnval = true;
1117 }
1118 result.Dispose();
1119 }
1120 }
1121 catch (Exception e)
1122 {
1123 m_log.Error(e.ToString());
1124 return false;
1125 }
1126
1127 return returnval;
1128 }
1129
1130 /// <summary>
1131 /// Create (or replace if existing) an avatar appearence
1132 /// </summary>
1133 /// <param name="appearance"></param>
1134 /// <returns>Succes?</returns>
1135 public bool insertAppearanceRow(AvatarAppearance appearance)
1136 {
1137 string sql = String.Empty;
1138 sql += "REPLACE INTO ";
1139 sql += "avatarappearance (owner, serial, visual_params, texture, avatar_height, ";
1140 sql += "body_item, body_asset, skin_item, skin_asset, hair_item, hair_asset, eyes_item, eyes_asset, ";
1141 sql += "shirt_item, shirt_asset, pants_item, pants_asset, shoes_item, shoes_asset, socks_item, socks_asset, ";
1142 sql += "jacket_item, jacket_asset, gloves_item, gloves_asset, undershirt_item, undershirt_asset, underpants_item, underpants_asset, ";
1143 sql += "skirt_item, skirt_asset) values (";
1144 sql += "?owner, ?serial, ?visual_params, ?texture, ?avatar_height, ";
1145 sql += "?body_item, ?body_asset, ?skin_item, ?skin_asset, ?hair_item, ?hair_asset, ?eyes_item, ?eyes_asset, ";
1146 sql += "?shirt_item, ?shirt_asset, ?pants_item, ?pants_asset, ?shoes_item, ?shoes_asset, ?socks_item, ?socks_asset, ";
1147 sql += "?jacket_item, ?jacket_asset, ?gloves_item, ?gloves_asset, ?undershirt_item, ?undershirt_asset, ?underpants_item, ?underpants_asset, ";
1148 sql += "?skirt_item, ?skirt_asset)";
1149
1150 bool returnval = false;
1151
1152 // we want to send in byte data, which means we can't just pass down strings
1153 try
1154 {
1155 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
1156 {
1157 dbcon.Open();
1158
1159 using (MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand())
1160 {
1161 cmd.CommandText = sql;
1162 cmd.Parameters.AddWithValue("?owner", appearance.Owner.ToString());
1163 cmd.Parameters.AddWithValue("?serial", appearance.Serial);
1164 cmd.Parameters.AddWithValue("?visual_params", appearance.VisualParams);
1165 cmd.Parameters.AddWithValue("?texture", appearance.Texture.GetBytes());
1166 cmd.Parameters.AddWithValue("?avatar_height", appearance.AvatarHeight);
1167 cmd.Parameters.AddWithValue("?body_item", appearance.BodyItem.ToString());
1168 cmd.Parameters.AddWithValue("?body_asset", appearance.BodyAsset.ToString());
1169 cmd.Parameters.AddWithValue("?skin_item", appearance.SkinItem.ToString());
1170 cmd.Parameters.AddWithValue("?skin_asset", appearance.SkinAsset.ToString());
1171 cmd.Parameters.AddWithValue("?hair_item", appearance.HairItem.ToString());
1172 cmd.Parameters.AddWithValue("?hair_asset", appearance.HairAsset.ToString());
1173 cmd.Parameters.AddWithValue("?eyes_item", appearance.EyesItem.ToString());
1174 cmd.Parameters.AddWithValue("?eyes_asset", appearance.EyesAsset.ToString());
1175 cmd.Parameters.AddWithValue("?shirt_item", appearance.ShirtItem.ToString());
1176 cmd.Parameters.AddWithValue("?shirt_asset", appearance.ShirtAsset.ToString());
1177 cmd.Parameters.AddWithValue("?pants_item", appearance.PantsItem.ToString());
1178 cmd.Parameters.AddWithValue("?pants_asset", appearance.PantsAsset.ToString());
1179 cmd.Parameters.AddWithValue("?shoes_item", appearance.ShoesItem.ToString());
1180 cmd.Parameters.AddWithValue("?shoes_asset", appearance.ShoesAsset.ToString());
1181 cmd.Parameters.AddWithValue("?socks_item", appearance.SocksItem.ToString());
1182 cmd.Parameters.AddWithValue("?socks_asset", appearance.SocksAsset.ToString());
1183 cmd.Parameters.AddWithValue("?jacket_item", appearance.JacketItem.ToString());
1184 cmd.Parameters.AddWithValue("?jacket_asset", appearance.JacketAsset.ToString());
1185 cmd.Parameters.AddWithValue("?gloves_item", appearance.GlovesItem.ToString());
1186 cmd.Parameters.AddWithValue("?gloves_asset", appearance.GlovesAsset.ToString());
1187 cmd.Parameters.AddWithValue("?undershirt_item", appearance.UnderShirtItem.ToString());
1188 cmd.Parameters.AddWithValue("?undershirt_asset", appearance.UnderShirtAsset.ToString());
1189 cmd.Parameters.AddWithValue("?underpants_item", appearance.UnderPantsItem.ToString());
1190 cmd.Parameters.AddWithValue("?underpants_asset", appearance.UnderPantsAsset.ToString());
1191 cmd.Parameters.AddWithValue("?skirt_item", appearance.SkirtItem.ToString());
1192 cmd.Parameters.AddWithValue("?skirt_asset", appearance.SkirtAsset.ToString());
1193
1194 if (cmd.ExecuteNonQuery() > 0)
1195 returnval = true;
1196 }
1197 }
1198 }
1199 catch (Exception e)
1200 {
1201 m_log.Error(e.ToString());
1202 return false;
1203 }
1204
1205 return returnval;
1206
1207 }
1208
1209 public void writeAttachments(UUID agentID, Hashtable data)
1210 {
1211 string sql = "delete from avatarattachments where UUID = ?uuid";
1212
1213 using (MySqlConnection dbcon = new MySqlConnection(connectionString))
1214 {
1215 dbcon.Open();
1216
1217 MySqlCommand cmd = (MySqlCommand)dbcon.CreateCommand();
1218 cmd.CommandText = sql;
1219 cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
1220
1221 cmd.ExecuteNonQuery();
1222
1223 if (data == null)
1224 return;
1225
1226 sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attachpoint, ?item, ?asset)";
1227
1228 cmd = (MySqlCommand)dbcon.CreateCommand();
1229 cmd.CommandText = sql;
1230
1231 foreach (DictionaryEntry e in data)
1232 {
1233 int attachpoint = Convert.ToInt32(e.Key);
1234
1235 Hashtable item = (Hashtable)e.Value;
1236
1237 cmd.Parameters.Clear();
1238 cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
1239 cmd.Parameters.AddWithValue("?attachpoint", attachpoint);
1240 cmd.Parameters.AddWithValue("?item", item["item"]);
1241 cmd.Parameters.AddWithValue("?asset", item["asset"]);
1242
1243 cmd.ExecuteNonQuery();
1244 }
1245 }
1246 }
1247 }
1248}