| 2633 | |
| 2634 | |
| 2635 | bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc) |
| 2636 | { |
| 2637 | short ItemType; |
| 2638 | if (!a_Buffer.ReadBEShort(ItemType)) |
| 2639 | { |
| 2640 | return false; |
| 2641 | } |
| 2642 | if (ItemType <= 0) |
| 2643 | { |
| 2644 | a_ItemDesc = "<empty>"; |
| 2645 | return true; |
| 2646 | } |
| 2647 | if (!a_Buffer.CanReadBytes(5)) |
| 2648 | { |
| 2649 | return false; |
| 2650 | } |
| 2651 | char ItemCount; |
| 2652 | short ItemDamage; |
| 2653 | short MetadataLength; |
| 2654 | a_Buffer.ReadChar(ItemCount); |
| 2655 | a_Buffer.ReadBEShort(ItemDamage); |
| 2656 | a_Buffer.ReadBEShort(MetadataLength); |
| 2657 | Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount); |
| 2658 | if (MetadataLength <= 0) |
| 2659 | { |
| 2660 | return true; |
| 2661 | } |
| 2662 | AString Metadata; |
| 2663 | Metadata.resize(MetadataLength); |
| 2664 | if (!a_Buffer.ReadBuf((void *)Metadata.data(), MetadataLength)) |
| 2665 | { |
| 2666 | return false; |
| 2667 | } |
| 2668 | AString MetaHex; |
| 2669 | CreateHexDump(MetaHex, Metadata.data(), Metadata.size(), 16); |
| 2670 | AppendPrintf(a_ItemDesc, "; %d bytes of meta:\n%s", MetadataLength, MetaHex.c_str()); |
| 2671 | |
| 2672 | // Save metadata to a file: |
| 2673 | AString fnam; |
| 2674 | Printf(fnam, "%s_item_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++); |
| 2675 | FILE * f = fopen(fnam.c_str(), "wb"); |
| 2676 | if (f != NULL) |
| 2677 | { |
| 2678 | fwrite(Metadata.data(), 1, Metadata.size(), f); |
| 2679 | fclose(f); |
| 2680 | AppendPrintf(a_ItemDesc, "\n (saved to file \"%s\")", fnam.c_str()); |
| 2681 | } |
| 2682 | |
| 2683 | return true; |
| 2684 | } |
| 2685 | |
| 2686 | |
| 2687 |
nothing calls this directly
no test coverage detected