1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Xml;
using System.Reflection;
using System.Text;
using System.Threading;
using OpenSim.Framework;
using OpenSim.Framework.Capabilities;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Serialization;
using OpenSim.Services.Interfaces;
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
using OpenMetaverse;
using log4net;
using Nini.Config;
using Mono.Addins;
using PermissionMask = OpenSim.Framework.PermissionMask;
namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BasicInventoryAccessModule")]
public class BasicInventoryAccessModule : INonSharedRegionModule, IInventoryAccessModule
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected bool m_Enabled = false;
protected Scene m_Scene;
protected IUserManagement m_UserManagement;
protected IUserManagement UserManagementModule
{
get
{
if (m_UserManagement == null)
m_UserManagement = m_Scene.RequestModuleInterface<IUserManagement>();
return m_UserManagement;
}
}
public bool CoalesceMultipleObjectsToInventory { get; set; }
#region INonSharedRegionModule
public Type ReplaceableInterface
{
get { return null; }
}
public virtual string Name
{
get { return "BasicInventoryAccessModule"; }
}
public virtual void Initialise(IConfigSource source)
{
IConfig moduleConfig = source.Configs["Modules"];
if (moduleConfig != null)
{
string name = moduleConfig.GetString("InventoryAccessModule", "");
if (name == Name)
{
m_Enabled = true;
InitialiseCommon(source);
m_log.InfoFormat("[INVENTORY ACCESS MODULE]: {0} enabled.", Name);
}
}
}
/// <summary>
/// Common module config for both this and descendant classes.
/// </summary>
/// <param name="source"></param>
protected virtual void InitialiseCommon(IConfigSource source)
{
IConfig inventoryConfig = source.Configs["Inventory"];
if (inventoryConfig != null)
CoalesceMultipleObjectsToInventory
= inventoryConfig.GetBoolean("CoalesceMultipleObjectsToInventory", true);
else
CoalesceMultipleObjectsToInventory = true;
}
public virtual void PostInitialise()
{
}
public virtual void AddRegion(Scene scene)
{
if (!m_Enabled)
return;
m_Scene = scene;
scene.RegisterModuleInterface<IInventoryAccessModule>(this);
scene.EventManager.OnNewClient += OnNewClient;
}
protected virtual void OnNewClient(IClientAPI client)
{
client.OnCreateNewInventoryItem += CreateNewInventoryItem;
}
public virtual void Close()
{
if (!m_Enabled)
return;
}
public virtual void RemoveRegion(Scene scene)
{
if (!m_Enabled)
return;
m_Scene = null;
}
public virtual void RegionLoaded(Scene scene)
{
if (!m_Enabled)
return;
}
#endregion
#region Inventory Access
/// <summary>
/// Create a new inventory item. Called when the client creates a new item directly within their
/// inventory (e.g. by selecting a context inventory menu option).
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="transactionID"></param>
/// <param name="folderID"></param>
/// <param name="callbackID"></param>
/// <param name="description"></param>
/// <param name="name"></param>
/// <param name="invType"></param>
/// <param name="type"></param>
/// <param name="wearableType"></param>
/// <param name="nextOwnerMask"></param>
public void CreateNewInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
uint callbackID, string description, string name, sbyte invType,
sbyte assetType, byte wearableType,
uint nextOwnerMask, int creationDate)
{
m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Received request to create inventory item {0} in folder {1}, transactionID {2}", name,
folderID, transactionID);
if (!m_Scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
return;
InventoryFolderBase folder = m_Scene.InventoryService.GetFolder(remoteClient.AgentId, folderID);
if (folder == null && Enum.IsDefined(typeof(FolderType), (sbyte)invType))
{
folder = m_Scene.InventoryService.GetFolderForType(remoteClient.AgentId, (FolderType)invType);
if (folder != null)
m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Requested folder not found but found folder for type {0}", invType);
}
if (folder == null || folder.Owner != remoteClient.AgentId)
return;
if (transactionID != UUID.Zero)
{
IAgentAssetTransactions agentTransactions = m_Scene.AgentTransactionsModule;
if (agentTransactions != null)
{
if (agentTransactions.HandleItemCreationFromTransaction(
remoteClient, transactionID, folderID, callbackID, description,
name, invType, assetType, wearableType, nextOwnerMask))
return;
}
}
ScenePresence presence;
if (m_Scene.TryGetScenePresence(remoteClient.AgentId, out presence))
{
byte[] data = null;
if (invType == (sbyte)InventoryType.Landmark && presence != null)
{
string suffix = string.Empty, prefix = string.Empty;
string strdata = GenerateLandmark(presence, out prefix, out suffix);
data = Encoding.ASCII.GetBytes(strdata);
name = prefix + name;
description += suffix;
}
AssetBase asset = m_Scene.CreateAsset(name, description, assetType, data, remoteClient.AgentId);
m_Scene.AssetService.Store(asset);
m_Scene.CreateNewInventoryItem(
remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID,
name, description, 0, callbackID, asset.FullID, asset.Type, invType,
(uint)PermissionMask.All | (uint)PermissionMask.Export, // Base
(uint)PermissionMask.All | (uint)PermissionMask.Export, // Current
0, nextOwnerMask, 0, creationDate, false); // Data from viewer
}
else
{
m_log.ErrorFormat(
"[INVENTORY ACCESS MODULE]: ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
remoteClient.AgentId);
}
}
protected virtual string GenerateLandmark(ScenePresence presence, out string prefix, out string suffix)
{
prefix = string.Empty;
suffix = string.Empty;
Vector3 pos = presence.AbsolutePosition;
return String.Format("Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
presence.Scene.RegionInfo.RegionID,
pos.X, pos.Y, pos.Z,
presence.RegionHandle);
}
/// <summary>
/// Capability originating call to update the asset of an item in an agent's inventory
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="itemID"></param>
/// <param name="data"></param>
/// <returns></returns>
public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
{
InventoryItemBase item = m_Scene.InventoryService.GetItem(remoteClient.AgentId, itemID);
if (item == null)
{
m_log.ErrorFormat(
"[INVENTORY ACCESS MODULE]: Could not find item {0} for caps inventory update", itemID);
return UUID.Zero;
}
if (item.Owner != remoteClient.AgentId)
return UUID.Zero;
if ((InventoryType)item.InvType == InventoryType.Notecard)
{
if (!m_Scene.Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId))
{
remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
return UUID.Zero;
}
remoteClient.SendAlertMessage("Notecard saved");
}
else if ((InventoryType)item.InvType == InventoryType.LSL)
{
if (!m_Scene.Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
{
remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
return UUID.Zero;
}
remoteClient.SendAlertMessage("Script saved");
}
else if ((CustomInventoryType)item.InvType == CustomInventoryType.AnimationSet)
{
AnimationSet animSet = new AnimationSet(data);
if (!animSet.Validate(x => {
int perms = m_Scene.InventoryService.GetAssetPermissions(remoteClient.AgentId, x);
int required = (int)(PermissionMask.Transfer | PermissionMask.Copy);
if ((perms & required) != required)
return false;
return true;
}))
{
data = animSet.ToBytes();
}
}
AssetBase asset =
CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data, remoteClient.AgentId.ToString());
item.AssetID = asset.FullID;
m_Scene.AssetService.Store(asset);
m_Scene.InventoryService.UpdateItem(item);
// remoteClient.SendInventoryItemCreateUpdate(item);
return (asset.FullID);
}
public virtual bool UpdateInventoryItemAsset(UUID ownerID, InventoryItemBase item, AssetBase asset)
{
if (item != null && item.Owner == ownerID && asset != null)
{
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Updating item {0} {1} with new asset {2}",
// item.Name, item.ID, asset.ID);
item.AssetID = asset.FullID;
item.Description = asset.Description;
item.Name = asset.Name;
item.AssetType = asset.Type;
item.InvType = (int)InventoryType.Object;
m_Scene.AssetService.Store(asset);
m_Scene.InventoryService.UpdateItem(item);
return true;
}
else
{
m_log.ErrorFormat("[INVENTORY ACCESS MODULE]: Given invalid item for inventory update: {0}",
(item == null || asset == null? "null item or asset" : "wrong owner"));
return false;
}
}
public virtual List<InventoryItemBase> CopyToInventory(
DeRezAction action, UUID folderID,
List<SceneObjectGroup> objectGroups, IClientAPI remoteClient, bool asAttachment)
{
List<InventoryItemBase> copiedItems = new List<InventoryItemBase>();
Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>();
if (CoalesceMultipleObjectsToInventory)
{
// The following code groups the SOG's by owner. No objects
// belonging to different people can be coalesced, for obvious
// reasons.
foreach (SceneObjectGroup g in objectGroups)
{
if (!bundlesToCopy.ContainsKey(g.OwnerID))
bundlesToCopy[g.OwnerID] = new List<SceneObjectGroup>();
bundlesToCopy[g.OwnerID].Add(g);
}
}
else
{
// If we don't want to coalesce then put every object in its own bundle.
foreach (SceneObjectGroup g in objectGroups)
{
List<SceneObjectGroup> bundle = new List<SceneObjectGroup>();
bundle.Add(g);
bundlesToCopy[g.UUID] = bundle;
}
}
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Copying {0} object bundles to folder {1} action {2} for {3}",
// bundlesToCopy.Count, folderID, action, remoteClient.Name);
// Each iteration is really a separate asset being created,
// with distinct destinations as well.
foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values)
copiedItems.Add(CopyBundleToInventory(action, folderID, bundle, remoteClient, asAttachment));
return copiedItems;
}
/// <summary>
/// Copy a bundle of objects to inventory. If there is only one object, then this will create an object
/// item. If there are multiple objects then these will be saved as a single coalesced item.
/// </summary>
/// <param name="action"></param>
/// <param name="folderID"></param>
/// <param name="objlist"></param>
/// <param name="remoteClient"></param>
/// <param name="asAttachment">Should be true if the bundle is being copied as an attachment. This prevents
/// attempted serialization of any script state which would abort any operating scripts.</param>
/// <returns>The inventory item created by the copy</returns>
protected InventoryItemBase CopyBundleToInventory(
DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient,
bool asAttachment)
{
CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero);
Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>();
Dictionary<UUID, Quaternion> originalRotations = new Dictionary<UUID, Quaternion>();
// this possible is not needed if keyframes are saved
Dictionary<UUID, KeyframeMotion> originalKeyframes = new Dictionary<UUID, KeyframeMotion>();
foreach (SceneObjectGroup objectGroup in objlist)
{
if (objectGroup.RootPart.KeyframeMotion != null)
{
objectGroup.RootPart.KeyframeMotion.Suspend();
}
objectGroup.RootPart.SetForce(Vector3.Zero);
objectGroup.RootPart.SetAngularImpulse(Vector3.Zero, false);
originalKeyframes[objectGroup.UUID] = objectGroup.RootPart.KeyframeMotion;
objectGroup.RootPart.KeyframeMotion = null;
Vector3 inventoryStoredPosition = objectGroup.AbsolutePosition;
originalPositions[objectGroup.UUID] = inventoryStoredPosition;
Quaternion inventoryStoredRotation = objectGroup.GroupRotation;
originalRotations[objectGroup.UUID] = inventoryStoredRotation;
// Restore attachment data after trip through the sim
if (objectGroup.RootPart.AttachPoint > 0)
{
inventoryStoredPosition = objectGroup.RootPart.AttachedPos;
inventoryStoredRotation = objectGroup.RootPart.AttachRotation;
}
// Trees could be attached and it's been done, but it makes
// no sense. State must be preserved because it's the tree type
if (objectGroup.RootPart.Shape.PCode != (byte) PCode.Tree &&
objectGroup.RootPart.Shape.PCode != (byte) PCode.NewTree)
{
objectGroup.RootPart.Shape.State = objectGroup.RootPart.AttachPoint;
if (objectGroup.RootPart.AttachPoint > 0)
objectGroup.RootPart.Shape.LastAttachPoint = objectGroup.RootPart.AttachPoint;
}
objectGroup.AbsolutePosition = inventoryStoredPosition;
objectGroup.RootPart.RotationOffset = inventoryStoredRotation;
// Make sure all bits but the ones we want are clear
// on take.
// This will be applied to the current perms, so
// it will do what we want.
objectGroup.RootPart.NextOwnerMask &=
((uint)PermissionMask.Copy |
(uint)PermissionMask.Transfer |
(uint)PermissionMask.Modify |
(uint)PermissionMask.Export);
objectGroup.RootPart.NextOwnerMask |=
(uint)PermissionMask.Move;
coa.Add(objectGroup);
}
string itemXml;
// If we're being called from a script, then trying to serialize that same script's state will not complete
// in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
// the client/server crashes rather than logging out normally, the attachment's scripts will resume
// without state on relog. Arguably, this is what we want anyway.
if (objlist.Count > 1)
itemXml = CoalescedSceneObjectsSerializer.ToXml(coa, !asAttachment);
else
itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment);
// Restore the position of each group now that it has been stored to inventory.
foreach (SceneObjectGroup objectGroup in objlist)
{
objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
objectGroup.RootPart.RotationOffset = originalRotations[objectGroup.UUID];
objectGroup.RootPart.KeyframeMotion = originalKeyframes[objectGroup.UUID];
if (objectGroup.RootPart.KeyframeMotion != null)
objectGroup.RootPart.KeyframeMotion.Resume();
}
InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Created item is {0}",
// item != null ? item.ID.ToString() : "NULL");
if (item == null)
return null;
item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
item.CreatorData = objlist[0].RootPart.CreatorData;
if (objlist.Count > 1)
{
item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems;
// If the objects have different creators then don't specify a creator at all
foreach (SceneObjectGroup objectGroup in objlist)
{
if ((objectGroup.RootPart.CreatorID.ToString() != item.CreatorId)
|| (objectGroup.RootPart.CreatorData.ToString() != item.CreatorData))
{
item.CreatorId = UUID.Zero.ToString();
item.CreatorData = string.Empty;
break;
}
}
}
else
{
item.SaleType = objlist[0].RootPart.ObjectSaleType;
item.SalePrice = objlist[0].RootPart.SalePrice;
}
AssetBase asset = CreateAsset(
objlist[0].GetPartName(objlist[0].RootPart.LocalId),
objlist[0].GetPartDescription(objlist[0].RootPart.LocalId),
(sbyte)AssetType.Object,
Utils.StringToBytes(itemXml),
objlist[0].OwnerID.ToString());
m_Scene.AssetService.Store(asset);
item.AssetID = asset.FullID;
if (DeRezAction.SaveToExistingUserInventoryItem == action)
{
m_Scene.InventoryService.UpdateItem(item);
}
else
{
AddPermissions(item, objlist[0], objlist, remoteClient);
item.CreationDate = Util.UnixTimeSinceEpoch();
item.Description = asset.Description;
item.Name = asset.Name;
item.AssetType = asset.Type;
m_Scene.AddInventoryItem(item);
if (remoteClient != null && item.Owner == remoteClient.AgentId)
{
remoteClient.SendInventoryItemCreateUpdate(item, 0);
}
else
{
ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner);
if (notifyUser != null)
{
notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0);
}
}
}
// This is a hook to do some per-asset post-processing for subclasses that need that
if (remoteClient != null && action != DeRezAction.Delete)
ExportAsset(remoteClient.AgentId, asset.FullID);
return item;
}
protected virtual void ExportAsset(UUID agentID, UUID assetID)
{
// nothing to do here
}
/// <summary>
/// Add relevant permissions for an object to the item.
/// </summary>
/// <param name="item"></param>
/// <param name="so"></param>
/// <param name="objsForEffectivePermissions"></param>
/// <param name="remoteClient"></param>
/// <returns></returns>
protected InventoryItemBase AddPermissions(
InventoryItemBase item, SceneObjectGroup so, List<SceneObjectGroup> objsForEffectivePermissions,
IClientAPI remoteClient)
{
uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7;
uint allObjectsNextOwnerPerms = 0x7fffffff;
// For the porposes of inventory, an object is modify if the prims
// are modify. This allows renaming an object that contains no
// mod items.
foreach (SceneObjectGroup grp in objsForEffectivePermissions)
{
uint groupPerms = grp.GetEffectivePermissions(true);
if ((grp.RootPart.BaseMask & (uint)PermissionMask.Modify) != 0)
groupPerms |= (uint)PermissionMask.Modify;
effectivePerms &= groupPerms;
}
effectivePerms |= (uint)PermissionMask.Move;
if (remoteClient != null && (remoteClient.AgentId != so.RootPart.OwnerID) && m_Scene.Permissions.PropagatePermissions())
{
uint perms = effectivePerms;
uint nextPerms = (perms & 7) << 13;
if ((nextPerms & (uint)PermissionMask.Copy) == 0)
perms &= ~(uint)PermissionMask.Copy;
if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
perms &= ~(uint)PermissionMask.Transfer;
if ((nextPerms & (uint)PermissionMask.Modify) == 0)
perms &= ~(uint)PermissionMask.Modify;
// item.BasePermissions = perms & so.RootPart.NextOwnerMask;
uint nextp = so.RootPart.NextOwnerMask | (uint)PermissionMask.FoldedMask;
item.BasePermissions = perms & nextp;
item.CurrentPermissions = item.BasePermissions;
item.NextPermissions = perms & so.RootPart.NextOwnerMask;
item.EveryOnePermissions = so.RootPart.EveryoneMask & so.RootPart.NextOwnerMask;
item.GroupPermissions = so.RootPart.GroupMask & so.RootPart.NextOwnerMask;
// apply next owner perms on rez
item.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
}
else
{
item.BasePermissions = effectivePerms;
item.CurrentPermissions = effectivePerms;
item.NextPermissions = so.RootPart.NextOwnerMask & effectivePerms;
item.EveryOnePermissions = so.RootPart.EveryoneMask & effectivePerms;
item.GroupPermissions = so.RootPart.GroupMask & effectivePerms;
item.CurrentPermissions &=
((uint)PermissionMask.Copy |
(uint)PermissionMask.Transfer |
(uint)PermissionMask.Modify |
(uint)PermissionMask.Move |
(uint)PermissionMask.Export |
7); // Preserve folded permissions
}
return item;
}
/// <summary>
/// Create an item using details for the given scene object.
/// </summary>
/// <param name="action"></param>
/// <param name="remoteClient"></param>
/// <param name="so"></param>
/// <param name="folderID"></param>
/// <returns></returns>
protected InventoryItemBase CreateItemForObject(
DeRezAction action, IClientAPI remoteClient, SceneObjectGroup so, UUID folderID)
{
// m_log.DebugFormat(
// "[BASIC INVENTORY ACCESS MODULE]: Creating item for object {0} {1} for folder {2}, action {3}",
// so.Name, so.UUID, folderID, action);
//
// Get the user info of the item destination
//
UUID userID = UUID.Zero;
if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
action == DeRezAction.SaveToExistingUserInventoryItem)
{
// Take or take copy require a taker
// Saving changes requires a local user
//
if (remoteClient == null)
return null;
userID = remoteClient.AgentId;
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is {1} {2}",
// action, remoteClient.Name, userID);
}
else if (so.RootPart.OwnerID == so.RootPart.GroupID)
{
// Group owned objects go to the last owner before the object was transferred.
userID = so.RootPart.LastOwnerID;
}
else
{
// Other returns / deletes go to the object owner
//
userID = so.RootPart.OwnerID;
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is object owner {1}",
// action, userID);
}
if (userID == UUID.Zero) // Can't proceed
{
return null;
}
// If we're returning someone's item, it goes back to the
// owner's Lost And Found folder.
// Delete is treated like return in this case
// Deleting your own items makes them go to trash
//
InventoryFolderBase folder = null;
InventoryItemBase item = null;
if (DeRezAction.SaveToExistingUserInventoryItem == action)
{
item = m_Scene.InventoryService.GetItem(userID, so.RootPart.FromUserInventoryItemID);
//item = userInfo.RootFolder.FindItem(
// objectGroup.RootPart.FromUserInventoryItemID);
if (null == item)
{
m_log.DebugFormat(
"[INVENTORY ACCESS MODULE]: Object {0} {1} scheduled for save to inventory has already been deleted.",
so.Name, so.UUID);
return null;
}
}
else
{
// Folder magic
//
if (action == DeRezAction.Delete)
{
// Deleting someone else's item
//
if (remoteClient == null ||
so.OwnerID != remoteClient.AgentId)
{
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound);
}
else
{
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Trash);
}
}
else if (action == DeRezAction.Return)
{
// Dump to lost + found unconditionally
//
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound);
}
if (folderID == UUID.Zero && folder == null)
{
if (action == DeRezAction.Delete)
{
// Deletes go to trash by default
//
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Trash);
}
else
{
if (remoteClient == null || so.RootPart.OwnerID != remoteClient.AgentId)
{
// Taking copy of another person's item. Take to
// Objects folder.
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object);
so.FromFolderID = UUID.Zero;
}
else
{
// Catch all. Use lost & found
//
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound);
}
}
}
// Override and put into where it came from, if it came
// from anywhere in inventory and the owner is taking it back.
//
if (action == DeRezAction.Take || action == DeRezAction.TakeCopy)
{
if (so.FromFolderID != UUID.Zero && so.RootPart.OwnerID == remoteClient.AgentId)
{
folder = m_Scene.InventoryService.GetFolder(userID, so.FromFolderID);
if(folder.Type == 14 || folder.Type == 16)
{
// folder.Type = 6;
folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object);
}
}
}
if (folder == null) // None of the above
{
folder = new InventoryFolderBase(folderID);
if (folder == null) // Nowhere to put it
{
return null;
}
}
item = new InventoryItemBase();
item.ID = UUID.Random();
item.InvType = (int)InventoryType.Object;
item.Folder = folder.ID;
item.Owner = userID;
}
return item;
}
// compatibility do not use
public virtual SceneObjectGroup RezObject(
IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
{
return RezObject(remoteClient, itemID, UUID.Zero, RayEnd, RayStart,
RayTargetID, BypassRayCast, RayEndIsIntersection,
RezSelected, RemoveItem, fromTaskID, attachment);
}
public virtual SceneObjectGroup RezObject(
IClientAPI remoteClient, UUID itemID, UUID rezGroupID, Vector3 RayEnd, Vector3 RayStart,
UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
{
// m_log.DebugFormat("[INVENTORY ACCESS MODULE]: RezObject for {0}, item {1}", remoteClient.Name, itemID);
InventoryItemBase item = m_Scene.InventoryService.GetItem(remoteClient.AgentId, itemID);
if (item == null)
{
return null;
}
item.Owner = remoteClient.AgentId;
return RezObject(
remoteClient, item, rezGroupID, item.AssetID,
RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
RezSelected, RemoveItem, fromTaskID, attachment);
}
// compatility
public virtual SceneObjectGroup RezObject(
IClientAPI remoteClient, InventoryItemBase item, UUID assetID, Vector3 RayEnd, Vector3 RayStart,
UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
{
return RezObject(remoteClient, item, UUID.Zero, assetID,
RayEnd, RayStart, RayTargetID,
BypassRayCast, RayEndIsIntersection,
RezSelected, RemoveItem, fromTaskID, attachment);
}
public virtual SceneObjectGroup RezObject(
IClientAPI remoteClient, InventoryItemBase item, UUID groupID, UUID assetID,
Vector3 RayEnd, Vector3 RayStart, UUID RayTargetID,
byte BypassRayCast, bool RayEndIsIntersection,
bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
{
AssetBase rezAsset = m_Scene.AssetService.Get(assetID.ToString());
if (rezAsset == null)
{
if (item != null)
{
m_log.WarnFormat(
"[InventoryAccessModule]: Could not find asset {0} for item {1} {2} for {3} in RezObject()",
assetID, item.Name, item.ID, remoteClient.Name);
remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: could not find asset {0} for item {1}.", assetID, item.Name), false);
}
else
{
m_log.WarnFormat(
"[INVENTORY ACCESS MODULE]: Could not find asset {0} for {1} in RezObject()",
assetID, remoteClient.Name);
remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: could not find asset {0}.", assetID), false);
}
return null;
}
if(rezAsset.Data == null || rezAsset.Data.Length == 0)
{
m_log.WarnFormat(
"[INVENTORY ACCESS MODULE]: missing data in asset {0} to RezObject()",
assetID, remoteClient.Name);
remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: missing data in asset {0} ", assetID), false);
return null;
}
SceneObjectGroup group = null;
List<SceneObjectGroup> objlist;
List<Vector3> veclist;
Vector3 bbox;
float offsetHeight;
byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0);
Vector3 pos;
bool single
= m_Scene.GetObjectsToRez(
rezAsset.Data, attachment, out objlist, out veclist, out bbox, out offsetHeight);
if (single)
{
pos = m_Scene.GetNewRezLocation(
RayStart, RayEnd, RayTargetID, Quaternion.Identity,
BypassRayCast, bRayEndIsIntersection, true, bbox, false);
pos.Z += offsetHeight;
}
else
{
pos = m_Scene.GetNewRezLocation(RayStart, RayEnd,
RayTargetID, Quaternion.Identity,
BypassRayCast, bRayEndIsIntersection, true,
bbox, false);
pos -= bbox / 2;
}
int primcount = 0;
foreach (SceneObjectGroup g in objlist)
primcount += g.PrimCount;
if (!m_Scene.Permissions.CanRezObject(
primcount, remoteClient.AgentId, pos)
&& !attachment)
{
// The client operates in no fail mode. It will
// have already removed the item from the folder
// if it's no copy.
// Put it back if it's not an attachment
//
if (item != null)
{
if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment))
remoteClient.SendBulkUpdateInventory(item);
}
return null;
}
if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment))
return null;
for (int i = 0; i < objlist.Count; i++)
{
group = objlist[i];
SceneObjectPart rootPart = group.RootPart;
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}",
// group.Name, group.LocalId, group.UUID,
// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask,
// remoteClient.Name);
// Vector3 storedPosition = group.AbsolutePosition;
if (group.UUID == UUID.Zero)
{
m_log.Debug("[INVENTORY ACCESS MODULE]: Object has UUID.Zero! Position 3");
}
// if this was previously an attachment and is now being rezzed,
// save the old attachment info.
if (group.IsAttachment == false && group.RootPart.Shape.State != 0)
{
group.RootPart.AttachedPos = group.AbsolutePosition;
group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint;
}
if (item == null)
{
// Change ownership. Normally this is done in DoPreRezWhenFromItem(), but in this case we must do it here.
foreach (SceneObjectPart part in group.Parts)
{
// Make the rezzer the owner, as this is not necessarily set correctly in the serialized asset.
part.LastOwnerID = part.OwnerID;
part.OwnerID = remoteClient.AgentId;
part.RezzerID = remoteClient.AgentId;
}
}
group.ResetIDs();
if (!attachment)
{
// If it's rezzed in world, select it. Much easier to
// find small items.
//
foreach (SceneObjectPart part in group.Parts)
{
part.CreateSelected = true;
}
if (rootPart.Shape.PCode == (byte)PCode.Prim)
group.ClearPartAttachmentData();
}
else
{
group.IsAttachment = true;
}
group.SetGroup(groupID, remoteClient);
// If we're rezzing an attachment then don't ask
// AddNewSceneObject() to update the client since
// we'll be doing that later on. Scheduling more than
// one full update during the attachment
// process causes some clients to fail to display the
// attachment properly.
m_Scene.AddNewSceneObject(group, true, false);
if (!attachment)
{
group.AbsolutePosition = pos + veclist[i];
// Fire on_rez
group.CreateScriptInstances(0, true, m_Scene.DefaultScriptEngine, 1);
rootPart.ParentGroup.ResumeScripts();
group.ScheduleGroupForFullUpdate();
}
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: Rezzed {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}",
// group.Name, group.LocalId, group.UUID,
// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask,
// remoteClient.Name);
}
// group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
if (item != null)
DoPostRezWhenFromItem(item, attachment);
return group;
}
/// <summary>
/// Do pre-rez processing when the object comes from an item.
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="item"></param>
/// <param name="objlist"></param>
/// <param name="pos"></param>
/// <param name="veclist">
/// List of vector position adjustments for a coalesced objects. For ordinary objects
/// this list will contain just Vector3.Zero. The order of adjustments must match the order of objlist
/// </param>
/// <param name="isAttachment"></param>
/// <returns>true if we can processed with rezzing, false if we need to abort</returns>
private bool DoPreRezWhenFromItem(
IClientAPI remoteClient, InventoryItemBase item, List<SceneObjectGroup> objlist,
Vector3 pos, List<Vector3> veclist, bool isAttachment)
{
UUID fromUserInventoryItemId = UUID.Zero;
// If we have permission to copy then link the rezzed object back to the user inventory
// item that it came from. This allows us to enable 'save object to inventory'
if (!m_Scene.Permissions.BypassPermissions())
{
if ((item.CurrentPermissions & (uint)PermissionMask.Copy)
== (uint)PermissionMask.Copy && (item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
{
fromUserInventoryItemId = item.ID;
}
}
else
{
if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
{
// Brave new fullperm world
fromUserInventoryItemId = item.ID;
}
}
for (int i = 0; i < objlist.Count; i++)
{
SceneObjectGroup g = objlist[i];
if (!m_Scene.Permissions.CanRezObject(
g.PrimCount, remoteClient.AgentId, pos + veclist[i])
&& !isAttachment)
{
// The client operates in no fail mode. It will
// have already removed the item from the folder
// if it's no copy.
// Put it back if it's not an attachment
//
if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!isAttachment))
remoteClient.SendBulkUpdateInventory(item);
ILandObject land = m_Scene.LandChannel.GetLandObject(pos.X, pos.Y);
remoteClient.SendAlertMessage(string.Format(
"Can't rez object '{0}' at <{1:F3}, {2:F3}, {3:F3}> on parcel '{4}' in region {5}.",
item.Name, pos.X, pos.Y, pos.Z, land != null ? land.LandData.Name : "Unknown", m_Scene.Name));
return false;
}
}
for (int i = 0; i < objlist.Count; i++)
{
SceneObjectGroup so = objlist[i];
SceneObjectPart rootPart = so.RootPart;
// Since renaming the item in the inventory does not
// affect the name stored in the serialization, transfer
// the correct name from the inventory to the
// object itself before we rez.
//
// Only do these for the first object if we are rezzing a coalescence.
// nahh dont mess with coalescence objects,
// the name in inventory can be change for inventory purpuses only
if (objlist.Count == 1)
{
rootPart.Name = item.Name;
rootPart.Description = item.Description;
}
if ((item.Flags & (uint)InventoryItemFlags.ObjectSlamSale) != 0)
{
rootPart.ObjectSaleType = item.SaleType;
rootPart.SalePrice = item.SalePrice;
}
so.FromFolderID = item.Folder;
// m_log.DebugFormat(
// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}",
// rootPart.OwnerID, item.Owner, item.CurrentPermissions);
if ((rootPart.OwnerID != item.Owner) ||
(item.CurrentPermissions & (uint)PermissionMask.Slam) != 0 ||
(item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0)
{
//Need to kill the for sale here
rootPart.ObjectSaleType = 0;
rootPart.SalePrice = 10;
if (m_Scene.Permissions.PropagatePermissions())
{
foreach (SceneObjectPart part in so.Parts)
{
part.GroupMask = 0; // DO NOT propagate here
part.LastOwnerID = part.OwnerID;
part.OwnerID = item.Owner;
part.RezzerID = item.Owner;
part.Inventory.ChangeInventoryOwner(item.Owner);
// Reconstruct the original item's base permissions. They
// can be found in the lower (folded) bits.
if ((item.BasePermissions & (uint)PermissionMask.FoldedMask) != 0)
{
// We have permissions stored there so use them
part.NextOwnerMask = ((item.BasePermissions & 7) << 13);
if ((item.BasePermissions & (uint)PermissionMask.FoldedExport) != 0)
part.NextOwnerMask |= (uint)PermissionMask.Export;
part.NextOwnerMask |= (uint)PermissionMask.Move;
}
else
{
// This is a legacy object and we can't avoid the issues that
// caused perms loss or escalation before, treat it the legacy
// way.
part.NextOwnerMask = item.NextPermissions;
}
}
so.ApplyNextOwnerPermissions();
// In case the user has changed flags on a received item
// we have to apply those changes after the slam. Else we
// get a net loss of permissions.
// On legacy objects, this opts for a loss of permissions rather
// than the previous handling that allowed escalation.
foreach (SceneObjectPart part in so.Parts)
{
if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
{
part.GroupMask = item.GroupPermissions & part.BaseMask;
part.EveryoneMask = item.EveryOnePermissions & part.BaseMask;
part.NextOwnerMask = item.NextPermissions & part.BaseMask;
}
}
}
}
else
{
foreach (SceneObjectPart part in so.Parts)
{
part.FromUserInventoryItemID = fromUserInventoryItemId;
if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
part.EveryoneMask = item.EveryOnePermissions;
if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
part.NextOwnerMask = item.NextPermissions;
if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
part.GroupMask = item.GroupPermissions;
}
}
rootPart.TrimPermissions();
so.AggregateDeepPerms();
if (isAttachment)
so.FromItemID = item.ID;
}
return true;
}
/// <summary>
/// Do post-rez processing when the object comes from an item.
/// </summary>
/// <param name="item"></param>
/// <param name="isAttachment"></param>
private void DoPostRezWhenFromItem(InventoryItemBase item, bool isAttachment)
{
if (!m_Scene.Permissions.BypassPermissions())
{
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
{
// If this is done on attachments, no
// copy ones will be lost, so avoid it
//
if (!isAttachment)
{
List<UUID> uuids = new List<UUID>();
uuids.Add(item.ID);
m_Scene.InventoryService.DeleteItems(item.Owner, uuids);
}
}
}
}
protected void AddUserData(SceneObjectGroup sog)
{
UserManagementModule.AddUser(sog.RootPart.CreatorID, sog.RootPart.CreatorData);
foreach (SceneObjectPart sop in sog.Parts)
UserManagementModule.AddUser(sop.CreatorID, sop.CreatorData);
}
public virtual void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
{
}
public virtual bool CanGetAgentInventoryItem(IClientAPI remoteClient, UUID itemID, UUID requestID)
{
InventoryItemBase assetRequestItem = GetItem(remoteClient.AgentId, itemID);
if (assetRequestItem == null)
{
ILibraryService lib = m_Scene.RequestModuleInterface<ILibraryService>();
if (lib != null)
assetRequestItem = lib.LibraryRootFolder.FindItem(itemID);
if (assetRequestItem == null)
return false;
}
// At this point, we need to apply perms
// only to notecards and scripts. All
// other asset types are always available
//
if (assetRequestItem.AssetType == (int)AssetType.LSLText)
{
if (!m_Scene.Permissions.CanViewScript(itemID, UUID.Zero, remoteClient.AgentId))
{
remoteClient.SendAgentAlertMessage("Insufficient permissions to view script", false);
return false;
}
}
else if (assetRequestItem.AssetType == (int)AssetType.Notecard)
{
if (!m_Scene.Permissions.CanViewNotecard(itemID, UUID.Zero, remoteClient.AgentId))
{
remoteClient.SendAgentAlertMessage("Insufficient permissions to view notecard", false);
return false;
}
}
if (assetRequestItem.AssetID != requestID)
{
m_log.WarnFormat(
"[INVENTORY ACCESS MODULE]: {0} requested asset {1} from item {2} but this does not match item's asset {3}",
Name, requestID, itemID, assetRequestItem.AssetID);
return false;
}
return true;
}
public virtual bool IsForeignUser(UUID userID, out string assetServerURL)
{
assetServerURL = string.Empty;
return false;
}
#endregion
#region Misc
/// <summary>
/// Create a new asset data structure.
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <param name="invType"></param>
/// <param name="assetType"></param>
/// <param name="data"></param>
/// <returns></returns>
private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, string creatorID)
{
AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID);
asset.Description = description;
asset.Data = (data == null) ? new byte[1] : data;
return asset;
}
protected virtual InventoryItemBase GetItem(UUID agentID, UUID itemID)
{
IInventoryService invService = m_Scene.RequestModuleInterface<IInventoryService>();
InventoryItemBase item = invService.GetItem(agentID, itemID);
if (item != null && item.CreatorData != null && item.CreatorData != string.Empty)
UserManagementModule.AddUser(item.CreatorIdAsUuid, item.CreatorData);
return item;
}
#endregion
}
}
|