2001-01-01 11:57:25 -05:00
|
|
|
/*
|
|
|
|
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"
|
2001-01-28 05:16:43 -05:00
|
|
|
#include "ignore.h"
|
2001-03-16 17:14:50 -05:00
|
|
|
#include "settings.h"
|
2005-10-10 14:32:32 -04:00
|
|
|
#include "recode.h"
|
2001-01-01 11:57:25 -05:00
|
|
|
|
2001-11-01 20:05:14 -05:00
|
|
|
#include "irc-servers.h"
|
2001-01-28 05:16:43 -05:00
|
|
|
#include "irc-channels.h"
|
2001-02-06 17:10:57 -05:00
|
|
|
#include "irc-queries.h"
|
2001-01-01 11:57:25 -05:00
|
|
|
|
|
|
|
#include "../core/module-formats.h"
|
2001-01-07 14:42:59 -05:00
|
|
|
#include "module-formats.h"
|
2001-01-01 11:57:25 -05:00
|
|
|
#include "printtext.h"
|
|
|
|
#include "fe-messages.h"
|
|
|
|
|
2001-01-28 05:16:43 -05:00
|
|
|
#include "fe-queries.h"
|
|
|
|
#include "window-items.h"
|
|
|
|
|
2001-06-04 15:50:16 -04:00
|
|
|
static const char *skip_target(const char *target)
|
|
|
|
{
|
|
|
|
if (target != NULL && *target == '@') {
|
|
|
|
/* @#channel, @+#channel - Hybrid6 / Bahamut features */
|
|
|
|
if (target[1] == '+' && ischannel(target[2]))
|
|
|
|
target += 2;
|
|
|
|
else if (ischannel(target[1]))
|
|
|
|
target++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2001-01-01 11:57:25 -05:00
|
|
|
static void sig_message_own_public(SERVER_REC *server, const char *msg,
|
|
|
|
const char *target, const char *origtarget)
|
|
|
|
{
|
2001-06-04 15:50:16 -04:00
|
|
|
const char *oldtarget;
|
2005-10-10 14:32:32 -04:00
|
|
|
char *nickmode, *recoded;
|
2001-01-01 11:57:25 -05:00
|
|
|
|
2001-06-04 15:50:16 -04:00
|
|
|
oldtarget = target;
|
|
|
|
target = skip_target(target);
|
|
|
|
if (IS_IRC_SERVER(server) && target != oldtarget) {
|
|
|
|
/* Hybrid 6 / Bahamut feature, send msg to all
|
|
|
|
ops / ops+voices in channel */
|
|
|
|
nickmode = channel_get_nickmode(channel_find(server, target),
|
2001-01-01 11:57:25 -05:00
|
|
|
server->nick);
|
|
|
|
|
2005-10-10 14:32:32 -04:00
|
|
|
/* ugly: recode the sent message back for printing */
|
|
|
|
recoded = recode_in(SERVER(server), msg, target);
|
2001-06-04 15:50:16 -04:00
|
|
|
printformat_module("fe-common/core", server, target,
|
2001-01-01 11:57:25 -05:00
|
|
|
MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
|
|
|
|
MSGLEVEL_NO_ACT,
|
2001-01-07 14:42:59 -05:00
|
|
|
TXT_OWN_MSG_CHANNEL,
|
2005-10-10 14:32:32 -04:00
|
|
|
server->nick, oldtarget, recoded, nickmode);
|
|
|
|
g_free(recoded);
|
2001-01-01 11:57:25 -05:00
|
|
|
signal_stop();
|
|
|
|
}
|
2005-10-10 14:32:32 -04:00
|
|
|
|
2001-01-01 11:57:25 -05:00
|
|
|
}
|
|
|
|
|
2001-01-28 05:16:43 -05:00
|
|
|
/* received msg to all ops in channel */
|
2001-01-01 11:57:25 -05:00
|
|
|
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),
|
2004-09-13 18:09:54 -04:00
|
|
|
nick);
|
2001-01-01 11:57:25 -05:00
|
|
|
|
|
|
|
optarget = g_strconcat("@", target, NULL);
|
|
|
|
printformat_module("fe-common/core", server, target,
|
2001-12-03 14:50:21 -05:00
|
|
|
MSGLEVEL_PUBLIC,
|
|
|
|
TXT_PUBMSG_CHANNEL,
|
2001-01-01 11:57:25 -05:00
|
|
|
nick, optarget, msg, nickmode);
|
|
|
|
g_free(optarget);
|
|
|
|
}
|
|
|
|
|
2001-01-28 05:16:43 -05:00
|
|
|
static void sig_message_own_wall(SERVER_REC *server, const char *msg,
|
|
|
|
const char *target)
|
|
|
|
{
|
2005-10-10 14:32:32 -04:00
|
|
|
char *nickmode, *optarget, *recoded;
|
2001-01-28 05:16:43 -05:00
|
|
|
|
|
|
|
nickmode = channel_get_nickmode(channel_find(server, target),
|
|
|
|
server->nick);
|
|
|
|
|
|
|
|
optarget = g_strconcat("@", target, NULL);
|
2005-10-10 14:32:32 -04:00
|
|
|
/* ugly: recode the sent message back for printing */
|
|
|
|
recoded = recode_in(SERVER(server), msg, target);
|
2001-01-28 05:16:43 -05:00
|
|
|
printformat_module("fe-common/core", server, target,
|
|
|
|
MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
|
|
|
|
MSGLEVEL_NO_ACT,
|
|
|
|
TXT_OWN_MSG_CHANNEL,
|
2005-10-12 14:22:14 -04:00
|
|
|
server->nick, optarget, recoded, nickmode);
|
2005-10-10 14:32:32 -04:00
|
|
|
g_free(recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
g_free(optarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_own_action(IRC_SERVER_REC *server, const char *msg,
|
|
|
|
const char *target)
|
|
|
|
{
|
2001-02-06 17:10:57 -05:00
|
|
|
void *item;
|
2005-10-10 14:32:32 -04:00
|
|
|
char *freemsg = NULL, *recoded;
|
2001-02-06 17:10:57 -05:00
|
|
|
|
|
|
|
if (ischannel(*target))
|
|
|
|
item = irc_channel_find(server, target);
|
|
|
|
else
|
|
|
|
item = irc_query_find(server, target);
|
|
|
|
|
2005-10-12 14:22:14 -04:00
|
|
|
if (settings_get_bool("emphasis"))
|
|
|
|
msg = freemsg = expand_emphasis(item, msg);
|
|
|
|
|
2005-10-10 14:32:32 -04:00
|
|
|
/* ugly: recode the sent message back for printing */
|
|
|
|
recoded = recode_in(SERVER(server), msg, target);
|
2001-03-16 17:14:50 -05:00
|
|
|
|
2001-02-06 17:10:57 -05:00
|
|
|
printformat(server, target,
|
|
|
|
MSGLEVEL_ACTIONS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT |
|
|
|
|
(ischannel(*target) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS),
|
|
|
|
item != NULL ? IRCTXT_OWN_ACTION : IRCTXT_OWN_ACTION_TARGET,
|
2005-10-12 14:22:14 -04:00
|
|
|
server->nick, recoded, target);
|
2005-10-10 14:32:32 -04:00
|
|
|
g_free(recoded);
|
2001-03-16 17:14:50 -05:00
|
|
|
g_free_not_null(freemsg);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_irc_action(IRC_SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *address,
|
|
|
|
const char *target)
|
|
|
|
{
|
|
|
|
void *item;
|
2005-10-15 14:45:25 -04:00
|
|
|
char *freemsg = NULL, *recoded;
|
2001-01-28 05:16:43 -05:00
|
|
|
int level;
|
|
|
|
|
|
|
|
level = MSGLEVEL_ACTIONS |
|
|
|
|
(ischannel(*target) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS);
|
|
|
|
|
|
|
|
if (ignore_check(SERVER(server), nick, address, target, msg, level))
|
|
|
|
return;
|
|
|
|
|
2001-03-16 17:14:50 -05:00
|
|
|
if (ischannel(*target))
|
2001-01-28 05:16:43 -05:00
|
|
|
item = irc_channel_find(server, target);
|
2001-03-16 17:14:50 -05:00
|
|
|
else
|
|
|
|
item = privmsg_get_query(SERVER(server), nick, FALSE, level);
|
2001-01-28 05:16:43 -05:00
|
|
|
|
2001-03-16 17:14:50 -05:00
|
|
|
if (settings_get_bool("emphasis"))
|
|
|
|
msg = freemsg = expand_emphasis(item, msg);
|
|
|
|
|
2005-10-15 14:45:25 -04:00
|
|
|
recoded = recode_in(SERVER(server), msg, target);
|
2001-03-16 17:14:50 -05:00
|
|
|
if (ischannel(*target)) {
|
|
|
|
/* channel action */
|
2001-01-28 05:16:43 -05:00
|
|
|
if (window_item_is_active(item)) {
|
|
|
|
/* message to active channel in window */
|
|
|
|
printformat(server, target, level,
|
2005-10-15 14:45:25 -04:00
|
|
|
IRCTXT_ACTION_PUBLIC, nick, recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
} else {
|
|
|
|
/* message to not existing/active channel */
|
|
|
|
printformat(server, target, level,
|
|
|
|
IRCTXT_ACTION_PUBLIC_CHANNEL,
|
2005-10-15 14:45:25 -04:00
|
|
|
nick, target, recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* private action */
|
|
|
|
printformat(server, nick, MSGLEVEL_ACTIONS | MSGLEVEL_MSGS,
|
|
|
|
item == NULL ? IRCTXT_ACTION_PRIVATE :
|
|
|
|
IRCTXT_ACTION_PRIVATE_QUERY,
|
2005-10-15 14:45:25 -04:00
|
|
|
nick, address == NULL ? "" : address, recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
2005-10-15 14:45:25 -04:00
|
|
|
|
|
|
|
g_free(recoded);
|
|
|
|
g_free_not_null(freemsg);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_own_notice(IRC_SERVER_REC *server, const char *msg,
|
|
|
|
const char *target)
|
|
|
|
{
|
2005-10-10 14:32:32 -04:00
|
|
|
/* ugly: recode the sent message back for printing */
|
|
|
|
char *recoded = recode_in(SERVER(server), msg, target);
|
2002-10-14 11:18:32 -04:00
|
|
|
printformat(server, skip_target(target), MSGLEVEL_NOTICES |
|
2001-01-28 05:16:43 -05:00
|
|
|
MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT,
|
|
|
|
IRCTXT_OWN_NOTICE, target, msg);
|
2005-10-10 14:32:32 -04:00
|
|
|
g_free(recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_irc_notice(SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *address,
|
|
|
|
const char *target)
|
|
|
|
{
|
2001-06-04 15:50:16 -04:00
|
|
|
const char *oldtarget;
|
2005-10-15 14:45:25 -04:00
|
|
|
char *recoded;
|
|
|
|
|
2002-10-14 11:18:32 -04:00
|
|
|
oldtarget = target;
|
|
|
|
target = skip_target(target);
|
|
|
|
|
2001-11-19 12:21:11 -05:00
|
|
|
if (address == NULL || *address == '\0') {
|
2001-01-28 05:16:43 -05:00
|
|
|
/* notice from server */
|
2005-10-15 14:45:25 -04:00
|
|
|
recoded = recode_in(SERVER(server), msg, NULL);
|
2001-01-28 05:16:43 -05:00
|
|
|
if (!ignore_check(server, nick, "",
|
|
|
|
target, msg, MSGLEVEL_SNOTES)) {
|
2001-11-18 08:43:05 -05:00
|
|
|
printformat(server, target, MSGLEVEL_SNOTES,
|
2001-01-28 05:16:43 -05:00
|
|
|
IRCTXT_NOTICE_SERVER, nick, msg);
|
|
|
|
}
|
2005-10-15 14:45:25 -04:00
|
|
|
g_free(recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ignore_check(server, nick, address,
|
|
|
|
ischannel(*target) ? target : NULL,
|
|
|
|
msg, MSGLEVEL_NOTICES))
|
|
|
|
return;
|
|
|
|
|
2005-10-15 14:45:25 -04:00
|
|
|
recoded = recode_in(SERVER(server), msg, target);
|
|
|
|
if (ischannel(*target)) {
|
2001-01-28 05:16:43 -05:00
|
|
|
/* notice in some channel */
|
|
|
|
printformat(server, target, MSGLEVEL_NOTICES,
|
2005-10-15 14:45:25 -04:00
|
|
|
IRCTXT_NOTICE_PUBLIC, nick, oldtarget, recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
} else {
|
|
|
|
/* private notice */
|
|
|
|
privmsg_get_query(SERVER(server), nick, FALSE,
|
|
|
|
MSGLEVEL_NOTICES);
|
|
|
|
printformat(server, nick, MSGLEVEL_NOTICES,
|
2005-10-15 14:45:25 -04:00
|
|
|
IRCTXT_NOTICE_PRIVATE, nick, address, recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
2005-10-15 14:45:25 -04:00
|
|
|
g_free(recoded);
|
2001-01-28 05:16:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_own_ctcp(IRC_SERVER_REC *server, const char *cmd,
|
|
|
|
const char *data, const char *target)
|
|
|
|
{
|
|
|
|
printformat(server, target, MSGLEVEL_CTCPS |
|
|
|
|
MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT,
|
|
|
|
IRCTXT_OWN_CTCP, target, cmd, data);
|
|
|
|
}
|
|
|
|
|
2002-02-13 10:31:57 -05:00
|
|
|
static void sig_message_irc_ctcp(IRC_SERVER_REC *server, const char *cmd,
|
|
|
|
const char *data, const char *nick,
|
|
|
|
const char *addr, const char *target)
|
2001-01-07 14:42:59 -05:00
|
|
|
{
|
|
|
|
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
|
2002-02-13 10:31:57 -05:00
|
|
|
IRCTXT_CTCP_REQUESTED, nick, addr, cmd, data, target);
|
2001-01-07 14:42:59 -05:00
|
|
|
}
|
|
|
|
|
2001-01-01 11:57:25 -05:00
|
|
|
void fe_irc_messages_init(void)
|
|
|
|
{
|
2001-06-26 18:29:16 -04:00
|
|
|
signal_add_last("message own_public", (SIGNAL_FUNC) sig_message_own_public);
|
|
|
|
signal_add_last("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public);
|
|
|
|
signal_add_last("message irc own_wall", (SIGNAL_FUNC) sig_message_own_wall);
|
|
|
|
signal_add_last("message irc own_action", (SIGNAL_FUNC) sig_message_own_action);
|
|
|
|
signal_add_last("message irc action", (SIGNAL_FUNC) sig_message_irc_action);
|
|
|
|
signal_add_last("message irc own_notice", (SIGNAL_FUNC) sig_message_own_notice);
|
|
|
|
signal_add_last("message irc notice", (SIGNAL_FUNC) sig_message_irc_notice);
|
|
|
|
signal_add_last("message irc own_ctcp", (SIGNAL_FUNC) sig_message_own_ctcp);
|
|
|
|
signal_add_last("message irc ctcp", (SIGNAL_FUNC) sig_message_irc_ctcp);
|
2001-01-01 11:57:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2001-01-28 05:16:43 -05:00
|
|
|
signal_remove("message irc own_wall", (SIGNAL_FUNC) sig_message_own_wall);
|
|
|
|
signal_remove("message irc own_action", (SIGNAL_FUNC) sig_message_own_action);
|
|
|
|
signal_remove("message irc action", (SIGNAL_FUNC) sig_message_irc_action);
|
|
|
|
signal_remove("message irc own_notice", (SIGNAL_FUNC) sig_message_own_notice);
|
|
|
|
signal_remove("message irc notice", (SIGNAL_FUNC) sig_message_irc_notice);
|
|
|
|
signal_remove("message irc own_ctcp", (SIGNAL_FUNC) sig_message_own_ctcp);
|
2001-01-07 14:42:59 -05:00
|
|
|
signal_remove("message irc ctcp", (SIGNAL_FUNC) sig_message_irc_ctcp);
|
2001-01-01 11:57:25 -05:00
|
|
|
}
|