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()
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()
def __init__(self, pos, size, delay=0.01): self.scrollpad = ScrollPad(pos, size) self.queue = Queue() self.g_writer = spawn(self.writer) self.delay = delay _, self.width = size