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"
37 #define MIN(a, b) ((a) < (b) ? (a) : (b))
39 extern struct CtdlServInfo serv_info;
41 void citedit(FILE *fp, long int base_pos);
42 void getline(char *, int);
51 int send_complete_line;
52 int recv_complete_line;
63 printf("%s\n",&buf[4]);
67 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
68 set_keepalives(KA_CHAT);
74 send_complete_line = 0;
75 recv_complete_line = 0;
81 FD_SET(getsockfd(),&rfds);
82 tv.tv_sec = S_KEEPALIVE;
84 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
86 if (FD_ISSET(getsockfd(), &rfds)) {
89 recv_complete_line = 1;
90 goto RCL; /* ugly, but we've gotta get out! */
93 buf[strlen(buf) + 1] = 0;
94 buf[strlen(buf)] = ch;
99 if (FD_ISSET(0, &rfds)) {
101 if ((ch == 10) || (ch == 13)) {
102 send_complete_line = 1;
104 else if ((ch == 8) || (ch == 127)) {
105 if (strlen(wbuf) > 0) {
106 wbuf[strlen(wbuf)-1] = 0;
112 wbuf[strlen(wbuf) + 1] = 0;
113 wbuf[strlen(wbuf)] = ch;
118 /* if the user hit return, send the line */
119 RCL: if (send_complete_line) {
122 send_complete_line = 0;
125 /* if it's time to word wrap, send a partial line */
126 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
128 for (a=0; a<strlen(wbuf); ++a) {
129 if (wbuf[a] == 32) pos = a;
134 send_complete_line = 0;
139 strcpy(wbuf,&wbuf[pos+1]);
143 if (recv_complete_line) {
144 printf("\r%79s\r","");
145 if (!strcmp(buf,"000")) {
147 printf("Exiting chat mode\n");
150 set_keepalives(KA_YES);
153 /* Some users complained about the client and server
154 * losing protocol synchronization when exiting chat.
155 * This little dialog forces everything to be
158 serv_puts("ECHO __ExitingChat__");
161 } while (strcmp(buf, "200 __ExitingChat__"));
166 if (num_parms(buf)>=2) {
167 extract(c_user,buf,0);
168 extract(c_text,buf,1);
169 if (num_parms(buf)>2)
171 extract(c_room,buf,2);
172 printf("Got room %s\n", c_room);
175 if (strucmp(c_text,"NOOP")) {
176 if (!strcmp(c_user, fullname)) {
177 color(BRIGHT_YELLOW);
179 else if (!strcmp(c_user,":")) {
185 if (strcmp(c_user,last_user)) {
186 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
189 size_t i = MIN(sizeof buf - 1,
193 safestrncpy(&buf[i], c_text,
196 while (strlen(buf)<79) strcat(buf," ");
197 if (strcmp(c_user,last_user)) {
198 printf("\r%79s\n","");
199 strcpy(last_user,c_user);
201 printf("\r%s\n",buf);
205 color(BRIGHT_YELLOW);
207 recv_complete_line = 0;
214 * send an express message
217 static char last_paged[32] = "";
218 char buf[256], touser[256], msg[256];
221 strcpy(touser, last_paged);
222 strprompt("Page who", touser, 30);
224 /* old server -- use inline paging */
225 if (serv_info.serv_paging_level == 0) {
226 newprompt("Message: ", msg, 69);
227 snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
230 if (!strncmp(buf, "200", 3)) {
231 strcpy(last_paged, touser);
233 printf("%s\n", &buf[4]);
237 /* new server -- use extended paging */
238 else if (serv_info.serv_paging_level >= 1) {
239 snprintf(buf, sizeof buf, "SEXP %s||", touser);
243 printf("%s\n", &buf[4]);
247 printf("Type message to send. Enter a blank line when finished.\n");
248 pagefp = fopen(temp, "w+");
251 fseek(pagefp, 0L, SEEK_END);
252 if ( ftell(pagefp) > 2) {
254 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
258 strcpy(last_paged, touser);
259 while (fgets(buf, 256, pagefp) != NULL) {
260 buf[strlen(buf)-1] = 0;
265 printf("Message sent.\n");
268 printf("%s\n", &buf[4]);
272 printf("No message sent.\n");