Provide data to plugins from chunk packets properly

This commit is contained in:
Ammar Askar 2012-12-26 20:07:34 +05:00
parent d9199a3e2a
commit 83ad822bad
3 changed files with 36 additions and 20 deletions

View File

@ -16,6 +16,7 @@ from Crypto.Cipher import PKCS1_v1_5
EntityID = 0
class ServerConnection(threading.Thread):
def __init__(self, pluginLoader, username, sessionID, server, port, options=None):
threading.Thread.__init__(self)
@ -116,7 +117,6 @@ class ServerConnection(threading.Thread):
print "Connection to server failed"
traceback.print_exc()
sys.exit(1)
return False
class EncryptedFileObjectHandler():

View File

@ -440,13 +440,17 @@ def handle2B(FileObject):
def handle33(FileObject):
X = DataUtil.readInt(FileObject)
Z = DataUtil.readInt(FileObject)
GroundUpContinous = DataUtil.readBoolean(FileObject)
GroundUpContinuous = DataUtil.readBoolean(FileObject)
PrimaryBitMap = DataUtil.readShort(FileObject)
AddBitMap = DataUtil.readShort(FileObject)
CompressedSize = DataUtil.readInt(FileObject)
FileObject.read(CompressedSize) #not going to be inflating and using this data until I know how to :3
RawData = FileObject.read(CompressedSize)
return {'x': X,
'z': Z
'z': Z,
'GroundUpContinuous': GroundUpContinuous,
'PrimaryBitMap': PrimaryBitMap,
'AddBitMap': AddBitMap,
'RawData': RawData
}
@ -521,14 +525,25 @@ def handle38(FileObject):
#int - chunk data length
ChunkDataLength = DataUtil.readInt(FileObject)
DataUtil.readBoolean(FileObject)
FileObject.read(ChunkDataLength) #just gonna ignore this for now
SkyLightSent = DataUtil.readBoolean(FileObject)
RawData = FileObject.read(ChunkDataLength)
#metadata - ignoring this
metadata = []
for i in range(ChunkCount):
FileObject.read(12)
ChunkX = DataUtil.readInt(FileObject)
ChunkZ = DataUtil.readInt(FileObject)
PrimaryBitMap = DataUtil.readUnsignedShort(FileObject)
AddBitMap = DataUtil.readUnsignedShort(FileObject)
metadata.append({'x': ChunkX,
'z': ChunkZ,
'PrimaryBitMap': PrimaryBitMap,
'AddBitMap': AddBitMap
})
return {'ChunkCount': ChunkCount
return {'ChunkCount': ChunkCount,
'SkyLightSent': SkyLightSent,
'RawData': RawData,
'ChunkMeta': metadata
}

View File

@ -1,5 +1,7 @@
import string
import copy
import base64
class PacketDumper:
options = None
@ -7,28 +9,27 @@ class PacketDumper:
def onEnable(self, parser):
parser.add_option("-d", "--dump-packets",
action="store_true", dest="dumpPackets", default=False,
help="run with this argument to dump packets")
action="store_true", dest="dumpPackets", default=False,
help="run with this argument to dump packets")
parser.add_option("-o", "--out-file", dest="filename", default="dump.txt",
help="file to dump packets to")
help="file to dump packets to")
def onDisable(self):
if (self.writeFile != None):
if self.writeFile is not None:
self.writeFile.close()
def optionsParsed(self, parsedOptions):
self.options = parsedOptions
if (self.options.dumpPackets):
if self.options.dumpPackets:
self.writeFile = open(self.options.filename, 'w')
def packetReceive(self, packetID, receivedPacket):
packet = copy.deepcopy(receivedPacket)
if (self.writeFile != None):
if (packetID == "\x33" or packetID == "\x38"):
packet = {'ChunkPlaceHolder': 0}
if (packetID == "\x03"):
if self.writeFile is not None:
if packetID == "\x33" or packetID == "\x38":
packet['Data'] = base64.b64encode(packet['RawData'])
del packet['RawData']
if packetID == "\x03":
packet['Message'] = filter(lambda x: x in string.printable, packet['Message'])
self.writeFile.write(hex(ord(packetID)) + " : " + str(packet) + '\n')