|  | @@ -12,6 +12,8 @@ Director::Director() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    // active = false;
 | 
	
		
			
				|  |  |    game = 0;  // not in a game
 | 
	
		
			
				|  |  | +  galaxy.reset();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    // do everything proxy_deactivate does ...
 | 
	
		
			
				|  |  |    // proxy_deactivate();
 | 
	
		
			
				|  |  |    active = false;
 | 
	
	
		
			
				|  | @@ -28,6 +30,8 @@ Director::Director() {
 | 
	
		
			
				|  |  |    SF_sectorline = [this](const std::string &s) { this->SL_sectorline(s); };
 | 
	
		
			
				|  |  |    SF_portline = [this](const std::string &s) { this->SL_portline(s); };
 | 
	
		
			
				|  |  |    SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  build_menu();
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  Director::~Director() { BUGZ_LOG(warning) << "Director::~Director()"; }
 | 
	
	
		
			
				|  | @@ -111,20 +115,13 @@ void Director::server_line(const std::string &line,
 | 
	
		
			
				|  |  |      There's a delay here when I save the game data.
 | 
	
		
			
				|  |  |      I've moved it futher down.  Hide it at a prompt, so it isn't so noticeable.
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    /*
 | 
	
		
			
				|  |  | -    if (game) {
 | 
	
		
			
				|  |  | -      // TODO:  Save galaxy data
 | 
	
		
			
				|  |  | -      galaxy.save();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    game = 0;
 | 
	
		
			
				|  |  | -    */
 | 
	
		
			
				|  |  |      // reset "active game" -- we're at the TWGS main menu
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    if (line.find("Selection (? for menu): ") != std::string::npos) {
 | 
	
		
			
				|  |  |      char ch = line[line.length() - 1];
 | 
	
		
			
				|  |  |      if (ch >= 'A' && ch < 'Q') {
 | 
	
		
			
				|  |  | -      if ((game) && (game != ch) ) {
 | 
	
		
			
				|  |  | +      if ((game) && (game != ch)) {
 | 
	
		
			
				|  |  |          galaxy.save();
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        game = ch;
 | 
	
	
		
			
				|  | @@ -141,6 +138,7 @@ void Director::server_line(const std::string &line,
 | 
	
		
			
				|  |  |          galaxy.save();
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        game = 0;
 | 
	
		
			
				|  |  | +      galaxy.reset();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -164,7 +162,7 @@ void Director::server_line(const std::string &line,
 | 
	
		
			
				|  |  |     This is where all of the server lines are gleaned for all the
 | 
	
		
			
				|  |  |     information that we can get out of them.
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    // When activating the computer 
 | 
	
		
			
				|  |  | +    // When activating the computer
 | 
	
		
			
				|  |  |      SP: [Command [TL=00:00:00]:[926] (?=Help)? : ]
 | 
	
		
			
				|  |  |      Sector: 926
 | 
	
		
			
				|  |  |      CI: [c]
 | 
	
	
		
			
				|  | @@ -188,7 +186,6 @@ void Director::server_line(const std::string &line,
 | 
	
		
			
				|  |  |      if (line == ": ") SL_parser = SF_cimline;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    if (SL_parser) {
 | 
	
		
			
				|  |  |      SL_parser(line);
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -208,11 +205,11 @@ void Director::server_prompt(const std::string &prompt,
 | 
	
		
			
				|  |  |    current_prompt = prompt;
 | 
	
		
			
				|  |  |    current_raw_prompt = raw_prompt;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | - 
 | 
	
		
			
				|  |  |    if (game) {
 | 
	
		
			
				|  |  |      if (prompt == "Selection (? for menu): ") {
 | 
	
		
			
				|  |  | -        galaxy.save();
 | 
	
		
			
				|  |  | -        game = 0;
 | 
	
		
			
				|  |  | +      galaxy.save();
 | 
	
		
			
				|  |  | +      game = 0;
 | 
	
		
			
				|  |  | +      galaxy.reset();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // in-game parsing here.
 | 
	
	
		
			
				|  | @@ -234,6 +231,28 @@ void Director::server_prompt(const std::string &prompt,
 | 
	
		
			
				|  |  |    if (chain) chain->server_prompt(prompt);
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +void Director::build_menu(void) {
 | 
	
		
			
				|  |  | +  main_menu = std::make_shared<MenuDispatch>(*this);
 | 
	
		
			
				|  |  | +  MenuDispatch *md = static_cast<MenuDispatch *>(&(*main_menu));
 | 
	
		
			
				|  |  | +  md->menu_box_color = "\x1b[1;33;44m";
 | 
	
		
			
				|  |  | +  md->menu_text_color = "\x1b[1;37;44m";
 | 
	
		
			
				|  |  | +  md->menu_title = "Proxy Menu";
 | 
	
		
			
				|  |  | +  md->menu_options_color = "\x1b[1;36;40m";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  md->menu_prompt =
 | 
	
		
			
				|  |  | +      "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
 | 
	
		
			
				|  |  | +      "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
 | 
	
		
			
				|  |  | +  md->lazy = true;
 | 
	
		
			
				|  |  | +  md->menu = {{"C", "Configure"},        {"D", "Display Report"},
 | 
	
		
			
				|  |  | +              {"E", "Export Data/Save"}, {"P", "Port CIM"},
 | 
	
		
			
				|  |  | +              {"W", "Warp CIM"},         {"T", "Trading Report"},
 | 
	
		
			
				|  |  | +              {"S", "Scripts"},          {"X", "eXit"}};
 | 
	
		
			
				|  |  | +  md->setNotify([this]() { this->menu_choice(); });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  cim = std::make_shared<CIMDispatch>(*this);
 | 
	
		
			
				|  |  | +  cim->setNotify([this]() { this->cim_done(); });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  void Director::proxy_activate(void) {
 | 
	
		
			
				|  |  |    active = true;   // yes, set keep-alive timer.
 | 
	
		
			
				|  |  |    to_server(" ");  // start keep-alive timer.
 | 
	
	
		
			
				|  | @@ -265,21 +284,8 @@ void Director::proxy_activate(void) {
 | 
	
		
			
				|  |  |    to_client(box.row(output));
 | 
	
		
			
				|  |  |    to_client(box.bottom());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  std::shared_ptr<Dispatch> menu = std::make_shared<MenuDispatch>(*this);
 | 
	
		
			
				|  |  | -  chain = menu;
 | 
	
		
			
				|  |  | -  MenuDispatch *md = static_cast<MenuDispatch *>(&(*menu));
 | 
	
		
			
				|  |  | -  md->menu_box_color = "\x1b[1;33;44m";
 | 
	
		
			
				|  |  | -  md->menu_text_color = "\x1b[1;37;44m";
 | 
	
		
			
				|  |  | -  md->menu_title = "Proxy Menu";
 | 
	
		
			
				|  |  | -  md->menu_options_color = "\x1b[1;36;40m";
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  md->menu_prompt =
 | 
	
		
			
				|  |  | -      "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
 | 
	
		
			
				|  |  | -      "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
 | 
	
		
			
				|  |  | -  md->lazy = true;
 | 
	
		
			
				|  |  | -  md->menu = {{"A", "Apple"}, {"B", "Blue"}, {"R", "Rabbit"}, {"Z", "ZOOO!"}};
 | 
	
		
			
				|  |  | -  md->setNotify([this]() { this->menu_choice(); });
 | 
	
		
			
				|  |  | -  menu->activate();
 | 
	
		
			
				|  |  | +  chain = main_menu;
 | 
	
		
			
				|  |  | +  main_menu->activate();
 | 
	
		
			
				|  |  |    /*
 | 
	
		
			
				|  |  |      // Using InputDispatch  -- and see have_input
 | 
	
		
			
				|  |  |      std::shared_ptr<Dispatch> readline = std::make_shared<InputDispatch>(*this);
 | 
	
	
		
			
				|  | @@ -300,6 +306,39 @@ void Director::menu_choice(void) {
 | 
	
		
			
				|  |  |        proxy_deactivate();
 | 
	
		
			
				|  |  |        return;
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  | +      switch (md->input[0]) {
 | 
	
		
			
				|  |  | +        case 'C':  // configure
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'D':  // display report
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'E':  // Export Data/Save
 | 
	
		
			
				|  |  | +          to_client("Saving...");
 | 
	
		
			
				|  |  | +          galaxy.save();
 | 
	
		
			
				|  |  | +          to_client("\rSaved....\n\r");
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'P':  // Port CIM
 | 
	
		
			
				|  |  | +          // TO FIX: Save type 0 & 9 ports, and restore!
 | 
	
		
			
				|  |  | +          chain = cim;
 | 
	
		
			
				|  |  | +          to_server("^RQ");
 | 
	
		
			
				|  |  | +          to_client("Port CIM Report\n\r");
 | 
	
		
			
				|  |  | +          chain->activate();
 | 
	
		
			
				|  |  | +          return;
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'W':  // Warp CIM
 | 
	
		
			
				|  |  | +          chain = cim;
 | 
	
		
			
				|  |  | +          to_server("^IQ");
 | 
	
		
			
				|  |  | +          to_client("Warp CIM Report\n\r");
 | 
	
		
			
				|  |  | +          chain->activate();
 | 
	
		
			
				|  |  | +          return;
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'T':  // Trading Report
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'S':  // Scripts
 | 
	
		
			
				|  |  | +          break;
 | 
	
		
			
				|  |  | +        case 'X':  // Exit
 | 
	
		
			
				|  |  | +          proxy_deactivate();
 | 
	
		
			
				|  |  | +          return;
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  |        std::string text = str(
 | 
	
		
			
				|  |  |            boost::format("Back from Menu [%1%] was selected.\n\r") % md->input);
 | 
	
		
			
				|  |  |        to_client(text);
 | 
	
	
		
			
				|  | @@ -328,6 +367,12 @@ void Director::have_input(void) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +void Director::cim_done(void) {
 | 
	
		
			
				|  |  | +  BUGZ_LOG(info) << "CIM done";
 | 
	
		
			
				|  |  | +  chain = main_menu;
 | 
	
		
			
				|  |  | +  main_menu->activate();
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  void Director::proxy_deactivate(void) {
 | 
	
		
			
				|  |  |    active = false;
 | 
	
		
			
				|  |  |    // reset everything back to good state
 | 
	
	
		
			
				|  | @@ -351,8 +396,9 @@ void Director::SL_cimline(const std::string &line) {
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    if (line == ": ") {
 | 
	
		
			
				|  |  |      // do I need to do anything special here for this?
 | 
	
		
			
				|  |  | -    // Maybe -- We would save special ports that don't show up (StarDock/Special) before.
 | 
	
		
			
				|  |  | -    // We don't know (at this point) if this is warps or ports.
 | 
	
		
			
				|  |  | +    // Maybe -- We would save special ports that don't show up
 | 
	
		
			
				|  |  | +    // (StarDock/Special) before. We don't know (at this point) if this is warps
 | 
	
		
			
				|  |  | +    // or ports.
 | 
	
		
			
				|  |  |      return;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    if (line.empty()) {
 | 
	
	
		
			
				|  | @@ -372,7 +418,7 @@ void Director::SL_cimline(const std::string &line) {
 | 
	
		
			
				|  |  |        BUGZ_LOG(fatal) << "portcim:  FAIL [" << line << "]";
 | 
	
		
			
				|  |  |      else
 | 
	
		
			
				|  |  |        BUGZ_LOG(fatal) << "portcim: " << p;
 | 
	
		
			
				|  |  | -    galaxy.add_port(p);    
 | 
	
		
			
				|  |  | +    galaxy.add_port(p);
 | 
	
		
			
				|  |  |    } else {
 | 
	
		
			
				|  |  |      // warpcim
 | 
	
		
			
				|  |  |      BUGZ_LOG(fatal) << "warpcim: [" << line << "]";
 | 
	
	
		
			
				|  | @@ -417,36 +463,36 @@ void Director::SL_sectorline(const std::string &line) {
 | 
	
		
			
				|  |  |      sectorline: [Warps to Sector(s) :  70 - 441 - 575 - 600 - 629 - 711]
 | 
	
		
			
				|  |  |      sectorline: [Warps to Sector(s) :  70 - (475) - 569]
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  | -   if (in(line, "Sector  :")) {
 | 
	
		
			
				|  |  | -     current_sector = stoi(line.substr(10));
 | 
	
		
			
				|  |  | -     BUGZ_LOG(warning) << "SECTOR: " << current_sector;
 | 
	
		
			
				|  |  | -   }
 | 
	
		
			
				|  |  | -   if (in(line, "Ports   :")) {
 | 
	
		
			
				|  |  | -     std::string port_class;
 | 
	
		
			
				|  |  | -     size_t pos = line.find(", Class ");
 | 
	
		
			
				|  |  | -     if (pos != std::string::npos) {
 | 
	
		
			
				|  |  | -       pos += 8;
 | 
	
		
			
				|  |  | -       int class_ = stoi(line.substr(pos));
 | 
	
		
			
				|  |  | -       BUGZ_LOG(fatal) << "PORT: " << class_;
 | 
	
		
			
				|  |  | -       galaxy.add_port(current_sector, class_);
 | 
	
		
			
				|  |  | -     }
 | 
	
		
			
				|  |  | -   }
 | 
	
		
			
				|  |  | -   if (in(line, "Warps to Sector(s) :")) {
 | 
	
		
			
				|  |  | -     std::string temp = line.substr( 20 );
 | 
	
		
			
				|  |  | -     replace(temp, " - ", " ");
 | 
	
		
			
				|  |  | -     // unexplored sectors ()
 | 
	
		
			
				|  |  | -     // Should I track these?
 | 
	
		
			
				|  |  | -     replace(temp, "(", "");
 | 
	
		
			
				|  |  | -     replace(temp, ")", "");
 | 
	
		
			
				|  |  | -     sector_warps sw;
 | 
	
		
			
				|  |  | -     auto warps = split(temp);
 | 
	
		
			
				|  |  | -     sw.sector = current_sector;
 | 
	
		
			
				|  |  | -     for( auto const &w : warps) {
 | 
	
		
			
				|  |  | -       sw.add(stoi(w));
 | 
	
		
			
				|  |  | -     }
 | 
	
		
			
				|  |  | -     BUGZ_LOG(fatal) << "WARPS: " << sw;
 | 
	
		
			
				|  |  | -     galaxy.add_warp(sw);
 | 
	
		
			
				|  |  | -   }
 | 
	
		
			
				|  |  | +    if (in(line, "Sector  :")) {
 | 
	
		
			
				|  |  | +      current_sector = stoi(line.substr(10));
 | 
	
		
			
				|  |  | +      BUGZ_LOG(warning) << "SECTOR: " << current_sector;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    if (in(line, "Ports   :")) {
 | 
	
		
			
				|  |  | +      std::string port_class;
 | 
	
		
			
				|  |  | +      size_t pos = line.find(", Class ");
 | 
	
		
			
				|  |  | +      if (pos != std::string::npos) {
 | 
	
		
			
				|  |  | +        pos += 8;
 | 
	
		
			
				|  |  | +        int class_ = stoi(line.substr(pos));
 | 
	
		
			
				|  |  | +        BUGZ_LOG(fatal) << "PORT: " << class_;
 | 
	
		
			
				|  |  | +        galaxy.add_port(current_sector, class_);
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    if (in(line, "Warps to Sector(s) :")) {
 | 
	
		
			
				|  |  | +      std::string temp = line.substr(20);
 | 
	
		
			
				|  |  | +      replace(temp, " - ", " ");
 | 
	
		
			
				|  |  | +      // unexplored sectors ()
 | 
	
		
			
				|  |  | +      // Should I track these?
 | 
	
		
			
				|  |  | +      replace(temp, "(", "");
 | 
	
		
			
				|  |  | +      replace(temp, ")", "");
 | 
	
		
			
				|  |  | +      sector_warps sw;
 | 
	
		
			
				|  |  | +      auto warps = split(temp);
 | 
	
		
			
				|  |  | +      sw.sector = current_sector;
 | 
	
		
			
				|  |  | +      for (auto const &w : warps) {
 | 
	
		
			
				|  |  | +        sw.add(stoi(w));
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      BUGZ_LOG(fatal) << "WARPS: " << sw;
 | 
	
		
			
				|  |  | +      galaxy.add_warp(sw);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -470,14 +516,14 @@ void Director::SL_portline(const std::string &line) {
 | 
	
		
			
				|  |  |     */
 | 
	
		
			
				|  |  |    BUGZ_LOG(info) << "portline : " << line;
 | 
	
		
			
				|  |  |    if (in(line, "%")) {
 | 
	
		
			
				|  |  | -  // size_t pos = line.find('%');
 | 
	
		
			
				|  |  | -  // if (pos != line.npos) {
 | 
	
		
			
				|  |  | +    // size_t pos = line.find('%');
 | 
	
		
			
				|  |  | +    // if (pos != line.npos) {
 | 
	
		
			
				|  |  |      // Ok, this is a valid portline
 | 
	
		
			
				|  |  |      std::string work = line;
 | 
	
		
			
				|  |  |      replace(work, "Fuel Ore", "Fuel");
 | 
	
		
			
				|  |  |      auto parts = split(work);
 | 
	
		
			
				|  |  |      BUGZ_LOG(fatal) << "portline split:";
 | 
	
		
			
				|  |  | -    for( auto const p : parts) {
 | 
	
		
			
				|  |  | +    for (auto const p : parts) {
 | 
	
		
			
				|  |  |        BUGZ_LOG(fatal) << p;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      // BUGZ_LOG(fatal) << "portline split : [" << parts << "]";
 |