* Replaced the Java chat with a new system based on IFRAME's and JavaScript
authorArt Cancro <ajc@citadel.org>
Fri, 20 Feb 2004 06:07:06 +0000 (06:07 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 20 Feb 2004 06:07:06 +0000 (06:07 +0000)
webcit/ChangeLog
webcit/context_loop.c
webcit/paging.c
webcit/static/MultiUserChat102.java
webcit/static/wcCitServer.java
webcit/static/wcCitUtil.java
webcit/static/wcchat.java
webcit/webcit.c
webcit/webcit.h

index c233a8f00bb27403f0fde6525f66653cc336831b..657881e2125666ae82bccb559d25d74930c547f4 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 505.1  2004/02/20 06:07:06  ajc
+* Replaced the Java chat with a new system based on IFRAME's and JavaScript
+
 Revision 505.0  2004/02/19 03:32:50  ajc
 * THIS IS 5.05
 
@@ -1666,3 +1669,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
 
+
index 0b2f7f47120e311baa118ed0eb944f006e9be7b5..3e3302a1b6685fb3983ac4700d671caf94bbf2df 100644 (file)
@@ -102,6 +102,7 @@ BREAKOUT:   pthread_mutex_unlock(&SessionListMutex);
                if (session_to_kill != NULL) {
                        pthread_mutex_lock(&session_to_kill->SessionMutex);
                        close(session_to_kill->serv_sock);
+                       close(session_to_kill->chat_sock);
                        if (session_to_kill->preferences != NULL) {
                                free(session_to_kill->preferences);
                        }
@@ -338,7 +339,6 @@ void context_loop(int sock)
           || (!strncasecmp(buf, "/do_welcome", 11))
           || (!strncasecmp(buf, "/page_popup", 11))
           || (!strncasecmp(buf, "/page_user", 10))     /* Sometimes this is wrong */
-          || (!strncasecmp(buf, "/display_page", 13))  /* Sometimes this is wrong */
           || (!strncasecmp(buf, "/listsub", 8))
           || (!strncasecmp(buf, "/freebusy", 9))
           || (!strncasecmp(buf, "/termquit", 9)) ) {
@@ -370,6 +370,8 @@ void context_loop(int sock)
                TheSession = (struct wcsession *)
                        malloc(sizeof(struct wcsession));
                memset(TheSession, 0, sizeof(struct wcsession));
+               TheSession->serv_sock = (-1);
+               TheSession->chat_sock = (-1);
                TheSession->wc_session = GenerateSessionID();
                pthread_mutex_init(&TheSession->SessionMutex, NULL);
 
index aeaf7aab5590565426ba19ff93455c3f5f23973f..92b7351807d060fae7968b6e8a3d4cf4d9751b41 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/poll.h>
 #include <sys/time.h>
 #include <limits.h>
 #include <netinet/in.h>
@@ -115,28 +116,22 @@ void do_chat(void)
 
        output_headers(1);
 
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">Real-time chat</SPAN>\n");
-       wprintf("</TD></TR></TABLE>\n");
-
-       if (!strcasecmp(ctdlhost, "uds")) {
-               wprintf("<I>Sorry ... chat is not available here.</i></BR>\n");
-       }
-       else {
-               wprintf("A chat window should be appearing on your screen ");
-               wprintf("momentarily.  When you're ");
-               wprintf("done, type <TT>/quit</TT> to exit.  You can also ");
-               wprintf("type <TT>/help</TT> for more commands.\n");
-       
-               wprintf("<applet codebase=\"/static\" ");
-               wprintf("code=\"wcchat\" width=2 height=2>\n");
-               wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
-               wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
-               wprintf("<PARAM NAME=roomname VALUE=\"%s\">\n", WC->wc_roomname);
-               wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
-               wprintf("so you won't be able to access Chat.  Sorry.\n");
-               wprintf("</applet>\n");
-       }
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
+               "<SPAN CLASS=\"titlebar\">Real-time chat</SPAN>\n"
+               "</TD></TR></TABLE>\n"
+               "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"/chat_recv\" "
+               "NAME=\"chat_recv\">\n"
+               "<!-- Alternate content for non-supporting browsers -->\n"
+               "If you are seeing this message, your browser does not contain\n"
+               "the IFRAME support required for the chat window.  Please upgrade\n"
+               "to a supported browser, such as\n"
+               "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
+               "</IFRAME>\n"
+               "<HR width=100%%>\n"
+               "<IFRAME WIDTH=100%% HEIGHT=50 SRC=\"/chat_send\" "
+               "NAME=\"chat_send\">\n"
+               "</IFRAME>\n"
+       );
        wDumpContent(1);
 }
 
