Ironed out some bugs, removed nogui chatting until I can figure out a nice non blocking approach

This commit is contained in:
Ammar Askar 2012-09-11 20:03:36 +05:00
parent 4ffcc4b04d
commit 908f9465a4
3 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import urllib2, urllib import urllib2, urllib
from networking import PacketSenderManager
def loginToMinecraft(username, password): def loginToMinecraft(username, password):
try: try:

View File

@ -1,12 +1,12 @@
import socket import socket
import PacketListenerManager import PacketListenerManager
import urllib2 import urllib2
import urllib
import traceback import traceback
import threading import threading
import hashlib import hashlib
import string import string
import Utils import Utils
import sys
from networking import PacketSenderManager from networking import PacketSenderManager
from Crypto.Random import _UserFriendlyRNG from Crypto.Random import _UserFriendlyRNG
from Crypto.Util import asn1 from Crypto.Util import asn1
@ -110,7 +110,8 @@ class ServerConnection(threading.Thread):
#Success \o/ We can now begin sending our stuff to the server #Success \o/ We can now begin sending our stuff to the server
#Instantiate our main packet listener #Instantiate our main packet listener
PacketListener(self, self.window, self.socket, self.FileObject).start() self.listener = PacketListener(self, self.window, self.socket, self.FileObject)
self.listener.start()
#Encrypt the verification token from earlier along with our shared secret with the server's rsa key #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) self.RSACipher = PKCS1_v1_5.new(self.pubkey)
@ -186,10 +187,17 @@ class PacketListener(threading.Thread):
#Create an AES cipher from the previously obtained public key #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.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.decipher = AES.new(self.connection.sharedSecret, AES.MODE_CFB, IV=self.connection.sharedSecret)
self.rawsocket = self.socket self.rawsocket = self.socket
self.connection.rawsocket = self.connection.socket
self.socket = EncryptedSocketObjectHandler(self.rawsocket, self.cipher) self.socket = EncryptedSocketObjectHandler(self.rawsocket, self.cipher)
self.connection.socket = self.socket
self.rawFileObject = self.FileObject self.rawFileObject = self.FileObject
self.connection.rawFileObject = self.connection.FileObject
self.FileObject = EncryptedFileObjectHandler(self.rawFileObject, self.decipher) self.FileObject = EncryptedFileObjectHandler(self.rawFileObject, self.decipher)
self.connection.FileObject = self.FileObject
self.encryptedConnection = True self.encryptedConnection = True
def run(self): def run(self):
@ -203,7 +211,7 @@ class PacketListener(threading.Thread):
self.window.Status.SetLabel("Ping timeout") self.window.Status.SetLabel("Ping timeout")
else: else:
print "Ping timeout" print "Ping timeout"
traceback.print_exc() sys.exit()
break break
if(response == "\x00"): if(response == "\x00"):
PacketListenerManager.handle00(self.FileObject, self.socket) PacketListenerManager.handle00(self.FileObject, self.socket)
@ -339,6 +347,7 @@ class PacketListener(threading.Thread):
DisconMessage = PacketListenerManager.handleFF(self.FileObject) DisconMessage = PacketListenerManager.handleFF(self.FileObject)
if(self.window == None): if(self.window == None):
print "Disconnected: " + DisconMessage print "Disconnected: " + DisconMessage
sys.exit()
if(self.window): if(self.window):
if(hasattr(self.window, 'ChatPanel')): if(hasattr(self.window, 'ChatPanel')):
self.window.ChatPanel.Status.SetLabel("Disconnected: " + DisconMessage) self.window.ChatPanel.Status.SetLabel("Disconnected: " + DisconMessage)

View File

@ -99,7 +99,7 @@ class KeepConnectionAlive(threading.Thread):
if __name__ == "__main__": if __name__ == "__main__":
noGUI = False noGUI = False
if (len(sys.argv) > 1): if (len(sys.argv) > 1):
if (sys.argv.count("nogui") > 1) : if (sys.argv.count("nogui") > 0) :
noGUI = True noGUI = True
if(noGUI or wxImportError): if(noGUI or wxImportError):
@ -121,9 +121,7 @@ if __name__ == "__main__":
port = 25565 port = 25565
connection = NetworkManager.ServerConnection(None, derp['Username'], passwd, sessionid, host, port) connection = NetworkManager.ServerConnection(None, derp['Username'], passwd, sessionid, host, port)
connection.start() connection.start()
while True: raw_input()
chat = raw_input()
PacketSenderManager.send03(connection.grabSocket(), chat)
else: else:
app = wx.PySimpleApp() app = wx.PySimpleApp()
Login = GUI.MainFrame(None, -1, "") Login = GUI.MainFrame(None, -1, "")