Add PASS option

WEBIRC is now -W.
master
Curtis McEnroe 2018-08-09 18:26:53 -04:00
parent dbdf13b51a
commit d1fea96e86
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 18 additions and 8 deletions

10
chat.c
View File

@ -55,17 +55,19 @@ static char *prompt(const char *prompt) {
int main(int argc, char *argv[]) {
char *host = NULL;
const char *port = "6697";
const char *webPass = NULL;
const char *pass = NULL;
const char *webirc = NULL;
int opt;
while (0 < (opt = getopt(argc, argv, "h:j:n:p:vw:"))) {
while (0 < (opt = getopt(argc, argv, "W:h:j:n:p:vw:"))) {
switch (opt) {
break; case 'W': webirc = optarg;
break; case 'h': host = strdup(optarg);
break; case 'j': chat.chan = strdup(optarg);
break; case 'n': chat.nick = strdup(optarg);
break; case 'p': port = optarg;
break; case 'v': chat.verbose = true;
break; case 'w': webPass = optarg;
break; case 'w': pass = optarg;
break; default: return EX_USAGE;
}
}
@ -82,7 +84,7 @@ int main(int argc, char *argv[]) {
uiLog(L"Traveling...");
uiDraw();
int sock = ircConnect(host, port, webPass);
int sock = ircConnect(host, port, pass, webirc);
free(host);
struct pollfd fds[2] = {

4
chat.h
View File

@ -41,7 +41,9 @@ enum {
IRC_UNDERLINE = 037,
};
int ircConnect(const char *host, const char *port, const char *webPass);
int ircConnect(
const char *host, const char *port, const char *pass, const char *webPass
);
void ircRead(void);
void ircWrite(const char *ptr, size_t len);

12
irc.c
View File

@ -43,7 +43,9 @@ static void webirc(const char *pass) {
);
}
int ircConnect(const char *host, const char *port, const char *webPass) {
int ircConnect(
const char *host, const char *port, const char *pass, const char *webPass
) {
int error;
struct tls_config *config = tls_config_new();
@ -80,8 +82,12 @@ int ircConnect(const char *host, const char *port, const char *webPass) {
if (error) err(EX_PROTOCOL, "tls_connect");
if (webPass) webirc(webPass);
ircFmt("NICK %s\r\n", chat.nick);
ircFmt("USER %s 0 * :%s\r\n", chat.user, chat.nick);
if (pass) ircFmt("PASS :%s\r\n", pass);
ircFmt(
"NICK %s\r\n"
"USER %s 0 * :%s\r\n",
chat.nick, chat.user, chat.nick
);
return sock;
}