@@ -178,3 +173,226 @@ void page_popup(void)
 }
 
 
+
+/*
+ * Support function for chat -- make sure the chat socket is connected
+ * and in chat mode.
+ */
+int setup_chat_socket(void) {
+       char buf[SIZ];
+       int i;
+       int good_chatmode = 0;
+
+       if (WC->chat_sock < 0) {
+
+               for (i=0; i<CHATLINES; ++i) {
+                       strcpy(WC->chatlines[i], "");
+               }
+
+               if (!strcasecmp(ctdlhost, "uds")) {
+                       /* unix domain socket */
+                       sprintf(buf, "%s/citadel.socket", ctdlport);
+                       WC->chat_sock = uds_connectsock(buf);
+               }
+               else {
+                       /* tcp socket */
+                       WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
+               }
+
+               if (WC->chat_sock < 0) {
+                       return(errno);
+               }
+
+               /* Temporarily swap the serv and chat sockets during chat talk */
+               i = WC->serv_sock;
+               WC->serv_sock = WC->chat_sock;
+               WC->chat_sock = i;
+
+               serv_gets(buf);
+               if (buf[0] == '2') {
+                       serv_printf("USER %s", WC->wc_username);
+                       serv_gets(buf);
+                       if (buf[0] == '3') {
+                               serv_printf("PASS %s", WC->wc_password);
+                               serv_gets(buf);
+                               if (buf[0] == '2') {
+                                       serv_printf("GOTO %s", WC->wc_roomname);
+                                       serv_gets(buf);
+                                       if (buf[0] == '2') {
+                                               serv_puts("CHAT");
+                                               serv_gets(buf);
+                                               if (buf[0] == '8') {
+                                                       good_chatmode = 1;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               /* Unswap the sockets. */
+               i = WC->serv_sock;
+               WC->serv_sock = WC->chat_sock;
+               WC->chat_sock = i;
+
+               if (!good_chatmode) close(WC->serv_sock);
+
+       }
+       return(0);
+}
+
+
+
+/*
+ * receiving side of the chat window
+ */
+void chat_recv(void) {
+       int i;
+       char name[SIZ];
+       char text[SIZ];
+       struct pollfd pf;
+       int got_data = 0;
+       int end_chat_now = 0;
+
+       output_headers(0);
+
+       wprintf("Content-type: text/html\n");
+       wprintf("\n");
+       wprintf("<HTML>\n"
+               "<HEAD>\n"
+               "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3\">\n"
+               "</HEAD>\n"
+               "<BODY>"
+       );
+
+       if (setup_chat_socket() != 0) {
+               wprintf("Error setting up chat socket</BODY></HTML>\n");
+               wDumpContent(0);
+               return;
+       }
+
+       /*
+        * See if there is any chat data waiting.
+        */
+       do {
+               got_data = 0;
+               pf.fd = WC->chat_sock;
+               pf.events = POLLIN;
+               pf.revents = 0;
+               if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
+                       ++got_data;
+
+                       for (i=0; i<CHATLINES-1; ++i) {
+                               strcpy(WC->chatlines[i], WC->chatlines[i+1]);
+                       }
+       
+                       /* Temporarily swap the serv and chat sockets during chat talk */
+                       i = WC->serv_sock;
+                       WC->serv_sock = WC->chat_sock;
+                       WC->chat_sock = i;
+       
+                       serv_gets(WC->chatlines[CHATLINES-1]);
+                       if (!strcmp(WC->chatlines[CHATLINES-1], "000")) {
+                               end_chat_now = 1;
+                               strcpy(WC->chatlines[CHATLINES-1], ":|exiting chat mode");
+                       }
+                       
+                       /* Unswap the sockets. */
+                       i = WC->serv_sock;
+                       WC->serv_sock = WC->chat_sock;
+                       WC->chat_sock = i;
+               }
+       } while ( (got_data) && (!end_chat_now) );
+
+       /*
+        * Display appropriately.
+        */
+       for (i=0; i<CHATLINES; ++i) {
+               if (strlen(WC->chatlines[i]) > 0) {
+                       extract(name, WC->chatlines[i], 0);
+                       extract(text, WC->chatlines[i], 1);
+                       if (!strcasecmp(name, WC->wc_username)) {
+                               wprintf("<FONT COLOR=\"#00FF00\">");
+                       }
+                       else if (!strcmp(name, ":")) {
+                               wprintf("<FONT COLOR=\"#FF0000\">");
+                       }
+                       else {
+                               wprintf("<FONT COLOR=\"#0000FF\">");
+                       }
+                       escputs(name);
+                       wprintf(": </FONT>");
+                       escputs(text);
+                       wprintf("<BR>\n");
+               }
+       }
+
+       if (end_chat_now) {
+               close(WC->chat_sock);
+               WC->chat_sock = (-1);
+               wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"top.location.replace('/do_welcome');\">\n");
+       }
+
+       wprintf("</BODY></HTML>\n");
+       wDumpContent(0);
+}
+
+
+/*
+ * sending side of the chat window
+ */
+void chat_send(void) {
+       int i;
+       char send_this[SIZ];
+
+       output_headers(0);
+       wprintf("Content-type: text/html\n");
+       wprintf("\n");
+       wprintf("<HTML>"
+               "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
+       );
+
+       if (bstr("send_this") != NULL) {
+               strcpy(send_this, bstr("send_this"));
+       }
+       else {
+               strcpy(send_this, "");
+       }
+
+       if (bstr("sendbutton") != NULL) {
+
+               if (!strcasecmp(bstr("sendbutton"), "Exit")) {
+                       strcpy(send_this, "/quit");
+               }
+
+               if (setup_chat_socket() != 0) {
+                       wprintf("Error setting up chat socket</BODY></HTML>\n");
+                       wDumpContent(0);
+                       return;
+               }
+
+               /* Temporarily swap the serv and chat sockets during chat talk */
+               i = WC->serv_sock;
+               WC->serv_sock = WC->chat_sock;
+               WC->chat_sock = i;
+
+               serv_puts(send_this);
+
+               /* Unswap the sockets. */
+               i = WC->serv_sock;
+               WC->serv_sock = WC->chat_sock;
+               WC->chat_sock = i;
+
+       }
+
+       wprintf("Send: ");
+       wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
+       wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
+       wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
+       wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
+       wprintf("</FORM>\n");
+
+       wprintf("</BODY></HTML>\n");
+       wDumpContent(0);
+}
+
+
index fe620bad4d33a429991cbe650c80337eb5a2377b..2a120c7544d7a0f31394ab130f62d947840d9eb3 100644 (file)
@@ -24,37 +24,37 @@ class ReceiveChat extends Thread {
        String MyName;
        StringTokenizer ST;
        MultiUserChat102 ParentMUC;
-       Label[] Linez = new Label[25];
+        Label[] Linez = new Label[25];
        int a;
-       
-       ReceiveChat(MultiUserChat102 muc, Panel t, wcCitServer s, String n) {
+
+        ReceiveChat(MultiUserChat102 muc, Panel t, wcCitServer s,
+                    String n) {
                TheArea = t;
                serv = s;
                MyName = n;
                ParentMUC = muc;
                serv.AddClientThread(this);
 
-               TheArea.setLayout(new GridLayout(25,1));
+               TheArea.setLayout(new GridLayout(25, 1));
 
-               for (a=0; a<25; ++a) {
+               for (a = 0; a < 25; ++a) {
                        Linez[a] = new Label(" ");
                        Linez[a].setBackground(Color.black);
                        Linez[a].setForeground(Color.black);
                        TheArea.add(Linez[a]);
-                       }
-
-               TheArea.validate();
+               } TheArea.validate();
 
-               }
+       }
 
        private void ScrollIt(String TheNewLine, Color NewLineColor) {
-               for (a=0; a<24; ++a) {
-                       Linez[a].setText(Linez[a+1].getText());
-                       Linez[a].setForeground(Linez[a+1].getForeground());
-                       }
+               for (a = 0; a < 24; ++a) {
+                       Linez[a].setText(Linez[a + 1].getText());
+                       Linez[a].setForeground(Linez[a + 1].
+                                              getForeground());
+               }
                Linez[24].setText(TheNewLine);
                Linez[24].setForeground(NewLineColor);
-               }
+       }
 
 
        public void run() {
@@ -62,7 +62,7 @@ class ReceiveChat extends Thread {
                int a;
 
                LastLineUser = "  ";
-               while(true) {
+               while (true) {
                        boof = serv.ServGets();
 
                        if (boof.equals("000")) {
@@ -70,83 +70,82 @@ class ReceiveChat extends Thread {
                                ParentMUC.dispose();
                                stop();
                                destroy();
-                               }
+                       }
 
 
                        ST = new StringTokenizer(boof, "|");
                        if (ST.hasMoreTokens()) {
                                cUser = ST.nextToken();
-                               }
-                       else {
+                       } else {
                                cUser = ":";
-                               }
+                       }
                        if (ST.hasMoreTokens()) {
                                cText = ST.nextToken();
-                               }
-                       else {
+                       } else {
                                cText = " ";
-                               }
+                       }
                        if (!cText.startsWith("NOOP")) {
                                if (!LastLineUser.equals(cUser)) {
                                        ScrollIt("", Color.black);
                                        ThisLine = cUser + ": ";
-                                       }
-                               else {
-ThisLine = "                                  ".substring(0, cUser.length()+2);
-                                       }
+                               } else {
+                                       ThisLine =
+                                           "                                  ".
+                                           substring(0,
+                                                     cUser.length() + 2);
+                               }
                                ThisLine = ThisLine + cText;
                                UserColor = Color.green;
                                if (cUser.equals(":")) {
                                        UserColor = Color.red;
-                                       }
+                               }
                                if (cUser.equalsIgnoreCase(MyName)) {
                                        UserColor = Color.yellow;
-                                       }
+                               }
                                ScrollIt(ThisLine, UserColor);
                                LastLineUser = cUser;
-                               }
                        }
                }
