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 if (num_parms(buf)>=2) {
154 extract(c_user,buf,0);
155 extract(c_text,buf,1);
156 if (num_parms(buf)>2)
158 extract(c_room,buf,2);
159 printf("Got room %s\n", c_room);
162 if (strucmp(c_text,"NOOP")) {
163 if (!strcmp(c_user, fullname)) {
164 color(BRIGHT_YELLOW);
166 else if (!strcmp(c_user,":")) {
172 if (strcmp(c_user,last_user)) {
173 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
176 size_t i = MIN(sizeof buf - 1,
180 safestrncpy(&buf[i], c_text,
183 while (strlen(buf)<79) strcat(buf," ");
184 if (strcmp(c_user,last_user)) {
185 printf("\r%79s\n","");
186 strcpy(last_user,c_user);
188 printf("\r%s\n",buf);
192 color(BRIGHT_YELLOW);
194 recv_complete_line = 0;
201 * send an express message
204 static char last_paged[32] = "";
205 char buf[256], touser[256], msg[256];
208 strcpy(touser, last_paged);
209 strprompt("Page who", touser, 30);
211 /* old server -- use inline paging */
212 if (serv_info.serv_paging_level == 0) {
213 newprompt("Message: ", msg, 69);
214 snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
217 if (!strncmp(buf, "200", 3)) {
218 strcpy(last_paged, touser);
220 printf("%s\n", &buf[4]);
224 /* new server -- use extended paging */
225 else if (serv_info.serv_paging_level >= 1) {
226 snprintf(buf, sizeof buf, "SEXP %s||", touser);
230 printf("%s\n", &buf[4]);
234 printf("Type message to send. Enter a blank line when finished.\n");
235 pagefp = fopen(temp, "w+");
238 fseek(pagefp, 0L, SEEK_END);
239 if ( ftell(pagefp) > 2) {
241 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
245 strcpy(last_paged, touser);
246 while (fgets(buf, 256, pagefp) != NULL) {
247 buf[strlen(buf)-1] = 0;
252 printf("Message sent.\n");
255 printf("%s\n", &buf[4]);
259 printf("No message sent.\n");