if self.server.clients[connection_id] == self:
self.server.queue.put((connection_id, self.data))
break
-
+
def handleConnected(self):
import uuid
print('CONNECTION FROM:', self.address)
game.tui.do_refresh = True
cmd_ANNOTATION.argtypes = 'yx_tuple:nonneg string'
+def cmd_PONG(game):
+ pass
+cmd_PONG.argtypes = ''
+
class Game(GameBase):
commands = {'LOGIN_OK': cmd_LOGIN_OK,
+ 'PONG': cmd_PONG,
'CHAT': cmd_CHAT,
'PLAYER_ID': cmd_PLAYER_ID,
'TURN': cmd_TURN,
def loop(self, stdscr):
import time
+ import datetime
def safe_addstr(y, x, line):
if y < self.size.y - 1 or x + len(line) < self.size.x:
self.input_ = ''
input_prompt = '> '
connect()
+ last_ping = datetime.datetime.now()
+ interval = datetime.timedelta(seconds=30)
while True:
+ now = datetime.datetime.now()
+ if now - last_ping > interval:
+ self.send('PING')
+ last_ping = now
if self.do_refresh:
draw_screen()
self.do_refresh = False