-
        }
 
+}
 
 
 
 
-public class MultiUserChat102
-       extends Frame {
 
-wcCitServer serv;
-ReceiveChat MyReceive;
-Panel AllUsers;
-TextField SendBox;
-wcchat ParentApplet;
+public class MultiUserChat102 extends Frame {
 
+       wcCitServer serv;
+       ReceiveChat MyReceive;
+       Panel AllUsers;
+       TextField SendBox;
+       wcchat ParentApplet;
 
-MultiUserChat102(wcCitServer PrimaryServ, wcchat P) {
-       super ("Multiuser Chat");
 
-       String boof;
+        MultiUserChat102(wcCitServer PrimaryServ, wcchat P) {
+               super("Multiuser Chat");
 
-       /* Set up a new server connection as a piggyback to the first. */
-       serv = PrimaryServ;
-       ParentApplet = P;
+               String boof;
 
-       resize(600,400);
-       setLayout(new BorderLayout());
+               /* Set up a new server connection as a piggyback to the first. */
+                serv = PrimaryServ;
+                ParentApplet = P;
 
-       boof = "This is the buffer before the chat command.";
-       serv.ServPuts("CHAT");
-       boof = serv.ServGets();
+                resize(600, 400);
+                setLayout(new BorderLayout());
 
-       if (boof.charAt(0) != '8') {
-               add("Center", new Label("ERROR: " + boof) );
-               show();
+                boof = "This is the buffer before the chat command.";
+                serv.ServPuts("CHAT");
+                boof = serv.ServGets();
+
+               if (boof.charAt(0) != '8') {
+                       add("Center", new Label("ERROR: " + boof));
+                       show();
                }
 
-       else {
-               DoChat(PrimaryServ.GetUserName());
+               else {
+                       DoChat(PrimaryServ.GetUserName());
                }
 
        }
@@ -155,44 +154,54 @@ MultiUserChat102(wcCitServer PrimaryServ, wcchat P) {
 /*
  * Do the actual chat stuff
  */
-private void DoChat(String MyName) {
-       String boof;
+       private void DoChat(String MyName) {
+               String boof;
 
-       SendBox = new TextField(80);
+               SendBox = new TextField(80);
 
-       AllUsers = new Panel();
+               AllUsers = new Panel();
 
-       add("Center", AllUsers);
-       add("South", SendBox);
-       show();
+               add("Center", AllUsers);
+               add("South", SendBox);
+               show();
 
-       MyReceive = new ReceiveChat(this, AllUsers, serv, MyName);
-       MyReceive.start();
+               MyReceive = new ReceiveChat(this, AllUsers, serv, MyName);
+               MyReceive.start();
 
-       SendBox.requestFocus();
+               SendBox.requestFocus();
        }
 
 
-public boolean handleEvent(Event evt) {
-       int LastSpace;
+       public boolean handleEvent(Event evt) {
+               int LastSpace;
 
-       if ( (evt.target == SendBox) && (evt.id == Event.ACTION_EVENT) ) {
-               serv.ServPuts(SendBox.getText());
-               SendBox.setText("");
+               if ((evt.target == SendBox)
+                   && (evt.id == Event.ACTION_EVENT)) {
+                       serv.ServPuts(SendBox.getText());
+                       SendBox.setText("");
                }
 
-       else if (evt.target == SendBox) {
-               if ( SendBox.getText().length() + serv.GetUserName().length() > 78 ) {
-                       LastSpace = SendBox.getText().lastIndexOf(' ');
-                       if (LastSpace < 0) {
-                               serv.ServPuts(SendBox.getText());
-                               SendBox.setText("");
-                               }
-                       else {
-                               serv.ServPuts(SendBox.getText().substring(0,LastSpace));
-                               SendBox.setText(SendBox.getText().substring(LastSpace));
-                               if (SendBox.getText().charAt(0) == ' ') {
-                                       SendBox.setText(SendBox.getText().substring(1));
+               else if (evt.target == SendBox) {
+                       if (SendBox.getText().length() +
+                           serv.GetUserName().length() > 78) {
+                               LastSpace =
+                                   SendBox.getText().lastIndexOf(' ');
+                               if (LastSpace < 0) {
+                                       serv.ServPuts(SendBox.getText());
+                                       SendBox.setText("");
+                               } else {
+                                       serv.ServPuts(SendBox.getText().
+                                                     substring(0,
+                                                               LastSpace));
+                                       SendBox.setText(SendBox.getText().
+                                                       substring
+                                                       (LastSpace));
+                                       if (SendBox.getText().charAt(0) ==
+                                           ' ') {
+                                               SendBox.setText(SendBox.
+                                                               getText().
+                                                               substring
+                                                               (1));
                                        }
                                }
                        }
index dff93252f1e213a09d6c0ad0d36a8b4974770cc2..6cf9c3175da6dcd2b020757bc61267329df45ad6 100644 (file)
@@ -21,45 +21,44 @@ import java.util.*;
  */
 class wcKeepAlive extends Thread {
 
-       wcCitServer serv;               /* Pointer to server connection class */
+       wcCitServer serv;       /* Pointer to server connection class */
        boolean FullKeepAlives; /* TRUE for full keepalives, FALSE for half keepalives */
 
-       wcKeepAlive() {
-               }
-
-       public void PointToServer(wcCitServer which_serv, boolean WhatKindOfKeepAlives) {
+        wcKeepAlive() {
+       } public void PointToServer(wcCitServer which_serv,
+                                   boolean WhatKindOfKeepAlives) {
                serv = which_serv;
                serv.AddClientThread(this);
                FullKeepAlives = WhatKindOfKeepAlives;
-               }
+       }
 
        public void run() {
                String buf;
-               while(true) {
+               while (true) {
 
                        /* Sleep for sixty seconds between keepalives. */
                        try {
                                sleep(60000);
-                               }
-                       catch (InterruptedException e) {
-                               }
+                       }
+                       catch(InterruptedException e) {
+                       }
                        /* Full keepalives - send a NOOP, wait for a reply, then retrieve
                         * express messages if the server said there are any.
                         */
                        if (FullKeepAlives) {
                                buf = serv.ServTrans("NOOP") + "    ";
-                               }
+                       }
 
                        /* Half keepalives - blindly send a NOOP and we're done. */
                        else {
                                serv.ServPuts("NOOP");
-                               }
-
                        }
+
                }
-               
        }
 
+}
+
 
 
 /*
@@ -82,48 +81,46 @@ public class wcCitServer {
 
        public void SetTransBuf(String bufstring) {
                TransBuf = bufstring;
-               }
-
-       public String GetTransBuf() {
+       } public String GetTransBuf() {
                return TransBuf;
-               }
+       }
 
 /* attach to the server */
-       private void BuildConnection(String ServerHost, int ServerPort, boolean WhichKA) {
+       private void BuildConnection(String ServerHost, int ServerPort,
+                                    boolean WhichKA) {
 
                String buf;
 
                try {
                        sock = new Socket(ServerHost, ServerPort);
-                       ofp = new
-                               DataOutputStream(sock.getOutputStream());
-                       ifp = new
-                               DataInputStream(sock.getInputStream());
-                       }
+                       ofp = new DataOutputStream(sock.getOutputStream());
+                       ifp = new DataInputStream(sock.getInputStream());
+               }
                catch(UnknownHostException e) {
                        System.out.println(e);
-                       }
+               }
                catch(IOException e) {
                        System.out.println(e);
-                       }
+               }
 
                /* Connection established.  At this point, this function
                 * has the server connection all to itself, so we can do
                 * whatever we want with it. */
-       
-               /* Get the 'server ready' message */    
+
+               /* Get the 'server ready' message */
                buf = ServGets();
 
                /* Identify the client software to the server */
                ServTrans("IDEN 0|5|001|Cit/UX Java Client|");
-               
+
                /* Download various information about the server */
                SetTransBuf("");
                buf = ServTrans("INFO");
-               StringTokenizer InfoST = new StringTokenizer(TransBuf,"\n");
+               StringTokenizer InfoST =
+                   new StringTokenizer(TransBuf, "\n");
                while (InfoST.hasMoreTokens()) {
                        ServerInfo.addElement(InfoST.nextToken());
-                       }
+               }
 
 
                /* At this point, all server accesses must cooperate with
@@ -134,14 +131,14 @@ public class wcCitServer {
                ka.PointToServer(this, WhichKA);
                ka.start();
 
-               }
+       }
 
 
 /*
  * Attach to server command for the primary socket
  */
        public void AttachToServer(String ServerHost, int ServerPort) {
-               
+
                /* Connect to the server */
 /* NOTE ... we've changed the primary connection keepalives to HALF because we're using the
  * primary connection to jump right into a chat window.
@@ -153,7 +150,7 @@ public class wcCitServer {
                 */
                PrimaryServerHost = ServerHost;
                PrimaryServerPort = ServerPort;
-               }
+       }
 
 
 /* 
@@ -161,25 +158,26 @@ public class wcCitServer {
  */
        public String GetServerHost() {
                return PrimaryServerHost;
-               }
+       }
 
-       public int GetServerPort() {    
+       public int GetServerPort() {
                return PrimaryServerPort;
-               }
+       }
 
 
 /*
  * Set up a piggyback connection
  */
-       public void Piggyback(wcCitServer PrimaryServ, boolean KeepAliveType) {
+       public void Piggyback(wcCitServer PrimaryServ,
+                             boolean KeepAliveType) {
                PrimaryServerHost = PrimaryServ.GetServerHost();
                PrimaryServerPort = PrimaryServ.GetServerPort();
                PrimaryServerUser = PrimaryServ.GetUserName();
                PrimaryServerPassword = PrimaryServ.GetPassword();
                BuildConnection(PrimaryServerHost, PrimaryServerPort,
                                KeepAliveType);
-               
-               }
+
+       }
 
 
 
@@ -187,28 +185,27 @@ public class wcCitServer {
        public String ServInfo(int index) {
                String retbuf;
                if (index >= ServerInfo.size()) {
-                       return("");
-                       }
-               else {
+                       return ("");
+               } else {
                        retbuf = ServerInfo.elementAt(index).toString();
-                       return(retbuf);
-                       }
+                       return (retbuf);
                }
+       }
 
 
 /* read a line from the server */
        public String ServGets() {
-               
+
                String buf = "";
 
                try {
                        buf = ifp.readLine();
-                       }
+               }
                catch(IOException e) {
                        System.out.println(e);
-                       }
-               return buf;
                }
+               return buf;
+       }
 
 
 /* write a line to the server */
@@ -216,41 +213,41 @@ public class wcCitServer {
 
                try {
                        ofp.writeBytes(buf + "\n");
-                       }
+               }
                catch(IOException e) {
                        System.out.println(e);
-                       }
                }
+       }
 
 
 /* lock the server connection so other threads don't screw us up */
        public synchronized void BeginTrans() {
-               while(in_trans) {
+               while (in_trans) {
                        try {
-                               System.out.println("-sleeping-"); /* trace */
+                               System.out.println("-sleeping-");       /* trace */
                                Thread.sleep(100);
-                               }
-                       catch (InterruptedException e) {
-                               }
                        }
+                       catch(InterruptedException e) {
+                       }
+               }
 
                in_trans = true;
-               }
+       }
 
 /* release the lock */
        public void EndTrans() {
                in_trans = false;
-               }
+       }
 
 
 /* perform an autonomous server transaction */
        public String ServTrans(String ServCmd) {
-               String buf; 
+               String buf;
                BeginTrans();
                buf = DataTrans(ServCmd);
                EndTrans();
                return buf;
-               }
+       }
 
 /* perform a non-autonomous server transaction */
        public String DataTrans(String ServCmd) {
@@ -260,51 +257,52 @@ public class wcCitServer {
 
                /* perform the transaction */
 
-               System.out.println(">"+ServCmd);        /* trace */
+               System.out.println(">" + ServCmd);      /* trace */
                ServPuts(ServCmd);
                buf = ServGets();
-               System.out.println("<"+buf);            /* trace */
+               System.out.println("<" + buf);  /* trace */
 
-           try {
-               if (buf.startsWith("4")) {
-                       ofp.writeBytes(TransBuf);
-                       if (!TransBuf.endsWith("\n")) {
-                               ofp.writeBytes("\n");
+               try {
+                       if (buf.startsWith("4")) {
+                               ofp.writeBytes(TransBuf);
+                               if (!TransBuf.endsWith("\n")) {
+                                       ofp.writeBytes("\n");
                                }
-                       ofp.writeBytes("000");
-                       TransBuf = "";
+                               ofp.writeBytes("000");
+                               TransBuf = "";
                        }
 
-               if (buf.startsWith("1")) {
-                       TransBuf = "";
-                       inbuf = "";
-                       do {
-                               inbuf = ServGets();
-                               if (!TransBuf.equals("")) {
-                                       TransBuf = TransBuf + "\n";
+                       if (buf.startsWith("1")) {
+                               TransBuf = "";
+                               inbuf = "";
+                               do {
+                                       inbuf = ServGets();
+                                       if (!TransBuf.equals("")) {
+                                               TransBuf = TransBuf + "\n";
                                        }
-                               if (!inbuf.equals("000")) {
-                                       TransBuf = TransBuf + inbuf;
+                                       if (!inbuf.equals("000")) {
+                                               TransBuf =
+                                                   TransBuf + inbuf;
                                        }
                                } while (!inbuf.equals("000"));
                        }
-                   }
-           catch(IOException e) {
-               System.out.println(e);
                }
-
-               return(buf);
+               catch(IOException e) {
+                       System.out.println(e);
                }
 
+               return (buf);
+       }
+
        public void AddClientThread(Thread ct) {
                ClientThreads.addElement(ct);
                System.out.println("--new thread registered--");
-               }
+       }
 
        public void RemoveClientThread(Thread ct) {
                ClientThreads.removeElement(ct);
                System.out.println("--thread removed--");
-               }
+       }
 
 
 
@@ -314,22 +312,20 @@ public class wcCitServer {
         */
        public void SetUserName(String U) {
                PrimaryServerUser = U;
-               }
-       
+       }
+
        public void SetPassword(String P) {
                PrimaryServerPassword = P;
-               }
+       }
 
        public String GetUserName() {
                return PrimaryServerUser;
-               }
+       }
 
        public String GetPassword() {
                return PrimaryServerPassword;
-               }
-
-
-
        }
 
 
+
+}
index 4e34deb5280266ed73f267e94677cd73d74043bd..7d164632463e3bc8d30f95e5a396dd12dd8481b0 100644 (file)
@@ -9,19 +9,19 @@ import java.util.*;
 
 public class wcCitUtil extends Object {
 
-public static String Extract(String SourceString, int ParmNum) {
-       StringTokenizer toks;
-       String buf;
-       int pos;
+       public static String Extract(String SourceString, int ParmNum) {
+               StringTokenizer toks;
+               String buf;
+               int pos;
 
-       pos = 0;
-       toks = new StringTokenizer(SourceString, "|");
-       while (toks.hasMoreTokens()) {
-               buf = toks.nextToken();
-               if (pos == ParmNum) return buf;
-               ++pos;
-               }
-       return "";
+                pos = 0;
+                toks = new StringTokenizer(SourceString, "|");
+               while (toks.hasMoreTokens()) {
+                       buf = toks.nextToken();
+                       if (pos == ParmNum)
+                               return buf;
+                       ++pos;
+               } return "";
        }
 
 }
index 184a9aa6ef2c48d2c52c11e2f57eed54f551e6bb..ea2c305eaee047bcda01cf2ae5e6490d648ba977 100644 (file)
@@ -10,9 +10,9 @@ import java.applet.*;
 
 public class wcchat extends Applet {
 
-String ServerHost = "uncnsrd.mt-kisco.ny.us";
-int ServerPort = 504;
-       
+       String ServerHost = "uncensored.citadel.org";
+       int ServerPort = 504;
+
        public void init() {
 
                /* Unless overridden, the Citadel server is expected to be
@@ -21,24 +21,24 @@ int ServerPort = 504;
                 */
                if (getDocumentBase() != null) {
                        ServerHost = getDocumentBase().getHost();
-                       }
+               }
 
                /* The 'host' parameter tells the client to look somewhere other
                 * than the applet host for the Citadel server.
-                */
-               if (getParameter("host") != null) {
+                */ if (getParameter("host") != null) {
                        ServerHost = getParameter("host");
-                       }
+               }
 
                /* The 'port' parameter tells the client to look on a
                 * nonstandard port for the Citadel server.
                 */
                if (getParameter("port") != null) {
-                       ServerPort = Integer.parseInt(getParameter("port"));
-                       }
-
+                       ServerPort =
+                           Integer.parseInt(getParameter("port"));
                }
 
+       }
+
        public void start() {
                wcCitServer serv = new wcCitServer();
                String buf = null;
@@ -46,16 +46,22 @@ int ServerPort = 504;
                serv.AttachToServer(ServerHost, ServerPort);
                buf = serv.ServTrans("USER " + getParameter("username"));
                if (buf.charAt(0) == '3') {
-                       buf = serv.ServTrans("PASS "+getParameter("password"));
+                       buf =
+                           serv.ServTrans("PASS " +
+                                          getParameter("password"));
                        if (buf.charAt(0) == '2') {
-                               serv.SetUserName(wcCitUtil.Extract(buf.substring(4), 0));
-                               buf = serv.ServTrans("GOTO "+getParameter("roomname"));
+                               serv.SetUserName(wcCitUtil.
+                                                Extract(buf.substring(4),
+                                                        0));
+                               buf =
+                                   serv.ServTrans("GOTO " +
+                                                  getParameter
+                                                  ("roomname"));
                                new MultiUserChat102(serv, this);
-                               }
                        }
-               else {
+               else {
                        System.out.println("ooops...");
-                       }
                }
+       }
 
 }
index a4363adc5fc02cfb1a17264e308555414a639dac..e388d799d595879ffe2af8b0df1c1a2f4747c680 100644 (file)
@@ -1123,6 +1123,10 @@ void session_loop(struct httprequest *req)
                edit_me();
        } else if (!strcasecmp(action, "display_siteconfig")) {
                display_siteconfig();
+       } else if (!strcasecmp(action, "chat_recv")) {
+               chat_recv();
+       } else if (!strcasecmp(action, "chat_send")) {
+               chat_send();
        } else if (!strcasecmp(action, "page_popup")) {
                page_popup();
        } else if (!strcasecmp(action, "siteconfig")) {
index 94413e6d1f06e0e13abb9157b393907afa993bf2..b9d261bd093a0cbe61792631d3493aaaadc66ef1 100644 (file)
 #define SLEEPING               180             /* TCP connection timeout */
 #define WEBCIT_TIMEOUT         900             /* WebCit session timeout */
 #define PORT_NUM               2000            /* port number to listen on */
-#define SERVER                 "WebCit v5.05"  /* who's in da house */
+#define SERVER                 "WebCit v5.04"  /* who's in da house */
 #define DEVELOPER_ID           0
 #define CLIENT_ID              4
-#define CLIENT_VERSION         505             /* This version of WebCit */
+#define CLIENT_VERSION         504             /* This version of WebCit */
 #define MINIMUM_CIT_VERSION    611             /* min required Citadel vers */
 #define DEFAULT_HOST           "localhost"     /* Default Citadel server */
 #define DEFAULT_PORT           "504"
@@ -163,6 +163,7 @@ struct wc_attachment {
        char *data;
 };
 
+#define CHATLINES 8
 
 /*
  * One of these is kept for each active Citadel session.
@@ -181,6 +182,7 @@ struct wcsession {
        int is_room_aide;
        int http_sock;
        int serv_sock;
+       int chat_sock;
        unsigned room_flags;
        int wc_view;
        int wc_default_view;
@@ -218,6 +220,7 @@ struct wcsession {
        char ImportantMessage[SIZ];
        int outside_frameset_allowed;   /* nonzero if current req is allowed
                                         * outside of the main frameset */
+       char chatlines[CHATLINES][SIZ];
 };
 
 #define extract(dest,source,parmnum)   extract_token(dest,source,parmnum,'|')
@@ -343,6 +346,8 @@ void fmt_time(char *buf, time_t thetime);
 void httpdate(char *buf, time_t thetime);
 void end_webcit_session(void);
 void page_popup(void);
+void chat_recv(void);
+void chat_send(void);
 void http_redirect(char *);
 void clear_local_substs(void);
 void svprintf(char *keyname, int keytype, const char *format,...);