forked from cinderblocks/libremetaverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryBase.cs
More file actions
976 lines (909 loc) · 34.7 KB
/
Copy pathInventoryBase.cs
File metadata and controls
976 lines (909 loc) · 34.7 KB
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
/*
* Copyright (c) 2006-2016, openmetaverse.co
* Copyright (c) 2021-2025, Sjofn LLC.
* All rights reserved.
*
* - 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.
* - Neither the name of the openmetaverse.co 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 COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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.Threading;
using LibreMetaverse.StructuredData;
using MessagePack;
namespace LibreMetaverse
{
/// <summary>
/// Base Class for Inventory Items
/// </summary>
[MessagePackObject]
[Union(0, typeof(InventoryFolder))]
[Union(1, typeof(InventoryItem))]
[Union(2, typeof(InventoryAnimation))]
[Union(3, typeof(InventoryAttachment))]
[Union(4, typeof(InventoryCallingCard))]
[Union(5, typeof(InventoryCategory))]
[Union(6, typeof(InventoryGesture))]
[Union(7, typeof(InventoryLSL))]
[Union(8, typeof(InventoryLandmark))]
[Union(9, typeof(InventoryMaterial))]
[Union(10, typeof(InventoryNotecard))]
[Union(11, typeof(InventoryObject))]
[Union(12, typeof(InventorySettings))]
[Union(13, typeof(InventorySnapshot))]
[Union(14, typeof(InventorySound))]
[Union(15, typeof(InventoryTexture))]
[Union(16, typeof(InventoryWearable))]
public abstract partial class InventoryBase
{
/// <summary><see cref="LibreMetaverse.UUID"/> of item/folder</summary>
[Key("UUID")]
public UUID UUID { get; set; }
/// <summary><see cref="LibreMetaverse.UUID"/> of parent folder</summary>
[Key("ParentUUID")]
public UUID ParentUUID { get; set; }
/// <summary>Name of item/folder</summary>
[Key("Name")]
public string Name { get; set; } = string.Empty;
/// <summary>Item/Folder Owners <see cref="LibreMetaverse.UUID"/></summary>
[Key("OwnerID")]
public UUID OwnerID { get; set; }
/// <summary>
/// Constructor, takes an itemID as a parameter
/// </summary>
/// <param name="UUID">The <see cref="LibreMetaverse.UUID"/> of the item</param>
protected InventoryBase(UUID UUID)
{
if (UUID == UUID.Zero)
Logger.Warn("Initializing an InventoryBase with UUID.Zero");
this.UUID = UUID;
}
/// <summary>
/// Hash code based solely on UUID — the stable identity of an inventory object.
/// </summary>
public override int GetHashCode() => UUID.GetHashCode();
/// <summary>
/// Determine whether the specified <see cref="InventoryBase"/> object is equal to the current object
/// </summary>
/// <param name="obj">InventoryBase object to compare against</param>
/// <returns>true if objects are the same</returns>
public override bool Equals(object? obj)
{
return obj is InventoryBase inv && Equals(inv);
}
/// <summary>
/// Determine whether the specified <see cref="InventoryBase"/> object is equal to the current object
/// </summary>
/// <param name="o">InventoryBase object to compare against</param>
/// <returns>true if objects are the same</returns>
public virtual bool Equals(InventoryBase o)
{
return o.UUID == UUID
&& o.ParentUUID == ParentUUID
&& o.Name == Name
&& o.OwnerID == OwnerID;
}
/// <summary>
/// Convert inventory to OSD
/// </summary>
/// <returns>OSD representation</returns>
public abstract OSD GetOSD();
}
/// <summary>
/// An Item in Inventory
/// </summary>
[MessagePackObject]
public partial class InventoryItem : InventoryBase
{
public override string ToString()
{
return $"{AssetType} {AssetUUID} ({InventoryType} {UUID}) '{Name}'/'{Description}' {Permissions}";
}
/// <summary><see cref="UUID"/> of the underlying asset</summary>
[Key("AssetUUID")]
public UUID AssetUUID { get; set; }
/// <summary>Combined <see cref="LibreMetaverse.Permissions"/> of the item</summary>
[Key("Permissions")]
public Permissions Permissions { get; set; }
/// <summary><see cref="LibreMetaverse.AssetType"/> of the underlying asset</summary>
[Key("AssetType")]
public AssetType AssetType { get; set; }
/// <summary><see cref="LibreMetaverse.InventoryType"/> of the item</summary>
[Key("InventoryType")]
public InventoryType InventoryType { get; set; }
/// <summary><see cref="UUID"/> of the creator of the item</summary>
[Key("CreatorID")]
public UUID CreatorID { get; set; }
/// <summary>Description of the item</summary>
[Key("Description")]
public string Description { get; set; } = string.Empty;
/// <summary><see cref="Group"/>s <see cref="UUID"/> the item is owned by</summary>
[Key("GroupID")]
public UUID GroupID { get; set; }
/// <summary>If true, item is owned by a group</summary>
[Key("GroupOwned")]
public bool GroupOwned { get; set; }
/// <summary>Price the item can be purchased for</summary>
[Key("SalePrice")]
public int SalePrice { get; set; }
/// <summary><see cref="LibreMetaverse.SaleType"/> of the item</summary>
[Key("SaleType")]
public SaleType SaleType { get; set; }
/// <summary>Combined flags from <see cref="InventoryItemFlags"/></summary>
[Key("Flags")]
public uint Flags { get; set; }
/// <summary>VM runtime for scripts (e.g. "lsl2", "mono", "luau"), from the task inventory response's metadata; null if not a script or not provided</summary>
[Key("Runtime")]
public string? Runtime { get; set; }
/// <summary>Time and date the inventory item was created, stored as
/// UTC (Coordinated Universal Time)</summary>
[Key("CreationDate")]
public DateTime CreationDate { get; set; }
/// <summary>Used to update the AssetID in requests sent to the server</summary>
[Key("TransactionID")]
public UUID TransactionID { get; set; }
/// <summary><see cref="UUID"/> of the previous owner of the item</summary>
[Key("LastOwnerID")]
public UUID LastOwnerID { get; set; }
/// <summary>
/// For a link: the inventory UUID of the item this link points to.
/// For a non-link: this item's own inventory UUID.
/// </summary>
[IgnoreMember]
public UUID ResolvedItemID => IsLink() ? AssetUUID : UUID;
/// <summary>
/// For a non-link: this item's underlying asset UUID.
/// For a link: <see cref="UUID.Zero"/> — the asset UUID cannot be determined without
/// resolving the link through the inventory store first.
/// </summary>
[IgnoreMember]
public UUID ResolvedAssetID => IsLink() ? UUID.Zero : AssetUUID;
/// <summary>
/// Construct a new InventoryItem object
/// </summary>
/// <param name="UUID">The <see cref="UUID"/> of the item</param>
public InventoryItem(UUID UUID)
: base(UUID) { }
/// <summary>
/// Construct a new InventoryItem object of a specific Type
/// </summary>
/// <param name="type">The type of item from <see cref="T:LibreMetaverse.InventoryType" /></param>
/// <param name="itemID"><see cref="T:LibreMetaverse.UUID" /> of the item</param>
public InventoryItem(InventoryType type, UUID itemID) : base(itemID) { InventoryType = type; }
/// <summary>
/// Indicates inventory item is a link
/// </summary>
/// <returns>True if inventory item is a link to another inventory item</returns>
public bool IsLink()
{
return AssetType == AssetType.Link || AssetType == AssetType.LinkFolder;
}
/// <inheritdoc />
/// <summary>
/// Compares an object
/// </summary>
/// <param name="obj">The object to compare</param>
/// <returns>true if comparison object matches</returns>
public override bool Equals(object? obj)
{
return obj is InventoryItem item && Equals(item);
}
public override int GetHashCode() => base.GetHashCode();
/// <inheritdoc />
/// <summary>
/// Determine whether the specified <see cref="T:LibreMetaverse.InventoryBase" /> object is equal to the current object
/// </summary>
/// <param name="o">The <see cref="T:LibreMetaverse.InventoryBase" /> object to compare against</param>
/// <returns>true if objects are the same</returns>
public override bool Equals(InventoryBase o)
{
return o is InventoryItem item && Equals(item);
}
/// <summary>
/// Determine whether the specified <see cref="InventoryItem"/> object is equal to the current object
/// </summary>
/// <param name="o">The <see cref="InventoryItem"/> object to compare against</param>
/// <returns>true if objects are the same</returns>
public bool Equals(InventoryItem o)
{
return base.Equals(o)
&& o.AssetType == AssetType
&& o.AssetUUID == AssetUUID
&& o.CreationDate == CreationDate
&& o.Description == Description
&& o.Flags == Flags
&& o.GroupID == GroupID
&& o.GroupOwned == GroupOwned
&& o.InventoryType == InventoryType
&& o.Permissions.Equals(Permissions)
&& o.SalePrice == SalePrice
&& o.SaleType == SaleType
&& o.LastOwnerID == LastOwnerID;
}
/// <summary>
/// Create InventoryItem from OSD
/// </summary>
/// <param name="data">OSD Data that makes up InventoryItem</param>
/// <returns>Inventory item created</returns>
public static InventoryItem FromOSD(OSD data)
{
/* OSD map looks like (from e.g. GetTaskInventoryAsync()):
{
"asset_id": "00000000-0000-0000-0000-000000000000",
"created_at": 1785363605,
"desc": "description",
"flags": 0,
"inv_type": "script",
"item_id": "806baac6-64cd-daae-efff-627208ed1d2b",
"metadata": {
"script": {
"runtime": "luau"
}
},
"name": "New Script",
"parent_id": "74a61033-366a-0b89-4d4b-649c5b0de2ad",
"permissions": {
"base_mask": 2147483647,
"creator_id": "90d514eb-85f5-4ffe-b95e-20bcc77168db",
"everyone_mask": 0,
"group_id": "00000000-0000-0000-0000-000000000000",
"group_mask": 0,
"is_owner_group": false,
"last_owner_id": "90d514eb-85f5-4ffe-b95e-20bcc77168db",
"next_owner_mask": 532480,
"owner_id": "90d514eb-85f5-4ffe-b95e-20bcc77168db",
"owner_mask": 2147483647
},
"sale_info": {
"sale_price": 10,
"sale_type": "not"
},
"type": "lsltext"
}
*/
OSDMap descItem = (OSDMap)data;
InventoryType invType = descItem["inv_type"].Type == OSDType.String
? Utils.StringToInventoryType(descItem["inv_type"].AsString())
: (InventoryType)descItem["inv_type"].AsInteger();
AssetType assetType = descItem["type"].Type == OSDType.String
? Utils.StringToAssetType(descItem["type"].AsString())
: (AssetType)descItem["type"].AsInteger();
/*
* Objects that have been attached in-world prior to being stored on the
* asset server are stored with the InventoryType of 0 (Texture)
* instead of 17 (Attachment)
*
* This corrects that behavior by forcing Object Asset types that have an
* invalid InventoryType with the proper InventoryType of Attachment.
*/
if (invType == InventoryType.Texture &&
(assetType == AssetType.Object || assetType == AssetType.Mesh))
{
invType = InventoryType.Attachment;
}
InventoryItem item = InventoryManager.CreateInventoryItem(invType, descItem["item_id"]);
item.ParentUUID = descItem["parent_id"];
item.Name = descItem["name"];
item.Description = descItem["desc"];
item.AssetUUID = descItem["asset_id"];
item.AssetType = assetType;
item.CreationDate = Utils.UnixTimeToDateTime(descItem["created_at"]);
item.Flags = descItem["flags"];
if (descItem["metadata"] is OSDMap meta && meta["script"] is OSDMap scriptMeta && scriptMeta.TryGetValue("runtime", out var runtime))
{
item.Runtime = runtime.AsString();
}
OSDMap perms = (OSDMap)descItem["permissions"];
item.OwnerID = perms["owner_id"];
item.CreatorID = perms["creator_id"];
item.LastOwnerID = perms["last_owner_id"];
item.Permissions = new Permissions(perms["base_mask"], perms["everyone_mask"], perms["group_mask"], perms["next_owner_mask"], perms["owner_mask"]);
item.GroupOwned = perms["is_owner_group"];
item.GroupID = perms["group_id"];
OSDMap sale = (OSDMap)descItem["sale_info"];
item.SalePrice = sale["sale_price"];
item.SaleType = (SaleType)sale["sale_type"].AsInteger();
return item;
}
/// <summary>
/// Update InventoryItem from new OSD data
/// </summary>
/// <param name="data">Data to update in <see cref="OSDMap"/> format</param>
public void Update(OSDMap data)
{
if (data.ContainsKey("item_id"))
{
UUID = data["item_id"].AsUUID();
}
if (data.ContainsKey("parent_id"))
{
ParentUUID = data["parent_id"].AsUUID();
}
if (data.ContainsKey("agent_id"))
{
OwnerID = data["agent_id"].AsUUID();
}
if (data.ContainsKey("name"))
{
Name = data["name"].AsString();
}
if (data.ContainsKey("desc"))
{
Description = data["desc"].AsString();
}
if (data.TryGetValue("permissions", out var permissions))
{
Permissions = Permissions.FromOSD(permissions);
}
if (data.TryGetValue("sale_info", out var saleInfo))
{
OSDMap sale = (OSDMap)saleInfo;
SalePrice = sale["sale_price"].AsInteger();
SaleType = (SaleType)sale["sale_type"].AsInteger();
}
if (data.ContainsKey("shadow_id"))
{
AssetUUID = InventoryManager.DecryptShadowID(data["shadow_id"].AsUUID());
}
if (data.ContainsKey("asset_id"))
{
AssetUUID = data["asset_id"].AsUUID();
}
if (data.ContainsKey("linked_id"))
{
AssetUUID = data["linked_id"].AsUUID();
}
if (data.ContainsKey("type"))
{
AssetType type = AssetType.Unknown;
switch (data["type"].Type)
{
case OSDType.String:
type = Utils.StringToAssetType(data["type"].AsString());
break;
case OSDType.Integer:
type = (AssetType)data["type"].AsInteger();
break;
}
if (type != AssetType.Unknown)
{
AssetType = type;
}
}
if (data.ContainsKey("inv_type"))
{
InventoryType type = InventoryType.Unknown;
switch (data["inv_type"].Type)
{
case OSDType.String:
type = Utils.StringToInventoryType(data["inv_type"].AsString());
break;
case OSDType.Integer:
type = (InventoryType)data["inv_type"].AsInteger();
break;
}
if (type != InventoryType.Unknown)
{
InventoryType = type;
}
}
if (data.TryGetValue("flags", out var flags))
{
Flags = flags;
}
if (data.TryGetValue("created_at", out var createdAt))
{
CreationDate = Utils.UnixTimeToDateTime(createdAt);
}
}
/// <summary>
/// Convert InventoryItem to OSD
/// </summary>
/// <returns>OSD representation of InventoryItem</returns>
public override OSD GetOSD()
{
OSDMap map = new OSDMap
{
["item_id"] = UUID,
["parent_id"] = ParentUUID,
["type"] = (sbyte)AssetType,
["inv_type"] = (sbyte)InventoryType,
["flags"] = Flags,
["name"] = Name,
["desc"] = Description,
["asset_id"] = AssetUUID,
["created_at"] = CreationDate
};
OSDMap perms = (OSDMap)Permissions.GetOSD();
perms["creator_id"] = CreatorID;
perms["last_owner_id"] = LastOwnerID;
perms["is_owner_group"] = GroupOwned;
perms["group_id"] = GroupID;
map["permissions"] = perms;
OSDMap sale = new OSDMap
{
["sale_price"] = SalePrice,
["sale_type"] = (sbyte)SaleType
};
map["sale_info"] = sale;
return map;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryTexture Class representing a graphical image
/// </summary>
/// <seealso cref="T:LibreMetaverse.Imaging.ManagedImage" />
[MessagePackObject]
public partial class InventoryTexture : InventoryItem
{
/// <summary>
/// Construct an InventoryTexture object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryTexture(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Texture;
}
}
/// <inheritdoc />
/// <summary>
/// InventorySound Class representing a playable sound
/// </summary>
[MessagePackObject]
public partial class InventorySound : InventoryItem
{
/// <summary>
/// Construct an InventorySound object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventorySound(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Sound;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryCallingCard Class, contains information on another avatar
/// </summary>
[MessagePackObject]
public partial class InventoryCallingCard : InventoryItem
{
/// <summary>
/// Construct an InventoryCallingCard object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryCallingCard(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.CallingCard;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryLandmark Class, contains details on a specific location
/// </summary>
[MessagePackObject]
public partial class InventoryLandmark : InventoryItem
{
/// <summary>
/// Construct an InventoryLandmark object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryLandmark(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Landmark;
}
/// <summary>
/// Landmarks use the InventoryItemFlags struct and will have a flag of 1 set if they have been visited
/// </summary>
[IgnoreMember]
public bool LandmarkVisited
{
get => (Flags & 1) != 0;
set
{
if (value) Flags |= 1;
else Flags &= ~1u;
}
}
}
/// <inheritdoc />
/// <summary>
/// InventoryObject Class contains details on a primitive or coalesced set of primitives
/// </summary>
[MessagePackObject]
public partial class InventoryObject : InventoryItem
{
/// <summary>
/// Construct an InventoryObject object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryObject(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Object;
}
/// <summary>
/// Gets or sets the upper byte of the Flags value
/// </summary>
[IgnoreMember]
public InventoryItemFlags ItemFlags
{
get => (InventoryItemFlags)(Flags & ~0xFF);
set => Flags = (uint)value | (Flags & 0xFF);
}
/// <summary>
/// Gets or sets the object attachment point, the lower byte of the Flags value
/// </summary>
[IgnoreMember]
public AttachmentPoint AttachPoint
{
get => (AttachmentPoint)(Flags & 0xFF);
set => Flags = (uint)value | (Flags & 0xFFFFFF00);
}
}
/// <inheritdoc />
/// <summary>
/// InventoryNotecard Class, contains details on an encoded text document
/// </summary>
[MessagePackObject]
public partial class InventoryNotecard : InventoryItem
{
/// <summary>
/// Construct an InventoryNotecard object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryNotecard(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Notecard;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryCategory Class
/// </summary>
[MessagePackObject]
public partial class InventoryCategory : InventoryItem
{
/// <summary>
/// Construct an InventoryCategory object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryCategory(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Category;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryLSL Class, represents a Linden Scripting Language object
/// </summary>
[MessagePackObject]
public partial class InventoryLSL : InventoryItem
{
/// <summary>
/// Construct an InventoryLSL object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryLSL(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.LSL;
}
}
/// <inheritdoc />
/// <summary>
/// InventorySnapshot Class, an image taken with the viewer
/// </summary>
[MessagePackObject]
public partial class InventorySnapshot : InventoryItem
{
/// <inheritdoc />
/// <summary>
/// Construct an InventorySnapshot object
/// </summary>
/// <param name="UUID">A <see cref="T:LibreMetaverse.UUID" /> which becomes the
/// <seealso cref="T:LibreMetaverse.InventoryItem" /> objects UUID</param>
public InventorySnapshot(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Snapshot;
}
}
/// <summary>
/// InventoryAttachment Class, contains details on an attachable object
/// </summary>
[MessagePackObject]
public partial class InventoryAttachment : InventoryItem
{
/// <summary>
/// Construct an InventoryAttachment object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryAttachment(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Attachment;
}
/// <summary>
/// Get the last AttachmentPoint this object was attached to
/// </summary>
[IgnoreMember]
public AttachmentPoint AttachmentPoint
{
get => (AttachmentPoint)Flags;
set => Flags = (uint)value;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryWearable Class, details on a clothing item or body part
/// </summary>
[MessagePackObject]
public partial class InventoryWearable : InventoryItem
{
/// <summary>
/// Construct an InventoryWearable object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryWearable(UUID UUID) : base(UUID) { InventoryType = InventoryType.Wearable; }
/// <summary>
/// The <see cref="LibreMetaverse.WearableType"/>, Skin, Shape, Skirt, Etc
/// </summary>
[IgnoreMember]
public WearableType WearableType
{
get => (WearableType)Flags;
set => Flags = (uint)value;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryAnimation Class, A bvh encoded object which animates an avatar
/// </summary>
[MessagePackObject]
public partial class InventoryAnimation : InventoryItem
{
/// <summary>
/// Construct an InventoryAnimation object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryAnimation(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Animation;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryGesture Class, details on a series of animations, sounds, and actions
/// </summary>
[MessagePackObject]
public partial class InventoryGesture : InventoryItem
{
/// <summary>
/// Construct an InventoryGesture object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryGesture(UUID UUID)
: base(UUID)
{
InventoryType = InventoryType.Gesture;
}
}
/// <inheritdoc />
/// <summary>
/// InventorySettings, LLSD settings blob as an asset
/// </summary>
[MessagePackObject]
public partial class InventorySettings : InventoryItem
{
/// <summary>
/// Construct an InventorySettings object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventorySettings(UUID UUID) : base(UUID)
{
InventoryType = InventoryType.Settings;
}
}
/// <inheritdoc />
/// <summary>
/// InventoryMaterial, material as an asset
/// </summary>
[MessagePackObject]
public partial class InventoryMaterial : InventoryItem
{
/// <summary>
/// Construct an InventoryMaterial object
/// </summary>
/// <param name="UUID">A <see cref="UUID"/> which becomes the
/// <seealso cref="InventoryItem"/> objects UUID</param>
public InventoryMaterial(UUID UUID) : base(UUID)
{
InventoryType = InventoryType.Material;
}
}
/// <inheritdoc />
/// <summary>
/// A folder contains <see cref="T:LibreMetaverse.InventoryItem" />s and has certain attributes specific
/// to itself
/// </summary>
[MessagePackObject]
public partial class InventoryFolder : InventoryBase
{
public const int VERSION_UNKNOWN = -1;
/// <summary>The Preferred <see cref="T:LibreMetaverse.FolderType"/> for a folder.</summary>
[Key("PreferredType")]
public FolderType PreferredType { get; set; }
/// <summary>The Version of this folder</summary>
[Key("Version")]
public int Version { get; set; }
private int _descendentCount;
/// <summary>Number of child items this folder contains.</summary>
[Key("DescendentCount")]
public int DescendentCount
{
get => _descendentCount;
set => _descendentCount = value;
}
/// <summary>
/// Atomically adjusts DescendentCount by delta, clamping to zero.
/// Use this instead of direct assignment for concurrent updates.
/// </summary>
internal void AdjustDescendentCount(int delta)
{
if (delta == 0) return;
int initial, newVal;
do
{
initial = Volatile.Read(ref _descendentCount);
newVal = Math.Max(0, initial + delta);
}
while (Interlocked.CompareExchange(ref _descendentCount, newVal, initial) != initial);
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="UUID">UUID of the folder</param>
public InventoryFolder(UUID UUID)
: base(UUID)
{
PreferredType = FolderType.None;
Version = 1;
DescendentCount = 0;
}
/// <summary>
/// Returns folder name
/// </summary>
/// <returns>Return folder name as string</returns>
public override string ToString()
{
return Name;
}
public override bool Equals(object? obj)
{
return obj is InventoryFolder folder && Equals(folder);
}
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(InventoryBase o)
{
return o is InventoryFolder folder && Equals(folder);
}
public bool Equals(InventoryFolder o)
{
return base.Equals(o as InventoryBase)
&& o.DescendentCount == DescendentCount
&& o.PreferredType == PreferredType
&& o.Version == Version;
}
/// <summary>
/// Create InventoryFolder from OSD
/// </summary>
/// <param name="data">OSD Data that makes up InventoryFolder</param>
/// <returns>Inventory folder created</returns>
public static InventoryFolder FromOSD(OSD data)
{
var res = (OSDMap)data;
UUID folderId = res.TryGetValue("category_id", out var catId) ? catId : res["folder_id"];
var folder = new InventoryFolder(folderId)
{
UUID = folderId,
Version = res.ContainsKey("version") ? res["version"].AsInteger() : VERSION_UNKNOWN,
ParentUUID = res["parent_id"].AsUUID(),
DescendentCount = res["descendents"],
OwnerID = res.TryGetValue("agent_id", out var agentId) ? agentId : res["owner_id"],
PreferredType = (FolderType)(sbyte)res["type_default"].AsUInteger(),
Name = res["name"]
};
return folder;
}
public void Update(OSDMap data)
{
if (data.ContainsKey("category_id"))
{
UUID = data["category_id"].AsUUID();
}
if (data.ContainsKey("version"))
{
Version = data["version"].AsInteger();
}
if (data.ContainsKey("parent_id"))
{
ParentUUID = data["parent_id"].AsUUID();
}
if (data.ContainsKey("type_default"))
{
PreferredType = (FolderType)(sbyte)data["type_default"].AsUInteger();
}
if (data.ContainsKey("descendents"))
{
DescendentCount = data["descendents"].AsInteger();
}
if (data.ContainsKey("owner_id"))
{
OwnerID = data["owner_id"].AsUUID();
}
if (data.ContainsKey("agent_id"))
{
OwnerID = data["agent_id"].AsUUID();
}
if (data.ContainsKey("name"))
{
Name = data["name"].AsString();
}
}
/// <summary>
/// Convert InventoryFolder to OSD
/// </summary>
/// <returns>OSD representation of InventoryFolder</returns>
public override OSD GetOSD()
{
OSDMap res = new OSDMap(4)
{
["item_id"] = UUID,
["version"] = Version,
["parent_id"] = ParentUUID,
["type"] = (sbyte)PreferredType,
["name"] = Name
};
return res;
}
}
}