aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorMelanie Thielker2008-08-18 17:22:36 +0000
committerMelanie Thielker2008-08-18 17:22:36 +0000
commit05506cff499b999d6c01e0517e658293b4791317 (patch)
treec0990ac8347181cbec66bd4adc61c6af3b486b4d /OpenSim
parentMantis#1992. Thank you kindly, ChrisDown for a patch that: (diff)
downloadopensim-SC_OLD-05506cff499b999d6c01e0517e658293b4791317.zip
opensim-SC_OLD-05506cff499b999d6c01e0517e658293b4791317.tar.gz
opensim-SC_OLD-05506cff499b999d6c01e0517e658293b4791317.tar.bz2
opensim-SC_OLD-05506cff499b999d6c01e0517e658293b4791317.tar.xz
Avatar Attachment persistence!! Patch #9168 (Mantis #1171)
Plumbs in attachment persistence and adds the tables. Currently MySQL only, no user functionality yet.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/MySQL/MySQLManager.cs51
-rw-r--r--OpenSim/Data/MySQL/MySQLUserData.cs25
-rw-r--r--OpenSim/Data/MySQL/Resources/005_UserStore.sql5
-rw-r--r--OpenSim/Data/SQLite/Resources/005_UserStore.sql5
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs101
5 files changed, 187 insertions, 0 deletions
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs
index 6ad6609..3a62ec2 100644
--- a/OpenSim/Data/MySQL/MySQLManager.cs
+++ b/OpenSim/Data/MySQL/MySQLManager.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Collections;
30using System.Data; 31using System.Data;
31using System.IO; 32using System.IO;
32using System.Reflection; 33using System.Reflection;
@@ -660,6 +661,26 @@ namespace OpenSim.Data.MySQL
660 } 661 }
661 662
662 663
664 // Read attachment list from data reader
665 public Hashtable readAttachments(IDataReader r)
666 {
667 Hashtable ret = new Hashtable();
668
669 while(r.Read())
670 {
671 int attachpoint = Convert.ToInt32(r["attachpoint"]);
672 if(ret.ContainsKey(attachpoint))
673 continue;
674 Hashtable item = new Hashtable();
675 item.Add("item", r["item"].ToString());
676 item.Add("asset", r["asset"].ToString());
677
678 ret.Add(attachpoint, item);
679 }
680
681 return ret;
682 }
683
663 /// <summary> 684 /// <summary>
664 /// Inserts a new row into the log database 685 /// Inserts a new row into the log database
665 /// </summary> 686 /// </summary>
@@ -1176,5 +1197,35 @@ namespace OpenSim.Data.MySQL
1176 1197
1177 } 1198 }
1178 1199
1200 public void writeAttachments(LLUUID agentID, Hashtable data)
1201 {
1202 string sql = "delete from avatarattachments where UUID = ?uuid";
1203
1204 MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand();
1205 cmd.CommandText = sql;
1206 cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
1207
1208 cmd.ExecuteNonQuery();
1209
1210 sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attchpoint, ?item, ?asset)";
1211
1212 cmd = (MySqlCommand) dbcon.CreateCommand();
1213 cmd.CommandText = sql;
1214
1215 foreach(DictionaryEntry e in data)
1216 {
1217 int attachpoint = Convert.ToInt32(e.Key);
1218
1219 Hashtable item = (Hashtable)e.Value;
1220
1221 cmd.Parameters.Clear();
1222 cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
1223 cmd.Parameters.AddWithValue("?attachpoint", attachpoint);
1224 cmd.Parameters.AddWithValue("?item", item["item"]);
1225 cmd.Parameters.AddWithValue("?asset", item["asset"]);
1226
1227 cmd.ExecuteNonQuery();
1228 }
1229 }
1179 } 1230 }
1180} 1231}
diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs
index f77d947..627bc0c 100644
--- a/OpenSim/Data/MySQL/MySQLUserData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserData.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Data; 31using System.Data;
31using System.Reflection; 32using System.Reflection;
@@ -34,6 +35,7 @@ using libsecondlife;
34using log4net; 35using log4net;
35using OpenSim.Framework; 36using OpenSim.Framework;
36using OpenSim.Data.Base; 37using OpenSim.Data.Base;
38using MySql.Data.MySqlClient;
37 39
38namespace OpenSim.Data.MySQL 40namespace OpenSim.Data.MySQL
39{ 41{
@@ -737,6 +739,8 @@ namespace OpenSim.Data.MySQL
737 reader.Dispose(); 739 reader.Dispose();
738 result.Dispose(); 740 result.Dispose();
739 741
742 appearance.SetAttachments(GetUserAttachments(user));
743
740 return appearance; 744 return appearance;
741 } 745 }
742 } 746 }
@@ -762,6 +766,8 @@ namespace OpenSim.Data.MySQL
762 { 766 {
763 appearance.Owner = user; 767 appearance.Owner = user;
764 database.insertAppearanceRow(appearance); 768 database.insertAppearanceRow(appearance);
769
770 UpdateUserAttachments(user, appearance.GetAttachments());
765 } 771 }
766 } 772 }
767 catch (Exception e) 773 catch (Exception e)
@@ -818,5 +824,24 @@ namespace OpenSim.Data.MySQL
818 { 824 {
819 get {return "0.1";} 825 get {return "0.1";}
820 } 826 }
827
828 public Hashtable GetUserAttachments(LLUUID agentID)
829 {
830 MySqlCommand cmd = (MySqlCommand) (database.Connection.CreateCommand());
831 cmd.CommandText = "select attachpoint, item, asset from avatarattachments where UUID = ?uuid";
832 cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
833
834 IDataReader r = cmd.ExecuteReader();
835
836 return database.readAttachments(r);
837 }
838
839 public void UpdateUserAttachments(LLUUID agentID, Hashtable data)
840 {
841 if(data == null)
842 return;
843
844 database.writeAttachments(agentID, data);
845 }
821 } 846 }
822} 847}
diff --git a/OpenSim/Data/MySQL/Resources/005_UserStore.sql b/OpenSim/Data/MySQL/Resources/005_UserStore.sql
new file mode 100644
index 0000000..55896bc
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/005_UserStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL, `attachpoint` int(11) NOT NULL, `item` char(36) NOT NULL, `asset` char(36) NOT NULL) ENGINE=InnoDB;
4
5COMMIT;
diff --git a/OpenSim/Data/SQLite/Resources/005_UserStore.sql b/OpenSim/Data/SQLite/Resources/005_UserStore.sql
new file mode 100644
index 0000000..e45c09a
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/005_UserStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `attachpoint` int(11) NOT NULL DEFAULT 0, `item` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `asset` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000');
4
5COMMIT;
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 3133f83..1c086d5 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -361,6 +361,11 @@ namespace OpenSim.Framework
361 h["underpants_asset"] = UnderPantsAsset.ToString(); 361 h["underpants_asset"] = UnderPantsAsset.ToString();
362 h["skirt_item"] = SkirtItem.ToString(); 362 h["skirt_item"] = SkirtItem.ToString();
363 h["skirt_asset"] = SkirtAsset.ToString(); 363 h["skirt_asset"] = SkirtAsset.ToString();
364
365 Hashtable attachments = GetAttachments();
366 if(attachments != null)
367 h["attachments"] = attachments;
368
364 return h; 369 return h;
365 } 370 }
366 371
@@ -405,6 +410,12 @@ namespace OpenSim.Framework
405 UnderPantsAsset = new LLUUID((string)h["underpants_asset"]); 410 UnderPantsAsset = new LLUUID((string)h["underpants_asset"]);
406 SkirtItem = new LLUUID((string)h["skirt_item"]); 411 SkirtItem = new LLUUID((string)h["skirt_item"]);
407 SkirtAsset = new LLUUID((string)h["skirt_asset"]); 412 SkirtAsset = new LLUUID((string)h["skirt_asset"]);
413
414 if(h.ContainsKey("attachments"))
415 {
416 Hashtable attachments = (Hashtable) h["attachments"];
417 SetAttachments(attachments);
418 }
408 } 419 }
409 420
410 [SecurityPermission(SecurityAction.LinkDemand, 421 [SecurityPermission(SecurityAction.LinkDemand,
@@ -424,5 +435,95 @@ namespace OpenSim.Framework
424 info.AddValue("m_textureEntry", m_texture.ToBytes()); 435 info.AddValue("m_textureEntry", m_texture.ToBytes());
425 info.AddValue("m_avatarHeight", m_avatarHeight); 436 info.AddValue("m_avatarHeight", m_avatarHeight);
426 } 437 }
438
439 private Dictionary<int, LLUUID[]> m_attachments = new Dictionary<int, LLUUID[]>();
440
441 public void SetAttachments(Hashtable data)
442 {
443 m_attachments.Clear();
444
445 if(data == null)
446 return;
447
448 foreach (DictionaryEntry e in data)
449 {
450 int attachpoint = Convert.ToInt32(e.Key);
451
452 if (m_attachments.ContainsKey(attachpoint))
453 continue;
454
455 LLUUID item;
456 LLUUID asset;
457
458 Hashtable uuids = (Hashtable) e.Value;
459 LLUUID.TryParse(uuids["item"].ToString(), out item);
460 LLUUID.TryParse(uuids["asset"].ToString(), out asset);
461
462 LLUUID[] attachment = new LLUUID[2];
463 attachment[0] = item;
464 attachment[1] = asset;
465
466 m_attachments[attachpoint] = attachment;
467 }
468 }
469
470 public Hashtable GetAttachments()
471 {
472 if(m_attachments.Count == 0)
473 return null;
474
475 Hashtable ret = new Hashtable();
476
477 foreach (KeyValuePair<int, LLUUID[]> kvp in m_attachments)
478 {
479 int attachpoint = kvp.Key;
480 LLUUID[] uuids = kvp.Value;
481
482 Hashtable data = new Hashtable();
483 data["item"] = uuids[0].ToString();
484 data["asset"] = uuids[1].ToString();
485
486 ret[attachpoint] = data;
487 }
488
489 return ret;
490 }
491
492 public List<int> GetAttachedPoints()
493 {
494 return new List<int>(m_attachments.Keys);
495 }
496
497 public LLUUID GetAttachedItem(int attachpoint)
498 {
499 if (!m_attachments.ContainsKey(attachpoint))
500 return LLUUID.Zero;
501
502 return m_attachments[attachpoint][0];
503 }
504
505 public LLUUID GetAttachedAsset(int attachpoint)
506 {
507 if (!m_attachments.ContainsKey(attachpoint))
508 return LLUUID.Zero;
509
510 return m_attachments[attachpoint][1];
511 }
512
513 public void AddAttachment(int attachpoint, LLUUID item, LLUUID asset)
514 {
515 if (item == LLUUID.Zero || asset == LLUUID.Zero)
516 {
517 if (m_attachments.ContainsKey(attachpoint))
518 m_attachments.Remove(attachpoint);
519 return;
520 }
521
522 if (!m_attachments.ContainsKey(attachpoint))
523 m_attachments[attachpoint] = new LLUUID[2];
524
525 m_attachments[attachpoint][0] = item;
526 m_attachments[attachpoint][1] = asset;
527 }
427 } 528 }
428} 529}