int proc_loop(void) { int rc = 0; log_debug("setting working directory ...\n"); if ((mkdir(daemon_cfg.notify_dir, 0777) != 0) && (errno != EEXIST)) { rc = -errno; log_error("failed create folder %s (errno = %d)\n", daemon_cfg.notify_dir, errno); goto err; } log_debug("setting store ...\n"); rc = open_store(); if (rc < 0) { goto err; } log_debug("setting flow ...\n"); rc = open_flow(); if (rc < 0) { goto err; } log_debug("setting notification ...\n"); rc = open_notify(); if (rc < 0) { goto err; } log_debug("setting message processing ...\n"); rc = open_message(); if (rc < 0) { goto err; } log_debug("starting loop ...\n"); while ((0 == daemon_cfg.sig) && (errno != EINTR)) { fd_set readfds; struct timeval tv; int max_fd = -1; FD_ZERO(&readfds); FD_SET(daemon_cfg.sock_fd, &readfds); max_fd = daemon_cfg.sock_fd; FD_SET(daemon_cfg.notify_fd, &readfds); max_fd = (max_fd < daemon_cfg.notify_fd ? daemon_cfg.notify_fd : max_fd); /* Use timeout for select() call */ tv.tv_sec = 60; tv.tv_usec = 0; rc = select(max_fd + 1, &readfds, NULL, NULL, &tv); if (rc < 0) { rc = 0; if (errno != EINTR) { rc = -errno; log_error("Failed select() errno %d (%s)\n", errno, strerror(errno)); } goto err; } else if (rc == 0) { continue; } /* Check messages from processes */ if (FD_ISSET(daemon_cfg.sock_fd, &readfds)) { log_debug("message processing ...\n"); rc = proc_message(); } /* Check any events from file system monitor */ if (FD_ISSET(daemon_cfg.notify_fd, &readfds)) { log_debug("notification processing ...\n"); rc = proc_notify(); } } err: log_debug("finishing loop ...\n"); close_message(); close_notify(); close_flow(); close_store(); return rc; }
void NeutralSystem::special() { System::special(); utilities::clear_display(); // always an ambush FightEvent fe(player, 5, 3); fe.run(); utilities::wait_for_user(); utilities::clear_display(); // game is over if (player->is_dead()) return; // 15% chance of finding money if (rand() % 100 < 15) { MonetaryEvent me(player); me.run(); utilities::wait_for_user(); utilities::clear_display(); } // 15% chance of being taxed if (rand() % 100 < 15) { TaxEvent te(player); te.run(); utilities::wait_for_user(); } // user done with menu bool done = false; // user already asked for info? bool asked = false; while (!done) { utilities::clear_display(); make_menu(); int num_ops = static_cast<int>(system_menu.get_num_options()); system_menu.display(); std::cout << "What would you like to do?\n"; int choice = utilities::get_valid_int_in_range(1, num_ops); utilities::clear_display(); std::string map_header = std::string("========== Map - Current System: ") + player->get_cur_system()->get_name() + " ==========\n\n"; switch (choice) { case 1: done = true; break; case 2: player->print_status("========== Status ==========\n\n"); break; case 3: std::cout << map_header; view_map(); break; case 4: open_store(); break; case 5: sell(); break; case 6: refuel(); break; case 7: repair(); break; case 8: buy_ship(); break; case 9: { if (!asked) { ask_info(); asked = true; } else std::cout << "You have already gotten all the information you can get right now!\n\n"; break; } default: jump_to(choice); done = true; // wants to jump } utilities::wait_for_user(); } }