]> code.citadel.org Git - citadel.git/blobdiff - citadel/client_chat.c
* Make stealth mode available to all users
[citadel.git] / citadel / client_chat.c
index c30cd66994b54b163883f67e41a7d34cda0bd898..b5d867fe41753a6b139e1bfc851f93684ea93f46 100644 (file)
 #include <string.h>
 #include <signal.h>
 #include <errno.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/types.h>
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -33,6 +44,7 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
+#include "screen.h"
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
@@ -63,22 +75,23 @@ void chatmode(void)
        serv_puts("CHAT");
        serv_gets(buf);
        if (buf[0] != '8') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
-       printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
+       scr_printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
        set_keepalives(KA_NO);
        last_transmit = time(NULL);
 
        strcpy(buf, "");
        strcpy(wbuf, "");
        color(BRIGHT_YELLOW);
-       printf("> ");
+       sln_printf_if("\n");
+       sln_printf("> ");
        send_complete_line = 0;
        recv_complete_line = 0;
 
        while (1) {
-               fflush(stdout);
+               sln_flush();
                FD_ZERO(&rfds);
                FD_SET(0, &rfds);
                FD_SET(getsockfd(), &rfds);
@@ -98,16 +111,16 @@ void chatmode(void)
                        goto RCL;
                }
                if (FD_ISSET(0, &rfds)) {
-                       ch = inkey();
+                       ch = scr_getc(SCR_BLOCK);
                        if ((ch == 10) || (ch == 13)) {
                                send_complete_line = 1;
                        } else if ((ch == 8) || (ch == 127)) {
                                if (strlen(wbuf) > 0) {
                                        wbuf[strlen(wbuf) - 1] = 0;
-                                       printf("%c %c", 8, 8);
+                                       sln_printf("%c %c", 8, 8);
                                }
                        } else {
-                               putc(ch, stdout);
+                               sln_putc(ch);
                                wbuf[strlen(wbuf) + 1] = 0;
                                wbuf[strlen(wbuf)] = ch;
                        }
@@ -139,15 +152,13 @@ void chatmode(void)
                        }
                }
                if (recv_complete_line) {
-                       printf("\r%79s\r", "");
+                       sln_printf("\r%79s\r", "");
                        if (!strcmp(buf, "000")) {
                                color(BRIGHT_WHITE);
-                               printf("Exiting chat mode\n");
-
-                               fflush(stdout);
+                               sln_printf("\rExiting chat mode\n");
+                               sln_flush();
                                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
@@ -166,7 +177,7 @@ void chatmode(void)
                                extract(c_text, buf, 1);
                                if (num_parms(buf) > 2) {
                                        extract(c_room, buf, 2);
-                                       printf("Got room %s\n", c_room);
+                                       scr_printf("Got room %s\n", c_room);
                                }
                                if (strcasecmp(c_text, "NOOP")) {
                                        if (!strcmp(c_user, fullname)) {
@@ -189,15 +200,16 @@ void chatmode(void)
                                        while (strlen(buf) < 79)
                                                strcat(buf, " ");
                                        if (strcmp(c_user, last_user)) {
-                                               printf("\r%79s\n", "");
+                                               sln_printf("\r%79s\n", "");
                                                strcpy(last_user, c_user);
                                        }
-                                       printf("\r%s\n", buf);
-                                       fflush(stdout);
+                                       scr_printf("\r%s\n", buf);
+                                       scr_flush();
                                }
                        }
                        color(BRIGHT_YELLOW);
-                       printf("> %s", wbuf);
+                       sln_printf("\r> %s", wbuf);
+                       sln_flush();
                        recv_complete_line = 0;
                        strcpy(buf, "");
                }
@@ -233,7 +245,7 @@ void page_user()
                if (!strncmp(buf, "200", 3)) {
                        strcpy(last_paged, touser);
                }
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        /* new server -- use extended paging */
@@ -242,11 +254,11 @@ void page_user()
                serv_puts(buf);
                serv_gets(buf);
                if (buf[0] != '2') {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                        return;
                }
-               if (make_message(temp, touser, 0, 0, 0) != 0) {
-                       printf("No message sent.\n");
+               if (client_make_message(temp, touser, 0, 0, 0, NULL) != 0) {
+                       scr_printf("No message sent.\n");
                        return;
                }
                pagefp = fopen(temp, "r");
@@ -262,9 +274,9 @@ void page_user()
                        }
                        fclose(pagefp);
                        serv_puts("000");
-                       printf("Message sent.\n");
+                       scr_printf("Message sent.\n");
                } else {
-                       printf("%s\n", &buf[4]);
+                       scr_printf("%s\n", &buf[4]);
                }
        }
 }
@@ -280,7 +292,39 @@ void quiet_mode(void)
        serv_puts("DEXP 2");
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
+               return;
+       }
+       qstate = atoi(&buf[4]);
+       if (qstate == 0)
+               qstate = 1;
+       else
+               qstate = 0;
+       snprintf(buf, sizeof buf, "DEXP %d", qstate);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] != '2') {
+               scr_printf("%s\n", &buf[4]);
+               return;
+       }
+       qstate = atoi(&buf[4]);
+       if (qstate) {
+               scr_printf("Quiet mode enabled (no other users may page you)\n");
+       } else {
+               scr_printf("Quiet mode disabled (other users may page you)\n");
+       }
+}
+
+
+void stealth_mode(void)
+{
+       int qstate;
+       char buf[SIZ];
+
+       serv_puts("STEL 2");
+       serv_gets(buf);
+       if (buf[0] != '2') {
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        qstate = atoi(&buf[4]);
@@ -288,17 +332,17 @@ void quiet_mode(void)
                qstate = 1;
        else
                qstate = 0;
-       sprintf(buf, "DEXP %d", qstate);
+       snprintf(buf, sizeof buf, "STEL %d", qstate);
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0] != '2') {
-               printf("%s\n", &buf[4]);
+               scr_printf("%s\n", &buf[4]);
                return;
        }
        qstate = atoi(&buf[4]);
        if (qstate) {
-               printf("Quiet mode enabled (no other users may page you)\n");
+               scr_printf("Stealth mode enabled (you are invisible)\n");
        } else {
-               printf("Quiet mode disabled (other users may page you)\n");
+               scr_printf("Stealth mode disabled (you are listed as online)\n");
        }
 }