]> code.citadel.org Git - citadel.git/commitdiff
Got auto-reconnect working ... sort of.
authorArt Cancro <ajc@citadel.org>
Sat, 8 May 1999 03:55:07 +0000 (03:55 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 8 May 1999 03:55:07 +0000 (03:55 +0000)
daphne/citclient.cpp
daphne/includes.hpp
daphne/userlogin.cpp

index 51e75bf5ffc3f27e96548ff73714ea594bacc7b9..6b5809f9d96ad1fbacf5361b181bed7310311a98 100644 (file)
@@ -1,5 +1,6 @@
 
 #include "includes.hpp"
+#include <unistd.h>
 
 
 //  
@@ -16,6 +17,10 @@ int CitClient::attach(wxString host, wxString port) {
        if (sock.attach(host, port)==0) {
                serv_gets(ServerReady);
                initialize_session();
+
+               curr_host = host;       // Remember host and port, in case
+               curr_port = port;       // we need to auto-reconnect later
+
                return(0);
        }
        else return(1);
@@ -99,7 +104,14 @@ int CitClient::serv_trans(
        // it must begin HERE.
 
        serv_puts(command);
+       
+       if (IsConnected() == FALSE) {
+               reconnect_session();
+               serv_puts(command);
+       }
+
        serv_gets(response);
+
        first_digit = (response.GetChar(0)) - '0';
 
        if (response.GetChar(3) == '*')
@@ -246,6 +258,35 @@ bool CitClient::GotoRoom(wxString roomname, wxString password,
 
 
 
+// Reconnect a broken session
+
+void CitClient::reconnect_session(void) {
+       wxString sendcmd;
+
+       CurrentRoom = "__ This is not the name of any valid room __";
+
+       // Give a crashed server some time to restart
+       sleep(5);
+
+       if (attach(curr_host, curr_port) != 0) {
+               // FIX do this more elegantly
+               cout << "Could not re-establish session (1)\n";
+       }
+
+       sendcmd = "USER " + curr_user;
+       if (serv_trans(sendcmd) != 3) {
+               // FIX do this more elegantly
+               cout << "Could not re-establish session (2)\n";
+       }
+
+       sendcmd = "PASS " + curr_pass;
+       if (serv_trans(sendcmd) != 2) {
+               // FIX do this more elegantly
+               cout << "Could not re-establish session (3)\n";
+       }
+}
+
+
 
 
 
index 9d208d366dee47f36a8e80422d1d35b67876c58c..5f8b8de6f1f1a92be68fa0c77f1f142c0325d4f6 100644 (file)
@@ -99,6 +99,7 @@ public:
        // ... and about the user ...
        wxString curr_user;
        wxString curr_pass;
+       int axlevel;
        
        // Stuff we have to keep track of ...
        wxString CurrentRoom;
@@ -107,8 +108,13 @@ private:
        TCPsocket sock;                                 // transport layer
        void serv_gets(wxString& buf);                  // session layer
        void serv_puts(wxString buf);                   // session layer
+       void reconnect_session(void);                   // session layer
        void download_express_messages(void);           // presentation layer
-       void CitClient::initialize_session(void);       // presentation layer
+       void initialize_session(void);                  // presentation layer
+
+       wxString curr_host;
+       wxString curr_port;
+
 };
 
 
index 9a7185bcef666649732602ed9e91b868fb867269..dea79e71a5797b6b9507fc038f955fb4ed6cc9fb 100644 (file)
@@ -290,6 +290,7 @@ void UserLogin::BeginSession(wxString serv_response) {
        extract(citsock->curr_user, serv_response.Mid(4), 0);
        BigMDI->SetStatusText(citsock->curr_user, 1);
        citsock->GotoRoom("_BASEROOM_", "", junk);
+       citsock->axlevel = extract_int(serv_response.Mid(4), 1);
 
        // FIX ... add code here to perform registration if necessary