summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-06-15 20:56:58 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-06-15 20:56:58 +0000
commitcf75515274e9d20c48a2d40300981e7f2c5a0726 (patch)
tree41ccd9641e6c5f4e9ca088eb2fc87446860bf4fe
parent91396de7403c8d6080307ea529d84b5b381d80f9 (diff)
downloadirssi-cf75515274e9d20c48a2d40300981e7f2c5a0726.zip
You can specify command(s) to be sent automatically to server after
connected with /IRCNET -autosendcmd. Useful for IRC networks with NickServ. Patch by <Tommi.Komulainen@iki.fi> Ability to send a command automatically to server IRC network git-svn-id: http://svn.irssi.org/repos/irssi/trunk@354 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r--docs/manual.txt9
-rw-r--r--src/fe-common/irc/fe-ircnet.c13
-rw-r--r--src/irc/core/ircnet-setup.c17
-rw-r--r--src/irc/core/ircnet-setup.h1
4 files changed, 35 insertions, 5 deletions
diff --git a/docs/manual.txt b/docs/manual.txt
index 1134f539..da5a4f9c 100644
--- a/docs/manual.txt
+++ b/docs/manual.txt
@@ -363,7 +363,7 @@
/IRCNET ADD [-kicks <count>] [-msgs <count>] [-modes <count>]
[-whois <count>] [-cmdspeed <ms>] [-cmdmax <count>]
[-nick <nick>] [-user <user>] [-realname <name>]
- [-host <host>] <name>
+ [-host <host>] [-autosendcmd <cmd>] <name>
-kicks: Maximum number of nicks in one /KICK command
-msgs: Maximum number of nicks in one /MSG command
@@ -373,6 +373,13 @@
-cmdmax: Same as /SET cmd_max_at_once, see section 3.1
-nick, -user, -realname: Specify what nick/user/name to use
-host: Specify what host name to use, if you have multiple
+ -autosendcmd: Command to send after connecting to a server
+
+ With -autosendcmd argument you can automatically run any commands
+ after connecting to ircnet. This is useful for automatically
+ identifying yourself to NickServ, for example
+
+ /IRCNET ADD -autosendcmd "/msg NickServ identify secret" OPN
/IRCNET REMOVE <name>
diff --git a/src/fe-common/irc/fe-ircnet.c b/src/fe-common/irc/fe-ircnet.c
index 2ebbc3af..88e1d806 100644
--- a/src/fe-common/irc/fe-ircnet.c
+++ b/src/fe-common/irc/fe-ircnet.c
@@ -52,6 +52,8 @@ static void cmd_ircnet_list(void)
g_string_sprintfa(str, "realname: %s, ", rec->realname);
if (rec->own_host != NULL)
g_string_sprintfa(str, "host: %s, ", rec->own_host);
+ if (rec->autosendcmd != NULL)
+ g_string_sprintfa(str, "autosendcmd: %s, ", rec->autosendcmd);
if (rec->cmd_queue_speed > 0)
g_string_sprintfa(str, "cmdspeed: %d, ", rec->cmd_queue_speed);
@@ -78,13 +80,14 @@ static void cmd_ircnet_list(void)
static void cmd_ircnet_add(const char *data)
{
char *params, *args, *kicks, *msgs, *modes, *whois;
- char *cmdspeed, *cmdmax, *nick, *user, *realname, *host, *name;
+ char *cmdspeed, *cmdmax, *nick, *user, *realname, *host, *autosendcmd, *name;
IRCNET_REC *rec;
- args = "kicks msgs modes whois cmdspeed cmdmax nick user realname host";
- params = cmd_get_params(data, 12 | PARAM_FLAG_MULTIARGS, &args,
+ args = "kicks msgs modes whois cmdspeed cmdmax nick user realname host autosendcmd";
+ params = cmd_get_params(data, 13 | PARAM_FLAG_MULTIARGS, &args,
&kicks, &msgs, &modes, &whois, &cmdspeed,
- &cmdmax, &nick, &user, &realname, &host, &name);
+ &cmdmax, &nick, &user, &realname, &host,
+ &autosendcmd, &name);
if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
rec = ircnet_find(name);
@@ -99,6 +102,7 @@ static void cmd_ircnet_add(const char *data)
g_free_and_null(rec->own_host);
rec->own_ip = NULL;
}
+ if (stristr(args, "-autosendcmd")) g_free_and_null(rec->autosendcmd);
}
if (stristr(args, "-kicks")) rec->max_kicks = atoi(kicks);
@@ -116,6 +120,7 @@ static void cmd_ircnet_add(const char *data)
rec->own_host = g_strdup(host);
rec->own_ip = NULL;
}
+ if (*autosendcmd != '\0') rec->autosendcmd = g_strdup(autosendcmd);
ircnet_create(rec);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IRCNET_ADDED, name);
diff --git a/src/irc/core/ircnet-setup.c b/src/irc/core/ircnet-setup.c
index bd913705..57cfab1a 100644
--- a/src/irc/core/ircnet-setup.c
+++ b/src/irc/core/ircnet-setup.c
@@ -26,6 +26,7 @@
#include "irc-server.h"
#include "ircnet-setup.h"
+#include "special-vars.h"
GSList *ircnets; /* list of available ircnets */
@@ -41,6 +42,7 @@ static void ircnet_config_add(IRCNET_REC *ircnet)
iconfig_node_set_str(node, "username", ircnet->username);
iconfig_node_set_str(node, "realname", ircnet->realname);
iconfig_node_set_str(node, "host", ircnet->own_host);
+ iconfig_node_set_str(node, "autosendcmd", ircnet->autosendcmd);
if (ircnet->max_cmds_at_once > 0)
config_node_set_int(node, "cmdmax", ircnet->max_cmds_at_once);
@@ -84,6 +86,7 @@ void ircnet_destroy(IRCNET_REC *ircnet)
g_free_not_null(ircnet->username);
g_free_not_null(ircnet->realname);
g_free_not_null(ircnet->own_host);
+ g_free_not_null(ircnet->autosendcmd);
g_free(ircnet);
}
@@ -118,6 +121,7 @@ static IRCNET_REC *ircnet_add(CONFIG_NODE *node)
rec->username = g_strdup(config_node_get_str(node, "username", NULL));
rec->realname = g_strdup(config_node_get_str(node, "realname", NULL));
rec->own_host = g_strdup(config_node_get_str(node, "host", NULL));
+ rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));
rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
@@ -147,10 +151,22 @@ static void read_ircnets(void)
}
}
+static void sig_connected(IRC_SERVER_REC *server)
+{
+ IRCNET_REC *ircnet;
+
+ if (server->connrec->ircnet == NULL) return;
+
+ ircnet = ircnet_find(server->connrec->ircnet);
+ if (ircnet->autosendcmd)
+ eval_special_string(ircnet->autosendcmd, "", server, NULL);
+}
+
void ircnets_setup_init(void)
{
read_ircnets();
signal_add("setup reread", (SIGNAL_FUNC) read_ircnets);
+ signal_add("event connected", (SIGNAL_FUNC) sig_connected);
}
void ircnets_setup_deinit(void)
@@ -159,4 +175,5 @@ void ircnets_setup_deinit(void)
ircnet_destroy(ircnets->data);
signal_remove("setup reread", (SIGNAL_FUNC) read_ircnets);
+ signal_remove("event connected", (SIGNAL_FUNC) sig_connected);
}
diff --git a/src/irc/core/ircnet-setup.h b/src/irc/core/ircnet-setup.h
index 2b82f171..8339cc07 100644
--- a/src/irc/core/ircnet-setup.h
+++ b/src/irc/core/ircnet-setup.h
@@ -9,6 +9,7 @@ typedef struct {
char *realname;
char *own_host; /* address to use when connecting this server */
+ char *autosendcmd; /* command to send after connecting to this ircnet */
IPADDR *own_ip; /* resolved own_address if not NULL */
int max_cmds_at_once;