Formatting

This commit is contained in:
Ammar Askar 2012-12-26 01:38:02 +05:00
parent 2abe34e88c
commit d9199a3e2a
11 changed files with 667 additions and 582 deletions

View File

@ -7,16 +7,17 @@ from hashlib import sha1
# This function courtesy of barneygale
def javaHexDigest(digest):
d = long(digest.hexdigest(), 16)
if d >> 39*4 & 0x8:
d = "-%x" % ((-d) & (2**(40*4)-1))
if d >> 39 * 4 & 0x8:
d = "-%x" % ((-d) & (2 ** (40 * 4) - 1))
else:
d = "%x" % d
return d
def translate_escape(m):
c = m.group(1).lower()
if c == "0": return "\x1b[30m\x1b[21m" # black
if c == "0": return "\x1b[30m\x1b[21m" # black
elif c == "1": return "\x1b[34m\x1b[21m" # dark blue
elif c == "2": return "\x1b[32m\x1b[21m" # dark green
elif c == "3": return "\x1b[36m\x1b[21m" # dark cyan
@ -38,46 +39,48 @@ def translate_escape(m):
elif c == "n": return "\x1b[4m" # underline
elif c == "o": return "\x1b[3m" # italic (escape code not widely supported)
elif c == "r": return "\x1b[0m" # reset
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'
header = {'Content-Type' : 'application/x-www-form-urlencoded'}
data = {'user' : username,
'password' : password,
'version' : '13'}
header = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {'user': username,
'password': password,
'version': '13'}
data = urllib.urlencode(data)
req = urllib2.Request(url, data, header)
opener = urllib2.build_opener()
response = opener.open(req, None, 10)
response = response.read()
except urllib2.URLError:
return {'Response' : "Can't connect to minecraft.net"}
if(not "deprecated" in response.lower()):
return {'Response' : response}
return {'Response': "Can't connect to minecraft.net"}
if (not "deprecated" in response.lower()):
return {'Response': response}
response = response.split(":")
sessionid = response[3]
toReturn = {'Response' : "Good to go!",
'Username' : response[2],
'SessionID' : sessionid
}
toReturn = {'Response': "Good to go!",
'Username': response[2],
'SessionID': sessionid
}
return toReturn
class MinecraftLoginThread(threading.Thread):
def __init__(self, username, password):
threading.Thread.__init__(self)
self.username = username
self.password = password
def run(self):
self.response = loginToMinecraft(self.username, self.password)
def getResponse(self):
return self.response

View File

