Stop client on loss of connection
This commit is contained in:
parent
5029f376a6
commit
ac65d9ab0a
1 changed files with 71 additions and 65 deletions
26
client.py
26
client.py
|
|
@ -65,8 +65,13 @@ class Client():
|
|||
)
|
||||
self.inputthread.start()
|
||||
|
||||
# update screen until stopped
|
||||
while not self.stopping:
|
||||
self.update_screen()
|
||||
|
||||
if self.logfile:
|
||||
self.save_log(self.logfile)
|
||||
|
||||
def update_screen(self):
|
||||
self._drawevent.wait()
|
||||
self._drawevent.clear()
|
||||
|
||||
|
|
@ -84,9 +89,6 @@ class Client():
|
|||
|
||||
curses.doupdate()
|
||||
|
||||
if self.logfile:
|
||||
self.save_log(self.logfile)
|
||||
|
||||
def redraw(self):
|
||||
self._drawevent.set()
|
||||
|
||||
|
|
@ -108,10 +110,7 @@ class Client():
|
|||
elif mode == self.MOVE_MAP:
|
||||
self.map_.scroll(x*20, y*10)
|
||||
|
||||
def input_thread(self, scr):
|
||||
while True:
|
||||
i = scr.get_wch()
|
||||
|
||||
def handle_input(self, i):
|
||||
if i == "\x1b": self.stop()
|
||||
elif i == curses.KEY_F1: self.movement = self.MOVE_NORMAL
|
||||
elif i == curses.KEY_F2: self.movement = self.MOVE_FAST
|
||||
|
|
@ -153,16 +152,21 @@ class Client():
|
|||
elif isinstance(i, str) and len(i) == 1 and ord(i) > 31 and (i not in string.whitespace or i == " "):
|
||||
self.map_.write(i)
|
||||
|
||||
def input_thread(self, scr):
|
||||
while True:
|
||||
i = scr.get_wch()
|
||||
self.handle_input(i)
|
||||
self.log(f"K: {i!r}")
|
||||
|
||||
def connection_thread(self):
|
||||
while True:
|
||||
try:
|
||||
while True:
|
||||
j = self._ws.recv()
|
||||
if j:
|
||||
self.handle_json(json.loads(j))
|
||||
except (WSException, ConnectionResetError, OSError):
|
||||
#self.stop()
|
||||
self._ws = None
|
||||
self.stop()
|
||||
return
|
||||
|
||||
def handle_json(self, message):
|
||||
|
|
@ -172,7 +176,9 @@ class Client():
|
|||
|
||||
def stop(self):
|
||||
self.stopping = True
|
||||
if self._ws:
|
||||
self._ws.close()
|
||||
self._ws = None
|
||||
self.redraw()
|
||||
|
||||
def request_chunks(self, coords):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue