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"
49 #define MIN(a, b) ((a) < (b) ? (a) : (b))
51 extern struct CtdlServInfo serv_info;
53 void getline(char *, int);
55 char last_paged[SIZ] = "";
65 int send_complete_line;
66 int recv_complete_line;
78 scr_printf("%s\n", &buf[4]);
81 scr_printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
82 set_keepalives(KA_NO);
83 last_transmit = time(NULL);
89 send_complete_line = 0;
90 recv_complete_line = 0;
96 FD_SET(getsockfd(), &rfds);
97 tv.tv_sec = S_KEEPALIVE;
99 retval = select(getsockfd() + 1, &rfds, NULL, NULL, &tv);
101 if (FD_ISSET(getsockfd(), &rfds)) {
104 recv_complete_line = 1;
105 goto RCL; /* ugly, but we've gotta get out! */
107 buf[strlen(buf) + 1] = 0;
108 buf[strlen(buf)] = ch;
112 if (FD_ISSET(0, &rfds)) {
114 if ((ch == 10) || (ch == 13)) {
115 send_complete_line = 1;
116 } else if ((ch == 8) || (ch == 127)) {
117 if (strlen(wbuf) > 0) {
118 wbuf[strlen(wbuf) - 1] = 0;
119 scr_printf("%c %c", 8, 8);
123 wbuf[strlen(wbuf) + 1] = 0;
124 wbuf[strlen(wbuf)] = ch;
127 /* if the user hit return, send the line */
128 RCL:if (send_complete_line) {
130 last_transmit = time(NULL);
132 send_complete_line = 0;
134 /* if it's time to word wrap, send a partial line */
135 if (strlen(wbuf) >= (77 - strlen(fullname))) {
137 for (a = 0; a < strlen(wbuf); ++a) {
143 last_transmit = time(NULL);
145 send_complete_line = 0;
149 last_transmit = time(NULL);
150 strcpy(wbuf, &wbuf[pos + 1]);
153 if (recv_complete_line) {
154 scr_printf("\r%79s\r", "");
155 if (!strcmp(buf, "000")) {
157 scr_printf("Exiting chat mode\n");
160 set_keepalives(KA_YES);
163 /* Some users complained about the client and server
164 * losing protocol synchronization when exiting chat.
165 * This little dialog forces everything to be
168 serv_puts("ECHO __ExitingChat__");
171 } while (strcmp(buf, "200 __ExitingChat__"));
176 if (num_parms(buf) >= 2) {
177 extract(c_user, buf, 0);
178 extract(c_text, buf, 1);
179 if (num_parms(buf) > 2) {
180 extract(c_room, buf, 2);
181 scr_printf("Got room %s\n", c_room);
183 if (strcasecmp(c_text, "NOOP")) {
184 if (!strcmp(c_user, fullname)) {
185 color(BRIGHT_YELLOW);
186 } else if (!strcmp(c_user, ":")) {
191 if (strcmp(c_user, last_user)) {
192 snprintf(buf, sizeof buf, "%s: %s", c_user, c_text);
194 size_t i = MIN(sizeof buf - 1,
198 safestrncpy(&buf[i], c_text,
201 while (strlen(buf) < 79)
203 if (strcmp(c_user, last_user)) {
204 scr_printf("\r%79s\n", "");
205 strcpy(last_user, c_user);
207 scr_printf("\r%s\n", buf);
211 color(BRIGHT_YELLOW);
212 scr_printf("> %s", wbuf);
213 recv_complete_line = 0;
217 /* If the user is sitting idle, send a half-keepalive to the
218 * server to prevent session timeout.
220 if ((time(NULL) - last_transmit) >= S_KEEPALIVE) {
222 last_transmit = time(NULL);
229 * send an express message
233 char buf[SIZ], touser[SIZ], msg[SIZ];
236 strcpy(touser, last_paged);
237 strprompt("Page who", touser, 30);
239 /* old server -- use inline paging */
240 if (serv_info.serv_paging_level == 0) {
241 newprompt("Message: ", msg, 69);
242 snprintf(buf, sizeof buf, "SEXP %s|%s", touser, msg);
245 if (!strncmp(buf, "200", 3)) {
246 strcpy(last_paged, touser);
248 scr_printf("%s\n", &buf[4]);
251 /* new server -- use extended paging */
252 else if (serv_info.serv_paging_level >= 1) {
253 snprintf(buf, sizeof buf, "SEXP %s||", touser);
257 scr_printf("%s\n", &buf[4]);
260 if (client_make_message(temp, touser, 0, 0, 0) != 0) {
261 scr_printf("No message sent.\n");
264 pagefp = fopen(temp, "r");
266 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
270 strcpy(last_paged, touser);
271 while (fgets(buf, sizeof buf, pagefp) != NULL) {
272 buf[strlen(buf) - 1] = 0;
277 scr_printf("Message sent.\n");
279 scr_printf("%s\n", &buf[4]);
287 void quiet_mode(void)
295 scr_printf("%s\n", &buf[4]);
298 qstate = atoi(&buf[4]);
303 sprintf(buf, "DEXP %d", qstate);
307 scr_printf("%s\n", &buf[4]);
310 qstate = atoi(&buf[4]);
312 scr_printf("Quiet mode enabled (no other users may page you)\n");
314 scr_printf("Quiet mode disabled (other users may page you)\n");