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);
43 char last_paged[SIZ] = "";
53 int send_complete_line;
54 int recv_complete_line;
66 printf("%s\n", &buf[4]);
69 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
70 set_keepalives(KA_NO);
71 last_transmit = time(NULL);
77 send_complete_line = 0;
78 recv_complete_line = 0;
84 FD_SET(getsockfd(), &rfds);
85 tv.tv_sec = S_KEEPALIVE;
87 retval = select(getsockfd() + 1, &rfds, NULL, NULL, &tv);
89 if (FD_ISSET(getsockfd(), &rfds)) {
92 recv_complete_line = 1;
93 goto RCL; /* ugly, but we've gotta get out! */
95 buf[strlen(buf) + 1] = 0;
96 buf[strlen(buf)] = ch;
100 if (FD_ISSET(0, &rfds)) {
102 if ((ch == 10) || (ch == 13)) {
103 send_complete_line = 1;
104 } else if ((ch == 8) || (ch == 127)) {
105 if (strlen(wbuf) > 0) {
106 wbuf[strlen(wbuf) - 1] = 0;
107 printf("%c %c", 8, 8);
111 wbuf[strlen(wbuf) + 1] = 0;
112 wbuf[strlen(wbuf)] = ch;
115 /* if the user hit return, send the line */
116 RCL:if (send_complete_line) {
118 last_transmit = time(NULL);
120 send_complete_line = 0;
122 /* if it's time to word wrap, send a partial line */
123 if (strlen(wbuf) >= (77 - strlen(fullname))) {
125 for (a = 0; a < strlen(wbuf); ++a) {
131 last_transmit = time(NULL);
133 send_complete_line = 0;
137 last_transmit = time(NULL);
138 strcpy(wbuf, &wbuf[pos + 1]);
141 if (recv_complete_line) {
142 printf("\r%79s\r", "");
143 if (!strcmp(buf, "000")) {
145 printf("Exiting chat mode\n");
148 set_keepalives(KA_YES);
151 /* Some users complained about the client and server
152 * losing protocol synchronization when exiting chat.
153 * This little dialog forces everything to be
156 serv_puts("ECHO __ExitingChat__");
159 } while (strcmp(buf, "200 __ExitingChat__"));
164 if (num_parms(buf) >= 2) {
165 extract(c_user, buf, 0);
166 extract(c_text, buf, 1);
167 if (num_parms(buf) > 2) {
168 extract(c_room, buf, 2);
169 printf("Got room %s\n", c_room);
171 if (strcasecmp(c_text, "NOOP")) {
172 if (!strcmp(c_user, fullname)) {
173 color(BRIGHT_YELLOW);
174 } else if (!strcmp(c_user, ":")) {
179 if (strcmp(c_user, last_user)) {
180 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
182 size_t i = MIN(sizeof buf - 1,
186 safestrncpy(&buf[i], c_text,
189 while (strlen(buf) < 79)
191 if (strcmp(c_user, last_user)) {
192 printf("\r%79s\n", "");
193 strcpy(last_user, c_user);
195 printf("\r%s\n", buf);
199 color(BRIGHT_YELLOW);
200 printf("> %s", wbuf);
201 recv_complete_line = 0;
205 /* If the user is sitting idle, send a half-keepalive to the
206 * server to prevent session timeout.
208 if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
210 last_transmit = time(NULL);
217 * send an express message
221 char buf[SIZ], touser[SIZ], msg[SIZ];
224 strcpy(touser, last_paged);
225 strprompt("Page who", touser, 30);
227 /* old server -- use inline paging */
228 if (serv_info.serv_paging_level == 0) {
229 newprompt("Message: ", msg, 69);
230 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
233 if (!strncmp(buf, "200", 3)) {
234 strcpy(last_paged, touser);
236 printf("%s\n", &buf[4]);
239 /* new server -- use extended paging */
240 else if (serv_info.serv_paging_level >= 1) {
241 snprintf(buf, sizeof buf, "SEXP %s||", touser);
245 printf("%s\n", &buf[4]);
248 if (make_message(temp, touser, 0, 0, 0) != 0) {
249 printf("No message sent.\n");
252 pagefp = fopen(temp, "r");
254 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
258 strcpy(last_paged, touser);
259 while (fgets(buf, sizeof buf, pagefp) != NULL) {
260 buf[strlen(buf) - 1] = 0;
265 printf("Message sent.\n");
267 printf("%s\n", &buf[4]);
275 void quiet_mode(void)
283 printf("%s\n", &buf[4]);
286 qstate = atoi(&buf[4]);
291 sprintf(buf, "DEXP %d", qstate);
295 printf("%s\n", &buf[4]);
298 qstate = atoi(&buf[4]);
300 printf("Quiet mode enabled (no other users may page you)\n");
302 printf("Quiet mode disabled (other users may page you)\n");