What are buffers exactly?
Well, in order to save on some bandwidth the kit packs a lot of character information that would be sent over the wire into binary buffers and then compresses it on top of that! These buffers are stored as blobs in the character database under character_buffer (they are also used for player accounts too). Not all information is stored in the buffer, but with Characters most of that information is.
If you want to interact with this information you will need to pull it out and decompress it. Below is some example code using in the auction process to show how this works.
Sample code
#Open up the Character DB...isolation_level is needed if you wish to write to it
dbconn = sqlite.connect("./data/character/character.db",isolation_level = None)
dcursor = dbconn.cursor()
dcursor.execute("BEGIN TRANSACTION;")
#Going to get the buffer and the name of the character
dcursor.execute("SELECT character_name, buffer from character_buffer;")
#Loop through the results
for name,buffer in dcursor.fetchall():
try:
#Decompress it using zlib
dbuffer = zlib.decompress(buffer)
#Write to a file so we can open it up as a DB
f = file("./data/tmp/abuffer","wb")
f.write(dbuffer)
f.close()
#Open that file up as a sqLite DB so we can work with it. At this point it is decompressed
bconn = sqlite.connect("./data/tmp/abuffer",isolation_level = None)
bcursor = bconn.cursor()
#Update the Auction IDN
bcursor.execute("UPDATE character SET auction_id_n = 0")
#Close DB and Cursor
bcursor.close()
bconn.close()
#Going to open the file again this time to dump it into a buffer
f = file("./data/tmp/abuffer","rb")
dbuffer = f.read()
f.close()
#Compress the file and make sure it is binary
dbuffer = zlib.compress(dbuffer)
dbuffer = sqlite.Binary(dbuffer)
#Values passed via the ? below. Used to make SQLite happy about the BLOB value for the buffer
values = (dbuffer,name)
#Update the Character DB with the new buffer
dcursor.execute("UPDATE character_buffer SET buffer = ? WHERE character_name = ?",values)
You can take this example and use it to do some other processes or check inside of buffers for anything you need.
