Exemplo n.º 1
0
void
irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
               struct t_irc_channel *channel, const char *address,
               const char *nick, const char *remote_nick, char *arguments,
               char *message)
{
    char *pos_end, *pos_space, *pos_args;
    const char *reply;
    char *decoded_reply;
    struct t_irc_channel *ptr_channel;
    struct t_irc_nick *ptr_nick;
    int nick_is_me;

    while (arguments && arguments[0])
    {
        pos_end = strrchr (arguments + 1, '\01');
        if (pos_end)
            pos_end[0] = '\0';

        pos_args = NULL;
        pos_space = strchr (arguments + 1, ' ');
        if (pos_space)
        {
            pos_space[0] = '\0';
            pos_args = pos_space + 1;
            while (pos_args[0] == ' ')
            {
                pos_args++;
            }
        }

        /* CTCP ACTION */
        if (strcmp (arguments + 1, "ACTION") == 0)
        {
            nick_is_me = (irc_server_strcasecmp (server, server->nick, nick) == 0);
            if (channel)
            {
                ptr_nick = irc_nick_search (server, channel, nick);
                irc_channel_nick_speaking_add (channel,
                                               nick,
                                               (pos_args) ?
                                               weechat_string_has_highlight (pos_args,
                                                                             server->nick) : 0);
                irc_channel_nick_speaking_time_remove_old (channel);
                irc_channel_nick_speaking_time_add (server, channel, nick,
                                                    time (NULL));
                weechat_printf_date_tags (channel->buffer,
                                          date,
                                          irc_protocol_tags (command,
                                                             (nick_is_me) ?
                                                             "irc_action,notify_none,no_highlight" :
                                                             "irc_action,notify_message",
                                                             nick),
                                          "%s%s%s%s%s%s%s",
                                          weechat_prefix ("action"),
                                          irc_nick_mode_for_display (server, ptr_nick, 0),
                                          (ptr_nick) ? ptr_nick->color : ((nick) ? irc_nick_find_color (nick) : IRC_COLOR_CHAT_NICK),
                                          nick,
                                          (pos_args) ? IRC_COLOR_RESET : "",
                                          (pos_args) ? " " : "",
                                          (pos_args) ? pos_args : "");
            }
            else
            {
                ptr_channel = irc_channel_search (server, remote_nick);
                if (!ptr_channel)
                {
                    ptr_channel = irc_channel_new (server,
                                                   IRC_CHANNEL_TYPE_PRIVATE,
                                                   remote_nick, 0, 0);
                    if (!ptr_channel)
                    {
                        weechat_printf (server->buffer,
                                        _("%s%s: cannot create new "
                                          "private buffer \"%s\""),
                                        weechat_prefix ("error"),
                                        IRC_PLUGIN_NAME, remote_nick);
                    }
                }
                if (ptr_channel)
                {
                    if (!ptr_channel->topic)
                        irc_channel_set_topic (ptr_channel, address);

                    weechat_printf_date_tags (ptr_channel->buffer,
                                              date,
                                              irc_protocol_tags (command,
                                                                 (nick_is_me) ?
                                                                 "irc_action,notify_none,no_highlight" :
                                                                 "irc_action,notify_private",
                                                                 nick),
                                              "%s%s%s%s%s%s",
                                              weechat_prefix ("action"),
                                              (nick_is_me) ?
                                              IRC_COLOR_CHAT_NICK_SELF : irc_nick_color_for_pv (ptr_channel, nick),
                                              nick,
                                              (pos_args) ? IRC_COLOR_RESET : "",
                                              (pos_args) ? " " : "",
                                              (pos_args) ? pos_args : "");
                    weechat_hook_signal_send ("irc_pv",
                                              WEECHAT_HOOK_SIGNAL_STRING,
                                              message);
                }
            }
        }
        /* CTCP PING */
        else if (strcmp (arguments + 1, "PING") == 0)
        {
            reply = irc_ctcp_get_reply (server, arguments + 1);
            irc_ctcp_display_request (server, date, command, channel, nick,
                                      arguments + 1, pos_args, reply);
            if (!reply || reply[0])
            {
                irc_ctcp_reply_to_nick (server, command, channel, nick,
                                        arguments + 1, pos_args);
            }
        }
        /* CTCP DCC */
        else if (strcmp (arguments + 1, "DCC") == 0)
        {
            irc_ctcp_recv_dcc (server, nick, pos_args, message);
        }
        /* other CTCP */
        else
        {
            reply = irc_ctcp_get_reply (server, arguments + 1);
            if (reply)
            {
                irc_ctcp_display_request (server, date, command, channel, nick,
                                          arguments + 1, pos_args, reply);

                if (reply[0])
                {
                    decoded_reply = irc_ctcp_replace_variables (server, reply);
                    if (decoded_reply)
                    {
                        irc_ctcp_reply_to_nick (server, command, channel, nick,
                                                arguments + 1, decoded_reply);
                        free (decoded_reply);
                    }
                }
            }
            else
            {
                if (weechat_config_boolean (irc_config_look_display_ctcp_unknown))
                {
                    weechat_printf_date_tags (irc_msgbuffer_get_target_buffer (server,
                                                                               nick,
                                                                               NULL,
                                                                               "ctcp",
                                                                               (channel) ? channel->buffer : NULL),
                                              date,
                                              irc_protocol_tags (command,
                                                                 "irc_ctcp",
                                                                 NULL),
                                              _("%sUnknown CTCP requested by %s%s%s: "
                                                "%s%s%s%s%s"),
                                              weechat_prefix ("network"),
                                              irc_nick_color_for_message (server,
                                                                          NULL,
                                                                          nick),
                                              nick,
                                              IRC_COLOR_RESET,
                                              IRC_COLOR_CHAT_CHANNEL,
                                              arguments + 1,
                                              (pos_args) ? IRC_COLOR_RESET : "",
                                              (pos_args) ? " " : "",
                                              (pos_args) ? pos_args : "");
                }
            }
        }

        weechat_hook_signal_send ("irc_ctcp",
                                  WEECHAT_HOOK_SIGNAL_STRING,
                                  message);

        if (pos_space)
            pos_space[0] = ' ';

        if (pos_end)
            pos_end[0] = '\01';

        arguments = (pos_end) ? pos_end + 1 : NULL;
    }
}
Exemplo n.º 2
0
void
irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
                                const char *text)
{
    struct t_irc_nick *ptr_nick;
    char *pos, *text2, *text_decoded, str_tags[256], *str_color;
    const char *ptr_text;

    /* if message is an action, force "action" to 1 and extract message */
    if (strncmp (text, "\01ACTION ", 8) == 0)
    {
        action = 1;
        pos = strrchr (text + 8, '\01');
        if (pos)
            text2 = weechat_strndup (text + 8, pos - text - 8);
        else
            text2 = strdup (text + 8);
    }
    else
        text2 = strdup (text);

    text_decoded = irc_color_decode (
        (text2) ? text2 : text,
        weechat_config_boolean (irc_config_network_colors_send));

    IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

    if (ptr_channel)
    {
        ptr_nick = NULL;
        if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
        {
            ptr_nick = irc_nick_search (ptr_server, ptr_channel,
                                        ptr_server->nick);
        }

        if (action)
        {
            snprintf (str_tags, sizeof (str_tags),
                      "irc_action,self_msg,notify_none,no_highlight");
        }
        else
        {
            str_color = irc_color_for_tags (
                weechat_config_color (
                    weechat_config_get ("weechat.color.chat_nick_self")));
            snprintf (str_tags, sizeof (str_tags),
                      "notify_none,self_msg,no_highlight,prefix_nick_%s",
                      (str_color) ? str_color : "default");
            if (str_color)
                free (str_color);
        }
        ptr_text = (text_decoded) ? text_decoded : ((text2) ? text2 : text);
        if (action)
        {
            weechat_printf_date_tags (
                buffer,
                0,
                irc_protocol_tags (
                    "privmsg", str_tags,
                    (ptr_nick) ? ptr_nick->name : ptr_server->nick,
                    NULL),
                "%s%s%s%s%s %s",
                weechat_prefix ("action"),
                irc_nick_mode_for_display (ptr_server, ptr_nick, 0),
                IRC_COLOR_CHAT_NICK_SELF,
                ptr_server->nick,
                IRC_COLOR_RESET,
                ptr_text);
        }
        else
        {
            weechat_printf_date_tags (
                buffer,
                0,
                irc_protocol_tags (
                    "privmsg", str_tags,
                    (ptr_nick) ? ptr_nick->name : ptr_server->nick,
                    NULL),
                "%s%s",
                irc_nick_as_prefix (
                    ptr_server,
                    (ptr_nick) ? ptr_nick : NULL,
                    (ptr_nick) ? NULL : ptr_server->nick,
                    IRC_COLOR_CHAT_NICK_SELF),
                ptr_text);
        }
    }

    if (text2)
        free (text2);
    if (text_decoded)
        free (text_decoded);
}
Exemplo n.º 3
0
char *
irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item,
                           struct t_gui_window *window,
                           struct t_gui_buffer *buffer,
                           struct t_hashtable *extra_info)
{
    struct t_irc_server *server;
    struct t_irc_channel *channel;
    struct t_irc_nick *ptr_nick;
    char *buf, str_prefix[64];
    int length;

