diff options
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r-- | src/core/netconnection.cc | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 4892792..ee3e754 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -56,8 +56,13 @@ void NetConnection::connect(std::string const &to_host, int to_port) struct hostent *serverhostent; serverhostent = gethostbyname(to_host.c_str()); if (!serverhostent) { - con_warn << "Could not resolve '" << to_host.c_str() << "'" << std::endl; + std::ostringstream str; + str << "Could not resolve hostname'" << to_host.c_str() << "'"; + con_error << str.str() << std::endl; + abort(); + + application()->messagebox(str.str().c_str()); return; } @@ -76,8 +81,13 @@ void NetConnection::connect(std::string const &to_host, int to_port) server_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)serverhostent->h_addr))); memset(server_addr.sin_zero, '\0', sizeof server_addr.sin_zero); if (server_addr.sin_addr.s_addr == INADDR_NONE) { - con_error << "Network invalid address " << to_host << "!" << std::endl; + std::ostringstream str; + str << "Invalid address for '" << to_host << "'"; + con_error << str.str() << std::endl; + abort(); + + application()->messagebox(str.str().c_str()); return; } @@ -156,12 +166,14 @@ void NetConnection::receive() if (bytes_received == 0) { con_print << "^BDisconnected." << std::endl; - abort(); + abort(); + application()->messagebox("Disconnected from server."); return; } else if (bytes_received < 0) { con_error << "Network receive() error!" << std::endl; //perror("recv"); abort(); + application()->messagebox("Disconnected from server."); return; } @@ -249,8 +261,9 @@ void NetConnection::frame() int nb = select(fd() + 1, &readset, NULL, NULL, &timeout); if (nb == 0) { if (connection_timeout + NETTIMEOUT < core::application()->time()) { - con_error << "Connection timeout!\n"; + con_error << "Connection timeout exceeded!\n"; abort(); + application()->messagebox("Connection timeout exceeded!"); } return; } @@ -649,6 +662,39 @@ void NetConnection::parse_incoming_message(const std::string & message) } } + } else if (command.compare("box") == 0) { + + // box "text" "label1" "cmd1" "label2" "cmd2" + char c; + + // read text + std::string text; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + text += c; + + std::string label1; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + label1 += c; + + std::string command1; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + command1 += c; + + std::string label2; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + label2 += c; + + std::string command2; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + command2 += c; + + application()->notify_messagebox(text, label1, command1, label2, command2); + } else if (command.compare("connect") == 0) { if (connection_state == Pending) { |