mirror of
https://github.com/irssi/irssi.git
synced 2026-08-20 09:02:13 +02:00
Improved nick_match_msg() - it shouldn't give wrong matches as easily
anymore. Also supports multiple targets in one line (nick1,nick2: hello) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@996 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
057ec3b8a8
commit
6e19541f46
6 changed files with 82 additions and 29 deletions
|
|
@ -46,7 +46,7 @@ static int ignore_check_replies(IGNORE_REC *rec, CHANNEL_REC *channel,
|
||||||
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
|
for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
|
||||||
NICK_REC *nick = tmp->data;
|
NICK_REC *nick = tmp->data;
|
||||||
|
|
||||||
if (nick_match_msg(channel->server, text, nick->nick))
|
if (nick_match_msg(channel, text, nick->nick))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
g_slist_free(nicks);
|
g_slist_free(nicks);
|
||||||
|
|
|
||||||
|
|
@ -262,46 +262,93 @@ static void sig_channel_destroyed(CHANNEL_REC *channel)
|
||||||
g_hash_table_destroy(channel->nicks);
|
g_hash_table_destroy(channel->nicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check is `msg' is meant for `nick'. */
|
static NICK_REC *nick_nfind(CHANNEL_REC *channel, const char *nick, int len)
|
||||||
int nick_match_msg(SERVER_REC *server, const char *msg, const char *nick)
|
|
||||||
{
|
{
|
||||||
int len;
|
NICK_REC *rec;
|
||||||
|
char *tmpnick;
|
||||||
|
|
||||||
|
tmpnick = g_strndup(nick, len);
|
||||||
|
rec = g_hash_table_lookup(channel->nicks, tmpnick);
|
||||||
|
g_free(tmpnick);
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check is `msg' is meant for `nick'. */
|
||||||
|
int nick_match_msg(CHANNEL_REC *channel, const char *msg, const char *nick)
|
||||||
|
{
|
||||||
|
const char *msgstart, *orignick;
|
||||||
|
int len, fullmatch;
|
||||||
|
|
||||||
g_return_val_if_fail(nick != NULL, FALSE);
|
g_return_val_if_fail(nick != NULL, FALSE);
|
||||||
g_return_val_if_fail(msg != NULL, FALSE);
|
g_return_val_if_fail(msg != NULL, FALSE);
|
||||||
|
|
||||||
if (server != NULL && server->nick_match_msg != NULL)
|
if (channel != NULL && channel->server->nick_match_msg != NULL)
|
||||||
return server->nick_match_msg(msg, nick);
|
return channel->server->nick_match_msg(msg, nick);
|
||||||
|
|
||||||
/* first check for identical match */
|
/* first check for identical match */
|
||||||
len = strlen(nick);
|
len = strlen(nick);
|
||||||
if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len]))
|
if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len]))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/* check if it matches for alphanumeric parts of nick */
|
orignick = nick;
|
||||||
while (*nick != '\0' && *msg != '\0') {
|
for (;;) {
|
||||||
if (*nick == *msg) {
|
nick = orignick;
|
||||||
/* total match */
|
msgstart = msg;
|
||||||
msg++;
|
fullmatch = TRUE;
|
||||||
} else if (isalnum(*msg) && !isalnum(*nick)) {
|
|
||||||
/* some strange char in your nick, pass it */
|
/* check if it matches for alphanumeric parts of nick */
|
||||||
} else
|
while (*nick != '\0' && *msg != '\0') {
|
||||||
|
if (*nick == *msg) {
|
||||||
|
/* total match */
|
||||||
|
msg++;
|
||||||
|
} else if (isalnum(*msg) && !isalnum(*nick)) {
|
||||||
|
/* some strange char in your nick, pass it */
|
||||||
|
fullmatch = FALSE;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
|
||||||
|
nick++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg != msgstart && !isalnumhigh(*msg)) {
|
||||||
|
/* at least some of the chars in line matched the
|
||||||
|
nick, and msg continue with non-alphanum character,
|
||||||
|
this might be for us.. */
|
||||||
|
if (*nick != '\0') {
|
||||||
|
/* remove the rest of the non-alphanum chars
|
||||||
|
from nick and check if it then matches. */
|
||||||
|
fullmatch = FALSE;
|
||||||
|
while (*nick != '\0' && !isalnum(*nick))
|
||||||
|
nick++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*nick == '\0') {
|
||||||
|
/* yes, match! */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no match. check if this is a message to multiple people
|
||||||
|
(like nick1,nick2: text) */
|
||||||
|
while (*msg != '\0' && *msg != ' ' && *msg != ',') msg++;
|
||||||
|
|
||||||
|
if (*msg != ',') {
|
||||||
|
nick = orignick;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
nick++;
|
msg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isalnumhigh(*msg)) {
|
if (*nick != '\0')
|
||||||
/* message continues with another alphanumeric character,
|
return FALSE; /* didn't match */
|
||||||
it isn't for us. */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* remove all the non-alphanumeric characters at the end of
|
if (fullmatch)
|
||||||
the nick and check if message matched that far. */
|
return TRUE; /* matched without fuzzyness */
|
||||||
while (*nick != '\0' && !isalnum(*nick)) nick++;
|
|
||||||
|
|
||||||
return *nick == '\0';
|
/* matched with some fuzzyness .. check if there's an exact match
|
||||||
|
for some other nick in the same channel. */
|
||||||
|
return nick_nfind(channel, msgstart, (int) (msg-msgstart)) == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nicklist_init(void)
|
void nicklist_init(void)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ void nicklist_update_flags(SERVER_REC *server, const char *nick,
|
||||||
int nicklist_compare(NICK_REC *p1, NICK_REC *p2);
|
int nicklist_compare(NICK_REC *p1, NICK_REC *p2);
|
||||||
|
|
||||||
/* Check is `msg' is meant for `nick'. */
|
/* Check is `msg' is meant for `nick'. */
|
||||||
int nick_match_msg(SERVER_REC *server, const char *msg, const char *nick);
|
int nick_match_msg(CHANNEL_REC *channel, const char *msg, const char *nick);
|
||||||
|
|
||||||
void nicklist_init(void);
|
void nicklist_init(void);
|
||||||
void nicklist_deinit(void);
|
void nicklist_deinit(void);
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
|
||||||
|
|
||||||
channel = channel_find(server, target);
|
channel = channel_find(server, target);
|
||||||
if (channel != NULL) {
|
if (channel != NULL) {
|
||||||
list = nick_match_msg(server, msg, server->nick) ?
|
list = nick_match_msg(channel, msg, server->nick) ?
|
||||||
&channel->lastownmsgs :
|
&channel->lastownmsgs :
|
||||||
&channel->lastmsgs;
|
&channel->lastmsgs;
|
||||||
last_msg_add(list, nick);
|
last_msg_add(list, nick);
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,9 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
|
||||||
char *color;
|
char *color;
|
||||||
|
|
||||||
chanrec = channel_find(server, target);
|
chanrec = channel_find(server, target);
|
||||||
for_me = nick_match_msg(server, msg, server->nick);
|
g_return_if_fail(chanrec != NULL);
|
||||||
|
|
||||||
|
for_me = nick_match_msg(chanrec, msg, server->nick);
|
||||||
color = for_me ? NULL :
|
color = for_me ? NULL :
|
||||||
hilight_find_nick(target, nick, address, MSGLEVEL_PUBLIC, msg);
|
hilight_find_nick(target, nick, address, MSGLEVEL_PUBLIC, msg);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,8 +145,7 @@ static void sig_message(SERVER_REC *server, const char *msg,
|
||||||
/* hilight */
|
/* hilight */
|
||||||
if (item != NULL) item->last_color = hilight_last_nick_color();
|
if (item != NULL) item->last_color = hilight_last_nick_color();
|
||||||
level = (item != NULL && item->last_color > 0) ||
|
level = (item != NULL && item->last_color > 0) ||
|
||||||
(level & hilight_level) ||
|
(level & hilight_level) ?
|
||||||
nick_match_msg(SERVER(server), msg, server->nick) ?
|
|
||||||
NEWDATA_HILIGHT : NEWDATA_MSG;
|
NEWDATA_HILIGHT : NEWDATA_MSG;
|
||||||
if (item != NULL && item->new_data < level) {
|
if (item != NULL && item->new_data < level) {
|
||||||
item->new_data = level;
|
item->new_data = level;
|
||||||
|
|
@ -169,7 +168,12 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
|
||||||
const char *nick, const char *addr,
|
const char *nick, const char *addr,
|
||||||
const char *target)
|
const char *target)
|
||||||
{
|
{
|
||||||
sig_message(server, msg, nick, addr, target, MSGLEVEL_PUBLIC);
|
int level = MSGLEVEL_PUBLIC;
|
||||||
|
|
||||||
|
if (nick_match_msg(channel_find(server, target), msg, server->nick))
|
||||||
|
level |= MSGLEVEL_HILIGHT;
|
||||||
|
|
||||||
|
sig_message(server, msg, nick, addr, target, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sig_message_private(SERVER_REC *server, const char *msg,
|
static void sig_message_private(SERVER_REC *server, const char *msg,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue