2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
fe-events.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 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 "module-formats.h"
|
|
|
|
#include "signals.h"
|
2000-06-30 15:54:34 -04:00
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "irc.h"
|
|
|
|
#include "levels.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
|
|
|
#include "servers-redirect.h"
|
|
|
|
#include "servers-reconnect.h"
|
|
|
|
#include "queries.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "ignore.h"
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "fe-queries.h"
|
|
|
|
#include "irc-channels.h"
|
|
|
|
#include "irc-nicklist.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "irc-hilight-text.h"
|
|
|
|
#include "windows.h"
|
|
|
|
|
|
|
|
#include "completion.h"
|
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
#define target_level(target) \
|
|
|
|
(ischannel((target)[0]) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS)
|
|
|
|
|
2000-06-28 17:47:13 -04:00
|
|
|
static void print_channel_msg(IRC_SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
IRC_CHANNEL_REC *chanrec;
|
2000-04-26 04:03:38 -04:00
|
|
|
NICK_REC *nickrec;
|
2000-07-10 19:00:56 -04:00
|
|
|
const char *nickmode;
|
2000-08-29 19:43:59 -04:00
|
|
|
int for_me, print_channel, level;
|
2000-07-10 19:00:56 -04:00
|
|
|
char *color;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
chanrec = irc_channel_find(server, target);
|
2000-06-12 18:57:53 -04:00
|
|
|
for_me = irc_nick_match(server->nick, msg);
|
2000-07-02 08:07:49 -04:00
|
|
|
color = for_me ? NULL : irc_hilight_find_nick(target, nick, addr, MSGLEVEL_PUBLIC, msg);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
nickrec = chanrec == NULL ? NULL :
|
|
|
|
nicklist_find(CHANNEL(chanrec), nick);
|
2000-06-12 18:57:53 -04:00
|
|
|
nickmode = (!settings_get_bool("show_nickmode") || nickrec == NULL) ? "" :
|
|
|
|
(nickrec->op ? "@" : nickrec->voice ? "+" : " ");
|
|
|
|
|
2000-07-22 21:39:08 -04:00
|
|
|
print_channel = !window_item_is_active((WI_ITEM_REC *) chanrec);
|
|
|
|
if (!print_channel && settings_get_bool("print_active_channel") &&
|
|
|
|
window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL)
|
|
|
|
print_channel = TRUE;
|
|
|
|
|
2000-08-29 19:43:59 -04:00
|
|
|
level = MSGLEVEL_PUBLIC |
|
|
|
|
(color != NULL ? MSGLEVEL_HILIGHT :
|
|
|
|
(for_me ? MSGLEVEL_HILIGHT : MSGLEVEL_NOHILIGHT));
|
2000-07-22 21:39:08 -04:00
|
|
|
if (!print_channel) {
|
2000-06-12 18:57:53 -04:00
|
|
|
/* message to active channel in window */
|
|
|
|
if (color != NULL) {
|
|
|
|
/* highlighted nick */
|
2000-08-29 19:43:59 -04:00
|
|
|
printformat(server, target, level, IRCTXT_PUBMSG_HILIGHT,
|
|
|
|
color, nick, msg, nickmode);
|
2000-06-12 18:57:53 -04:00
|
|
|
} else {
|
2000-08-29 19:43:59 -04:00
|
|
|
printformat(server, target, level,
|
2000-06-12 18:57:53 -04:00
|
|
|
for_me ? IRCTXT_PUBMSG_ME : IRCTXT_PUBMSG, nick, msg, nickmode);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* message to not existing/active channel */
|
|
|
|
if (color != NULL) {
|
|
|
|
/* highlighted nick */
|
2000-08-29 19:43:59 -04:00
|
|
|
printformat(server, target, level, IRCTXT_PUBMSG_HILIGHT_CHANNEL,
|
|
|
|
color, nick, target, msg, nickmode);
|
2000-06-12 18:57:53 -04:00
|
|
|
} else {
|
2000-08-29 19:43:59 -04:00
|
|
|
printformat(server, target, level,
|
2000-06-12 18:57:53 -04:00
|
|
|
for_me ? IRCTXT_PUBMSG_ME_CHANNEL : IRCTXT_PUBMSG_CHANNEL,
|
|
|
|
nick, target, msg, nickmode);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free_not_null(color);
|
2000-06-12 18:57:53 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
|
|
|
{
|
2000-09-06 17:30:56 -04:00
|
|
|
QUERY_REC *query;
|
2000-06-12 18:57:53 -04:00
|
|
|
char *params, *target, *msg;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
|
|
|
|
if (nick == NULL) nick = server->real_address;
|
|
|
|
if (addr == NULL) addr = "";
|
|
|
|
|
|
|
|
if (!ignore_check(server, nick, addr, target, msg, target_level(target))) {
|
|
|
|
if (ischannel(*target)) {
|
|
|
|
/* message to channel */
|
2000-06-12 19:19:34 -04:00
|
|
|
print_channel_msg(server, msg, nick, addr, target);
|
2000-06-12 18:57:53 -04:00
|
|
|
} else {
|
|
|
|
/* private message */
|
2000-09-06 17:30:56 -04:00
|
|
|
query = privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_MSGS);
|
2000-06-12 18:57:53 -04:00
|
|
|
printformat(server, nick, MSGLEVEL_MSGS,
|
2000-09-06 17:30:56 -04:00
|
|
|
query == NULL ? IRCTXT_MSG_PRIVATE : IRCTXT_MSG_PRIVATE_QUERY, nick, addr, msg);
|
2000-06-12 18:57:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we use "ctcp msg" here because "ctcp msg action" can be ignored with
|
2000-06-12 18:57:53 -04:00
|
|
|
/IGNORE * CTCPS, and we don't want that.. */
|
2000-07-30 13:32:55 -04:00
|
|
|
static void ctcp_msg_check_action(const char *data, IRC_SERVER_REC *server,
|
|
|
|
const char *nick, const char *addr, const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-09-06 17:30:56 -04:00
|
|
|
void *item;
|
2000-07-15 09:04:03 -04:00
|
|
|
int level;
|
2000-06-12 18:57:53 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
if (g_strncasecmp(data, "ACTION ", 7) != 0)
|
|
|
|
return;
|
|
|
|
data += 7;
|
|
|
|
|
2000-07-15 09:04:03 -04:00
|
|
|
level = MSGLEVEL_ACTIONS |
|
|
|
|
(ischannel(*target) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS);
|
|
|
|
if (ignore_check(server, nick, addr, target, data, level))
|
2000-06-12 18:57:53 -04:00
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
if (ischannel(*target)) {
|
|
|
|
/* channel action */
|
2000-09-06 17:30:56 -04:00
|
|
|
item = irc_channel_find(server, target);
|
2000-06-12 18:57:53 -04:00
|
|
|
|
|
|
|
if (window_item_is_active(item)) {
|
|
|
|
/* message to active channel in window */
|
2000-07-15 09:04:03 -04:00
|
|
|
printformat(server, target, level,
|
2000-06-12 18:57:53 -04:00
|
|
|
IRCTXT_ACTION_PUBLIC, nick, data);
|
|
|
|
} else {
|
|
|
|
/* message to not existing/active channel */
|
2000-07-15 09:04:03 -04:00
|
|
|
printformat(server, target, level,
|
2000-06-12 18:57:53 -04:00
|
|
|
IRCTXT_ACTION_PUBLIC_CHANNEL, nick, target, data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* private action */
|
2000-09-06 17:30:56 -04:00
|
|
|
item = privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_MSGS);
|
2000-07-15 09:04:03 -04:00
|
|
|
printformat(server, nick, level,
|
2000-06-12 18:57:53 -04:00
|
|
|
item == NULL ? IRCTXT_ACTION_PRIVATE : IRCTXT_ACTION_PRIVATE_QUERY,
|
|
|
|
nick, addr == NULL ? "" : addr, data);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
static void event_notice(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-12 18:57:53 -04:00
|
|
|
char *params, *target, *msg;
|
|
|
|
int op_notice;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
|
|
|
|
if (nick == NULL) {
|
|
|
|
nick = server->real_address == NULL ?
|
|
|
|
server->connrec->address :
|
|
|
|
server->real_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr == NULL) {
|
|
|
|
/* notice from server */
|
|
|
|
if (*msg != 1 && !ignore_check(server, nick, "", target, msg, MSGLEVEL_SNOTES))
|
|
|
|
printformat(server, target, MSGLEVEL_SNOTES, IRCTXT_NOTICE_SERVER, nick, msg);
|
|
|
|
} else {
|
|
|
|
op_notice = *target == '@' && ischannel(target[1]);
|
|
|
|
if (op_notice) target++;
|
|
|
|
|
2000-09-06 17:30:56 -04:00
|
|
|
if (ignore_check(server, nick, addr, ischannel(*target) ?
|
|
|
|
target : NULL, msg, MSGLEVEL_NOTICES))
|
|
|
|
return;
|
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
if (ischannel(*target)) {
|
|
|
|
/* notice in some channel */
|
2000-09-06 17:30:56 -04:00
|
|
|
printformat(server, target, MSGLEVEL_NOTICES,
|
|
|
|
op_notice ? IRCTXT_NOTICE_PUBLIC_OPS : IRCTXT_NOTICE_PUBLIC,
|
|
|
|
nick, target, msg);
|
2000-06-12 18:57:53 -04:00
|
|
|
} else {
|
|
|
|
/* private notice */
|
2000-09-06 17:30:56 -04:00
|
|
|
privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_NOTICES);
|
|
|
|
printformat(server, nick, MSGLEVEL_NOTICES, IRCTXT_NOTICE_PRIVATE, nick, addr, msg);
|
2000-06-12 18:57:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_join(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *channel, *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 1, &channel);
|
|
|
|
tmp = strchr(channel, 7); /* ^G does something weird.. */
|
|
|
|
if (tmp != NULL) *tmp = '\0';
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
if (!ignore_check(server, nick, addr, channel, NULL, MSGLEVEL_JOINS))
|
|
|
|
printformat(server, channel, MSGLEVEL_JOINS, IRCTXT_JOIN, nick, addr, channel);
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_part(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *channel, *reason;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &channel, &reason);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
if (!ignore_check(server, nick, addr, channel, NULL, MSGLEVEL_PARTS))
|
|
|
|
printformat(server, channel, MSGLEVEL_PARTS, IRCTXT_PART, nick, addr, channel, reason);
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void event_quit(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
|
|
|
{
|
2000-07-23 08:56:02 -04:00
|
|
|
WINDOW_REC *window;
|
2000-04-26 04:03:38 -04:00
|
|
|
GString *chans;
|
2000-07-23 08:56:02 -04:00
|
|
|
GSList *tmp, *windows;
|
2000-04-27 08:02:54 -04:00
|
|
|
char *print_channel;
|
2000-05-30 10:54:36 -04:00
|
|
|
int once, count;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
if (*data == ':') data++; /* quit message */
|
2000-04-27 08:02:54 -04:00
|
|
|
if (ignore_check(server, nick, addr, NULL, data, MSGLEVEL_QUITS))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-04-27 08:02:54 -04:00
|
|
|
print_channel = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
once = settings_get_bool("show_quit_once");
|
2000-05-30 10:54:36 -04:00
|
|
|
|
2000-07-23 08:56:02 -04:00
|
|
|
count = 0; windows = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
chans = !once ? NULL : g_string_new(NULL);
|
|
|
|
for (tmp = channels; tmp != NULL; tmp = tmp->next) {
|
2000-08-26 11:39:44 -04:00
|
|
|
IRC_CHANNEL_REC *rec = tmp->data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
if (!IS_IRC_CHANNEL(rec) || rec->server != server ||
|
|
|
|
!nicklist_find(CHANNEL(rec), nick) ||
|
2000-07-23 08:56:02 -04:00
|
|
|
ignore_check(server, nick, addr, rec->name, data, MSGLEVEL_QUITS))
|
|
|
|
continue;
|
2000-04-27 08:02:54 -04:00
|
|
|
|
2000-07-23 08:56:02 -04:00
|
|
|
if (print_channel == NULL || active_win->active == (WI_ITEM_REC *) rec)
|
|
|
|
print_channel = rec->name;
|
|
|
|
|
|
|
|
if (!once) {
|
|
|
|
window = window_item_window((WI_ITEM_REC *) rec);
|
|
|
|
if (g_slist_find(windows, window) == NULL) {
|
|
|
|
windows = g_slist_append(windows, window);
|
2000-04-26 04:03:38 -04:00
|
|
|
printformat(server, rec->name, MSGLEVEL_QUITS, IRCTXT_QUIT, nick, addr, data);
|
2000-05-30 10:54:36 -04:00
|
|
|
}
|
2000-07-23 08:56:02 -04:00
|
|
|
} else {
|
|
|
|
g_string_sprintfa(chans, "%s,", rec->name);
|
|
|
|
count++;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
2000-07-23 08:56:02 -04:00
|
|
|
g_slist_free(windows);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (once) {
|
|
|
|
g_string_truncate(chans, chans->len-1);
|
2000-04-27 08:02:54 -04:00
|
|
|
printformat(server, print_channel, MSGLEVEL_QUITS,
|
2000-05-30 10:54:36 -04:00
|
|
|
count <= 1 ? IRCTXT_QUIT : IRCTXT_QUIT_ONCE,
|
2000-04-26 04:03:38 -04:00
|
|
|
nick, addr, data, chans->str);
|
|
|
|
g_string_free(chans, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_kick(const char *data, IRC_SERVER_REC *server, const char *kicker, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *channel, *nick, *reason;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 3 | PARAM_FLAG_GETREST, &channel, &nick, &reason);
|
|
|
|
if (!ignore_check(server, kicker, addr, channel, reason, MSGLEVEL_KICKS)) {
|
|
|
|
printformat(server, channel, MSGLEVEL_KICKS,
|
|
|
|
IRCTXT_KICK, nick, channel, kicker, reason);
|
|
|
|
}
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_nick_change(IRC_SERVER_REC *server, const char *target, const char *newnick, const char *oldnick, const char *addr, int ownnick)
|
|
|
|
{
|
|
|
|
if (ignore_check(server, oldnick, addr, target, newnick, MSGLEVEL_NICKS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ownnick)
|
|
|
|
printformat(server, target, MSGLEVEL_NICKS, IRCTXT_YOUR_NICK_CHANGED, newnick);
|
|
|
|
else
|
|
|
|
printformat(server, target, MSGLEVEL_NICKS, IRCTXT_NICK_CHANGED, oldnick, newnick);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void event_nick(gchar *data, IRC_SERVER_REC *server, gchar *sender, gchar *addr)
|
|
|
|
{
|
2000-07-23 08:56:02 -04:00
|
|
|
GSList *tmp, *windows;
|
2000-04-26 04:03:38 -04:00
|
|
|
char *params, *newnick;
|
|
|
|
int ownnick, msgprint;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
if (ignore_check(server, sender, addr, NULL, NULL, MSGLEVEL_NICKS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
params = event_get_params(data, 1, &newnick);
|
|
|
|
|
|
|
|
msgprint = FALSE;
|
|
|
|
ownnick = g_strcasecmp(sender, server->nick) == 0;
|
|
|
|
|
2000-07-23 08:56:02 -04:00
|
|
|
/* Print to each channel/query where the nick is.
|
|
|
|
Don't print more than once to the same window. */
|
|
|
|
windows = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
|
|
|
|
CHANNEL_REC *channel = tmp->data;
|
2000-07-23 08:56:02 -04:00
|
|
|
WINDOW_REC *window =
|
|
|
|
window_item_window((WI_ITEM_REC *) channel);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-07-23 08:56:02 -04:00
|
|
|
if (nicklist_find(channel, sender) &&
|
|
|
|
g_slist_find(windows, window) == NULL) {
|
|
|
|
windows = g_slist_append(windows, window);
|
2000-04-26 04:03:38 -04:00
|
|
|
print_nick_change(server, channel->name, newnick, sender, addr, ownnick);
|
|
|
|
msgprint = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
|
|
|
|
QUERY_REC *query = tmp->data;
|
2000-07-23 08:56:02 -04:00
|
|
|
WINDOW_REC *window =
|
|
|
|
window_item_window((WI_ITEM_REC *) query);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
if (g_strcasecmp(query->name, sender) == 0 &&
|
2000-07-23 08:56:02 -04:00
|
|
|
g_slist_find(windows, window) == NULL) {
|
|
|
|
windows = g_slist_append(windows, window);
|
2000-08-26 11:39:44 -04:00
|
|
|
print_nick_change(server, query->name, newnick, sender, addr, ownnick);
|
2000-04-26 04:03:38 -04:00
|
|
|
msgprint = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-07-23 08:56:02 -04:00
|
|
|
g_slist_free(windows);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (!msgprint && ownnick)
|
|
|
|
printformat(server, NULL, MSGLEVEL_NICKS, IRCTXT_YOUR_NICK_CHANGED, newnick);
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void event_mode(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
|
|
|
{
|
|
|
|
char *params, *channel, *mode;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
if (nick == NULL) nick = server->real_address;
|
|
|
|
|
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &channel, &mode);
|
|
|
|
if (ignore_check(server, nick, addr, channel, mode, MSGLEVEL_MODES)) {
|
|
|
|
g_free(params);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ischannel(*channel)) {
|
|
|
|
/* user mode change */
|
|
|
|
printformat(server, NULL, MSGLEVEL_MODES, IRCTXT_USERMODE_CHANGE, mode, channel);
|
|
|
|
} else if (addr == NULL) {
|
|
|
|
/* channel mode changed by server */
|
|
|
|
printformat(server, channel, MSGLEVEL_MODES,
|
|
|
|
IRCTXT_SERVER_CHANMODE_CHANGE, channel, mode, nick);
|
|
|
|
} else {
|
|
|
|
/* channel mode changed by normal user */
|
|
|
|
printformat(server, channel, MSGLEVEL_MODES,
|
|
|
|
IRCTXT_CHANMODE_CHANGE, channel, mode, nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void event_pong(const char *data, IRC_SERVER_REC *server, const char *nick)
|
|
|
|
{
|
|
|
|
char *params, *host, *reply;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
if (nick == NULL) nick = server->real_address;
|
|
|
|
|
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &host, &reply);
|
|
|
|
printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_PONG, host, reply);
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_invite(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *channel;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 2, NULL, &channel);
|
2000-06-30 15:54:34 -04:00
|
|
|
if (*channel != '\0' && !ignore_check(server, nick, addr, channel, NULL, MSGLEVEL_INVITES)) {
|
|
|
|
channel = show_lowascii(channel);
|
2000-06-10 20:58:15 -04:00
|
|
|
printformat(server, NULL, MSGLEVEL_INVITES, IRCTXT_INVITE, nick, channel);
|
2000-06-30 15:54:34 -04:00
|
|
|
g_free(channel);
|
|
|
|
}
|
2000-06-10 20:58:15 -04:00
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_topic(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *channel, *topic;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &channel, &topic);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
if (!ignore_check(server, nick, addr, channel, topic, MSGLEVEL_TOPICS))
|
|
|
|
printformat(server, channel, MSGLEVEL_TOPICS,
|
|
|
|
*topic != '\0' ? IRCTXT_NEW_TOPIC : IRCTXT_TOPIC_UNSET,
|
|
|
|
nick, channel, topic);
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_error(const char *data, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
if (*data == ':') data++;
|
|
|
|
printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_ERROR, data);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_wallops(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
if (*data == ':') data++;
|
|
|
|
if (ignore_check(server, nick, addr, NULL, data, MSGLEVEL_WALLOPS))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (g_strncasecmp(data, "\001ACTION", 7) != 0)
|
2000-06-10 20:58:15 -04:00
|
|
|
printformat(server, NULL, MSGLEVEL_WALLOPS, IRCTXT_WALLOPS, nick, data);
|
|
|
|
else {
|
|
|
|
/* Action in WALLOP */
|
|
|
|
int len;
|
2000-06-12 18:57:53 -04:00
|
|
|
char *tmp;
|
2000-06-10 20:58:15 -04:00
|
|
|
|
2000-06-12 18:57:53 -04:00
|
|
|
tmp = g_strdup(data);
|
|
|
|
len = strlen(tmp);
|
|
|
|
if (tmp[len-1] == 1) tmp[len-1] = '\0';
|
|
|
|
printformat(server, NULL, MSGLEVEL_WALLOPS, IRCTXT_ACTION_WALLOPS, nick, tmp);
|
|
|
|
g_free(tmp);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void channel_sync(CHANNEL_REC *channel)
|
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(channel != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
printformat(channel->server, channel->name, MSGLEVEL_CLIENTNOTICE|MSGLEVEL_NO_ACT,
|
|
|
|
IRCTXT_CHANNEL_SYNCED, channel->name, (long) (time(NULL)-channel->createtime));
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void event_connected(IRC_SERVER_REC *server)
|
|
|
|
{
|
2000-06-12 18:57:53 -04:00
|
|
|
const char *nick;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(server != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-09-06 19:24:12 -04:00
|
|
|
nick = settings_get_str("nick");
|
2000-06-10 20:58:15 -04:00
|
|
|
if (*nick == '\0' || g_strcasecmp(server->nick, nick) == 0)
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
/* someone has our nick, find out who. */
|
|
|
|
irc_send_cmdv(server, "WHOIS %s", nick);
|
|
|
|
server_redirect_event((SERVER_REC *) server, nick, 1,
|
|
|
|
"event 318", "event empty", 1,
|
|
|
|
"event 401", "event empty", 1,
|
|
|
|
"event 311", "nickfind event whois", 1,
|
|
|
|
"event 301", "event empty", 1,
|
|
|
|
"event 312", "event empty", 1,
|
|
|
|
"event 313", "event empty", 1,
|
|
|
|
"event 317", "event empty", 1,
|
|
|
|
"event 319", "event empty", 1, NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_nickfind_whois(const char *data, IRC_SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
char *params, *nick, *user, *host, *realname;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
params = event_get_params(data, 6, NULL, &nick, &user, &host, NULL, &realname);
|
|
|
|
printformat(server, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_YOUR_NICK_OWNED, nick, user, host, realname);
|
|
|
|
g_free(params);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_ban_type_changed(const char *bantype)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-10 20:58:15 -04:00
|
|
|
GString *str;
|
|
|
|
|
|
|
|
g_return_if_fail(bantype != NULL);
|
|
|
|
|
|
|
|
if (strcmp(bantype, "UD") == 0)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_BANTYPE, "Normal");
|
|
|
|
else if (strcmp(bantype, "HD") == 0 || strcmp(bantype, "H") == 0)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_BANTYPE, "Host");
|
|
|
|
else if (strcmp(bantype, "D") == 0)
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_BANTYPE, "Domain");
|
|
|
|
else {
|
|
|
|
str = g_string_new("Custom:");
|
|
|
|
if (*bantype == 'N') {
|
|
|
|
g_string_append(str, " Nick");
|
|
|
|
bantype++;
|
|
|
|
}
|
|
|
|
if (*bantype == 'U') {
|
|
|
|
g_string_append(str, " User");
|
|
|
|
bantype++;
|
|
|
|
}
|
|
|
|
if (*bantype == 'H') {
|
|
|
|
g_string_append(str, " Host");
|
|
|
|
bantype++;
|
|
|
|
}
|
|
|
|
if (*bantype == 'D')
|
|
|
|
g_string_append(str, " Domain");
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_BANTYPE, str->str);
|
|
|
|
g_string_free(str, TRUE);
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-06-10 17:40:00 -04:00
|
|
|
static void sig_whowas_event_end(const char *data, IRC_SERVER_REC *server, const char *sender, const char *addr)
|
|
|
|
{
|
|
|
|
char *params, *nick;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
if (server->whowas_found) {
|
|
|
|
signal_emit("event 369", 4, data, server, sender, addr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
params = event_get_params(data, 2, NULL, &nick);
|
|
|
|
printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_WHOIS_NOT_FOUND, nick);
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
2000-06-10 20:58:15 -04:00
|
|
|
static void event_received(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
char *params, *cmd, *args, *ptr;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
g_return_if_fail(data != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
if (!isdigit((gint) *data)) {
|
|
|
|
printtext(server, NULL, MSGLEVEL_CRAP, "%s", data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* numeric event. */
|
|
|
|
params = event_get_params(data, 3 | PARAM_FLAG_GETREST, &cmd, NULL, &args);
|
|
|
|
ptr = strstr(args, " :");
|
2000-04-26 04:03:38 -04:00
|
|
|
if (ptr != NULL) *(ptr+1) = ' ';
|
|
|
|
printtext(server, NULL, MSGLEVEL_CRAP, "%s", args);
|
|
|
|
g_free(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_empty(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void fe_events_init(void)
|
|
|
|
{
|
|
|
|
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
2000-06-12 18:57:53 -04:00
|
|
|
signal_add("ctcp msg", (SIGNAL_FUNC) ctcp_msg_check_action);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("ctcp msg action", (SIGNAL_FUNC) sig_empty);
|
|
|
|
signal_add("event notice", (SIGNAL_FUNC) event_notice);
|
|
|
|
signal_add("event join", (SIGNAL_FUNC) event_join);
|
|
|
|
signal_add("event part", (SIGNAL_FUNC) event_part);
|
|
|
|
signal_add("event quit", (SIGNAL_FUNC) event_quit);
|
|
|
|
signal_add("event kick", (SIGNAL_FUNC) event_kick);
|
|
|
|
signal_add("event nick", (SIGNAL_FUNC) event_nick);
|
|
|
|
signal_add("event mode", (SIGNAL_FUNC) event_mode);
|
|
|
|
signal_add("event pong", (SIGNAL_FUNC) event_pong);
|
|
|
|
signal_add("event invite", (SIGNAL_FUNC) event_invite);
|
|
|
|
signal_add("event topic", (SIGNAL_FUNC) event_topic);
|
|
|
|
signal_add("event error", (SIGNAL_FUNC) event_error);
|
|
|
|
signal_add("event wallops", (SIGNAL_FUNC) event_wallops);
|
|
|
|
|
|
|
|
signal_add("default event", (SIGNAL_FUNC) event_received);
|
|
|
|
|
|
|
|
signal_add("channel sync", (SIGNAL_FUNC) channel_sync);
|
|
|
|
signal_add("event connected", (SIGNAL_FUNC) event_connected);
|
|
|
|
signal_add("nickfind event whois", (SIGNAL_FUNC) event_nickfind_whois);
|
|
|
|
signal_add("ban type changed", (SIGNAL_FUNC) event_ban_type_changed);
|
2000-06-10 17:40:00 -04:00
|
|
|
signal_add("whowas event end", (SIGNAL_FUNC) sig_whowas_event_end);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fe_events_deinit(void)
|
|
|
|
{
|
|
|
|
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
|
2000-06-12 18:57:53 -04:00
|
|
|
signal_remove("ctcp msg", (SIGNAL_FUNC) ctcp_msg_check_action);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("ctcp msg action", (SIGNAL_FUNC) sig_empty);
|
|
|
|
signal_remove("event notice", (SIGNAL_FUNC) event_notice);
|
|
|
|
signal_remove("event join", (SIGNAL_FUNC) event_join);
|
|
|
|
signal_remove("event part", (SIGNAL_FUNC) event_part);
|
|
|
|
signal_remove("event quit", (SIGNAL_FUNC) event_quit);
|
|
|
|
signal_remove("event kick", (SIGNAL_FUNC) event_kick);
|
|
|
|
signal_remove("event nick", (SIGNAL_FUNC) event_nick);
|
|
|
|
signal_remove("event mode", (SIGNAL_FUNC) event_mode);
|
|
|
|
signal_remove("event pong", (SIGNAL_FUNC) event_pong);
|
|
|
|
signal_remove("event invite", (SIGNAL_FUNC) event_invite);
|
|
|
|
signal_remove("event topic", (SIGNAL_FUNC) event_topic);
|
|
|
|
signal_remove("event error", (SIGNAL_FUNC) event_error);
|
|
|
|
signal_remove("event wallops", (SIGNAL_FUNC) event_wallops);
|
|
|
|
|
|
|
|
signal_remove("default event", (SIGNAL_FUNC) event_received);
|
|
|
|
|
|
|
|
signal_remove("channel sync", (SIGNAL_FUNC) channel_sync);
|
|
|
|
signal_remove("event connected", (SIGNAL_FUNC) event_connected);
|
|
|
|
signal_remove("nickfind event whois", (SIGNAL_FUNC) event_nickfind_whois);
|
|
|
|
signal_remove("ban type changed", (SIGNAL_FUNC) event_ban_type_changed);
|
2000-06-10 17:40:00 -04:00
|
|
|
signal_remove("whowas event end", (SIGNAL_FUNC) sig_whowas_event_end);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|