aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorKitto Flora2010-01-07 23:04:28 -0500
committerKitto Flora2010-01-07 23:04:28 -0500
commit6591f8a5927a386d4c9a37ee093a700a4af90bdf (patch)
treefb4b9f5ca0fed4ce3b38ed8dcd0323f348e8fa35 /OpenSim
parentMerge branch 'master' of ssh://3dhosting.de/var/git/careminster (diff)
parentAllow estate managers (if estate_owner_is_god is set) to actually enter (diff)
downloadopensim-SC_OLD-6591f8a5927a386d4c9a37ee093a700a4af90bdf.zip
opensim-SC_OLD-6591f8a5927a386d4c9a37ee093a700a4af90bdf.tar.gz
opensim-SC_OLD-6591f8a5927a386d4c9a37ee093a700a4af90bdf.tar.bz2
opensim-SC_OLD-6591f8a5927a386d4c9a37ee093a700a4af90bdf.tar.xz
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/IXInventoryData.cs84
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs5
-rw-r--r--OpenSim/Data/MySQL/MySQLXInventoryData.cs156
-rw-r--r--OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs7
-rw-r--r--OpenSim/Services/Interfaces/IInventoryService.cs2
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs508
7 files changed, 766 insertions, 1 deletions
diff --git a/OpenSim/Data/IXInventoryData.cs b/OpenSim/Data/IXInventoryData.cs
new file mode 100644
index 0000000..cd9273e
--- /dev/null
+++ b/OpenSim/Data/IXInventoryData.cs
@@ -0,0 +1,84 @@
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.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32
33namespace OpenSim.Data
34{
35 public class XInventoryFolder
36 {
37 public string folderName;
38 public int type;
39 public int version;
40 public UUID folderID;
41 public UUID agentID;
42 public UUID parentFolderID;
43 }
44
45 public class XInventoryItem
46 {
47 public UUID assetID;
48 public int assetType;
49 public string inventoryName;
50 public string inventoryDescription;
51 public int inventoryNextPermissions;
52 public int inventoryCurrentPermissions;
53 public int invType;
54 public UUID creatorID;
55 public int inventoryBasePermissions;
56 public int inventoryEveryOnePermissions;
57 public int salePrice;
58 public int saleType;
59 public int creationDate;
60 public UUID groupID;
61 public bool groupOwned;
62 public int flags;
63 public UUID inventoryID;
64 public UUID avatarID;
65 public UUID parentFolderID;
66 public int inventoryGroupPermissions;
67 }
68
69 public interface IXInventoryData
70 {
71 XInventoryFolder[] GetFolders(string[] fields, string[] vals);
72 XInventoryItem[] GetItems(string[] fields, string[] vals);
73
74 bool StoreFolder(XInventoryFolder folder);
75 bool StoreItem(XInventoryItem item);
76
77 bool DeleteFolders(string field, string val);
78 bool DeleteItems(string field, string val);
79
80 bool MoveItem(string id, string newParent);
81 XInventoryItem[] GetActiveGestures(UUID principalID);
82 int GetAssetPermissions(UUID principalID, UUID assetID);
83 }
84}
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index b2bd5f6..fdb98eb 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -153,6 +153,11 @@ namespace OpenSim.Data.MySQL
153 UUID.TryParse(reader[name].ToString(), out uuid); 153 UUID.TryParse(reader[name].ToString(), out uuid);
154 m_Fields[name].SetValue(row, uuid); 154 m_Fields[name].SetValue(row, uuid);
155 } 155 }
156 else if (m_Fields[name].GetValue(row) is int)
157 {
158 int v = Convert.ToInt32(reader[name]);
159 m_Fields[name].SetValue(row, v);
160 }
156 else 161 else
157 { 162 {
158 m_Fields[name].SetValue(row, reader[name]); 163 m_Fields[name].SetValue(row, reader[name]);
diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
new file mode 100644
index 0000000..0eebc9c
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
@@ -0,0 +1,156 @@
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.Data;
30using System.Reflection;
31using System.Collections.Generic;
32using log4net;
33using MySql.Data.MySqlClient;
34using OpenMetaverse;
35using OpenSim.Framework;
36
37namespace OpenSim.Data.MySQL
38{
39 /// <summary>
40 /// A MySQL Interface for the Asset Server
41 /// </summary>
42 public class MySQLXInventoryData : IXInventoryData
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 private MySQLGenericTableHandler<XInventoryFolder> m_Folders;
48 private MySqlItemHandler m_Items;
49
50 public MySQLXInventoryData(string conn, string realm)
51 {
52 m_Folders = new MySQLGenericTableHandler<XInventoryFolder>(
53 conn, "inventoryfolders", "InventoryStore");
54 m_Items = new MySqlItemHandler(
55 conn, "inventoryitems", String.Empty);
56 }
57
58 public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
59 {
60 return m_Folders.Get(fields, vals);
61 }
62
63 public XInventoryItem[] GetItems(string[] fields, string[] vals)
64 {
65 return m_Items.Get(fields, vals);
66 }
67
68 public bool StoreFolder(XInventoryFolder folder)
69 {
70 return m_Folders.Store(folder);
71 }
72
73 public bool StoreItem(XInventoryItem item)
74 {
75 return m_Items.Store(item);
76 }
77
78 public bool DeleteFolders(string field, string val)
79 {
80 return m_Folders.Delete(field, val);
81 }
82
83 public bool DeleteItems(string field, string val)
84 {
85 return m_Items.Delete(field, val);
86 }
87
88 public bool MoveItem(string id, string newParent)
89 {
90 return m_Items.MoveItem(id, newParent);
91 }
92
93 public XInventoryItem[] GetActiveGestures(UUID principalID)
94 {
95 return m_Items.GetActiveGestures(principalID);
96 }
97
98 public int GetAssetPermissions(UUID principalID, UUID assetID)
99 {
100 return m_Items.GetAssetPermissions(principalID, assetID);
101 }
102 }
103
104 public class MySqlItemHandler : MySQLGenericTableHandler<XInventoryItem>
105 {
106 public MySqlItemHandler(string c, string t, string m) :
107 base(c, t, m)
108 {
109 }
110
111 public bool MoveItem(string id, string newParent)
112 {
113 MySqlCommand cmd = new MySqlCommand();
114
115 cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm);
116 cmd.Parameters.AddWithValue("?ParentFolderID", newParent);
117 cmd.Parameters.AddWithValue("?InventoryID", id);
118
119 return ExecuteNonQuery(cmd) == 0 ? false : true;
120 }
121
122 public XInventoryItem[] GetActiveGestures(UUID principalID)
123 {
124 MySqlCommand cmd = new MySqlCommand();
125 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = ?uuid and assetType = ?type and flags = 1", m_Realm);
126
127 cmd.Parameters.AddWithValue("?uuid", principalID.ToString());
128 cmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture);
129
130 return DoQuery(cmd);
131 }
132
133 public int GetAssetPermissions(UUID principalID, UUID assetID)
134 {
135 MySqlCommand cmd = new MySqlCommand();
136
137 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = ?PrincipalID and assetID = ?AssetID group by assetID", m_Realm);
138 cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
139 cmd.Parameters.AddWithValue("?AssetID", assetID.ToString());
140
141 IDataReader reader = ExecuteReader(cmd);
142
143 int perms = 0;
144
145 if (reader.Read())
146 {
147 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
148 }
149
150 reader.Close();
151 CloseReaderCommand(cmd);
152
153 return perms;
154 }
155 }
156}
diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
index e837e9a..f66f01f 100644
--- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
+++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs
@@ -596,7 +596,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions
596 return objectOwnerMask; 596 return objectOwnerMask;
597 597
598 // Estate users should be able to edit anything in the sim 598 // Estate users should be able to edit anything in the sim
599 if (IsEstateManager(user) && m_RegionOwnerIsGod && !IsAdministrator(objectOwner)) 599 if (IsEstateManager(user) && m_RegionOwnerIsGod && (!IsAdministrator(objectOwner)) || objectOwner == user)
600 return objectOwnerMask; 600 return objectOwnerMask;
601 601
602 // Admin should be able to edit anything in the sim (including admin objects) 602 // Admin should be able to edit anything in the sim (including admin objects)
@@ -888,6 +888,9 @@ namespace OpenSim.Region.CoreModules.World.Permissions
888 DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); 888 DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
889 if (m_bypassPermissions) return m_bypassPermissionsValue; 889 if (m_bypassPermissions) return m_bypassPermissionsValue;
890 890
891 if (IsEstateManager(user) && m_RegionOwnerIsGod)
892 return true;
893
891 return IsAdministrator(user); 894 return IsAdministrator(user);
892 } 895 }
893 896
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index bce7d32..18ec25f 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -2056,6 +2056,13 @@ namespace OpenSim.Region.Framework.Scenes
2056 group.Children.Count, remoteClient.AgentId, pos) 2056 group.Children.Count, remoteClient.AgentId, pos)
2057 && !attachment) 2057 && !attachment)
2058 { 2058 {
2059 // The client operates in no fail mode. It will
2060 // have already removed the item from the folder
2061 // if it's no copy.
2062 // Put it back if it's not an attachment
2063 //
2064 if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
2065 remoteClient.SendBulkUpdateInventory(item);
2059 return null; 2066 return null;
2060 } 2067 }
2061 2068
diff --git a/OpenSim/Services/Interfaces/IInventoryService.cs b/OpenSim/Services/Interfaces/IInventoryService.cs
index c775090..1b78fb3 100644
--- a/OpenSim/Services/Interfaces/IInventoryService.cs
+++ b/OpenSim/Services/Interfaces/IInventoryService.cs
@@ -59,6 +59,7 @@ namespace OpenSim.Services.Interfaces
59 /// </summary> 59 /// </summary>
60 /// <param name="userID"></param> 60 /// <param name="userID"></param>
61 /// <returns></returns> 61 /// <returns></returns>
62 [Obsolete]
62 InventoryCollection GetUserInventory(UUID userID); 63 InventoryCollection GetUserInventory(UUID userID);
63 64
64 /// <summary> 65 /// <summary>
@@ -67,6 +68,7 @@ namespace OpenSim.Services.Interfaces
67 /// </summary> 68 /// </summary>
68 /// <param name="userID"></param> 69 /// <param name="userID"></param>
69 /// <param name="callback"></param> 70 /// <param name="callback"></param>
71 [Obsolete]
70 void GetUserInventory(UUID userID, InventoryReceiptCallback callback); 72 void GetUserInventory(UUID userID, InventoryReceiptCallback callback);
71 73
72 /// <summary> 74 /// <summary>
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
new file mode 100644
index 0000000..2c79c77
--- /dev/null
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -0,0 +1,508 @@
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.Generic;
30using OpenMetaverse;
31using log4net;
32using Nini.Config;
33using System.Reflection;
34using OpenSim.Services.Base;
35using OpenSim.Services.Interfaces;
36using OpenSim.Data;
37using OpenSim.Framework;
38
39namespace OpenSim.Services.InventoryService
40{
41 public class XInventoryService : ServiceBase, IInventoryService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected IXInventoryData m_Database;
48
49 public XInventoryService(IConfigSource config) : base(config)
50 {
51 string dllName = String.Empty;
52 string connString = String.Empty;
53 //string realm = "Inventory"; // OSG version doesn't use this
54
55 //
56 // Try reading the [InventoryService] section first, if it exists
57 //
58 IConfig authConfig = config.Configs["InventoryService"];
59 if (authConfig != null)
60 {
61 dllName = authConfig.GetString("StorageProvider", dllName);
62 connString = authConfig.GetString("ConnectionString", connString);
63 // realm = authConfig.GetString("Realm", realm);
64 }
65
66 //
67 // Try reading the [DatabaseService] section, if it exists
68 //
69 IConfig dbConfig = config.Configs["DatabaseService"];
70 if (dbConfig != null)
71 {
72 if (dllName == String.Empty)
73 dllName = dbConfig.GetString("StorageProvider", String.Empty);
74 if (connString == String.Empty)
75 connString = dbConfig.GetString("ConnectionString", String.Empty);
76 }
77
78 //
79 // We tried, but this doesn't exist. We can't proceed.
80 //
81 if (dllName == String.Empty)
82 throw new Exception("No StorageProvider configured");
83
84 m_Database = LoadPlugin<IXInventoryData>(dllName,
85 new Object[] {connString, String.Empty});
86 if (m_Database == null)
87 throw new Exception("Could not find a storage interface in the given module");
88 }
89
90 public bool CreateUserInventory(UUID principalID)
91 {
92 // This is braindeaad. We can't ever communicate that we fixed
93 // an existing inventory. Well, just return root folder status,
94 // but check sanity anyway.
95 //
96 bool result = false;
97
98 InventoryFolderBase rootFolder = GetRootFolder(principalID);
99
100 if (rootFolder == null)
101 {
102 rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Inventory"));
103 result = true;
104 }
105
106 XInventoryFolder[] sysFolders = GetSystemFolders(principalID);
107
108 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
109 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations");
110 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
111 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Bodypart, "Body Parts");
112 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
113 CreateFolder(principalID, rootFolder.ID, (int)AssetType.CallingCard, "Calling Cards");
114 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
115 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Clothing, "Clothing");
116 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
117 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Gesture, "Gestures");
118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Landmark, "Landmarks");
120 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
121 CreateFolder(principalID, rootFolder.ID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
122 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
123 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Notecard, "Notecards");
124 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
125 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Object, "Objects");
126 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
127 CreateFolder(principalID, rootFolder.ID, (int)AssetType.SnapshotFolder, "Photo Album");
128 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
129 CreateFolder(principalID, rootFolder.ID, (int)AssetType.LSLText, "Scripts");
130 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
131 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Sound, "Sounds");
132 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
133 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Texture, "Textures");
134 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
135 CreateFolder(principalID, rootFolder.ID, (int)AssetType.TrashFolder, "Trash");
136
137 return result;
138 }
139
140 private XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name)
141 {
142 XInventoryFolder newFolder = new XInventoryFolder();
143
144 newFolder.folderName = name;
145 newFolder.type = type;
146 newFolder.version = 1;
147 newFolder.folderID = UUID.Random();
148 newFolder.agentID = principalID;
149 newFolder.parentFolderID = parentID;
150
151 m_Database.StoreFolder(newFolder);
152
153 return newFolder;
154 }
155
156 private XInventoryFolder[] GetSystemFolders(UUID principalID)
157 {
158 XInventoryFolder[] allFolders = m_Database.GetFolders(
159 new string[] { "agentID" },
160 new string[] { principalID.ToString() });
161
162 XInventoryFolder[] sysFolders = Array.FindAll(
163 allFolders,
164 delegate (XInventoryFolder f)
165 {
166 if (f.type > 0)
167 return true;
168 return false;
169 });
170
171 return sysFolders;
172 }
173
174 public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
175 {
176 XInventoryFolder[] allFolders = m_Database.GetFolders(
177 new string[] { "agentID" },
178 new string[] { principalID.ToString() });
179
180 if (allFolders.Length == 0)
181 return null;
182
183 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
184
185 foreach (XInventoryFolder x in allFolders)
186 {
187 m_log.DebugFormat("[INVENTORY]: Adding folder {0} to skeleton", x.folderName);
188 folders.Add(ConvertToOpenSim(x));
189 }
190
191 return folders;
192 }
193
194 public InventoryFolderBase GetRootFolder(UUID principalID)
195 {
196 XInventoryFolder[] folders = m_Database.GetFolders(
197 new string[] { "agentID", "parentFolderID"},
198 new string[] { principalID.ToString(), UUID.Zero.ToString() });
199
200 if (folders.Length == 0)
201 return null;
202
203 return ConvertToOpenSim(folders[0]);
204 }
205
206 public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
207 {
208 XInventoryFolder[] folders = m_Database.GetFolders(
209 new string[] { "agentID", "type"},
210 new string[] { principalID.ToString(), ((int)type).ToString() });
211
212 if (folders.Length == 0)
213 return null;
214
215 return ConvertToOpenSim(folders[0]);
216 }
217
218 public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
219 {
220 // This method doesn't receive a valud principal id from the
221 // connector. So we disregard the principal and look
222 // by ID.
223 //
224 m_log.DebugFormat("[INVENTORY]: Fetch contents for folder {0}", folderID.ToString());
225 InventoryCollection inventory = new InventoryCollection();
226 inventory.UserID = principalID;
227 inventory.Folders = new List<InventoryFolderBase>();
228 inventory.Items = new List<InventoryItemBase>();
229
230 XInventoryFolder[] folders = m_Database.GetFolders(
231 new string[] { "parentFolderID"},
232 new string[] { folderID.ToString() });
233
234 foreach (XInventoryFolder x in folders)
235 {
236 m_log.DebugFormat("[INVENTORY]: Adding folder {0} to response", x.folderName);
237 inventory.Folders.Add(ConvertToOpenSim(x));
238 }
239
240 XInventoryItem[] items = m_Database.GetItems(
241 new string[] { "parentFolderID"},
242 new string[] { folderID.ToString() });
243
244 foreach (XInventoryItem i in items)
245 {
246 m_log.DebugFormat("[INVENTORY]: Adding item {0} to response", i.inventoryName);
247 inventory.Items.Add(ConvertToOpenSim(i));
248 }
249
250 return inventory;
251 }
252
253 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
254 {
255 // Since we probably don't get a valid principal here, either ...
256 //
257 List<InventoryItemBase> invItems = new List<InventoryItemBase>();
258
259 XInventoryItem[] items = m_Database.GetItems(
260 new string[] { "parentFolderID"},
261 new string[] { UUID.Zero.ToString() });
262
263 foreach (XInventoryItem i in items)
264 invItems.Add(ConvertToOpenSim(i));
265
266 return invItems;
267 }
268
269 public bool AddFolder(InventoryFolderBase folder)
270 {
271 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
272 return m_Database.StoreFolder(xFolder);
273 }
274
275 public bool UpdateFolder(InventoryFolderBase folder)
276 {
277 return AddFolder(folder);
278 }
279
280 public bool MoveFolder(InventoryFolderBase folder)
281 {
282 XInventoryFolder[] x = m_Database.GetFolders(
283 new string[] { "folderID" },
284 new string[] { folder.ID.ToString() });
285
286 if (x.Length == 0)
287 return false;
288
289 x[0].parentFolderID = folder.ParentID;
290
291 return m_Database.StoreFolder(x[0]);
292 }
293
294 // We don't check the principal's ID here
295 //
296 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
297 {
298 // Ignore principal ID, it's bogus at connector level
299 //
300 foreach (UUID id in folderIDs)
301 {
302 InventoryFolderBase f = new InventoryFolderBase();
303 f.ID = id;
304 PurgeFolder(f);
305 m_Database.DeleteFolders("folderID", id.ToString());
306 }
307
308 return true;
309 }
310
311 public bool PurgeFolder(InventoryFolderBase folder)
312 {
313 XInventoryFolder[] subFolders = m_Database.GetFolders(
314 new string[] { "parentFolderID" },
315 new string[] { folder.ID.ToString() });
316
317 foreach (XInventoryFolder x in subFolders)
318 {
319 PurgeFolder(ConvertToOpenSim(x));
320 m_Database.DeleteFolders("folderID", x.folderID.ToString());
321 }
322
323 m_Database.DeleteItems("parentFolderID", folder.ID.ToString());
324
325 return true;
326 }
327
328 public bool AddItem(InventoryItemBase item)
329 {
330 return m_Database.StoreItem(ConvertFromOpenSim(item));
331 }
332
333 public bool UpdateItem(InventoryItemBase item)
334 {
335 return m_Database.StoreItem(ConvertFromOpenSim(item));
336 }
337
338 public bool MoveItems(UUID principalID, List<InventoryItemBase> items)
339 {
340 // Principal is b0rked. *sigh*
341 //
342 foreach (InventoryItemBase i in items)
343 {
344 m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
345 }
346
347 return true;
348 }
349
350 public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
351 {
352 // Just use the ID... *facepalms*
353 //
354 foreach (UUID id in itemIDs)
355 m_Database.DeleteItems("inventoryID", id.ToString());
356
357 return true;
358 }
359
360 public InventoryItemBase GetItem(InventoryItemBase item)
361 {
362 XInventoryItem[] items = m_Database.GetItems(
363 new string[] { "inventoryID" },
364 new string[] { item.ID.ToString() });
365
366 if (items.Length == 0)
367 return null;
368
369 return ConvertToOpenSim(items[0]);
370 }
371
372 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
373 {
374 XInventoryFolder[] folders = m_Database.GetFolders(
375 new string[] { "folderID"},
376 new string[] { folder.ID.ToString() });
377
378 if (folders.Length == 0)
379 return null;
380
381 return ConvertToOpenSim(folders[0]);
382 }
383
384 public List<InventoryItemBase> GetActiveGestures(UUID principalID)
385 {
386 XInventoryItem[] items = m_Database.GetActiveGestures(principalID);
387
388 if (items.Length == 0)
389 return null;
390
391 List<InventoryItemBase> ret = new List<InventoryItemBase>();
392
393 foreach (XInventoryItem x in items)
394 ret.Add(ConvertToOpenSim(x));
395
396 return ret;
397 }
398
399 public int GetAssetPermissions(UUID principalID, UUID assetID)
400 {
401 return m_Database.GetAssetPermissions(principalID, assetID);
402 }
403
404 // CM never needed those. Left unimplemented.
405 // Obsolete in core
406 //
407 public InventoryCollection GetUserInventory(UUID userID)
408 {
409 return null;
410 }
411 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
412 {
413 }
414
415 // Unused.
416 //
417 public bool HasInventoryForUser(UUID userID)
418 {
419 return false;
420 }
421
422 // CM Helpers
423 //
424 private InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
425 {
426 InventoryFolderBase newFolder = new InventoryFolderBase();
427
428 newFolder.ParentID = folder.parentFolderID;
429 newFolder.Type = (short)folder.type;
430 newFolder.Version = (ushort)folder.version;
431 newFolder.Name = folder.folderName;
432 newFolder.Owner = folder.agentID;
433 newFolder.ID = folder.folderID;
434
435 return newFolder;
436 }
437
438 private XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
439 {
440 XInventoryFolder newFolder = new XInventoryFolder();
441
442 newFolder.parentFolderID = folder.ParentID;
443 newFolder.type = (int)folder.Type;
444 newFolder.version = (int)folder.Version;
445 newFolder.folderName = folder.Name;
446 newFolder.agentID = folder.Owner;
447 newFolder.folderID = folder.ID;
448
449 return newFolder;
450 }
451
452 private InventoryItemBase ConvertToOpenSim(XInventoryItem item)
453 {
454 InventoryItemBase newItem = new InventoryItemBase();
455
456 newItem.AssetID = item.assetID;
457 newItem.AssetType = item.assetType;
458 newItem.Name = item.inventoryName;
459 newItem.Owner = item.avatarID;
460 newItem.ID = item.inventoryID;
461 newItem.InvType = item.invType;
462 newItem.Folder = item.parentFolderID;
463 newItem.CreatorId = item.creatorID.ToString();
464 newItem.Description = item.inventoryDescription;
465 newItem.NextPermissions = (uint)item.inventoryNextPermissions;
466 newItem.CurrentPermissions = (uint)item.inventoryCurrentPermissions;
467 newItem.BasePermissions = (uint)item.inventoryBasePermissions;
468 newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions;
469 newItem.GroupPermissions = (uint)item.inventoryGroupPermissions;
470 newItem.GroupID = item.groupID;
471 newItem.GroupOwned = item.groupOwned;
472 newItem.SalePrice = item.salePrice;
473 newItem.SaleType = (byte)item.saleType;
474 newItem.Flags = (uint)item.flags;
475 newItem.CreationDate = item.creationDate;
476
477 return newItem;
478 }
479
480 private XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
481 {
482 XInventoryItem newItem = new XInventoryItem();
483
484 newItem.assetID = item.AssetID;
485 newItem.assetType = item.AssetType;
486 newItem.inventoryName = item.Name;
487 newItem.avatarID = item.Owner;
488 newItem.inventoryID = item.ID;
489 newItem.invType = item.InvType;
490 newItem.parentFolderID = item.Folder;
491 newItem.creatorID = item.CreatorIdAsUuid;
492 newItem.inventoryDescription = item.Description;
493 newItem.inventoryNextPermissions = (int)item.NextPermissions;
494 newItem.inventoryCurrentPermissions = (int)item.CurrentPermissions;
495 newItem.inventoryBasePermissions = (int)item.BasePermissions;
496 newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions;
497 newItem.inventoryGroupPermissions = (int)item.GroupPermissions;
498 newItem.groupID = item.GroupID;
499 newItem.groupOwned = item.GroupOwned;
500 newItem.salePrice = item.SalePrice;
501 newItem.saleType = (int)item.SaleType;
502 newItem.flags = (int)item.Flags;
503 newItem.creationDate = item.CreationDate;
504
505 return newItem;
506 }
507 }
508}