Explorar el Código

Need server_line raw_line, to display to client.

If we get any input from the server, we need to display it
to the client when the proxy is active.
Steve Thielemann hace 3 años
padre
commit
9495004801
Se han modificado 6 ficheros con 31 adiciones y 23 borrados
  1. 3 3
      director.cpp
  2. 2 2
      director.h
  3. 15 8
      dispatchers.cpp
  4. 7 6
      dispatchers.h
  5. 3 3
      session.cpp
  6. 1 1
      session.h

+ 3 - 3
director.cpp

@@ -28,7 +28,7 @@ void Director::client_input(const std::string &input) {
     chain->client_input(input);
     return;
   }
-  
+
   if (active) {
     if (input == "Q" || input == "q") proxy_deactivate();
     return;
@@ -99,7 +99,7 @@ void Director::client_input(const std::string &input) {
 
 }
 
-void Director::server_line(const std::string &line) {
+void Director::server_line(const std::string &line, const std::string &raw_line) {
   // check for if we entered game/left game
 
   if (line.find("TradeWars Game Server   ") != std::string::npos) {
@@ -128,7 +128,7 @@ void Director::server_line(const std::string &line) {
   }
    */
   if (chain) {
-    chain->server_line(line);
+    chain->server_line(line, raw_line);
   }
 }
 

+ 2 - 2
director.h

@@ -13,7 +13,7 @@ class Director {
   std::function <void(notifyFunc)> post;
   
   void client_input(const std::string &input);
-  void server_line(const std::string &line);
+  void server_line(const std::string &line, const std::string &raw_line);
   void server_prompt(const std::string &prompt, const std::string &raw_prompt);
 
   bool active;
@@ -44,7 +44,7 @@ class Director {
 
   void have_input(void);
   int count;
-  
+
  private:
   StringFunc SL_parser;
   void SL_cimline(const std::string &line);

+ 15 - 8
dispatchers.cpp

@@ -31,11 +31,11 @@ void Dispatch::chain_client_input(const std::string &input) {
   }
 }
 
-void Dispatch::chain_server_line(const std::string &line) {
+void Dispatch::chain_server_line(const std::string &line, const std::string &raw_line) {
   if (chain) {
-    chain->chain_server_line(line);
+    chain->chain_server_line(line, raw_line);
   } else {
-    server_line(line);
+    server_line(line, raw_line);
   }
 }
 
@@ -47,7 +47,7 @@ void Dispatch::chain_server_prompt(const std::string &prompt) {
   }
 }
 
-void Dispatch::server_line(const std::string &line) {}
+void Dispatch::server_line(const std::string &line, const std::string &raw_line) {}
 void Dispatch::server_prompt(const std::string &prompt) {}
 void Dispatch::client_input(const std::string &input) {}
 
@@ -166,7 +166,7 @@ void MainDispatch::deactivate(void) {
   notify();
 }
 
-void MainDispatch::server_line(const std::string &line) {
+void MainDispatch::server_line(const std::string &line, const std::string &raw_line) {
   BUGZ_LOG(info) << "MDSL: " << line;
   to_client("SL: ");
   to_client(line);
@@ -211,7 +211,11 @@ void InputDispatch::activate(void) {
 
 void InputDispatch::deactivate(void) { notify(); }
 
-void InputDispatch::server_line(const std::string &line) {}
+void InputDispatch::server_line(const std::string &line, const std::string &raw_line) {
+  // TO FIX:
+  // clear user input and input prompt, display server_line,
+  // and re-display prompt.
+}
 // void InputDispatch::server_prompt(const std::string &prompt) {}
 
 void InputDispatch::client_input(const std::string &cinput) {
@@ -358,7 +362,10 @@ void MenuDispatch::calculate_widths(void) {
   instant = max_option_width == 1;
 }
 
-void MenuDispatch::server_line(const std::string &line) {}
+void MenuDispatch::server_line(const std::string &line, const std::string &raw_line) {
+  // TODO:
+  // Clear prompt, display raw server line, restore prompt.
+}
 
 void MenuDispatch::client_input(const std::string &cinput) {
   for (auto const ch : cinput) {
@@ -453,7 +460,7 @@ void CoreDispatch::deactivate(void) {
   notify();
 }
 
-void CoreDispatch::server_line(const std::string &line) {}
+void CoreDispatch::server_line(const std::string &line, const std::string &raw_line) {}
 void CoreDispatch::server_prompt(const std::string &prompt) {}
 void CoreDispatch::client_input(const std::string &input) {
   BUGZ_LOG(warning) << "Got: " << input << " prompt=" << get_prompt();

+ 7 - 6
dispatchers.h

@@ -46,10 +46,10 @@ class Dispatch {
 
   // default to chain calls
   void chain_client_input(const std::string &input);
-  void chain_server_line(const std::string &line);
+  void chain_server_line(const std::string &line, const std::string &raw_line);
   void chain_server_prompt(const std::string &prompt);
   virtual void client_input(const std::string &input);
-  virtual void server_line(const std::string &line);
+  virtual void server_line(const std::string &line, const std::string &raw_line);
   virtual void server_prompt(const std::string &prompt);
 };
 
@@ -73,7 +73,8 @@ class InputDispatch : public Dispatch {
   void deactivate(void) override;
 
   // optional here
-  void server_line(const std::string &line) override;
+  void server_line(const std::string &line,
+                   const std::string &raw_line) override;
   // void server_prompt(const std::string &prompt);
   void client_input(const std::string &cinput) override;
 };
@@ -107,7 +108,7 @@ class MenuDispatch : public Dispatch {
   void deactivate(void) override;
 
   // optional here
-  void server_line(const std::string &line) override;
+  void server_line(const std::string &line, const std::string &raw_line) override;
   // void server_prompt(const std::string &prompt);
   void client_input(const std::string &cinput) override;
 };
@@ -136,7 +137,7 @@ class MainDispatch : public Dispatch {
   void have_input(void);
   void menu_choice(void);
 
-  void server_line(const std::string &line) override;
+  void server_line(const std::string &line, const std::string &raw_line) override;
   void server_prompt(const std::string &prompt) override;
   // void client_input(const std::string &input);
 
@@ -153,7 +154,7 @@ class CoreDispatch : public Dispatch {
   void deactivate(void) override;
 
   // optional here
-  void server_line(const std::string &line) override;
+  void server_line(const std::string &line, const std::string &raw_line) override;
   void server_prompt(const std::string &prompt) override;
   void client_input(const std::string &input) override;
 };

+ 3 - 3
session.cpp

@@ -138,9 +138,9 @@ void Session::on_connect(const boost::system::error_code error) {
  * See \ref split_lines()
  * @param line
  */
-void Session::on_server_line(const std::string &line) {
+void Session::on_server_line(const std::string &line, const std::string &raw_line) {
   BUGZ_LOG(info) << "SL: [" << line << "]";
-  director.server_line(line);
+  director.server_line(line, raw_line);
 
 #ifdef DECOUPLE
   if (line.find("TradeWars Game Server   ") != std::string::npos) {
@@ -237,7 +237,7 @@ void Session::split_lines(std::string line) {
   }
 
   std::string temp = clean_string(line);
-  on_server_line(temp);
+  on_server_line(temp, line);
 }
 
 /*

+ 1 - 1
session.h

@@ -51,7 +51,7 @@ class Session : public std::enable_shared_from_this<Session> {
  private:
   Director director;
 
-  void on_server_line(const std::string &line);
+  void on_server_line(const std::string &line, const std::string &raw_line);
   void on_server_prompt(const std::string &prompt,
                         const std::string &raw_prompt);