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 getline(char *, int);
52 int send_complete_line;
53 int recv_complete_line;
64 printf("%s\n",&buf[4]);
68 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
69 set_keepalives(KA_CHAT);
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! */
94 buf[strlen(buf) + 1] = 0;
95 buf[strlen(buf)] = ch;
100 if (FD_ISSET(0, &rfds)) {
102 if ((ch == 10) || (ch == 13)) {
103 send_complete_line = 1;
105 else if ((ch == 8) || (ch == 127)) {
106 if (strlen(wbuf) > 0) {
107 wbuf[strlen(wbuf)-1] = 0;
113 wbuf[strlen(wbuf) + 1] = 0;
114 wbuf[strlen(wbuf)] = ch;
119 /* if the user hit return, send the line */
120 RCL: if (send_complete_line) {
123 send_complete_line = 0;
126 /* if it's time to word wrap, send a partial line */
127 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
129 for (a=0; a<strlen(wbuf); ++a) {
130 if (wbuf[a] == 32) pos = a;
135 send_complete_line = 0;
140 strcpy(wbuf,&wbuf[pos+1]);
144 if (recv_complete_line) {
145 printf("\r%79s\r","");
146 if (!strcmp(buf,"000")) {
148 printf("Exiting chat mode\n");
151 set_keepalives(KA_YES);
154 /* Some users complained about the client and server
155 * losing protocol synchronization when exiting chat.
156 * This little dialog forces everything to be
159 serv_puts("ECHO __ExitingChat__");
162 } while (strcmp(buf, "200 __ExitingChat__"));
167 if (num_parms(buf)>=2) {
168 extract(c_user,buf,0);
169 extract(c_text,buf,1);
170 if (num_parms(buf)>2)
172 extract(c_room,buf,2);
173 printf("Got room %s\n", c_room);
176 if (strucmp(c_text,"NOOP")) {
177 if (!strcmp(c_user, fullname)) {
178 color(BRIGHT_YELLOW);
180 else if (!strcmp(c_user,":")) {
186 if (strcmp(c_user,last_user)) {
187 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
190 size_t i = MIN(sizeof buf - 1,
194 safestrncpy(&buf[i], c_text,
197 while (strlen(buf)<79) strcat(buf," ");
198 if (strcmp(c_user,last_user)) {
199 printf("\r%79s\n","");
200 strcpy(last_user,c_user);
202 printf("\r%s\n",buf);
206 color(BRIGHT_YELLOW);
208 recv_complete_line = 0;
215 * send an express message
218 static char last_paged[32] = "";
219 char buf[256], touser[256], msg[256];
222 strcpy(touser, last_paged);
223 strprompt("Page who", touser, 30);
225 /* old server -- use inline paging */
226 if (serv_info.serv_paging_level == 0) {
227 newprompt("Message: ", msg, 69);
228 snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
231 if (!strncmp(buf, "200", 3)) {
232 strcpy(last_paged, touser);
234 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]);
248 if ( make_message(temp, touser, 0, 0, 0) != 0 ) {
249 printf("No message sent.\n");
253 pagefp = fopen(temp, "r");
255 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
259 strcpy(last_paged, touser);
260 while (fgets(buf, 256, pagefp) != NULL) {
261 buf[strlen(buf)-1] = 0;
266 printf("Message sent.\n");
269 printf("%s\n", &buf[4]);