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>
26 #include "client_chat.h"
30 #include "citadel_decls.h"
33 #define MIN(a, b) ((a) < (b) ? (a) : (b))
35 extern struct CtdlServInfo serv_info;
37 void citedit(FILE *fp, long int base_pos);
38 void getline(char *, int);
47 int send_complete_line;
48 int recv_complete_line;
59 printf("%s\n",&buf[4]);
63 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
64 set_keepalives(KA_CHAT);
70 send_complete_line = 0;
71 recv_complete_line = 0;
77 FD_SET(getsockfd(),&rfds);
78 tv.tv_sec = S_KEEPALIVE;
80 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
82 if (FD_ISSET(getsockfd(), &rfds)) {
85 recv_complete_line = 1;
86 goto RCL; /* ugly, but we've gotta get out! */
89 buf[strlen(buf) + 1] = 0;
90 buf[strlen(buf)] = ch;
95 if (FD_ISSET(0, &rfds)) {
97 if ((ch == 10) || (ch == 13)) {
98 send_complete_line = 1;
100 else if ((ch == 8) || (ch == 127)) {
101 if (strlen(wbuf) > 0) {
102 wbuf[strlen(wbuf)-1] = 0;
108 wbuf[strlen(wbuf) + 1] = 0;
109 wbuf[strlen(wbuf)] = ch;
114 /* if the user hit return, send the line */
115 RCL: if (send_complete_line) {
118 send_complete_line = 0;
121 /* if it's time to word wrap, send a partial line */
122 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
124 for (a=0; a<strlen(wbuf); ++a) {
125 if (wbuf[a] == 32) pos = a;
130 send_complete_line = 0;
135 strcpy(wbuf,&wbuf[pos+1]);
139 if (recv_complete_line) {
140 printf("\r%79s\r","");
141 if (!strcmp(buf,"000")) {
143 printf("Exiting chat mode\n");
146 set_keepalives(KA_YES);
149 if (num_parms(buf)>=2) {
150 extract(c_user,buf,0);
151 extract(c_text,buf,1);
152 if (num_parms(buf)>2)
154 extract(c_room,buf,2);
155 printf("Got room %s\n", c_room);
158 if (strucmp(c_text,"NOOP")) {
159 if (!strcmp(c_user, fullname)) {
162 else if (!strcmp(c_user,":")) {
168 if (strcmp(c_user,last_user)) {
169 snprintf(buf,sizeof buf,"%s: %s",c_user,c_text);
172 size_t i = MIN(sizeof buf - 1,
176 safestrncpy(&buf[i], c_text,
179 while (strlen(buf)<79) strcat(buf," ");
180 if (strcmp(c_user,last_user)) {
181 printf("\r%79s\n","");
182 strcpy(last_user,c_user);
184 printf("\r%s\n",buf);
190 recv_complete_line = 0;
197 * send an express message
200 static char last_paged[32] = "";
201 char buf[256], touser[256], msg[256];
205 strcpy(touser, last_paged);
206 strprompt("Page who", touser, 30);
208 /* old server -- use inline paging */
209 if (serv_info.serv_paging_level == 0) {
210 newprompt("Message: ",msg,69);
211 snprintf(buf,sizeof buf,"SEXP %s|%s",touser,msg);
214 if (!strncmp(buf, "200", 3)) {
215 strcpy(last_paged, touser);
217 printf("%s\n", &buf[4]);
221 /* new server -- use extended paging */
222 else if (serv_info.serv_paging_level >= 1) {
223 snprintf(buf, sizeof buf, "SEXP %s||", touser);
227 printf("%s\n", &buf[4]);
231 printf("Type message to send. Enter a blank line when finished.\n");
232 memset(longmsg, 0, sizeof longmsg);
233 for (i=0; i<5; ++i) {
235 getline(&longmsg[i][0], 77);
236 if (strlen(&longmsg[i][0])==0) i=5;
238 snprintf(buf, sizeof buf, "SEXP %s|-", touser);
242 strcpy(last_paged, touser);
244 if (strlen(&longmsg[i][0])>0)
245 serv_puts(&longmsg[i][0]);
247 printf("Message sent.\n");
250 printf("%s\n", &buf[4]);