4 * front end for chat mode
5 * (the "single process" version - no more fork() anymore)
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
30 #include <sys/types.h>
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
36 #include "client_chat.h"
40 #include "citadel_decls.h"
48 #define MIN(a, b) ((a) < (b) ? (a) : (b))
50 extern struct CtdlServInfo serv_info;
52 void getline(char *, int);
54 char last_paged[SIZ] = "";
64 int send_complete_line;
65 int recv_complete_line;
77 printf("%s\n", &buf[4]);
80 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
81 set_keepalives(KA_NO);
82 last_transmit = time(NULL);
88 send_complete_line = 0;
89 recv_complete_line = 0;
95 FD_SET(getsockfd(), &rfds);
96 tv.tv_sec = S_KEEPALIVE;
98 retval = select(getsockfd() + 1, &rfds, NULL, NULL, &tv);
100 if (FD_ISSET(getsockfd(), &rfds)) {
103 recv_complete_line = 1;
104 goto RCL; /* ugly, but we've gotta get out! */
106 buf[strlen(buf) + 1] = 0;
107 buf[strlen(buf)] = ch;
111 if (FD_ISSET(0, &rfds)) {
113 if ((ch == 10) || (ch == 13)) {
114 send_complete_line = 1;
115 } else if ((ch == 8) || (ch == 127)) {
116 if (strlen(wbuf) > 0) {
117 wbuf[strlen(wbuf) - 1] = 0;
118 printf("%c %c", 8, 8);
122 wbuf[strlen(wbuf) + 1] = 0;
123 wbuf[strlen(wbuf)] = ch;
126 /* if the user hit return, send the line */
127 RCL:if (send_complete_line) {
129 last_transmit = time(NULL);
131 send_complete_line = 0;
133 /* if it's time to word wrap, send a partial line */
134 if (strlen(wbuf) >= (77 - strlen(fullname))) {
136 for (a = 0; a < strlen(wbuf); ++a) {
142 last_transmit = time(NULL);
144 send_complete_line = 0;
148 last_transmit = time(NULL);
149 strcpy(wbuf, &wbuf[pos + 1]);
152 if (recv_complete_line) {
153 printf("\r%79s\r", "");
154 if (!strcmp(buf, "000")) {
156 printf("Exiting chat mode\n");
159 set_keepalives(KA_YES);
162 /* Some users complained about the client and server
163 * losing protocol synchronization when exiting chat.
164 * This little dialog forces everything to be
167 serv_puts("ECHO __ExitingChat__");
170 } while (strcmp(buf, "200 __ExitingChat__"));
175 if (num_parms(buf) >= 2) {
176 extract(c_user, buf, 0);
177 extract(c_text, buf, 1);
178 if (num_parms(buf) > 2) {
179 extract(c_room, buf, 2);
180 printf("Got room %s\n", c_room);
182 if (strcasecmp(c_text, "NOOP")) {
183 if (!strcmp(c_user, fullname)) {
184 color(BRIGHT_YELLOW);
185 } else if (!strcmp(c_user, ":")) {
190 if (strcmp(c_user, last_user)) {
191 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
193 size_t i = MIN(sizeof buf - 1,
197 safestrncpy(&buf[i], c_text,
200 while (strlen(buf) < 79)
202 if (strcmp(c_user, last_user)) {
203 printf("\r%79s\n", "");
204 strcpy(last_user, c_user);
206 printf("\r%s\n", buf);
210 color(BRIGHT_YELLOW);
211 printf("> %s", wbuf);
212 recv_complete_line = 0;
216 /* If the user is sitting idle, send a half-keepalive to the
217 * server to prevent session timeout.
219 if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
221 last_transmit = time(NULL);
228 * send an express message
232 char buf[SIZ], touser[SIZ], msg[SIZ];
235 strcpy(touser, last_paged);
236 strprompt("Page who", touser, 30);
238 /* old server -- use inline paging */
239 if (serv_info.serv_paging_level == 0) {
240 newprompt("Message: ", msg, 69);
241 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
244 if (!strncmp(buf, "200", 3)) {
245 strcpy(last_paged, touser);
247 printf("%s\n", &buf[4]);
250 /* new server -- use extended paging */
251 else if (serv_info.serv_paging_level >= 1) {
252 snprintf(buf, sizeof buf, "SEXP %s||", touser);
256 printf("%s\n", &buf[4]);
259 if (make_message(temp, touser, 0, 0, 0) != 0) {
260 printf("No message sent.\n");
263 pagefp = fopen(temp, "r");
265 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
269 strcpy(last_paged, touser);
270 while (fgets(buf, sizeof buf, pagefp) != NULL) {
271 buf[strlen(buf) - 1] = 0;
276 printf("Message sent.\n");
278 printf("%s\n", &buf[4]);
286 void quiet_mode(void)
294 printf("%s\n", &buf[4]);
297 qstate = atoi(&buf[4]);
302 sprintf(buf, "DEXP %d", qstate);
306 printf("%s\n", &buf[4]);
309 qstate = atoi(&buf[4]);
311 printf("Quiet mode enabled (no other users may page you)\n");
313 printf("Quiet mode disabled (other users may page you)\n");