+class PlomSocketClient(PlomSocket):
+
+ def __init__(self, recv_handler, url):
+ import socket
+ self.recv_handler = recv_handler
+ host, port = url.split(':')
+ super().__init__(socket.create_connection((host, port)))
+
+ def close(self):
+ self.socket.close()
+
+ def run(self):
+ import ssl
+ try:
+ for msg in self.recv():
+ if msg == 'NEED_SSL':
+ self.socket = ssl.wrap_socket(self.socket)
+ continue
+ self.recv_handler(msg)
+ except BrokenSocketConnection:
+ pass # we assume socket will be known as dead by now
+
+def cmd_TURN(game, n):
+ game.turn = n
+ game.things = []
+ game.portals = {}
+ game.turn_complete = False
+cmd_TURN.argtypes = 'int:nonneg'
+
+def cmd_LOGIN_OK(game):
+ game.tui.switch_mode('post_login_wait')
+ game.tui.send('GET_GAMESTATE')
+ game.tui.log_msg('@ welcome')
+cmd_LOGIN_OK.argtypes = ''
+
+def cmd_CHAT(game, msg):
+ game.tui.log_msg('# ' + msg)
+ game.tui.do_refresh = True
+cmd_CHAT.argtypes = 'string'
+
+def cmd_PLAYER_ID(game, player_id):
+ game.player_id = player_id
+cmd_PLAYER_ID.argtypes = 'int:nonneg'
+
+def cmd_THING_POS(game, thing_id, position):
+ t = game.get_thing(thing_id, True)
+ t.position = position
+cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
+
+def cmd_THING_NAME(game, thing_id, name):
+ t = game.get_thing(thing_id, True)
+ t.name = name
+cmd_THING_NAME.argtypes = 'int:nonneg string'
+
+def cmd_MAP(game, geometry, size, content):
+ map_geometry_class = globals()['MapGeometry' + geometry]
+ game.map_geometry = map_geometry_class(size)
+ game.map_content = content
+ if type(game.map_geometry) == MapGeometrySquare:
+ game.tui.movement_keys = {
+ game.tui.keys['square_move_up']: 'UP',
+ game.tui.keys['square_move_left']: 'LEFT',
+ game.tui.keys['square_move_down']: 'DOWN',
+ game.tui.keys['square_move_right']: 'RIGHT',
+ }
+ elif type(game.map_geometry) == MapGeometryHex:
+ game.tui.movement_keys = {
+ game.tui.keys['hex_move_upleft']: 'UPLEFT',
+ game.tui.keys['hex_move_upright']: 'UPRIGHT',
+ game.tui.keys['hex_move_right']: 'RIGHT',
+ game.tui.keys['hex_move_downright']: 'DOWNRIGHT',
+ game.tui.keys['hex_move_downleft']: 'DOWNLEFT',
+ game.tui.keys['hex_move_left']: 'LEFT',
+ }
+cmd_MAP.argtypes = 'string:map_geometry yx_tuple:pos string'
+
+def cmd_GAME_STATE_COMPLETE(game):
+ game.info_db = {}
+ if game.tui.mode.name == 'post_login_wait':
+ game.tui.switch_mode('play')
+ game.tui.help()
+ if game.tui.mode.shows_info:
+ game.tui.query_info()
+ player = game.get_thing(game.player_id, False)
+ if player.position in game.portals:
+ game.tui.teleport_target_host = game.portals[player.position]
+ game.tui.switch_mode('teleport')
+ game.turn_complete = True
+ game.tui.do_refresh = True
+cmd_GAME_STATE_COMPLETE.argtypes = ''
+
+def cmd_PORTAL(game, position, msg):
+ game.portals[position] = msg
+cmd_PORTAL.argtypes = 'yx_tuple:nonneg string'
+
+def cmd_PLAY_ERROR(game, msg):
+ game.tui.flash()
+ game.tui.do_refresh = True
+cmd_PLAY_ERROR.argtypes = 'string'