Formatting
This commit is contained in:
1 parent
2abe34e88c
commit
d9199a3e2a
11 files changed
+516
-431
No files matched your search
@@ -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
|
||||
@@ -41,35 +42,37 @@ 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'
|
||||
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):
|
||||
|
||||
class MinecraftLoginThread(threading.Thread):
|
||||
def __init__(self, username, password):
|
||||
threading.Thread.__init__(self)
|
||||
self.username = username
|
||||
|
||||
+39
-16
@@ -6,78 +6,99 @@ 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)
|
||||
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)
|
||||
@@ -88,11 +109,12 @@ def readEntityMetadata(FileObject):
|
||||
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
|
||||
}
|
||||
@@ -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
|
||||
@@ -42,8 +41,8 @@ class ServerConnection(threading.Thread):
|
||||
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
|
||||
@@ -65,7 +64,7 @@ class ServerConnection(threading.Thread):
|
||||
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()
|
||||
@@ -78,7 +77,7 @@ class ServerConnection(threading.Thread):
|
||||
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
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
|
||||
+362
-302
File diff suppressed because it is too large.
Load diff
@@ -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)
|
||||
@@ -2,7 +2,6 @@ import os
|
||||
import imp
|
||||
|
||||
class PluginLoader():
|
||||
|
||||
path = ""
|
||||
plugins = []
|
||||
listeners = []
|
||||
|
||||
+1
-3
@@ -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):
|
||||
|
||||
@@ -2,18 +2,16 @@ 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")
|
||||
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):
|
||||
@@ -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')
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ from pynbt.nbt import (
|
||||
TAG_List,
|
||||
TAG_Compound,
|
||||
TAG_Int_Array
|
||||
)
|
||||
)
|
||||
+4
-4
@@ -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()`.
|
||||
|
||||
@@ -6,21 +6,20 @@ 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")
|
||||
@@ -30,13 +29,13 @@ if __name__ == "__main__":
|
||||
|
||||
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):
|
||||
@@ -44,7 +43,7 @@ if __name__ == "__main__":
|
||||
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']
|
||||
@@ -53,7 +52,7 @@ if __name__ == "__main__":
|
||||
else:
|
||||
sessionid = None
|
||||
|
||||
if(options.server != ""):
|
||||
if (options.server != ""):
|
||||
serverAddress = options.server
|
||||
else:
|
||||
serverAddress = raw_input("Enter host and port if any: ")
|
||||
|
||||
Reference in new issue
Block a user