summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorIvan Agarkov <i_agarkov@wargaming.net>2020-12-13 21:57:41 +0300
committerAlexander Barton <alex@barton.de>2023-09-16 12:40:33 +0200
commitcfd7d4288ebf55e6b65f33900a9ffac63a6ac6e2 (patch)
treea98260e4462e4741fda6217a036ca2e42fa8a6c3 /src
parent3b70f4ba0c5045772290d159e07d65c95c724670 (diff)
downloadngircd-cfd7d4288ebf55e6b65f33900a9ffac63a6ac6e2.tar.gz
ngircd-cfd7d4288ebf55e6b65f33900a9ffac63a6ac6e2.zip
Channel autojoin functionality
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/channel.c2
-rw-r--r--src/ngircd/conf.c3
-rw-r--r--src/ngircd/conf.h1
-rw-r--r--src/ngircd/login.c31
-rw-r--r--src/ngircd/login.h1
5 files changed, 36 insertions, 2 deletions
diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c
index d47b16f2..03af496b 100644
--- a/src/ngircd/channel.c
+++ b/src/ngircd/channel.c
@@ -186,8 +186,6 @@ Channel_InitPredefined( void )
 		    new_chan->name, new_chan->modes, new_chan->key,
 		    new_chan->maxusers);
 	}
-	if (channel_count)
-		array_free(&Conf_Channels);
 
 	/* Make sure the local &SERVER channel exists */
 	if (!Channel_Search("&SERVER")) {
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 860aea8f..5ee552e6 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -2000,6 +2000,9 @@ Handle_CHANNEL(const char *File, int Line, char *Var, char *Arg)
 			Config_Error_TooLong(File, Line, Var);
 		return;
 	}
+	if( strcasecmp( Var, "Autojoin" ) == 0 )
+		/* Check autojoin */
+		chan->autojoin = Check_ArgIsTrue(Arg);
 	if( strcasecmp( Var, "Key" ) == 0 ) {
 		/* Initial Channel Key (mode k) */
 		len = strlcpy(chan->key, Arg, sizeof(chan->key));
diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h
index 97ce336d..f3e2c5a5 100644
--- a/src/ngircd/conf.h
+++ b/src/ngircd/conf.h
@@ -87,6 +87,7 @@ struct Conf_Channel {
 	char key[CLIENT_PASS_LEN];      /**< Channel key ("password", mode "k" ) */
 	char topic[COMMAND_LEN];	/**< Initial topic */
 	char keyfile[512];		/**< Path and name of channel key file */
+	bool autojoin;			/**< 1 to make all users autojoin this channel */
 	unsigned long maxusers;		/**< User limit for this channel, mode "l" */
 	unsigned int modes_num;		/**< Number of channel modes to evaluate */
 };
diff --git a/src/ngircd/login.c b/src/ngircd/login.c
index 38b9a353..0dd0bd89 100644
--- a/src/ngircd/login.c
+++ b/src/ngircd/login.c
@@ -201,9 +201,40 @@ Login_User_PostAuth(CLIENT *Client)
 	} else
 		IRC_SetPenalty(Client, 1);
 
+  /* Autojoin clients to the channels */
+  Login_Autojoin(Client);
+
 	return CONNECTED;
 }
 
+/**
+ * Autojoin clients to the channels set by administrator
+ * If autojoin is not set in Config or the channel is not available for search - do nothing
+ *
+ **/
+GLOBAL void
+Login_Autojoin(CLIENT *Client)
+{
+	/** make an autojoin to each channel that is good for it **/
+	REQUEST Req;
+	const struct Conf_Channel *conf_chan;
+	size_t i, n, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
+	conf_chan = array_start(&Conf_Channels);
+	assert(channel_count == 0 || conf_chan != NULL);
+
+	for (i = 0; i < channel_count; i++, conf_chan++) {
+		if(!conf_chan->autojoin)
+			continue;
+		if (!Channel_Search(conf_chan->name))
+			continue;
+		Req.prefix = Client_ID(Client_ThisServer());
+		Req.command = "JOIN";
+		Req.argc = 1;
+		Req.argv[0] = conf_chan->name;
+		IRC_JOIN(Client, &Req);
+	}
+}
+
 #ifdef PAM
 
 /**
diff --git a/src/ngircd/login.h b/src/ngircd/login.h
index 6e3a21d6..b5d7be1e 100644
--- a/src/ngircd/login.h
+++ b/src/ngircd/login.h
@@ -19,6 +19,7 @@
 
 GLOBAL bool Login_User PARAMS((CLIENT * Client));
 GLOBAL bool Login_User_PostAuth PARAMS((CLIENT *Client));
+GLOBAL void Login_Autojoin PARAMS((CLIENT *Client));
 
 #endif