@ -6,93 +6,115 @@ 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'))
socket.send(value.encode('utf-16be'))
def readEntityMetadata(FileObject):
metadata = {}
byte = readUnsignedByte(FileObject)
while byte != 127:
index = byte & 0x1F # Lower 5 bits
ty = byte >> 5 # Upper 3 bits
ty = byte >> 5 # Upper 3 bits
if ty == 0: val = readByte(FileObject)
if ty == 1: val = readShort(FileObject)
if ty == 2: val = readInt(FileObject)
if ty == 3: val = readFloat(FileObject)
if ty == 4:
if ty == 4:
val = readString(FileObject)
if ty == 5:
val = {}
val["id"] = readShort(FileObject)
if (val["id"] != -1):
val["count"] = readByte(FileObject)
val["count"] = readByte(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,24 +123,25 @@ def readEntityMetadata(FileObject):
byte = readUnsignedByte(FileObject)
return metadata
def readSlotData(FileObject):
BlockID = readShort(FileObject)
if(BlockID != -1):
if (BlockID != -1):
ItemCount = readByte(FileObject)
Damage = readShort(FileObject)
MetadataLength = readShort(FileObject)
if(MetadataLength != -1):
if (MetadataLength != -1):
ByteArray = readByteArray(FileObject, MetadataLength)
NBTData = NBTFile(BytesIO(ByteArray), compression=NBTFile.Compression.GZIP)
return {'BlockID' : BlockID,
'ItemCount' : ItemCount,
'Damage' : Damage,
'Data' : NBTData
}
return {'BlockID' : BlockID,
'ItemCount' : ItemCount,
'Damage' : Damage
}
return {'BlockID' : -1,
'ItemCount' : 0
}
return {'BlockID': BlockID,
'ItemCount': ItemCount,
'Damage': Damage,
'Data': NBTData
}
return {'BlockID': BlockID,
'ItemCount': ItemCount,
'Damage': Damage
}
return {'BlockID': -1,
'ItemCount': 0
}

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
@ -27,45 +26,45 @@ class ServerConnection(threading.Thread):
self.sessionID = sessionID
self.server = server
self.port = port
def disconnect(self, reason="Disconnected by user"):
PacketSenderManager.sendFF(self.socket, reason)
self.listener.kill = True
self.socket.close()
def setWindow(self, window):
self.window = window
def grabSocket(self):
return self.socket
def run(self):
try:
#Create the socket and fileobject
self.socket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
self.socket.connect ( ( self.server, self.port ) )
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(( self.server, self.port ))
self.FileObject = self.socket.makefile()
#Send out the handshake packet
PacketSenderManager.sendHandshake(self.socket, self.username, self.server, self.port)
#Receive the encryption packet id
packetid = self.socket.recv(1)
#Sanity check the packet id
assert packetid == "\xFD", "Server didn't respond back to handshake with proper packet!"
#Parse the packet
packetFD = PacketListenerManager.handleFD(self.FileObject)
#Import the server's public key
self.pubkey = RSA.importKey(packetFD['Public Key'])
#Generate a 16 byte (128 bit) shared secret
self.sharedSecret = _UserFriendlyRNG.get_random_bytes(16)
#Authenticate the server from sessions.minecraft.net
if(packetFD['ServerID'] != '-'):
if (packetFD['ServerID'] != '-'):
try:
#Grab the server id
sha1 = hashlib.sha1()
@ -77,26 +76,26 @@ class ServerConnection(threading.Thread):
#Open up the url with the appropriate get parameters
url = "http://session.minecraft.net/game/joinserver.jsp?user=" + self.username + "&sessionId=" + self.sessionID + "&serverId=" + serverid
response = urllib2.urlopen(url).read()
if(response != "OK"):
if (response != "OK"):
print "Response from sessions.minecraft.net wasn't OK, it was " + response
return False
#Success \o/ We can now begin sending our serverAddress to the server
#Instantiate our main packet listener
self.listener = PacketListener(self, self.socket, self.FileObject)
self.listener.setDaemon(True)
self.listener.start()
#Encrypt the verification token from earlier along with our shared secret with the server's rsa key
self.RSACipher = PKCS1_v1_5.new(self.pubkey)
encryptedSanityToken = self.RSACipher.encrypt(str(packetFD['Token']))
encryptedSharedSecret = self.RSACipher.encrypt(str(self.sharedSecret))
#Send out a a packet FC to the server
PacketSenderManager.sendFC(self.socket, encryptedSharedSecret, encryptedSanityToken)
except Exception, e:
traceback.print_exc()
else:
@ -105,12 +104,12 @@ class ServerConnection(threading.Thread):
self.listener = PacketListener(self, self.socket, self.FileObject)
self.listener.setDaemon(True)
self.listener.start()
#Encrypt the verification token from earlier along with our shared secret with the server's rsa key
self.RSACipher = PKCS1_v1_5.new(self.pubkey)
encryptedSanityToken = self.RSACipher.encrypt(str(packetFD['Token']))
encryptedSharedSecret = self.RSACipher.encrypt(str(self.sharedSecret))
#Send out a a packet FC to the server
PacketSenderManager.sendFC(self.socket, encryptedSharedSecret, encryptedSanityToken)
except Exception, e:
@ -118,37 +117,37 @@ class ServerConnection(threading.Thread):
traceback.print_exc()
sys.exit(1)
return False
class EncryptedFileObjectHandler():
def __init__(self, fileobject, cipher):
self.fileobject = fileobject
self.cipher = cipher
self.length = 0
def read(self, length):
rawData = self.fileobject.read(length)
self.length += length
unencryptedData = self.cipher.decrypt(rawData)
return unencryptedData
def tell(self):
return self.length
class EncryptedSocketObjectHandler():
def __init__(self, socket, cipher):
self.socket = socket
self.cipher = cipher
def send(self, serverAddress):
self.socket.send(self.cipher.encrypt(serverAddress))
def close(self):
self.socket.close()
class PacketListener(threading.Thread):
def __init__(self, connection, socket, FileObject):
threading.Thread.__init__(self)
self.connection = connection
@ -156,24 +155,24 @@ class PacketListener(threading.Thread):
self.FileObject = FileObject
self.encryptedConnection = False
self.kill = False
def enableEncryption(self):
#Create an AES cipher from the previously obtained public key
self.cipher = AES.new(self.connection.sharedSecret, AES.MODE_CFB, IV=self.connection.sharedSecret)
self.decipher = AES.new(self.connection.sharedSecret, AES.MODE_CFB, IV=self.connection.sharedSecret)
self.rawsocket = self.socket
self.connection.rawsocket = self.connection.socket
self.socket = EncryptedSocketObjectHandler(self.rawsocket, self.cipher)
self.connection.socket = self.socket
self.rawFileObject = self.FileObject
self.connection.rawFileObject = self.connection.FileObject
self.FileObject = EncryptedFileObjectHandler(self.rawFileObject, self.decipher)
self.connection.FileObject = self.FileObject
self.encryptedConnection = True
def run(self):
while True:
if (self.kill):
@ -183,144 +182,145 @@ class PacketListener(threading.Thread):
if (response == ""):
continue
except Exception, e:
if(self.window):
if (self.window):
self.window.Status.SetLabel("Ping timeout")
else:
print "Ping timeout"
sys.exit()
break
if(response == "\x00"):
if (response == "\x00"):
packet = PacketListenerManager.handle00(self.FileObject, self.socket)
elif(response == "\x01"):
elif (response == "\x01"):
packet = PacketListenerManager.handle01(self.FileObject)
print "Logged in \o/ Received an entity id of " + str(packet['EntityID'])
elif(response == "\x03"):
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"):
elif (response == "\x04"):
packet = PacketListenerManager.handle04(self.FileObject)
elif(response == "\x05"):
elif (response == "\x05"):
packet = PacketListenerManager.handle05(self.FileObject)
elif(response == "\x06"):
elif (response == "\x06"):
packet = PacketListenerManager.handle06(self.FileObject)
elif(response == "\x07"):
elif (response == "\x07"):
packet = PacketListenerManager.handle07(self.FileObject)
elif(response == "\x08"):
elif (response == "\x08"):
packet = PacketListenerManager.handle08(self.FileObject)
elif(response == "\x09"):
elif (response == "\x09"):
packet = PacketListenerManager.handle09(self.FileObject)
elif(response == "\x0D"):
elif (response == "\x0D"):
packet = PacketListenerManager.handle0D(self.FileObject)
elif(response == "\x10"):
elif (response == "\x10"):
packet = PacketListenerManager.handle10(self.FileObject)
elif(response == "\x11"):
elif (response == "\x11"):
packet = PacketListenerManager.handle11(self.FileObject)
elif(response == "\x12"):
elif (response == "\x12"):
packet = PacketListenerManager.handle12(self.FileObject)
elif(response == "\x14"):
elif (response == "\x14"):
packet = PacketListenerManager.handle14(self.FileObject)
elif(response == "\x15"):
elif (response == "\x15"):
packet = PacketListenerManager.handle15(self.FileObject)
elif(response == "\x16"):
elif (response == "\x16"):
packet = PacketListenerManager.handle16(self.FileObject)
elif(response == "\x17"):
elif (response == "\x17"):
packet = PacketListenerManager.handle17(self.FileObject)
elif(response == "\x18"):
elif (response == "\x18"):
packet = PacketListenerManager.handle18(self.FileObject)
elif(response == "\x19"):
elif (response == "\x19"):
packet = PacketListenerManager.handle19(self.FileObject)
elif(response == "\x1A"):
elif (response == "\x1A"):
packet = PacketListenerManager.handle1A(self.FileObject)
elif(response == "\x1C"):
elif (response == "\x1C"):
packet = PacketListenerManager.handle1C(self.FileObject)
elif(response == "\x1D"):
elif (response == "\x1D"):
packet = PacketListenerManager.handle1D(self.FileObject)
elif(response == "\x1E"):
elif (response == "\x1E"):
packet = PacketListenerManager.handle1E(self.FileObject)
elif(response == "\x1F"):
elif (response == "\x1F"):
packet = PacketListenerManager.handle1F(self.FileObject)
elif(response == "\x20"):
elif (response == "\x20"):
packet = PacketListenerManager.handle20(self.FileObject)
elif(response == "\x21"):
elif (response == "\x21"):
packet = PacketListenerManager.handle21(self.FileObject)
elif(response == "\x22"):
elif (response == "\x22"):
packet = PacketListenerManager.handle22(self.FileObject)
elif(response == "\x23"):
elif (response == "\x23"):
packet = PacketListenerManager.handle23(self.FileObject)
elif(response == "\x26"):
elif (response == "\x26"):
packet = PacketListenerManager.handle26(self.FileObject)
elif(response == "\x27"):
elif (response == "\x27"):
packet = PacketListenerManager.handle27(self.FileObject)
elif(response == "\x28"):
elif (response == "\x28"):
packet = PacketListenerManager.handle28(self.FileObject)
elif(response == "\x29"):
elif (response == "\x29"):
packet = PacketListenerManager.handle29(self.FileObject)
elif(response == "\x2A"):
elif (response == "\x2A"):
packet = PacketListenerManager.handle2A(self.FileObject)
elif(response == "\x2B"):
elif (response == "\x2B"):
packet = PacketListenerManager.handle2B(self.FileObject)
elif(response == "\x33"):
elif (response == "\x33"):
packet = PacketListenerManager.handle33(self.FileObject)
elif(response == "\x34"):
elif (response == "\x34"):
packet = PacketListenerManager.handle34(self.FileObject)
elif(response == "\x35"):
elif (response == "\x35"):
packet = PacketListenerManager.handle35(self.FileObject)
elif(response == "\x36"):
elif (response == "\x36"):
packet = PacketListenerManager.handle36(self.FileObject)
elif(response == "\x37"):
elif (response == "\x37"):
packet = PacketListenerManager.handle37(self.FileObject)
elif(response == "\x38"):
elif (response == "\x38"):
packet = PacketListenerManager.handle38(self.FileObject)
elif(response == "\x3C"):
elif (response == "\x3C"):
packet = PacketListenerManager.handle3C(self.FileObject)
elif(response == "\x3D"):
elif (response == "\x3D"):
packet = PacketListenerManager.handle3D(self.FileObject)
elif(response == "\x3E"):
elif (response == "\x3E"):
packet = PacketListenerManager.handle3E(self.FileObject)
elif(response == "\x46"):
elif (response == "\x46"):
packet = PacketListenerManager.handle46(self.FileObject)
elif(response == "\x47"):
elif (response == "\x47"):
packet = PacketListenerManager.handle47(self.FileObject)
elif(response == "\x64"):
elif (response == "\x64"):
packet = PacketListenerManager.handle64(self.FileObject)
elif(response == "\x65"):
elif (response == "\x65"):
packet = PacketListenerManager.handle65(self.FileObject)
elif(response == "\x67"):
elif (response == "\x67"):
packet = PacketListenerManager.handle67(self.FileObject)
elif(response == "\x68"):
elif (response == "\x68"):
packet = PacketListenerManager.handle68(self.FileObject)
elif(response == "\x69"):
elif (response == "\x69"):
packet = PacketListenerManager.handle69(self.FileObject)
elif(response == "\x6A"):
elif (response == "\x6A"):
packet = PacketListenerManager.handle6A(self.FileObject)
elif(response == "\x6B"):
elif (response == "\x6B"):
packet = PacketListenerManager.handle6B(self.FileObject)
elif(response == "\x82"):
elif (response == "\x82"):
packet = PacketListenerManager.handle82(self.FileObject)
elif(response == "\x83"):
elif (response == "\x83"):
packet = PacketListenerManager.handle83(self.FileObject)
elif(response == "\x84"):
elif (response == "\x84"):
packet = PacketListenerManager.handle84(self.FileObject)
elif(response == "\xC8"):
elif (response == "\xC8"):
packet = PacketListenerManager.handleC8(self.FileObject)
elif(response == "\xC9"):
elif (response == "\xC9"):
packet = PacketListenerManager.handleC9(self.FileObject)
elif(response == "\xCA"):
elif (response == "\xCA"):
packet = PacketListenerManager.handleCA(self.FileObject)
elif(response == "\xCB"):
elif (response == "\xCB"):
packet = PacketListenerManager.handleCB(self.FileObject)
elif(response == "\xFA"):
elif (response == "\xFA"):
packet = PacketListenerManager.handleFA(self.FileObject)
elif(response == "\xFC"):
elif (response == "\xFC"):
packet = PacketListenerManager.handleFC(self.FileObject)
if (not self.encryptedConnection):
self.enableEncryption()
self.connection.isConnected = True
PacketSenderManager.sendCD(self.socket, 0)
elif(response == "\xFF"):
elif (response == "\xFF"):
packet = PacketListenerManager.handleFF(self.FileObject)
print "Disconnected: " + packet['Reason']
self.connection.disconnect()
@ -333,7 +333,7 @@ class PacketListener(threading.Thread):
self.connection.pluginLoader.disablePlugins()
sys.exit(1)
break
# Invoke plugin listeners
for listener in self.connection.pluginLoader.getPacketListeners():
listener(response, packet)

File diff suppressed because it is too large Load Diff

View File

@ -3,52 +3,57 @@ import DataUtil
def send00(socket, KAid):
#packet id
socket.send("\x00")
#int - keep alive id
DataUtil.sendInt(socket, KAid)
def sendHandshake(socket, username, host, port):
#packet id
socket.send("\x02")
#byte - protocol version
DataUtil.sendByte(socket, 51)
#string - username
DataUtil.sendString(socket, username)
#string - server host
DataUtil.sendString(socket, host)
#int - server port
DataUtil.sendInt(socket, port)
def send03(socket, message):
#packet id
socket.send("\x03")
#-----string - message-----#
DataUtil.sendString(socket, message)
def sendCD(socket, payload):
#packet id
socket.send("\xCD")
#payload - byte
DataUtil.sendByte(socket, payload)
def sendFC(socket, secret, token):
#packet id
socket.send("\xFC")
#shared secret
DataUtil.sendShort(socket, secret.__len__()) #length
socket.send(secret)
#token
DataUtil.sendShort(socket, token.__len__())
socket.send(token)
def sendFF(socket, reason):
#string - disconnect reason
DataUtil.sendString(socket, reason)

View File

@ -2,14 +2,13 @@ import os
import imp
class PluginLoader():
path = ""
plugins = []
listeners = []
def __init__(self, path):
self.path = path
def loadPlugins(self, parser):
for item in os.listdir(self.path):
@ -33,23 +32,23 @@ class PluginLoader():
pass
except AttributeError:
print "Plugin " + name + " is malformed"
def disablePlugins(self):
for plugin in self.plugins:
try:
plugin.onDisable()
except AttributeError:
pass
def notifyOptions(self, options):
for plugin in self.plugins:
try:
plugin.optionsParsed(options)
except AttributeError:
pass
def getPlugins(self):
return self.plugins
def getPacketListeners(self):
return self.listeners

View File

@ -1,12 +1,10 @@
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")
help="file to dump messages to")
def onDisable(self):
if (self.writeFile != None):

