mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2025-01-10 18:07:56 +01:00
More progress
This commit is contained in:
parent
dd11f5fd4f
commit
135c924f8d
@ -3,6 +3,8 @@ import wx
|
||||
import PacketManager
|
||||
import urllib2
|
||||
import traceback
|
||||
import threading
|
||||
import struct
|
||||
|
||||
#Eclipse pyDev error fix
|
||||
wx=wx
|
||||
@ -31,10 +33,33 @@ class ServerConnection:
|
||||
self.window.connectStatus.SetLabel("Response from sessions.minecraft.net wasn't OK")
|
||||
return False
|
||||
PacketManager.sendLoginRequest(self.socket, self.username)
|
||||
PacketListener(self.window, self.socket).start()
|
||||
except Exception, e:
|
||||
self.window.connectStatus.SetForegroundColour(wx.RED)
|
||||
self.window.connectStatus.SetLabel("Connection to server failed")
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
|
||||
class PacketListener(threading.Thread):
|
||||
|
||||
def __init__(self, window, socket):
|
||||
threading.Thread.__init__(self)
|
||||
self.socket = socket
|
||||
self.window = window
|
||||
|
||||
def run(self):
|
||||
self.socket.settimeout(60)
|
||||
while True:
|
||||
try:
|
||||
response = self.socket.recv(256)
|
||||
except socket.timeout, e:
|
||||
self.window.connectStatus.SetLabel("Ping timeout")
|
||||
break
|
||||
print hex(ord(response[0]))
|
||||
if(response[0] == "\x00"):
|
||||
PacketManager.handle00(self.socket)
|
||||
if(response[0] == "\xFF"):
|
||||
response = response[3:].decode("utf-16be", 'strict')
|
||||
print response
|
||||
#DisconMessage = PacketManager.handleFF(self.socket, response)
|
||||
self.window.connectStatus.SetLabel("Disconnected: " + response)
|
||||
|
@ -35,17 +35,18 @@ def ReceiveLoginRequest(socket):
|
||||
return ""
|
||||
response = response[1:]
|
||||
|
||||
def handle00(socket, message):
|
||||
message = message[1:]
|
||||
message = struct.unpack('!i')
|
||||
def handle00(socket):
|
||||
print "Sending keep alive response"
|
||||
socket.send("\x00")
|
||||
socket.send(struct.pack('!i'), message)
|
||||
socket.send(struct.pack('!i', 0))
|
||||
|
||||
def handleFF(socket, message):
|
||||
message = message[3:]
|
||||
message = message.decode("utf-16be")
|
||||
print "Disconnected: " + message
|
||||
sys.exit()
|
||||
def handleFF(socket, response):
|
||||
response = response[3:]
|
||||
print "Length: " + str(response.__len__())
|
||||
print response
|
||||
response = response.decode("utf-16be", 'strict')
|
||||
print response
|
||||
return response
|
||||
|
||||
def handleIncomingPacket(socket):
|
||||
response = socket.recv(256)
|
||||
|
@ -88,6 +88,8 @@ class Window(wx.Frame):
|
||||
|
||||
def onConnectClick(self, event):
|
||||
StuffEnteredIntoBox = self.AddressEntry.GetValue()
|
||||
if(StuffEnteredIntoBox == ""):
|
||||
self.topLabel.SetLabel("Logged in as " + self.username + "! Enter a server address")
|
||||
self.sizer.DeleteWindows()
|
||||
self.sizer = wx.GridBagSizer()
|
||||
self.connectStatus = wx.StaticText(self, -1, label=u'Connecting ...')
|
||||
@ -202,7 +204,7 @@ class KeepConnectionAlive(threading.Thread):
|
||||
popup.ShowModal()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = wx.App()
|
||||
app = wx.App(0)
|
||||
Window(None, title='pyCraft')
|
||||
app.MainLoop()
|
||||
|
Loading…
Reference in New Issue
Block a user