void irc_notify_check_now (struct t_irc_notify *notify) { /* don't send anything if we are not connected to the server */ if (!notify->server->is_connected) return; if (notify->server->monitor > 0) { /* send MONITOR for nick */ irc_server_sendf (notify->server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "MONITOR + %s", notify->nick); } else { /* send ISON for nick (MONITOR not supported on server) */ irc_redirect_new (notify->server, "ison", "notify", 1, NULL, 0, NULL); irc_server_sendf (notify->server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "ISON :%s", notify->nick); } if (notify->check_away) { /* send WHOIS for nick */ irc_redirect_new (notify->server, "whois", "notify", 1, notify->nick, 0, "301,401"); irc_server_sendf (notify->server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "WHOIS :%s", notify->nick); } }
int irc_input_data (struct t_gui_buffer *buffer, const char *input_data, int flags) { const char *ptr_data; char *data_with_colors, *msg; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (buffer == irc_raw_buffer) { if (dogechat_strcasecmp (input_data, "q") == 0) dogechat_buffer_close (buffer); } else { /* * if send unknown commands is enabled and that input data is a * command, then send this command to IRC server */ if (dogechat_config_boolean (irc_config_network_send_unknown_commands) && !dogechat_string_input_for_buffer (input_data)) { if (ptr_server) { irc_server_sendf (ptr_server, flags, NULL, "%s", dogechat_utf8_next_char (input_data)); } return DOGECHAT_RC_OK; } if (ptr_channel) { ptr_data = dogechat_string_input_for_buffer (input_data); if (!ptr_data) ptr_data = input_data; data_with_colors = irc_color_encode ( ptr_data, dogechat_config_boolean (irc_config_network_colors_send)); msg = strdup ((data_with_colors) ? data_with_colors : ptr_data); if (msg) { irc_input_send_user_message (buffer, flags, NULL, msg); free (msg); } if (data_with_colors) free (data_with_colors); } else { dogechat_printf (buffer, _("%s%s: this buffer is not a channel!"), dogechat_prefix ("error"), IRC_PLUGIN_NAME); } } return DOGECHAT_RC_OK; }
void irc_input_send_user_message (struct t_gui_buffer *buffer, char *text) { int max_length; char *pos, *pos_max, *last_space, *pos_next, *next, saved_char; IRC_GET_SERVER_CHANNEL(buffer); if (!ptr_server || !ptr_channel || !text || !text[0]) return; if (!ptr_server->is_connected) { weechat_printf (buffer, _("%s%s: you are not connected to server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } next = NULL; last_space = NULL; saved_char = '\0'; max_length = 512 - 16 - 65 - 10 - strlen (ptr_server->nick) - strlen (ptr_channel->name); if (max_length > 0) { if ((int)strlen (text) > max_length) { pos = text; pos_max = text + max_length; while (pos && pos[0]) { if (pos[0] == ' ') last_space = pos; pos_next = weechat_utf8_next_char (pos); if (pos_next > pos_max) break; pos = pos_next; } if (last_space && (last_space < pos)) pos = last_space + 1; saved_char = pos[0]; pos[0] = '\0'; next = pos; } } irc_server_sendf (ptr_server, 1, "PRIVMSG %s :%s", ptr_channel->name, text); irc_input_user_message_display (buffer, text); if (next) { next[0] = saved_char; irc_input_send_user_message (buffer, next); } }
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); } }
int irc_notify_timer_ison_cb (const void *pointer, void *data, int remaining_calls) { char *message, hash_key[32]; const char *str_message; int num_nicks, number; struct t_irc_server *ptr_server; struct t_hashtable *hashtable; /* make C compiler happy */ (void) pointer; (void) data; (void) remaining_calls; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->is_connected && ptr_server->notify_list && (ptr_server->monitor == 0)) { message = irc_notify_build_message_with_nicks (ptr_server, "ISON :", " ", &num_nicks); if (message && (num_nicks > 0)) { hashtable = irc_message_split (ptr_server, message); if (hashtable) { number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "msg%d", number); str_message = weechat_hashtable_get (hashtable, hash_key); if (!str_message) break; irc_redirect_new (ptr_server, "ison", "notify", 1, NULL, 0, NULL); irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "%s", str_message); number++; } weechat_hashtable_free (hashtable); } } if (message) free (message); } } return WEECHAT_RC_OK; }
int irc_input_data_cb (void *data, struct t_gui_buffer *buffer, const char *input_data) { const char *ptr_data; char *data_with_colors, *msg; /* make C compiler happy */ (void) data; IRC_GET_SERVER_CHANNEL(buffer); /* if send unknown commands is enabled and that input data is a command, then send this command to IRC server */ if (weechat_config_boolean (irc_config_network_send_unknown_commands) && (input_data[0] == '/') && (input_data[1] != '/')) { if (ptr_server) irc_server_sendf (ptr_server, 1, input_data + 1); return WEECHAT_RC_OK; } if (ptr_channel) { ptr_data = ((input_data[0] == '/') && (input_data[1] == '/')) ? input_data + 1 : input_data; data_with_colors = irc_color_encode (ptr_data, weechat_config_boolean (irc_config_network_colors_send)); msg = strdup ((data_with_colors) ? data_with_colors : ptr_data); if (msg) { irc_input_send_user_message (buffer, msg); free (msg); } if (data_with_colors) free (data_with_colors); } else { weechat_printf (buffer, _("%s%s: this buffer is not a channel!"), weechat_prefix ("error"), IRC_PLUGIN_NAME); } return WEECHAT_RC_OK; }
void irc_notify_free_all (struct t_irc_server *server) { /* remove all monitored nicks */ if ((server->monitor > 0) && (server->is_connected) && !irc_signal_upgrade_received) { irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "MONITOR C"); } /* free notify list */ while (server->notify_list) { irc_notify_free (server, server->notify_list, 0); } }
void irc_notify_free (struct t_irc_server *server, struct t_irc_notify *notify, int remove_monitor) { if (!server || !notify) return; (void) weechat_hook_signal_send ("irc_notify_removing", WEECHAT_HOOK_SIGNAL_POINTER, notify); /* free data */ if (notify->nick) { if ((server->monitor > 0) && remove_monitor && (server->is_connected) && !irc_signal_upgrade_received) { /* remove one monitored nick */ irc_server_sendf (notify->server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "MONITOR - %s", notify->nick); } free (notify->nick); } if (notify->away_message) free (notify->away_message); /* remove notify from list */ if (notify->prev_notify) (notify->prev_notify)->next_notify = notify->next_notify; if (notify->next_notify) (notify->next_notify)->prev_notify = notify->prev_notify; if (server->notify_list == notify) server->notify_list = notify->next_notify; if (server->last_notify == notify) server->last_notify = notify->prev_notify; free (notify); if (server->notify_count > 0) server->notify_count--; (void) weechat_hook_signal_send ("irc_notify_removed", WEECHAT_HOOK_SIGNAL_STRING, NULL); }
int irc_notify_timer_whois_cb (const void *pointer, void *data, int remaining_calls) { struct t_irc_server *ptr_server; struct t_irc_notify *ptr_notify, *ptr_next_notify; /* make C compiler happy */ (void) pointer; (void) data; (void) remaining_calls; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->is_connected && ptr_server->notify_list) { ptr_notify = ptr_server->notify_list; while (ptr_notify) { ptr_next_notify = ptr_notify->next_notify; if (ptr_notify->check_away) { /* * redirect whois, and get only 2 messages: * 301: away message * 401: no such nick/channel */ irc_redirect_new (ptr_server, "whois", "notify", 1, ptr_notify->nick, 0, "301,401"); irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "WHOIS :%s", ptr_notify->nick); } ptr_notify = ptr_next_notify; } } } return WEECHAT_RC_OK; }
void irc_input_send_user_message (struct t_gui_buffer *buffer, int flags, const char *tags, char *message) { int number, action; char hash_key[32], *str_args; struct t_hashtable *hashtable; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (!ptr_server || !ptr_channel || !message || !message[0]) return; if (!ptr_server->is_connected) { weechat_printf (buffer, _("%s%s: you are not connected to server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } hashtable = irc_server_sendf (ptr_server, flags | IRC_SERVER_SEND_RETURN_HASHTABLE, tags, "PRIVMSG %s :%s", ptr_channel->name, message); if (hashtable) { action = (strncmp (message, "\01ACTION ", 8) == 0); 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; irc_input_user_message_display (buffer, action, str_args); number++; } weechat_hashtable_free (hashtable); } }
void irc_notify_send_monitor (struct t_irc_server *server) { struct t_hashtable *hashtable; char *message, hash_key[32]; const char *str_message; int num_nicks, number; message = irc_notify_build_message_with_nicks (server, "MONITOR + ", ",", &num_nicks); if (message && (num_nicks > 0)) { hashtable = irc_message_split (server, message); if (hashtable) { number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "msg%d", number); str_message = weechat_hashtable_get (hashtable, hash_key); if (!str_message) break; irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "%s", str_message); number++; } weechat_hashtable_free (hashtable); } } if (message) free (message); }