Пример #1
0
    def send_json_options(self, game_id, player_name):
        def do_send(data, returncode):
            if returncode != 0:
                # fail silently for returncode 1 for now, probably just an old
                # version missing the command line option
                if returncode != 1:
                    self.logger.warning("Error while getting JSON options!")
                return
            self.append_message('{"msg":"options","watcher":true,"options":' +
                                data + '}')

        if not self.username: return
        if game_id not in config.games: return

        game = config.games[game_id]
        if not "send_json_options" in game or not game["send_json_options"]:
            return

        call = [game["crawl_binary"]]

        if "pre_options" in game:
            call += game["pre_options"]

        call += ["-name", player_name, "-rc", self.rcfile_path(game_id)]
        if "options" in game:
            call += game["options"]
        call.append("-print-webtiles-options")

        checkoutput.check_output(call, do_send)
Пример #2
0
        def build_callback(game_key, call, next_callback):
            def update_save_info(data, returncode):
                global sockets
                if not self in sockets:
                    return
                if returncode == 0:
                    try:
                        save_dict = json_decode(data)[
                            load_games.game_modes[game_key]]
                        if not save_dict["loadable"]:
                            # the save in this slot is in use.
                            self.save_info[
                                game_key] = "[playing]"  # TODO: something better??
                        elif load_games.game_modes[game_key] == save_dict[
                                "game_type"]:
                            # save in the slot matches the game type we are
                            # checking.
                            self.save_info[
                                game_key] = "[" + save_dict["short_desc"] + "]"
                        else:
                            # There is a save, but it has a different game type.
                            # This happens if multiple game types share a slot.
                            self.save_info[game_key] = "[slot full]"
                    except Exception:
                        # game key missing (or other error). This will mainly
                        # happen if there are no saves at all for the player
                        # name. It can also happen under some dgamelaunch-config
                        # setups if escape codes are incorrectly inserted into
                        # the output for some calls. See:
                        # https://github.com/crawl/dgamelaunch-config/commit/6ad788ceb5614b3c83d65b61bf26a122e592b98d
                        self.save_info[game_key] = ""
                else:
                    # error in the subprocess: this will happen if the binary
                    # does not support `-save-json`. Print a warning so that
                    # the admin can see that they have save info enabled
                    # incorrectly for this binary.
                    logging.warn("Save info check for '%s' failed" % game_key)
                    self.save_info[game_key] = ""
                next_callback()

            return lambda: checkoutput.check_output(call, update_save_info)