diff options
46 files changed, 667 insertions, 687 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d6dd6e84..1cc943eb 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -18,6 +18,7 @@ libcore_a_SOURCES = \ channels.c \ channels-setup.c \ commands.c \ + chat-commands.c \ chat-protocols.c \ chatnets.c \ core.c \ diff --git a/src/core/channels.c b/src/core/channels.c index 1577472c..c21758af 100644 --- a/src/core/channels.c +++ b/src/core/channels.c @@ -21,10 +21,12 @@ #include "module.h" #include "signals.h" #include "misc.h" +#include "special-vars.h" +#include "servers.h" #include "channels.h" - -typedef CHANNEL_REC *(*CHANNEL_FIND_FUNC)(SERVER_REC *, const char *); +#include "channels-setup.h" +#include "nicklist.h" GSList *channels; /* List of all channels */ @@ -91,10 +93,7 @@ static CHANNEL_REC *channel_find_server(SERVER_REC *server, if (server->channel_find_func != NULL) { /* use the server specific channel find function */ - CHANNEL_FIND_FUNC channel_find_func; - channel_find_func = - (CHANNEL_FIND_FUNC) server->channel_find_func; - return channel_find_func(server, name); + return server->channel_find_func(server, name); } for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { @@ -122,11 +121,93 @@ CHANNEL_REC *channel_find(SERVER_REC *server, const char *name) (void *) name); } +/* connected to server, autojoin to channels. */ +static void event_connected(SERVER_REC *server) +{ + GString *chans; + GSList *tmp; + + g_return_if_fail(SERVER(server)); + + if (server->connrec->reconnection) + return; + + /* join to the channels marked with autojoin in setup */ + chans = g_string_new(NULL); + for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) { + CHANNEL_SETUP_REC *rec = tmp->data; + + if (!rec->autojoin || + !channel_chatnet_match(rec->chatnet, + server->connrec->chatnet)) + continue; + + g_string_sprintfa(chans, "%s,", rec->name); + } + + if (chans->len > 0) { + g_string_truncate(chans, chans->len-1); + server->channels_join(server, chans->str, TRUE); + } + + g_string_free(chans, TRUE); +} + +static int match_nick_flags(SERVER_REC *server, NICK_REC *nick, char flag) +{ + char *flags = server->get_nick_flags(); + + return (flag == flags[0] && nick->op) || + (flag == flags[1] && (nick->voice || nick->halfop || + nick->op)) || + (flag == flags[2] && (nick->halfop || nick->op)); +} + +/* Send the auto send command to channel */ +void channel_send_autocommands(CHANNEL_REC *channel) +{ + CHANNEL_SETUP_REC *rec; + NICK_REC *nick; + char **bots, **bot; + + g_return_if_fail(IS_CHANNEL(channel)); + + rec = channels_setup_find(channel->name, channel->server->connrec->chatnet); + if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd) + return; + + if (rec->botmasks == NULL || !*rec->botmasks) { + /* just send the command. */ + eval_special_string(rec->autosendcmd, "", channel->server, channel); + return; + } + + /* find first available bot.. */ + bots = g_strsplit(rec->botmasks, " ", -1); + for (bot = bots; *bot != NULL; bot++) { + const char *botnick = *bot; + + nick = nicklist_find(channel, + channel->server->isnickflag(*botnick) ? + botnick+1 : botnick); + if (nick == NULL || + !match_nick_flags(channel->server, nick, *botnick)) + continue; + + /* got one! */ + eval_special_string(rec->autosendcmd, nick->nick, channel->server, channel); + break; + } + g_strfreev(bots); +} + void channels_init(void) { + signal_add("event connected", (SIGNAL_FUNC) event_connected); } void channels_deinit(void) { + signal_remove("event connected", (SIGNAL_FUNC) event_connected); module_uniq_destroy("CHANNEL"); } diff --git a/src/core/channels.h b/src/core/channels.h index 91a330c1..1ebf7abb 100644 --- a/src/core/channels.h +++ b/src/core/channels.h @@ -29,6 +29,9 @@ void channel_destroy(CHANNEL_REC *channel); /* find channel by name, if `server' is NULL, search from all servers */ CHANNEL_REC *channel_find(SERVER_REC *server, const char *name); +/* Send the auto send command to channel */ +void channel_send_autocommands(CHANNEL_REC *channel); + void channels_init(void); void channels_deinit(void); diff --git a/src/core/chat-protocols.c b/src/core/chat-protocols.c index a5537f88..40413682 100644 --- a/src/core/chat-protocols.c +++ b/src/core/chat-protocols.c @@ -23,9 +23,7 @@ typedef struct { int id; - char *name; - char *fullname; - char *chatnet; + CHAT_PROTOCOL_REC *rec; } PROTOCOL_REC; static int id_counter; @@ -47,7 +45,7 @@ static PROTOCOL_REC *chat_protocol_find(const char *name) for (tmp = protocols; tmp != NULL; tmp = tmp->next) { PROTOCOL_REC *rec = tmp->data; - if (g_strcasecmp(rec->name, name) == 0) + if (g_strcasecmp(rec->rec->name, name) == 0) return rec; } @@ -71,25 +69,19 @@ static PROTOCOL_REC *chat_protocol_find_id(int id) } /* Register new chat protocol. */ -void chat_protocol_register(const char *name, - const char *fullname, - const char *chatnet) +void chat_protocol_register(CHAT_PROTOCOL_REC *rec) { - PROTOCOL_REC *rec; + PROTOCOL_REC *proto; - g_return_if_fail(name != NULL); - g_return_if_fail(fullname != NULL); - g_return_if_fail(chatnet != NULL); + g_return_if_fail(rec != NULL); - if (chat_protocol_find(name) != NULL) + if (chat_protocol_find(rec->name) != NULL) return; - rec = g_new0(PROTOCOL_REC, 1); - rec->id = ++id_counter; - rec->name = g_strdup(name); - rec->fullname = g_strdup(fullname); - rec->chatnet = g_strdup(chatnet); - protocols = g_slist_append(protocols, rec); + proto = g_new0(PROTOCOL_REC, 1); + proto->id = ++id_counter; + proto->rec = rec; + protocols = g_slist_append(protocols, proto); } static void chat_protocol_destroy(PROTOCOL_REC *rec) @@ -97,10 +89,7 @@ static void chat_protocol_destroy(PROTOCOL_REC *rec) g_return_if_fail(rec != NULL); protocols = g_slist_remove(protocols, rec); - - g_free(rec->name); - g_free(rec->fullname); - g_free(rec->chatnet); + g_free(rec->rec); g_free(rec); } @@ -126,37 +115,15 @@ int chat_protocol_lookup(const char *name) return rec == NULL ? -1 : rec->id; } -/* Return the name for the specified chat protocol ID. */ -const char *chat_protocol_get_name(int id) -{ - PROTOCOL_REC *rec; - - g_return_val_if_fail(id > 0, NULL); - - rec = chat_protocol_find_id(id); - return rec == NULL ? NULL : rec->name; -} - -/* Return the full name for the specified chat protocol ID. */ -const char *chat_protocol_get_fullname(int id) -{ - PROTOCOL_REC *rec; - - g_return_val_if_fail(id > 0, NULL); - - rec = chat_protocol_find_id(id); - return rec == NULL ? NULL : rec->fullname; -} - -/* Return the chatnet identifier name for the specified chat protocol ID. */ -const char *chat_protocol_get_chatnet(int id) +/* Return the record for the specified chat protocol ID. */ +CHAT_PROTOCOL_REC *chat_protocol_get_rec(int id) { PROTOCOL_REC *rec; g_return_val_if_fail(id > 0, NULL); rec = chat_protocol_find_id(id); - return rec == NULL ? NULL : rec->chatnet; + return rec == NULL ? NULL : rec->rec; } void chat_protocols_init(void) diff --git a/src/core/chat-protocols.h b/src/core/chat-protocols.h index 42b413cf..1f38da50 100644 --- a/src/core/chat-protocols.h +++ b/src/core/chat-protocols.h @@ -1,27 +1,27 @@ #ifndef __CHAT_PROTOCOLS_H #define __CHAT_PROTOCOLS_H +typedef struct { + char *name; + char *fullname; + char *chatnet; +} CHAT_PROTOCOL_REC; + #define PROTO_CHECK_CAST(object, cast, type_field, id) \ ((cast *) chat_protocol_check_cast(object, \ offsetof(cast, type_field), id)) void *chat_protocol_check_cast(void *object, int type_pos, const char *id); /* Register new chat protocol. */ -void chat_protocol_register(const char *name, - const char *fullname, - const char *chatnet); +void chat_protocol_register(CHAT_PROTOCOL_REC *rec); /* Unregister chat protocol. */ void chat_protocol_unregister(const char *name); /* Return the ID for the specified chat protocol. */ int chat_protocol_lookup(const char *name); -/* Return the name for the specified chat protocol ID. */ -const char *chat_protocol_get_name(int id); -/* Return the full name for the specified chat protocol ID. */ -const char *chat_protocol_get_fullname(int id); -/* Return the chatnet identifier name for the specified chat protocol ID. */ -const char *chat_protocol_get_chatnet(int id); +/* Return the record for the specified chat protocol ID. */ +CHAT_PROTOCOL_REC *chat_protocol_get_rec(int id); void chat_protocols_init(void); void chat_protocols_deinit(void); diff --git a/src/core/core.c b/src/core/core.c index c4e7e020..7ec453d1 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -39,6 +39,9 @@ #include "queries.h" #include "nicklist.h" +void chat_commands_init(void); +void chat_commands_deinit(void); + int irssi_gui; void core_init(void) @@ -62,6 +65,8 @@ void core_init(void) channels_init(); queries_init(); nicklist_init(); + + chat_commands_init(); } void core_deinit(void) @@ -69,6 +74,8 @@ void core_deinit(void) while (modules != NULL) module_unload(modules->data); + chat_commands_deinit(); + nicklist_deinit(); queries_deinit(); channels_deinit(); diff --git a/src/core/masks.c b/src/core/masks.c index 38fbdf45..909650b2 100644 --- a/src/core/masks.c +++ b/src/core/masks.c @@ -24,8 +24,6 @@ #include "servers.h" -typedef int (*MASK_MATCH_FUNC) (const char *, const char *); - /* Returns TRUE if mask contains '!' ie. address should be checked too. Also checks if mask contained any wildcards. */ static int check_address(const char *mask, int *wildcards) @@ -52,12 +50,9 @@ static int check_address(const char *mask, int *wildcards) static int check_mask(SERVER_REC *server, const char *mask, const char *str, int wildcards) { - MASK_MATCH_FUNC mask_match_func; - if (server != NULL && server->mask_match_func != NULL) { /* use server specified mask match function */ - mask_match_func = (MASK_MATCH_FUNC)server->mask_match_func; - return mask_match_func(mask, str); + return server->mask_match_func(mask, str); } return wildcards ? match_wildcards(mask, str) : @@ -103,7 +98,7 @@ int mask_match_address(SERVER_REC *server, const char *mask, int masks_match(SERVER_REC *server, const char *masks, const char *nick, const char *address) { - MASK_MATCH_FUNC mask_match_func; + int (*mask_match_func)(const char *, const char *); char **list, **tmp, *mask; int found; @@ -112,8 +107,7 @@ int masks_match(SERVER_REC *server, const char *masks, nick != NULL && address != NULL, FALSE); mask_match_func = server != NULL && server->mask_match_func != NULL ? - (MASK_MATCH_FUNC) server->mask_match_func : - (MASK_MATCH_FUNC) match_wildcards; + server->mask_match_func : match_wildcards; found = FALSE; mask = g_strdup_printf("%s!%s", nick, address); diff --git a/src/core/nicklist.c b/src/core/nicklist.c index 1ba78f94..0cb19123 100644 --- a/src/core/nicklist.c +++ b/src/core/nicklist.c @@ -25,6 +25,9 @@ #include "nicklist.h" #include "masks.h" +#define isalnumhigh(a) \ + (isalnum(a) || (unsigned char) (a) >= 128) + /* Add new nick to list */ NICK_REC *nicklist_insert(CHANNEL_REC *channel, const char *nick, int op, int voice, int send_massjoin) @@ -255,6 +258,48 @@ static void sig_channel_destroyed(CHANNEL_REC *channel) g_hash_table_destroy(channel->nicks); } +/* Check is `msg' is meant for `nick'. */ +int nick_match_msg(SERVER_REC *server, const char *msg, const char *nick) +{ + int len; + + g_return_val_if_fail(nick != NULL, FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + if (server != NULL && server->nick_match_msg != NULL) + return server->nick_match_msg(msg, nick); + + /* first check for identical match */ + len = strlen(nick); + if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len])) + return TRUE; + + /* check if it matches for alphanumeric parts of nick */ + 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 */ + } else + break; + + nick++; + } + + if (isalnumhigh(*msg)) { + /* message continues with another alphanumeric character, + it isn't for us. */ + return FALSE; + } + + /* remove all the non-alphanumeric characters at the end of + the nick and check if message matched that far. */ + while (*nick != '\0' && !isalnum(*nick)) nick++; + + return *nick == '\0'; +} + void nicklist_init(void) { signal_add_first("channel created", (SIGNAL_FUNC) sig_channel_created); diff --git a/src/core/nicklist.h b/src/core/nicklist.h index cd9276c3..c9015ab7 100644 --- a/src/core/nicklist.h +++ b/src/core/nicklist.h @@ -44,6 +44,9 @@ void nicklist_update_flags(SERVER_REC *server, const char *nick, /* Nick record comparision for sort functions */ int nicklist_compare(NICK_REC *p1, NICK_REC *p2); +/* Check is `msg' is meant for `nick'. */ +int nick_match_msg(SERVER_REC *server, const char *msg, const char *nick); + void nicklist_init(void); void nicklist_deinit(void); diff --git a/src/core/queries.c b/src/core/queries.c index c9793f7a..9be0f156 100644 --- a/src/core/queries.c +++ b/src/core/queries.c @@ -26,8 +26,6 @@ GSList *queries; -typedef QUERY_REC *(*QUERY_FIND_FUNC)(SERVER_REC *, const char *); - /* Create a new query */ QUERY_REC *query_create(int chat_type, SERVER_REC *server, const char *nick, int automatic) @@ -91,9 +89,7 @@ static QUERY_REC *query_find_server(SERVER_REC *server, const char *nick) if (server->query_find_func != NULL) { /* use the server specific query find function */ - QUERY_FIND_FUNC query_find_func; - query_find_func = (QUERY_FIND_FUNC) server->query_find_func; - return query_find_func(server, nick); + return server->query_find_func(server, nick); } for (tmp = server->queries; tmp != NULL; tmp = tmp->next) { diff --git a/src/core/server-rec.h b/src/core/server-rec.h index e9c069b7..8aaef6f9 100644 --- a/src/core/server-rec.h +++ b/src/core/server-rec.h @@ -32,6 +32,7 @@ GHashTable *module_data; char *version; /* server version */ char *away_reason; +char *last_invite; /* channel where you were last invited */ int server_operator:1; int usermode_away:1; int banned:1; /* not allowed to connect to this server */ @@ -43,9 +44,28 @@ int lag; /* server lag in milliseconds */ GSList *channels; GSList *queries; -/* support for multiple server types */ -void *channel_find_func; -void *query_find_func; -void *mask_match_func; +/* -- support for multiple server types -- */ + +/* -- must not be NULL: -- */ +/* join to a number of channels, channels are specified in `data' separated + with commas. there can exist other information after first space like + channel keys etc. */ +void (*channels_join)(void *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 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); +/* send public or private message to server */ +void (*send_message)(void *server, const char *target, const char *msg); + +/* -- Default implementations are used if NULL -- */ +void *(*channel_find_func)(void *server, const char *name); +void *(*query_find_func)(void *server, const char *nick); +int (*mask_match_func)(const char *mask, const char *data); +/* returns true if `msg' was meant for `nick' */ +int (*nick_match_msg)(const char *nick, const char *msg); #undef STRUCT_SERVER_CONNECT_REC diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index d28863a1..00b3f132 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -244,6 +244,16 @@ static void sig_reconnect(SERVER_REC *server) } } +static void sig_connected(SERVER_REC *server) +{ + g_return_if_fail(IS_SERVER(server)); + if (!server->connrec->reconnection) + return; + + if (server->connrec->channels != NULL) + server->channels_join(server, server->connrec->channels, TRUE); +} + /* Remove all servers from reconnect list */ /* SYNTAX: RMRECONNS */ static void cmd_rmreconns(void) @@ -336,10 +346,11 @@ void servers_reconnect_init(void) signal_add("server connect failed", (SIGNAL_FUNC) sig_reconnect); signal_add("server disconnected", (SIGNAL_FUNC) sig_reconnect); + signal_add("event connected", (SIGNAL_FUNC) sig_connected); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); command_bind("rmreconns", NULL, (SIGNAL_FUNC) cmd_rmreconns); command_bind("reconnect", NULL, (SIGNAL_FUNC) cmd_reconnect); command_bind_first("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect); - signal_add("setup changed", (SIGNAL_FUNC) read_settings); } void servers_reconnect_deinit(void) @@ -351,8 +362,9 @@ void servers_reconnect_deinit(void) signal_remove("server connect failed", (SIGNAL_FUNC) sig_reconnect); signal_remove("server disconnected", (SIGNAL_FUNC) sig_reconnect); + signal_remove("event connected", (SIGNAL_FUNC) sig_connected); + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); command_unbind("rmreconns", (SIGNAL_FUNC) cmd_rmreconns); command_unbind("reconnect", (SIGNAL_FUNC) cmd_reconnect); command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect); - signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/core/servers.c b/src/core/servers.c index b2f619ca..9ec53902 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -28,6 +28,7 @@ #include "rawlog.h" #include "settings.h" +#include "chat-protocols.h" #include "servers.h" #include "servers-reconnect.h" #include "servers-redirect.h" diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am index d739cdfe..962b4f5b 100644 --- a/src/fe-common/core/Makefile.am +++ b/src/fe-common/core/Makefile.am @@ -14,6 +14,7 @@ libfe_common_core_a_SOURCES = \ fe-common-core.c \ fe-core-commands.c \ fe-log.c \ + fe-messages.c \ fe-modules.c \ fe-queries.c \ fe-server.c \ diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c index 6d665c68..69ee9e18 100644 --- a/src/fe-common/core/fe-common-core.c +++ b/src/fe-common/core/fe-common-core.c @@ -49,6 +49,9 @@ void fe_core_log_deinit(void); void fe_log_init(void); void fe_log_deinit(void); +void fe_messages_init(void); +void fe_messages_deinit(void); + void fe_modules_init(void); void fe_modules_deinit(void); @@ -76,7 +79,6 @@ void fe_common_core_init(void) settings_add_bool("lookandfeel", "timestamps", TRUE); settings_add_bool("lookandfeel", "msgs_timestamps", FALSE); settings_add_bool("lookandfeel", "hide_text_style", FALSE); - settings_add_bool("lookandfeel", "show_nickmode", TRUE); settings_add_bool("lookandfeel", "bell_beeps", FALSE); settings_add_str("lookandfeel", "beep_on_msg", ""); settings_add_bool("lookandfeel", "beep_when_away", TRUE); @@ -99,6 +101,7 @@ void fe_common_core_init(void) fe_channels_init(); fe_queries_init(); fe_log_init(); + fe_messages_init(); fe_modules_init(); fe_server_init(); fe_settings_init(); @@ -121,6 +124,7 @@ void fe_common_core_deinit(void) printtext_deinit(); fe_channels_deinit(); fe_queries_deinit(); + fe_messages_deinit(); fe_log_deinit(); fe_modules_deinit(); fe_server_deinit(); diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c new file mode 100644 index 00000000..5a85b6f3 --- /dev/null +++ b/src/fe-common/core/fe-messages.c @@ -0,0 +1,222 @@ +/* + fe-messages.c : irssi + + Copyright (C) 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" +#include "commands.h" +#include "levels.h" +#include "special-vars.h" +#include "settings.h" + +#include "window-items.h" +#include "fe-queries.h" +#include "channels.h" +#include "nicklist.h" +#include "hilight-text.h" + +static char *get_nickmode(CHANNEL_REC *channel, const char *nick) +{ + NICK_REC *nickrec; + + g_return_val_if_fail(nick != NULL, NULL); + + nickrec = channel == NULL ? NULL : + nicklist_find(channel, nick); + return (nickrec == NULL || !settings_get_bool("show_nickmode")) ? + "" : (nickrec->op ? "@" : (nickrec->voice ? "+" : " ")); +} + +static void sig_message_public(SERVER_REC *server, const char *msg, + const char *nick, const char *address, + const char *target) +{ + CHANNEL_REC *chanrec; + const char *nickmode; + int for_me, print_channel, level; + char *color; + + chanrec = channel_find(server, target); + for_me = nick_match_msg(server, msg, server->nick); + color = for_me ? NULL : + hilight_find_nick(target, nick, address, MSGLEVEL_PUBLIC, msg); + + 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; + + level = MSGLEVEL_PUBLIC | + (color != NULL ? MSGLEVEL_HILIGHT : + (for_me ? MSGLEVEL_HILIGHT : MSGLEVEL_NOHILIGHT)); + + nickmode = get_nickmode(chanrec, nick); + if (!print_channel) { + /* message to active channel in window */ + if (color != NULL) { + /* highlighted nick */ + printformat(server, target, level, + IRCTXT_PUBMSG_HILIGHT, + color, nick, msg, nickmode); + } else { + printformat(server, target, level, + for_me ? IRCTXT_PUBMSG_ME : IRCTXT_PUBMSG, + nick, msg, nickmode); + } + } else { + /* message to not existing/active channel */ + if (color != NULL) { + /* highlighted nick */ + printformat(server, target, level, + IRCTXT_PUBMSG_HILIGHT_CHANNEL, + color, nick, target, msg, nickmode); + } else { + printformat(server, target, level, + for_me ? IRCTXT_PUBMSG_ME_CHANNEL : + IRCTXT_PUBMSG_CHANNEL, + nick, target, msg, nickmode); + } + } + + g_free_not_null(color); +} + +static void sig_message_private(SERVER_REC *server, const char *msg, + const char *nick, const char *address) +{ + QUERY_REC *query; + + query = privmsg_get_query(server, nick, FALSE, MSGLEVEL_MSGS); + printformat(server, nick, MSGLEVEL_MSGS, + query == NULL ? IRCTXT_MSG_PRIVATE : + IRCTXT_MSG_PRIVATE_QUERY, nick, address, msg); +} + +static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel, + const char *target, const char *msg) +{ + WINDOW_REC *window; + const char *nickmode; + int print_channel; + + nickmode = get_nickmode(channel, server->nick); + + window = channel == NULL ? NULL : + window_item_window((WI_ITEM_REC *) channel); + + print_channel = window == NULL || + window->active != (WI_ITEM_REC *) channel; + + if (!print_channel && settings_get_bool("print_active_channel") && + window != NULL && g_slist_length(window->items) > 1) + print_channel = TRUE; + + if (!print_channel) { + printformat(server, target, MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, + IRCTXT_OWN_MSG, server->nick, msg, nickmode); + } else { + printformat(server, target, MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, + IRCTXT_OWN_MSG_CHANNEL, server->nick, target, msg, nickmode); + } +} + +static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) +{ + GHashTable *optlist; + CHANNEL_REC *channel; + char *target, *msg, *freestr, *newtarget; + void *free_arg; + int free_ret; + + g_return_if_fail(data != 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); + 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); + + 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++; + } + + 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_free_not_null(freestr); + + cmd_params_free(free_arg); +} + +void fe_messages_init(void) +{ + settings_add_bool("lookandfeel", "show_nickmode", TRUE); + settings_add_bool("lookandfeel", "print_active_channel", FALSE); + + signal_add("message public", (SIGNAL_FUNC) sig_message_public); + signal_add("message private", (SIGNAL_FUNC) sig_message_private); + 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); + command_unbind("msg", (SIGNAL_FUNC) cmd_msg); +} diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c index 3c26c21e..32fca57f 100644 --- a/src/fe-common/core/fe-server.c +++ b/src/fe-common/core/fe-server.c @@ -102,7 +102,7 @@ static void cmd_server_add(const char *data) signal_emit("server add create", 2, &rec, optlist); if (rec == NULL) { /* no chatnet option specified, use the first. */ - g_hash_table_insert(optlist, (char *) chat_protocol_get_chatnet(1), ""); + g_hash_table_insert(optlist, (char *) chat_protocol_get_rec(1)->name, ""); signal_emit("server add create", 2, &rec, optlist); if (rec == NULL) { /* bug? */ diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index b31f9cbd..06029fe9 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -35,7 +35,7 @@ (MSGLEVEL_PUBLIC | MSGLEVEL_MSGS | \ MSGLEVEL_ACTIONS | MSGLEVEL_DCCMSGS) -static int hilight_next; +static int hilight_next, last_nick_color; GSList *hilights; static void hilight_add_config(HILIGHT_REC *rec) @@ -281,6 +281,30 @@ static void sig_print_text_stripped(WINDOW_REC *window, SERVER_REC *server, cons g_free_not_null(color); } +char *hilight_find_nick(const char *channel, const char *nick, + const char *address, int level, const char *msg) +{ + char *color, *mask; + + mask = g_strdup_printf("%s!%s", nick, address); + color = hilight_match(channel, mask, level, msg); + g_free(mask); + + last_nick_color = (color != NULL && *color == 3) ? + atoi(color+1) : 0; + return color; +} + +int hilight_last_nick_color(void) +{ + return last_nick_color; +} + +static void sig_message(void) +{ + last_nick_color = 0; +} + static void read_hilight_config(void) { CONFIG_NODE *node; @@ -448,6 +472,7 @@ static void cmd_dehilight(const char *data) void hilight_text_init(void) { hilight_next = FALSE; + last_nick_color = 0; read_hilight_config(); settings_add_str("misc", "hilight_color", "8"); @@ -456,6 +481,8 @@ void hilight_text_init(void) signal_add_first("print text", (SIGNAL_FUNC) sig_print_text); signal_add_first("print text stripped", (SIGNAL_FUNC) sig_print_text_stripped); signal_add("setup reread", (SIGNAL_FUNC) read_hilight_config); + signal_add_last("message public", (SIGNAL_FUNC) sig_message); + signal_add_last("message private", (SIGNAL_FUNC) sig_message); command_bind("hilight", NULL, (SIGNAL_FUNC) cmd_hilight); command_bind("dehilight", NULL, (SIGNAL_FUNC) cmd_dehilight); @@ -469,6 +496,8 @@ void hilight_text_deinit(void) signal_remove("print text", (SIGNAL_FUNC) sig_print_text); signal_remove("print text stripped", (SIGNAL_FUNC) sig_print_text_stripped); signal_remove("setup reread", (SIGNAL_FUNC) read_hilight_config); + signal_remove("message public", (SIGNAL_FUNC) sig_message); + signal_remove("message private", (SIGNAL_FUNC) sig_message); command_unbind("hilight", (SIGNAL_FUNC) cmd_hilight); command_unbind("dehilight", (SIGNAL_FUNC) cmd_dehilight); } diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h index c69be970..0d2291a4 100644 --- a/src/fe-common/core/hilight-text.h +++ b/src/fe-common/core/hilight-text.h @@ -17,7 +17,12 @@ typedef struct { extern GSList *hilights; -char *hilight_match(const char *channel, const char *nickmask, int level, const char *str); +char *hilight_match(const char *channel, const char *nickmask, + int level, const char *str); + +char *hilight_find_nick(const char *channel, const char *nick, + const char *address, int level, const char *msg); +int hilight_last_nick_color(void); void hilight_text_init(void); void hilight_text_deinit(void); diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 8670059f..3a7bd333 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -76,6 +76,24 @@ FORMAT_REC fecommon_core_formats[] = { { "chansetup_footer", "", 0 }, /* ---- */ + { NULL, "Messages", 0 }, + + { "own_msg", "%K<%n$2%W$0%K>%n %|$1", 3, { 0, 0, 0 } }, + { "own_msg_channel", "%K<%n$3%W$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, + { "own_msg_private", "%K[%rmsg%K(%R$0%K)]%n $1", 2, { 0, 0 } }, + { "own_msg_private_query", "%K<%W$2%K>%n %|$1", 3, { 0, 0, 0 } }, + { "pubmsg_me", "%K<%n$2%Y$0%K>%n %|$1", 3, { 0, 0, 0 } }, + { "pubmsg_me_channel", "%K<%n$3%Y$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, + { "pubmsg_hilight", "%K<%n$3$0$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, + { "pubmsg_hilight_channel", "%K<%n$4$0$1%K:%c$2%K>%n %|$3", 5, { 0, 0, 0, 0, 0 } }, + { "pubmsg", "%K<%n$2$0%K>%n %|$1", 3, { 0, 0, 0 } }, + { "pubmsg_channel", "%K<%n$3$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, + { "msg_private", "%K[%R$0%K(%r$1%K)]%n $2", 3, { 0, 0, 0 } }, + { "msg_private_query", "%K<%R$0%K>%n %|$2", 3, { 0, 0, 0 } }, + { "no_msgs_got", "You have not received a message from anyone yet", 0 }, + { "no_msgs_sent", "You have not sent a message to anyone yet", 0 }, + + /* ---- */ { NULL, "Queries", 0 }, { "query_start", "Starting query with %_$0%_", 1, { 0 } }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 41dcc1d5..7c53a3f2 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -51,13 +51,30 @@ enum { IRCTXT_CHANSETUP_LINE, IRCTXT_CHANSETUP_FOOTER, - IRCTXT_FILL_4, + IRCTXT_FILL_4, + + IRCTXT_OWN_MSG, + IRCTXT_OWN_MSG_CHANNEL, + IRCTXT_OWN_MSG_PRIVATE, + IRCTXT_OWN_MSG_PRIVATE_QUERY, + IRCTXT_PUBMSG_ME, + IRCTXT_PUBMSG_ME_CHANNEL, + IRCTXT_PUBMSG_HILIGHT, + IRCTXT_PUBMSG_HILIGHT_CHANNEL, + IRCTXT_PUBMSG, + IRCTXT_PUBMSG_CHANNEL, + IRCTXT_MSG_PRIVATE, + IRCTXT_MSG_PRIVATE_QUERY, + IRCTXT_NO_MSGS_GOT, + IRCTXT_NO_MSGS_SENT, + + IRCTXT_FILL_5, IRCTXT_QUERY_STARTED, IRCTXT_NO_QUERY, IRCTXT_QUERY_SERVER_CHANGED, - IRCTXT_FILL_5, + IRCTXT_FILL_6, IRCTXT_HILIGHT_HEADER, IRCTXT_HILIGHT_LINE, @@ -65,7 +82,7 @@ enum { IRCTXT_HILIGHT_NOT_FOUND, IRCTXT_HILIGHT_REMOVED, - IRCTXT_FILL_6, + IRCTXT_FILL_7, IRCTXT_ALIAS_ADDED, IRCTXT_ALIAS_REMOVED, @@ -74,7 +91,7 @@ enum { IRCTXT_ALIASLIST_LINE, IRCTXT_ALIASLIST_FOOTER, - IRCTXT_FILL_7, + IRCTXT_FILL_8, IRCTXT_LOG_OPENED, IRCTXT_LOG_CLOSED, @@ -91,7 +108,7 @@ enum { IRCTXT_LOG_NO_AWAY_MSGS, IRCTXT_LOG_AWAY_MSGS, - IRCTXT_FILL_8, + IRCTXT_FILL_9, IRCTXT_MODULE_ALREADY_LOADED, IRCTXT_MODULE_LOAD_ERROR, @@ -99,7 +116,7 @@ enum { IRCTXT_MODULE_LOADED, IRCTXT_MODULE_UNLOADED, - IRCTXT_FILL_9, + IRCTXT_FILL_10, IRCTXT_COMMAND_UNKNOWN, IRCTXT_COMMAND_AMBIGUOUS, @@ -113,7 +130,7 @@ enum { IRCTXT_CHAN_NOT_SYNCED, IRCTXT_NOT_GOOD_IDEA, - IRCTXT_FILL_10, + IRCTXT_FILL_11, IRCTXT_THEME_SAVED, IRCTXT_THEME_SAVE_FAILED, @@ -123,7 +140,7 @@ enum { IRCTXT_FORMAT_SUBTITLE, IRCTXT_FORMAT_ITEM, - IRCTXT_FILL_11, + IRCTXT_FILL_12, IRCTXT_NOT_TOGGLE, IRCTXT_PERL_ERROR, diff --git a/src/fe-common/core/window-activity.c b/src/fe-common/core/window-activity.c index 32783a18..0ae85f25 100644 --- a/src/fe-common/core/window-activity.c +++ b/src/fe-common/core/window-activity.c @@ -27,6 +27,8 @@ #include "windows.h" #include "window-items.h" +#include "nicklist.h" +#include "hilight-text.h" static const char *noact_channels; @@ -119,6 +121,58 @@ static void sig_hilight_window_item(WI_ITEM_REC *item) signal_emit("window activity", 2, window, GINT_TO_POINTER(oldlevel)); } +static void sig_message(SERVER_REC *server, const char *msg, + const char *nick, const char *addr, + const char *target, int level) +{ + WINDOW_REC *window; + WI_ITEM_REC *item; + + /* get window and window item */ + item = window_item_find(server, target); + window = item == NULL ? + window_find_closest(server, target, level) : + window_item_window(item); + + if (window == active_win) + return; + + /* hilight */ + if (item != NULL) item->last_color = hilight_last_nick_color(); + level = (item != NULL && item->last_color > 0) || + (level & MSGLEVEL_MSGS) || + nick_match_msg(SERVER(server), msg, server->nick) ? + NEWDATA_HILIGHT : NEWDATA_MSG; + if (item != NULL && item->new_data < level) { + item->new_data = level; + signal_emit("window item hilight", 1, item); + } else { + int oldlevel = window->new_data; + + if (window->new_data < level) { + window->new_data = level; + window->last_color = hilight_last_nick_color(); + signal_emit("window hilight", 2, window, + GINT_TO_POINTER(oldlevel)); + } + signal_emit("window activity", 2, window, + GINT_TO_POINTER(oldlevel)); + } +} + +static void sig_message_public(SERVER_REC *server, const char *msg, + const char *nick, const char *addr, + const char *target) +{ + sig_message(server, msg, nick, addr, target, MSGLEVEL_PUBLIC); +} + +static void sig_message_private(SERVER_REC *server, const char *msg, + const char *nick, const char *addr) +{ + sig_message(server, msg, nick, addr, nick, MSGLEVEL_MSGS); +} + static void read_settings(void) { noact_channels = settings_get_str("noact_channels"); @@ -134,6 +188,8 @@ void window_activity_init(void) signal_add("window changed", (SIGNAL_FUNC) sig_dehilight_window); signal_add("window dehilight", (SIGNAL_FUNC) sig_dehilight_window); signal_add("window item hilight", (SIGNAL_FUNC) sig_hilight_window_item); + signal_add("message public", (SIGNAL_FUNC) sig_message_public); + signal_add("message private", (SIGNAL_FUNC) sig_message_private); signal_add("setup changed", (SIGNAL_FUNC) read_settings); } @@ -144,5 +200,7 @@ void window_activity_deinit(void) signal_remove("window changed", (SIGNAL_FUNC) sig_dehilight_window); signal_remove("window dehilight", (SIGNAL_FUNC) sig_dehilight_window); signal_remove("window item hilight", (SIGNAL_FUNC) sig_hilight_window_item); + signal_remove("message public", (SIGNAL_FUNC) sig_message_public); + signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/fe-common/core/window-save.c b/src/fe-common/core/window-save.c index 175389c1..11125b61 100644 --- a/src/fe-common/core/window-save.c +++ b/src/fe-common/core/window-save.c @@ -130,8 +130,8 @@ static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node) subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK); iconfig_node_set_str(subnode, "type", type); - iconfig_node_set_str(subnode, "chat_type", - chat_protocol_get_name(rec->chat_type)); + type = chat_protocol_get_rec(rec->chat_type)->name; + iconfig_node_set_str(subnode, "chat_type", type); iconfig_node_set_str(subnode, "name", rec->name); if (server != NULL) diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am index 28196e37..9e3055c1 100644 --- a/src/fe-common/irc/Makefile.am +++ b/src/fe-common/irc/Makefile.am @@ -24,13 +24,10 @@ libfe_common_irc_a_SOURCES = \ fe-netsplit.c \ fe-common-irc.c \ irc-completion.c \ - irc-window-activity.c \ - irc-hilight-text.c \ irc-modules.c \ module-formats.c noinst_HEADERS = \ fe-common-irc.h \ - irc-hilight-text.h \ module.h \ module-formats.h diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c index e45d4bab..8692c596 100644 --- a/src/fe-common/irc/fe-common-irc.c +++ b/src/fe-common/irc/fe-common-irc.c @@ -67,12 +67,6 @@ void fe_netsplit_deinit(void); void fe_netjoin_init(void); void fe_netjoin_deinit(void); -void irc_hilight_text_init(void); -void irc_hilight_text_deinit(void); - -void irc_window_activity_init(void); -void irc_window_activity_deinit(void); - static char *autocon_server; static char *autocon_password; static int autocon_port; @@ -102,7 +96,6 @@ void fe_common_irc_init(void) settings_add_bool("lookandfeel", "show_away_once", TRUE); settings_add_bool("lookandfeel", "show_quit_once", FALSE); - settings_add_bool("lookandfeel", "print_active_channel", FALSE); theme_register(fecommon_irc_formats); @@ -117,8 +110,6 @@ void fe_common_irc_init(void) fe_netsplit_init(); fe_netjoin_init(); irc_completion_init(); - irc_hilight_text_init(); - irc_window_activity_init(); fe_irc_modules_init(); } @@ -138,8 +129,6 @@ void fe_common_irc_deinit(void) fe_netsplit_deinit(); fe_netjoin_deinit(); irc_completion_deinit(); - irc_hilight_text_deinit(); - irc_window_activity_deinit(); theme_unregister(); } diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index d317f5a9..9fcd935f 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -35,7 +35,6 @@ #include "fe-queries.h" #include "irc-channels.h" #include "irc-nicklist.h" -#include "irc-hilight-text.h" #include "windows.h" #include "completion.h" @@ -43,62 +42,8 @@ #define target_level(target) \ (ischannel((target)[0]) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS) -static void print_channel_msg(IRC_SERVER_REC *server, const char *msg, - const char *nick, const char *addr, - const char *target) -{ - IRC_CHANNEL_REC *chanrec; - NICK_REC *nickrec; - const char *nickmode; - int for_me, print_channel, level; - char *color; - - chanrec = irc_channel_find(server, target); - for_me = irc_nick_match(server->nick, msg); - color = for_me ? NULL : irc_hilight_find_nick(target, nick, addr, MSGLEVEL_PUBLIC, msg); - - nickrec = chanrec == NULL ? NULL : - nicklist_find(CHANNEL(chanrec), nick); - nickmode = (!settings_get_bool("show_nickmode") || nickrec == NULL) ? "" : - (nickrec->op ? "@" : nickrec->voice ? "+" : " "); - - 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; - - level = MSGLEVEL_PUBLIC | - (color != NULL ? MSGLEVEL_HILIGHT : - (for_me ? MSGLEVEL_HILIGHT : MSGLEVEL_NOHILIGHT)); - if (!print_channel) { - /* message to active channel in window */ - if (color != NULL) { - /* highlighted nick */ - printformat(server, target, level, IRCTXT_PUBMSG_HILIGHT, - color, nick, msg, nickmode); - } else { - printformat(server, target, level, - for_me ? IRCTXT_PUBMSG_ME : IRCTXT_PUBMSG, nick, msg, nickmode); - } - } else { - /* message to not existing/active channel */ - if (color != NULL) { - /* highlighted nick */ - printformat(server, target, level, IRCTXT_PUBMSG_HILIGHT_CHANNEL, - color, nick, target, msg, nickmode); - } else { - printformat(server, target, level, - for_me ? IRCTXT_PUBMSG_ME_CHANNEL : IRCTXT_PUBMSG_CHANNEL, - nick, target, msg, nickmode); - } - } - - g_free_not_null(color); -} - static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr) { - QUERY_REC *query; char *params, *target, *msg; g_return_if_fail(data != NULL); @@ -108,15 +53,9 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char * if (addr == NULL) addr = ""; if (!ignore_check(server, nick, addr, target, msg, target_level(target))) { - if (ischannel(*target)) { - /* message to channel */ - print_channel_msg(server, msg, nick, addr, target); - } else { - /* private message */ - query = privmsg_get_query(SERVER(server), nick, FALSE, MSGLEVEL_MSGS); - printformat(server, nick, MSGLEVEL_MSGS, - query == NULL ? IRCTXT_MSG_PRIVATE : IRCTXT_MSG_PRIVATE_QUERY, nick, addr, msg); - } + 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-commands.c b/src/fe-common/irc/fe-irc-commands.c index 852e2ecc..aae3bbc1 100644 --- a/src/fe-common/irc/fe-irc-commands.c +++ b/src/fe-common/irc/fe-irc-commands.c @@ -37,96 +37,6 @@ #include "windows.h" #include "window-items.h" -static void cmd_msg(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) -{ - GHashTable *optlist; - WINDOW_REC *window; - IRC_CHANNEL_REC *channel; - NICK_REC *nickrec; - const char *nickmode; - char *target, *msg, *freestr, *newtarget; - void *free_arg; - int free_ret, print_channel; - - g_return_if_fail(data != 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 = IRC_SERVER(cmd_options_get_server("msg", optlist, SERVER(server))); - - if (*target == '=') - { - /* dcc msg - handled in fe-dcc.c */ - cmd_params_free(free_arg); - return; - } - - free_ret = FALSE; - if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) - newtarget = parse_special(&target, SERVER(server), item, NULL, &free_ret, NULL); - else if (strcmp(target, "*") == 0 && - (IS_IRC_CHANNEL(item) || IS_IRC_QUERY(item))) - newtarget = item->name; - else newtarget = target; - - 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; - - if (server == NULL || !server->connected) cmd_param_error(CMDERR_NOT_CONNECTED); - channel = irc_channel_find(server, target); - - freestr = !free_ret ? NULL : target; - if (*target == '@' && ischannel(target[1])) - target++; /* Hybrid 6 feature, send msg to all ops in channel */ - - if (ischannel(*target)) - { - /* msg to channel */ - nickrec = channel == NULL ? NULL : - nicklist_find(CHANNEL(channel), server->nick); - nickmode = !settings_get_bool("show_nickmode") || nickrec == NULL ? "" : - nickrec->op ? "@" : nickrec->voice ? "+" : " "; - - window = channel == NULL ? NULL : window_item_window((WI_ITEM_REC *) channel); - - print_channel = window == NULL || - window->active != (WI_ITEM_REC *) channel; - if (!print_channel && settings_get_bool("print_active_channel") && - window != NULL && g_slist_length(window->items) > 1) - print_channel = TRUE; - - if (!print_channel) - { - printformat(server, target, MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - IRCTXT_OWN_MSG, server->nick, msg, nickmode); - } - else - { - printformat(server, target, MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - IRCTXT_OWN_MSG_CHANNEL, server->nick, target, msg, nickmode); - } - } - else - { - /* private message */ - item = (WI_ITEM_REC *) privmsg_get_query(SERVER(server), target, TRUE, MSGLEVEL_MSGS); - printformat(server, target, MSGLEVEL_MSGS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT, - item == NULL ? IRCTXT_OWN_MSG_PRIVATE : IRCTXT_OWN_MSG_PRIVATE_QUERY, target, msg, server->nick); - } - g_free_not_null(freestr); - - cmd_params_free(free_arg); -} - /* SYNTAX: ME <message> */ static void cmd_me(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { @@ -428,7 +338,6 @@ static void cmd_ts(const char *data) void fe_irc_commands_init(void) { - command_bind_last("msg", NULL, (SIGNAL_FUNC) cmd_msg); command_bind_last("me", NULL, (SIGNAL_FUNC) cmd_me); command_bind_last("action", NULL, (SIGNAL_FUNC) cmd_action); command_bind("notice", NULL, (SIGNAL_FUNC) cmd_notice); @@ -445,7 +354,6 @@ void fe_irc_commands_init(void) void fe_irc_commands_deinit(void) { - command_unbind("msg", (SIGNAL_FUNC) cmd_msg); command_unbind("me", (SIGNAL_FUNC) cmd_me); command_unbind("action", (SIGNAL_FUNC) cmd_action); command_unbind("notice", (SIGNAL_FUNC) cmd_notice); diff --git a/src/fe-common/irc/irc-completion.c b/src/fe-common/irc/irc-completion.c index 3f06fee4..005e8bd3 100644 --- a/src/fe-common/irc/irc-completion.c +++ b/src/fe-common/irc/irc-completion.c @@ -235,7 +235,7 @@ static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char * } mchannel = MODULE_DATA(channel); - list = irc_nick_match(server->nick, msg) ? + list = nick_match_msg(SERVER(server), msg, server->nick) ? &mchannel->lastownmsgs : &mchannel->lastmsgs; nick_completion_create(list, time(NULL), nick); diff --git a/src/fe-common/irc/irc-hilight-text.c b/src/fe-common/irc/irc-hilight-text.c deleted file mode 100644 index 7969f7d4..00000000 --- a/src/fe-common/irc/irc-hilight-text.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - irc-hilight-text.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 "signals.h" -#include "settings.h" - -#include "hilight-text.h" - -static int last_color; - -char *irc_hilight_find_nick(const char *channel, const char *nick, - const char *address, int level, const char *msg) -{ - char *color, *mask; - - mask = g_strdup_printf("%s!%s", nick, address); - color = hilight_match(channel, mask, level, msg); - g_free(mask); - - last_color = (color != NULL && *color == 3) ? - atoi(color+1) : 0; - return color; -} - -int irc_hilight_last_color(void) -{ - return last_color; -} - -static void event_privmsg(void) -{ - last_color = 0; -} - -void irc_hilight_text_init(void) -{ - last_color = 0; - signal_add_last("event privmsg", (SIGNAL_FUNC) event_privmsg); -} - -void irc_hilight_text_deinit(void) -{ - signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg); -} diff --git a/src/fe-common/irc/irc-hilight-text.h b/src/fe-common/irc/irc-hilight-text.h deleted file mode 100644 index 9d2b1b3d..00000000 --- a/src/fe-common/irc/irc-hilight-text.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __IRC_HILIGHT_TEXT_H -#define __IRC_HILIGHT_TEXT_H - -char *irc_hilight_find_nick(const char *channel, const char *nick, - const char *address, int level, const char *msg); - -int irc_hilight_last_color(void); - -#endif diff --git a/src/fe-common/irc/irc-window-activity.c b/src/fe-common/irc/irc-window-activity.c deleted file mode 100644 index 4cb2fae8..00000000 --- a/src/fe-common/irc/irc-window-activity.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - irc-window-activity.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 "signals.h" -#include "levels.h" - -#include "irc.h" -#include "ignore.h" -#include "irc-servers.h" -#include "irc-nicklist.h" - -#include "completion.h" -#include "windows.h" -#include "window-items.h" -#include "irc-hilight-text.h" - -static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr) -{ - WINDOW_REC *window; - WI_ITEM_REC *item; - char *params, *target, *msg; - int level; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg); - - /* get window and window item */ - level = ischannel(*target) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS; - item = window_item_find(server, ischannel(*target) ? target : nick); - window = item == NULL ? - window_find_closest(server, target, GPOINTER_TO_INT(level)) : - window_item_window(item); - - /* check that msg wasn't send to current window and - that it didn't get ignored */ - if (window != active_win && !ignore_check(server, nick, addr, target, msg, level)) { - /* hilight */ - if (item != NULL) item->last_color = irc_hilight_last_color(); - level = (item != NULL && item->last_color > 0) || - !ischannel(*target) || irc_nick_match(server->nick, msg) ? - NEWDATA_HILIGHT : NEWDATA_MSG; - if (item != NULL && item->new_data < level) { - item->new_data = level; - signal_emit("window item hilight", 1, item); - } else { - int oldlevel = window->new_data; - - if (window->new_data < level) { - window->new_data = level; - window->last_color = irc_hilight_last_color(); - signal_emit("window hilight", 2, window, GINT_TO_POINTER(oldlevel)); - } - signal_emit("window activity", 2, window, GINT_TO_POINTER(oldlevel)); - } - } - - g_free(params); -} - -void irc_window_activity_init(void) -{ - signal_add_last("event privmsg", (SIGNAL_FUNC) event_privmsg); -} - -void irc_window_activity_deinit(void) -{ - signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg); -} diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c index 1a1c433c..ab6bf381 100644 --- a/src/fe-common/irc/module-formats.c +++ b/src/fe-common/irc/module-formats.c @@ -122,10 +122,6 @@ FORMAT_REC fecommon_irc_formats[] = { /* ---- */ { NULL, "Your messages", 0 }, - { "own_msg", "%K<%n$2%W$0%K>%n %|$1", 3, { 0, 0, 0 } }, - { "own_msg_channel", "%K<%n$3%W$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, - { "own_msg_private", "%K[%rmsg%K(%R$0%K)]%n $1", 2, { 0, 0 } }, - { "own_msg_private_query", "%K<%W$2%K>%n %|$1", 3, { 0, 0, 0 } }, { "own_notice", "%K[%rnotice%K(%R$0%K)]%n $1", 2, { 0, 0 } }, { "own_action", "%W * $0%n $1", 2, { 0, 0 } }, { "own_ctcp", "%K[%rctcp%K(%R$0%K)]%n $1 $2", 3, { 0, 0, 0 } }, @@ -134,14 +130,6 @@ FORMAT_REC fecommon_irc_formats[] = { /* ---- */ { NULL, "Received messages", 0 }, - { "pubmsg_me", "%K<%n$2%Y$0%K>%n %|$1", 3, { 0, 0, 0 } }, - { "pubmsg_me_channel", "%K<%n$3%Y$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, - { "pubmsg_hilight", "%K<%n$3$0$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, - { "pubmsg_hilight_channel", "%K<%n$4$0$1%K:%c$2%K>%n %|$3", 5, { 0, 0, 0, 0, 0 } }, - { "pubmsg", "%K<%n$2$0%K>%n %|$1", 3, { 0, 0, 0 } }, - { "pubmsg_channel", "%K<%n$3$0%K:%c$1%K>%n %|$2", 4, { 0, 0, 0, 0 } }, - { "msg_private", "%K[%R$0%K(%r$1%K)]%n $2", 3, { 0, 0, 0 } }, - { "msg_private_query", "%K<%R$0%K>%n %|$2", 3, { 0, 0, 0 } }, { "notice_server", "%g!$0%n $1", 2, { 0, 0 } }, { "notice_public", "%K-%M$0%K:%m$1%K-%n $2", 3, { 0, 0, 0 } }, { "notice_public_ops", "%K-%M$0%K:%m@$1%K-%n $2", 3, { 0, 0, 0 } }, @@ -180,8 +168,6 @@ FORMAT_REC fecommon_irc_formats[] = { { "ignore_header", "Ignorance List:", 0 }, { "ignore_line", "$[-4]0 $1: $2 $3 $4", 4, { 1, 0, 0, 0 } }, { "ignore_footer", "", 0 }, - { "no_msgs_got", "You have not received a message from anyone yet", 0 }, - { "no_msgs_sent", "You have not sent a message to anyone yet", 0 }, { NULL, NULL, 0 } }; diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h index 9a49926e..c85905f0 100644 --- a/src/fe-common/irc/module-formats.h +++ b/src/fe-common/irc/module-formats.h @@ -96,10 +96,6 @@ enum { IRCTXT_FILL_6, - IRCTXT_OWN_MSG, - IRCTXT_OWN_MSG_CHANNEL, - IRCTXT_OWN_MSG_PRIVATE, - IRCTXT_OWN_MSG_PRIVATE_QUERY, IRCTXT_OWN_NOTICE, IRCTXT_OWN_ME, IRCTXT_OWN_CTCP, @@ -107,14 +103,6 @@ enum { IRCTXT_FILL_7, - IRCTXT_PUBMSG_ME, - IRCTXT_PUBMSG_ME_CHANNEL, - IRCTXT_PUBMSG_HILIGHT, - IRCTXT_PUBMSG_HILIGHT_CHANNEL, - IRCTXT_PUBMSG, - IRCTXT_PUBMSG_CHANNEL, - IRCTXT_MSG_PRIVATE, - IRCTXT_MSG_PRIVATE_QUERY, IRCTXT_NOTICE_SERVER, IRCTXT_NOTICE_PUBLIC, IRCTXT_NOTICE_PUBLIC_OPS, @@ -149,9 +137,7 @@ enum { IRCTXT_IGNORE_NO_IGNORES, IRCTXT_IGNORE_HEADER, IRCTXT_IGNORE_LINE, - IRCTXT_IGNORE_FOOTER, - IRCTXT_NO_MSGS_GOT, - IRCTXT_NO_MSGS_SENT + IRCTXT_IGNORE_FOOTER }; extern FORMAT_REC fecommon_irc_formats[]; diff --git a/src/irc/core/channel-rejoin.c b/src/irc/core/channel-rejoin.c index 0715952e..9efed72c 100644 --- a/src/irc/core/channel-rejoin.c +++ b/src/irc/core/channel-rejoin.c @@ -75,7 +75,7 @@ static void server_rejoin_channels(IRC_SERVER_REC *server) while (server->rejoin_channels != NULL) { char *channel = server->rejoin_channels->data; - irc_channels_join(server, channel, TRUE); + server->channels_join(server, channel, TRUE); server->rejoin_channels = g_slist_remove(server->rejoin_channels, channel); } diff --git a/src/irc/core/ignore.c b/src/irc/core/ignore.c index ae85a22b..7ec3122e 100644 --- a/src/irc/core/ignore.c +++ b/src/irc/core/ignore.c @@ -56,7 +56,7 @@ static int ignore_check_replies(IGNORE_REC *rec, IRC_SERVER_REC *server, for (tmp = nicks; tmp != NULL; tmp = tmp->next) { NICK_REC *nick = tmp->data; - if (irc_nick_match(nick->nick, text)) + if (nick_match_msg(SERVER(server), text, nick->nick)) return TRUE; } g_slist_free(nicks); @@ -114,7 +114,7 @@ int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host, /* pattern */ patt_len = 0; - if (rec->pattern != NULL) { + if (rec->pattern != NULL && text != NULL) { if (!mask_len && !best_mask) { patt_len = strlen(rec->pattern); if (patt_len <= best_patt) continue; diff --git a/src/irc/core/irc-channels-setup.c b/src/irc/core/irc-channels-setup.c index 51d8a991..33e383de 100644 --- a/src/irc/core/irc-channels-setup.c +++ b/src/irc/core/irc-channels-setup.c @@ -20,95 +20,14 @@ #include "module.h" #include "signals.h" -#include "nicklist.h" -#include "servers.h" -#include "special-vars.h" - -#include "servers-setup.h" -#include "channels-setup.h" - -#include "irc.h" -#include "irc-chatnets.h" -#include "irc-servers.h" -#include "irc-channels.h" - -/* connected to server, autojoin to channels. */ -static void event_connected(IRC_SERVER_REC *server) -{ - GString *chans; - GSList *tmp; - - if (!IS_IRC_SERVER(server) || server->connrec->reconnection) - return; - - /* join to the channels marked with autojoin in setup */ - chans = g_string_new(NULL); - for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) { - CHANNEL_SETUP_REC *rec = tmp->data; - - if (!rec->autojoin || - !channel_chatnet_match(rec->chatnet, - server->connrec->chatnet)) - continue; - - g_string_sprintfa(chans, "%s,", rec->name); - } - - if (chans->len > 0) { - g_string_truncate(chans, chans->len-1); - irc_channels_join(server, chans->str, TRUE); - } - - g_string_free(chans, TRUE); -} - -/* channel wholist received: send the auto send command */ -static void channel_wholist(CHANNEL_REC *channel) -{ - CHANNEL_SETUP_REC *rec; - NICK_REC *nick; - char **bots, **bot; - - g_return_if_fail(IS_CHANNEL(channel)); - - rec = channels_setup_find(channel->name, channel->server->connrec->chatnet); - if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd) - return; - - if (rec->botmasks == NULL || !*rec->botmasks) { - /* just send the command. */ - eval_special_string(rec->autosendcmd, "", channel->server, channel); - return; - } - - /* find first available bot.. */ - bots = g_strsplit(rec->botmasks, " ", -1); - for (bot = bots; *bot != NULL; bot++) { - const char *botnick = *bot; - - nick = nicklist_find(channel, isnickflag(*botnick) ? - botnick+1 : botnick); - if (nick == NULL) - continue; - if ((*botnick == '@' && !nick->op) || - (*botnick == '+' && !nick->voice && !nick->op)) - continue; - - /* got one! */ - eval_special_string(rec->autosendcmd, nick->nick, channel->server, channel); - break; - } - g_strfreev(bots); -} +#include "channels.h" void irc_channels_setup_init(void) { - signal_add("event connected", (SIGNAL_FUNC) event_connected); - signal_add("channel wholist", (SIGNAL_FUNC) channel_wholist); + signal_add("channel wholist", (SIGNAL_FUNC) channel_send_autocommands); } void irc_channels_setup_deinit(void) { - signal_remove("event connected", (SIGNAL_FUNC) event_connected); - signal_remove("channel wholist", (SIGNAL_FUNC) channel_wholist); + signal_remove("channel wholist", (SIGNAL_FUNC) channel_send_autocommands); } diff --git a/src/irc/core/irc-channels.c b/src/irc/core/irc-channels.c index 7786199a..fffd2445 100644 --- a/src/irc/core/irc-channels.c +++ b/src/irc/core/irc-channels.c @@ -92,7 +92,8 @@ static void sig_channel_destroyed(IRC_CHANNEL_REC *channel) #define get_join_key(key) \ (((key) == NULL || *(key) == '\0') ? "x" : (key)) -void irc_channels_join(IRC_SERVER_REC *server, const char *data, int automatic) +static void irc_channels_join(IRC_SERVER_REC *server, const char *data, + int automatic) { CHANNEL_SETUP_REC *schannel; IRC_CHANNEL_REC *chanrec; @@ -191,6 +192,7 @@ static void sig_connected(SERVER_REC *server) return; server->channel_find_func = (void *) irc_channel_find_server; + server->channels_join = (void *) irc_channels_join; } void irc_channels_init(void) diff --git a/src/irc/core/irc-channels.h b/src/irc/core/irc-channels.h index 5181378f..41826cb1 100644 --- a/src/irc/core/irc-channels.h +++ b/src/irc/core/irc-channels.h @@ -35,8 +35,4 @@ IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server, #define irc_channel_find(server, name) \ IRC_CHANNEL(channel_find(SERVER(server), name)) -/* Join to channels. `data' contains channels and channel keys */ -void irc_channels_join(IRC_SERVER_REC *server, - const char *data, int automatic); - #endif diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index 035b17b1..5c8fe19b 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -153,42 +153,6 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server, cmd_params_free(free_arg); } -/* SYNTAX: MSG [-<server tag>] <targets> <message> */ -static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) -{ - GHashTable *optlist; - char *target, *msg; - void *free_arg; - int free_ret; - - g_return_if_fail(data != 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 = IRC_SERVER(cmd_options_get_server("msg", optlist, SERVER(server))); - if (!IS_IRC_SERVER(server) || !server->connected) - cmd_param_error(CMDERR_NOT_CONNECTED); - - free_ret = FALSE; - if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) - target = parse_special(&target, SERVER(server), item, NULL, &free_ret, NULL); - else if (strcmp(target, "*") == 0 && - (IS_IRC_CHANNEL(item) || IS_IRC_QUERY(item))) - target = item->name; - if (target != NULL) { - g_string_sprintf(tmpstr, "PRIVMSG %s :%s", target, msg); - irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd); - } - - if (free_ret && target != NULL) g_free(target); - - cmd_params_free(free_arg); -} - /* SYNTAX: NOTICE <targets> <message> */ static void cmd_notice(const char *data, IRC_SERVER_REC *server) { @@ -254,33 +218,6 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server) cmd_params_free(free_arg); } -/* SYNTAX: JOIN [-invite] [-<server tag>] <channels> [<keys>] */ -static void cmd_join(const char *data, IRC_SERVER_REC *server) -{ - GHashTable *optlist; - char *channels; - void *free_arg; - - g_return_if_fail(data != NULL); - if (!IS_IRC_SERVER(server) || !server->connected) - cmd_return_error(CMDERR_NOT_CONNECTED); - - if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS | - PARAM_FLAG_GETREST, "join", &optlist, &channels)) - return; - - if (g_hash_table_lookup(optlist, "invite")) { - if (server->last_invite != NULL) - irc_channels_join(server, server->last_invite, FALSE); - } else { - /* -<server tag> */ - server = IRC_SERVER(cmd_options_get_server("join", optlist, SERVER(server))); - if (server != NULL) irc_channels_join(server, channels, FALSE); - } - - cmd_params_free(free_arg); -} - /* SYNTAX: PART [<channels>] [<message>] */ static void cmd_part(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { @@ -946,11 +883,9 @@ void irc_commands_init(void) signal_add("server connected", (SIGNAL_FUNC) sig_connected); command_bind("server", NULL, (SIGNAL_FUNC) cmd_server); command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect); - command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg); command_bind("notice", NULL, (SIGNAL_FUNC) cmd_notice); command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp); command_bind("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp); - command_bind("join", NULL, (SIGNAL_FUNC) cmd_join); command_bind("part", NULL, (SIGNAL_FUNC) cmd_part); command_bind("kick", NULL, (SIGNAL_FUNC) cmd_kick); command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic); @@ -1036,7 +971,6 @@ void irc_commands_init(void) command_set_options("topic", "delete"); command_set_options("list", "yes"); command_set_options("away", "one all"); - command_set_options("join", "invite"); } void irc_commands_deinit(void) @@ -1046,11 +980,9 @@ void irc_commands_deinit(void) signal_remove("server connected", (SIGNAL_FUNC) sig_connected); command_unbind("server", (SIGNAL_FUNC) cmd_server); command_unbind("connect", (SIGNAL_FUNC) cmd_connect); - command_unbind("msg", (SIGNAL_FUNC) cmd_msg); command_unbind("notice", (SIGNAL_FUNC) cmd_notice); command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp); command_unbind("nctcp", (SIGNAL_FUNC) cmd_nctcp); - command_unbind("join", (SIGNAL_FUNC) cmd_join); command_unbind("part", (SIGNAL_FUNC) cmd_part); command_unbind("kick", (SIGNAL_FUNC) cmd_kick); command_unbind("topic", (SIGNAL_FUNC) cmd_topic); diff --git a/src/irc/core/irc-core.c b/src/irc/core/irc-core.c index 657696ef..104fc403 100644 --- a/src/irc/core/irc-core.c +++ b/src/irc/core/irc-core.c @@ -51,7 +51,14 @@ void irc_channels_setup_deinit(void); void irc_core_init(void) { - chat_protocol_register("IRC", "Internet Relay Chat", "ircnet"); + CHAT_PROTOCOL_REC *rec; + + rec = g_new0(CHAT_PROTOCOL_REC, 1); + rec->name = "IRC"; + rec->fullname = "Internet Relay Chat"; + rec->chatnet = "ircnet"; + + chat_protocol_register(rec); irc_chatnets_init(); irc_servers_init(); diff --git a/src/irc/core/irc-nicklist.c b/src/irc/core/irc-nicklist.c index 3b3dcd8a..420b3834 100644 --- a/src/irc/core/irc-nicklist.c +++ b/src/irc/core/irc-nicklist.c @@ -34,9 +34,6 @@ (a) == '[' || (a) == ']' || (a) == '{' || (a) == '}' || \ (a) == '|' || (a) == '\\' || (a) == '^') -#define isalnumhigh(a) \ - (isalnum(a) || (unsigned char) (a) >= 128) - /* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *irc_nick_strip(const char *nick) { @@ -56,45 +53,6 @@ char *irc_nick_strip(const char *nick) return stripped; } -/* Check is `msg' is meant for `nick'. */ -int irc_nick_match(const char *nick, const char *msg) -{ - int len; - - g_return_val_if_fail(nick != NULL, FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - /* first check for identical match */ - len = strlen(nick); - if (g_strncasecmp(msg, nick, len) == 0 && !isalnumhigh((int) msg[len])) - return TRUE; - - /* check if it matches for alphanumeric parts of nick */ - 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 */ - } else - break; - - nick++; - } - - if (isalnumhigh(*msg)) { - /* message continues with another alphanumeric character, - it isn't for us. */ - return FALSE; - } - - /* remove all the non-alphanumeric characters at the end of - the nick and check if message matched that far. */ - while (*nick != '\0' && !isalnum(*nick)) nick++; - - return *nick == '\0'; -} - static void event_names_list(const char *data, SERVER_REC *server) { CHANNEL_REC *chanrec; @@ -378,6 +336,17 @@ static void sig_usermode(SERVER_REC *server) nicklist_update_flags(server, server->nick, server->usermode_away, -1); } +static const char *get_nick_flags(void) +{ + return "@+%"; +} + +static void sig_connected(IRC_SERVER_REC *server) +{ + if (IS_IRC_SERVER(server)) + server->get_nick_flags = (void *) get_nick_flags; +} + void irc_nicklist_init(void) { signal_add("event nick", (SIGNAL_FUNC) event_nick); @@ -395,6 +364,7 @@ void irc_nicklist_init(void) signal_add("event 302", (SIGNAL_FUNC) event_userhost); signal_add("userhost event", (SIGNAL_FUNC) event_userhost); signal_add("user mode changed", (SIGNAL_FUNC) sig_usermode); + signal_add("server connected", (SIGNAL_FUNC) sig_connected); } void irc_nicklist_deinit(void) @@ -414,4 +384,5 @@ void irc_nicklist_deinit(void) signal_remove("event 302", (SIGNAL_FUNC) event_userhost); signal_remove("userhost event", (SIGNAL_FUNC) event_userhost); signal_remove("user mode changed", (SIGNAL_FUNC) sig_usermode); + signal_remove("server connected", (SIGNAL_FUNC) sig_connected); } diff --git a/src/irc/core/irc-nicklist.h b/src/irc/core/irc-nicklist.h index e4172b89..f6c7be51 100644 --- a/src/irc/core/irc-nicklist.h +++ b/src/irc/core/irc-nicklist.h @@ -9,7 +9,4 @@ void irc_nicklist_deinit(void); /* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *irc_nick_strip(const char *nick); -/* Check if `msg' is meant for `nick'. */ -int irc_nick_match(const char *nick, const char *msg); - #endif diff --git a/src/irc/core/irc-servers-reconnect.c b/src/irc/core/irc-servers-reconnect.c index 2b44ea4b..7ff72eac 100644 --- a/src/irc/core/irc-servers-reconnect.c +++ b/src/irc/core/irc-servers-reconnect.c @@ -90,11 +90,9 @@ static int sig_set_user_mode(IRC_SERVER_REC *server) static void sig_connected(IRC_SERVER_REC *server) { - if (!server->connrec->reconnection) + if (!IS_IRC_SERVER(server) || !server->connrec->reconnection) return; - if (server->connrec->channels != NULL) - irc_channels_join(server, server->connrec->channels, TRUE); if (server->connrec->away_reason != NULL) signal_emit("command away", 2, server->connrec->away_reason, server, NULL); if (server->connrec->usermode != NULL) { diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 16e6ed40..5ce3b45e 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -61,6 +61,30 @@ static void sig_server_connect_free(IRC_SERVER_CONNECT_REC *conn) g_free_not_null(conn->alternate_nick); } +static int isnickflag_func(char flag) +{ + return isnickflag(flag); +} + +static int ischannel_func(char flag) +{ + return ischannel(flag); +} + +static void send_message(IRC_SERVER_REC *server, const char *target, + const char *msg) +{ + char *str; + + g_return_if_fail(server != NULL); + g_return_if_fail(target != NULL); + g_return_if_fail(msg != NULL); + + str = g_strdup_printf("PRIVMSG %s :%s", target, msg); + irc_send_cmd_split(server, str, 2, server->max_msgs_in_cmd); + g_free(str); +} + static void server_init(IRC_SERVER_REC *server) { IRC_SERVER_CONNECT_REC *conn; @@ -100,6 +124,9 @@ static void server_init(IRC_SERVER_REC *server) address, conn->realname); server->cmdcount = 0; + server->isnickflag = isnickflag_func; + server->ischannel = ischannel_func; + server->send_message = (void *) send_message; } IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn) diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index 0b66f27c..25b6f422 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -37,7 +37,6 @@ typedef struct { char *real_address; /* address the irc server gives */ char *usermode; /* The whole mode string .. */ char *userhost; /* /USERHOST <nick> - set when joined to first channel */ - char *last_invite; /* channel where you were last invited */ int whois_coming:1; /* Mostly just to display away message right.. */ int whois_found:1; /* Did WHOIS return any entries? */ diff --git a/src/perl/Makefile.am b/src/perl/Makefile.am index 4022876d..8ef5ddf0 100644 --- a/src/perl/Makefile.am +++ b/src/perl/Makefile.am @@ -19,35 +19,36 @@ perl-signals.h: $(top_srcdir)/docs/signals.txt $(srcdir)/get-signals.pl EXTRA_DIST = \ libperl_dynaloader.la \ get-signals.pl \ - xs/Irssi-bans.xs \ - xs/Irssi-channel.xs \ - xs/Irssi-core.xs \ - xs/Irssi-dcc.xs \ - xs/Irssi-flood.xs \ - xs/Irssi-ignore.xs \ - xs/Irssi-log.xs \ - xs/Irssi-masks.xs \ - xs/Irssi-modes.xs \ - xs/Irssi-netsplit.xs \ - xs/Irssi-notifylist.xs \ - xs/Irssi-query.xs \ - xs/Irssi-rawlog.xs \ - xs/Irssi-server.xs \ - xs/Irssi-settings.xs \ - xs/Irssi-window.xs \ - xs/Irssi.xs \ - xs/Irssi.pm \ - xs/Makefile.PL.in \ - xs/typemap + core/Irssi-bans.xs \ + core/Irssi-channel.xs \ + core/Irssi-core.xs \ + core/Irssi-dcc.xs \ + core/Irssi-flood.xs \ + core/Irssi-ignore.xs \ + core/Irssi-log.xs \ + core/Irssi-masks.xs \ + core/Irssi-modes.xs \ + core/Irssi-netsplit.xs \ + core/Irssi-notifylist.xs \ + core/Irssi-query.xs \ + core/Irssi-rawlog.xs \ + core/Irssi-server.xs \ + core/Irssi-settings.xs \ + core/Irssi-window.xs \ + core/Irssi.xs \ + core/Irssi.pm \ + core/Makefile.PL.in \ + core/typemap noinst_HEADERS = \ module.h \ - xs/module.h + core/module.h \ + irc/module.h all-local: - cd xs && if [ ! -f Makefile ]; then if [ "x$(PERL_LIB_DIR)" = "x" ]; then $(perlpath) Makefile.PL; else $(perlpath) Makefile.PL LIB=$(PERL_LIB_DIR); fi; fi && $(MAKE) && cd .. + for dir in core irc; do cd $$dir && if [ ! -f Makefile ]; then if [ "x$(PERL_LIB_DIR)" = "x" ]; then $(perlpath) Makefile.PL; else $(perlpath) Makefile.PL LIB=$(PERL_LIB_DIR); fi; fi && $(MAKE) && cd ..; done install-exec-local: - cd xs && make install && cd .. + for dir in core irc; do cd $$dir && make install && cd ..; done libirssi_perl_la_LIBADD = $(PERL_LDFLAGS) |