diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/command.c | 82 | ||||
-rw-r--r-- | src/config.c | 19 | ||||
-rw-r--r-- | src/irc/irc-commands.c | 9 | ||||
-rw-r--r-- | src/irc/irc-server.c | 18 | ||||
-rw-r--r-- | src/irc/irc.h | 4 | ||||
-rw-r--r-- | weechat/ChangeLog | 1 | ||||
-rw-r--r-- | weechat/src/command.c | 82 | ||||
-rw-r--r-- | weechat/src/config.c | 19 | ||||
-rw-r--r-- | weechat/src/irc/irc-commands.c | 9 | ||||
-rw-r--r-- | weechat/src/irc/irc-server.c | 18 | ||||
-rw-r--r-- | weechat/src/irc/irc.h | 4 |
12 files changed, 222 insertions, 44 deletions
@@ -5,6 +5,7 @@ ChangeLog - 2003-10-04 Version 0.0.2 (under dev!): + * command & auto-join channels when connected to server * new commands for alias: /alias, /unalias (new section in config file) * config is now saved automatically when quitting WeeChat, /save command added * new commands for servers: /server, /connect, /disconnect diff --git a/src/command.c b/src/command.c index 692b8e1af..deaca0c10 100644 --- a/src/command.c +++ b/src/command.c @@ -59,7 +59,8 @@ t_weechat_command weechat_commands[] = { "server", N_("list, add or remove servers"), N_("[list] | " "[servername hostname port [-auto | -noauto] [-pwd password] [-nicks nick1 " - "[nick2 [nick3]]] [-username username] [-realname realname]] | " + "[nick2 [nick3]]] [-username username] [-realname realname] " + "[-command command] [-autojoin channel[,channel]] ] | " "[del servername]"), N_("servername: server name, for internal & display use\n" "hostname: name or IP address of server\n" @@ -491,15 +492,17 @@ int exec_weechat_command (t_irc_server *server, char *string) { int i, j, argc, return_code, length1, length2; - char *pos, *ptr_args, **argv, *alias_command; + char *command, *pos, *ptr_args, **argv, *alias_command; t_weechat_alias *ptr_alias; if ((!string[0]) || (string[0] != '/')) return 0; + command = strdup (string); + /* look for end of command */ ptr_args = NULL; - pos = strchr (string, ' '); + pos = strchr (command, ' '); if (pos) { pos[0] = '\0'; @@ -515,7 +518,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (i = 0; weechat_commands[i].command_name; i++) { - if (strcasecmp (weechat_commands[i].command_name, string + 1) == 0) + if (strcasecmp (weechat_commands[i].command_name, command + 1) == 0) { if ((argc < weechat_commands[i].min_arg) || (argc > weechat_commands[i].max_arg)) @@ -527,7 +530,7 @@ exec_weechat_command (t_irc_server *server, char *string) WEECHAT_NAME " command '%s' " "(expected: %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, weechat_commands[i].max_arg, (weechat_commands[i].max_arg > 1) ? "s" : ""); @@ -537,7 +540,7 @@ exec_weechat_command (t_irc_server *server, char *string) WEECHAT_NAME " command '%s' " "(expected: between %d and %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, weechat_commands[i].min_arg, weechat_commands[i].max_arg, (weechat_commands[i].max_arg > @@ -554,7 +557,7 @@ exec_weechat_command (t_irc_server *server, char *string) if (return_code < 0) gui_printf (NULL, _("%s " WEECHAT_NAME " command \"%s\" failed\n"), - WEECHAT_ERROR, string + 1); + WEECHAT_ERROR, command + 1); } if (argv) { @@ -567,7 +570,7 @@ exec_weechat_command (t_irc_server *server, char *string) } for (i = 0; irc_commands[i].command_name; i++) { - if ((strcasecmp (irc_commands[i].command_name, string + 1) == 0) && + if ((strcasecmp (irc_commands[i].command_name, command + 1) == 0) && ((irc_commands[i].cmd_function_args) || (irc_commands[i].cmd_function_1arg))) { @@ -580,7 +583,7 @@ exec_weechat_command (t_irc_server *server, char *string) _("%s wrong argument count for IRC command '%s' " "(expected: %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, irc_commands[i].max_arg, (irc_commands[i].max_arg > 1) ? "s" : ""); else @@ -589,7 +592,7 @@ exec_weechat_command (t_irc_server *server, char *string) _("%s wrong argument count for IRC command '%s' " "(expected: between %d and %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, irc_commands[i].min_arg, irc_commands[i].max_arg, (irc_commands[i].max_arg > 1) ? "s" : ""); } @@ -612,7 +615,7 @@ exec_weechat_command (t_irc_server *server, char *string) if (return_code < 0) gui_printf (NULL, _("%s IRC command \"%s\" failed\n"), - WEECHAT_ERROR, string + 1); + WEECHAT_ERROR, command + 1); } if (argv) { @@ -626,7 +629,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (strcasecmp (ptr_alias->alias_name, string + 1) == 0) + if (strcasecmp (ptr_alias->alias_name, command + 1) == 0) { if (ptr_args) { @@ -636,11 +639,11 @@ exec_weechat_command (t_irc_server *server, char *string) strcpy (alias_command, ptr_alias->alias_command); alias_command[length1] = ' '; strcpy (alias_command + length1 + 1, ptr_args); + exec_weechat_command (server, alias_command); + free (alias_command); } else - alias_command = strdup (ptr_alias->alias_command); - exec_weechat_command (server, alias_command); - free (alias_command); + exec_weechat_command (server, ptr_alias->alias_command); if (argv) { @@ -654,7 +657,7 @@ exec_weechat_command (t_irc_server *server, char *string) gui_printf (NULL, _("%s unknown command '%s' (type /help for help)\n"), WEECHAT_ERROR, - string + 1); + command + 1); if (argv) { for (j = 0; argv[j]; j++) @@ -1055,6 +1058,26 @@ weechat_cmd_server (int argc, char **argv) COLOR_WIN_CHAT, _(" Realname : %s\n"), ptr_server->realname); + irc_display_prefix (NULL, PREFIX_INFO); + if (ptr_server->command && ptr_server->command[0]) + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Command : %s\n"), + ptr_server->command); + else + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Command : (none)\n")); + irc_display_prefix (NULL, PREFIX_INFO); + if (ptr_server->autojoin && ptr_server->autojoin[0]) + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Auto-join : %s\n"), + ptr_server->autojoin); + else + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Auto-join : (none)\n")); } } else @@ -1191,6 +1214,30 @@ weechat_cmd_server (int argc, char **argv) } server.realname = strdup (argv[++i]); } + if (strcasecmp (argv[0], "-command") == 0) + { + if (i == (argc - 1)) + { + gui_printf (NULL, + _("%s missing command for \"-command\" parameter\n"), + WEECHAT_ERROR); + server_destroy (&server); + return -1; + } + server.command = strdup (argv[++i]); + } + if (strcasecmp (argv[0], "-autojoin") == 0) + { + if (i == (argc - 1)) + { + gui_printf (NULL, + _("%s missing password for \"-autojoin\" parameter\n"), + WEECHAT_ERROR); + server_destroy (&server); + return -1; + } + server.autojoin = strdup (argv[++i]); + } } } @@ -1198,7 +1245,8 @@ weechat_cmd_server (int argc, char **argv) new_server = server_new (server.name, server.autoconnect, server.address, server.port, server.password, server.nick1, server.nick2, server.nick3, server.username, - server.realname); + server.realname, server.command, + server.autojoin); if (new_server) { irc_display_prefix (NULL, PREFIX_INFO); diff --git a/src/config.c b/src/config.c index 0d34efea0..703e5d4d1 100644 --- a/src/config.c +++ b/src/config.c @@ -484,6 +484,14 @@ t_config_option weechat_options_server[] = N_("real name to use on IRC server"), OPTION_TYPE_STRING, 0, 0, 0, "", NULL, NULL, &(cfg_server.realname), NULL }, + { "server_command", N_("first command to run when connected to server"), + N_("first command to run when connected to server"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.command), NULL }, + { "server_autojoin", N_("list of channels to join when connected to server"), + N_("comma separated list of channels to join when connected to server"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.autojoin), NULL }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -551,7 +559,8 @@ config_allocate_server (char *filename, int line_number) if (!server_new (cfg_server.name, cfg_server.autoconnect, cfg_server.address, cfg_server.port, cfg_server.password, cfg_server.nick1, cfg_server.nick2, - cfg_server.nick3, cfg_server.username, cfg_server.realname)) + cfg_server.nick3, cfg_server.username, cfg_server.realname, + cfg_server.command, cfg_server.autojoin)) { server_free_all (); gui_printf (NULL, @@ -1016,6 +1025,8 @@ config_create_default () fputs ("server_nick3=weechat3\n", file); fputs ("server_username=weechat\n", file); fputs ("server_realname=WeeChat default realname\n", file); + fputs ("server_command=\n", file); + fputs ("server_autojoin=\n", file); fclose (file); free (filename); @@ -1160,6 +1171,12 @@ config_write (char *config_name) fputs (line, file); sprintf (line, "server_realname=%s\n", ptr_server->realname); fputs (line, file); + sprintf (line, "server_command=%s\n", + (ptr_server->command) ? ptr_server->command : ""); + fputs (line, file); + sprintf (line, "server_autojoin=%s\n", + (ptr_server->autojoin) ? ptr_server->autojoin : ""); + fputs (line, file); } fclose (file); diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c index 3391973a5..f852adf44 100644 --- a/src/irc/irc-commands.c +++ b/src/irc/irc-commands.c @@ -2104,6 +2104,15 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *arguments) server->is_connected = 1; gui_redraw_window_status (server->window); gui_redraw_window_input (server->window); + + /* execute command once connected */ + if (server->command && server->command[0]) + user_command(server, server->command); + + /* autojoin */ + if (server->autojoin && server->autojoin[0]) + return irc_cmd_send_join (server, server->autojoin); + return 0; } diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 4f82fd747..a05c51ae1 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -66,6 +66,8 @@ server_init (t_irc_server *server) server->nick3 = NULL; server->username = NULL; server->realname = NULL; + server->command = NULL; + server->autojoin = NULL; server->nick = NULL; server->is_connected = 0; server->sock4 = -1; @@ -137,6 +139,10 @@ server_destroy (t_irc_server *server) free (server->username); if (server->realname) free (server->realname); + if (server->command) + free (server->command); + if (server->autojoin) + free (server->autojoin); if (server->nick) free (server->nick); if (server->channels) @@ -153,6 +159,8 @@ server_free (t_irc_server *server) t_irc_server *new_irc_servers; /* remove server from queue */ + if (last_irc_server == server) + last_irc_server = server->prev_server; if (server->prev_server) { (server->prev_server)->next_server = server->next_server; @@ -190,7 +198,7 @@ server_free_all () t_irc_server * server_new (char *name, int autoconnect, char *address, int port, char *password, char *nick1, char *nick2, char *nick3, - char *username, char *realname) + char *username, char *realname, char *command, char *autojoin) { t_irc_server *new_server; @@ -199,10 +207,12 @@ server_new (char *name, int autoconnect, char *address, int port, #if DEBUG >= 1 log_printf ("creating new server (name:%s, address:%s, port:%d, pwd:%s, " - "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s)\n", + "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, " + "command:%s, autojoin:%s)\n", name, address, port, (password) ? password : "", (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", - (username) ? username : "", (realname) ? realname : ""); + (username) ? username : "", (realname) ? realname : "", + (command) ? command : "", (autojoin) ? autojoin : ""); #endif if ((new_server = server_alloc ())) @@ -219,6 +229,8 @@ server_new (char *name, int autoconnect, char *address, int port, (username) ? strdup (username) : strdup ("weechat"); new_server->realname = (realname) ? strdup (realname) : strdup ("realname"); + new_server->command = command; + new_server->autojoin = autojoin; new_server->nick = strdup (new_server->nick1); } else diff --git a/src/irc/irc.h b/src/irc/irc.h index 8dcd30639..4ec4d4d98 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -87,6 +87,8 @@ struct t_irc_server char *nick3; /* 2nd alternate nickname */ char *username; /* user name */ char *realname; /* real name */ + char *command; /* command to run once connected */ + char *autojoin; /* channels to automatically join */ /* internal vars */ char *nick; /* current nickname */ @@ -144,7 +146,7 @@ extern void server_destroy (t_irc_server *); extern void server_free (t_irc_server *); extern void server_free_all (); extern t_irc_server *server_new (char *, int, char *, int, char *, char *, - char *, char *, char *, char *); + char *, char *, char *, char *, char *, char *); extern int server_send (t_irc_server *, char *, int); extern int server_sendf (t_irc_server *, char *, ...); extern void server_recv (t_irc_server *); diff --git a/weechat/ChangeLog b/weechat/ChangeLog index 852f9689c..8bb10d431 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -5,6 +5,7 @@ ChangeLog - 2003-10-04 Version 0.0.2 (under dev!): + * command & auto-join channels when connected to server * new commands for alias: /alias, /unalias (new section in config file) * config is now saved automatically when quitting WeeChat, /save command added * new commands for servers: /server, /connect, /disconnect diff --git a/weechat/src/command.c b/weechat/src/command.c index 692b8e1af..deaca0c10 100644 --- a/weechat/src/command.c +++ b/weechat/src/command.c @@ -59,7 +59,8 @@ t_weechat_command weechat_commands[] = { "server", N_("list, add or remove servers"), N_("[list] | " "[servername hostname port [-auto | -noauto] [-pwd password] [-nicks nick1 " - "[nick2 [nick3]]] [-username username] [-realname realname]] | " + "[nick2 [nick3]]] [-username username] [-realname realname] " + "[-command command] [-autojoin channel[,channel]] ] | " "[del servername]"), N_("servername: server name, for internal & display use\n" "hostname: name or IP address of server\n" @@ -491,15 +492,17 @@ int exec_weechat_command (t_irc_server *server, char *string) { int i, j, argc, return_code, length1, length2; - char *pos, *ptr_args, **argv, *alias_command; + char *command, *pos, *ptr_args, **argv, *alias_command; t_weechat_alias *ptr_alias; if ((!string[0]) || (string[0] != '/')) return 0; + command = strdup (string); + /* look for end of command */ ptr_args = NULL; - pos = strchr (string, ' '); + pos = strchr (command, ' '); if (pos) { pos[0] = '\0'; @@ -515,7 +518,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (i = 0; weechat_commands[i].command_name; i++) { - if (strcasecmp (weechat_commands[i].command_name, string + 1) == 0) + if (strcasecmp (weechat_commands[i].command_name, command + 1) == 0) { if ((argc < weechat_commands[i].min_arg) || (argc > weechat_commands[i].max_arg)) @@ -527,7 +530,7 @@ exec_weechat_command (t_irc_server *server, char *string) WEECHAT_NAME " command '%s' " "(expected: %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, weechat_commands[i].max_arg, (weechat_commands[i].max_arg > 1) ? "s" : ""); @@ -537,7 +540,7 @@ exec_weechat_command (t_irc_server *server, char *string) WEECHAT_NAME " command '%s' " "(expected: between %d and %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, weechat_commands[i].min_arg, weechat_commands[i].max_arg, (weechat_commands[i].max_arg > @@ -554,7 +557,7 @@ exec_weechat_command (t_irc_server *server, char *string) if (return_code < 0) gui_printf (NULL, _("%s " WEECHAT_NAME " command \"%s\" failed\n"), - WEECHAT_ERROR, string + 1); + WEECHAT_ERROR, command + 1); } if (argv) { @@ -567,7 +570,7 @@ exec_weechat_command (t_irc_server *server, char *string) } for (i = 0; irc_commands[i].command_name; i++) { - if ((strcasecmp (irc_commands[i].command_name, string + 1) == 0) && + if ((strcasecmp (irc_commands[i].command_name, command + 1) == 0) && ((irc_commands[i].cmd_function_args) || (irc_commands[i].cmd_function_1arg))) { @@ -580,7 +583,7 @@ exec_weechat_command (t_irc_server *server, char *string) _("%s wrong argument count for IRC command '%s' " "(expected: %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, irc_commands[i].max_arg, (irc_commands[i].max_arg > 1) ? "s" : ""); else @@ -589,7 +592,7 @@ exec_weechat_command (t_irc_server *server, char *string) _("%s wrong argument count for IRC command '%s' " "(expected: between %d and %d arg%s)\n"), WEECHAT_ERROR, - string + 1, + command + 1, irc_commands[i].min_arg, irc_commands[i].max_arg, (irc_commands[i].max_arg > 1) ? "s" : ""); } @@ -612,7 +615,7 @@ exec_weechat_command (t_irc_server *server, char *string) if (return_code < 0) gui_printf (NULL, _("%s IRC command \"%s\" failed\n"), - WEECHAT_ERROR, string + 1); + WEECHAT_ERROR, command + 1); } if (argv) { @@ -626,7 +629,7 @@ exec_weechat_command (t_irc_server *server, char *string) for (ptr_alias = weechat_alias; ptr_alias; ptr_alias = ptr_alias->next_alias) { - if (strcasecmp (ptr_alias->alias_name, string + 1) == 0) + if (strcasecmp (ptr_alias->alias_name, command + 1) == 0) { if (ptr_args) { @@ -636,11 +639,11 @@ exec_weechat_command (t_irc_server *server, char *string) strcpy (alias_command, ptr_alias->alias_command); alias_command[length1] = ' '; strcpy (alias_command + length1 + 1, ptr_args); + exec_weechat_command (server, alias_command); + free (alias_command); } else - alias_command = strdup (ptr_alias->alias_command); - exec_weechat_command (server, alias_command); - free (alias_command); + exec_weechat_command (server, ptr_alias->alias_command); if (argv) { @@ -654,7 +657,7 @@ exec_weechat_command (t_irc_server *server, char *string) gui_printf (NULL, _("%s unknown command '%s' (type /help for help)\n"), WEECHAT_ERROR, - string + 1); + command + 1); if (argv) { for (j = 0; argv[j]; j++) @@ -1055,6 +1058,26 @@ weechat_cmd_server (int argc, char **argv) COLOR_WIN_CHAT, _(" Realname : %s\n"), ptr_server->realname); + irc_display_prefix (NULL, PREFIX_INFO); + if (ptr_server->command && ptr_server->command[0]) + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Command : %s\n"), + ptr_server->command); + else + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Command : (none)\n")); + irc_display_prefix (NULL, PREFIX_INFO); + if (ptr_server->autojoin && ptr_server->autojoin[0]) + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Auto-join : %s\n"), + ptr_server->autojoin); + else + gui_printf_color (NULL, + COLOR_WIN_CHAT, + _(" Auto-join : (none)\n")); } } else @@ -1191,6 +1214,30 @@ weechat_cmd_server (int argc, char **argv) } server.realname = strdup (argv[++i]); } + if (strcasecmp (argv[0], "-command") == 0) + { + if (i == (argc - 1)) + { + gui_printf (NULL, + _("%s missing command for \"-command\" parameter\n"), + WEECHAT_ERROR); + server_destroy (&server); + return -1; + } + server.command = strdup (argv[++i]); + } + if (strcasecmp (argv[0], "-autojoin") == 0) + { + if (i == (argc - 1)) + { + gui_printf (NULL, + _("%s missing password for \"-autojoin\" parameter\n"), + WEECHAT_ERROR); + server_destroy (&server); + return -1; + } + server.autojoin = strdup (argv[++i]); + } } } @@ -1198,7 +1245,8 @@ weechat_cmd_server (int argc, char **argv) new_server = server_new (server.name, server.autoconnect, server.address, server.port, server.password, server.nick1, server.nick2, server.nick3, server.username, - server.realname); + server.realname, server.command, + server.autojoin); if (new_server) { irc_display_prefix (NULL, PREFIX_INFO); diff --git a/weechat/src/config.c b/weechat/src/config.c index 0d34efea0..703e5d4d1 100644 --- a/weechat/src/config.c +++ b/weechat/src/config.c @@ -484,6 +484,14 @@ t_config_option weechat_options_server[] = N_("real name to use on IRC server"), OPTION_TYPE_STRING, 0, 0, 0, "", NULL, NULL, &(cfg_server.realname), NULL }, + { "server_command", N_("first command to run when connected to server"), + N_("first command to run when connected to server"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.command), NULL }, + { "server_autojoin", N_("list of channels to join when connected to server"), + N_("comma separated list of channels to join when connected to server"), + OPTION_TYPE_STRING, 0, 0, 0, + "", NULL, NULL, &(cfg_server.autojoin), NULL }, { NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } }; @@ -551,7 +559,8 @@ config_allocate_server (char *filename, int line_number) if (!server_new (cfg_server.name, cfg_server.autoconnect, cfg_server.address, cfg_server.port, cfg_server.password, cfg_server.nick1, cfg_server.nick2, - cfg_server.nick3, cfg_server.username, cfg_server.realname)) + cfg_server.nick3, cfg_server.username, cfg_server.realname, + cfg_server.command, cfg_server.autojoin)) { server_free_all (); gui_printf (NULL, @@ -1016,6 +1025,8 @@ config_create_default () fputs ("server_nick3=weechat3\n", file); fputs ("server_username=weechat\n", file); fputs ("server_realname=WeeChat default realname\n", file); + fputs ("server_command=\n", file); + fputs ("server_autojoin=\n", file); fclose (file); free (filename); @@ -1160,6 +1171,12 @@ config_write (char *config_name) fputs (line, file); sprintf (line, "server_realname=%s\n", ptr_server->realname); fputs (line, file); + sprintf (line, "server_command=%s\n", + (ptr_server->command) ? ptr_server->command : ""); + fputs (line, file); + sprintf (line, "server_autojoin=%s\n", + (ptr_server->autojoin) ? ptr_server->autojoin : ""); + fputs (line, file); } fclose (file); diff --git a/weechat/src/irc/irc-commands.c b/weechat/src/irc/irc-commands.c index 3391973a5..f852adf44 100644 --- a/weechat/src/irc/irc-commands.c +++ b/weechat/src/irc/irc-commands.c @@ -2104,6 +2104,15 @@ irc_cmd_recv_004 (t_irc_server *server, char *host, char *arguments) server->is_connected = 1; gui_redraw_window_status (server->window); gui_redraw_window_input (server->window); + + /* execute command once connected */ + if (server->command && server->command[0]) + user_command(server, server->command); + + /* autojoin */ + if (server->autojoin && server->autojoin[0]) + return irc_cmd_send_join (server, server->autojoin); + return 0; } diff --git a/weechat/src/irc/irc-server.c b/weechat/src/irc/irc-server.c index 4f82fd747..a05c51ae1 100644 --- a/weechat/src/irc/irc-server.c +++ b/weechat/src/irc/irc-server.c @@ -66,6 +66,8 @@ server_init (t_irc_server *server) server->nick3 = NULL; server->username = NULL; server->realname = NULL; + server->command = NULL; + server->autojoin = NULL; server->nick = NULL; server->is_connected = 0; server->sock4 = -1; @@ -137,6 +139,10 @@ server_destroy (t_irc_server *server) free (server->username); if (server->realname) free (server->realname); + if (server->command) + free (server->command); + if (server->autojoin) + free (server->autojoin); if (server->nick) free (server->nick); if (server->channels) @@ -153,6 +159,8 @@ server_free (t_irc_server *server) t_irc_server *new_irc_servers; /* remove server from queue */ + if (last_irc_server == server) + last_irc_server = server->prev_server; if (server->prev_server) { (server->prev_server)->next_server = server->next_server; @@ -190,7 +198,7 @@ server_free_all () t_irc_server * server_new (char *name, int autoconnect, char *address, int port, char *password, char *nick1, char *nick2, char *nick3, - char *username, char *realname) + char *username, char *realname, char *command, char *autojoin) { t_irc_server *new_server; @@ -199,10 +207,12 @@ server_new (char *name, int autoconnect, char *address, int port, #if DEBUG >= 1 log_printf ("creating new server (name:%s, address:%s, port:%d, pwd:%s, " - "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s)\n", + "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s, " + "command:%s, autojoin:%s)\n", name, address, port, (password) ? password : "", (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", - (username) ? username : "", (realname) ? realname : ""); + (username) ? username : "", (realname) ? realname : "", + (command) ? command : "", (autojoin) ? autojoin : ""); #endif if ((new_server = server_alloc ())) @@ -219,6 +229,8 @@ server_new (char *name, int autoconnect, char *address, int port, (username) ? strdup (username) : strdup ("weechat"); new_server->realname = (realname) ? strdup (realname) : strdup ("realname"); + new_server->command = command; + new_server->autojoin = autojoin; new_server->nick = strdup (new_server->nick1); } else diff --git a/weechat/src/irc/irc.h b/weechat/src/irc/irc.h index 8dcd30639..4ec4d4d98 100644 --- a/weechat/src/irc/irc.h +++ b/weechat/src/irc/irc.h @@ -87,6 +87,8 @@ struct t_irc_server char *nick3; /* 2nd alternate nickname */ char *username; /* user name */ char *realname; /* real name */ + char *command; /* command to run once connected */ + char *autojoin; /* channels to automatically join */ /* internal vars */ char *nick; /* current nickname */ @@ -144,7 +146,7 @@ extern void server_destroy (t_irc_server *); extern void server_free (t_irc_server *); extern void server_free_all (); extern t_irc_server *server_new (char *, int, char *, int, char *, char *, - char *, char *, char *, char *); + char *, char *, char *, char *, char *, char *); extern int server_send (t_irc_server *, char *, int); extern int server_sendf (t_irc_server *, char *, ...); extern void server_recv (t_irc_server *); |