Ver Fonte

Handle fail to connect, etc.

Updated prompt (space between talkto and
input).
bugz há 3 anos atrás
pai
commit
d88c63d445
2 ficheiros alterados com 26 adições e 5 exclusões
  1. 17 0
      irc.cpp
  2. 9 5
      main.cpp

+ 17 - 0
irc.cpp

@@ -172,6 +172,11 @@ void ircClient::on_resolve(
   if (logging) {
     log() << "Resolve: " << error.message() << std::endl;
   }
+  if (error) {
+    std::string output = "Unable to resolve (DNS Issue?): " + error.message();
+    message(output);
+    socket.async_shutdown(std::bind(&ircClient::on_shutdown, this, _1));
+  }
   boost::asio::async_connect(socket.next_layer(), results,
                              std::bind(&ircClient::on_connect, this, _1, _2));
 }
@@ -182,6 +187,12 @@ void ircClient::on_connect(error_code error,
     log() << "Connect: " << error.message() << ", endpoint: " << endpoint
           << std::endl;
   }
+  if (error) {
+    std::string output = "Unable to connect: " + error.message();
+    message(output);
+    socket.async_shutdown(std::bind(&ircClient::on_shutdown, this, _1));
+  }
+
   socket.async_handshake(boost::asio::ssl::stream_base::client,
                          std::bind(&ircClient::on_handshake, this, _1));
 }
@@ -190,6 +201,12 @@ void ircClient::on_handshake(error_code error) {
   if (logging) {
     log() << "Handshake: " << error.message() << std::endl;
   }
+  if (error) {
+    std::string output = "Handshake: " + error.message();
+    message(output);
+    socket.async_shutdown(std::bind(&ircClient::on_shutdown, this, _1));
+  }
+
   std::string request = registration();
   boost::asio::async_write(socket, boost::asio::buffer(request),
                            std::bind(&ircClient::on_write, this, _1, _2));

+ 9 - 5
main.cpp

@@ -38,13 +38,13 @@ void clear_input(door::Door &d) {
   if (prompt.empty())
     return;
   erase(d, input.size());
-  erase(d, prompt.size());
+  erase(d, prompt.size() + 1);
 }
 
 void restore_input(door::Door &d) {
   if (prompt.empty())
     return;
-  d << prompt_color << prompt << input_color << input;
+  d << prompt_color << prompt << input_color << " " << input;
 }
 
 /*
@@ -71,8 +71,8 @@ bool check_for_input(door::Door &d, ircClient &irc) {
     // ok, nothing has been displayed at this time.
     if (d.haskey()) {
       // something to do.
-      prompt = "[" + irc.talkto + "] ";
-      d << prompt_color << prompt << input_color;
+      prompt = "[" + irc.talkto + "]";
+      d << prompt_color << prompt << input_color << " ";
       c = d.sleep_key(1);
       if (c < 0) {
         // handle timeout/hangup/out of time
@@ -155,7 +155,7 @@ bool check_for_input(door::Door &d, ircClient &irc) {
           // erasing the last character
           erase(d, 1);
           input.clear();
-          erase(d, prompt.size());
+          erase(d, prompt.size() + 1);
           prompt.clear();
           return false;
         }
@@ -244,6 +244,10 @@ int main(int argc, char *argv[]) {
         // command given
         if (std::toupper(input[1]) == 'Q') {
           irc.write("QUIT");
+        } else {
+          // for now, just output whatever they gave us.
+          input.erase(0,1);
+          irc.write(input);
         }
       } else {
         std::string output = "PRIVMSG " + irc.talkto + " :" + input;