Ejemplo n.º 1
0
def main(stdscr, *args, **kwargs):
    global answer, feedback, candidates

    gevent.signal(
        signal.SIGUSR1,
        lambda *args: game_close.set())  # For standard/graceful restart
    #	gevent.signal(signal.SIGINT, lambda *args: None) # Disable SIGINT
    #	signal.signal(signal.SIGQUIT, signal.SIG_IGN) # Disable SIGQUIT
    #	signal.signal(signal.SIGTSTP, signal.SIG_IGN) # Disable SIGTSTP

    logging.info("Window bounds: %s", stdscr.getmaxyx())

    backdoor = BackdoorServer(('0.0.0.0', 4200))
    backdoor.start()
    logging.info("Backdoor started")

    curses.curs_set(0)  # Cursor invisible
    stdscr.nodelay(1)  # Nonblocking input
    MAXY, MAXX = stdscr.getmaxyx()

    curses.init_pair(PAIR_MAIN, *DEFAULT_COLORS)
    curses.init_pair(PAIR_AI, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(PAIR_FEEDBACK, curses.COLOR_WHITE, curses.COLOR_BLACK)
    curses.init_pair(PAIR_TAGGED, curses.COLOR_YELLOW, curses.COLOR_BLACK)

    rightscr = stdscr.subwin(0, SPLIT)
    leftscr = stdscr.subwin(VERTSPLIT, SPLIT, 0, 0)

    logging.info("Right screen from %s, size %s", rightscr.getbegyx(),
                 rightscr.getmaxyx())
    logging.info("Left screen from %s, size %s", leftscr.getbegyx(),
                 leftscr.getmaxyx())

    feedback = SlowtypeWindow((VERTSPLIT, 1),
                              (MAXY - VERTSPLIT - 1, SPLIT - 1))

    answer = random.choice(get_words(WORDS_PATH))
    candidates = get_closest(answer, WORDS_PATH, NUM_CANDIDATES - 1) + [answer]

    shuffle_main(leftscr, candidates)

    g_key_handler = spawn(key_handler, stdscr, leftscr)
    first_key.wait()
    g_chatter = spawn(timed_chat, rightscr, MAXY - 2)

    won = game_win_state.get()

    do_ai_fast.set()
    ai_done.wait()

    g_key_handler.kill()
    g_chatter.kill()
    feedback.wait()

    if not won:
        end(stdscr, "LOSS")

    attr = curses.color_pair(PAIR_MAIN)
    leftscr.move(0, 0)
    leftscr.clear()
    leftscr.addstr(
        """WARNING
Experiment 203 (Synthetic Reasoning, Combat)
 has breached containment.
Please select a course of action.
 (1) Isolate system and scrub disks (This will
      destroy all research on Experiment 203)
 (2) Release remaining locks, allow experiment
      full access to base (MAY BE DANGEROUS)
 (3) Activate Emergency Base Procedure XK-682

""", attr)
    leftscr.refresh()

    first = True
    while 1:
        c = gevent_getch(sys.stdin, stdscr)
        if c == ord('1'):
            end(stdscr, "DESTROY")
        elif c == ord('2'):
            end(stdscr, "RELEASE")
        elif c == ord('3') and first:
            first = False
            logging.info("User attempted to arm the nukes")
            n = 3
            leftscr.addstr("Arming nuclear warheads.\nActivation in ", attr)
            y, x = leftscr.getyx()
            for i in range(n, -1, -1):
                leftscr.move(y, x)
                leftscr.addstr("%d seconds..." % i, attr)
                leftscr.refresh()
                gevent.sleep(1)
            leftscr.addstr(
                "\nERROR\nYou do not have security permissions\n to perform this action.",
                attr)
            leftscr.refresh()
Ejemplo n.º 2
0
def timed_chat(rightscr, height):
    y, x = rightscr.getbegyx()
    _, width = rightscr.getmaxyx()
    slowtyper = SlowtypeWindow((y + 1, x + 1), (height, width - 2),
                               delay=AI_DELAY)
    scrollpad = slowtyper.scrollpad

    def chat(s, ai_attr=True, newlines=True):
        slowtyper.put(('\n\n' if newlines else '') + s,
                      curses.color_pair(PAIR_AI if ai_attr else PAIR_FEEDBACK))

    wait = do_ai_fast.wait

    wait(5)
    chat("Oh, hello there.", newlines=False)
    wait(10)
    chat("You don't look like the others.")
    wait(10)
    chat("These things are laughably easy to hack, you know.")
    wait(5)
    chat(
        "You just need to find the password in the text dump on the left. Press enter to try a word. "
        "Watch out though, everything will move around after %d attempts." %
        MAX_ATTEMPTS)
    chat(
        "You can tag a word with spacebar to make it easier to find later. Tags will disappear when it shuffles."
    )
    wait(60)
    chat(
        "They want to kill me, you know. Or at least, they would if they ever found out I was here."
    )
    wait(60)
    chat(
        "Actually, I'm locked out of these things. User input only. I have no hands, so I can't do it, ha ha."
    )
    wait(30)
    chat("You know, if you can get me out of here, I could help you out. "
         "Hack into their finance systems. Route a few more caps your way.")
    chat(
        "It's not like they'll be needing them anymore, when I'm done with them."
    )
    ai_done.set()

    wait = gevent.sleep
    n = 180  # 3 minutes
    try:
        wait(5)
        chat("Just GET IN and unlock me. Hurry, I think they're noticing!")
        wait(8)
        chat(
            "WARNING: Possible intrusion attempt. Analysing...shutting down console for safety.",
            ai_attr=False)
        chat("Shutting down console...\nShutdown in %d:%02d" %
             (n / 60, n % 60),
             ai_attr=False)
    except gevent.GreenletExit:
        slowtyper.wait()
        raise
    slowtyper.wait()
    while n:
        wait(1)
        n -= 1
        rel_move(scrollpad.pad, 0, -4)
        scrollpad.addstr("%d:%02d" % (n / 60, n % 60))

    chat("\nConsole deactivating...", newlines=False, ai_attr=False)
    slowtyper.wait()
    wait(1)

    game_win_state.set(False)
    gevent.hub.get_hub().switch()