4 * front end for chat mode
5 * (the "single process" version - no more fork() anymore)
19 #include <sys/types.h>
20 #ifdef HAVE_SYS_SELECT_H
21 #include <sys/select.h>
25 #include "client_chat.h"
29 #include "citadel_decls.h"
37 #define MIN(a, b) ((a) < (b) ? (a) : (b))
39 extern struct CtdlServInfo serv_info;
41 void getline(char *, int);
51 int send_complete_line;
52 int recv_complete_line;
64 printf("%s\n", &buf[4]);
67 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
68 set_keepalives(KA_NO);
69 last_transmit = time(NULL);
75 send_complete_line = 0;
76 recv_complete_line = 0;
82 FD_SET(getsockfd(), &rfds);
83 tv.tv_sec = S_KEEPALIVE;
85 retval = select(getsockfd() + 1, &rfds, NULL, NULL, &tv);
87 if (FD_ISSET(getsockfd(), &rfds)) {
90 recv_complete_line = 1;
91 goto RCL; /* ugly, but we've gotta get out! */
93 buf[strlen(buf) + 1] = 0;
94 buf[strlen(buf)] = ch;
98 if (FD_ISSET(0, &rfds)) {
100 if ((ch == 10) || (ch == 13)) {
101 send_complete_line = 1;
102 } else if ((ch == 8) || (ch == 127)) {
103 if (strlen(wbuf) > 0) {
104 wbuf[strlen(wbuf) - 1] = 0;
105 printf("%c %c", 8, 8);
109 wbuf[strlen(wbuf) + 1] = 0;
110 wbuf[strlen(wbuf)] = ch;
113 /* if the user hit return, send the line */
114 RCL:if (send_complete_line) {
116 last_transmit = time(NULL);
118 send_complete_line = 0;
120 /* if it's time to word wrap, send a partial line */
121 if (strlen(wbuf) >= (77 - strlen(fullname))) {
123 for (a = 0; a < strlen(wbuf); ++a) {
129 last_transmit = time(NULL);
131 send_complete_line = 0;
135 last_transmit = time(NULL);
136 strcpy(wbuf, &wbuf[pos + 1]);
139 if (recv_complete_line) {
140 printf("\r%79s\r", "");
141 if (!strcmp(buf, "000")) {
143 printf("Exiting chat mode\n");
146 set_keepalives(KA_YES);
149 /* Some users complained about the client and server
150 * losing protocol synchronization when exiting chat.
151 * This little dialog forces everything to be
154 serv_puts("ECHO __ExitingChat__");
157 } while (strcmp(buf, "200 __ExitingChat__"));
162 if (num_parms(buf) >= 2) {
163 extract(c_user, buf, 0);
164 extract(c_text, buf, 1);
165 if (num_parms(buf) > 2) {
166 extract(c_room, buf, 2);
167 printf("Got room %s\n", c_room);
169 if (strcasecmp(c_text, "NOOP")) {
170 if (!strcmp(c_user, fullname)) {
171 color(BRIGHT_YELLOW);
172 } else if (!strcmp(c_user, ":")) {
177 if (strcmp(c_user, last_user)) {
178 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
180 size_t i = MIN(sizeof buf - 1,
184 safestrncpy(&buf[i], c_text,
187 while (strlen(buf) < 79)
189 if (strcmp(c_user, last_user)) {
190 printf("\r%79s\n", "");
191 strcpy(last_user, c_user);
193 printf("\r%s\n", buf);
197 color(BRIGHT_YELLOW);
198 printf("> %s", wbuf);
199 recv_complete_line = 0;
203 /* If the user is sitting idle, send a half-keepalive to the
204 * server to prevent session timeout.
206 if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
208 last_transmit = time(NULL);
215 * send an express message
219 static char last_paged[32] = "";
220 char buf[SIZ], touser[SIZ], msg[SIZ];
223 strcpy(touser, last_paged);
224 strprompt("Page who", touser, 30);
226 /* old server -- use inline paging */
227 if (serv_info.serv_paging_level == 0) {
228 newprompt("Message: ", msg, 69);
229 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
232 if (!strncmp(buf, "200", 3)) {
233 strcpy(last_paged, touser);
235 printf("%s\n", &buf[4]);
238 /* new server -- use extended paging */
239 else if (serv_info.serv_paging_level >= 1) {
240 snprintf(buf, sizeof buf, "SEXP %s||", touser);
244 printf("%s\n", &buf[4]);
247 if (make_message(temp, touser, 0, 0, 0) != 0) {
248 printf("No message sent.\n");
251 pagefp = fopen(temp, "r");
253 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
257 strcpy(last_paged, touser);
258 while (fgets(buf, sizeof buf, pagefp) != NULL) {
259 buf[strlen(buf) - 1] = 0;
264 printf("Message sent.\n");
266 printf("%s\n", &buf[4]);
274 void quiet_mode(void)
282 printf("%s\n", &buf[4]);
285 qstate = atoi(&buf[4]);
290 sprintf(buf, "DEXP %d", qstate);
294 printf("%s\n", &buf[4]);
297 qstate = atoi(&buf[4]);
299 printf("Quiet mode enabled (no other users may page you)\n");
301 printf("Quiet mode disabled (other users may page you)\n");