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);
50 int send_complete_line;
51 int recv_complete_line;
62 printf("%s\n",&buf[4]);
66 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
67 set_keepalives(KA_CHAT);
73 send_complete_line = 0;
74 recv_complete_line = 0;
80 FD_SET(getsockfd(),&rfds);
81 tv.tv_sec = S_KEEPALIVE;
83 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
85 if (FD_ISSET(getsockfd(), &rfds)) {
88 recv_complete_line = 1;
89 goto RCL; /* ugly, but we've gotta get out! */
92 buf[strlen(buf) + 1] = 0;
93 buf[strlen(buf)] = ch;
98 if (FD_ISSET(0, &rfds)) {
100 if ((ch == 10) || (ch == 13)) {
101 send_complete_line = 1;
103 else if ((ch == 8) || (ch == 127)) {
104 if (strlen(wbuf) > 0) {
105 wbuf[strlen(wbuf)-1] = 0;
111 wbuf[strlen(wbuf) + 1] = 0;
112 wbuf[strlen(wbuf)] = ch;
117 /* if the user hit return, send the line */
118 RCL: if (send_complete_line) {
121 send_complete_line = 0;
124 /* if it's time to word wrap, send a partial line */
125 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
127 for (a=0; a<strlen(wbuf); ++a) {
128 if (wbuf[a] == 32) pos = a;
133 send_complete_line = 0;
138 strcpy(wbuf,&wbuf[pos+1]);
142 if (recv_complete_line) {
143 printf("\r%79s\r","");
144 if (!strcmp(buf,"000")) {
146 printf("Exiting chat mode\n");
149 set_keepalives(KA_YES);
152 /* Some users complained about the client and server
153 * losing protocol synchronization when exiting chat.
154 * This little dialog forces everything to be
157 serv_puts("ECHO __ExitingChat__");
160 } while (strcmp(buf, "200 __ExitingChat__"));
165 if (num_parms(buf)>=2) {
166 extract(c_user,buf,0);
167 extract(c_text,buf,1);
168 if (num_parms(buf)>2)
170 extract(c_room,buf,2);
171 printf("Got room %s\n", c_room);
174 if (strcasecmp(c_text,"NOOP")) {
175 if (!strcmp(c_user, fullname)) {
176 color(BRIGHT_YELLOW);
178 else if (!strcmp(c_user,":")) {
184 if (strcmp(c_user,last_user)) {
185 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
188 size_t i = MIN(sizeof buf - 1,
192 safestrncpy(&buf[i], c_text,
195 while (strlen(buf)<79) strcat(buf," ");
196 if (strcmp(c_user,last_user)) {
197 printf("\r%79s\n","");
198 strcpy(last_user,c_user);
200 printf("\r%s\n",buf);
204 color(BRIGHT_YELLOW);
206 recv_complete_line = 0;
213 * send an express message
216 static char last_paged[32] = "";
217 char buf[256], touser[256], msg[256];
220 strcpy(touser, last_paged);
221 strprompt("Page who", touser, 30);
223 /* old server -- use inline paging */
224 if (serv_info.serv_paging_level == 0) {
225 newprompt("Message: ", msg, 69);
226 snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
229 if (!strncmp(buf, "200", 3)) {
230 strcpy(last_paged, touser);
232 printf("%s\n", &buf[4]);
236 /* new server -- use extended paging */
237 else if (serv_info.serv_paging_level >= 1) {
238 snprintf(buf, sizeof buf, "SEXP %s||", touser);
242 printf("%s\n", &buf[4]);
246 if ( make_message(temp, touser, 0, 0, 0) != 0 ) {
247 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, 256, pagefp) != NULL) {
259 buf[strlen(buf)-1] = 0;
264 printf("Message sent.\n");
267 printf("%s\n", &buf[4]);
275 void quiet_mode(void) {
282 printf("%s\n", &buf[4]);
285 qstate = atoi(&buf[4]);
286 if (qstate == 0) qstate = 1;
288 sprintf(buf, "DEXP %d", qstate);
292 printf("%s\n", &buf[4]);
295 qstate = atoi(&buf[4]);
297 printf("Quiet mode enabled (no other users may page you)\n");
300 printf("Quiet mode disabled (other users may page you)\n");