Quote:
Originally Posted by Theeper
Maybe I don't understand this, but wouldn't it be easier to just to create a format and unpack() the whole binary struct ? Especially if you want to repack it and update the DB.
I got about 1/3 of the way through creating the format before I got bored and moved on to something more interesting.
|
unpack() is certainly one way to do it. As a matter of fact, I started to work on a version of the same script to utilize unpack, but it can be difficult to modify if the profile blob ever changes, or if you make a mistake somewhere in the script. Not only that, but you would probably run into some issues when you have to create sub-arrays, like for bind points, item materials, item tints, AA's (which current has 240 sub-arrays), languages, spells in the spell book, memorized spells, skills, buffs, group members, tributes, disciplines, leadership abilities, bandoliers, and potion belts (whew!). The easiest way I've found so far to handle those is using for() statements. Otherwise, the script would be about 3x larger than it is right now. But, I do use it to convert data types (to float for example).
As far as efficiency, I'm not sure if unpack would take less time to process. I do know that, on the initial load (query and all), the page takes between 0.8 seconds & 1.3 seconds for PHP to process (including a Magelo-like character viewer), and on subsequent loads (after the query is cached), it takes between 0.3 seconds & 0.7 seconds to process. Of course, my server is a 433 MHz processor w/ 256MB of RAM that I had laying around.
As far as putting it back into the database, that's the easy part. There is a function, bin2asc(), listed on the page that converts the info from binary back to the ASCII format the blob is in. You can then inject it into the original $profileResult using substr_replace() or rebuild it from the array, and post it back into the database. The part I have been having trouble figuring out is the checksum, which I assume is the checksum of the blob, which I also assume prevents you from just injecting the changed info (although I haven't tested this yet). I've found how it is calculated in the source (see the checksum field in
profile schema ), but I'm having some trouble understanding it.