Moved some stuff from irc to core. Added command_bind_proto() function to

bind protocol-specific commands. Added #define command_bind_irc() for easier
access. CMD_IRC_SERVER(server) check should be done at the beginning of each
command requiring IRC server as active server, it handles it correctly the
cases when it is not. Did some other cleanups as well.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1955 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-11-02 01:05:14 +00:00 committed by cras
commit f354fe54c7
70 changed files with 381 additions and 438 deletions

View file

@ -236,8 +236,11 @@ static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
if (*data == '\0')
cmd_channel_list_joined();
else
else if (server_ischannel(server, data)) {
signal_emit("command join", 3, data, server, item);
} else {
command_runsub("channel", data, server, item);
}
}
/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]

View file

@ -45,6 +45,7 @@ static int ret_texts[] = {
TXT_NOT_JOINED,
TXT_CHAN_NOT_FOUND,
TXT_CHAN_NOT_SYNCED,
TXT_ILLEGAL_PROTO,
TXT_NOT_GOOD_IDEA
};
@ -145,6 +146,43 @@ static void cmd_beep(void)
signal_emit("beep", 0);
}
static void cmd_nick(const char *data, SERVER_REC *server)
{
g_return_if_fail(data != NULL);
if (*data != '\0') return;
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
/* display current nick */
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_YOUR_NICK, server->nick);
signal_stop();
}
static void cmd_join(const char *data, SERVER_REC *server)
{
GHashTable *optlist;
char *channels;
void *free_arg;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"join", &optlist, &channels))
return;
server = cmd_options_get_server("join", optlist, server);
if (g_hash_table_lookup(optlist, "invite") &&
server != NULL && server->last_invite == NULL) {
/* ..all this trouble just to print this error message */
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_INVITED);
signal_stop();
}
cmd_params_free(free_arg);
}
static void sig_stop(void)
{
signal_stop();
@ -277,6 +315,8 @@ void fe_core_commands_init(void)
command_bind("version", NULL, (SIGNAL_FUNC) cmd_version);
command_bind("cat", NULL, (SIGNAL_FUNC) cmd_cat);
command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep);
command_bind_first("nick", NULL, (SIGNAL_FUNC) cmd_nick);
command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_join);
signal_add("send command", (SIGNAL_FUNC) event_command);
signal_add_last("send command", (SIGNAL_FUNC) event_command_last);
@ -293,6 +333,8 @@ void fe_core_commands_deinit(void)
command_unbind("version", (SIGNAL_FUNC) cmd_version);
command_unbind("cat", (SIGNAL_FUNC) cmd_cat);
command_unbind("beep", (SIGNAL_FUNC) cmd_beep);
command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
command_unbind("join", (SIGNAL_FUNC) cmd_join);
signal_remove("send command", (SIGNAL_FUNC) event_command);
signal_remove("send command", (SIGNAL_FUNC) event_command_last);

View file