    /* make C compiler happy */
    (void) data;
    (void) item;
    (void) window;
    (void) extra_info;

    if (!buffer)
        return NULL;

    irc_buffer_get_server_and_channel (buffer, &server, &channel);
    if (!server || !server->nick)
        return NULL;

    /* build prefix */
    str_prefix[0] = '\0';
    if (weechat_config_boolean (irc_config_look_item_nick_prefix)
        && channel
        && (channel->type == IRC_CHANNEL_TYPE_CHANNEL))
    {
        ptr_nick = irc_nick_search (server, channel, server->nick);
        if (ptr_nick)
        {
            if (ptr_nick->prefix[0] != ' ')
            {
                snprintf (str_prefix, sizeof (str_prefix), "%s%s",
                          weechat_color (irc_nick_get_prefix_color_name (server, ptr_nick->prefix[0])),
                          ptr_nick->prefix);
            }
        }
    }

    /* build bar item */
    length = 64 + strlen (server->nick) + 64 +
        ((server->nick_modes) ? strlen (server->nick_modes) : 0) + 64 + 1;

    buf = malloc (length);
    if (buf)
    {
        if (weechat_config_boolean (irc_config_look_item_nick_modes)
            && server->nick_modes && server->nick_modes[0])
        {
            snprintf (buf, length, "%s%s%s%s(%s%s%s)",
                      str_prefix,
                      IRC_COLOR_INPUT_NICK,
                      server->nick,
                      IRC_COLOR_BAR_DELIM,
                      IRC_COLOR_ITEM_NICK_MODES,
                      server->nick_modes,
                      IRC_COLOR_BAR_DELIM);
        }
        else
        {
            snprintf (buf, length, "%s%s%s",
                      str_prefix,
                      IRC_COLOR_INPUT_NICK,
                      server->nick);
        }
    }

