Exemple #1
0
void
irc_input_user_message_display (struct t_gui_buffer *buffer, const char *text)
{
    struct t_irc_nick *ptr_nick;
    char *text_decoded;

    text_decoded = irc_color_decode (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);
        }

        weechat_printf_tags (buffer,
                             irc_protocol_tags ("privmsg",
                                                "notify_none,no_highlight",
                                                (ptr_nick) ? ptr_nick->name : ptr_server->nick),
                             "%s%s",
                             irc_nick_as_prefix (ptr_server,
                                                 (ptr_nick) ? ptr_nick : NULL,
                                                 (ptr_nick) ? NULL : ptr_server->nick,
                                                 IRC_COLOR_CHAT_NICK_SELF),
                             (text_decoded) ? text_decoded : text);
    }

    if (text_decoded)
        free (text_decoded);
}
Exemple #2
0
void
irc_ctcp_display_request (struct t_irc_server *server,
                          const char *command,
                          struct t_irc_channel *channel,
                          const char *nick,  const char *ctcp,
                          const char *arguments,
                          const char *reply)
{
    /* CTCP blocked and user doesn't want to see message? then just return */
    if (reply && !reply[0]
        && !weechat_config_boolean (irc_config_look_display_ctcp_blocked))
        return;

    weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, nick,
                                                          NULL, "ctcp",
                                                          (channel) ? channel->buffer : NULL),
                         irc_protocol_tags (command, "irc_ctcp", NULL),
                         _("%sCTCP requested by %s%s%s: %s%s%s%s%s%s"),
                         weechat_prefix ("network"),
                         IRC_COLOR_CHAT_NICK,
                         nick,
                         IRC_COLOR_RESET,
                         IRC_COLOR_CHAT_CHANNEL,
                         ctcp,
                         IRC_COLOR_RESET,
                         (arguments) ? " " : "",
                         (arguments) ? arguments : "",
                         (reply && !reply[0]) ? _(" (blocked)") : "");
}
Exemple #3
0
void
irc_ctcp_reply_to_nick (struct t_irc_server *server,
                        const char *command,
                        struct t_irc_channel *channel,
                        const char *nick, const char *ctcp,
                        const char *arguments)
{
    struct t_hashtable *hashtable;
    int number;
    char hash_key[32];
    const char *str_args;

    hashtable = irc_server_sendf (server,
                                  IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE,
                                  NULL,
                                  "NOTICE %s :\01%s%s%s\01",
                                  nick, ctcp,
                                  (arguments) ? " " : "",
                                  (arguments) ? arguments : "");

    if (hashtable)
    {
        if (weechat_config_boolean (irc_config_look_display_ctcp_reply))
        {
            number = 1;
            while (1)
            {
                snprintf (hash_key, sizeof (hash_key), "args%d", number);
                str_args = weechat_hashtable_get (hashtable, hash_key);
                if (!str_args)
                    break;
                weechat_printf_tags (irc_msgbuffer_get_target_buffer (server,
                                                                      nick,
                                                                      NULL,
                                                                      "ctcp",
                                                                      (channel) ? channel->buffer : NULL),
                                     irc_protocol_tags (command,
                                                        "irc_ctcp,irc_ctcp_reply,"
                                                        "notify_none,no_highlight",
                                                        NULL),
                                     _("%sCTCP reply to %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,
                                     ctcp,
                                     (str_args[0]) ? IRC_COLOR_RESET : "",
                                     (str_args[0]) ? " " : "",
                                     str_args);
                number++;
            }
        }
        weechat_hashtable_free (hashtable);
    }
}
Exemple #4
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);
}
Exemple #5
0
void
irc_ctcp_recv (struct t_irc_server *server, 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_tags (channel->buffer,
                                     irc_protocol_tags (command,
                                                        (nick_is_me) ?
                                                        "irc_action,notify_none,no_highlight" :
                                                        "irc_action,notify_message",
                                                        nick),
                                     "%s%s%s%s%s%s",
                                     weechat_prefix ("action"),
                                     (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_tags (ptr_channel->buffer,
                                         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, 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, 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_tags (irc_msgbuffer_get_target_buffer (server,
                                                                          nick,
                                                                          NULL,
                                                                          "ctcp",
                                                                          (channel) ? channel->buffer : NULL),
                                         irc_protocol_tags (command,
                                                            "irc_ctcp",
                                                            NULL),
                                         _("%sUnknown CTCP requested by %s%s%s: "
                                           "%s%s%s%s%s"),
                                         weechat_prefix ("network"),
                                         IRC_COLOR_CHAT_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;
    }
}
Exemple #6
0
void
irc_ctcp_display_reply_from_nick (struct t_irc_server *server,
                                  const char *command, const char *nick,
                                  char *arguments)
{
    char *pos_end, *pos_space, *pos_args, *pos_usec;
    struct timeval tv;
    long sec1, usec1, sec2, usec2, difftime;

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

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

                    gettimeofday (&tv, NULL);
                    sec1 = atol (pos_args);
                    usec1 = atol (pos_usec + 1);
                    sec2 = tv.tv_sec;
                    usec2 = tv.tv_usec;

                    difftime = ((sec2 * 1000000) + usec2) -
                        ((sec1 * 1000000) + usec1);
                    weechat_printf_tags (irc_msgbuffer_get_target_buffer (server,
                                                                          nick,
                                                                          NULL,
                                                                          "ctcp",
                                                                          NULL),
                                         irc_protocol_tags (command,
                                                            "irc_ctcp",
                                                            NULL),
                                         _("%sCTCP reply from %s%s%s: %s%s%s "
                                           "%ld.%ld %s"),
                                         weechat_prefix ("network"),
                                         IRC_COLOR_CHAT_NICK,
                                         nick,
                                         IRC_COLOR_RESET,
                                         IRC_COLOR_CHAT_CHANNEL,
                                         arguments + 1,
                                         IRC_COLOR_RESET,
                                         difftime / 1000000,
                                         (difftime % 1000000) / 1000,
                                         (NG_("second", "seconds",
                                              (difftime / 1000000))));

                    pos_usec[0] = ' ';
                }
            }
            else
            {
                weechat_printf_tags (irc_msgbuffer_get_target_buffer (server,
                                                                      nick,
                                                                      NULL,
                                                                      "ctcp",
                                                                      NULL),
                                     irc_protocol_tags (command,
                                                        "irc_ctcp",
                                                        NULL),
                                     _("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
                                     weechat_prefix ("network"),
                                     IRC_COLOR_CHAT_NICK,
                                     nick,
                                     IRC_COLOR_RESET,
                                     IRC_COLOR_CHAT_CHANNEL,
                                     arguments + 1,
                                     IRC_COLOR_RESET,
                                     " ",
                                     pos_args);
            }
            pos_space[0] = ' ';
        }
        else
        {
            weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, nick,
                                                                  NULL, "ctcp",
                                                                  NULL),
                                 irc_protocol_tags (command, NULL, NULL),
                                 _("%sCTCP reply from %s%s%s: %s%s%s%s%s"),
                                 weechat_prefix ("network"),
                                 IRC_COLOR_CHAT_NICK,
                                 nick,
                                 IRC_COLOR_RESET,
                                 IRC_COLOR_CHAT_CHANNEL,
                                 arguments + 1,
                                 "",
                                 "",
                                 "");
        }

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

        arguments = (pos_end) ? pos_end + 1 : NULL;
    }
}