| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 | 
							- #ifndef SESSION_H
 
- #define SESSION_H
 
- #include <boost/asio.hpp>
 
- #include <boost/asio/ip/basic_resolver.hpp>
 
- #include <map>
 
- #include <string>
 
- #include "session_common.h"
 
- #include "dispatchers.h"
 
- #define MAX_BUFFER 256
 
- /*
 
- The Session:
 
-  */
 
- class Session : public std::enable_shared_from_this<Session> {
 
- public:
 
-   Session(boost::asio::ip::tcp::socket socket,
 
-           boost::asio::io_service &io_service, std::string hostname,
 
-           std::string port);
 
-   ~Session();
 
-   void start(void);
 
-   const std::string &get_prompt(void);
 
-   void set_prompt(const std::string &prompt);
 
-   void to_client(const std::string &message);
 
-   void to_server(const std::string &message);
 
-   DispatchSettings save_settings(void);
 
-   void restore_settings(const DispatchSettings &ss);
 
-   // what uses these? how do you use these?
 
-   StringFunc emit_server_line;
 
-   StringFunc emit_server_prompt;
 
-   StringFunc emit_client_input;
 
-   bool show_client = true;
 
-   bool talk_direct = true;
 
-   void post(notifyFunc nf);
 
- private:
 
-   void on_server_line(const std::string &line);
 
-   void on_server_prompt(const std::string &prompt);
 
-   void parse_auth(void);
 
-   void on_connect(const boost::system::error_code error);
 
-   void server_read(void);
 
-   void on_resolve(const boost::system::error_code error,
 
-                   const boost::asio::ip::tcp::resolver::results_type results);
 
-   void client_read(void);
 
-   void client_input(const std::string &input);
 
-   void on_shutdown(boost::system::error_code ec);
 
-   void split_lines(std::string line);
 
-   void process_lines(std::string &received);
 
- private:
 
-   void set_prompt_timer(void);
 
-   void reset_prompt_timer(void);
 
-   void on_prompt_timeout(const boost::system::error_code error);
 
-   void stayin_alive(const boost::system::error_code error);
 
-   void start_keepin_alive(void);
 
-   int time_ms;
 
-   int keepalive_secs;
 
-   MainDispatch main;
 
-   void proxy_activate(void);
 
-   void proxy_deactivate(void);
 
-   // std::stack<Dispatch *> director;
 
-   bool active = false;
 
-   /**
 
-    * The client's socket
 
-    */
 
-   boost::asio::ip::tcp::socket socket_;
 
-   boost::asio::io_service &io_service_;
 
-   boost::asio::ip::tcp::resolver resolver_;
 
-   /**
 
-    * The server's socket
 
-    */
 
-   boost::asio::ip::tcp::socket server_;
 
-   /**
 
-    * The time that we'll use to fire off the "prompt" event.
 
-    *
 
-    * The idea being that we'd receive chars, processing lines.
 
-    * And if we have something in server_prompt start the timer.
 
-    * If we receive more, process lines, if !server_prompt.empty()
 
-    * reset the timer.
 
-    *
 
-    * If the timer fires (and isn't aborted), fire off the prompt.
 
-    *
 
-    * I'm not so sure about this -- because this adds delay to the
 
-    * proxy.  [It might be better to just fire off "some" text, and
 
-    * have it ignored, rather then adding a delay.]  Or, this might
 
-    * not matter at all, I'm thinking milliseconds here!
 
-    */
 
-   boost::asio::high_resolution_timer prompt_timer_;
 
-   /**
 
-    * Keep connection alive, don't timeout.
 
-    *
 
-    * This gets set by to_server config[keepalive], and sends a
 
-    * space ' ' if we haven't sent anything to the server in that
 
-    * many seconds.
 
-    */
 
-   boost::asio::high_resolution_timer keep_alive_;
 
-   /**
 
-    * What characters have been received from the server,
 
-    * that weren't \n terminated?
 
-    *
 
-    * This needs to be reset/cleared if there's a \r (carriage return).
 
-    */
 
-   std::string server_prompt;
 
-   /**
 
-    * FAIL-WHALE: This was supposed to hold the number of characters
 
-    * already sent to the user at this point in time, but I'm having
 
-    * a hard time tracking those.
 
-    *
 
-    */
 
-   // int server_sent;
 
-   /**
 
-    * The client read buffer.
 
-    *
 
-    * This is too big, we don't get that many characters from the client.
 
-    *
 
-    */
 
-   char read_buffer[MAX_BUFFER + 1];
 
-   /**
 
-    * The server read buffer.
 
-    * This is MAX_BUFFER + 1 (to store the \0 to terminate the string)
 
-    */
 
-   char server_buffer[MAX_BUFFER + 1];
 
-   /**
 
-    * The rlogin information received from the client.
 
-    *
 
-    * We check this, and if it isn't valid, we spoof some rlogin
 
-    * connection.
 
-    */
 
-   std::string rlogin_auth;
 
-   /**
 
-    * The username passed in via rlogin.  We need this so we know what
 
-    * name we need to store the data under.
 
-    */
 
-   std::string rlogin_name;
 
-   std::string host;
 
-   std::string port;
 
-   char game = 0;
 
-   /**
 
-    * Are we connected to the server?
 
-    *
 
-    * Don't shutdown the server socket if we aren't connected.
 
-    */
 
-   bool connected = false;
 
- };
 
- /*
 
- maybe move the resolver part to the server, so I don't need io_service?
 
- I'm not sure what the socket connection part is going to need just yet,
 
- so I probably won't move that just yet.  [NNY!]
 
- */
 
- class Server {
 
- 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)
 
-    */
 
-   std::string host_;
 
-   /**
 
-    * The port to connect to (from config)
 
-    *
 
-    */
 
-   std::string port_;
 
-   bool only_one;
 
- };
 
- #ifdef NEVERMORE
 
- // The simple way to get the boost logging to log file and line number
 
- // information.  [Let the BUGZ_LOG macro do it!]
 
- #include <iomanip>
 
- #include <string.h>
 
- const char *trim_path(const char *filepath);
 
- #define BUGZ_LOG(severity)                                                     \
 
-   BOOST_LOG_TRIVIAL(severity)                                                  \
 
-       << "(" << std::setw(15) << trim_path(__FILE__) << ":" << std::setw(4)    \
 
-       << std::left << __LINE__ << ") "
 
- #endif
 
- #endif
 
 
  |