+def cmd_PLAYER_HAT(game, hat, connection_id):
+ t = game.get_player(connection_id)
+ if not t:
+ raise GameError('can only edit hat when already logged in')
+ if not t.name in game.hats:
+ raise GameError('not currently wearing an editable hat')
+ if len(hat) != 18:
+ raise GameError('wrong hat string length')
+ legal_chars = t.get_cookie_chars()
+ for c in hat:
+ if c not in legal_chars:
+ raise GameError('used illegal character: "%s" – '
+ 'allowed characters: %s'
+ % (c, legal_chars))
+ game.hats[t.name] = hat
+ game.changed = True
+ # FIXME: pseudo-FOV-change actually
+ game.record_fov_change(t.position)
+cmd_PLAYER_HAT.argtypes = 'string'
+