4 * client_chat.c -- front end for chat mode
5 * (the "single process" version - no more fork() anymore)
21 #include <sys/types.h>
22 #ifdef HAVE_SYS_SELECT_H
23 #include <sys/select.h>
27 #include "client_chat.h"
31 #include "citadel_decls.h"
39 #define MIN(a, b) ((a) < (b) ? (a) : (b))
41 extern struct CtdlServInfo serv_info;
43 void citedit(FILE *fp, long int base_pos);
44 void getline(char *, int);
53 int send_complete_line;
54 int recv_complete_line;
65 printf("%s\n",&buf[4]);
69 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
70 set_keepalives(KA_CHAT);
76 send_complete_line = 0;
77 recv_complete_line = 0;
83 FD_SET(getsockfd(),&rfds);
84 tv.tv_sec = S_KEEPALIVE;
86 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
88 if (FD_ISSET(getsockfd(), &rfds)) {
91 recv_complete_line = 1;
92 goto RCL; /* ugly, but we've gotta get out! */
95 buf[strlen(buf) + 1] = 0;
96 buf[strlen(buf)] = ch;
101 if (FD_ISSET(0, &rfds)) {
103 if ((ch == 10) || (ch == 13)) {
104 send_complete_line = 1;
106 else if ((ch == 8) || (ch == 127)) {
107 if (strlen(wbuf) > 0) {
108 wbuf[strlen(wbuf)-1] = 0;
114 wbuf[strlen(wbuf) + 1] = 0;
115 wbuf[strlen(wbuf)] = ch;
120 /* if the user hit return, send the line */
121 RCL: if (send_complete_line) {
124 send_complete_line = 0;
127 /* if it's time to word wrap, send a partial line */
128 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
130 for (a=0; a<strlen(wbuf); ++a) {
131 if (wbuf[a] == 32) pos = a;
136 send_complete_line = 0;
141 strcpy(wbuf,&wbuf[pos+1]);
145 if (recv_complete_line) {
146 printf("\r%79s\r","");
147 if (!strcmp(buf,"000")) {
149 printf("Exiting chat mode\n");
152 set_keepalives(KA_YES);
155 /* Some users complained about the client and server
156 * losing protocol synchronization when exiting chat.
157 * This little dialog forces everything to be
160 serv_puts("ECHO __ExitingChat__");
163 } while (strcmp(buf, "200 __ExitingChat__"));
168 if (num_parms(buf)>=2) {
169 extract(c_user,buf,0);
170 extract(c_text,buf,1);
171 if (num_parms(buf)>2)
173 extract(c_room,buf,2);
174 printf("Got room %s\n", c_room);
177 if (strucmp(c_text,"NOOP")) {
178 if (!strcmp(c_user, fullname)) {
179 color(BRIGHT_YELLOW);
181 else if (!strcmp(c_user,":")) {
187 if (strcmp(c_user,last_user)) {
188 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
191 size_t i = MIN(sizeof buf - 1,
195 safestrncpy(&buf[i], c_text,
198 while (strlen(buf)<79) strcat(buf," ");
199 if (strcmp(c_user,last_user)) {
200 printf("\r%79s\n","");
201 strcpy(last_user,c_user);
203 printf("\r%s\n",buf);
207 color(BRIGHT_YELLOW);
209 recv_complete_line = 0;
216 * send an express message
219 static char last_paged[32] = "";
220 char buf[256], touser[256], msg[256];
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]);
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]);
249 if ( make_message(temp, touser, 0, 0, 0) != 0 ) {
250 printf("No message sent.\n");
254 pagefp = fopen(temp, "r");
256 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
260 strcpy(last_paged, touser);
261 while (fgets(buf, 256, pagefp) != NULL) {
262 buf[strlen(buf)-1] = 0;
267 printf("Message sent.\n");
270 printf("%s\n", &buf[4]);