]> code.citadel.org Git - citadel.git/commitdiff
Now we have a working "new user" button, a unified login/newuser startup
authorArt Cancro <ajc@citadel.org>
Sun, 14 Mar 1999 04:43:53 +0000 (04:43 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 14 Mar 1999 04:43:53 +0000 (04:43 +0000)
backend, and a three-pane statusbar that shows the user and room names.

daphne/citclient.cpp
daphne/includes.hpp
daphne/main.cpp
daphne/tcp_sockets.cpp
daphne/userlogin.cpp

index a4d49856fc83cbb213967651462dc9566b56e70b..2668e9e6b16e8e6f55956a1c9826475583674ff2 100644 (file)
@@ -3,12 +3,12 @@
 
 
 //  
-//              LOW LEVEL OPERATIONS
+//     TRANSPORT LAYER OPERATIONS
 //
 
 // Attach to the Citadel server
 // FIX (add check for not allowed to log in)
-int CitClient::attach(const wxString& host, const wxString& port) {
+int CitClient::attach(wxString host, wxString port) {
        wxString ServerReady;
 
        if (sock.is_connected())
@@ -69,7 +69,7 @@ void CitClient::serv_puts(wxString buf) {
 
 
 //
-//            HIGH LEVEL COMMANDS
+//             SESSION LAYER OPERATIONS
 //
 
 
@@ -77,14 +77,28 @@ void CitClient::serv_puts(wxString buf) {
 int CitClient::serv_trans(
                        wxString& command,
                        wxString& response,
-                       wxStringList& xferbuf
+                       wxStringList& xferbuf,
+                       wxString desired_room
                        ) {
 
        int first_digit;
         int i;
-       wxString buf;
+       wxString buf, pw, junk;
        bool express_messages_waiting = FALSE;
 
+       // If the caller specified that this transaction must take place
+       // in a particular room, make sure we're in that room.
+       if (desired_room.Length() > 0) {
+               if (desired_room.CmpNoCase(CurrentRoom) != 0) {
+                       pw = "";
+                       GotoRoom(desired_room, pw, junk);
+               }
+       }
+
+
+       // If a mutex is to be wrapped around this function in the future,
+       // it must begin HERE.
+
        serv_puts(command);
        serv_gets(response);
        first_digit = (response.GetChar(0)) - '0';
@@ -105,6 +119,9 @@ int CitClient::serv_trans(
                serv_puts("000");
        }
 
+       // If a mutex is to be wrapped around this function in the future,
+       // it must end HERE.
+
        if (express_messages_waiting) {
                download_express_messages();
        }
@@ -113,6 +130,14 @@ int CitClient::serv_trans(
 }
 
 // Shorter forms of serv_trans()
+int CitClient::serv_trans(
+                       wxString& command,
+                       wxString& response,
+                       wxStringList& xferbuf
+                       ) {
+       return serv_trans(command, response, xferbuf, "");
+}
+
 int CitClient::serv_trans(wxString& command, wxString& response) {
        wxStringList junklist;
        return serv_trans(command, response, junklist);
@@ -123,6 +148,25 @@ int CitClient::serv_trans(wxString& command) {
        return serv_trans(command, junkbuf);
 }
 
+//
+//             PRESENTATION LAYER OPERATIONS
+//
+
+
+void CitClient::download_express_messages(void) {
+       wxString sendcmd, recvcmd, x_user, x_sys;
+       wxStringList xferbuf;
+
+       sendcmd = "GEXP";
+       while (serv_trans(sendcmd, recvcmd, xferbuf) == 1) {
+               extract(x_user, recvcmd, 3);
+               extract(x_sys, recvcmd, 4);
+               (void)new express_message(this, x_user, x_sys, xferbuf);
+       }
+}
+
+
+
 // Set up some things that we do at the beginning of every session
 void CitClient::initialize_session(void)  {
        wxStringList info;
@@ -132,6 +176,8 @@ void CitClient::initialize_session(void)  {
        wxString *infoptr;
        wxString infoline;
 
+       CurrentRoom = "";
+
        sendcmd = "IDEN 0|6|001|Daphne";
        serv_trans(sendcmd);
 
@@ -161,20 +207,30 @@ void CitClient::initialize_session(void)  {
 
 
 
-void CitClient::download_express_messages(void) {
-       wxString sendcmd, recvcmd, x_user, x_sys;
-       wxStringList xferbuf;
+// Goto a room
 
-       sendcmd = "GEXP";
-       while (serv_trans(sendcmd, recvcmd, xferbuf) == 1) {
-               extract(x_user, recvcmd, 3);
-               extract(x_sys, recvcmd, 4);
-               (void)new express_message(this, x_user, x_sys, xferbuf);
-       }
+bool CitClient::GotoRoom(wxString roomname, wxString password,
+                       wxString& server_response) {
+       int retval;
+       wxString sendcmd, recvcmd;
+
+       sendcmd = "GOTO " + roomname + "|" + password;
+       retval = serv_trans(sendcmd, recvcmd);
+       server_response = recvcmd;
+
+       if (retval != 2) return FALSE;
+
+       extract(CurrentRoom, recvcmd.Mid(4, 255), 0);
+       BigMDI->SetStatusText(CurrentRoom, 2);
+       return TRUE;
 }
 
 
 
+
+
+
+
 // This is a simple timer that periodically wakes up and sends a NOOP to the
 // server.  This accomplishes two things: it keeps the server connection
 // alive by trickling some data through when it's otherwise idle, and it allows
@@ -190,12 +246,7 @@ keepalive::keepalive(CitClient *sock)
 
 void keepalive::Notify(void) {
        if (which_sock->IsConnected()) {
-               which_sock->serv_trans("NOOP");
+               wxString noop = "NOOP";
+               which_sock->serv_trans(noop);
        }
 }
-
-
-
-
-
-
index 8452a7069204b23015ce48604cb1604b2d26d5a1..064e122e658d3883875e691105c5f209da4f383f 100644 (file)
@@ -30,7 +30,7 @@ public:
        bool is_connected(void);
 private:
        int serv_sock;
-       int connectsock(const char *, const char *, const char *);
+       int connectsock(char *, char *, char *);
        void timeout(int);
 };
 
@@ -42,10 +42,16 @@ public:
        CitClient(void);
        ~CitClient(void);
 
-       // High-level Citadel IPC methods
-       int attach(const wxString& host, const wxString& port);
+       // Citadel session-layer commands
+       int attach(wxString host, wxString port);
        void detach(void);
        bool IsConnected(void);
+       int CitClient::serv_trans(
+                       wxString& command,
+                       wxString& response,
+                       wxStringList& xferbuf,
+                       wxString desired_room
+                        );
        int CitClient::serv_trans(
                        wxString& command,
                        wxString& response,
@@ -54,7 +60,11 @@ public:
        int CitClient::serv_trans(wxString& command, wxString& response);
        int CitClient::serv_trans(wxString& command);
 
-       // Various things we learn about the server
+       // Citadel presentation-layer commands
+       bool CitClient::GotoRoom(wxString roomname, wxString password,
+                               wxString& server_response);
+
+       // Various things we learn about the server ...
        int SessionID;
        wxString NodeName;
        wxString HumanNode;
@@ -67,13 +77,16 @@ public:
        wxString MorePrompt;
        bool UseFloors;
        int PagingLevel;
+       
+       // Stuff we have to keep track of ...
+       wxString CurrentRoom;
 
 private:
-       void serv_gets(wxString& buf);
-       void serv_puts(wxString buf);
-       void download_express_messages(void);
-       TCPsocket sock;
-       void CitClient::initialize_session(void);
+       TCPsocket sock;                                 // transport layer
+       void serv_gets(wxString& buf);                  // session layer
+       void serv_puts(wxString buf);                   // session layer
+       void download_express_messages(void);           // presentation layer
+       void CitClient::initialize_session(void);       // presentation layer
 };
 
 
@@ -153,6 +166,7 @@ private:
        wxButton *newuser_button;
        wxButton *exit_button;
        void OnButtonPressed(wxCommandEvent& whichbutton);
+       void UserLogin::BeginSession(wxString serv_response);
        CitClient *citsock;
        wxMDIParentFrame *citMyMDI;
        DECLARE_EVENT_TABLE()
index 64e0c566c8b81fb307d3caef81a463b9b4680ff8..a93ed6010afb9a114a77412c78d0dca5115c64db 100644 (file)
@@ -200,8 +200,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
        SetMenuBar(menuBar);
 
        // create a status bar just for fun (by default with 1 pane only)
-       CreateStatusBar(1);
-       SetStatusText("Not connected");
+       CreateStatusBar(3);
+       SetStatusText("Not connected", 0);
 }
 
 
@@ -320,14 +320,18 @@ void MyFrame::OnDoCmd(wxCommandEvent& whichbutton) {
 
 void MyFrame::OnConnect(wxCommandEvent& unused) {
        int retval;
+       wxString DefaultHost, DefaultPort;
+
+       DefaultHost = "uncnsrd.mt-kisco.ny.us";
+       DefaultPort = "citadel";
 
        if (citadel->IsConnected()) {
                wxMessageBox("You are already connected to a Citadel server.",
                        "Oops!");
        } else {
-               retval = citadel->attach("uncnsrd", "citadel");
+               retval = citadel->attach(DefaultHost, DefaultPort);
                if (retval == 0) {
-                       SetStatusText("Connected to " + citadel->HumanNode);
+                       SetStatusText("Connected to " + citadel->HumanNode, 0);
                        new TestWindow(citadel, this);
                        new UserLogin(citadel, this);
                } else {
index 9ddcfb381f74abbf9519675a9a7978003af91ef5..cc96232f5e44641ea2fe458569c852f5c85dfad9 100644 (file)
@@ -35,8 +35,8 @@ void TCPsocket::timeout(int signum) {
        serv_sock = (-1);
 }
 
-int TCPsocket::connectsock(const char *host, const char *service,
-                       const char *protocol)
+int TCPsocket::connectsock(char *host, char *service,
+                       char *protocol)
 {
        struct hostent *phe;
        struct servent *pse;
index 159281010a38a31610fabda02b2a0c10ac70ab21..0435f0bf11b84bcf12749832aadc843e88fbe6bf 100644 (file)
@@ -227,8 +227,7 @@ void UserLogin::OnButtonPressed(wxCommandEvent& whichbutton) {
        }
 
        if (whichbutton.GetId() == BUTTON_LOGIN) {
-               sendbuf = "USER ";
-               sendbuf += username->GetValue();
+               sendbuf = "USER " + username->GetValue();
                r = citsock->serv_trans(sendbuf, recvbuf);
                if (r != 3) {
                        wxMessageDialog nouser(this,
@@ -249,9 +248,39 @@ void UserLogin::OnButtonPressed(wxCommandEvent& whichbutton) {
                                        wxDefaultPosition);
                                nopass.ShowModal();
                        } else {
-                               // FIX do login procedure here
+                               BeginSession(recvbuf);
                                delete this;    // dismiss the login box
                        }
                }
        }
+
+       if (whichbutton.GetId() == BUTTON_NEWUSER) {
+               sendbuf = "NEWU " + username->GetValue();
+               r = citsock->serv_trans(sendbuf, recvbuf);
+               if (r != 2) {
+                       wxMessageDialog nouser(this,
+                               recvbuf.Mid(4,32767),
+                               "Error",
+                               wxOK | wxCENTRE | wxICON_INFORMATION,
+                               wxDefaultPosition);
+                       nouser.ShowModal();
+               } else {
+                       sendbuf = "SETP " + password->GetValue();
+                       citsock->serv_trans(sendbuf);
+                       BeginSession(recvbuf);
+                       delete this;            // dismiss the login box
+               }
+       }
+}
+
+
+
+void UserLogin::BeginSession(wxString serv_response) {
+       wxString junk, username;
+
+       extract(username, serv_response.Mid(4, 255), 0);
+       BigMDI->SetStatusText(username, 1);
+       citsock->GotoRoom("_BASEROOM_", "", junk);
+
+       // FIX ... add code here to perform registration if necessary
 }