diff --git a/main.cc b/main.cc index dbbf36e..221b9e8 100644 --- a/main.cc +++ b/main.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -25,4 +26,65 @@ main(int argc, char *argv[]) use_default_colors(); line_position = count_lines(log_path) - LOG_LENGTH + 1; + + switch (mode) { + case CLIENT_MODE: + log_append(log_path, "CLIENT MODE"); + client_start(); + break; + case SERVER_MODE: + log_append(log_path, "SERVER MODE"); + server_start(listen_port); + break; + default: + goto panic_no_mode; + break; + } + + while (!quit) { + file_disp(log_path, line_position, LOG_LENGTH); + + if (count_lines(log_path) > LOG_LENGTH) + line_position++; + + /* prompt for input */ + move(12, 0); + printw("> "); + + /* await input */ + getstr(usr_in); + log_append(log_path, usr_in); + send(socket_descriptor_client, (char *)usr_in, strlen(usr_in), 0); + } + + /* Final exit point if everything goes OK */ + + endwin(); + + switch (mode) { + case CLIENT_MODE: + client_stop(); + break; + case SERVER_MODE: + server_stop(); + break; + default: + goto panic_no_mode; + break; + } + + return 0; + +panic_no_mode: + fprintf(stderr, "-----FATAL ERROR, THIS SHOULD NEVER HAPPEN-----\n"); + fprintf(stderr, "You may ask yourself... how do I work this?\n"); + fprintf(stderr, "And you may find yourself... past the point of return 0;!\n"); + fprintf(stderr, "And you may ask yourself... well, how did I get here?\n"); + + if (mode == NO_MODE) + fprintf(stderr, "Fatal: Mode was not set!\n"); + else + fprintf(stderr, "Fatal: Mode was set to invalid enum %i\n", mode); + + return 1; }