Commits

Anonymous committed a9098ff

added autojoin and nickserv auth

  • Participants
  • Parent commits 011fab8

Comments (0)

Files changed (1)

 static char channel[256];
 static char *host;
 
+static int auth_nickserv = 0;
+static char *password = NULL;
+static char *autojoin = NULL;
+
 static void irc_display(const char *fmt, ...);
 
 #include "config.h"
 	} else if (strcmp("PING", cmd) == 0) {
 		irc_send("PONG %s", msg);
 	} else {
+		char *endptr;
+		int id;
+		id = strtol(cmd, &endptr, 10);
+		if (id == 1) { 
+			/* first response from server: try to authenicate
+			 * and join channel */
+			if (auth_nickserv && password != NULL) {
+				irc_send("PRIVMSG NickServ IDENTIFY %s", password);
+			}
+			if (autojoin != NULL) {
+				irc_send("JOIN %s", autojoin);
+				strncpy(channel, autojoin, sizeof(channel));
+			}
+		}
 		server_message(usr, cmd, arg, msg);
 	}
 }
 				nick = optarg;
 				break;
 			case 'j':
-				/* TODO: set auto-join channel */
+				autojoin = optarg;
 				break;
 			case 'k':
-				/* TODO: set password */
+				password = optarg;
 				break;
 			case 'N':
-				/* TODO: use NickServ */
+				auth_nickserv = 1;
 				break;
 			case 'h':
 			default:
 		nick = whoami();
 	}
 
+	if(auth_nickserv == 0 && password) {
+		irc_send("PASS %s", password);
+	}
 	irc_send("NICK %s", nick);
 	irc_send("USER %s localhost %s :%s", nick, host, nick);