Formatting

This commit is contained in:
Ammar Askar committed 2012-12-26 01:38:02 +05:00
1 parent 2abe34e88c
commit d9199a3e2a
9 files changed
+100 -15

No files matched your search

+4 -1
View File
@@ -13,6 +13,7 @@ def javaHexDigest(digest):
d = "%x" % d
return d
def translate_escape(m):
c = m.group(1).lower()
@@ -41,9 +42,11 @@ def translate_escape(m):
return ""
def translate_escapes(s):
return re.sub(ur"\xa7([0-9a-zA-Z])", translate_escape, s) + "\x1b[0m"
def loginToMinecraft(username, password):
try:
url = 'https://login.minecraft.net'
@@ -68,8 +71,8 @@ def loginToMinecraft(username, password):
}
return toReturn
class MinecraftLoginThread(threading.Thread):
class MinecraftLoginThread(threading.Thread):
def __init__(self, username, password):
threading.Thread.__init__(self)
self.username = username
+24 -1
View File
@@ -6,72 +6,93 @@ from pynbt import NBTFile
def readBoolean(FileObject):
return struct.unpack('?', FileObject.read(1))[0]
def readByte(FileObject):
return struct.unpack('>b', FileObject.read(1))[0]
def readUnsignedByte(FileObject):
return struct.unpack('>B', FileObject.read(1))[0]
def readShort(FileObject):
return struct.unpack('>h', FileObject.read(2))[0]
def readUnsignedShort(FileObject):
return struct.unpack('>H', FileObject.read(2))[0]
def readInt(FileObject):
return struct.unpack('>i', FileObject.read(4))[0]
def readFloat(FileObject):
return struct.unpack('>f', FileObject.read(4))[0]
def readLong(FileObject):
return struct.unpack('>q', FileObject.read(8))[0]
def readDouble(FileObject):
return struct.unpack('>d', FileObject.read(8))[0]
def readByteArray(FileObject, length):
return struct.unpack(str(length) + "s", FileObject.read(length))[0]
def readString(FileObject):
length = readShort(FileObject) * 2
return FileObject.read(length).decode("utf-16be")
def sendBoolean(socket, value):
assert type(value) is types.BooleanType, "value is not a boolean: %r" % value
socket.send(struct.pack('?', value))
def sendByte(socket, value):
socket.send(struct.pack('>b', value))
def sendUnsignedByte(socket, value):
socket.send(struct.pack('>B', value))
def sendShort(socket, value):
socket.send(struct.pack('>h', value))
def sendUnsignedShort(socket, value):
socket.send(struct.pack('>H', value))
def sendInt(socket, value):
assert type(value) is types.IntType, "value is not an integer: %r" % value
socket.send(struct.pack('>i', value))
def sendFloat(socket, value):
socket.send(struct.pack('>f', value))
def sendLong(socket, value):
socket.send(struct.pack('>q', value))
def sendDouble(socket, value):
socket.send(struct.pack('>d', value))
def sendString(socket, value):
if (type(value) is not types.StringType):
value = str(value)
socket.send(struct.pack('>h', value.__len__()))
socket.send(value.encode('utf-16be'))
def readEntityMetadata(FileObject):
metadata = {}
byte = readUnsignedByte(FileObject)
@@ -92,7 +113,8 @@ def readEntityMetadata(FileObject):
val["damage"] = readShort(FileObject)
nbtDataLength = readShort(FileObject)
if (nbtDataLength != -1):
val["NBT"] = NBTFile(BytesIO(readByteArray(FileObject, nbtDataLength)), compression=NBTFile.Compression.GZIP)
val["NBT"] = NBTFile(BytesIO(readByteArray(FileObject, nbtDataLength)),
compression=NBTFile.Compression.GZIP)
if ty == 6:
val = []
for i in range(3):
@@ -101,6 +123,7 @@ def readEntityMetadata(FileObject):
byte = readUnsignedByte(FileObject)
return metadata
def readSlotData(FileObject):
BlockID = readShort(FileObject)
if (BlockID != -1):
+5 -5
View File
@@ -17,7 +17,6 @@ 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)
self.pluginLoader = pluginLoader
@@ -119,8 +118,8 @@ class ServerConnection(threading.Thread):
sys.exit(1)
return False
class EncryptedFileObjectHandler():
class EncryptedFileObjectHandler():
def __init__(self, fileobject, cipher):
self.fileobject = fileobject
self.cipher = cipher
@@ -135,8 +134,8 @@ class EncryptedFileObjectHandler():
def tell(self):
return self.length
class EncryptedSocketObjectHandler():
class EncryptedSocketObjectHandler():
def __init__(self, socket, cipher):
self.socket = socket
self.cipher = cipher
@@ -147,8 +146,8 @@ class EncryptedSocketObjectHandler():
def close(self):
self.socket.close()
class PacketListener(threading.Thread):
class PacketListener(threading.Thread):
def __init__(self, connection, socket, FileObject):
threading.Thread.__init__(self)
self.connection = connection
@@ -197,7 +196,8 @@ class PacketListener(threading.Thread):
elif (response == "\x03"):
packet = PacketListenerManager.handle03(self.FileObject)
# Add "\x1b" because it is essential for ANSI escapes emitted by translate_escapes
filtered_string = filter(lambda x: x in string.printable + "\x1b", Utils.translate_escapes(packet['Message']))
filtered_string = filter(lambda x: x in string.printable + "\x1b",
Utils.translate_escapes(packet['Message']))
print filtered_string
elif (response == "\x04"):
+62 -2
View File
@@ -7,6 +7,7 @@ def handle00(FileObject, socket):
KAid = DataUtil.readInt(FileObject)
PacketSenderManager.send00(socket, KAid)
def handle01(FileObject):
Eid = DataUtil.readInt(FileObject)
world = DataUtil.readString(FileObject)
@@ -23,14 +24,17 @@ def handle01(FileObject):
'MaxPlayers': maxplayers
}
def handle02(FileObject):
message = DataUtil.readString(FileObject)
return message
def handle03(FileObject):
message = DataUtil.readString(FileObject)
return {'Message': message}
def handle04(FileObject):
time = DataUtil.readLong(FileObject)
dayTime = DataUtil.readLong(FileObject)
@@ -38,6 +42,7 @@ def handle04(FileObject):
'DayTime': dayTime
}
def handle05(FileObject):
EntityID = DataUtil.readInt(FileObject)
Slot = DataUtil.readShort(FileObject)
@@ -47,6 +52,7 @@ def handle05(FileObject):
'Item': Item
}
def handle06(FileObject):
x = DataUtil.readInt(FileObject)
y = DataUtil.readInt(FileObject)
@@ -56,6 +62,7 @@ def handle06(FileObject):
'z': z
}
def handle07(FileObject):
userID = DataUtil.readInt(FileObject)
targetID = DataUtil.readInt(FileObject)
@@ -65,6 +72,7 @@ def handle07(FileObject):
'mButton': mButton
}
def handle08(FileObject):
health = DataUtil.readShort(FileObject)
food = DataUtil.readShort(FileObject)
@@ -74,6 +82,7 @@ def handle08(FileObject):
'saturation': saturation
}
def handle09(FileObject):
dimension = DataUtil.readInt(FileObject)
difficulty = DataUtil.readByte(FileObject)
@@ -87,6 +96,7 @@ def handle09(FileObject):
'World': world
}
def handle0D(FileObject):
x = DataUtil.readDouble(FileObject)
stance = DataUtil.readDouble(FileObject)
@@ -104,10 +114,12 @@ def handle0D(FileObject):
'onGround': onGround
}
def handle10(FileObject):
slotID = DataUtil.readShort(FileObject)
return {'SlotID': slotID}
def handle11(FileObject):
EntityID = DataUtil.readInt(FileObject)
FileObject.read(1) #Unused
@@ -120,6 +132,7 @@ def handle11(FileObject):
'z': z
}
def handle12(FileObject):
EntityID = DataUtil.readInt(FileObject)
Animation = DataUtil.readByte(FileObject)
@@ -127,6 +140,7 @@ def handle12(FileObject):
'AnimationID': Animation
}
def handle14(FileObject):
EntityID = DataUtil.readInt(FileObject)
PlayerName = DataUtil.readString(FileObject)
@@ -149,6 +163,7 @@ def handle14(FileObject):
}
return toReturn
def handle15(FileObject):
EntityID = DataUtil.readInt(FileObject)
ItemID = DataUtil.readShort(FileObject)
@@ -178,6 +193,7 @@ def handle15(FileObject):
toReturn['Damage'] = Damage
return toReturn
def handle16(FileObject):
CollectedID = DataUtil.readInt(FileObject)
CollectorID = DataUtil.readInt(FileObject)
@@ -185,6 +201,7 @@ def handle16(FileObject):
'CollectorID': CollectorID
}
def handle17(FileObject):
EntityID = DataUtil.readInt(FileObject)
Type = DataUtil.readByte(FileObject)
@@ -219,6 +236,7 @@ def handle17(FileObject):
'pitch': pitch
}
def handle18(FileObject):
EntityID = DataUtil.readInt(FileObject)
Type = DataUtil.readByte(FileObject)
@@ -247,6 +265,7 @@ def handle18(FileObject):
'VelocityZ': VelocityZ
}
def handle19(FileObject):
EntityID = DataUtil.readInt(FileObject)
Title = DataUtil.readString(FileObject)
@@ -262,6 +281,7 @@ def handle19(FileObject):
'Direction': Direction
}
def handle1A(FileObject):
EntityID = DataUtil.readInt(FileObject)
x = DataUtil.readInt(FileObject)
@@ -275,6 +295,7 @@ def handle1A(FileObject):
'Count': Count
}
def handle1C(FileObject):
EntityID = DataUtil.readInt(FileObject)
VelocityX = DataUtil.readShort(FileObject)
@@ -286,6 +307,7 @@ def handle1C(FileObject):
'VelocityZ': VelocityZ
}
def handle1D(FileObject):
EntityArrayLength = DataUtil.readByte(FileObject)
Entities = []
@@ -293,10 +315,12 @@ def handle1D(FileObject):
Entities.append(DataUtil.readInt(FileObject))
return Entities
def handle1E(FileObject):
EntityID = DataUtil.readInt(FileObject)
return EntityID
def handle1F(FileObject):
EntityID = DataUtil.readInt(FileObject)
x = DataUtil.readByte(FileObject)
@@ -308,6 +332,7 @@ def handle1F(FileObject):
'z': z
}
def handle20(FileObject):
EntityID = DataUtil.readInt(FileObject)
Yaw = DataUtil.readByte(FileObject)
@@ -317,6 +342,7 @@ def handle20(FileObject):
'Pitch': Pitch
}
def handle21(FileObject):
EntityID = DataUtil.readInt(FileObject)
x = DataUtil.readByte(FileObject)
@@ -332,6 +358,7 @@ def handle21(FileObject):
'Pitch': Pitch
}
def handle22(FileObject):
EntityID = DataUtil.readInt(FileObject)
x = DataUtil.readInt(FileObject)
@@ -347,6 +374,7 @@ def handle22(FileObject):
'Pitch': Pitch
}
def handle23(FileObject):
EntityID = DataUtil.readInt(FileObject)
HeadYaw = DataUtil.readByte(FileObject)
@@ -354,6 +382,7 @@ def handle23(FileObject):
'HeadYaw': HeadYaw
}
def handle26(FileObject):
EntityID = DataUtil.readInt(FileObject)
Status = DataUtil.readByte(FileObject)
@@ -361,6 +390,7 @@ def handle26(FileObject):
'Status': Status
}
def handle27(FileObject):
EntityID = DataUtil.readInt(FileObject)
VehicleID = DataUtil.readInt(FileObject)
@@ -368,6 +398,7 @@ def handle27(FileObject):
'VehicleID': VehicleID
}
def handle28(FileObject):
EntityID = DataUtil.readInt(FileObject)
metadata = DataUtil.readEntityMetadata(FileObject)
@@ -375,6 +406,7 @@ def handle28(FileObject):
'MetaData': metadata
}
def handle29(FileObject):
EntityID = DataUtil.readInt(FileObject)
EffectID = DataUtil.readByte(FileObject)
@@ -386,6 +418,7 @@ def handle29(FileObject):
'Duration': Duration
}
def handle2A(FileObject):
EntityID = DataUtil.readInt(FileObject)
EffectID = DataUtil.readByte(FileObject)
@@ -393,6 +426,7 @@ def handle2A(FileObject):
'EffectID': EffectID
}
def handle2B(FileObject):
ExperienceBar = DataUtil.readFloat(FileObject)
Level = DataUtil.readShort(FileObject)
@@ -402,6 +436,7 @@ def handle2B(FileObject):
'TotalExp': TotalExp
}
def handle33(FileObject):
X = DataUtil.readInt(FileObject)
Z = DataUtil.readInt(FileObject)
@@ -414,6 +449,7 @@ def handle33(FileObject):
'z': Z
}
def handle34(FileObject):
ChunkX = DataUtil.readInt(FileObject)
ChunkZ = DataUtil.readInt(FileObject)
@@ -425,6 +461,7 @@ def handle34(FileObject):
'AffectedBlocks': AffectedBlocks
}
def handle35(FileObject):
X = DataUtil.readInt(FileObject)
Y = DataUtil.readByte(FileObject)
@@ -438,6 +475,7 @@ def handle35(FileObject):
'MetaData': BlockMetaData
}
def handle36(FileObject):
X = DataUtil.readInt(FileObject)
Y = DataUtil.readShort(FileObject)
@@ -453,6 +491,7 @@ def handle36(FileObject):
'BlockID': BlockID
}
def handle37(FileObject):
#int - EntityID
EntityID = DataUtil.readInt(FileObject)
@@ -475,6 +514,7 @@ def handle37(FileObject):
'DestroyedStage': DestroyedStage
}
def handle38(FileObject):
#short - number of chunks
ChunkCount = DataUtil.readShort(FileObject)
@@ -491,6 +531,7 @@ def handle38(FileObject):
return {'ChunkCount': ChunkCount
}
def handle3C(FileObject):
X = DataUtil.readDouble(FileObject)
Y = DataUtil.readDouble(FileObject)
@@ -515,6 +556,7 @@ def handle3C(FileObject):
'AffectedBlocks': AffectedBlocks
}
def handle3D(FileObject):
EffectID = DataUtil.readInt(FileObject)
X = DataUtil.readInt(FileObject)
@@ -530,6 +572,7 @@ def handle3D(FileObject):
'NoVolumeDecrease': NoVolDecrease
}
def handle3E(FileObject):
Sound = DataUtil.readString(FileObject)
x = DataUtil.readInt(FileObject)
@@ -545,6 +588,7 @@ def handle3E(FileObject):
'Pitch': Pitch
}
def handle46(FileObject):
Reason = DataUtil.readByte(FileObject)
GameMode = DataUtil.readByte(FileObject)
@@ -552,6 +596,7 @@ def handle46(FileObject):
'GameMode': GameMode
}
def handle47(FileObject):
EntityID = DataUtil.readInt(FileObject)
FileObject.read(1) #Boolean don't do nothing
@@ -564,6 +609,7 @@ def handle47(FileObject):
'z': z
}
def handle64(FileObject):
WindowID = DataUtil.readByte(FileObject)
InventoryType = DataUtil.readByte(FileObject)
@@ -575,10 +621,12 @@ def handle64(FileObject):
'NumberOfSlots': NumberOfSlots
}
def handle65(FileObject):
WindowID = DataUtil.readByte(FileObject)
return WindowID
def handle67(FileObject):
WindowID = DataUtil.readByte(FileObject)
Slot = DataUtil.readShort(FileObject)
@@ -588,6 +636,7 @@ def handle67(FileObject):
'SlotData': SlotData
}
def handle68(FileObject):
WindowID = DataUtil.readByte(FileObject)
Count = DataUtil.readShort(FileObject)
@@ -600,6 +649,7 @@ def handle68(FileObject):
'Slots': Slots
}
def handle69(FileObject):
WindowID = DataUtil.readByte(FileObject)
Property = DataUtil.readShort(FileObject)
@@ -609,6 +659,7 @@ def handle69(FileObject):
'Value': Value
}
def handle6A(FileObject):
WindowID = DataUtil.readByte(FileObject)
ActionType = DataUtil.readShort(FileObject)
@@ -618,6 +669,7 @@ def handle6A(FileObject):
'Accepted': Accepted
}
def handle6B(FileObject):
Slot = DataUtil.readShort(FileObject)
ClickedItem = DataUtil.readSlotData(FileObject)
@@ -625,6 +677,7 @@ def handle6B(FileObject):
'ClickedItem': ClickedItem
}
def handle82(FileObject):
X = DataUtil.readInt(FileObject)
Y = DataUtil.readShort(FileObject)
@@ -642,6 +695,7 @@ def handle82(FileObject):
'Line4': Line4
}
def handle83(FileObject):
ItemType = DataUtil.readShort(FileObject)
ItemID = DataUtil.readShort(FileObject)
@@ -652,6 +706,7 @@ def handle83(FileObject):
'Text': Text
}
def handle84(FileObject):
X = DataUtil.readInt(FileObject)
Y = DataUtil.readShort(FileObject)
@@ -673,6 +728,7 @@ def handle84(FileObject):
'Action': Action
}
def handleC8(FileObject):
StatID = DataUtil.readInt(FileObject)
Amount = DataUtil.readByte(FileObject)
@@ -680,6 +736,7 @@ def handleC8(FileObject):
'Amount': Amount
}
def handleC9(FileObject):
PlayerName = DataUtil.readString(FileObject)
Online = DataUtil.readBoolean(FileObject)
@@ -689,6 +746,7 @@ def handleC9(FileObject):
'Ping': Ping
}
def handleCA(FileObject):
#byte - flags
Flags = DataUtil.readByte(FileObject)
@@ -703,10 +761,12 @@ def handleCA(FileObject):
'Walk Speed': WalkSpeed
}
def handleCB(FileObject):
text = DataUtil.readString(FileObject)
return {'Text': text}
def handleFA(FileObject):
Channel = DataUtil.readString(FileObject)
length = DataUtil.readShort(FileObject)
@@ -715,8 +775,8 @@ def handleFA(FileObject):
'message': message
}
def handleFC(FileObject):
def handleFC(FileObject):
#short - shared secret length
secretLength = DataUtil.readShort(FileObject)
@@ -735,7 +795,6 @@ def handleFC(FileObject):
def handleFD(FileObject):
#string - server id
serverid = DataUtil.readString(FileObject)
@@ -756,6 +815,7 @@ def handleFD(FileObject):
'Token': token
}
def handleFF(FileObject):
Reason = DataUtil.readString(FileObject)
return {'Reason': Reason}
+5
View File
@@ -7,6 +7,7 @@ def send00(socket, KAid):
#int - keep alive id
DataUtil.sendInt(socket, KAid)
def sendHandshake(socket, username, host, port):
#packet id
socket.send("\x02")
@@ -23,6 +24,7 @@ def sendHandshake(socket, username, host, port):
#int - server port
DataUtil.sendInt(socket, port)
def send03(socket, message):
#packet id
socket.send("\x03")
@@ -30,6 +32,7 @@ def send03(socket, message):
#-----string - message-----#
DataUtil.sendString(socket, message)
def sendCD(socket, payload):
#packet id
socket.send("\xCD")
@@ -37,6 +40,7 @@ def sendCD(socket, payload):
#payload - byte
DataUtil.sendByte(socket, payload)
def sendFC(socket, secret, token):
#packet id
socket.send("\xFC")
@@ -49,6 +53,7 @@ def sendFC(socket, secret, token):
DataUtil.sendShort(socket, token.__len__())
socket.send(token)
def sendFF(socket, reason):
#string - disconnect reason
DataUtil.sendString(socket, reason)
-1
View File
@@ -2,7 +2,6 @@ import os
import imp
class PluginLoader():
path = ""
plugins = []
listeners = []
-2
View File
@@ -1,10 +1,8 @@
class IRC:
options = None
writeFile = None
def onEnable(self, parser):
parser.add_option("-q", "--irc-out-file", dest="ircDump", default="ircdump.txt",
help="file to dump messages to")
-2
View File
@@ -2,12 +2,10 @@ import string
import copy
class PacketDumper:
options = None
writeFile = None
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")
-1
View File
@@ -6,7 +6,6 @@ from networking import PacketSenderManager, NetworkManager
from optparse import OptionParser
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-u", "--username", dest="username", default="",