Beispiel #1
0
        private void ReadInventorySaleInfo(Stream assetdata, ref NotecardInventoryItem item)
        {
            if (ReadLine(assetdata) != "{")
            {
                throw new NotANotecardFormatException();
            }
            while (true)
            {
                var line = ReadLine(assetdata);
                if (line == "}")
                {
                    return;
                }

                var  data = line.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int  ival;
                uint uval;
                switch (data[0])
                {
                case "sale_type":
                    item.SaleInfo.TypeName = data[1];
                    break;

                case "sale_price":
                    if (!int.TryParse(data[1], out ival))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.SaleInfo.Price = ival;
                    break;

                case "perm_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.SaleInfo.PermMask = (InventoryPermissionsMask)uval;
                    break;

                default:
                    throw new NotANotecardFormatException();
                }
            }
        }
Beispiel #2
0
        private NotecardInventoryItem ReadInventoryItems(Stream assetdata)
        {
            NotecardInventoryItem item = null;
            uint extcharindex          = 0;

            if (ReadLine(assetdata) != "{")
            {
                throw new NotANotecardFormatException();
            }
            while (true)
            {
                var line = ReadLine(assetdata);
                if (line == "}")
                {
                    if (item == null)
                    {
                        throw new NotANotecardFormatException();
                    }
                    return(item);
                }

                var data = line.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (data.Length == 4 && data[0] == "ext" && data[1] == "char" && data[2] == "index")
                {
                    if (!uint.TryParse(data[3], out extcharindex))
                    {
                        throw new NotANotecardFormatException();
                    }
                }
                else if (data[0] == "inv_item")
                {
                    item = ReadInventoryItem(assetdata);
                    item.ExtCharIndex = extcharindex;
                }
                else
                {
                    throw new NotANotecardFormatException();
                }
            }
        }
Beispiel #3
0
 private static string ItemToString(NotecardInventoryItem item) => string.Format(ItemFormatString,
                                                                                 item.ExtCharIndex,
                                                                                 item.ID, item.ParentFolderID,
                                                                                 (uint)item.Permissions.Base,
                                                                                 (uint)item.Permissions.Current,
                                                                                 (uint)item.Permissions.Group,
                                                                                 (uint)item.Permissions.EveryOne,
                                                                                 (uint)item.Permissions.NextOwner,
                                                                                 item.Creator.ID,
                                                                                 item.Owner.ID,
                                                                                 item.LastOwner.ID,
                                                                                 item.Group.ID,
                                                                                 item.AssetID,
                                                                                 item.AssetTypeName,
                                                                                 item.InventoryTypeName,
                                                                                 (uint)item.Flags,
                                                                                 item.SaleInfo.TypeName,
                                                                                 item.SaleInfo.Price,
                                                                                 item.Name,
                                                                                 item.Description,
                                                                                 item.CreationDate.AsULong
                                                                                 );
Beispiel #4
0
        private NotecardInventoryItem ReadInventoryItem(Stream assetdata)
        {
            var item = new NotecardInventoryItem();

            if (ReadLine(assetdata) != "{")
            {
                throw new NotANotecardFormatException();
            }
            while (true)
            {
                var line = ReadLine(assetdata);
                if (line == "}")
                {
                    return(item);
                }

                var data = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (data[0] == "item_id")
                {
                    item.SetNewID(data[1]);
                }
                else if (data[0] == "parent_id")
                {
                    item.ParentFolderID = data[1];
                }
                else if (data[0] == "permissions")
                {
                    ReadInventoryPermissions(assetdata, ref item);
                }
                else if (data[0] == "asset_id" && data.Length == 2)
                {
                    item.AssetID = data[1];
                }
                else if (data[0] == "type" && data.Length == 2)
                {
                    item.AssetTypeName = data[1];
                }
                else if (data[0] == "inv_type" && data.Length == 2)
                {
                    item.InventoryTypeName = data[1];
                }
                else if (data[0] == "flags" && data.Length == 2)
                {
                    uint uval;
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Flags = (InventoryFlags)uval;
                }
                else if (data[0] == "sale_info")
                {
                    ReadInventorySaleInfo(assetdata, ref item);
                }
                else if (data[0] == "name" && data.Length > 1)
                {
                    item.Name = line.Substring(5, line.Length - 6).Trim();
                }
                else if (data[0] == "desc" && data.Length > 1)
                {
                    item.Description = line.Substring(5, line.Length - 6).Trim();
                }
                else if (data[0] == "creation_date" && data.Length == 2)
                {
                    ulong uval;
                    if (!ulong.TryParse(data[1], out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.CreationDate = Date.UnixTimeToDateTime(uval);
                }
                else
                {
                    throw new NotANotecardFormatException();
                }
            }
        }
Beispiel #5
0
        private void ReadInventoryPermissions(Stream assetdata, ref NotecardInventoryItem item)
        {
            if (ReadLine(assetdata) != "{")
            {
                throw new NotANotecardFormatException();
            }
            while (true)
            {
                var line = ReadLine(assetdata);
                if (line == "}")
                {
                    return;
                }

                var  data = line.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                uint uval;
                switch (data[0])
                {
                case "base_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Permissions.Base = (InventoryPermissionsMask)uval;
                    break;

                case "owner_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Permissions.Current = (InventoryPermissionsMask)uval;
                    break;

                case "group_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Permissions.Group = (InventoryPermissionsMask)uval;
                    break;

                case "everyone_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Permissions.EveryOne = (InventoryPermissionsMask)uval;
                    break;

                case "next_owner_mask":
                    if (!uint.TryParse(data[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uval))
                    {
                        throw new NotANotecardFormatException();
                    }
                    item.Permissions.NextOwner = (InventoryPermissionsMask)uval;
                    break;

                case "creator_id":
                    item.Creator.ID = data[1];
                    break;

                case "owner_id":
                    item.Owner.ID = data[1];
                    break;

                case "last_owner_id":
                    item.LastOwner.ID = data[1];
                    break;

                case "group_id":
                    item.Group.ID = data[1];
                    break;

                default:
                    throw new NotANotecardFormatException();
                }
            }
        }