aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-01-06 22:43:45 +0000
committerJustin Clarke Casey2008-01-06 22:43:45 +0000
commit35a63c64f601459805f2eba839ce19eccf9b8592 (patch)
tree18110faf257fdd8f4d53005930c619fb7f5c33bc /OpenSim/Region/Environment
parentFor CharlieO: new folders created for new asset set stuff. Mantis 313 (diff)
downloadopensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.zip
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.gz
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.bz2
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.xz
Factor out inventory related code in SceneObjectPart into separate class
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs244
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs206
2 files changed, 245 insertions, 205 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
new file mode 100644
index 0000000..aab2291
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -0,0 +1,244 @@
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 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
29using System;
30using System.Collections.Generic;
31using System.Xml.Serialization;
32
33using libsecondlife;
34
35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes.Scripting;
38
39namespace OpenSim.Region.Environment.Scenes
40{
41 public partial class SceneObjectPart : IScriptHost
42 {
43 private string m_inventoryFileName = "";
44
45 /// <summary>
46 /// The inventory folder for this prim
47 /// </summary>
48 private LLUUID m_folderID = LLUUID.Zero;
49
50 /// <summary>
51 /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
52 /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
53 /// </summary>
54 public LLUUID FolderID
55 {
56 get { return m_folderID; }
57 set { m_folderID = value; }
58 }
59
60 /// <summary>
61 /// Holds in memory prim inventory
62 /// </summary>
63 protected IDictionary<LLUUID, TaskInventoryItem> m_taskInventory
64 = new Dictionary<LLUUID, TaskInventoryItem>();
65
66 [XmlIgnore]
67 public IDictionary<LLUUID, TaskInventoryItem> TaskInventory
68 {
69 get { return m_taskInventory; }
70 }
71
72 /// <summary>
73 /// Serial count for inventory file , used to tell if inventory has changed
74 /// no need for this to be part of Database backup
75 /// </summary>
76 protected uint m_inventorySerial = 0;
77
78 public uint InventorySerial
79 {
80 get { return m_inventorySerial; }
81 }
82
83 /// <summary>
84 /// Add an item to this prim's inventory.
85 /// </summary>
86 /// <param name="item"></param>
87 public void AddInventoryItem(TaskInventoryItem item)
88 {
89 item.parent_id = m_folderID;
90 item.creation_date = 1000;
91 item.ParentPartID = UUID;
92 m_taskInventory.Add(item.item_id, item);
93 m_inventorySerial++;
94 }
95
96 /// <summary>
97 /// Add a whole collection of items to the prim's inventory at once. We assume that the items already
98 /// have all their fields correctly filled out.
99 /// </summary>
100 /// <param name="items"></param>
101 public void AddInventoryItems(ICollection<TaskInventoryItem> items)
102 {
103 foreach (TaskInventoryItem item in items)
104 {
105 m_taskInventory.Add(item.item_id, item);
106 }
107
108 m_inventorySerial++;
109 }
110
111 public int RemoveInventoryItem(IClientAPI remoteClient, uint localID, LLUUID itemID)
112 {
113 if (localID == LocalID)
114 {
115 if (m_taskInventory.ContainsKey(itemID))
116 {
117 string type = m_taskInventory[itemID].inv_type;
118 m_taskInventory.Remove(itemID);
119 m_inventorySerial++;
120 if (type == "lsl_text")
121 {
122 return 10;
123 }
124 else
125 {
126 return 0;
127 }
128 }
129 }
130 return -1;
131 }
132
133 /// <summary>
134 ///
135 /// </summary>
136 /// <param name="client"></param>
137 /// <param name="localID"></param>
138 public bool GetInventoryFileName(IClientAPI client, uint localID)
139 {
140 if (m_inventorySerial > 0)
141 {
142 client.SendTaskInventory(m_uuid, (short) m_inventorySerial,
143 Helpers.StringToField(m_inventoryFileName));
144 return true;
145 }
146 else
147 {
148 client.SendTaskInventory(m_uuid, 0, new byte[0]);
149 return false;
150 }
151 }
152
153 public void RequestInventoryFile(IXfer xferManager)
154 {
155 byte[] fileData = new byte[0];
156 InventoryStringBuilder invString = new InventoryStringBuilder(m_folderID, UUID);
157 foreach (TaskInventoryItem item in m_taskInventory.Values)
158 {
159 invString.AddItemStart();
160 invString.AddNameValueLine("item_id", item.item_id.ToString());
161 invString.AddNameValueLine("parent_id", item.parent_id.ToString());
162
163 invString.AddPermissionsStart();
164 invString.AddNameValueLine("base_mask", "0x7FFFFFFF");
165 invString.AddNameValueLine("owner_mask", "0x7FFFFFFF");
166 invString.AddNameValueLine("group_mask", "0x7FFFFFFF");
167 invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF");
168 invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF");
169 invString.AddNameValueLine("creator_id", item.creator_id.ToString());
170 invString.AddNameValueLine("owner_id", item.owner_id.ToString());
171 invString.AddNameValueLine("last_owner_id", item.last_owner_id.ToString());
172 invString.AddNameValueLine("group_id", item.group_id.ToString());
173 invString.AddSectionEnd();
174
175 invString.AddNameValueLine("asset_id", item.asset_id.ToString());
176 invString.AddNameValueLine("type", item.type);
177 invString.AddNameValueLine("inv_type", item.inv_type);
178 invString.AddNameValueLine("flags", "0x00");
179 invString.AddNameValueLine("name", item.name + "|");
180 invString.AddNameValueLine("desc", item.desc + "|");
181 invString.AddNameValueLine("creation_date", item.creation_date.ToString());
182 invString.AddSectionEnd();
183 }
184
185 fileData = Helpers.StringToField(invString.BuildString);
186
187// MainLog.Instance.Verbose(
188// "PRIMINVENTORY", "RequestInventoryFile fileData: {0}", Helpers.FieldToUTF8String(fileData));
189
190 if (fileData.Length > 2)
191 {
192 xferManager.AddNewFile(m_inventoryFileName, fileData);
193 }
194 }
195
196 public class InventoryStringBuilder
197 {
198 public string BuildString = "";
199
200 public InventoryStringBuilder(LLUUID folderID, LLUUID parentID)
201 {
202 BuildString += "\tinv_object\t0\n\t{\n";
203 AddNameValueLine("obj_id", folderID.ToString());
204 AddNameValueLine("parent_id", parentID.ToString());
205 AddNameValueLine("type", "category");
206 AddNameValueLine("name", "Contents");
207 AddSectionEnd();
208 }
209
210 public void AddItemStart()
211 {
212 BuildString += "\tinv_item\t0\n";
213 BuildString += "\t{\n";
214 }
215
216 public void AddPermissionsStart()
217 {
218 BuildString += "\tpermissions 0\n";
219 BuildString += "\t{\n";
220 }
221
222 public void AddSectionEnd()
223 {
224 BuildString += "\t}\n";
225 }
226
227 public void AddLine(string addLine)
228 {
229 BuildString += addLine;
230 }
231
232 public void AddNameValueLine(string name, string value)
233 {
234 BuildString += "\t\t";
235 BuildString += name + "\t";
236 BuildString += value + "\n";
237 }
238
239 public void Close()
240 {
241 }
242 }
243 }
244}
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index b07b43c..f82771b 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -42,7 +42,7 @@ using OpenSim.Region.Physics.Manager;
42 42
43namespace OpenSim.Region.Environment.Scenes 43namespace OpenSim.Region.Environment.Scenes
44{ 44{
45 public class SceneObjectPart : IScriptHost 45 public partial class SceneObjectPart : IScriptHost
46 { 46 {
47 private const LLObject.ObjectFlags OBJFULL_MASK_GENERAL = 47 private const LLObject.ObjectFlags OBJFULL_MASK_GENERAL =
48 LLObject.ObjectFlags.ObjectCopy | LLObject.ObjectFlags.ObjectModify | LLObject.ObjectFlags.ObjectTransfer; 48 LLObject.ObjectFlags.ObjectCopy | LLObject.ObjectFlags.ObjectModify | LLObject.ObjectFlags.ObjectTransfer;
@@ -55,36 +55,8 @@ namespace OpenSim.Region.Environment.Scenes
55 55
56 private const uint FULL_MASK_PERMISSIONS_GENERAL = 2147483647; 56 private const uint FULL_MASK_PERMISSIONS_GENERAL = 2147483647;
57 private const uint FULL_MASK_PERMISSIONS_OWNER = 2147483647; 57 private const uint FULL_MASK_PERMISSIONS_OWNER = 2147483647;
58 private string m_inventoryFileName = "";
59
60 /// <summary>
61 /// The inventory folder for this prim
62 /// </summary>
63 private LLUUID m_folderID = LLUUID.Zero;
64
65 /// <summary>
66 /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
67 /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
68 /// </summary>
69 public LLUUID FolderID
70 {
71 get { return m_folderID; }
72 set { m_folderID = value; }
73 }
74 58
75 [XmlIgnore] public PhysicsActor PhysActor = null; 59 [XmlIgnore] public PhysicsActor PhysActor = null;
76
77 /// <summary>
78 /// Holds in memory prim inventory
79 /// </summary>
80 protected IDictionary<LLUUID, TaskInventoryItem> m_taskInventory
81 = new Dictionary<LLUUID, TaskInventoryItem>();
82
83 [XmlIgnore]
84 public IDictionary<LLUUID, TaskInventoryItem> TaskInventory
85 {
86 get { return m_taskInventory; }
87 }
88 60
89 public LLUUID LastOwnerID; 61 public LLUUID LastOwnerID;
90 public LLUUID OwnerID; 62 public LLUUID OwnerID;
@@ -130,17 +102,6 @@ namespace OpenSim.Region.Environment.Scenes
130 get { return CreatorID; } 102 get { return CreatorID; }
131 } 103 }
132 104
133 /// <summary>
134 /// Serial count for inventory file , used to tell if inventory has changed
135 /// no need for this to be part of Database backup
136 /// </summary>
137 protected uint m_inventorySerial = 0;
138
139 public uint InventorySerial
140 {
141 get { return m_inventorySerial; }
142 }
143
144 protected LLUUID m_uuid; 105 protected LLUUID m_uuid;
145 106
146 public LLUUID UUID 107 public LLUUID UUID
@@ -1066,123 +1027,6 @@ namespace OpenSim.Region.Environment.Scenes
1066 1027
1067 #endregion 1028 #endregion
1068 1029
1069 #region Inventory
1070
1071 /// <summary>
1072 /// Add an item to this prim's inventory.
1073 /// </summary>
1074 /// <param name="item"></param>
1075 public void AddInventoryItem(TaskInventoryItem item)
1076 {
1077 item.parent_id = m_folderID;
1078 item.creation_date = 1000;
1079 item.ParentPartID = UUID;
1080 m_taskInventory.Add(item.item_id, item);
1081 m_inventorySerial++;
1082 }
1083
1084 /// <summary>
1085 /// Add a whole collection of items to the prim's inventory at once. We assume that the items already
1086 /// have all their fields correctly filled out.
1087 /// </summary>
1088 /// <param name="items"></param>
1089 public void AddInventoryItems(ICollection<TaskInventoryItem> items)
1090 {
1091 foreach (TaskInventoryItem item in items)
1092 {
1093 m_taskInventory.Add(item.item_id, item);
1094 }
1095
1096 m_inventorySerial++;
1097 }
1098
1099 public int RemoveInventoryItem(IClientAPI remoteClient, uint localID, LLUUID itemID)
1100 {
1101 if (localID == LocalID)
1102 {
1103 if (m_taskInventory.ContainsKey(itemID))
1104 {
1105 string type = m_taskInventory[itemID].inv_type;
1106 m_taskInventory.Remove(itemID);
1107 m_inventorySerial++;
1108 if (type == "lsl_text")
1109 {
1110 return 10;
1111 }
1112 else
1113 {
1114 return 0;
1115 }
1116 }
1117 }
1118 return -1;
1119 }
1120
1121 /// <summary>
1122 ///
1123 /// </summary>
1124 /// <param name="client"></param>
1125 /// <param name="localID"></param>
1126 public bool GetInventoryFileName(IClientAPI client, uint localID)
1127 {
1128 if (m_inventorySerial > 0)
1129 {
1130 client.SendTaskInventory(m_uuid, (short) m_inventorySerial,
1131 Helpers.StringToField(m_inventoryFileName));
1132 return true;
1133 }
1134 else
1135 {
1136 client.SendTaskInventory(m_uuid, 0, new byte[0]);
1137 return false;
1138 }
1139 }
1140
1141 public void RequestInventoryFile(IXfer xferManager)
1142 {
1143 byte[] fileData = new byte[0];
1144 InventoryStringBuilder invString = new InventoryStringBuilder(m_folderID, UUID);
1145 foreach (TaskInventoryItem item in m_taskInventory.Values)
1146 {
1147 invString.AddItemStart();
1148 invString.AddNameValueLine("item_id", item.item_id.ToString());
1149 invString.AddNameValueLine("parent_id", item.parent_id.ToString());
1150
1151 invString.AddPermissionsStart();
1152 invString.AddNameValueLine("base_mask", "0x7FFFFFFF");
1153 invString.AddNameValueLine("owner_mask", "0x7FFFFFFF");
1154 invString.AddNameValueLine("group_mask", "0x7FFFFFFF");
1155 invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF");
1156 invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF");
1157 invString.AddNameValueLine("creator_id", item.creator_id.ToString());
1158 invString.AddNameValueLine("owner_id", item.owner_id.ToString());
1159 invString.AddNameValueLine("last_owner_id", item.last_owner_id.ToString());
1160 invString.AddNameValueLine("group_id", item.group_id.ToString());
1161 invString.AddSectionEnd();
1162
1163 invString.AddNameValueLine("asset_id", item.asset_id.ToString());
1164 invString.AddNameValueLine("type", item.type);
1165 invString.AddNameValueLine("inv_type", item.inv_type);
1166 invString.AddNameValueLine("flags", "0x00");
1167 invString.AddNameValueLine("name", item.name + "|");
1168 invString.AddNameValueLine("desc", item.desc + "|");
1169 invString.AddNameValueLine("creation_date", item.creation_date.ToString());
1170 invString.AddSectionEnd();
1171 }
1172
1173 fileData = Helpers.StringToField(invString.BuildString);
1174
1175// MainLog.Instance.Verbose(
1176// "PRIMINVENTORY", "RequestInventoryFile fileData: {0}", Helpers.FieldToUTF8String(fileData));
1177
1178 if (fileData.Length > 2)
1179 {
1180 xferManager.AddNewFile(m_inventoryFileName, fileData);
1181 }
1182 }
1183
1184 #endregion
1185
1186 #region ExtraParams 1030 #region ExtraParams
1187 1031
1188 public void UpdatePrimFlags(ushort type, bool inUse, byte[] data) 1032 public void UpdatePrimFlags(ushort type, bool inUse, byte[] data)
@@ -1688,53 +1532,5 @@ namespace OpenSim.Region.Environment.Scenes
1688 (int) (color.z*0xff)); 1532 (int) (color.z*0xff));
1689 Text = text; 1533 Text = text;
1690 } 1534 }
1691
1692 public class InventoryStringBuilder
1693 {
1694 public string BuildString = "";
1695
1696 public InventoryStringBuilder(LLUUID folderID, LLUUID parentID)
1697 {
1698 BuildString += "\tinv_object\t0\n\t{\n";
1699 AddNameValueLine("obj_id", folderID.ToString());
1700 AddNameValueLine("parent_id", parentID.ToString());
1701 AddNameValueLine("type", "category");
1702 AddNameValueLine("name", "Contents");
1703 AddSectionEnd();
1704 }
1705
1706 public void AddItemStart()
1707 {
1708 BuildString += "\tinv_item\t0\n";
1709 BuildString += "\t{\n";
1710 }
1711
1712 public void AddPermissionsStart()
1713 {
1714 BuildString += "\tpermissions 0\n";
1715 BuildString += "\t{\n";
1716 }
1717
1718 public void AddSectionEnd()
1719 {
1720 BuildString += "\t}\n";
1721 }
1722
1723 public void AddLine(string addLine)
1724 {
1725 BuildString += addLine;
1726 }
1727
1728 public void AddNameValueLine(string name, string value)
1729 {
1730 BuildString += "\t\t";
1731 BuildString += name + "\t";
1732 BuildString += value + "\n";
1733 }
1734
1735 public void Close()
1736 {
1737 }
1738 }
1739 } 1535 }
1740} 1536}