diff options
author | Timo Sirainen <cras@irssi.org> | 2001-01-01 16:57:25 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-01-01 16:57:25 +0000 |
commit | 2ae679be088b0c726bf1c482fd22ee3231c94349 (patch) | |
tree | 804506241870ee73d6506c731a4e72f7f7d90e1b /src | |
parent | 219c83ae6ab83e546fe18bc697ef3a1ab3d12caa (diff) | |
download | irssi-2ae679be088b0c726bf1c482fd22ee3231c94349.zip |
added "message own_public" and "message own_private" events that are
sent when /msg command is used. this way we don't need to parse the
/msg's options everywhere. also efnet @#channels support works now better.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1041 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/core/chat-commands.c | 9 | ||||
-rw-r--r-- | src/core/expandos.c | 42 | ||||
-rw-r--r-- | src/core/ignore.c | 2 | ||||
-rw-r--r-- | src/core/server-rec.h | 4 | ||||
-rw-r--r-- | src/fe-common/core/chat-completion.c | 81 | ||||
-rw-r--r-- | src/fe-common/core/fe-ignore.c | 4 | ||||
-rw-r--r-- | src/fe-common/core/fe-log.c | 2 | ||||
-rw-r--r-- | src/fe-common/core/fe-messages.c | 98 | ||||
-rw-r--r-- | src/fe-common/core/fe-messages.h | 2 | ||||
-rw-r--r-- | src/fe-common/irc/Makefile.am | 1 | ||||
-rw-r--r-- | src/fe-common/irc/fe-common-irc.c | 5 | ||||
-rw-r--r-- | src/fe-common/irc/fe-events.c | 12 | ||||
-rw-r--r-- | src/fe-common/irc/fe-irc-messages.c | 81 | ||||
-rw-r--r-- | src/irc/core/irc-servers.c | 4 | ||||
-rw-r--r-- | src/irc/core/irc.h | 4 |
15 files changed, 210 insertions, 141 deletions
diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 969be382..22dc9e4f 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -62,7 +62,7 @@ static void cmd_join(const char *data, SERVER_REC *server) static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { GHashTable *optlist; - char *target, *msg; + char *target, *origtarget, *msg; void *free_arg; int free_ret; @@ -78,16 +78,23 @@ static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) if (server == NULL || !server->connected) cmd_param_error(CMDERR_NOT_CONNECTED); + origtarget = target; free_ret = FALSE; if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { target = parse_special(&target, server, item, NULL, &free_ret, NULL, 0); + if (target != NULL && *target == '\0') + target = NULL; } else if (strcmp(target, "*") == 0 && item != NULL) target = item->name; if (target != NULL) server->send_message(server, target, msg); + signal_emit(target != NULL && server->ischannel(target) ? + "message own_public" : "message own_private", 4, + server, msg, target, origtarget); + if (free_ret && target != NULL) g_free(target); cmd_params_free(free_arg); } diff --git a/src/core/expandos.c b/src/core/expandos.c index 006dd443..a0fd3a28 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -391,13 +391,6 @@ static char *expando_chatnet(SERVER_REC *server, void *item, int *free_ret) return server == NULL ? "" : server->connrec->chatnet; } -static void sig_message_private(SERVER_REC *server, const char *msg, - const char *nick, const char *address) -{ - g_free_not_null(last_privmsg_from); - last_privmsg_from = g_strdup(nick); -} - static void sig_message_public(SERVER_REC *server, const char *msg, const char *nick, const char *address, const char *target) @@ -406,28 +399,27 @@ static void sig_message_public(SERVER_REC *server, const char *msg, last_public_from = g_strdup(nick); } -static void cmd_msg(const char *data, SERVER_REC *server) +static void sig_message_private(SERVER_REC *server, const char *msg, + const char *nick, const char *address) { - GHashTable *optlist; - char *target, *msg; - void *free_arg; - - g_return_if_fail(data != NULL); + g_free_not_null(last_privmsg_from); + last_privmsg_from = g_strdup(nick); +} - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | - PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, - "msg", &optlist, &target, &msg)) - return; +static void sig_message_own_private(SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) +{ + g_return_if_fail(server != NULL); + g_return_if_fail(msg != NULL); - if (*target != '\0' && *msg != '\0' && - !server->ischannel(*target) && isalpha(*target)) { - g_free_not_null(last_sent_msg); + if (target != NULL) { + if (target != last_sent_msg) { + g_free_not_null(last_sent_msg); + last_sent_msg = g_strdup(target); + } g_free_not_null(last_sent_msg_body); - last_sent_msg = g_strdup(target); last_sent_msg_body = g_strdup(msg); } - - cmd_params_free(free_arg); } static int sig_timer(void) @@ -532,9 +524,9 @@ void expandos_init(void) "window server changed", EXPANDO_ARG_WINDOW, NULL); timer_tag = g_timeout_add(1000, (GSourceFunc) sig_timer, NULL); - signal_add("command msg", (SIGNAL_FUNC) cmd_msg); signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message private", (SIGNAL_FUNC) sig_message_private); + signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private); } void expandos_deinit(void) @@ -559,5 +551,5 @@ void expandos_deinit(void) g_source_remove(timer_tag); signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); - signal_remove("command msg", (SIGNAL_FUNC) cmd_msg); + signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private); } diff --git a/src/core/ignore.c b/src/core/ignore.c index 81df32ba..5d94ad15 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -65,7 +65,7 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host, g_return_val_if_fail(server != NULL, 0); chanrec = (channel != NULL && server != NULL && - server->ischannel(*channel)) ? + server->ischannel(channel)) ? channel_find(server, channel) : NULL; best_mask = 0; best_patt = 0; best_ignore = FALSE; diff --git a/src/core/server-rec.h b/src/core/server-rec.h index 53b9f7f0..871cb80a 100644 --- a/src/core/server-rec.h +++ b/src/core/server-rec.h @@ -53,8 +53,8 @@ GSList *queries; void (*channels_join)(SERVER_REC *server, const char *data, int automatic); /* returns true if `flag' indicates a nick flag (op/voice/halfop) */ int (*isnickflag)(char flag); -/* returns true if `flag' indicates a channel */ -int (*ischannel)(char flag); +/* returns true if `data' indicates a channel */ +int (*ischannel)(const char *data); /* returns all nick flag characters in order op, voice, halfop. If some of them aren't supported '\0' can be used. */ const char *(*get_nick_flags)(void); diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c index 2d108d1c..5989d90b 100644 --- a/src/fe-common/core/chat-completion.c +++ b/src/fe-common/core/chat-completion.c @@ -127,53 +127,46 @@ static void sig_message_private(SERVER_REC *server, const char *msg, SERVER_LAST_MSG_ADD(server, nick); } -static void cmd_msg(const char *data, SERVER_REC *server) +static void sig_message_own_public(SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) { - GHashTable *optlist; - NICK_REC *nick; - char *target, *msg, *p; - void *free_arg; + CHANNEL_REC *channel; + NICK_REC *nick; + char *p, *msgnick; - g_return_if_fail(data != NULL); + g_return_if_fail(server != NULL); + g_return_if_fail(msg != NULL); + if (target == NULL) return; - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | - PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, - "msg", &optlist, &target, &msg)) + channel = channel_find(server, target); + if (channel == NULL) return; - server = cmd_options_get_server("msg", optlist, server); - - if (server != NULL && *target != '\0' && *msg != '\0' && - query_find(server, target) == NULL) { - CHANNEL_REC *channel = channel_find(server, target); - MODULE_CHANNEL_REC *mchannel; - - mchannel = MODULE_DATA(channel); - - if (channel != NULL) { - /* channel msg - if first word in line is nick, - add it to lastmsgs */ - p = strchr(msg, ' '); - if (p != NULL && p != msg) { - *p = '\0'; - nick = nicklist_find(channel, msg); - if (nick == NULL) { - /* probably ':' or ',' or some other - char after nick, try without it */ - p[-1] = '\0'; - nick = nicklist_find(channel, msg); - } - if (nick != NULL && nick != channel->ownnick) { - CHANNEL_LAST_MSG_ADD(channel, - nick->nick, TRUE); - } - } - } else if (!server->ischannel(*target)) { - /* private msg */ - SERVER_LAST_MSG_ADD(server, target); + + /* channel msg - if first word in line is nick, + add it to lastmsgs */ + p = strchr(msg, ' '); + if (p != NULL && p != msg) { + msgnick = g_strndup(msg, (int) (p-msg)); + nick = nicklist_find(channel, msgnick); + if (nick == NULL) { + /* probably ':' or ',' or some other + char after nick, try without it */ + msgnick[strlen(msgnick)-1] = '\0'; + nick = nicklist_find(channel, msgnick); } + if (nick != NULL && nick != channel->ownnick) + CHANNEL_LAST_MSG_ADD(channel, nick->nick, TRUE); } +} + +static void sig_message_own_private(SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) +{ + g_return_if_fail(server != NULL); + g_return_if_fail(msg != NULL); - cmd_params_free(free_arg); + if (target != NULL && query_find(server, target) == NULL) + SERVER_LAST_MSG_ADD(server, target); } static void sig_nick_removed(CHANNEL_REC *channel, NICK_REC *nick) @@ -462,7 +455,7 @@ static void sig_complete_word(GList **list, WINDOW_REC *window, if (server == NULL && servers != NULL) server = servers->data; - if (server != NULL && server->ischannel(*word)) { + if (server != NULL && server->ischannel(word)) { /* probably completing a channel name */ *list = completion_get_channels(window->active_server, word); return; @@ -731,7 +724,8 @@ void chat_completion_init(void) signal_add("complete command server", (SIGNAL_FUNC) sig_complete_connect); signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message private", (SIGNAL_FUNC) sig_message_private); - signal_add("command msg", (SIGNAL_FUNC) cmd_msg); + signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private); signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_removed); signal_add("nicklist changed", (SIGNAL_FUNC) sig_nick_changed); signal_add("send text", (SIGNAL_FUNC) event_text); @@ -748,7 +742,8 @@ void chat_completion_deinit(void) signal_remove("complete command server", (SIGNAL_FUNC) sig_complete_connect); signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); - signal_remove("command msg", (SIGNAL_FUNC) cmd_msg); + signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private); signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_removed); signal_remove("nicklist changed", (SIGNAL_FUNC) sig_nick_changed); signal_remove("send text", (SIGNAL_FUNC) event_text); diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c index db2d4ad3..3129370a 100644 --- a/src/fe-common/core/fe-ignore.c +++ b/src/fe-common/core/fe-ignore.c @@ -176,7 +176,7 @@ static void cmd_ignore(const char *data) if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); if (active_win->active_server != NULL && - active_win->active_server->ischannel(*mask)) { + active_win->active_server->ischannel(mask)) { chanarg = mask; mask = NULL; } @@ -264,7 +264,7 @@ static void cmd_unignore(const char *data) const char *chans[2] = { "*", NULL }; if (active_win->active_server != NULL && - active_win->active_server->ischannel(*data)) { + active_win->active_server->ischannel(data)) { chans[0] = data; data = NULL; } diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 676b9af2..b3f5b381 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -504,7 +504,7 @@ static int sig_autoremove(void) server = server_find_tag(logitem->servertag); if (logitem->type == LOG_ITEM_TARGET && - server != NULL && !server->ischannel(*logitem->name)) + server != NULL && !server->ischannel(logitem->name)) log_close(log); } return 1; diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c index b994fe5c..b1ef6ed3 100644 --- a/src/fe-common/core/fe-messages.c +++ b/src/fe-common/core/fe-messages.c @@ -109,7 +109,7 @@ char *expand_emphasis(WI_ITEM_REC *item, const char *text) return ret; } -static char *get_nickmode(CHANNEL_REC *channel, const char *nick) +char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick) { NICK_REC *nickrec; char *emptystr; @@ -158,7 +158,7 @@ static void sig_message_public(SERVER_REC *server, const char *msg, else freemsg = NULL; - nickmode = get_nickmode(chanrec, nick); + nickmode = channel_get_nickmode(chanrec, nick); if (!print_channel) { /* message to active channel in window */ if (color != NULL) { @@ -217,7 +217,7 @@ static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel, const char *nickmode; int print_channel; - nickmode = get_nickmode(channel, server->nick); + nickmode = channel_get_nickmode(channel, server->nick); window = channel == NULL ? NULL : window_item_window((WI_ITEM_REC *) channel); @@ -238,71 +238,45 @@ static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel, } } -static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) +static void sig_message_own_public(SERVER_REC *server, const char *msg, + const char *target) { - GHashTable *optlist; CHANNEL_REC *channel; - char *target, *msg, *freestr, *newtarget; - void *free_arg; - int free_ret; - g_return_if_fail(data != NULL); + g_return_if_fail(server != NULL); + g_return_if_fail(msg != NULL); - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | - PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, - "msg", &optlist, &target, &msg)) - return; - if (*target == '\0' || *msg == '\0') - cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); - server = cmd_options_get_server("msg", optlist, server); - - free_ret = FALSE; - if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) { - /* , and . are handled specially */ - newtarget = parse_special(&target, server, item, - NULL, &free_ret, NULL, 0); - if (newtarget == NULL) { - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - *target == ',' ? IRCTXT_NO_MSGS_GOT : - IRCTXT_NO_MSGS_SENT); - cmd_params_free(free_arg); - signal_stop(); - return; - } - target = newtarget; - } else if (strcmp(target, "*") == 0 && item != NULL) { - /* * means active channel */ - target = item->name; - } - - if (server == NULL || !server->connected) - cmd_param_error(CMDERR_NOT_CONNECTED); channel = channel_find(server, target); + print_own_channel_message(server, channel, target, msg); +} - freestr = !free_ret ? NULL : target; - if (*target == '@' && server->ischannel(target[1])) { - /* Hybrid 6 feature, send msg to all ops in channel - FIXME: this shouldn't really be here in core.. */ - target++; - } +static void sig_message_own_private(SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) +{ + QUERY_REC *query; - if (server->ischannel(*target)) { - /* msg to channel */ - print_own_channel_message(server, channel, target, msg); - } else { - /* private message */ - QUERY_REC *query; - - query = privmsg_get_query(server, target, TRUE, MSGLEVEL_MSGS); - printformat(server, target, MSGLEVEL_MSGS | - MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - query == NULL ? IRCTXT_OWN_MSG_PRIVATE : - IRCTXT_OWN_MSG_PRIVATE_QUERY, - target, msg, server->nick); + g_return_if_fail(server != NULL); + g_return_if_fail(msg != NULL); + + if (target == NULL) { + /* this should only happen if some special target failed and + we should display some error message. currently the special + targets are only ',' and '.'. */ + g_return_if_fail(strcmp(origtarget, ",") == 0 || + strcmp(origtarget, ".") == 0); + + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + *origtarget == ',' ? IRCTXT_NO_MSGS_GOT : + IRCTXT_NO_MSGS_SENT); + signal_stop(); + return; } - g_free_not_null(freestr); - cmd_params_free(free_arg); + query = privmsg_get_query(server, target, TRUE, MSGLEVEL_MSGS); + printformat(server, target, + MSGLEVEL_MSGS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, + query == NULL ? IRCTXT_OWN_MSG_PRIVATE : + IRCTXT_OWN_MSG_PRIVATE_QUERY, target, msg, server->nick); } static void sig_message_join(SERVER_REC *server, const char *channel, @@ -502,6 +476,8 @@ void fe_messages_init(void) signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message private", (SIGNAL_FUNC) sig_message_private); + signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private); signal_add("message join", (SIGNAL_FUNC) sig_message_join); signal_add("message part", (SIGNAL_FUNC) sig_message_part); signal_add("message quit", (SIGNAL_FUNC) sig_message_quit); @@ -510,13 +486,14 @@ void fe_messages_init(void) signal_add("message own_nick", (SIGNAL_FUNC) sig_message_own_nick); signal_add("message invite", (SIGNAL_FUNC) sig_message_invite); signal_add("message topic", (SIGNAL_FUNC) sig_message_topic); - command_bind_last("msg", NULL, (SIGNAL_FUNC) cmd_msg); } void fe_messages_deinit(void) { signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); + signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private); signal_remove("message join", (SIGNAL_FUNC) sig_message_join); signal_remove("message part", (SIGNAL_FUNC) sig_message_part); signal_remove("message quit", (SIGNAL_FUNC) sig_message_quit); @@ -525,5 +502,4 @@ void fe_messages_deinit(void) signal_remove("message own_nick", (SIGNAL_FUNC) sig_message_own_nick); signal_remove("message invite", (SIGNAL_FUNC) sig_message_invite); signal_remove("message topic", (SIGNAL_FUNC) sig_message_topic); - command_unbind("msg", (SIGNAL_FUNC) cmd_msg); } diff --git a/src/fe-common/core/fe-messages.h b/src/fe-common/core/fe-messages.h index 16b0b73d..afe7644d 100644 --- a/src/fe-common/core/fe-messages.h +++ b/src/fe-common/core/fe-messages.h @@ -5,4 +5,6 @@ underlining or bolding */ char *expand_emphasis(WI_ITEM_REC *item, const char *text); +char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick); + #endif diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am index 0abc41f9..b69499f1 100644 --- a/src/fe-common/irc/Makefile.am +++ b/src/fe-common/irc/Makefile.am @@ -14,6 +14,7 @@ INCLUDES = \ libfe_common_irc_a_SOURCES = \ fe-irc-channels.c \ fe-irc-commands.c \ + fe-irc-messages.c \ fe-irc-queries.c \ fe-irc-server.c \ fe-ircnet.c \ diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c index e3d23556..a0169299 100644 --- a/src/fe-common/irc/fe-common-irc.c +++ b/src/fe-common/irc/fe-common-irc.c @@ -39,6 +39,9 @@ void fe_irc_channels_deinit(void); void fe_irc_queries_init(void); void fe_irc_queries_deinit(void); +void fe_irc_messages_init(void); +void fe_irc_messages_deinit(void); + void fe_irc_commands_init(void); void fe_irc_commands_deinit(void); @@ -99,6 +102,7 @@ void fe_common_irc_init(void) fe_irc_channels_init(); fe_irc_queries_init(); + fe_irc_messages_init(); fe_irc_commands_init(); fe_ircnet_init(); fe_irc_server_init(); @@ -119,6 +123,7 @@ void fe_common_irc_deinit(void) fe_irc_channels_deinit(); fe_irc_queries_deinit(); + fe_irc_messages_deinit(); fe_irc_commands_deinit(); fe_ircnet_deinit(); fe_irc_server_deinit(); diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index 4ebc40b5..b03c2ca5 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -51,9 +51,15 @@ static void event_privmsg(IRC_SERVER_REC *server, const char *data, if (nick == NULL) nick = server->real_address; if (addr == NULL) addr = ""; - signal_emit(ischannel(*target) ? - "message public" : "message private", 5, - server, msg, nick, addr, target); + if (*target == '@' && ischannel(target[1])) { + /* Hybrid 6 feature, send msg to all ops in channel */ + signal_emit("message irc op_public", 5, + server, msg, nick, addr, target+1); + } else { + signal_emit(ischannel(*target) ? + "message public" : "message private", 5, + server, msg, nick, addr, target); + } g_free(params); } diff --git a/src/fe-common/irc/fe-irc-messages.c b/src/fe-common/irc/fe-irc-messages.c new file mode 100644 index 00000000..1d33c9c2 --- /dev/null +++ b/src/fe-common/irc/fe-irc-messages.c @@ -0,0 +1,81 @@ +/* + fe-irc-messages.c : irssi + + Copyright (C) 2001 Timo Sirainen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "module.h" +#include "signals.h" +#include "levels.h" +#include "channels.h" + +#include "irc.h" + +/* FIXME: hmm. there's should be some better way to use other module's + formats than this since now we can't use this module's formats.. */ +#include "../core/module-formats.h" +#include "printtext.h" +#include "fe-messages.h" + +static void sig_message_own_public(SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) +{ + char *nickmode; + + if (IS_IRC_SERVER(server) && target != NULL && + *target == '@' && ischannel(target[1])) { + /* Hybrid 6 feature, send msg to all ops in channel */ + nickmode = channel_get_nickmode(channel_find(server, target+1), + server->nick); + + printformat_module("fe-common/core", server, target+1, + MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT | + MSGLEVEL_NO_ACT, + IRCTXT_OWN_MSG_CHANNEL, + server->nick, target, msg, nickmode); + signal_stop(); + } +} + +static void sig_message_irc_op_public(SERVER_REC *server, const char *msg, + const char *nick, const char *address, + const char *target) +{ + char *nickmode, *optarget; + + nickmode = channel_get_nickmode(channel_find(server, target), + server->nick); + + optarget = g_strconcat("@", target, NULL); + printformat_module("fe-common/core", server, target, + MSGLEVEL_PUBLIC | MSGLEVEL_HILIGHT, + IRCTXT_PUBMSG_ME_CHANNEL, + nick, optarget, msg, nickmode); + g_free(optarget); +} + +void fe_irc_messages_init(void) +{ + signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_add("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public); +} + +void fe_irc_messages_deinit(void) +{ + signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_remove("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public); +} diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index ca548400..f39d858a 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -68,9 +68,9 @@ static int isnickflag_func(char flag) return isnickflag(flag); } -static int ischannel_func(char flag) +static int ischannel_func(const char *data) { - return ischannel(flag); + return ischannel_target(data); } static void send_message(SERVER_REC *server, const char *target, diff --git a/src/irc/core/irc.h b/src/irc/core/irc.h index 12065cb1..7eacca7a 100644 --- a/src/irc/core/irc.h +++ b/src/irc/core/irc.h @@ -25,6 +25,10 @@ (a) == '!' || /* secure */ \ (a) == '+') /* modeless */ +#define ischannel_target(a) \ + (ischannel((a)[0]) || \ + ((a)[0] == '@' && ischannel((a)[1]))) /* hybrid6 @#channel */ + #define IS_IRC_ITEM(rec) (IS_IRC_CHANNEL(rec) || IS_IRC_QUERY(rec)) extern char *current_server_event; /* current server event being processed */ |