Browse Source

Added circular buffer. Fixed connect.

We weren't able to connect when there's a customized game screen.
This is fixed.
Steve Thielemann 3 years ago
parent
commit
ceb3464285
3 changed files with 46 additions and 2 deletions
  1. 43 2
      director.cpp
  2. 2 0
      director.h
  3. 1 0
      pch.hpp

+ 43 - 2
director.cpp

@@ -127,6 +127,8 @@ void Director::client_input(const std::string &input) {
 void Director::server_line(const std::string &line,
                            const std::string &raw_line) {
   // check for if we entered game/left game
+  SL_history.push_back(line);
+
   if (!chain) BUGZ_LOG(info) << "SL: [" << line << "]";
 
   if (line.find("TradeWars Game Server   ") != std::string::npos) {
@@ -140,6 +142,45 @@ void Director::server_line(const std::string &line,
     // reset "active game" -- we're at the TWGS main menu
   }
 
+  if (line == "Trade Wars 2002 Win32 module now loading.") {
+    // This happens if the game is customized with ANSI/menus/etc.
+    // We're not detecting the Selection, go find what was selected.
+    auto find = SL_history.rbegin();
+    ++find;
+    while (find != SL_history.rend()) {
+      if (*find != "") {
+        std::string last_SL = *find;
+        char ch = last_SL[last_SL.length() - 1];
+        if ((game) && (game != ch)) {
+          galaxy.save();
+        }
+        game = ch;
+
+        BUGZ_LOG(warning) << "GAME " << game << " activated!";
+        galaxy.game = game;
+        galaxy.username = username;
+        galaxy.load();
+
+        // YAML loaded, set sensible default config values (if missing).
+        if (!galaxy.config.contains("display_lines")) {
+          galaxy.config["display_lines"] = 20;
+        }
+
+        galaxy.meta["help"]["display_lines"] =
+            "Number of report lines to display";
+
+        if (!galaxy.config.contains("burnt_percent")) {
+          galaxy.config["burnt_percent"] = 40;
+        }
+
+        galaxy.meta["help"]["burnt_percent"] =
+            "Don't display ports in report below this percent";
+        break;
+      }
+      ++find;
+    }
+  }
+
   if (line.find("Selection (? for menu): ") != std::string::npos) {
     char ch = line[line.length() - 1];
     if (ch >= 'A' && ch < 'Q') {
@@ -967,8 +1008,8 @@ void Director::macro_have_input(void) {
       char c = toupper(id->input[0]);
       macro_item.assign(1, c);
       if (galaxy.meta["macros"].contains(macro_item)) {
-        constexpr ANSIColor key("BOLD GREEN"); // COLOR::GREEN, ATTR::BOLD);
-        constexpr ANSIColor value("BOLD BLUE"); // COLOR::BLUE, ATTR::BOLD);
+        constexpr ANSIColor key("BOLD GREEN");   // COLOR::GREEN, ATTR::BOLD);
+        constexpr ANSIColor value("BOLD BLUE");  // COLOR::BLUE, ATTR::BOLD);
         std::string output =
             str(boost::format("%1%%2% : %3%%4%\n\r") % key() % macro_item %
                 value() % galaxy.meta["macros"][macro_item]);

+ 2 - 0
director.h

@@ -2,6 +2,7 @@
 #define DIRECTOR_H
 #include "galaxy.h"
 #include "session_common.h"
+#include <boost/circular_buffer.hpp>
 
 class Dispatch;
 class MenuDispatch;
@@ -109,6 +110,7 @@ class Director {
 
   int computer_port_sector;
   bool computer_port_done;
+  boost::circular_buffer<std::string> SL_history{10};
 };
 
 #include "dispatchers.h"

+ 1 - 0
pch.hpp

@@ -14,4 +14,5 @@
 #include <string>
 #include <map>
 #include "json.hpp"
+#include <boost/circular_buffer.hpp>