summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-common')
-rw-r--r--src/fe-common/core/chat-completion.c81
-rw-r--r--src/fe-common/core/fe-ignore.c4
-rw-r--r--src/fe-common/core/fe-log.c2
-rw-r--r--src/fe-common/core/fe-messages.c98
-rw-r--r--src/fe-common/core/fe-messages.h2
-rw-r--r--src/fe-common/irc/Makefile.am1
-rw-r--r--src/fe-common/irc/fe-common-irc.c5
-rw-r--r--src/fe-common/irc/fe-events.c12
-rw-r--r--src/fe-common/irc/fe-irc-messages.c81
9 files changed, 176 insertions, 110 deletions
diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c
index 2d108d1c..5989d90b 100644
--- a/src/fe-common/core/chat-completion.c
+++ b/src/fe-common/core/chat-completion.c
@@ -127,53 +127,46 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
SERVER_LAST_MSG_ADD(server, nick);
}
-static void cmd_msg(const char *data, SERVER_REC *server)
+static void sig_message_own_public(SERVER_REC *server, const char *msg,
+ const char *target, const char *origtarget)
{
- GHashTable *optlist;
- NICK_REC *nick;
- char *target, *msg, *p;
- void *free_arg;
+ CHANNEL_REC *channel;
+ NICK_REC *nick;
+ char *p, *msgnick;
- g_return_if_fail(data != NULL);
+ g_return_if_fail(server != NULL);
+ g_return_if_fail(msg != NULL);
+ if (target == NULL) return;
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
- PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
- "msg", &optlist, &target, &msg))
+ channel = channel_find(server, target);
+ if (channel == NULL)
return;
- server = cmd_options_get_server("msg", optlist, server);
-
- if (server != NULL && *target != '\0' && *msg != '\0' &&
- query_find(server, target) == NULL) {
- CHANNEL_REC *channel = channel_find(server, target);
- MODULE_CHANNEL_REC *mchannel;
-
- mchannel = MODULE_DATA(channel);
-
- if (channel != NULL) {
- /* channel msg - if first word in line is nick,
- add it to lastmsgs */
- p = strchr(msg, ' ');
- if (p != NULL && p != msg) {
- *p = '\0';
- nick = nicklist_find(channel, msg);
- if (nick == NULL) {
- /* probably ':' or ',' or some other
- char after nick, try without it */
- p[-1] = '\0';
- nick = nicklist_find(channel, msg);
- }
- if (nick != NULL && nick != channel->ownnick) {
- CHANNEL_LAST_MSG_ADD(channel,
- nick->nick, TRUE);
- }
- }
- } else if (!server->ischannel(*target)) {
- /* private msg */
- SERVER_LAST_MSG_ADD(server, target);
+
+ /* channel msg - if first word in line is nick,
+ add it to lastmsgs */
+ p = strchr(msg, ' ');
+ if (p != NULL && p != msg) {
+ msgnick = g_strndup(msg, (int) (p-msg));
+ nick = nicklist_find(channel, msgnick);
+ if (nick == NULL) {
+ /* probably ':' or ',' or some other
+ char after nick, try without it */
+ msgnick[strlen(msgnick)-1] = '\0';
+ nick = nicklist_find(channel, msgnick);
}
+ if (nick != NULL && nick != channel->ownnick)
+ CHANNEL_LAST_MSG_ADD(channel, nick->nick, TRUE);
}
+}
+
+static void sig_message_own_private(SERVER_REC *server, const char *msg,
+ const char *target, const char *origtarget)
+{
+ g_return_if_fail(server != NULL);
+ g_return_if_fail(msg != NULL);
- cmd_params_free(free_arg);
+ if (target != NULL && query_find(server, target) == NULL)
+ SERVER_LAST_MSG_ADD(server, target);
}
static void sig_nick_removed(CHANNEL_REC *channel, NICK_REC *nick)
@@ -462,7 +455,7 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
if (server == NULL && servers != NULL)
server = servers->data;
- if (server != NULL && server->ischannel(*word)) {
+ if (server != NULL && server->ischannel(word)) {
/* probably completing a channel name */
*list = completion_get_channels(window->active_server, word);
return;
@@ -731,7 +724,8 @@ void chat_completion_init(void)
signal_add("complete command server", (SIGNAL_FUNC) sig_complete_connect);
signal_add("message public", (SIGNAL_FUNC) sig_message_public);
signal_add("message private", (SIGNAL_FUNC) sig_message_private);
- signal_add("command msg", (SIGNAL_FUNC) cmd_msg);
+ signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_add("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);
signal_add("nicklist changed", (SIGNAL_FUNC) sig_nick_changed);
signal_add("send text", (SIGNAL_FUNC) event_text);
@@ -748,7 +742,8 @@ void chat_completion_deinit(void)
signal_remove("complete command server", (SIGNAL_FUNC) sig_complete_connect);
signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
- signal_remove("command msg", (SIGNAL_FUNC) cmd_msg);
+ signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_remove("nicklist remove", (SIGNAL_FUNC) sig_nick_removed);
signal_remove("nicklist changed", (SIGNAL_FUNC) sig_nick_changed);
signal_remove("send text", (SIGNAL_FUNC) event_text);
diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c
index db2d4ad3..3129370a 100644
--- a/src/fe-common/core/fe-ignore.c
+++ b/src/fe-common/core/fe-ignore.c
@@ -176,7 +176,7 @@ static void cmd_ignore(const char *data)
if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
if (active_win->active_server != NULL &&
- active_win->active_server->ischannel(*mask)) {
+ active_win->active_server->ischannel(mask)) {
chanarg = mask;
mask = NULL;
}
@@ -264,7 +264,7 @@ static void cmd_unignore(const char *data)
const char *chans[2] = { "*", NULL };
if (active_win->active_server != NULL &&
- active_win->active_server->ischannel(*data)) {
+ active_win->active_server->ischannel(data)) {
chans[0] = data;
data = NULL;
}
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index 676b9af2..b3f5b381 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -504,7 +504,7 @@ static int sig_autoremove(void)
server = server_find_tag(logitem->servertag);
if (logitem->type == LOG_ITEM_TARGET &&
- server != NULL && !server->ischannel(*logitem->name))
+ server != NULL && !server->ischannel(logitem->name))
log_close(log);
}
return 1;
diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c
index b994fe5c..b1ef6ed3 100644
--- a/src/fe-common/core/fe-messages.c
+++ b/src/fe-common/core/fe-messages.c
@@ -109,7 +109,7 @@ char *expand_emphasis(WI_ITEM_REC *item, const char *text)
return ret;
}
-static char *get_nickmode(CHANNEL_REC *channel, const char *nick)
+char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick)
{
NICK_REC *nickrec;
char *emptystr;
@@ -158,7 +158,7 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
else
freemsg = NULL;
- nickmode = get_nickmode(chanrec, nick);
+ nickmode = channel_get_nickmode(chanrec, nick);
if (!print_channel) {
/* message to active channel in window */
if (color != NULL) {
@@ -217,7 +217,7 @@ static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel,
const char *nickmode;
int print_channel;
- nickmode = get_nickmode(channel, server->nick);
+ nickmode = channel_get_nickmode(channel, server->nick);
window = channel == NULL ? NULL :
window_item_window((WI_ITEM_REC *) channel);
@@ -238,71 +238,45 @@ static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel,
}
}
-static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
+static void sig_message_own_public(SERVER_REC *server, const char *msg,
+ const char *target)
{
- GHashTable *optlist;
CHANNEL_REC *channel;
- char *target, *msg, *freestr, *newtarget;
- void *free_arg;
- int free_ret;
- g_return_if_fail(data != NULL);
+ g_return_if_fail(server != NULL);
+ g_return_if_fail(msg != NULL);
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
- PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
- "msg", &optlist, &target, &msg))
- return;
- if (*target == '\0' || *msg == '\0')
- cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- server = cmd_options_get_server("msg", optlist, server);
-
- free_ret = FALSE;
- if (strcmp(target, ",") == 0 || strcmp(target, ".") == 0) {
- /* , and . are handled specially */
- newtarget = parse_special(&target, server, item,
- NULL, &free_ret, NULL, 0);
- if (newtarget == NULL) {
- printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
- *target == ',' ? IRCTXT_NO_MSGS_GOT :
- IRCTXT_NO_MSGS_SENT);
- cmd_params_free(free_arg);
- signal_stop();
- return;
- }
- target = newtarget;
- } else if (strcmp(target, "*") == 0 && item != NULL) {
- /* * means active channel */
- target = item->name;
- }
-
- if (server == NULL || !server->connected)
- cmd_param_error(CMDERR_NOT_CONNECTED);
channel = channel_find(server, target);
+ print_own_channel_message(server, channel, target, msg);
+}
- freestr = !free_ret ? NULL : target;
- if (*target == '@' && server->ischannel(target[1])) {
- /* Hybrid 6 feature, send msg to all ops in channel
- FIXME: this shouldn't really be here in core.. */
- target++;
- }
+static void sig_message_own_private(SERVER_REC *server, const char *msg,
+ const char *target, const char *origtarget)
+{
+ QUERY_REC *query;
- if (server->ischannel(*target)) {
- /* msg to channel */
- print_own_channel_message(server, channel, target, msg);
- } else {
- /* private message */
- QUERY_REC *query;
-
- query = privmsg_get_query(server, target, TRUE, MSGLEVEL_MSGS);
- printformat(server, target, MSGLEVEL_MSGS |
- MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT,
- query == NULL ? IRCTXT_OWN_MSG_PRIVATE :
- IRCTXT_OWN_MSG_PRIVATE_QUERY,
- target, msg, server->nick);
+ g_return_if_fail(server != NULL);
+ g_return_if_fail(msg != NULL);
+
+ if (target == NULL) {
+ /* this should only happen if some special target failed and
+ we should display some error message. currently the special
+ targets are only ',' and '.'. */
+ g_return_if_fail(strcmp(origtarget, ",") == 0 ||
+ strcmp(origtarget, ".") == 0);
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
+ *origtarget == ',' ? IRCTXT_NO_MSGS_GOT :
+ IRCTXT_NO_MSGS_SENT);
+ signal_stop();
+ return;
}
- g_free_not_null(freestr);
- cmd_params_free(free_arg);
+ query = privmsg_get_query(server, target, TRUE, MSGLEVEL_MSGS);
+ printformat(server, target,
+ MSGLEVEL_MSGS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT,
+ query == NULL ? IRCTXT_OWN_MSG_PRIVATE :
+ IRCTXT_OWN_MSG_PRIVATE_QUERY, target, msg, server->nick);
}
static void sig_message_join(SERVER_REC *server, const char *channel,
@@ -502,6 +476,8 @@ void fe_messages_init(void)
signal_add("message public", (SIGNAL_FUNC) sig_message_public);
signal_add("message private", (SIGNAL_FUNC) sig_message_private);
+ signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_add("message join", (SIGNAL_FUNC) sig_message_join);
signal_add("message part", (SIGNAL_FUNC) sig_message_part);
signal_add("message quit", (SIGNAL_FUNC) sig_message_quit);
@@ -510,13 +486,14 @@ void fe_messages_init(void)
signal_add("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
signal_add("message invite", (SIGNAL_FUNC) sig_message_invite);
signal_add("message topic", (SIGNAL_FUNC) sig_message_topic);
- command_bind_last("msg", NULL, (SIGNAL_FUNC) cmd_msg);
}
void fe_messages_deinit(void)
{
signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
+ signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private);
signal_remove("message join", (SIGNAL_FUNC) sig_message_join);
signal_remove("message part", (SIGNAL_FUNC) sig_message_part);
signal_remove("message quit", (SIGNAL_FUNC) sig_message_quit);
@@ -525,5 +502,4 @@ void fe_messages_deinit(void)
signal_remove("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
signal_remove("message invite", (SIGNAL_FUNC) sig_message_invite);
signal_remove("message topic", (SIGNAL_FUNC) sig_message_topic);
- command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
}
diff --git a/src/fe-common/core/fe-messages.h b/src/fe-common/core/fe-messages.h
index 16b0b73d..afe7644d 100644
--- a/src/fe-common/core/fe-messages.h
+++ b/src/fe-common/core/fe-messages.h
@@ -5,4 +5,6 @@
underlining or bolding */
char *expand_emphasis(WI_ITEM_REC *item, const char *text);
+char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick);
+
#endif
diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am
index 0abc41f9..b69499f1 100644
--- a/src/fe-common/irc/Makefile.am
+++ b/src/fe-common/irc/Makefile.am
@@ -14,6 +14,7 @@ INCLUDES = \
libfe_common_irc_a_SOURCES = \
fe-irc-channels.c \
fe-irc-commands.c \
+ fe-irc-messages.c \
fe-irc-queries.c \
fe-irc-server.c \
fe-ircnet.c \
diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c
index e3d23556..a0169299 100644
--- a/src/fe-common/irc/fe-common-irc.c
+++ b/src/fe-common/irc/fe-common-irc.c
@@ -39,6 +39,9 @@ void fe_irc_channels_deinit(void);
void fe_irc_queries_init(void);
void fe_irc_queries_deinit(void);
+void fe_irc_messages_init(void);
+void fe_irc_messages_deinit(void);
+
void fe_irc_commands_init(void);
void fe_irc_commands_deinit(void);
@@ -99,6 +102,7 @@ void fe_common_irc_init(void)
fe_irc_channels_init();
fe_irc_queries_init();
+ fe_irc_messages_init();
fe_irc_commands_init();
fe_ircnet_init();
fe_irc_server_init();
@@ -119,6 +123,7 @@ void fe_common_irc_deinit(void)
fe_irc_channels_deinit();
fe_irc_queries_deinit();
+ fe_irc_messages_deinit();
fe_irc_commands_deinit();
fe_ircnet_deinit();
fe_irc_server_deinit();
diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c
index 4ebc40b5..b03c2ca5 100644
--- a/src/fe-common/irc/fe-events.c
+++ b/src/fe-common/irc/fe-events.c
@@ -51,9 +51,15 @@ static void event_privmsg(IRC_SERVER_REC *server, const char *data,
if (nick == NULL) nick = server->real_address;
if (addr == NULL) addr = "";
- signal_emit(ischannel(*target) ?
- "message public" : "message private", 5,
- server, msg, nick, addr, target);
+ if (*target == '@' && ischannel(target[1])) {
+ /* Hybrid 6 feature, send msg to all ops in channel */
+ signal_emit("message irc op_public", 5,
+ server, msg, nick, addr, target+1);
+ } else {
+ signal_emit(ischannel(*target) ?
+ "message public" : "message private", 5,
+ server, msg, nick, addr, target);
+ }
g_free(params);
}
diff --git a/src/fe-common/irc/fe-irc-messages.c b/src/fe-common/irc/fe-irc-messages.c
new file mode 100644
index 00000000..1d33c9c2
--- /dev/null
+++ b/src/fe-common/irc/fe-irc-messages.c
@@ -0,0 +1,81 @@
+/*
+ fe-irc-messages.c : irssi
+
+ Copyright (C) 2001 Timo Sirainen
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "module.h"
+#include "signals.h"
+#include "levels.h"
+#include "channels.h"
+
+#include "irc.h"
+
+/* FIXME: hmm. there's should be some better way to use other module's
+ formats than this since now we can't use this module's formats.. */
+#include "../core/module-formats.h"
+#include "printtext.h"
+#include "fe-messages.h"
+
+static void sig_message_own_public(SERVER_REC *server, const char *msg,
+ const char *target, const char *origtarget)
+{
+ char *nickmode;
+
+ if (IS_IRC_SERVER(server) && target != NULL &&
+ *target == '@' && ischannel(target[1])) {
+ /* Hybrid 6 feature, send msg to all ops in channel */
+ nickmode = channel_get_nickmode(channel_find(server, target+1),
+ server->nick);
+
+ printformat_module("fe-common/core", server, target+1,
+ MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
+ MSGLEVEL_NO_ACT,
+ IRCTXT_OWN_MSG_CHANNEL,
+ server->nick, target, msg, nickmode);
+ signal_stop();
+ }
+}
+
+static void sig_message_irc_op_public(SERVER_REC *server, const char *msg,
+ const char *nick, const char *address,
+ const char *target)
+{
+ char *nickmode, *optarget;
+
+ nickmode = channel_get_nickmode(channel_find(server, target),
+ server->nick);
+
+ optarget = g_strconcat("@", target, NULL);
+ printformat_module("fe-common/core", server, target,
+ MSGLEVEL_PUBLIC | MSGLEVEL_HILIGHT,
+ IRCTXT_PUBMSG_ME_CHANNEL,
+ nick, optarget, msg, nickmode);
+ g_free(optarget);
+}
+
+void fe_irc_messages_init(void)
+{
+ signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_add("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public);
+}
+
+void fe_irc_messages_deinit(void)
+{
+ signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+ signal_remove("message irc op_public", (SIGNAL_FUNC) sig_message_irc_op_public);
+}