]> code.citadel.org Git - citadel.git/blobdiff - citadel/client_chat.c
* Changed the comments at the beginning of each file to a consistent format
[citadel.git] / citadel / client_chat.c
index 6316a138e90c5857df29608b7932daf68cf9ed88..658e9c13b0b6a365b4ad5925364dc4f0f4f8a072 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Citadel/UX
+ * $Id$
  *
- * client_chat.c  --  front end for chat mode
- *                    (the "single process" version - no more fork() anymore)
+ * front end for chat mode
+ * (the "single process" version - no more fork() anymore)
  *
  */
 
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#ifdef NEED_SELECT_H
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
+#include <stdarg.h>
 #include "citadel.h"
+#include "client_chat.h"
+#include "commands.h"
+#include "routines.h"
+#include "ipc.h"
+#include "citadel_decls.h"
+#include "tools.h"
+#include "rooms.h"
+#include "messages.h"
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
 
-extern char fullname[];
-
-int inkey();
-void set_keepalives();
-int num_parms();
-void extract();
-int struncmp();
-int getsockfd();
-char serv_getc();
-void color();
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
+extern struct CtdlServInfo serv_info;
+extern char temp[];
+void getline(char *, int);
 
-void chatmode() {
+void chatmode(void) {
        char wbuf[256];
        char buf[256];
        char c_user[256];
@@ -62,7 +68,7 @@ void chatmode() {
 
        strcpy(buf,"");
        strcpy(wbuf,"");
-       color(3);
+       color(BRIGHT_YELLOW);
        printf("> ");
        send_complete_line = 0;
        recv_complete_line = 0;
@@ -136,11 +142,24 @@ RCL:          if (send_complete_line) {
            if (recv_complete_line) {   
                printf("\r%79s\r","");
                if (!strcmp(buf,"000")) {
-                       color(7);
+                       color(BRIGHT_WHITE);
                        printf("Exiting chat mode\n");
 
                        fflush(stdout);
                        set_keepalives(KA_YES);
+
+
+                       /* Some users complained about the client and server
+                        * losing protocol synchronization when exiting chat.
+                        * This little dialog forces everything to be
+                        * hunky-dory.
+                        */
+                       serv_puts("ECHO __ExitingChat__");
+                       do {
+                               serv_gets(buf);
+                       } while (strcmp(buf, "200 __ExitingChat__"));
+
+
                        return;
                        }
                if (num_parms(buf)>=2) {
@@ -152,23 +171,26 @@ RCL:          if (send_complete_line) {
                           printf("Got room %s\n", c_room);
                        }
                           
-                       if (strucmp(c_text,"NOOP")) {
+                       if (strcasecmp(c_text,"NOOP")) {
                                if (!strcmp(c_user, fullname)) {
-                                       color(3);
+                                       color(BRIGHT_YELLOW);
                                        }
                                else if (!strcmp(c_user,":")) {
-                                       color(1);
+                                       color(BRIGHT_RED);
                                        }
                                else {
-                                       color(2);
+                                       color(BRIGHT_GREEN);
                                        }
                                if (strcmp(c_user,last_user)) {
-                                       sprintf(buf,"%s: %s",c_user,c_text);
+                                       snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
                                        }
                                else {
-                                       sprintf(buf,"%40s","");
-                                       sprintf(&buf[strlen(c_user)+2],
-                                               "%s",c_text);
+                                       size_t i = MIN(sizeof buf - 1,
+                                                      strlen(c_user) + 2);
+
+                                       memset(buf, ' ', i);
+                                       safestrncpy(&buf[i], c_text,
+                                                   sizeof buf - i);
                                        }
                                while (strlen(buf)<79) strcat(buf," ");
                                if (strcmp(c_user,last_user)) {
@@ -179,7 +201,7 @@ RCL:            if (send_complete_line) {
                                fflush(stdout);
                                }
                        }
-               color(3);
+               color(BRIGHT_YELLOW);
                printf("> %s",wbuf);
                recv_complete_line = 0;
                strcpy(buf,"");
@@ -187,4 +209,94 @@ RCL:           if (send_complete_line) {
            }
        }
 
+/*
+ * send an express message
+ */
+void page_user() {
+       static char last_paged[32] = "";
+       char buf[256], touser[256], msg[256];
+       FILE *pagefp;
+
+       strcpy(touser, last_paged);
+       strprompt("Page who", touser, 30);
+
+       /* old server -- use inline paging */
+       if (serv_info.serv_paging_level == 0) {
+               newprompt("Message:  ", msg, 69);
+               snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (!strncmp(buf, "200", 3)) {
+                       strcpy(last_paged, touser);
+                       }
+               printf("%s\n", &buf[4]);
+               return;
+       }
+
+       /* new server -- use extended paging */ 
+       else if (serv_info.serv_paging_level >= 1) {
+               snprintf(buf, sizeof buf, "SEXP %s||", touser);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (buf[0] != '2') {
+                       printf("%s\n", &buf[4]);
+                       return;
+                       }
+
+               if ( make_message(temp, touser, 0, 0, 0) != 0 ) {
+                       printf("No message sent.\n");
+                       return;
+               }
 
+               pagefp = fopen(temp, "r");
+               unlink(temp);
+               snprintf(buf, sizeof buf, "SEXP %s|-", touser);
+               serv_puts(buf);
+               serv_gets(buf);
+               if (buf[0]=='4') {
+                       strcpy(last_paged, touser);
+                       while (fgets(buf, 256, pagefp) != NULL) {
+                               buf[strlen(buf)-1] = 0;
+                               serv_puts(buf);
+                               }
+                       fclose(pagefp);
+                       serv_puts("000");
+                       printf("Message sent.\n");
+               }
+               else {
+                       printf("%s\n", &buf[4]);
+               }
+       }
+}
+
+
+
+
+void quiet_mode(void) {
+       int qstate;
+       char buf[256];
+
+       serv_puts("DEXP 2");
+       serv_gets(buf);
+       if (buf[0]!='2') {
+               printf("%s\n", &buf[4]);
+               return;
+       }
+       qstate = atoi(&buf[4]);
+       if (qstate == 0) qstate = 1;
+       else qstate = 0;
+       sprintf(buf, "DEXP %d", qstate);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0]!='2') {
+               printf("%s\n", &buf[4]);
+               return;
+       }
+       qstate = atoi(&buf[4]);
+       if (qstate) {
+               printf("Quiet mode enabled (no other users may page you)\n");
+       }
+       else {
+               printf("Quiet mode disabled (other users may page you)\n");
+       }
+}