shithub: ircs

Download patch

ref: 5479f0fb4283ca4a5a58c9b7b50c5b86bde13aa1
parent: 78db7421d889f5af90135445bbdd996a5243e07d
author: kemal <kemalinanc8@gmail.com>
date: Mon Nov 15 04:50:49 EST 2021

ircs: simplify option handling, rejoin into channels after server welcomes us

--- a/main.c
+++ b/main.c
@@ -47,7 +47,7 @@
 int mainstacksize = Stacksize;
 char *logdir;
 
-static char *service;
+static char *service = "ircs";
 
 static char *post;
 static char *file;
@@ -315,6 +315,24 @@
 }
 
 static void
+rejoin(void)
+{
+	Triewalk w;
+	Rune key[64];
+	Ch *c;
+	long t;
+	char buf[Bufsize];
+
+	t = time(0);
+	triewalk(channels, &w, key, nelem(key));
+	while((c = trienext(&w)) != nil){
+		snprint(buf, sizeof(buf), "JOIN %s", c->name);
+		logsend(buf, t, &mainlog);
+		ircsend(buf);
+	}
+}
+
+static void
 partmsg(Ircmsg *irc, char *msg, long time)
 {
 	Ch *c;
@@ -500,6 +518,8 @@
 		target = irc.par[0];
 	} else if(strcmp(irc.cmd, "001") == 0){
 		/* welcome */
+		if(state == Reconnok)
+			rejoin();
 		sendul(ctlc, Ok);
 	} else if(strcmp(irc.cmd, "433") == 0){
 		/* nick in use */
@@ -766,24 +786,6 @@
 }
 
 static void
-rejoin(void)
-{
-	Triewalk w;
-	Rune key[64];
-	Ch *c;
-	long t;
-	char buf[Bufsize];
-
-	t = time(0);
-	triewalk(channels, &w, key, nelem(key));
-	while((c = trienext(&w)) != nil){
-		snprint(buf, sizeof(buf), "JOIN %s", c->name);
-		logsend(buf, t, &mainlog);
-		ircsend(buf);
-	}
-}
-
-static void
 reconnproc(void *)
 {
 	int c, i;
@@ -848,7 +850,6 @@
 			break;
 		case Reconnok:
 			state = Reconnok;
-			rejoin();
 			threadcreate(ircin, ioproc(), Stacksize);
 			break;
 		case Pipeend:
@@ -964,9 +965,11 @@
 		break;
 	case 'f':
 		file = EARGF(usage());
+		userdb = 0;
 		break;
 	case 'p':
 		passwd++;
+		usetls++;
 		break;
 	case 'r':
 		rawlog++;
@@ -986,18 +989,6 @@
 
 	if(argc != 2)
 		usage();
-
-	if(passwd && !usetls){
-		fprint(2, "-p requires -e, exiting\n");
-		threadexits("passwd");
-	}
-	if(file != nil)
-		userdb = 0;
-
-	if(service == nil)
-		service = "ircs";
-	else if(*service == 0)
-		sysfatal("empty srvname");
 
 	setnickuser(argv[0]);
 	addr = argv[1];