From 83ad822bad9e92ef6066fd17d4d0e657d8bed1d3 Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Wed, 26 Dec 2012 20:07:34 +0500 Subject: [PATCH] Provide data to plugins from chunk packets properly --- networking/NetworkManager.py | 2 +- networking/PacketListenerManager.py | 31 +++++++++++++++++++++-------- plugins/PacketDumper.py | 23 +++++++++++---------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/networking/NetworkManager.py b/networking/NetworkManager.py index 0681ce3..1d2374c 100644 --- a/networking/NetworkManager.py +++ b/networking/NetworkManager.py @@ -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(): diff --git a/networking/PacketListenerManager.py b/networking/PacketListenerManager.py index b91a371..3913605 100644 --- a/networking/PacketListenerManager.py +++ b/networking/PacketListenerManager.py @@ -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 } diff --git a/plugins/PacketDumper.py b/plugins/PacketDumper.py index 57b14fc..62d378d 100644 --- a/plugins/PacketDumper.py +++ b/plugins/PacketDumper.py @@ -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') - - \ No newline at end of file