2012-04-07 16:02:46 +02:00
|
|
|
import socket
|
2012-04-15 18:49:47 +02:00
|
|
|
import PacketListenerManager
|
2012-04-07 16:02:46 +02:00
|
|
|
import urllib2
|
|
|
|
import traceback
|
2012-04-10 21:14:32 +02:00
|
|
|
import threading
|
2012-09-02 19:54:16 +02:00
|
|
|
import hashlib
|
|
|
|
import string
|
2013-01-31 16:42:47 +01:00
|
|
|
import unicodedata
|
2012-09-05 21:28:55 +02:00
|
|
|
import Utils
|
2012-09-11 17:03:36 +02:00
|
|
|
import sys
|
2013-09-24 21:31:17 +02:00
|
|
|
import random
|
2012-09-02 19:54:16 +02:00
|
|
|
from networking import PacketSenderManager
|
|
|
|
from Crypto.Random import _UserFriendlyRNG
|
|
|
|
from Crypto.Util import asn1
|
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from Crypto.Cipher import AES
|
|
|
|
from Crypto.Cipher import PKCS1_v1_5
|
2012-04-07 16:02:46 +02:00
|
|
|
|
2012-04-11 22:22:58 +02:00
|
|
|
EntityID = 0
|
|
|
|
|
2012-12-26 16:07:34 +01:00
|
|
|
|
2012-04-11 22:22:58 +02:00
|
|
|
class ServerConnection(threading.Thread):
|
2013-09-24 21:31:17 +02:00
|
|
|
|
|
|
|
##=====
|
|
|
|
posX = None
|
|
|
|
posY = None
|
|
|
|
posZ = None
|
|
|
|
yaw = None
|
|
|
|
pitch = None
|
|
|
|
##=====
|
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
def __init__(self, pluginLoader, username, sessionID, server, port, options=None):
|
2012-04-11 22:22:58 +02:00
|
|
|
threading.Thread.__init__(self)
|
2012-12-17 14:40:49 +01:00
|
|
|
self.pluginLoader = pluginLoader
|
2012-10-26 02:02:42 +02:00
|
|
|
self.options = options
|
2012-10-09 17:16:37 +02:00
|
|
|
self.isConnected = False
|
2012-04-07 16:02:46 +02:00
|
|
|
self.username = username
|
|
|
|
self.sessionID = sessionID
|
|
|
|
self.server = server
|
|
|
|
self.port = port
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-10-26 15:09:16 +02:00
|
|
|
def disconnect(self, reason="Disconnected by user"):
|
|
|
|
PacketSenderManager.sendFF(self.socket, reason)
|
2012-09-12 02:11:58 +02:00
|
|
|
self.listener.kill = True
|
|
|
|
self.socket.close()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-07-17 23:42:42 +02:00
|
|
|
def setWindow(self, window):
|
|
|
|
self.window = window
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-04-15 18:49:47 +02:00
|
|
|
def grabSocket(self):
|
2012-10-09 17:16:37 +02:00
|
|
|
return self.socket
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-04-11 22:22:58 +02:00
|
|
|
def run(self):
|
2012-04-07 16:02:46 +02:00
|
|
|
try:
|
2012-09-02 19:54:16 +02:00
|
|
|
#Create the socket and fileobject
|
2012-12-25 21:38:02 +01:00
|
|
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
self.socket.connect(( self.server, self.port ))
|
2012-04-15 16:51:00 +02:00
|
|
|
self.FileObject = self.socket.makefile()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Send out the handshake packet
|
|
|
|
PacketSenderManager.sendHandshake(self.socket, self.username, self.server, self.port)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Receive the encryption packet id
|
|
|
|
packetid = self.socket.recv(1)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2013-07-01 08:36:57 +02:00
|
|
|
if (packetid == "\xFF"):
|
|
|
|
print PacketListenerManager.handleFF(self.FileObject)
|
2012-09-02 19:54:16 +02:00
|
|
|
#Sanity check the packet id
|
2012-10-26 15:09:16 +02:00
|
|
|
assert packetid == "\xFD", "Server didn't respond back to handshake with proper packet!"
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Parse the packet
|
|
|
|
packetFD = PacketListenerManager.handleFD(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Import the server's public key
|
|
|
|
self.pubkey = RSA.importKey(packetFD['Public Key'])
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Generate a 16 byte (128 bit) shared secret
|
|
|
|
self.sharedSecret = _UserFriendlyRNG.get_random_bytes(16)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Authenticate the server from sessions.minecraft.net
|
2012-12-25 21:38:02 +01:00
|
|
|
if (packetFD['ServerID'] != '-'):
|
2012-07-17 23:42:42 +02:00
|
|
|
try:
|
2012-12-04 10:48:49 +01:00
|
|
|
#Grab the server id
|
|
|
|
sha1 = hashlib.sha1()
|
|
|
|
sha1.update(packetFD['ServerID'])
|
|
|
|
sha1.update(self.sharedSecret)
|
|
|
|
sha1.update(packetFD['Public Key'])
|
|
|
|
#lovely java style hex digest by barneygale
|
|
|
|
serverid = Utils.javaHexDigest(sha1)
|
2012-09-02 19:54:16 +02:00
|
|
|
#Open up the url with the appropriate get parameters
|
2012-07-17 23:42:42 +02:00
|
|
|
url = "http://session.minecraft.net/game/joinserver.jsp?user=" + self.username + "&sessionId=" + self.sessionID + "&serverId=" + serverid
|
|
|
|
response = urllib2.urlopen(url).read()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
if (response != "OK"):
|
2012-11-19 19:56:51 +01:00
|
|
|
print "Response from sessions.minecraft.net wasn't OK, it was " + response
|
|
|
|
return False
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
#Success \o/ We can now begin sending our serverAddress to the server
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Instantiate our main packet listener
|
2012-12-04 16:47:29 +01:00
|
|
|
self.listener = PacketListener(self, self.socket, self.FileObject)
|
2012-12-17 14:40:49 +01:00
|
|
|
self.listener.setDaemon(True)
|
2012-09-11 17:03:36 +02:00
|
|
|
self.listener.start()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#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))
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
#Send out a a packet FC to the server
|
|
|
|
PacketSenderManager.sendFC(self.socket, encryptedSharedSecret, encryptedSanityToken)
|
2012-12-26 16:23:47 +01:00
|
|
|
self.pluginLoader.notify("onConnect")
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-07-17 23:42:42 +02:00
|
|
|
except Exception, e:
|
2012-09-02 19:54:16 +02:00
|
|
|
traceback.print_exc()
|
2012-04-11 22:22:58 +02:00
|
|
|
else:
|
2012-10-26 15:09:16 +02:00
|
|
|
print "Server is in offline mode"
|
2012-12-04 10:48:49 +01:00
|
|
|
#Instantiate our main packet listener
|
2012-12-04 16:47:29 +01:00
|
|
|
self.listener = PacketListener(self, self.socket, self.FileObject)
|
2012-12-17 14:40:49 +01:00
|
|
|
self.listener.setDaemon(True)
|
2012-12-04 10:48:49 +01:00
|
|
|
self.listener.start()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
#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))
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
#Send out a a packet FC to the server
|
|
|
|
PacketSenderManager.sendFC(self.socket, encryptedSharedSecret, encryptedSanityToken)
|
2012-12-26 16:23:47 +01:00
|
|
|
self.pluginLoader.notify("onConnect")
|
2012-04-07 16:02:46 +02:00
|
|
|
except Exception, e:
|
2012-10-26 15:09:16 +02:00
|
|
|
print "Connection to server failed"
|
2012-04-07 16:02:46 +02:00
|
|
|
traceback.print_exc()
|
2012-10-26 15:09:16 +02:00
|
|
|
sys.exit(1)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
class EncryptedFileObjectHandler():
|
|
|
|
def __init__(self, fileobject, cipher):
|
|
|
|
self.fileobject = fileobject
|
|
|
|
self.cipher = cipher
|
2012-11-03 15:08:39 +01:00
|
|
|
self.length = 0
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
def read(self, length):
|
2012-09-05 21:28:55 +02:00
|
|
|
rawData = self.fileobject.read(length)
|
2012-11-03 15:08:39 +01:00
|
|
|
self.length += length
|
2012-09-05 21:28:55 +02:00
|
|
|
unencryptedData = self.cipher.decrypt(rawData)
|
|
|
|
return unencryptedData
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-11-03 15:08:39 +01:00
|
|
|
def tell(self):
|
|
|
|
return self.length
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
class EncryptedSocketObjectHandler():
|
|
|
|
def __init__(self, socket, cipher):
|
|
|
|
self.socket = socket
|
|
|
|
self.cipher = cipher
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-12-04 10:48:49 +01:00
|
|
|
def send(self, serverAddress):
|
|
|
|
self.socket.send(self.cipher.encrypt(serverAddress))
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
def close(self):
|
|
|
|
self.socket.close()
|
2012-12-25 21:38:02 +01:00
|
|
|
|
|
|
|
|
2012-04-10 21:14:32 +02:00
|
|
|
class PacketListener(threading.Thread):
|
2013-09-24 21:31:17 +02:00
|
|
|
|
|
|
|
lastMoveTick = 0
|
|
|
|
|
2012-12-04 16:47:29 +01:00
|
|
|
def __init__(self, connection, socket, FileObject):
|
2012-04-10 21:14:32 +02:00
|
|
|
threading.Thread.__init__(self)
|
2012-09-02 19:54:16 +02:00
|
|
|
self.connection = connection
|
2012-04-10 21:14:32 +02:00
|
|
|
self.socket = socket
|
2012-04-15 16:51:00 +02:00
|
|
|
self.FileObject = FileObject
|
2012-09-02 19:54:16 +02:00
|
|
|
self.encryptedConnection = False
|
2012-09-12 02:11:58 +02:00
|
|
|
self.kill = False
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
def enableEncryption(self):
|
|
|
|
#Create an AES cipher from the previously obtained public key
|
2012-09-05 21:28:55 +02:00
|
|
|
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)
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
self.rawsocket = self.socket
|
2012-09-11 17:03:36 +02:00
|
|
|
self.connection.rawsocket = self.connection.socket
|
2012-09-02 19:54:16 +02:00
|
|
|
self.socket = EncryptedSocketObjectHandler(self.rawsocket, self.cipher)
|
2012-09-11 17:03:36 +02:00
|
|
|
self.connection.socket = self.socket
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
self.rawFileObject = self.FileObject
|
2012-09-11 17:03:36 +02:00
|
|
|
self.connection.rawFileObject = self.connection.FileObject
|
2012-09-05 21:28:55 +02:00
|
|
|
self.FileObject = EncryptedFileObjectHandler(self.rawFileObject, self.decipher)
|
2012-09-11 17:03:36 +02:00
|
|
|
self.connection.FileObject = self.FileObject
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-09-02 19:54:16 +02:00
|
|
|
self.encryptedConnection = True
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2012-04-10 21:14:32 +02:00
|
|
|
def run(self):
|
|
|
|
while True:
|
2012-09-12 02:11:58 +02:00
|
|
|
if (self.kill):
|
|
|
|
break
|
2012-04-10 21:14:32 +02:00
|
|
|
try:
|
2012-09-02 19:54:16 +02:00
|
|
|
response = self.FileObject.read(1)
|
|
|
|
if (response == ""):
|
|
|
|
continue
|
2012-07-17 23:42:42 +02:00
|
|
|
except Exception, e:
|
2012-12-31 03:20:06 +01:00
|
|
|
print "Ping timeout"
|
|
|
|
sys.exit()
|
2012-04-10 21:14:32 +02:00
|
|
|
break
|
2012-12-25 21:38:02 +01:00
|
|
|
if (response == "\x00"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle00(self.FileObject, self.socket)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x01"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle01(self.FileObject)
|
|
|
|
print "Logged in \o/ Received an entity id of " + str(packet['EntityID'])
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x03"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle03(self.FileObject)
|
2012-12-31 03:20:06 +01:00
|
|
|
if not self.connection.options.disableAnsiColours:
|
2013-01-31 16:42:47 +01:00
|
|
|
filtered_string = Utils.translate_escapes(packet['Message'])
|
2012-12-31 03:20:06 +01:00
|
|
|
else:
|
2013-01-31 16:42:47 +01:00
|
|
|
filtered_string = packet['Message']
|
2012-10-26 15:09:16 +02:00
|
|
|
print filtered_string
|
2012-12-17 14:40:49 +01:00
|
|
|
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x04"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle04(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x05"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle05(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x06"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle06(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x07"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle07(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x08"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle08(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x09"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle09(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x0D"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle0D(self.FileObject)
|
2013-09-24 21:31:17 +02:00
|
|
|
|
|
|
|
#===
|
|
|
|
self.connection.posX = packet['x']
|
|
|
|
self.connection.posY = packet['y']
|
|
|
|
self.connection.posZ = packet['z']
|
|
|
|
self.connection.yaw = packet['yaw']
|
|
|
|
self.connection.pitch = packet['pitch']
|
|
|
|
PacketSenderManager.send0D(self.socket, self.connection.posX, self.connection.posY,
|
|
|
|
self.connection.posZ,
|
|
|
|
(self.connection.posY + 1.6), self.connection.yaw, self.connection.pitch, False)
|
|
|
|
PacketSenderManager.sendCA(self.socket, 15, 0.05, 0.1)
|
|
|
|
#===
|
|
|
|
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x10"):
|
2012-12-20 23:28:38 +01:00
|
|
|
packet = PacketListenerManager.handle10(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x11"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle11(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x12"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle12(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x14"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle14(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x15"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle15(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x16"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle16(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x17"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle17(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x18"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle18(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x19"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle19(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x1A"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle1A(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x1C"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle1C(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x1D"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle1D(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x1E"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle1E(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x1F"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle1F(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x20"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle20(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x21"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle21(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x22"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle22(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x23"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle23(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x26"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle26(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x27"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle27(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x28"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle28(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x29"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle29(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x2A"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle2A(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x2B"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle2B(self.FileObject)
|
2013-07-01 08:36:57 +02:00
|
|
|
elif (response == "\x2C"):
|
|
|
|
packet = PacketListenerManager.handle2C(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x33"):
|
2012-12-17 14:40:49 +01:00
|
|
|
packet = PacketListenerManager.handle33(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x34"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle34(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x35"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle35(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x36"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle36(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x37"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle37(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x38"):
|
2012-12-17 14:40:49 +01:00
|
|
|
packet = PacketListenerManager.handle38(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x3C"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle3C(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x3D"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle3D(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x3E"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle3E(self.FileObject)
|
2013-03-16 23:07:41 +01:00
|
|
|
elif (response == "\x3F"):
|
|
|
|
packet = PacketListenerManager.handle3F(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x46"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle46(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x47"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle47(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x64"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle64(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x65"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle65(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x67"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle67(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x68"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle68(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x69"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle69(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x6A"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle6A(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x6B"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle6B(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x82"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle82(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x83"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle83(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\x84"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handle84(self.FileObject)
|
2013-07-24 19:45:56 +02:00
|
|
|
elif (response == "\x85"):
|
|
|
|
packet = PacketListenerManager.handle85(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xC8"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleC8(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xC9"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleC9(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xCA"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleCA(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xCB"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleCB(self.FileObject)
|
2013-03-16 23:07:41 +01:00
|
|
|
elif (response == "\xCE"):
|
|
|
|
packet = PacketListenerManager.handleCE(self.FileObject)
|
|
|
|
elif (response == "\xCF"):
|
|
|
|
packet = PacketListenerManager.handleCF(self.FileObject)
|
|
|
|
elif (response == "\xD0"):
|
|
|
|
packet = PacketListenerManager.handleD0(self.FileObject)
|
|
|
|
elif (response == "\xD1"):
|
|
|
|
packet = PacketListenerManager.handleD1(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xFA"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleFA(self.FileObject)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xFC"):
|
2012-10-26 02:02:42 +02:00
|
|
|
packet = PacketListenerManager.handleFC(self.FileObject)
|
2012-09-02 19:54:16 +02:00
|
|
|
if (not self.encryptedConnection):
|
|
|
|
self.enableEncryption()
|
2012-10-09 17:16:37 +02:00
|
|
|
self.connection.isConnected = True
|
2012-09-02 19:54:16 +02:00
|
|
|
PacketSenderManager.sendCD(self.socket, 0)
|
2012-12-25 21:38:02 +01:00
|
|
|
elif (response == "\xFF"):
|
2012-10-26 15:09:16 +02:00
|
|
|
packet = PacketListenerManager.handleFF(self.FileObject)
|
|
|
|
print "Disconnected: " + packet['Reason']
|
|
|
|
self.connection.disconnect()
|
2012-12-17 14:40:49 +01:00
|
|
|
self.connection.pluginLoader.disablePlugins()
|
2012-10-26 02:02:42 +02:00
|
|
|
sys.exit(1)
|
2012-04-14 17:29:04 +02:00
|
|
|
break
|
2012-09-02 19:54:16 +02:00
|
|
|
else:
|
2012-10-26 15:09:16 +02:00
|
|
|
print "Protocol error: " + hex(ord(response))
|
|
|
|
self.connection.disconnect("Protocol error, invalid packet: " + hex(ord(response)))
|
2012-12-17 14:40:49 +01:00
|
|
|
self.connection.pluginLoader.disablePlugins()
|
2012-10-26 15:09:16 +02:00
|
|
|
sys.exit(1)
|
|
|
|
break
|
2012-12-25 21:38:02 +01:00
|
|
|
|
2013-09-24 21:31:17 +02:00
|
|
|
#===
|
|
|
|
if (self.lastMoveTick == 0):
|
|
|
|
if (self.connection.posX != None):
|
|
|
|
if (self.connection.posY < 128):
|
|
|
|
self.connection.posY += 3
|
|
|
|
self.connection.posX += random.randint(-2, 3)
|
|
|
|
self.connection.posZ += random.randint(-2, 3)
|
|
|
|
PacketSenderManager.send0D(self.socket, self.connection.posX, self.connection.posY,
|
|
|
|
self.connection.posZ,
|
|
|
|
(self.connection.posY + 1.6), self.connection.yaw, self.connection.pitch, False)
|
|
|
|
self.lastMoveTick = 50
|
|
|
|
else:
|
|
|
|
self.lastMoveTick -= 1
|
|
|
|
#===
|
|
|
|
|
2012-12-17 14:40:49 +01:00
|
|
|
# Invoke plugin listeners
|
|
|
|
for listener in self.connection.pluginLoader.getPacketListeners():
|
|
|
|
listener(response, packet)
|