diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-04-08 18:38:00 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-04-08 18:38:00 +0000 |
commit | c525b231e4a5c39d708fdf25b87c25f3d8a769bb (patch) | |
tree | 83b5da5e97958704edb0c41dc37632fe4bbfb0f5 /src | |
parent | 6963ca7b651071d071d96228b6d6d0a2ef85cb91 (diff) | |
download | weechat-c525b231e4a5c39d708fdf25b87c25f3d8a769bb.zip |
Added hostnames associeted to nicks (available for /ban completion)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/completion.c | 51 | ||||
-rw-r--r-- | src/common/session.c | 4 | ||||
-rw-r--r-- | src/common/session.h | 3 | ||||
-rw-r--r-- | src/irc/irc-channel.c | 4 | ||||
-rw-r--r-- | src/irc/irc-commands.c | 2 | ||||
-rw-r--r-- | src/irc/irc-nick.c | 19 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 21 | ||||
-rw-r--r-- | src/irc/irc-server.c | 2 | ||||
-rw-r--r-- | src/irc/irc.h | 3 |
9 files changed, 93 insertions, 16 deletions
diff --git a/src/common/completion.c b/src/common/completion.c index 1155b785c..5c2b4a00a 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -369,6 +369,54 @@ completion_list_add_channel_nicks (t_completion *completion) } /* + * completion_list_add_channel_nicks_hosts: add channel nicks and hosts to completion list + */ + +void +completion_list_add_channel_nicks_hosts (t_completion *completion) +{ + t_irc_nick *ptr_nick; + char *buf; + int length; + + if (completion->channel) + { + if (((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_CHANNEL) + { + for (ptr_nick = ((t_irc_channel *)(completion->channel))->nicks; + ptr_nick; ptr_nick = ptr_nick->next_nick) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + ptr_nick->nick); + if (ptr_nick->host) + { + length = strlen (ptr_nick->nick) + 1 + + strlen (ptr_nick->host) + 1; + buf = (char *) malloc (length); + if (buf) + { + snprintf (buf, length, "%s!%s", + ptr_nick->nick, ptr_nick->host); + weelist_add (&completion->completion_list, + &completion->last_completion, + buf); + free (buf); + } + } + } + } + if (((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_PRIVATE) + { + weelist_add (&completion->completion_list, + &completion->last_completion, + ((t_irc_channel *)(completion->channel))->name); + } + completion->arg_is_nick = 1; + } +} + +/* * completion_list_add_option: add config option to completion list */ @@ -733,6 +781,9 @@ completion_build_list_template (t_completion *completion, char *template) case 'n': /* channel nicks */ completion_list_add_channel_nicks (completion); break; + case 'N': /* channel nicks and hosts */ + completion_list_add_channel_nicks_hosts (completion); + break; case 'o': /* config option */ completion_list_add_option (completion); break; diff --git a/src/common/session.c b/src/common/session.c index ad3146204..59973ccb0 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -147,6 +147,7 @@ session_save_nick (FILE *file, t_irc_nick *nick) rc = rc && (session_write_str (file, SESSION_NICK_NICK, nick->nick)); rc = rc && (session_write_int (file, SESSION_NICK_FLAGS, nick->flags)); rc = rc && (session_write_int (file, SESSION_NICK_COLOR, nick->color)); + rc = rc && (session_write_str (file, SESSION_NICK_HOST, nick->host)); rc = rc && (session_write_id (file, SESSION_NICK_END)); return rc; } @@ -1126,6 +1127,9 @@ session_load_nick (FILE *file) case SESSION_NICK_COLOR: rc = rc && (session_read_int (file, &(nick->color))); break; + case SESSION_NICK_HOST: + rc = rc && (session_read_str (file, &(nick->host))); + break; default: weechat_log_printf (_("session: warning: ignoring value from " "nick (object id: %d)\n")); diff --git a/src/common/session.h b/src/common/session.h index 7100e0bf0..143f504f0 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -113,7 +113,8 @@ enum t_session_nick SESSION_NICK_END = 0, SESSION_NICK_NICK, SESSION_NICK_FLAGS, - SESSION_NICK_COLOR + SESSION_NICK_COLOR, + SESSION_NICK_HOST }; enum t_session_dcc diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index 718bb7df6..0ffeb80d0 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -340,11 +340,11 @@ channel_remove_away (t_irc_channel *channel) */ void -channel_check_away (t_irc_server *server, t_irc_channel *channel) +channel_check_away (t_irc_server *server, t_irc_channel *channel, int force) { if (channel->type == CHANNEL_TYPE_CHANNEL) { - if ((cfg_irc_away_check_max_nicks == 0) || + if (force || (cfg_irc_away_check_max_nicks == 0) || (channel->nicks_count <= cfg_irc_away_check_max_nicks)) { channel->checking_away++; diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c index 2ec2bb313..5c6fe935d 100644 --- a/src/irc/irc-commands.c +++ b/src/irc/irc-commands.c @@ -52,7 +52,7 @@ t_irc_command irc_commands[] = N_("[channel] [nickname [nickname ...]]"), N_(" channel: channel for ban\n" "nickname: user or host to ban"), - "", 0, MAX_ARGS, 1, NULL, irc_cmd_send_ban, NULL }, + "%N", 0, MAX_ARGS, 1, NULL, irc_cmd_send_ban, NULL }, { "ctcp", N_("send a CTCP message (Client-To-Client Protocol)"), N_("nickname type [arguments]"), N_(" nickname: user to send CTCP to\n" diff --git a/src/irc/irc-nick.c b/src/irc/irc-nick.c index 28612b3ed..b4f2f63cd 100644 --- a/src/irc/irc-nick.c +++ b/src/irc/irc-nick.c @@ -192,6 +192,7 @@ nick_new (t_irc_server *server, t_irc_channel *channel, char *nick_name, /* initialize new nick */ new_nick->nick = strdup (nick_name); + new_nick->host = NULL; new_nick->flags = 0; NICK_SET_FLAG(new_nick, is_chanowner, NICK_CHANOWNER); NICK_SET_FLAG(new_nick, is_chanadmin, NICK_CHANADMIN); @@ -278,12 +279,14 @@ nick_free (t_irc_channel *channel, t_irc_nick *nick) if (nick->next_nick) (nick->next_nick)->prev_nick = nick->prev_nick; - + channel->nicks_count--; /* free data */ if (nick->nick) free (nick->nick); + if (nick->host) + free (nick->host); free (nick); channel->nicks = new_nicks; } @@ -389,11 +392,16 @@ nick_get_max_length (t_irc_channel *channel) void nick_set_away (t_irc_channel *channel, t_irc_nick *nick, int is_away) { - if (((is_away) && (!(nick->flags & NICK_AWAY))) || - ((!is_away) && (nick->flags & NICK_AWAY))) + if ((cfg_irc_away_check > 0) + && ((cfg_irc_away_check_max_nicks == 0) || + (channel->nicks_count <= cfg_irc_away_check_max_nicks))) { - NICK_SET_FLAG(nick, is_away, NICK_AWAY); - gui_draw_buffer_nick (channel->buffer, 0); + if (((is_away) && (!(nick->flags & NICK_AWAY))) || + ((!is_away) && (nick->flags & NICK_AWAY))) + { + NICK_SET_FLAG(nick, is_away, NICK_AWAY); + gui_draw_buffer_nick (channel->buffer, 0); + } } } @@ -405,6 +413,7 @@ void nick_print_log (t_irc_nick *nick) { weechat_log_printf ("=> nick %s (addr:0x%X)]\n", nick->nick, nick); + weechat_log_printf (" host . . . . . : %s\n", nick->host); weechat_log_printf (" flags. . . . . : %d\n", nick->flags); weechat_log_printf (" color. . . . . : %d\n", nick->color); weechat_log_printf (" prev_nick. . . : 0x%X\n", nick->prev_nick); diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index db707d199..b39f95e00 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -402,6 +402,7 @@ int irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments) { t_irc_channel *ptr_channel; + t_irc_nick *ptr_nick; char *pos; command_ignored |= ignore_check (host, "join", arguments, server->name); @@ -422,9 +423,9 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments BUFFER_TYPE_STANDARD, 1); } + pos = strchr (host, '!'); if (!command_ignored) { - pos = strchr (host, '!'); irc_display_prefix (server, ptr_channel->buffer, PREFIX_JOIN); gui_printf (ptr_channel->buffer, _("%s%s %s(%s%s%s)%s has joined %s%s\n"), @@ -432,13 +433,15 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *nick, char *arguments nick, GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT_HOST), - (pos) ? pos + 1 : "", + (pos) ? pos + 1 : host, GUI_COLOR(COLOR_WIN_CHAT_DARK), GUI_COLOR(COLOR_WIN_CHAT), GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), arguments); } - (void) nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0); + ptr_nick = nick_new (server, ptr_channel, nick, 0, 0, 0, 0, 0); + if (ptr_nick) + ptr_nick->host = strdup ((pos) ? pos + 1 : host); gui_draw_buffer_nick (ptr_channel->buffer, 1); gui_draw_buffer_status (ptr_channel->buffer, 1); return 0; @@ -4373,6 +4376,7 @@ irc_cmd_recv_352 (t_irc_server *server, char *host, char *nick, char *arguments) { char *pos_channel, *pos_user, *pos_host, *pos_server, *pos_nick; char *pos_attr, *pos_hopcount, *pos_realname; + int length; t_irc_channel *ptr_channel; t_irc_nick *ptr_nick; @@ -4443,8 +4447,16 @@ irc_cmd_recv_352 (t_irc_server *server, char *host, char *nick, char *arguments) { ptr_nick = nick_search (ptr_channel, pos_nick); if (ptr_nick) + { + if (ptr_nick->host) + free (ptr_nick->host); + length = strlen (pos_user) + 1 + strlen (pos_host) + 1; + ptr_nick->host = (char *) malloc (length); + if (ptr_nick->host) + snprintf (ptr_nick->host, length, "%s@%s", pos_user, pos_host); nick_set_away (ptr_channel, ptr_nick, (pos_attr[0] == 'G') ? 1 : 0); + } return 0; } @@ -4744,8 +4756,7 @@ irc_cmd_recv_366 (t_irc_server *server, char *host, char *nick, char *arguments) GUI_COLOR(COLOR_WIN_CHAT_DARK)); } irc_cmd_send_mode (server, NULL, ptr_channel->name); - if (cfg_irc_away_check > 0) - channel_check_away (server, ptr_channel); + channel_check_away (server, ptr_channel, 1); } else { diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 9a28a39c2..7a003d673 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -1837,7 +1837,7 @@ server_check_away () for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->type == CHANNEL_TYPE_CHANNEL) - channel_check_away (ptr_server, ptr_channel); + channel_check_away (ptr_server, ptr_channel, 0); } } } diff --git a/src/irc/irc.h b/src/irc/irc.h index 87687146e..2b2b00959 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -69,6 +69,7 @@ typedef struct t_irc_nick t_irc_nick; struct t_irc_nick { char *nick; /* nickname */ + char *host; /* full hostname */ int flags; /* chanowner/chanadmin (unrealircd), */ /* op, halfop, voice, away */ int color; /* color for nickname in chat window */ @@ -359,7 +360,7 @@ extern char *channel_get_charset_encode (t_irc_server *, t_irc_channel *); extern char *channel_iconv_decode (t_irc_server *, t_irc_channel *, char *); extern char *channel_iconv_encode (t_irc_server *, t_irc_channel *, char *); extern void channel_remove_away (t_irc_channel *); -extern void channel_check_away (t_irc_server *, t_irc_channel *); +extern void channel_check_away (t_irc_server *, t_irc_channel *, int); extern void channel_set_away (t_irc_channel *, char *, int); extern int channel_create_dcc (t_irc_dcc *); extern void channel_remove_dcc (t_irc_dcc *); |