X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=src%2Fttt-curses-client.c;h=25d724acf428a8680b9ad0af55629474ced6a076;hb=ea0446f90218c7c4d7f0296265039036a9fb2740;hp=23cd7d770f8f5696c444073dd7282bfaeed717ec;hpb=17914ca9aa3362737a3c860f02965eaac7c6df8a;p=ttt diff --git a/src/ttt-curses-client.c b/src/ttt-curses-client.c index 23cd7d7..25d724a 100644 --- a/src/ttt-curses-client.c +++ b/src/ttt-curses-client.c @@ -21,10 +21,6 @@ /* TODO: see /usr/share/doc/ncurses-devel-5.3/test/view.c for example code * to handle window resizing - * - * add code to read username from config file or prompt user if config - * file does not exist. (username is currently hardcoded and needs - * changed before compiling) * */ @@ -124,7 +120,7 @@ main (int argc, char **argv) int _socket; char buffer[BUFSIZ]; char inplin[1024]; - + ttt_status_t status; static WINDOW *mainwnd; static WINDOW *dispwin; @@ -144,7 +140,7 @@ main (int argc, char **argv) refresh (); dispwin = newwin (dlines - 5, cols - 2, 0, 0); statwin = newwin (4, cols - 2, dlines -3, 0); - inpwin = newwin (1, cols - 2, dlines, 0); + inpwin = newwin (2, cols - 2, dlines, 0); keypad (mainwnd, TRUE); // enable keyboard mapping keypad (inpwin, TRUE); // enable keyboard mapping nodelay (inpwin, TRUE); @@ -181,12 +177,6 @@ main (int argc, char **argv) wrefresh (dispwin); wrefresh (inpwin); - - ttt_socket_create_client (host, port, &_socket); - sockin=fdopen(_socket,"r"); - sockout=fdopen(_socket,"w"); - - xasprintf(&confpath,"%s/.ttt/",getenv("HOME")); xasprintf(&conffile,"%s/.ttt/client.conf",getenv("HOME")); username="user"; @@ -204,17 +194,30 @@ main (int argc, char **argv) } if ((conf_file = fopen(conffile,"r")) != NULL) { while (fgets(buffer,BUFSIZ,conf_file)) { + if (buffer[strlen(buffer)-1] == 10) buffer[strlen(buffer)-1] = '\0'; if (strncmp(buffer,"username=",9) == 0) { xasprintf (&username, "%s", &buffer[9]); - break; + } + if (strncmp(buffer,"port=",5) == 0) { + xasprintf (&port, "%s",&buffer[5]); } } fclose(conf_file); } + status=ttt_socket_create_client (host, port, &_socket); + if (status) { + endwin(); + printf("Unable to connect to server! Connection status: %d\n",status); + exit(1); + } + sockin=fdopen(_socket,"r"); + sockout=fdopen(_socket,"w"); + + fprintf(sockout, "HELO %s\r\n",username); fflush(sockout); - + if (fgets(buffer,BUFSIZ,sockin)) { if ((strncmp(buffer,"NOTICE MESSAGE ",15) == 0) && (strlen(buffer) > 15)) { wprint (dispwin, buffer); @@ -225,6 +228,10 @@ main (int argc, char **argv) wrefresh (dispwin); wrefresh (statwin); } + + fprintf(sockout, "WHO \r\n"); + fflush(sockout); + inplin[0]='\0'; while (1) { curs_set (1); @@ -237,14 +244,27 @@ main (int argc, char **argv) break; case 8: inplin[strlen(inplin)-1]='\0'; - wmove(inpwin,0,strlen(inplin)); - wclrtoeol(inpwin); + wmove (inpwin,0,strlen(inplin)); + wclrtoeol( inpwin); + wrefresh (inpwin); + break; + case 127: + inplin[strlen(inplin)-1]='\0'; + wmove (inpwin,0,strlen(inplin)); + wclrtoeol (inpwin); + wrefresh (inpwin); + break; + case 263: + inplin[strlen(inplin)-1]='\0'; + wmove (inpwin,0,strlen(inplin)); + wclrtoeol (inpwin); + wrefresh (inpwin); break; default: sprintf (inplin,"%s%c",inplin,(int) c); waddch (inpwin, c); + wrefresh (inpwin); } - wrefresh (inpwin); } if (fgets(buffer,BUFSIZ,sockin)) { @@ -261,7 +281,12 @@ main (int argc, char **argv) } if (((int) c == 13) || ((int) c == 10)) { curs_set (0); - fprintf(sockout,"MESSAGE \"%s\"\r\n",inplin); + if (inplin[0] == '/') { + fprintf(sockout,"%s\r\n",&inplin[1]); + } + else { + fprintf(sockout,"MESSAGE \"%s\"\r\n",inplin); + } fflush(sockout); inplin[0] = '\0'; if (fgets(buffer,BUFSIZ,sockin)) {