Just a demonstration to handle “attributes stones” in consignment:
import struct
import time
def int2str(number):
return chr(number)
def epoch2Date(epoch):
return time.strftime("%d-%m-%Y %H:%M:%S", time.localtime(epoch))
def analyzeData(data):
result = {}
packIndex = 0
response = struct.unpack_from("B", data, packIndex)[0]
packIndex += 1
if response == 1:
itemCount = struct.unpack_from("B", data, packIndex)[0]
packIndex += 1
pageCount = struct.unpack_from("B", data, packIndex)[0]
packIndex += 1
result['response'] = response
result['itemCount'] = itemCount
result['pageCount'] = pageCount
result['items'] = []
for i in range(0, itemCount):
personalID = struct.unpack_from("I", data, packIndex)[0]
packIndex += 4
nameLength = struct.unpack_from("H", data, packIndex)[0]
packIndex += 2
charName = ""
for i in range(0, nameLength):
nameCharacterHex = struct.unpack_from("B", data, packIndex)[0]
charName += int2str(nameCharacterHex)
packIndex += 1
saleStatus = struct.unpack_from("B", data, packIndex)[0]
packIndex += 1
refItemId = struct.unpack_from("I", data, packIndex)[0]
packIndex += 4
stackCount = struct.unpack_from("H", data, packIndex)[0]
packIndex += 2
itemContent = struct.unpack_from("H", data, packIndex)[0]
packIndex += 2
price = struct.unpack_from("Q", data, packIndex)[0]
packIndex += 8
regDate = epoch2Date(struct.unpack_from("Q", data, packIndex)[0])
packIndex += 8
resultItem = {
'personalID': personalID,
'charName': charName,
'refItemId': refItemId,
'itemContent': itemContent,
'price': price,
'regDate': regDate
}
result['items'].append(resultItem)
return result
data = b'\x01\x02\x01\xBB\x00\x00\x00\x07\x00\x4E\x69\x63\x6B\x73\x69\x7A\x00\x6E\x1B\x00\x00\x0B\x00\x00\x00\x20\xA1\x07\x00\x00\x00\x00\x00\x54\x40\xAF\x61\x00\x00\x00\x00\x1A\x00\x00\x00\x0A\x00\x44\x61\x72\x6B\x56\x6F\x6F\x44\x6F\x6F\x00\x32\x1B\x00\x00\x14\x00\x00\x00\x47\xF4\x10\x00\x00\x00\x00\x00\x34\x70\xAE\x61\x00\x00\x00\x00'
print(analyzeData(data))
And result:
{
"response":1,
"itemCount":2,
"pageCount":1,
"items":[
{
"personalID":187,
"charName":"Nicksiz",
"refItemId":7022,
"itemContent":0,
"price":500000,
"regDate":"07-12-2021 11:07:00"
},
{
"personalID":26,
"charName":"DarkVooDoo",
"refItemId":6962,
"itemContent":0,
"price":1111111,
"regDate":"06-12-2021 20:19:00"
}
]
}
Now, I have to come up with a solution to handle different item types