Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irc: restore away status and message when connecting to away ZNC (#1059) #1302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/plugins/irc/irc-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "irc-sasl.h"
#include "irc-server.h"
#include "irc-notify.h"
#include "irc-redirect.h"


/*
Expand Down Expand Up @@ -3106,6 +3107,8 @@ IRC_PROTOCOL_CALLBACK(305)
server->is_away = 0;
server->away_time = 0;

/* refresh localvars and bar item */
irc_server_set_away (server, server->nick, 0);
weechat_bar_item_update ("away");

return WEECHAT_RC_OK;
Expand Down Expand Up @@ -3137,6 +3140,12 @@ IRC_PROTOCOL_CALLBACK(306)
server->is_away = 1;
server->away_time = time (NULL);

/* whois own nick to get away message */
irc_redirect_new (server, "whois", "away", 1, server->nick, 0, "301");
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
"WHOIS :%s", server->nick);

/* refresh bar item */
weechat_bar_item_update ("away");

return WEECHAT_RC_OK;
Expand Down
83 changes: 83 additions & 0 deletions src/plugins/irc/irc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -5320,6 +5320,89 @@ irc_server_set_away (struct t_irc_server *server, const char *nick, int is_away)
}
}

/*
* Callback for hsignal on redirected command "whois" from numeric 306.
*/

int
irc_server_away_whois_cb (const void *pointer, void *data, const char *signal,
struct t_hashtable *hashtable)
{
/* copied from irc_notify_hsignal_cb */
const char *error, *server, *pattern, *command, *output;
char **messages, *irc_cmd, *arguments;
char *ptr_args, *pos;
int num_messages;
struct t_irc_server *ptr_server;

/* make C compiler happy */
(void) pointer;
(void) data;
(void) signal;

error = weechat_hashtable_get (hashtable, "error");
server = weechat_hashtable_get (hashtable, "server");
pattern = weechat_hashtable_get (hashtable, "pattern");
command = weechat_hashtable_get (hashtable, "command");
output = weechat_hashtable_get (hashtable, "output");

/* if there is an error on redirection, just ignore result */
if (error && error[0])
return WEECHAT_RC_OK;

/* missing things in redirection */
if (!server || !pattern || !command || !output)
return WEECHAT_RC_OK;

/* search server */
ptr_server = irc_server_search (server);
if (!ptr_server)
return WEECHAT_RC_OK;

/* search for start of arguments in command sent to server */
ptr_args = strchr (command, ' ');
if (!ptr_args)
return WEECHAT_RC_OK;
ptr_args++;
while ((ptr_args[0] == ' ') || (ptr_args[0] == ':'))
{
ptr_args++;
}
if (!ptr_args[0])
return WEECHAT_RC_OK;

/* read output of command */
messages = weechat_string_split (output, "\n", 0, 0, &num_messages);
if (messages && (num_messages > 0))
{
irc_message_parse (ptr_server, messages[0], NULL, NULL,
NULL, NULL, &irc_cmd, NULL, &arguments,
NULL, NULL, NULL, NULL, NULL);
if (irc_cmd && arguments)
{
/* away message */
pos = strchr (arguments, ':');
if (pos)
{
pos++;
/* nick is away */
ptr_server->away_message = strdup (pos);

/* refresh localvars and bar item */
irc_server_set_away (ptr_server, ptr_server->nick, 1);
weechat_bar_item_update ("away");
}
}
if (irc_cmd)
free (irc_cmd);
if (arguments)
free (arguments);
}

return WEECHAT_RC_OK;
}


/*
* Callback called when user sends (file or chat) to someone and that xfer
* plugin successfully initialized xfer and is ready for sending.
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/irc/irc-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ extern void irc_server_set_away (struct t_irc_server *server, const char *nick,
int is_away);
extern void irc_server_remove_away (struct t_irc_server *server);
extern void irc_server_check_away (struct t_irc_server *server);
extern int irc_server_away_whois_cb (const void *pointer, void *data,
const char *signal,
struct t_hashtable *hashtable);
extern void irc_server_switch_address (struct t_irc_server *server,
int connection);
extern void irc_server_disconnect (struct t_irc_server *server,
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/irc/irc.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_hsignal ("irc_redirect_command",
&irc_redirect_command_hsignal_cb, NULL, NULL);

weechat_hook_hsignal ("irc_redirection_away_whois",
&irc_server_away_whois_cb, NULL, NULL);

/* modifiers */
weechat_hook_modifier ("irc_color_decode",
&irc_color_modifier_cb, NULL, NULL);
Expand Down