Jelajahi Sumber

Save active game. Show ~dtor.

Steve Thielemann 3 tahun lalu
induk
melakukan
2312d98bf6
2 mengubah file dengan 14 tambahan dan 4 penghapusan
  1. 9 2
      session.cpp
  2. 5 2
      session.h

+ 9 - 2
session.cpp

@@ -174,6 +174,7 @@ void Session::dispatch_line(std::string line) {
 
   if (temp.find("TradeWars Game Server   ") != std::string::npos) {
     to_client("\rTradeWars Proxy v2++ READY (~ to activate)\n\r");
+    game = 0;
     // reset "active game" -- we're back at the menu
   }
 
@@ -184,8 +185,11 @@ void Session::dispatch_line(std::string line) {
   if (temp.find("Selection (? for menu): ") != std::string::npos) {
     char ch = temp[temp.length() - 1];
     if (ch >= 'A' && ch < 'Q') {
-      BUGZ_LOG(warning) << "GAME " << ch << " activated!";
+      game = ch;
+      BUGZ_LOG(warning) << "GAME " << game << " activated!";
     }
+    if (ch == 'Q')
+      game = 0;
   }
 
   // "Selection (? for menu): ?"
@@ -543,9 +547,11 @@ Server::Server(boost::asio::io_service &io_service,
     : io_service_{io_service}, acceptor_{io_service_, endpoint}, host_{host},
       port_{port} {
   only_one = from_config("one_connection", "0") == "1";
+  BUGZ_LOG(info) << "Server::Server()";
   do_accept();
 }
 
+Server::~Server() { BUGZ_LOG(info) << "Server::~Server()"; }
 /**
  * setup async connect accept
  *
@@ -562,8 +568,9 @@ void Server::do_accept(void) {
           ->start();
     }
 
-    if (!only_one)
+    if (!only_one) {
       do_accept();
+    }
   });
 }
 

+ 5 - 2
session.h

@@ -61,7 +61,7 @@ private:
   bool show_client = true;
   bool talk_direct = true;
   bool active = false;
-  
+
   /**
    * The client's socket
    */
@@ -139,7 +139,8 @@ private:
   std::string rlogin_name;
   std::string host;
   std::string port;
-
+  char game = 0;
+  
   /**
    * Are we connected to the server?
    *
@@ -162,12 +163,14 @@ public:
   Server(boost::asio::io_service &io_service,
          const boost::asio::ip::tcp::endpoint &endpoint, std::string host,
          std::string port);
+  ~Server();
 
 private:
   void do_accept(void);
 
   boost::asio::io_service &io_service_;
   boost::asio::ip::tcp::acceptor acceptor_;
+
   /**
    * The host to connect to (from config)
    */