    return buf;
}
Exemplo n.º 4
0
struct t_infolist *
irc_info_infolist_irc_nick_cb (void *data, const char *infolist_name,
                               void *pointer, const char *arguments)
{
    struct t_infolist *ptr_infolist;
    struct t_irc_server *ptr_server;
    struct t_irc_channel *ptr_channel;
    struct t_irc_nick *ptr_nick;
    char **argv;
    int argc;

    /* make C compiler happy */
    (void) data;
    (void) infolist_name;

    if (!arguments || !arguments[0])
        return NULL;

    ptr_server = NULL;
    ptr_channel = NULL;
    argv = dogechat_string_split (arguments, ",", 0, 0, &argc);
    if (!argv)
        return NULL;

    if (argc >= 2)
    {
        ptr_server = irc_server_search (argv[0]);
        if (!ptr_server)
        {
            dogechat_string_free_split (argv);
            return NULL;
        }
        ptr_channel = irc_channel_search (ptr_server, argv[1]);
        if (!ptr_channel)
        {
            dogechat_string_free_split (argv);
            return NULL;
        }
        if (!pointer && (argc >= 3))
        {
            pointer = irc_nick_search (ptr_server, ptr_channel,
                                       argv[2]);
            if (!pointer)
            {
                dogechat_string_free_split (argv);
                return NULL;
            }
        }
    }
    dogechat_string_free_split (argv);

    if (!ptr_server || !ptr_channel)
        return NULL;

    if (pointer && !irc_nick_valid (ptr_channel, pointer))
        return NULL;

    ptr_infolist = dogechat_infolist_new ();
    if (!ptr_infolist)
        return NULL;

    if (pointer)
    {
        /* build list with only one nick */
        if (!irc_nick_add_to_infolist (ptr_infolist,
                                       pointer))
        {
            dogechat_infolist_free (ptr_infolist);
            return NULL;
        }
        return ptr_infolist;
    }
    else
    {
        /* build list with all nicks of channel */
        for (ptr_nick = ptr_channel->nicks; ptr_nick;
             ptr_nick = ptr_nick->next_nick)
        {
            if (!irc_nick_add_to_infolist (ptr_infolist,
                                           ptr_nick))
            {
                dogechat_infolist_free (ptr_infolist);
                return NULL;
            }
        }
        return ptr_infolist;
    }

    return NULL;
}
Exemplo n.º 5
0
int
irc_mode_channel_set (struct t_irc_server *server,
                      struct t_irc_channel *channel,
                      const char *modes)
{
    char *pos_args, *str_modes, set_flag, **argv, *pos, *ptr_arg, chanmode_type;
    int argc, current_arg, update_channel_modes, channel_modes_updated;
    int smart_filter;
    struct t_irc_nick *ptr_nick;

    if (!server || !channel || !modes)
        return 0;

    channel_modes_updated = 0;
    argc = 0;
    argv = NULL;
    pos_args = strchr (modes, ' ');
    if (pos_args)
    {
        str_modes = weechat_strndup (modes, pos_args - modes);
        if (!str_modes)
            return 0;
        pos_args++;
        while (pos_args[0] == ' ')
            pos_args++;
        argv = weechat_string_split (pos_args, " ", 0, 0, &argc);
    }
    else
    {
        str_modes = strdup (modes);
        if (!str_modes)
            return 0;
    }

    current_arg = 0;

    smart_filter = (weechat_config_boolean (irc_config_look_smart_filter)
                    && weechat_config_string (irc_config_look_smart_filter_mode)
                    && weechat_config_string (irc_config_look_smart_filter_mode)[0]) ? 1 : 0;

    if (str_modes && str_modes[0])
    {
        set_flag = '+';
        pos = str_modes;
        while (pos && pos[0])
        {
            switch (pos[0])
            {
                case ':':
                case ' ':
                    break;
                case '+':
                    set_flag = '+';
                    break;
                case '-':
                    set_flag = '-';
                    break;
                default:
                    update_channel_modes = 1;
                    chanmode_type = irc_mode_get_chanmode_type (server, pos[0]);
                    ptr_arg = NULL;
                    switch (chanmode_type)
                    {
                        case 'A': /* always argument */
                            update_channel_modes = 0;
                            ptr_arg = (current_arg < argc) ?
                                argv[current_arg] : NULL;
                            break;
                        case 'B': /* always argument */
                            ptr_arg = (current_arg < argc) ?
                                argv[current_arg] : NULL;
                            break;
                        case 'C': /* argument if set */
                            ptr_arg = ((set_flag == '+') && (current_arg < argc)) ?
                                argv[current_arg] : NULL;
                            break;
                        case 'D': /* no argument */
                            break;
                    }
                    if (ptr_arg)
                        current_arg++;

                    if (smart_filter && !irc_mode_smart_filtered (pos[0]))
                        smart_filter = 0;

                    if (pos[0] == 'k')
                    {
                        /* channel key */
                        if (set_flag == '-')
                        {
                            if (channel->key)
                            {
                                free (channel->key);
                                channel->key = NULL;
                            }
                        }
                        else if ((set_flag == '+')
                                 && ptr_arg && (strcmp (ptr_arg, "*") != 0))
                        {
                            /* replace key for +k, but ignore "*" as new key */
                            if (channel->key)
                                free (channel->key);
                            channel->key = strdup (ptr_arg);
                        }
                    }
                    else if (pos[0] == 'l')
                    {
                        /* channel limit */
                        if (set_flag == '-')
                            channel->limit = 0;
                        if ((set_flag == '+') && ptr_arg)
                        {
                            channel->limit = atoi (ptr_arg);
                        }
                    }
                    else if ((chanmode_type != 'A')
                             && (irc_server_get_prefix_mode_index (server,
                                                                   pos[0]) >= 0))
                    {
                        /* mode for nick */
                        update_channel_modes = 0;
                        if (ptr_arg)
                        {
                            ptr_nick = irc_nick_search (server, channel,
                                                        ptr_arg);
                            if (ptr_nick)
                            {
                                irc_nick_set_mode (server, channel, ptr_nick,
                                                   (set_flag == '+'), pos[0]);
                                if (smart_filter
                                    && irc_channel_nick_speaking_time_search (server,
                                                                              channel,
                                                                              ptr_nick->name,
                                                                              1))
                                {
                                    smart_filter = 0;
                                }
                            }
                        }
                    }
                    if (update_channel_modes)
                    {
                        irc_mode_channel_update (server, channel, set_flag,
                                                 pos[0], ptr_arg);
                        channel_modes_updated = 1;
                    }
                    break;
            }
            pos++;
        }
    }

    if (str_modes)
        free (str_modes);
    if (argv)
        weechat_string_free_split (argv);

    if (channel_modes_updated)
        weechat_bar_item_update ("buffer_modes");

    return smart_filter;
}