View File

@ -2,23 +2,21 @@ 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")
parser.add_option("-d", "--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):
self.writeFile.close()
def optionsParsed(self, parsedOptions):
self.options = parsedOptions
if (self.options.dumpPackets):
@ -28,7 +26,7 @@ class PacketDumper:
packet = copy.deepcopy(receivedPacket)
if (self.writeFile != None):
if (packetID == "\x33" or packetID == "\x38"):
packet = {'ChunkPlaceHolder' : 0}
packet = {'ChunkPlaceHolder': 0}
if (packetID == "\x03"):
packet['Message'] = filter(lambda x: x in string.printable, packet['Message'])
self.writeFile.write(hex(ord(packetID)) + " : " + str(packet) + '\n')

View File

@ -12,4 +12,4 @@ from pynbt.nbt import (
TAG_List,
TAG_Compound,
TAG_Int_Array
)
)

View File

@ -46,7 +46,7 @@ class BaseTag(object):
# A tag of 0 means we've reached TAG_End, used to terminate
# a TAG_Compound.
break
# We read in each tag in turn, using its name as the key in
# We read in each tag in turn, using its name as the key in
# the dict (Since a compound cannot have repeating names,
# this works fine).
tmp = _tags[tag].read(read)
@ -113,7 +113,7 @@ class BaseTag(object):
elif isinstance(self, TAG_Compound):
for v in self.value.values():
v.write(write)
# A tag of type 0 (TAg_End) terminates a TAG_Compound.
# A tag of type 0 (TAg_End) terminates a TAG_Compound.
write('b', 0)
elif isinstance(self, TAG_String):
self._write_utf8(write, self.value)
@ -280,7 +280,7 @@ _tags = (
TAG_List,
TAG_Compound,
TAG_Int_Array
)
)
class NBTFile(TAG_Compound):
@ -295,7 +295,7 @@ class NBTFile(TAG_Compound):
GZIP = 20
def __init__(self, io=None, name=None, value=None, compression=None,
little_endian=False):
little_endian=False):
"""
Creates a new NBTFile or loads one from any file-like object providing
`read()`.

View File

@ -6,45 +6,44 @@ from networking import PacketSenderManager, NetworkManager
from optparse import OptionParser
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-u", "--username", dest="username", default="",
help="username to log in with")
help="username to log in with")
parser.add_option("-p", "--password", dest="password", default="",
help="password to log in with")
help="password to log in with")
parser.add_option("-s", "--server", dest="server", default="",
help="server to connect to")
help="server to connect to")
parser.add_option("-x", "--offline-mode", dest="offlineMode",
action="store_true", default=False,
help="run in offline mode i.e don't attempt to auth via minecraft.net")
action="store_true", default=False,
help="run in offline mode i.e don't attempt to auth via minecraft.net")
# pluginLoader
pluginLoader = PluginLoader("plugins")
pluginLoader.loadPlugins(parser)
(options, args) = parser.parse_args()
pluginLoader.notifyOptions(options)
if(options.username != ""):
if (options.username != ""):
user = options.username
else:
user = raw_input("Enter your username: ")
if(options.password != ""):
if (options.password != ""):
passwd = options.password
elif(not options.offlineMode):
elif (not options.offlineMode):
passwd = getpass.getpass("Enter your password: ")
if (not options.offlineMode):
loginThread = Utils.MinecraftLoginThread(user, passwd)
loginThread.start()
loginThread.join()
loginResponse = loginThread.getResponse()
if(loginResponse['Response'] != "Good to go!"):
if (loginResponse['Response'] != "Good to go!"):
print loginResponse['Response']
sys.exit(1)
sessionid = loginResponse['SessionID']
@ -52,8 +51,8 @@ if __name__ == "__main__":
print "Logged in as " + loginResponse['Username'] + "! Your session id is: " + sessionid
else:
sessionid = None
if(options.server != ""):
if (options.server != ""):
serverAddress = options.server
else:
serverAddress = raw_input("Enter host and port if any: ")
@ -71,9 +70,9 @@ if __name__ == "__main__":
try:
chat_input = raw_input()
if (connection.isConnected):
PacketSenderManager.send03(connection.grabSocket(), chat_input)
PacketSenderManager.send03(connection.grabSocket(), chat_input)
else:
pass
pass
except KeyboardInterrupt, e:
connection.disconnect()
pluginLoader.disablePlugins()