@ -82,6 +82,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "setupserver_added", "Server {server $0} saved", 2, { 0, 1 } },
{ "setupserver_removed", "Server {server $0} removed", 2, { 0, 1 } },
{ "setupserver_not_found", "Server {server $0} not found", 2, { 0, 1 } },
{ "your_nick", "Your nickname is {nick $0}", 1, { 0 } },
/* ---- */
{ NULL, "Channels", 0 },
@ -92,6 +93,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "quit", "{channick $0} {chanhost $1} has quit {reason $2}", 4, { 0, 0, 0, 0 } },
{ "quit_once", "{channel $3} {channick $0} {chanhost $1} has quit {reason $2}", 4, { 0, 0, 0, 0 } },
{ "invite", "{nick $0} invites you to {channel $1}", 2, { 0, 0 } },
{ "not_invited", "You have not been invited to a channel!", 0 },
{ "new_topic", "{nick $0} changed the topic of {channel $1} to: $2", 3, { 0, 0, 0 } },
{ "topic_unset", "Topic unset by {nick $0} on {channel $1}", 2, { 0, 0 } },
{ "your_nick_changed", "You're now known as {nick $1}", 3, { 0, 0, 0 } },
@ -202,6 +204,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "not_joined", "Not joined to any channel", 0 },
{ "chan_not_found", "Not joined to such channel", 0 },
{ "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 },
{ "illegal_proto", "Command isn't designed for the chat protocol of the active server", 0 },
{ "not_good_idea", "Doing this is not a good idea. Add -YES if you really mean it", 0 },
/* ---- */

View file

@ -59,6 +59,7 @@ enum {
TXT_SETUPSERVER_ADDED,
TXT_SETUPSERVER_REMOVED,
TXT_SETUPSERVER_NOT_FOUND,
TXT_YOUR_NICK,
TXT_FILL_3,
@ -68,6 +69,7 @@ enum {
TXT_QUIT,
TXT_QUIT_ONCE,
TXT_INVITE,
TXT_NOT_INVITED,
TXT_NEW_TOPIC,
TXT_TOPIC_UNSET,
TXT_YOUR_NICK_CHANGED,
@ -171,6 +173,7 @@ enum {
TXT_NOT_JOINED,
TXT_CHAN_NOT_FOUND,
TXT_CHAN_NOT_SYNCED,
TXT_ILLEGAL_PROTO,
TXT_NOT_GOOD_IDEA,
TXT_FILL_11,

View file

@ -29,6 +29,5 @@ libfe_common_irc_a_SOURCES = \
module-formats.c
noinst_HEADERS = \
fe-common-irc.h \
module.h \
module-formats.h

View file

@ -1,3 +1,4 @@
#include "common.h"
#include "irc.h"
#define MODULE_NAME "fe-common/irc/dcc"

View file

@ -23,7 +23,6 @@
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "levels.h"
#include "servers.h"
#include "channels.h"

View file

@ -23,10 +23,9 @@
#include "signals.h"
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "levels.h"
#include "servers.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "nicklist.h"

View file

@ -24,7 +24,6 @@
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "levels.h"
#include "servers.h"
#include "servers-redirect.h"
@ -32,12 +31,14 @@
#include "queries.h"
#include "ignore.h"
#include "fe-queries.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "irc-nicklist.h"
#include "irc-masks.h"
#include "fe-windows.h"
#include "printtext.h"
#include "fe-queries.h"
#include "fe-windows.h"
#include "completion.h"

View file

@ -21,16 +21,13 @@
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "commands.h"
#include "levels.h"
#include "servers.h"
#include "irc.h"
#include "channel-rejoin.h"
#include "printtext.h"
static void sig_channel_rejoin(IRC_SERVER_REC *server, REJOIN_REC *rec)
static void sig_channel_rejoin(SERVER_REC *server, REJOIN_REC *rec)
{
g_return_if_fail(rec != NULL);
@ -38,22 +35,12 @@ static void sig_channel_rejoin(IRC_SERVER_REC *server, REJOIN_REC *rec)
IRCTXT_CHANNEL_REJOIN, rec->channel);
}
static void cmd_channel(const char *data, SERVER_REC *server)
{
if (ischannel(*data)) {
signal_emit("command join", 2, data, server);
signal_stop();
}
}
void fe_irc_channels_init(void)
{
signal_add("channel rejoin new", (SIGNAL_FUNC) sig_channel_rejoin);
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
}
void fe_irc_channels_deinit(void)
{
signal_remove("channel rejoin new", (SIGNAL_FUNC) sig_channel_rejoin);
command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
}

View file

@ -21,16 +21,16 @@
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "commands.h"
#include "misc.h"
#include "special-vars.h"
#include "settings.h"
#include "levels.h"
#include "irc.h"
#include "servers.h"
#include "mode-lists.h"
#include "nicklist.h"
#include "irc-commands.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "irc-queries.h"
@ -56,8 +56,7 @@ static char *skip_target(char *target)
/* SYNTAX: ME <message> */
static void cmd_me(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
g_return_if_fail(data != NULL);
CMD_IRC_SERVER(server);
if (!IS_IRC_ITEM(item))
return;
@ -76,9 +75,7 @@ static void cmd_action(const char *data, IRC_SERVER_REC *server)
char *target, *text;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &text))
@ -98,9 +95,7 @@ static void cmd_notice(const char *data, IRC_SERVER_REC *server)
char *target, *msg;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &msg))
@ -118,9 +113,7 @@ static void cmd_ctcp(const char *data, IRC_SERVER_REC *server)
char *target, *ctcpcmd, *ctcpdata;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
&target, &ctcpcmd, &ctcpdata))
@ -148,9 +141,7 @@ static void cmd_nctcp(const char *data, IRC_SERVER_REC *server)
char *target, *text;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &text))
@ -170,9 +161,7 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server,
char *channame, *msg;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !IS_IRC_SERVER(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN |
PARAM_FLAG_GETREST, item, &channame, &msg))
@ -249,9 +238,7 @@ static void cmd_ban(const char *data, IRC_SERVER_REC *server,
char *channel, *nicks;
void *free_arg;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (!cmd_get_params(data, &free_arg, 2 |
PARAM_FLAG_OPTCHAN | PARAM_FLAG_GETREST,
@ -290,8 +277,7 @@ static void cmd_invitelist(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC
IRC_CHANNEL_REC *channel, *cur_channel;
GSList *tmp;
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected) cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
cur_channel = IRC_CHANNEL(item);
if (cur_channel == NULL) cmd_return_error(CMDERR_NOT_JOINED);
@ -317,28 +303,6 @@ static void cmd_invitelist(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC
}
}
static void cmd_join(const char *data, IRC_SERVER_REC *server)
{
if ((*data == '\0' || g_strncasecmp(data, "-invite", 7) == 0) &&
server != NULL && server->last_invite == NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NOT_INVITED);
signal_stop();
}
}
static void cmd_nick(const char *data, IRC_SERVER_REC *server)
{
g_return_if_fail(data != NULL);
if (*data != '\0') return;
if (server == NULL || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
/* display current nick */
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_YOUR_NICK, server->nick);
signal_stop();
}
/* SYNTAX: VER [<target>] */
static void cmd_ver(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
@ -346,8 +310,7 @@ static void cmd_ver(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
g_return_if_fail(data != NULL);
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (*data == '\0' && !IS_IRC_ITEM(item))
cmd_return_error(CMDERR_NOT_JOINED);
@ -465,21 +428,19 @@ static void cmd_sethost(const char *data, IRC_SERVER_REC *server)
void fe_irc_commands_init(void)
{
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);
command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp);
command_bind("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp);
command_bind("wall", NULL, (SIGNAL_FUNC) cmd_wall);
command_bind("ban", NULL, (SIGNAL_FUNC) cmd_ban);
command_bind("invitelist", NULL, (SIGNAL_FUNC) cmd_invitelist);
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind("nick", NULL, (SIGNAL_FUNC) cmd_nick);
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
command_bind("oper", NULL, (SIGNAL_FUNC) cmd_oper);
command_bind("sethost", NULL, (SIGNAL_FUNC) cmd_sethost);
command_bind_irc_last("me", NULL, (SIGNAL_FUNC) cmd_me);
command_bind_irc_last("action", NULL, (SIGNAL_FUNC) cmd_action);
command_bind_irc("notice", NULL, (SIGNAL_FUNC) cmd_notice);
command_bind_irc("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp);
command_bind_irc("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp);
command_bind_irc("wall", NULL, (SIGNAL_FUNC) cmd_wall);
command_bind_irc("ban", NULL, (SIGNAL_FUNC) cmd_ban);
command_bind_irc("invitelist", NULL, (SIGNAL_FUNC) cmd_invitelist);
command_bind_irc("ver", NULL, (SIGNAL_FUNC) cmd_ver);
command_bind_irc("topic", NULL, (SIGNAL_FUNC) cmd_topic);
command_bind_irc("ts", NULL, (SIGNAL_FUNC) cmd_ts);
command_bind_irc("oper", NULL, (SIGNAL_FUNC) cmd_oper);
command_bind_irc("sethost", NULL, (SIGNAL_FUNC) cmd_sethost);
}
void fe_irc_commands_deinit(void)
@ -492,8 +453,6 @@ void fe_irc_commands_deinit(void)
command_unbind("wall", (SIGNAL_FUNC) cmd_wall);
command_unbind("ban", (SIGNAL_FUNC) cmd_ban);
command_unbind("invitelist", (SIGNAL_FUNC) cmd_invitelist);
command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
command_unbind("topic", (SIGNAL_FUNC) cmd_topic);
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);

View file

@ -25,7 +25,7 @@
#include "ignore.h"
#include "settings.h"
#include "irc.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "irc-queries.h"

View file

@ -24,8 +24,6 @@
#include "queries.h"
#include "nicklist.h"
#include "irc.h"
static QUERY_REC *query_find_address(SERVER_REC *server, const char *address)
{
GSList *tmp;

View file

@ -165,7 +165,7 @@ static void cmd_ircnet_remove(const char *data)
}
}
static void cmd_ircnet(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
static void cmd_ircnet(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
if (*data == '\0')
cmd_ircnet_list();

View file

@ -25,7 +25,6 @@
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "modes.h"

View file

@ -25,7 +25,6 @@
#include "misc.h"
#include "settings.h"
#include "irc.h"
#include "irc-servers.h"
#include "modes.h"
#include "ignore.h"

View file

@ -21,12 +21,11 @@
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "commands.h"
#include "levels.h"
#include "settings.h"
#include "irc.h"
#include "irc-servers.h"
#include "irc-commands.h"
#include "ignore.h"
#include "netsplit.h"
@ -322,8 +321,7 @@ static void cmd_netsplit(const char *data, IRC_SERVER_REC *server)
{
GSList *list;
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
CMD_IRC_SERVER(server);
if (server->split_servers == NULL) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
@ -360,7 +358,7 @@ void fe_netsplit_init(void)
read_settings();
signal_add("netsplit new", (SIGNAL_FUNC) sig_netsplit_servers);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
command_bind("netsplit", NULL, (SIGNAL_FUNC) cmd_netsplit);
command_bind_irc("netsplit", NULL, (SIGNAL_FUNC) cmd_netsplit);
}
void fe_netsplit_deinit(void)

View file

@ -58,7 +58,6 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "joinerror_duplicate", "Channel {channel $0} already exists - cannot create it", 1, { 0 } },
{ "channel_rejoin", "Channel {channel $0} is temporarily unavailable, this is normally because of netsplits. Irssi will now automatically try to rejoin back to this channel until the join is successful. Use /RMREJOINS command if you wish to abort this.", 1, { 0 } },
{ "inviting", "Inviting {nick $0} to {channel $1}", 2, { 0, 0 } },
{ "not_invited", "You have not been invited to a channel!", 0 },
{ "channel_created", "Channel {channelhilight $0} created $1", 2, { 0, 0 } },
{ "url", "Home page for {channelhilight $0}: $1", 2, { 0, 0 } },
{ "topic", "Topic for {channelhilight $0}: $1", 2, { 0, 0 } },
@ -87,7 +86,6 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "unaway", "You are no longer marked as being away", 0 },
{ "nick_away", "{nick $0} is away: $1", 2, { 0, 0 } },
{ "no_such_nick", "{nick $0}: No such nick/channel", 1, { 0 } },
{ "your_nick", "Your nickname is {nick $0}", 1, { 0 } },
{ "nick_in_use", "Nick {nick $0} is already in use", 1, { 0 } },
{ "nick_unavailable", "Nick {nick $0} is temporarily unavailable", 1, { 0 } },
{ "your_nick_owned", "Your nick is owned by {nick $3} {comment $1@$2}", 4, { 0, 0, 0, 0 } },

View file

@ -35,7 +35,6 @@ enum {
IRCTXT_JOINERROR_DUPLICATE,
IRCTXT_CHANNEL_REJOIN,
IRCTXT_INVITING,
IRCTXT_NOT_INVITED,
IRCTXT_CHANNEL_CREATED,
IRCTXT_CHANNEL_URL,
IRCTXT_TOPIC,
@ -63,7 +62,6 @@ enum {
IRCTXT_UNAWAY,
IRCTXT_NICK_AWAY,
IRCTXT_NO_SUCH_NICK,
IRCTXT_YOUR_NICK,
IRCTXT_NICK_IN_USE,
IRCTXT_NICK_UNAVAILABLE,
IRCTXT_YOUR_NICK_OWNED,

View file

@ -1,3 +1,4 @@
#include "common.h"
#include "irc.h"
#define MODULE_NAME "fe-common/irc"

View file

@ -1,3 +1,4 @@
#include "common.h"
#include "irc.h"
#define MODULE_NAME "fe-common/irc/notifylist"