From 9e48d5aa47acf3cf315da7b863f74e4d5acca7a6 Mon Sep 17 00:00:00 2001 From: mcpcpc Date: Sat, 8 Aug 2020 00:28:35 -0400 Subject: add password argument --- README | 13 ++++++++++++- kirc.c | 23 ++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/README b/README index 324a771..0245fa9 100644 --- a/README +++ b/README @@ -11,6 +11,16 @@ result is a portable <250 sloc application that has no dependencies other than a C99 compiler. +TODO +---- + +- [ ] capture CTRL-C for safer child process shutdown +- [ ] better color default color scheme +- [ ] dynamic word wrap based on column width +- [ ] additional shortcut keys +- [ ] fix default arrow key and backspace behavior + + FEATURES -------- @@ -35,10 +45,11 @@ Building and installing from source: USAGE ----- -usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-v|V] +usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-k password] [-v|V] -s server address (default: 'irc.freenode.org') -p server port (default: '6667') -c channel name (default: '#kisslinux') -n user nickname +-n user password -v version information -V verbose output (e.g. raw stream) diff --git a/kirc.c b/kirc.c index 9fe65b9..588f3ee 100644 --- a/kirc.c +++ b/kirc.c @@ -22,9 +22,11 @@ static char *host = "irc.freenode.org"; /* irc host address */ static char *chan = "kisslinux"; /* channel */ static char *port = "6667"; /* port */ static char *nick = NULL; /* nickname */ +static char *pass = NULL; /* password */ static int kbhit(void) { + int byteswaiting; struct termios term; fd_set fds; @@ -45,6 +47,7 @@ kbhit(void) { static void raw(char *fmt, ...) { + va_list ap; va_start(ap, fmt); @@ -58,6 +61,7 @@ raw(char *fmt, ...) { static void con(void) { + struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_socktype = SOCK_STREAM @@ -69,6 +73,7 @@ con(void) { if (nick) raw("NICK %s\r\n", nick); if (nick) raw("USER %s - - :%s\r\n", nick, nick); + if (pass) raw("PASS %s\r\n", pass); fcntl(conn, F_SETFL, O_NONBLOCK); } @@ -83,13 +88,17 @@ printw(const char *format, ...) { va_start(argptr, format); vsnprintf(line, BUFF + 1, format, argptr); va_end(argptr); + if (strlen(line) <= CMAX) printf("%s", line); else if (strlen(line) > CMAX) { + for (i = 0; i < CMAX; i++) { if (line[i] == ' ') s1 = i; if (i == CMAX - 1) printf("%-*.*s\n", s1, s1, line); } + s2 = o = s1; + for (i = s1; line[i] != '\0'; i++) { if (line[i] == ' ') s2 = i; if ((i - o) == (CMAX - GUTL)) { @@ -141,8 +150,7 @@ pars(int sl, char *buf) { GUTL, GUTL, "-->", nic, cha); } else { - printw("\x1b[1m%*.*s\x1b[0m %s\n", \ - GUTL, GUTL, nic, msg); + printw("\x1b[1m%*.*s\x1b[0m %s\n", GUTL, GUTL, nic, msg); } } } @@ -157,11 +165,12 @@ main(int argc, char **argv) { while ((cval = getopt(argc, argv, "s:p:n:k:c:vV")) != -1) { switch (cval) { case 'v' : printf("kirc 0.0.1\n"); break; - case 'V' : verb = 1; break; - case 's' : host = optarg; break; - case 'p' : port = optarg; break; - case 'n' : nick = optarg; break; - case 'c' : chan = optarg; break; + case 'V' : verb = 1; break; + case 's' : host = optarg; break; + case 'p' : port = optarg; break; + case 'n' : nick = optarg; break; + case 'k' : pass = optarg; break; + case 'c' : chan = optarg; break; case '?' : return 1; } } -- cgit v1.2.3