summaryrefslogtreecommitdiff
path: root/python_client.py
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2014-01-27 08:47:50 +0100
committerTreeki <treeki@gmail.com>2014-01-27 08:47:50 +0100
commit277c08cbc35f4cb2b72f1b00ab3e5f8efd2f8fb2 (patch)
tree7ad60b604f57abebd10e008de3fcacea7824ca77 /python_client.py
parent8004d775c24dcfb63dcbd3366f86278ec808f0d7 (diff)
downloadbounce4-277c08cbc35f4cb2b72f1b00ab3e5f8efd2f8fb2.tar.gz
bounce4-277c08cbc35f4cb2b72f1b00ab3e5f8efd2f8fb2.zip
make the test client's connection handling a little more robust, not that it matters much
Diffstat (limited to '')
-rw-r--r--python_client.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/python_client.py b/python_client.py
index 22c31da..af0eecb 100644
--- a/python_client.py
+++ b/python_client.py
@@ -45,16 +45,16 @@ def clearCachedPackets(pid):
packetCache.remove(packet)
def reader():
- global lastReceivedPacketID, authed, sessionKey
+ global lastReceivedPacketID, authed, sessionKey, nextID, packetCache
readbuf = b''
sockCopy = sock
- print('(Connected)')
+ app.postEvent(mainwin, PacketEvent(-1, '(Connected to server)'))
while True:
data = sockCopy.recv(1024)
if not data:
- print('(Disconnected)')
+ app.postEvent(mainwin, PacketEvent(-1, '(Disconnected from server)'))
break
readbuf += data
@@ -87,9 +87,14 @@ def reader():
if type == 0x8001:
sessionKey = packetdata
authed = True
+ app.postEvent(mainwin, PacketEvent(-2, None))
+ app.postEvent(mainwin, PacketEvent(-1, 'Session started.'))
+ nextID = 1
+ packetCache = []
elif type == 0x8002:
- print('FAILED!')
+ app.postEvent(mainwin, PacketEvent(-1, 'Login error!'))
elif type == 0x8003:
+ app.postEvent(mainwin, PacketEvent(-1, 'Session resumed successfully.'))
authed = True
pid = u32.unpack(packetdata)[0]
clearCachedPackets(pid)
@@ -322,7 +327,20 @@ class MainWindow(QtWidgets.QMainWindow):
ptype = event.packetType
pdata = event.packetData
- if ptype == 1:
+ if ptype == -1:
+ # Special type for messages coming from the reader
+ # function. Messy as fuck, but doesn't matter in this
+ # throwaway client
+ self.debugTab.pushMessage(pdata)
+ elif ptype == -2:
+ # Also a special type, this means that it's
+ # a new session and we should delete all our
+ # existing tabs and other state
+ for wid,tab in self.tabLookup.items():
+ self.tabs.removeTab(self.tabs.indexOf(tab))
+ self.tabLookup = {}
+
+ elif ptype == 1:
strlen = u32.unpack_from(pdata, 0)[0]
msg = pdata[4:4+strlen].decode('utf-8', 'replace')
self.debugTab.pushMessage(msg)