4 * client_chat.c -- front end for chat mode
5 * (the "single process" version - no more fork() anymore)
19 #include <sys/types.h>
21 #include <sys/select.h>
25 extern char fullname[];
28 void set_keepalives();
44 int send_complete_line;
45 int recv_complete_line;
56 printf("%s\n",&buf[4]);
60 printf("Entering chat mode (type /quit to exit, /help for other cmds)\n");
61 set_keepalives(KA_CHAT);
67 send_complete_line = 0;
68 recv_complete_line = 0;
74 FD_SET(getsockfd(),&rfds);
75 tv.tv_sec = S_KEEPALIVE;
77 retval = select(getsockfd()+1, &rfds, NULL, NULL, &tv);
79 if (FD_ISSET(getsockfd(), &rfds)) {
82 recv_complete_line = 1;
83 goto RCL; /* ugly, but we've gotta get out! */
86 buf[strlen(buf) + 1] = 0;
87 buf[strlen(buf)] = ch;
92 if (FD_ISSET(0, &rfds)) {
94 if ((ch == 10) || (ch == 13)) {
95 send_complete_line = 1;
97 else if ((ch == 8) || (ch == 127)) {
98 if (strlen(wbuf) > 0) {
99 wbuf[strlen(wbuf)-1] = 0;
105 wbuf[strlen(wbuf) + 1] = 0;
106 wbuf[strlen(wbuf)] = ch;
111 /* if the user hit return, send the line */
112 RCL: if (send_complete_line) {
115 send_complete_line = 0;
118 /* if it's time to word wrap, send a partial line */
119 if ( strlen(wbuf) >= (77-strlen(fullname)) ) {
121 for (a=0; a<strlen(wbuf); ++a) {
122 if (wbuf[a] == 32) pos = a;
127 send_complete_line = 0;
132 strcpy(wbuf,&wbuf[pos+1]);
136 if (recv_complete_line) {
137 printf("\r%79s\r","");
138 if (!strcmp(buf,"000")) {
140 printf("Exiting chat mode\n");
143 set_keepalives(KA_YES);
146 if (num_parms(buf)>=2) {
147 extract(c_user,buf,0);
148 extract(c_text,buf,1);
149 if (num_parms(buf)>2)
151 extract(c_room,buf,2);
152 printf("Got room %s\n", c_room);
155 if (strucmp(c_text,"NOOP")) {
156 if (!strcmp(c_user, fullname)) {
159 else if (!strcmp(c_user,":")) {
165 if (strcmp(c_user,last_user)) {
166 sprintf(buf,"%s: %s",c_user,c_text);
169 sprintf(buf,"%40s","");
170 sprintf(&buf[strlen(c_user)+2],
173 while (strlen(buf)<79) strcat(buf," ");
174 if (strcmp(c_user,last_user)) {
175 printf("\r%79s\n","");
176 strcpy(last_user,c_user);
178 printf("\r%s\n",buf);
184 recv_complete_line = 0;