summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2003-10-06 22:24:19 +0000
committerSebastien Helleu <flashcode@flashtux.org>2003-10-06 22:24:19 +0000
commit954f1b98bfc6d4862ba1cefd33eea7201124d258 (patch)
tree7e2dc03e86e933c03a25514c632bc622ff849cf1 /src/irc
parent641e5cd05a68a2a9e7e6b043de05687855cb5029 (diff)
downloadweechat-954f1b98bfc6d4862ba1cefd33eea7201124d258.zip
Added /stats command, splited irc-commands.c in 3 files (commands, send, recv)
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/Makefile8
-rw-r--r--src/irc/irc-commands.c2839
-rw-r--r--src/irc/irc-recv.c2113
-rw-r--r--src/irc/irc-send.c811
-rw-r--r--src/irc/irc.h1
5 files changed, 2937 insertions, 2835 deletions
diff --git a/src/irc/Makefile b/src/irc/Makefile
index d22617bda..09ca6dc0d 100644
--- a/src/irc/Makefile
+++ b/src/irc/Makefile
@@ -20,7 +20,7 @@ CC=gcc
OPTIONS=-Wall -W -pipe -O2
OUTPUT=irc.a
-OBJS=irc-commands.o irc-display.o irc-server.o irc-channel.o irc-nick.o
+OBJS=irc-commands.o irc-send.o irc-recv.o irc-display.o irc-server.o irc-channel.o irc-nick.o
DEFINES=WEE_CURSES
all: $(OBJS)
@@ -37,8 +37,12 @@ irc-channel.o: irc-channel.c ../weechat.h irc.h ../gui/gui.h \
irc-commands.o: irc-commands.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h ../command.h ../irc/irc.h ../config.h
irc-display.o: irc-display.c ../weechat.h irc.h ../gui/gui.h \
- ../completion.h ../history.h
+ ../completion.h ../history.h ../config.h
irc-nick.o: irc-nick.c ../weechat.h irc.h ../gui/gui.h ../completion.h \
../history.h
+irc-recv.o: irc-recv.c ../weechat.h irc.h ../gui/gui.h ../completion.h \
+ ../history.h ../command.h ../irc/irc.h ../config.h
+irc-send.o: irc-send.c ../weechat.h irc.h ../gui/gui.h ../completion.h \
+ ../history.h ../command.h ../irc/irc.h ../config.h
irc-server.o: irc-server.c ../weechat.h irc.h ../gui/gui.h \
../completion.h ../history.h
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index 9f04540c7..384ba787a 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -151,6 +151,10 @@ t_irc_command irc_commands[] =
{ "restart", N_("tell the server to restart itself"),
"", "",
0, 0, 1, NULL, irc_cmd_send_restart, NULL },
+ { "stats", N_("query statistics about server"),
+ "[query [server]]",
+ "query: c/h/i/k/l/m/o/y/u (see RFC1459)\nserver: server name",
+ 0, 2, 1, NULL, irc_cmd_send_stats, NULL },
{ "topic", N_("get/set channel topic"),
N_("[channel] [topic]"), N_("channel: channel name\ntopic: new topic for channel "
"(if topic is \"-delete\" then topic is deleted)"),
@@ -170,6 +174,8 @@ t_irc_command irc_commands[] =
{ "003", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "004", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_004 },
{ "005", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
+ { "212", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
+ { "219", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "250", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "251", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "252", N_("a server message"), "", "", 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
@@ -315,2836 +321,3 @@ t_irc_command irc_commands[] =
"", "", 0, MAX_ARGS, 1, NULL, NULL, irc_cmd_recv_error },
{ NULL, NULL, NULL, NULL, 0, 0, 1, NULL, NULL, NULL }
};
-
-
-/*
- * irc_recv_command: executes action when receiving IRC command
- * returns: 0 = all ok, command executed
- * -1 = command failed
- * -2 = no command to execute
- * -3 = command not found
- */
-
-int
-irc_recv_command (t_irc_server *server,
- char *host, char *command, char *arguments)
-{
- int i, cmd_found;
-
- if (command == NULL)
- return -2;
-
- /* looks for irc command */
- cmd_found = -1;
- for (i = 0; irc_commands[i].command_name; i++)
- if (strcasecmp (irc_commands[i].command_name, command) == 0)
- {
- cmd_found = i;
- break;
- }
-
- /* command not found */
- if (cmd_found < 0)
- return -3;
-
- if (irc_commands[i].recv_function != NULL)
- return (int) (irc_commands[i].recv_function) (server, host, arguments);
-
- return 0;
-}
-
-/*
- * irc_login: login to irc server
- */
-
-void
-irc_login (t_irc_server *server)
-{
- char hostname[128];
-
- if ((server->password) && (server->password[0]))
- server_sendf (server, "PASS %s\r\n", server->password);
-
- gethostname (hostname, sizeof (hostname) - 1);
- hostname[sizeof (hostname) - 1] = '\0';
- if (!hostname[0])
- strcpy (hostname, _("unknown"));
- gui_printf (server->window,
- _("%s: using local hostname \"%s\"\n"),
- WEECHAT_NAME, hostname);
- server_sendf (server,
- "NICK %s\r\n"
- "USER %s %s %s :%s\r\n",
- server->nick, server->username, hostname, "servername",
- server->realname);
-}
-
-/*
- * irc_cmd_send_away: toggle away status
- */
-
-int
-irc_cmd_send_away (t_irc_server *server, char *arguments)
-{
- char *pos;
- t_irc_server *ptr_server;
-
- if (arguments && (strncmp (arguments, "-all", 4) == 0))
- {
- pos = arguments + 4;
- while (pos[0] == ' ')
- pos++;
- if (!pos[0])
- pos = NULL;
-
- for (ptr_server = irc_servers; ptr_server;
- ptr_server = ptr_server->next_server)
- {
- if (server->is_connected)
- {
- if (pos)
- server_sendf (ptr_server, "AWAY :%s\r\n", pos);
- else
- server_sendf (ptr_server, "AWAY\r\n");
- }
- }
- }
- else
- {
- if (arguments)
- server_sendf (server, "AWAY :%s\r\n", arguments);
- else
- server_sendf (server, "AWAY\r\n");
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_ctcp: send a ctcp message
- */
-
-int
-irc_cmd_send_ctcp (t_irc_server *server, char *arguments)
-{
- char *pos, *pos2;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- }
- else
- pos2 = NULL;
-
- if (strcasecmp (pos, "version") == 0)
- {
- if (pos2)
- server_sendf (server, "PRIVMSG %s :\01VERSION %s\01\r\n",
- arguments, pos2);
- else
- server_sendf (server, "PRIVMSG %s :\01VERSION\01\r\n",
- arguments);
- }
- if (strcasecmp (pos, "action") == 0)
- {
- if (pos2)
- server_sendf (server, "PRIVMSG %s :\01ACTION %s\01\r\n",
- arguments, pos2);
- else
- server_sendf (server, "PRIVMSG %s :\01ACTION\01\r\n",
- arguments);
- }
-
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_deop: remove operator privileges from nickname(s)
- */
-
-int
-irc_cmd_send_deop (t_irc_server *server, int argc, char **argv)
-{
- int i;
-
- if (WIN_IS_CHANNEL(gui_current_window))
- {
- for (i = 0; i < argc; i++)
- server_sendf (server, "MODE %s -o %s\r\n",
- CHANNEL(gui_current_window)->name,
- argv[i]);
- }
- else
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "deop");
- return 0;
-}
-
-/*
- * irc_cmd_send_devoice: remove voice from nickname(s)
- */
-
-int
-irc_cmd_send_devoice (t_irc_server *server, int argc, char **argv)
-{
- int i;
-
- if (WIN_IS_CHANNEL(gui_current_window))
- {
- for (i = 0; i < argc; i++)
- server_sendf (server, "MODE %s -v %s\r\n",
- CHANNEL(gui_current_window)->name,
- argv[i]);
- }
- else
- {
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "devoice");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_invite: invite a nick on a channel
- */
-
-int
-irc_cmd_send_invite (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "INVITE %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_join: join a new channel
- */
-
-int
-irc_cmd_send_join (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "JOIN %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_kick: forcibly remove a user from a channel
- */
-
-int
-irc_cmd_send_kick (t_irc_server *server, char *arguments)
-{
- if (string_is_channel (arguments))
- server_sendf (server, "KICK %s\r\n", arguments);
- else
- {
- if (WIN_IS_CHANNEL (gui_current_window))
- {
- server_sendf (server,
- "KICK %s %s\r\n",
- CHANNEL(gui_current_window)->name, arguments);
- }
- else
- {
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "kick");
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_kill: close client-server connection
- */
-
-int
-irc_cmd_send_kill (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "KILL %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_list: close client-server connection
- */
-
-int
-irc_cmd_send_list (t_irc_server *server, char *arguments)
-{
- if (arguments)
- server_sendf (server, "LIST %s\r\n", arguments);
- else
- server_sendf (server, "LIST\r\n");
- return 0;
-}
-
-/*
- * irc_cmd_send_me: send a ctcp action to the current channel
- */
-
-int
-irc_cmd_send_me (t_irc_server *server, char *arguments)
-{
- if (WIN_IS_SERVER(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can not be executed on a server window\n"),
- WEECHAT_ERROR, "me");
- return -1;
- }
- server_sendf (server, "PRIVMSG %s :\01ACTION %s\01\r\n",
- CHANNEL(gui_current_window)->name, arguments);
- irc_display_prefix (gui_current_window, PREFIX_ACTION_ME);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT_NICK, "%s", server->nick);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT, " %s\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_mode: change mode for channel/nickname
- */
-
-int
-irc_cmd_send_mode (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "MODE %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_msg: send a message to a nick or channel
- */
-
-int
-irc_cmd_send_msg (t_irc_server *server, char *arguments)
-{
- char *pos, *pos_comma;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
-
- while (arguments && arguments[0])
- {
- pos_comma = strchr (arguments, ',');
- if (pos_comma)
- {
- pos_comma[0] = '\0';
- pos_comma++;
- }
- if (strcmp (arguments, "*") == 0)
- {
- if (WIN_IS_SERVER(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can not be executed on a server window\n"),
- WEECHAT_ERROR, "msg *");
- return -1;
- }
- ptr_channel = CHANNEL(gui_current_window);
- ptr_nick = nick_search (ptr_channel, server->nick);
- if (ptr_nick)
- {
- irc_display_nick (ptr_channel->window, ptr_nick,
- MSG_TYPE_NICK, 1, 1, 0);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
- }
- else
- gui_printf (server->window,
- _("%s nick not found for \"%s\" command\n"),
- WEECHAT_ERROR, "msg");
- server_sendf (server, "PRIVMSG %s :%s\r\n", ptr_channel->name, pos);
- }
- else
- {
- if (string_is_channel (arguments))
- {
- ptr_channel = channel_search (server, arguments);
- if (ptr_channel)
- {
- ptr_nick = nick_search (ptr_channel, server->nick);
- if (ptr_nick)
- {
- irc_display_nick (ptr_channel->window, ptr_nick,
- MSG_TYPE_NICK, 1, 1, 0);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
- }
- else
- gui_printf (server->window,
- _("%s nick not found for \"%s\" command\n"),
- WEECHAT_ERROR, "msg");
- }
- server_sendf (server, "PRIVMSG %s :%s\r\n", arguments, pos);
- }
- else
- {
- ptr_channel = channel_search (server, arguments);
- if (!ptr_channel)
- {
- ptr_channel = channel_new (server, CHAT_PRIVATE, arguments);
- if (!ptr_channel)
- {
- gui_printf (server->window,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR,
- arguments);
- return -1;
- }
- gui_redraw_window_title (ptr_channel->window);
- }
-
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "<");
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_NICK_SELF,
- "%s", server->nick);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "> ");
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
- server_sendf (server, "PRIVMSG %s :%s\r\n", arguments, pos);
- }
- }
- arguments = pos_comma;
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s wrong argument count for \"%s\" command\n"),
- WEECHAT_ERROR, "msg");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_names: list nicknames on channels
- */
-
-int
-irc_cmd_send_names (t_irc_server *server, char *arguments)
-{
- if (arguments)
- server_sendf (server, "NAMES %s\r\n", arguments);
- else
- {
- if (!WIN_IS_CHANNEL(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "names");
- return -1;
- }
- else
- server_sendf (server, "NAMES %s\r\n",
- CHANNEL(gui_current_window)->name);
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_nick: change nickname
- */
-
-int
-irc_cmd_send_nick (t_irc_server *server, int argc, char **argv)
-{
- if (argc != 1)
- return -1;
- server_sendf (server, "NICK %s\r\n", argv[0]);
- return 0;
-}
-
-/*
- * irc_cmd_send_notice: send notice message
- */
-
-int
-irc_cmd_send_notice (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "NOTICE %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_op: give operator privileges to nickname(s)
- */
-
-int
-irc_cmd_send_op (t_irc_server *server, int argc, char **argv)
-{
- int i;
-
- if (WIN_IS_CHANNEL(gui_current_window))
- {
- for (i = 0; i < argc; i++)
- server_sendf (server, "MODE %s +o %s\r\n",
- CHANNEL(gui_current_window)->name,
- argv[i]);
- }
- else
- {
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "op");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_oper: get oper privileges
- */
-
-int
-irc_cmd_send_oper (t_irc_server *server, int argc, char **argv)
-{
- if (argc != 2)
- return -1;
- server_sendf (server, "OPER %s %s\r\n", argv[0], argv[1]);
- return 0;
-}
-
-/*
- * irc_cmd_send_part: leave a channel or close a private window
- */
-
-int
-irc_cmd_send_part (t_irc_server *server, char *arguments)
-{
- char *channel_name, *pos_args;
- t_irc_channel *ptr_channel;
-
- if (arguments)
- {
- if (string_is_channel (arguments))
- {
- channel_name = arguments;
- pos_args = strchr (arguments, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- }
- }
- else
- {
- if (WIN_IS_SERVER(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can not be executed on a server window\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
- channel_name = CHANNEL(gui_current_window)->name;
- pos_args = arguments;
- }
- }
- else
- {
- if (WIN_IS_SERVER(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can not be executed on a server window\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
- if (WIN_IS_PRIVATE(gui_current_window))
- {
- ptr_channel = CHANNEL(gui_current_window);
- gui_window_free (ptr_channel->window);
- channel_free (server, ptr_channel);
- gui_redraw_window_status (gui_current_window);
- gui_redraw_window_input (gui_current_window);
- return 0;
- }
- channel_name = CHANNEL(gui_current_window)->name;
- pos_args = NULL;
- }
-
- if (pos_args)
- server_sendf (server, "PART %s :%s\r\n", channel_name, pos_args);
- else
- server_sendf (server, "PART %s\r\n", channel_name);
- return 0;
-}
-
-/*
- * irc_cmd_send_ping: ping a server
- */
-
-int
-irc_cmd_send_ping (t_irc_server *server, int argc, char **argv)
-{
- if (argc == 1)
- server_sendf (server, "PING %s\r\n", argv[0]);
- if (argc == 2)
- server_sendf (server, "PING %s %s\r\n", argv[0],
- argv[1]);
- return 0;
-}
-
-/*
- * irc_cmd_send_pong: send pong answer to a daemon
- */
-
-int
-irc_cmd_send_pong (t_irc_server *server, int argc, char **argv)
-{
- if (argc == 1)
- server_sendf (server, "PONG %s\r\n", argv[0]);
- if (argc == 2)
- server_sendf (server, "PONG %s %s\r\n", argv[0],
- argv[1]);
- return 0;
-}
-
-/*
- * irc_cmd_send_quit: disconnect from all servers and quit WeeChat
- */
-
-int
-irc_cmd_send_quit (t_irc_server *server, char *arguments)
-{
- if (server && server->is_connected)
- {
- if (arguments)
- server_sendf (server, "QUIT :%s\r\n", arguments);
- else
- server_sendf (server, "QUIT\r\n");
- }
- quit_weechat = 1;
- return 0;
-}
-
-/*
- * irc_cmd_send_quote: send raw data to server
- */
-
-int
-irc_cmd_send_quote (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "%s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_send_rehash: tell the server to reload its config file
- */
-
-int
-irc_cmd_send_rehash (t_irc_server *server, char *arguments)
-{
- /* make gcc happy */
- (void) arguments;
-
- server_sendf (server, "REHASH\r\n");
- return 0;
-}
-
-/*
- * irc_cmd_send_restart: tell the server to restart itself
- */
-
-int
-irc_cmd_send_restart (t_irc_server *server, char *arguments)
-{
- /* make gcc happy */
- (void) arguments;
-
- server_sendf (server, "RESTART\r\n");
- return 0;
-}
-
-/*
- * irc_cmd_send_topic: get/set topic for a channel
- */
-
-int
-irc_cmd_send_topic (t_irc_server *server, char *arguments)
-{
- char *channel_name, *new_topic, *pos;
-
- channel_name = NULL;
- new_topic = NULL;
-
- if (arguments)
- {
- if (string_is_channel (arguments))
- {
- channel_name = arguments;
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- new_topic = (pos[0]) ? pos : NULL;
- }
- }
- else
- new_topic = arguments;
- }
-
- /* look for current channel if not specified */
- if (!channel_name)
- {
- if (WIN_IS_SERVER(gui_current_window))
- {
- gui_printf (server->window,
- _("%s \"%s\" command can not be executed on a server window\n"),
- WEECHAT_ERROR, "topic");
- return -1;
- }
- channel_name = CHANNEL(gui_current_window)->name;
- }
-
- if (new_topic)
- {
- if (strcmp (new_topic, "-delete") == 0)
- server_sendf (server, "TOPIC %s :\r\n", channel_name);
- else
- server_sendf (server, "TOPIC %s :%s\r\n", channel_name, new_topic);
- }
- else
- server_sendf (server, "TOPIC %s\r\n", channel_name);
- return 0;
-}
-
-/*
- * irc_cmd_send_version: gives the version info of nick or server (current or specified)
- */
-
-int
-irc_cmd_send_version (t_irc_server *server, char *arguments)
-{
- if (arguments)
- {
- if (WIN_IS_CHANNEL(gui_current_window) &&
- nick_search (CHANNEL(gui_current_window), arguments))
- server_sendf (server, "PRIVMSG %s :\01VERSION\01\r\n",
- arguments);
- else
- server_sendf (server, "VERSION %s\r\n",
- arguments);
- }
- else
- {
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf (server->window, _("%s, compiled on %s %s\n"),
- WEECHAT_NAME_AND_VERSION,
- __DATE__, __TIME__);
- server_sendf (server, "VERSION\r\n");
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_voice: give voice to nickname(s)
- */
-
-int
-irc_cmd_send_voice (t_irc_server *server, int argc, char **argv)
-{
- int i;
-
- if (WIN_IS_CHANNEL(gui_current_window))
- {
- for (i = 0; i < argc; i++)
- server_sendf (server, "MODE %s +v %s\r\n",
- CHANNEL(gui_current_window)->name,
- argv[i]);
- }
- else
- {
- gui_printf (server->window,
- _("%s \"%s\" command can only be executed in a channel window\n"),
- WEECHAT_ERROR, "voice");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_send_whois: query information about user(s)
- */
-
-int
-irc_cmd_send_whois (t_irc_server *server, char *arguments)
-{
- server_sendf (server, "WHOIS %s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_recv_error: error received from server
- */
-
-int
-irc_cmd_recv_error (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
- int first;
-
- /* make gcc happy */
- (void) server;
- (void) host;
-
- if (strncmp (arguments, "Closing Link", 12) == 0)
- {
- server_disconnect (server);
- return 0;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server->window, PREFIX_ERROR);
- first = 1;
-
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ' ');
- if ((pos[0] == ':') || (!pos2))
- {
- if (pos[0] == ':')
- pos++;
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- "%s%s\n", (first) ? "" : ": ", pos);
- pos = NULL;
- }
- else
- {
- pos2[0] = '\0';
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s%s",
- (first) ? "" : " ", pos);
- first = 0;
- pos = pos2 + 1;
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_join: 'join' message received
- */
-
-int
-irc_cmd_recv_join (t_irc_server *server, char *host, char *arguments)
-{
- t_irc_channel *ptr_channel;
- char *pos;
-
- ptr_channel = channel_search (server, arguments);
- if (!ptr_channel)
- {
- ptr_channel = channel_new (server, CHAT_CHANNEL, arguments);
- if (!ptr_channel)
- {
- gui_printf (server->window,
- _("%s cannot create new channel \"%s\"\n"),
- WEECHAT_ERROR, arguments);
- return -1;
- }
- }
-
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- irc_display_prefix (ptr_channel->window, PREFIX_JOIN);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
- "%s ", host);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
- "(");
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_HOST,
- "%s", pos + 1);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
- ")");
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
- _(" has joined "));
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
- "%s\n", arguments);
- nick_new (ptr_channel, host, 0, 0, 0);
- gui_redraw_window_nick (gui_current_window);
- return 0;
-}
-
-/*
- * irc_cmd_recv_kick: 'kick' message received
- */
-
-int
-irc_cmd_recv_kick (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos_nick, *pos_comment;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
-
- pos_comment = strchr (pos_nick, ' ');
- if (pos_comment)
- {
- pos_comment[0] = '\0';
- pos_comment++;
- while (pos_comment[0] == ' ')
- pos_comment++;
- if (pos_comment[0] == ':')
- pos_comment++;
- }
-
- ptr_channel = channel_search (server, arguments);
- if (!ptr_channel)
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "kick");
- return -1;
- }
-
- irc_display_prefix (ptr_channel->window, PREFIX_PART);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
- "%s", host);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
- _(" has kicked "));
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
- "%s", pos_nick);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
- _(" from "));
- if (pos_comment)
- {
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
- "%s ", arguments);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
- "(");
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
- "%s", pos_comment);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
- ")\n");
- }
- else
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
- "%s\n", arguments);
- }
- else
- {
- gui_printf (server->window,
- _("%s nick not found for \"%s\" command\n"),
- WEECHAT_ERROR, "kick");
- return -1;
- }
- ptr_nick = nick_search (ptr_channel, pos_nick);
- if (ptr_nick)
- {
- nick_free (ptr_channel, ptr_nick);
- gui_redraw_window_nick (gui_current_window);
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_mode: 'mode' message received
- */
-
-int
-irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2, *pos_parm;
- char set_flag;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* no host => we can't identify sender of message! */
- if (host == NULL)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "mode");
- return -1;
- }
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- pos = strchr (arguments, ' ');
- if (!pos)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without channel or nickname\n"),
- WEECHAT_ERROR, "mode");
- return -1;
- }
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
-
- pos_parm = strchr (pos, ' ');
- if (pos_parm)
- {
- pos_parm[0] = '\0';
- pos_parm++;
- while (pos_parm[0] == ' ')
- pos_parm++;
- pos2 = strchr (pos_parm, ' ');
- if (pos2)
- pos2[0] = '\0';
- }
-
- set_flag = '+';
-
- if (string_is_channel (arguments))
- {
- ptr_channel = channel_search (server, arguments);
- if (ptr_channel)
- {
- /* channel modes */
- while (pos && pos[0])
- {
- switch (pos[0])
- {
- case '+':
- set_flag = '+';
- break;
- case '-':
- set_flag = '-';
- break;
- case 'b':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "b", host,
- (set_flag == '+') ?
- _("sets ban on") :
- _("removes ban on"),
- pos_parm);
- /* TODO: change & redraw channel modes */
- break;
- case 'i':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "i", host,
- (set_flag == '+') ?
- _("sets invite-only channel flag") :
- _("removes invite-only channel flag"),
- NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 'l':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "l", host,
- (set_flag == '+') ?
- _("sets the user limit to") :
- _("removes user limit"),
- (set_flag == '+') ? pos_parm : NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 'm':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "m", host,
- (set_flag == '+') ?
- _("sets moderated channel flag") :
- _("removes moderated channel flag"),
- NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 'o':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "o", host,
- (set_flag == '+') ?
- _("gives channel operator status to") :
- _("removes channel operator status from"),
- pos_parm);
- ptr_nick = nick_search (ptr_channel, pos_parm);
- if (ptr_nick)
- {
- ptr_nick->is_op = (set_flag == '+') ? 1 : 0;
- nick_resort (ptr_channel, ptr_nick);
- gui_redraw_window_nick (ptr_channel->window);
- }
- break;
- /* TODO: remove this obsolete (?) channel flag? */
- case 'p':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "p", host,
- (set_flag == '+') ?
- _("sets private channel flag") :
- _("removes private channel flag"),
- NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 's':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "s", host,
- (set_flag == '+') ?
- _("sets secret channel flag") :
- _("removes secret channel flag"),
- NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 't':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "t", host,
- (set_flag == '+') ?
- _("sets topic protection") :
- _("removes topic protection"),
- NULL);
- /* TODO: change & redraw channel modes */
- break;
- case 'v':
- irc_display_mode (ptr_channel->window,
- arguments, set_flag, "v", host,
- (set_flag == '+') ?
- _("gives voice to") :
- _("removes voice from"),
- pos_parm);
-
- ptr_nick = nick_search (ptr_channel, pos_parm);
- if (ptr_nick)
- {
- ptr_nick->has_voice = (set_flag == '+') ? 1 : 0;
- nick_resort (ptr_channel, ptr_nick);
- gui_redraw_window_nick (ptr_channel->window);
- }
- break;
- }
- pos++;
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "mode");
- return -1;
- }
- }
- else
- {
- /* nickname modes */
- gui_printf (server->window, "(TODO!) nickname modes: channel=%s, args=%s\n", arguments, pos);
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_nick: 'nick' message received
- */
-
-int
-irc_cmd_recv_nick (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- int nick_is_me;
-
- /* no host => we can't identify sender of message! */
- if (host == NULL)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "nick");
- return -1;
- }
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- ptr_nick = nick_search (ptr_channel, host);
- if (ptr_nick)
- {
- nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0);
- nick_change (ptr_channel, ptr_nick, arguments);
- irc_display_prefix (ptr_channel->window, PREFIX_INFO);
- if (nick_is_me)
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- _("You are "));
- else
- {
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK,
- "%s", host);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, " is ");
- }
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- _("now known as "));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK,
- "%s\n",
- arguments);
- if (ptr_channel->window->win_nick)
- gui_redraw_window_nick (ptr_channel->window);
- }
- }
-
- if (strcmp (server->nick, host) == 0)
- {
- free (server->nick);
- server->nick = strdup (arguments);
- }
- gui_redraw_window_input (gui_current_window);
-
- return 0;
-}
-
-/*
- * irc_cmd_recv_notice: 'notice' message received
- */
-
-int
-irc_cmd_recv_notice (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
-
- if (host)
- {
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
- }
- else
- {
- gui_printf (server->window,
- _("%s nickname not found for \"%s\" command\n"),
- WEECHAT_ERROR, "notice");
- return -1;
- }
- irc_display_prefix (server->window, PREFIX_SERVER);
- if (strncmp (pos, "\01VERSION", 8) == 0)
- {
- pos += 9;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- gui_printf_color (server->window, COLOR_WIN_CHAT, "CTCP ");
- gui_printf_color (server->window, COLOR_WIN_CHAT_CHANNEL, "VERSION ");
- gui_printf_color (server->window, COLOR_WIN_CHAT, _("reply from"));
- gui_printf_color (server->window, COLOR_WIN_CHAT_NICK, " %s", host);
- gui_printf_color (server->window, COLOR_WIN_CHAT, ": %s\n", pos);
- }
- else
- gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", pos);
- return 0;
-}
-
-/*
- * irc_cmd_recv_part: 'part' message received
- */
-
-int
-irc_cmd_recv_part (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos_args;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* no host => we can't identify sender of message! */
- if (!host || !arguments)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without host or channel\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
-
- pos_args = strchr (arguments, ' ');
- if (pos_args)
- {
- pos_args[0] = '\0';
- pos_args++;
- while (pos_args[0] == ' ')
- pos_args++;
- if (pos_args[0] == ':')
- pos_args++;
- }
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- ptr_channel = channel_search (server, arguments);
- if (ptr_channel)
- {
- ptr_nick = nick_search (ptr_channel, host);
- if (ptr_nick)
- {
- if (strcmp (ptr_nick->nick, server->nick) == 0)
- {
- /* part request was issued by local client */
- gui_window_free (ptr_channel->window);
- channel_free (server, ptr_channel);
- gui_redraw_window_status (gui_current_window);
- gui_redraw_window_input (gui_current_window);
- }
- else
- {
-
- /* remove nick from nick list and display message */
- nick_free (ptr_channel, ptr_nick);
- irc_display_prefix (ptr_channel->window, PREFIX_PART);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK, "%s ", host);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, "(");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_HOST, "%s", pos+1);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, ")");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _(" has left "));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s", ptr_channel->name);
- if (pos_args && pos_args[0])
- {
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, " (");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, "%s", pos_args);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, ")");
- }
- gui_printf (ptr_channel->window, "\n");
-
- /* redraw nick list if this is current window */
- if (ptr_channel->window->win_nick)
- gui_redraw_window_nick (ptr_channel->window);
- }
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "part");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * irc_cmd_recv_ping: 'ping' command received
- */
-
-int
-irc_cmd_recv_ping (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
-
- (void)host;
- pos = strrchr (arguments, ' ');
- if (pos)
- pos[0] = '\0';
- server_sendf (server, "PONG :%s\r\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_recv_privmsg: 'privmsg' command received
- */
-
-int
-irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2, *host2;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- struct utsname *buf;
-
- /* no host => we can't identify sender of message! */
- if (host == NULL)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- {
- pos[0] = '\0';
- host2 = pos+1;
- }
- else
- host2 = host;
-
- /* receiver is a channel ? */
- if (string_is_channel (arguments))
- {
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
-
- ptr_channel = channel_search (server, arguments);
- if (ptr_channel)
- {
- if (strncmp (pos, "\01ACTION ", 8) == 0)
- {
- pos += 8;
- pos2 = strchr (pos, '\01');
- if (pos2)
- pos2[0] = '\0';
- irc_display_prefix (ptr_channel->window, PREFIX_ACTION_ME);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK, "%s", host);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, " %s\n", pos);
- }
- else
- {
- ptr_nick = nick_search (ptr_channel, host);
- if (ptr_nick)
- {
- irc_display_nick (ptr_channel->window, ptr_nick,
- MSG_TYPE_NICK, 1, 1, 0);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
- }
- else
- {
- gui_printf (server->window,
- _("%s nick not found for \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- }
- }
- else
- {
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
-
- if (strcmp (pos, "\01VERSION\01") == 0)
- {
- buf = (struct utsname *) malloc (sizeof (struct utsname));
- uname (buf);
- server_sendf (server,
- _("NOTICE %s :%sVERSION %s v%s"
- " compiled on %s, host \"%s\" is running "
- "%s %s / %s%s"),
- host, "\01", WEECHAT_NAME, WEECHAT_VERSION, __DATE__,
- &buf->nodename, &buf->sysname,
- &buf->release, &buf->machine, "\01\r\n");
- free (buf);
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, _("Received a "));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL, _("CTCP VERSION "));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, _("from"));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, " %s\n", host);
- }
- else
- {
- /* private message received */
- ptr_channel = channel_search (server, host);
- if (!ptr_channel)
- {
- ptr_channel = channel_new (server, CHAT_PRIVATE, host);
- if (!ptr_channel)
- {
- gui_printf (server->window,
- _("%s cannot create new private window \"%s\"\n"),
- WEECHAT_ERROR, host);
- return -1;
- }
- }
- if (!ptr_channel->topic)
- {
- ptr_channel->topic = strdup (host2);
- gui_redraw_window_title (ptr_channel->window);
- }
-
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "<");
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_NICK_PRIVATE,
- "%s", host);
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_NICK,
- COLOR_WIN_CHAT_DARK, "> ");
- gui_printf_color_type (ptr_channel->window,
- MSG_TYPE_MSG,
- COLOR_WIN_CHAT, "%s\n", pos);
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "privmsg");
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_quit: 'quit' command received
- */
-
-int
-irc_cmd_recv_quit (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
-
- /* no host => we can't identify sender of message! */
- if (host == NULL)
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without host\n"),
- WEECHAT_ERROR, "quit");
- return -1;
- }
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (ptr_channel->type == CHAT_PRIVATE)
- ptr_nick = NULL;
- else
- ptr_nick = nick_search (ptr_channel, host);
-
- if (ptr_nick || (strcmp (ptr_channel->name, host) == 0))
- {
- if (ptr_nick)
- nick_free (ptr_channel, ptr_nick);
- irc_display_prefix (ptr_channel->window, PREFIX_QUIT);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK, "%s ", host);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, "(");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_HOST, "%s", pos + 1);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, ") ");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _("has quit"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, " (");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, "%s",
- arguments);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, ")\n");
- if ((ptr_channel->window == gui_current_window) &&
- (ptr_channel->window->win_nick))
- gui_redraw_window_nick (ptr_channel->window);
- }
- }
-
- return 0;
-}
-
-/*
- * irc_cmd_recv_server_msg: command received from server (numeric)
- */
-
-int
-irc_cmd_recv_server_msg (t_irc_server *server, char *host, char *arguments)
-{
- /* make gcc happy */
- (void) host;
-
- /* skip nickname if at beginning of server message */
- if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
- {
- arguments += strlen (server->nick) + 1;
- while (arguments[0] == ' ')
- arguments++;
- }
-
- if (arguments[0] == ':')
- arguments++;
-
- /* display server message */
- irc_display_prefix (server->window, PREFIX_SERVER);
- gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_recv_server_reply: server reply
- */
-
-int
-irc_cmd_recv_server_reply (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
- int first;
-
- /* make gcc happy */
- (void) server;
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server->window, PREFIX_ERROR);
- first = 1;
-
- while (pos && pos[0])
- {
- pos2 = strchr (pos, ' ');
- if ((pos[0] == ':') || (!pos2))
- {
- if (pos[0] == ':')
- pos++;
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- "%s%s\n", (first) ? "" : ": ", pos);
- pos = NULL;
- }
- else
- {
- pos2[0] = '\0';
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s%s",
- (first) ? "" : " ", pos);
- first = 0;
- pos = pos2 + 1;
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_topic: 'topic' command received
- */
-
-int
-irc_cmd_recv_topic (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
- t_irc_channel *ptr_channel;
- t_gui_window *window;
-
- /* make gcc happy */
- (void) host;
-
- /* keep only nick name from host */
- pos = strchr (host, '!');
- if (pos)
- pos[0] = '\0';
-
- if (!string_is_channel (arguments))
- {
- gui_printf (server->window,
- _("%s \"%s\" command received without channel\n"),
- WEECHAT_ERROR, "topic");
- return -1;
- }
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] == ':')
- pos++;
- if (!pos[0])
- pos = NULL;
- }
-
- ptr_channel = channel_search (server, arguments);
- window = (ptr_channel) ? ptr_channel->window : server->window;
-
- irc_display_prefix (window, PREFIX_INFO);
- gui_printf_color (window,
- COLOR_WIN_CHAT_NICK, "%s",
- host);
- if (pos)
- {
- gui_printf_color (window,
- COLOR_WIN_CHAT, _(" has changed topic for "));
- gui_printf_color (window,
- COLOR_WIN_CHAT_CHANNEL, "%s",
- arguments);
- gui_printf_color (window,
- COLOR_WIN_CHAT, _(" to: \"%s\"\n"),
- pos);
- }
- else
- {
- gui_printf_color (window,
- COLOR_WIN_CHAT, _(" has unset topic for "));
- gui_printf_color (window,
- COLOR_WIN_CHAT_CHANNEL, "%s\n",
- arguments);
- }
-
- if (ptr_channel)
- {
- if (ptr_channel->topic)
- free (ptr_channel->topic);
- if (pos)
- ptr_channel->topic = strdup (pos);
- else
- ptr_channel->topic = strdup ("");
- gui_redraw_window_title (ptr_channel->window);
- }
-
- return 0;
-}
-
-/*
- * irc_cmd_recv_004: '004' command (connected to irc server)
- */
-
-int
-irc_cmd_recv_004 (t_irc_server *server, char *host, char *arguments)
-{
- /* make gcc happy */
- (void) host;
- (void) arguments;
-
- irc_cmd_recv_server_msg (server, host, arguments);
-
- /* connection to IRC server is ok! */
- server->is_connected = 1;
- gui_redraw_window_status (server->window);
- gui_redraw_window_input (server->window);
-
- /* execute command once connected */
- if (server->command && server->command[0])
- user_command(server, server->command);
-
- /* autojoin */
- if (server->autojoin && server->autojoin[0])
- return irc_cmd_send_join (server, server->autojoin);
-
- return 0;
-}
-
-/*
- * irc_cmd_recv_311: '311' command (away message)
- */
-
-int
-irc_cmd_recv_301 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_message;
-
- /* make gcc happy */
- (void) server;
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (gui_current_window, PREFIX_INFO);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT, _(" is away: %s\n"), pos_message);
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_311: '311' command (whois, user)
- */
-
-int
-irc_cmd_recv_311 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_user, *pos_host, *pos_realname;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_user = strchr (pos_nick, ' ');
- if (pos_user)
- {
- pos_user[0] = '\0';
- pos_user++;
- while (pos_user[0] == ' ')
- pos_user++;
- pos_host = strchr (pos_user, ' ');
- if (pos_host)
- {
- pos_host[0] = '\0';
- pos_host++;
- while (pos_host[0] == ' ')
- pos_host++;
- pos_realname = strchr (pos_host, ' ');
- if (pos_realname)
- {
- pos_realname[0] = '\0';
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- if (pos_realname[0] == '*')
- pos_realname++;
- while (pos_realname[0] == ' ')
- pos_realname++;
- if (pos_realname[0] == ':')
- pos_realname++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] (");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_HOST, "%s@%s",
- pos_user, pos_host);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, ")");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, ": %s\n", pos_realname);
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_312: '312' command (whois, server)
- */
-
-int
-irc_cmd_recv_312 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_server, *pos_serverinfo;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_server = strchr (pos_nick, ' ');
- if (pos_server)
- {
- pos_server[0] = '\0';
- pos_server++;
- while (pos_server[0] == ' ')
- pos_server++;
- pos_serverinfo = strchr (pos_server, ' ');
- if (pos_serverinfo)
- {
- pos_serverinfo[0] = '\0';
- pos_serverinfo++;
- while (pos_serverinfo[0] == ' ')
- pos_serverinfo++;
- if (pos_serverinfo[0] == ':')
- pos_serverinfo++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, "%s ", pos_server);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "(");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, "%s", pos_serverinfo);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, ")\n");
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_313: '313' command (whois, operator)
- */
-
-int
-irc_cmd_recv_313 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_message;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, "%s\n", pos_message);
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_317: '317' command (whois, idle)
- */
-
-int
-irc_cmd_recv_317 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_idle, *pos_signon, *pos_message;
- int idle_time, day, hour, min, sec;
- time_t datetime;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_idle = strchr (pos_nick, ' ');
- if (pos_idle)
- {
- pos_idle[0] = '\0';
- pos_idle++;
- while (pos_idle[0] == ' ')
- pos_idle++;
- pos_signon = strchr (pos_idle, ' ');
- if (pos_signon)
- {
- pos_signon[0] = '\0';
- pos_signon++;
- while (pos_signon[0] == ' ')
- pos_signon++;
- pos_message = strchr (pos_signon, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
-
- idle_time = atoi (pos_idle);
- day = idle_time / (60 * 60 * 24);
- hour = (idle_time % (60 * 60 * 24)) / (60 * 60);
- min = ((idle_time % (60 * 60 * 24)) % (60 * 60)) / 60;
- sec = ((idle_time % (60 * 60 * 24)) % (60 * 60)) % 60;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, _("idle: "));
- if (day > 0)
- {
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", day);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- (day > 1) ? _("days") : _("day"));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- ", ");
- }
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%02d ", hour);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- (hour > 1) ? _("hours") : _("hour"));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- " %02d ", min);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- (min > 1) ? _("minutes") : _("minute"));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- " %02d ", sec);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- (sec > 1) ? _("seconds") : _("second"));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT,
- ", ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, _("signon at: "));
- datetime = (time_t)(atol (pos_signon));
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s", ctime (&datetime));
- }
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_318: '318' command (whois, end)
- */
-
-int
-irc_cmd_recv_318 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_message;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, "%s\n", pos_message);
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_319: '319' command (whois, end)
- */
-
-int
-irc_cmd_recv_319 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_channel, *pos;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_channel = strchr (pos_nick, ' ');
- if (pos_channel)
- {
- pos_channel[0] = '\0';
- pos_channel++;
- while (pos_channel[0] == ' ')
- pos_channel++;
- if (pos_channel[0] == ':')
- pos_channel++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, _("Channels: "));
-
- while (pos_channel && pos_channel[0])
- {
- if (pos_channel[0] == '@')
- {
- gui_printf_color (server->window,
- COLOR_WIN_NICK_OP, "@");
- pos_channel++;
- }
- else
- {
- if (pos_channel[0] == '%')
- {
- gui_printf_color (server->window,
- COLOR_WIN_NICK_HALFOP, "%");
- pos_channel++;
- }
- else
- if (pos_channel[0] == '+')
- {
- gui_printf_color (server->window,
- COLOR_WIN_NICK_VOICE, "+");
- pos_channel++;
- }
- }
- pos = strchr (pos_channel, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s%s",
- pos_channel,
- (pos && pos[0]) ? " " : "\n");
- pos_channel = pos;
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_320: '320' command (whois, identified user)
- */
-
-int
-irc_cmd_recv_320 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_nick, *pos_message;
-
- /* make gcc happy */
- (void) host;
-
- pos_nick = strchr (arguments, ' ');
- if (pos_nick)
- {
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_message = strchr (pos_nick, ' ');
- if (pos_message)
- {
- pos_message[0] = '\0';
- pos_message++;
- while (pos_message[0] == ' ')
- pos_message++;
- if (pos_message[0] == ':')
- pos_message++;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "[");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- gui_printf_color (server->window,
- COLOR_WIN_CHAT_DARK, "] ");
- gui_printf_color (server->window,
- COLOR_WIN_CHAT, "%s\n", pos_message);
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_321: '321' command (/list start)
- */
-
-int
-irc_cmd_recv_321 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
-
- /* make gcc happy */
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf (server->window, "%s\n", pos);
- return 0;
-}
-
-/*
- * irc_cmd_recv_322: '322' command (channel for /list)
- */
-
-int
-irc_cmd_recv_322 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
-
- /* make gcc happy */
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf (server->window, "%s\n", pos);
- return 0;
-}
-
-/*
- * irc_cmd_recv_323: '323' command (/list end)
- */
-
-int
-irc_cmd_recv_323 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
-
- /* make gcc happy */
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- while (pos[0] == ' ')
- pos++;
- }
- else
- pos = arguments;
-
- irc_display_prefix (server->window, PREFIX_INFO);
- gui_printf (server->window, "%s\n", pos);
- return 0;
-}
-
-/*
- * irc_cmd_recv_331: '331' command received (no topic for channel)
- */
-
-int
-irc_cmd_recv_331 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos;
-
- /* make gcc happy */
- (void) server;
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- pos[0] = '\0';
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT, _("No topic set for "));
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT_CHANNEL, "%s\n", arguments);
- return 0;
-}
-
-/*
- * irc_cmd_recv_332: '332' command received (topic of channel)
- */
-
-int
-irc_cmd_recv_332 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
- t_irc_channel *ptr_channel;
-
- /* make gcc happy */
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- ptr_channel = channel_search (server, pos);
- if (ptr_channel)
- {
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (pos2[0] == ':')
- pos2++;
- if (ptr_channel->topic)
- free (ptr_channel->topic);
- ptr_channel->topic = strdup (pos2);
-
- irc_display_prefix (ptr_channel->window, PREFIX_INFO);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _("Topic for "));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL, "%s", pos);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _(" is: \"%s\"\n"), pos2);
-
- gui_redraw_window_title (ptr_channel->window);
- }
- else
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "332");
- return -1;
- }
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "332");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_333: '333' command received (infos about topic (nick / date)
- */
-
-int
-irc_cmd_recv_333 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos_channel, *pos_nick, *pos_date;
- t_irc_channel *ptr_channel;
- time_t datetime;
-
- /* make gcc happy */
- (void) host;
-
- pos_channel = strchr (arguments, ' ');
- if (pos_channel)
- {
- while (pos_channel[0] == ' ')
- pos_channel++;
- pos_nick = strchr (pos_channel, ' ');
- if (pos_nick)
- {
- pos_nick[0] = '\0';
- pos_nick++;
- while (pos_nick[0] == ' ')
- pos_nick++;
- pos_date = strchr (pos_nick, ' ');
- if (pos_date)
- {
- pos_date[0] = '\0';
- pos_date++;
- while (pos_date[0] == ' ')
- pos_date++;
-
- ptr_channel = channel_search (server, pos_channel);
- if (ptr_channel)
- {
- irc_display_prefix (ptr_channel->window, PREFIX_INFO);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _("Topic set by "));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_NICK, "%s", pos_nick);
- datetime = (time_t)(atol (pos_date));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, ", %s", ctime (&datetime));
- }
- else
- {
- gui_printf (server->window,
- _("%s channel not found for \"%s\" command\n"),
- WEECHAT_ERROR, "333");
- return -1;
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot identify date/time for \"%s\" command\n"),
- WEECHAT_ERROR, "333");
- return -1;
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot identify nickname for \"%s\" command\n"),
- WEECHAT_ERROR, "333");
- return -1;
- }
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot identify channel for \"%s\" command\n"),
- WEECHAT_ERROR, "333");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_351: '351' command received (server version)
- */
-
-int
-irc_cmd_recv_351 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
-
- /* make gcc happy */
- (void) server;
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- }
- else
- pos = arguments;
-
- pos2 = strstr (pos, " :");
- if (pos2)
- {
- pos2[0] = '\0';
- pos2 += 2;
- }
-
- irc_display_prefix (server->window, PREFIX_SERVER);
- if (pos2)
- gui_printf (server->window, "%s %s\n", pos, pos2);
- else
- gui_printf (server->window, "%s\n", pos);
- return 0;
-}
-
-/*
- * irc_cmd_recv_353: '353' command received (list of users on a channel)
- */
-
-int
-irc_cmd_recv_353 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos_nick;
- int is_op, is_halfop, has_voice;
- t_irc_channel *ptr_channel;
-
- /* make gcc happy */
- (void) host;
-
- pos = strstr (arguments, " = ");
- if (pos)
- arguments = pos + 3;
- pos = strchr (arguments, ' ');
- if (pos)
- {
- pos[0] = '\0';
-
- ptr_channel = channel_search (server, arguments);
- if (!ptr_channel)
- return 0;
-
- pos++;
- while (pos[0] == ' ')
- pos++;
- if (pos[0] != ':')
- {
- gui_printf (server->window,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "353");
- return -1;
- }
- pos++;
- if (pos[0])
- {
- while (pos && pos[0])
- {
- is_op = 0;
- is_halfop = 0;
- has_voice = 0;
- while ((pos[0] == '@') || (pos[0] == '%') || (pos[0] == '+'))
- {
- if (pos[0] == '@')
- is_op = 1;
- if (pos[0] == '%')
- is_halfop = 1;
- if (pos[0] == '+')
- has_voice = 1;
- pos++;
- }
- pos_nick = pos;
- pos = strchr (pos, ' ');
- if (pos)
- {
- pos[0] = '\0';
- pos++;
- }
- if (!nick_new (ptr_channel, pos_nick, is_op, is_halfop, has_voice))
- gui_printf (server->window,
- _("%s cannot create nick \"%s\" for channel \"%s\"\n"),
- WEECHAT_ERROR, pos_nick, ptr_channel->name);
- }
- }
- gui_redraw_window_nick (ptr_channel->window);
- }
- else
- {
- gui_printf (server->window,
- _("%s cannot parse \"%s\" command\n"),
- WEECHAT_ERROR, "353");
- return -1;
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_366: '366' command received (end of /names list)
- */
-
-int
-irc_cmd_recv_366 (t_irc_server *server, char *host, char *arguments)
-{
- char *pos, *pos2;
- t_irc_channel *ptr_channel;
- t_irc_nick *ptr_nick;
- int num_nicks, num_op, num_halfop, num_voice, num_normal;
-
- /* make gcc happy */
- (void) host;
-
- pos = strchr (arguments, ' ');
- if (pos)
- {
- while (pos[0] == ' ')
- pos++;
- pos2 = strchr (pos, ' ');
- if (pos2)
- {
- pos2[0] = '\0';
- pos2++;
- while (pos2[0] == ' ')
- pos2++;
- if (pos2[0] == ':')
- pos2++;
-
- ptr_channel = channel_search (server, pos);
- if (ptr_channel)
- {
-
- /* display users on channel */
- irc_display_prefix (ptr_channel->window, PREFIX_INFO);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
- _("Nicks "));
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
- "%s", ptr_channel->name);
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT, ": ");
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK, "[");
-
- for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
- {
- irc_display_nick (ptr_channel->window, ptr_nick,
- MSG_TYPE_INFO, 0, 0, 1);
- if (ptr_nick != ptr_channel->last_nick)
- gui_printf (ptr_channel->window, " ");
- }
- gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK, "]\n");
-
- /* display number of nicks, ops, halfops & voices on the channel */
- nick_count (ptr_channel, &num_nicks, &num_op, &num_halfop, &num_voice,
- &num_normal);
- irc_display_prefix (ptr_channel->window, PREFIX_INFO);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, _("Channel "));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%s", ptr_channel->name);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT, ": ");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", num_nicks);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- (num_nicks > 1) ? _("nicks") : _("nick"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, " (");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", num_op);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- (num_op > 1) ? _("ops") : _("op"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- ", ");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", num_halfop);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- (num_halfop > 1) ? _("halfops") : _("halfop"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- ", ");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", num_voice);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- (num_voice > 1) ? _("voices") : _("voice"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- ", ");
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_CHANNEL,
- "%d ", num_normal);
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT,
- _("normal"));
- gui_printf_color (ptr_channel->window,
- COLOR_WIN_CHAT_DARK, ")\n");
- }
- else
- {
- irc_display_prefix (gui_current_window, PREFIX_INFO);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT_CHANNEL, pos);
- gui_printf_color (gui_current_window,
- COLOR_WIN_CHAT, ": %s\n", pos2);
- return 0;
- }
- }
- }
- return 0;
-}
-
-/*
- * irc_cmd_recv_433: '433' command received (nickname already in use)
- */
-
-int
-irc_cmd_recv_433 (t_irc_server *server, char *host, char *arguments)
-{
- char hostname[128];
-
- if (!server->is_connected)
- {
- if (strcmp (server->nick, server->nick1) == 0)
- {
- gui_printf (server->window,
- _("%s: nickname \"%s\" is already in use, "
- "trying 2nd nickname \"%s\"\n"),
- WEECHAT_NAME, server->nick, server->nick2);
- free (server->nick);
- server->nick = strdup (server->nick2);
- }
- else
- {
- if (strcmp (server->nick, server->nick2) == 0)
- {
- gui_printf (server->window,
- _("%s: nickname \"%s\" is already in use, "
- "trying 3rd nickname \"%s\"\n"),
- WEECHAT_NAME, server->nick, server->nick3);
- free (server->nick);
- server->nick = strdup (server->nick3);
- }
- else
- {
- gui_printf (server->window,
- _("%s: all declared nicknames are already in use, "
- "closing connection with server!\n"),
- WEECHAT_NAME);
- server_disconnect (server);
- return 0;
- }
- }
-
- gethostname (hostname, sizeof (hostname) - 1);
- hostname[sizeof (hostname) - 1] = '\0';
- if (!hostname[0])
- strcpy (hostname, _("unknown"));
- server_sendf (server,
- "NICK %s\r\n",
- server->nick);
- }
- else
- return irc_cmd_recv_error (server, host, arguments);
- return 0;
-}
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
new file mode 100644
index 000000000..4404b6682
--- /dev/null
+++ b/src/irc/irc-recv.c
@@ -0,0 +1,2113 @@
+/*
+ * Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
+ * Bounga <bounga@altern.org>
+ * Xahlexx <xahlexx@tuxisland.org>
+ * See README for License detail.
+ *
+ * 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
+ */
+
+
+/* irc-recv.c: implementation of IRC commands (server to client),
+ according to RFC 1459,2810,2811,2812 */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/utsname.h>
+
+#include "../weechat.h"
+#include "irc.h"
+#include "../command.h"
+#include "../config.h"
+#include "../gui/gui.h"
+
+
+/*
+ * irc_recv_command: executes action when receiving IRC command
+ * returns: 0 = all ok, command executed
+ * -1 = command failed
+ * -2 = no command to execute
+ * -3 = command not found
+ */
+
+int
+irc_recv_command (t_irc_server *server,
+ char *host, char *command, char *arguments)
+{
+ int i, cmd_found;
+
+ if (command == NULL)
+ return -2;
+
+ /* looks for irc command */
+ cmd_found = -1;
+ for (i = 0; irc_commands[i].command_name; i++)
+ if (strcasecmp (irc_commands[i].command_name, command) == 0)
+ {
+ cmd_found = i;
+ break;
+ }
+
+ /* command not found */
+ if (cmd_found < 0)
+ return -3;
+
+ if (irc_commands[i].recv_function != NULL)
+ return (int) (irc_commands[i].recv_function) (server, host, arguments);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_error: error received from server
+ */
+
+int
+irc_cmd_recv_error (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+ int first;
+
+ /* make gcc happy */
+ (void) server;
+ (void) host;
+
+ if (strncmp (arguments, "Closing Link", 12) == 0)
+ {
+ server_disconnect (server);
+ return 0;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ irc_display_prefix (server->window, PREFIX_ERROR);
+ first = 1;
+
+ while (pos && pos[0])
+ {
+ pos2 = strchr (pos, ' ');
+ if ((pos[0] == ':') || (!pos2))
+ {
+ if (pos[0] == ':')
+ pos++;
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ "%s%s\n", (first) ? "" : ": ", pos);
+ pos = NULL;
+ }
+ else
+ {
+ pos2[0] = '\0';
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s%s",
+ (first) ? "" : " ", pos);
+ first = 0;
+ pos = pos2 + 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_join: 'join' message received
+ */
+
+int
+irc_cmd_recv_join (t_irc_server *server, char *host, char *arguments)
+{
+ t_irc_channel *ptr_channel;
+ char *pos;
+
+ ptr_channel = channel_search (server, arguments);
+ if (!ptr_channel)
+ {
+ ptr_channel = channel_new (server, CHAT_CHANNEL, arguments);
+ if (!ptr_channel)
+ {
+ gui_printf (server->window,
+ _("%s cannot create new channel \"%s\"\n"),
+ WEECHAT_ERROR, arguments);
+ return -1;
+ }
+ }
+
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ irc_display_prefix (ptr_channel->window, PREFIX_JOIN);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
+ "%s ", host);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
+ "(");
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_HOST,
+ "%s", pos + 1);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
+ ")");
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
+ _(" has joined "));
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
+ "%s\n", arguments);
+ nick_new (ptr_channel, host, 0, 0, 0);
+ gui_redraw_window_nick (gui_current_window);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_kick: 'kick' message received
+ */
+
+int
+irc_cmd_recv_kick (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos_nick, *pos_comment;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+
+ pos_comment = strchr (pos_nick, ' ');
+ if (pos_comment)
+ {
+ pos_comment[0] = '\0';
+ pos_comment++;
+ while (pos_comment[0] == ' ')
+ pos_comment++;
+ if (pos_comment[0] == ':')
+ pos_comment++;
+ }
+
+ ptr_channel = channel_search (server, arguments);
+ if (!ptr_channel)
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "kick");
+ return -1;
+ }
+
+ irc_display_prefix (ptr_channel->window, PREFIX_PART);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
+ "%s", host);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
+ _(" has kicked "));
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_NICK,
+ "%s", pos_nick);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
+ _(" from "));
+ if (pos_comment)
+ {
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
+ "%s ", arguments);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
+ "(");
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
+ "%s", pos_comment);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK,
+ ")\n");
+ }
+ else
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
+ "%s\n", arguments);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s nick not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "kick");
+ return -1;
+ }
+ ptr_nick = nick_search (ptr_channel, pos_nick);
+ if (ptr_nick)
+ {
+ nick_free (ptr_channel, ptr_nick);
+ gui_redraw_window_nick (gui_current_window);
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_mode: 'mode' message received
+ */
+
+int
+irc_cmd_recv_mode (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2, *pos_parm;
+ char set_flag;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* no host => we can't identify sender of message! */
+ if (host == NULL)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without host\n"),
+ WEECHAT_ERROR, "mode");
+ return -1;
+ }
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ pos = strchr (arguments, ' ');
+ if (!pos)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without channel or nickname\n"),
+ WEECHAT_ERROR, "mode");
+ return -1;
+ }
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+
+ pos_parm = strchr (pos, ' ');
+ if (pos_parm)
+ {
+ pos_parm[0] = '\0';
+ pos_parm++;
+ while (pos_parm[0] == ' ')
+ pos_parm++;
+ pos2 = strchr (pos_parm, ' ');
+ if (pos2)
+ pos2[0] = '\0';
+ }
+
+ set_flag = '+';
+
+ if (string_is_channel (arguments))
+ {
+ ptr_channel = channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ /* channel modes */
+ while (pos && pos[0])
+ {
+ switch (pos[0])
+ {
+ case '+':
+ set_flag = '+';
+ break;
+ case '-':
+ set_flag = '-';
+ break;
+ case 'b':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "b", host,
+ (set_flag == '+') ?
+ _("sets ban on") :
+ _("removes ban on"),
+ pos_parm);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 'i':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "i", host,
+ (set_flag == '+') ?
+ _("sets invite-only channel flag") :
+ _("removes invite-only channel flag"),
+ NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 'l':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "l", host,
+ (set_flag == '+') ?
+ _("sets the user limit to") :
+ _("removes user limit"),
+ (set_flag == '+') ? pos_parm : NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 'm':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "m", host,
+ (set_flag == '+') ?
+ _("sets moderated channel flag") :
+ _("removes moderated channel flag"),
+ NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 'o':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "o", host,
+ (set_flag == '+') ?
+ _("gives channel operator status to") :
+ _("removes channel operator status from"),
+ pos_parm);
+ ptr_nick = nick_search (ptr_channel, pos_parm);
+ if (ptr_nick)
+ {
+ ptr_nick->is_op = (set_flag == '+') ? 1 : 0;
+ nick_resort (ptr_channel, ptr_nick);
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ break;
+ /* TODO: remove this obsolete (?) channel flag? */
+ case 'p':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "p", host,
+ (set_flag == '+') ?
+ _("sets private channel flag") :
+ _("removes private channel flag"),
+ NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 's':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "s", host,
+ (set_flag == '+') ?
+ _("sets secret channel flag") :
+ _("removes secret channel flag"),
+ NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 't':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "t", host,
+ (set_flag == '+') ?
+ _("sets topic protection") :
+ _("removes topic protection"),
+ NULL);
+ /* TODO: change & redraw channel modes */
+ break;
+ case 'v':
+ irc_display_mode (ptr_channel->window,
+ arguments, set_flag, "v", host,
+ (set_flag == '+') ?
+ _("gives voice to") :
+ _("removes voice from"),
+ pos_parm);
+
+ ptr_nick = nick_search (ptr_channel, pos_parm);
+ if (ptr_nick)
+ {
+ ptr_nick->has_voice = (set_flag == '+') ? 1 : 0;
+ nick_resort (ptr_channel, ptr_nick);
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ break;
+ }
+ pos++;
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "mode");
+ return -1;
+ }
+ }
+ else
+ {
+ /* nickname modes */
+ gui_printf (server->window, "(TODO!) nickname modes: channel=%s, args=%s\n", arguments, pos);
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_nick: 'nick' message received
+ */
+
+int
+irc_cmd_recv_nick (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ int nick_is_me;
+
+ /* no host => we can't identify sender of message! */
+ if (host == NULL)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without host\n"),
+ WEECHAT_ERROR, "nick");
+ return -1;
+ }
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ ptr_nick = nick_search (ptr_channel, host);
+ if (ptr_nick)
+ {
+ nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0);
+ nick_change (ptr_channel, ptr_nick, arguments);
+ irc_display_prefix (ptr_channel->window, PREFIX_INFO);
+ if (nick_is_me)
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ _("You are "));
+ else
+ {
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK,
+ "%s", host);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, " is ");
+ }
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ _("now known as "));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK,
+ "%s\n",
+ arguments);
+ if (ptr_channel->window->win_nick)
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ }
+
+ if (strcmp (server->nick, host) == 0)
+ {
+ free (server->nick);
+ server->nick = strdup (arguments);
+ }
+ gui_redraw_window_input (gui_current_window);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_notice: 'notice' message received
+ */
+
+int
+irc_cmd_recv_notice (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+
+ if (host)
+ {
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s nickname not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "notice");
+ return -1;
+ }
+ irc_display_prefix (server->window, PREFIX_SERVER);
+ if (strncmp (pos, "\01VERSION", 8) == 0)
+ {
+ pos += 9;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ gui_printf_color (server->window, COLOR_WIN_CHAT, "CTCP ");
+ gui_printf_color (server->window, COLOR_WIN_CHAT_CHANNEL, "VERSION ");
+ gui_printf_color (server->window, COLOR_WIN_CHAT, _("reply from"));
+ gui_printf_color (server->window, COLOR_WIN_CHAT_NICK, " %s", host);
+ gui_printf_color (server->window, COLOR_WIN_CHAT, ": %s\n", pos);
+ }
+ else
+ gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", pos);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_part: 'part' message received
+ */
+
+int
+irc_cmd_recv_part (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos_args;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* no host => we can't identify sender of message! */
+ if (!host || !arguments)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without host or channel\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+
+ pos_args = strchr (arguments, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ if (pos_args[0] == ':')
+ pos_args++;
+ }
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ ptr_channel = channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ ptr_nick = nick_search (ptr_channel, host);
+ if (ptr_nick)
+ {
+ if (strcmp (ptr_nick->nick, server->nick) == 0)
+ {
+ /* part request was issued by local client */
+ gui_window_free (ptr_channel->window);
+ channel_free (server, ptr_channel);
+ gui_redraw_window_status (gui_current_window);
+ gui_redraw_window_input (gui_current_window);
+ }
+ else
+ {
+
+ /* remove nick from nick list and display message */
+ nick_free (ptr_channel, ptr_nick);
+ irc_display_prefix (ptr_channel->window, PREFIX_PART);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK, "%s ", host);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, "(");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_HOST, "%s", pos+1);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, ")");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _(" has left "));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s", ptr_channel->name);
+ if (pos_args && pos_args[0])
+ {
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, " (");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, "%s", pos_args);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, ")");
+ }
+ gui_printf (ptr_channel->window, "\n");
+
+ /* redraw nick list if this is current window */
+ if (ptr_channel->window->win_nick)
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_ping: 'ping' command received
+ */
+
+int
+irc_cmd_recv_ping (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+
+ (void)host;
+ pos = strrchr (arguments, ' ');
+ if (pos)
+ pos[0] = '\0';
+ server_sendf (server, "PONG :%s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_privmsg: 'privmsg' command received
+ */
+
+int
+irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2, *host2;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ struct utsname *buf;
+
+ /* no host => we can't identify sender of message! */
+ if (host == NULL)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without host\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ {
+ pos[0] = '\0';
+ host2 = pos+1;
+ }
+ else
+ host2 = host;
+
+ /* receiver is a channel ? */
+ if (string_is_channel (arguments))
+ {
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+
+ ptr_channel = channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ if (strncmp (pos, "\01ACTION ", 8) == 0)
+ {
+ pos += 8;
+ pos2 = strchr (pos, '\01');
+ if (pos2)
+ pos2[0] = '\0';
+ irc_display_prefix (ptr_channel->window, PREFIX_ACTION_ME);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK, "%s", host);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, " %s\n", pos);
+ }
+ else
+ {
+ ptr_nick = nick_search (ptr_channel, host);
+ if (ptr_nick)
+ {
+ irc_display_nick (ptr_channel->window, ptr_nick,
+ MSG_TYPE_NICK, 1, 1, 0);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s nick not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+
+ if (strcmp (pos, "\01VERSION\01") == 0)
+ {
+ buf = (struct utsname *) malloc (sizeof (struct utsname));
+ uname (buf);
+ server_sendf (server,
+ _("NOTICE %s :%sVERSION %s v%s"
+ " compiled on %s, host \"%s\" is running "
+ "%s %s / %s%s"),
+ host, "\01", WEECHAT_NAME, WEECHAT_VERSION, __DATE__,
+ &buf->nodename, &buf->sysname,
+ &buf->release, &buf->machine, "\01\r\n");
+ free (buf);
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, _("Received a "));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL, _("CTCP VERSION "));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, _("from"));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, " %s\n", host);
+ }
+ else
+ {
+ /* private message received */
+ ptr_channel = channel_search (server, host);
+ if (!ptr_channel)
+ {
+ ptr_channel = channel_new (server, CHAT_PRIVATE, host);
+ if (!ptr_channel)
+ {
+ gui_printf (server->window,
+ _("%s cannot create new private window \"%s\"\n"),
+ WEECHAT_ERROR, host);
+ return -1;
+ }
+ }
+ if (!ptr_channel->topic)
+ {
+ ptr_channel->topic = strdup (host2);
+ gui_redraw_window_title (ptr_channel->window);
+ }
+
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "<");
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_NICK_PRIVATE,
+ "%s", host);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "> ");
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "privmsg");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_quit: 'quit' command received
+ */
+
+int
+irc_cmd_recv_quit (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ /* no host => we can't identify sender of message! */
+ if (host == NULL)
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without host\n"),
+ WEECHAT_ERROR, "quit");
+ return -1;
+ }
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel->type == CHAT_PRIVATE)
+ ptr_nick = NULL;
+ else
+ ptr_nick = nick_search (ptr_channel, host);
+
+ if (ptr_nick || (strcmp (ptr_channel->name, host) == 0))
+ {
+ if (ptr_nick)
+ nick_free (ptr_channel, ptr_nick);
+ irc_display_prefix (ptr_channel->window, PREFIX_QUIT);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK, "%s ", host);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, "(");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_HOST, "%s", pos + 1);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, ") ");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _("has quit"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, " (");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, "%s",
+ arguments);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, ")\n");
+ if ((ptr_channel->window == gui_current_window) &&
+ (ptr_channel->window->win_nick))
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_server_msg: command received from server (numeric)
+ */
+
+int
+irc_cmd_recv_server_msg (t_irc_server *server, char *host, char *arguments)
+{
+ /* make gcc happy */
+ (void) host;
+
+ /* skip nickname if at beginning of server message */
+ if (strncmp (server->nick, arguments, strlen (server->nick)) == 0)
+ {
+ arguments += strlen (server->nick) + 1;
+ while (arguments[0] == ' ')
+ arguments++;
+ }
+
+ if (arguments[0] == ':')
+ arguments++;
+
+ /* display server message */
+ irc_display_prefix (server->window, PREFIX_SERVER);
+ gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_server_reply: server reply
+ */
+
+int
+irc_cmd_recv_server_reply (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+ int first;
+
+ /* make gcc happy */
+ (void) server;
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ irc_display_prefix (server->window, PREFIX_ERROR);
+ first = 1;
+
+ while (pos && pos[0])
+ {
+ pos2 = strchr (pos, ' ');
+ if ((pos[0] == ':') || (!pos2))
+ {
+ if (pos[0] == ':')
+ pos++;
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ "%s%s\n", (first) ? "" : ": ", pos);
+ pos = NULL;
+ }
+ else
+ {
+ pos2[0] = '\0';
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s%s",
+ (first) ? "" : " ", pos);
+ first = 0;
+ pos = pos2 + 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_topic: 'topic' command received
+ */
+
+int
+irc_cmd_recv_topic (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+ t_irc_channel *ptr_channel;
+ t_gui_window *window;
+
+ /* make gcc happy */
+ (void) host;
+
+ /* keep only nick name from host */
+ pos = strchr (host, '!');
+ if (pos)
+ pos[0] = '\0';
+
+ if (!string_is_channel (arguments))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command received without channel\n"),
+ WEECHAT_ERROR, "topic");
+ return -1;
+ }
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] == ':')
+ pos++;
+ if (!pos[0])
+ pos = NULL;
+ }
+
+ ptr_channel = channel_search (server, arguments);
+ window = (ptr_channel) ? ptr_channel->window : server->window;
+
+ irc_display_prefix (window, PREFIX_INFO);
+ gui_printf_color (window,
+ COLOR_WIN_CHAT_NICK, "%s",
+ host);
+ if (pos)
+ {
+ gui_printf_color (window,
+ COLOR_WIN_CHAT, _(" has changed topic for "));
+ gui_printf_color (window,
+ COLOR_WIN_CHAT_CHANNEL, "%s",
+ arguments);
+ gui_printf_color (window,
+ COLOR_WIN_CHAT, _(" to: \"%s\"\n"),
+ pos);
+ }
+ else
+ {
+ gui_printf_color (window,
+ COLOR_WIN_CHAT, _(" has unset topic for "));
+ gui_printf_color (window,
+ COLOR_WIN_CHAT_CHANNEL, "%s\n",
+ arguments);
+ }
+
+ if (ptr_channel)
+ {
+ if (ptr_channel->topic)
+ free (ptr_channel->topic);
+ if (pos)
+ ptr_channel->topic = strdup (pos);
+ else
+ ptr_channel->topic = strdup ("");
+ gui_redraw_window_title (ptr_channel->window);
+ }
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_004: '004' command (connected to irc server)
+ */
+
+int
+irc_cmd_recv_004 (t_irc_server *server, char *host, char *arguments)
+{
+ /* make gcc happy */
+ (void) host;
+ (void) arguments;
+
+ irc_cmd_recv_server_msg (server, host, arguments);
+
+ /* connection to IRC server is ok! */
+ server->is_connected = 1;
+ gui_redraw_window_status (server->window);
+ gui_redraw_window_input (server->window);
+
+ /* execute command once connected */
+ if (server->command && server->command[0])
+ user_command(server, server->command);
+
+ /* autojoin */
+ if (server->autojoin && server->autojoin[0])
+ return irc_cmd_send_join (server, server->autojoin);
+
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_311: '311' command (away message)
+ */
+
+int
+irc_cmd_recv_301 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_message;
+
+ /* make gcc happy */
+ (void) server;
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ irc_display_prefix (gui_current_window, PREFIX_INFO);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT, _(" is away: %s\n"), pos_message);
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_311: '311' command (whois, user)
+ */
+
+int
+irc_cmd_recv_311 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_user, *pos_host, *pos_realname;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_user = strchr (pos_nick, ' ');
+ if (pos_user)
+ {
+ pos_user[0] = '\0';
+ pos_user++;
+ while (pos_user[0] == ' ')
+ pos_user++;
+ pos_host = strchr (pos_user, ' ');
+ if (pos_host)
+ {
+ pos_host[0] = '\0';
+ pos_host++;
+ while (pos_host[0] == ' ')
+ pos_host++;
+ pos_realname = strchr (pos_host, ' ');
+ if (pos_realname)
+ {
+ pos_realname[0] = '\0';
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ if (pos_realname[0] == '*')
+ pos_realname++;
+ while (pos_realname[0] == ' ')
+ pos_realname++;
+ if (pos_realname[0] == ':')
+ pos_realname++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] (");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_HOST, "%s@%s",
+ pos_user, pos_host);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, ")");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, ": %s\n", pos_realname);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_312: '312' command (whois, server)
+ */
+
+int
+irc_cmd_recv_312 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_server, *pos_serverinfo;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_server = strchr (pos_nick, ' ');
+ if (pos_server)
+ {
+ pos_server[0] = '\0';
+ pos_server++;
+ while (pos_server[0] == ' ')
+ pos_server++;
+ pos_serverinfo = strchr (pos_server, ' ');
+ if (pos_serverinfo)
+ {
+ pos_serverinfo[0] = '\0';
+ pos_serverinfo++;
+ while (pos_serverinfo[0] == ' ')
+ pos_serverinfo++;
+ if (pos_serverinfo[0] == ':')
+ pos_serverinfo++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, "%s ", pos_server);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "(");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, "%s", pos_serverinfo);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, ")\n");
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_313: '313' command (whois, operator)
+ */
+
+int
+irc_cmd_recv_313 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_message;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, "%s\n", pos_message);
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_317: '317' command (whois, idle)
+ */
+
+int
+irc_cmd_recv_317 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_idle, *pos_signon, *pos_message;
+ int idle_time, day, hour, min, sec;
+ time_t datetime;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_idle = strchr (pos_nick, ' ');
+ if (pos_idle)
+ {
+ pos_idle[0] = '\0';
+ pos_idle++;
+ while (pos_idle[0] == ' ')
+ pos_idle++;
+ pos_signon = strchr (pos_idle, ' ');
+ if (pos_signon)
+ {
+ pos_signon[0] = '\0';
+ pos_signon++;
+ while (pos_signon[0] == ' ')
+ pos_signon++;
+ pos_message = strchr (pos_signon, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+
+ idle_time = atoi (pos_idle);
+ day = idle_time / (60 * 60 * 24);
+ hour = (idle_time % (60 * 60 * 24)) / (60 * 60);
+ min = ((idle_time % (60 * 60 * 24)) % (60 * 60)) / 60;
+ sec = ((idle_time % (60 * 60 * 24)) % (60 * 60)) % 60;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, _("idle: "));
+ if (day > 0)
+ {
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", day);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ (day > 1) ? _("days") : _("day"));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ ", ");
+ }
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%02d ", hour);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ (hour > 1) ? _("hours") : _("hour"));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ " %02d ", min);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ (min > 1) ? _("minutes") : _("minute"));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ " %02d ", sec);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ (sec > 1) ? _("seconds") : _("second"));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT,
+ ", ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, _("signon at: "));
+ datetime = (time_t)(atol (pos_signon));
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s", ctime (&datetime));
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_318: '318' command (whois, end)
+ */
+
+int
+irc_cmd_recv_318 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_message;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, "%s\n", pos_message);
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_319: '319' command (whois, end)
+ */
+
+int
+irc_cmd_recv_319 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_channel, *pos;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_channel = strchr (pos_nick, ' ');
+ if (pos_channel)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ if (pos_channel[0] == ':')
+ pos_channel++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, _("Channels: "));
+
+ while (pos_channel && pos_channel[0])
+ {
+ if (pos_channel[0] == '@')
+ {
+ gui_printf_color (server->window,
+ COLOR_WIN_NICK_OP, "@");
+ pos_channel++;
+ }
+ else
+ {
+ if (pos_channel[0] == '%')
+ {
+ gui_printf_color (server->window,
+ COLOR_WIN_NICK_HALFOP, "%");
+ pos_channel++;
+ }
+ else
+ if (pos_channel[0] == '+')
+ {
+ gui_printf_color (server->window,
+ COLOR_WIN_NICK_VOICE, "+");
+ pos_channel++;
+ }
+ }
+ pos = strchr (pos_channel, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s%s",
+ pos_channel,
+ (pos && pos[0]) ? " " : "\n");
+ pos_channel = pos;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_320: '320' command (whois, identified user)
+ */
+
+int
+irc_cmd_recv_320 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_nick, *pos_message;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_nick = strchr (arguments, ' ');
+ if (pos_nick)
+ {
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_message = strchr (pos_nick, ' ');
+ if (pos_message)
+ {
+ pos_message[0] = '\0';
+ pos_message++;
+ while (pos_message[0] == ' ')
+ pos_message++;
+ if (pos_message[0] == ':')
+ pos_message++;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "[");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT_DARK, "] ");
+ gui_printf_color (server->window,
+ COLOR_WIN_CHAT, "%s\n", pos_message);
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_321: '321' command (/list start)
+ */
+
+int
+irc_cmd_recv_321 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf (server->window, "%s\n", pos);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_322: '322' command (channel for /list)
+ */
+
+int
+irc_cmd_recv_322 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf (server->window, "%s\n", pos);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_323: '323' command (/list end)
+ */
+
+int
+irc_cmd_recv_323 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf (server->window, "%s\n", pos);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_331: '331' command received (no topic for channel)
+ */
+
+int
+irc_cmd_recv_331 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos;
+
+ /* make gcc happy */
+ (void) server;
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ pos[0] = '\0';
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT, _("No topic set for "));
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT_CHANNEL, "%s\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_332: '332' command received (topic of channel)
+ */
+
+int
+irc_cmd_recv_332 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+ t_irc_channel *ptr_channel;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ ptr_channel = channel_search (server, pos);
+ if (ptr_channel)
+ {
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (pos2[0] == ':')
+ pos2++;
+ if (ptr_channel->topic)
+ free (ptr_channel->topic);
+ ptr_channel->topic = strdup (pos2);
+
+ irc_display_prefix (ptr_channel->window, PREFIX_INFO);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _("Topic for "));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL, "%s", pos);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _(" is: \"%s\"\n"), pos2);
+
+ gui_redraw_window_title (ptr_channel->window);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "332");
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot identify channel for \"%s\" command\n"),
+ WEECHAT_ERROR, "332");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_333: '333' command received (infos about topic (nick / date)
+ */
+
+int
+irc_cmd_recv_333 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos_channel, *pos_nick, *pos_date;
+ t_irc_channel *ptr_channel;
+ time_t datetime;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos_channel = strchr (arguments, ' ');
+ if (pos_channel)
+ {
+ while (pos_channel[0] == ' ')
+ pos_channel++;
+ pos_nick = strchr (pos_channel, ' ');
+ if (pos_nick)
+ {
+ pos_nick[0] = '\0';
+ pos_nick++;
+ while (pos_nick[0] == ' ')
+ pos_nick++;
+ pos_date = strchr (pos_nick, ' ');
+ if (pos_date)
+ {
+ pos_date[0] = '\0';
+ pos_date++;
+ while (pos_date[0] == ' ')
+ pos_date++;
+
+ ptr_channel = channel_search (server, pos_channel);
+ if (ptr_channel)
+ {
+ irc_display_prefix (ptr_channel->window, PREFIX_INFO);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _("Topic set by "));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_NICK, "%s", pos_nick);
+ datetime = (time_t)(atol (pos_date));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, ", %s", ctime (&datetime));
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s channel not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "333");
+ return -1;
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot identify date/time for \"%s\" command\n"),
+ WEECHAT_ERROR, "333");
+ return -1;
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot identify nickname for \"%s\" command\n"),
+ WEECHAT_ERROR, "333");
+ return -1;
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot identify channel for \"%s\" command\n"),
+ WEECHAT_ERROR, "333");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_351: '351' command received (server version)
+ */
+
+int
+irc_cmd_recv_351 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+
+ /* make gcc happy */
+ (void) server;
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ }
+ else
+ pos = arguments;
+
+ pos2 = strstr (pos, " :");
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2 += 2;
+ }
+
+ irc_display_prefix (server->window, PREFIX_SERVER);
+ if (pos2)
+ gui_printf (server->window, "%s %s\n", pos, pos2);
+ else
+ gui_printf (server->window, "%s\n", pos);
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_353: '353' command received (list of users on a channel)
+ */
+
+int
+irc_cmd_recv_353 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos_nick;
+ int is_op, is_halfop, has_voice;
+ t_irc_channel *ptr_channel;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strstr (arguments, " = ");
+ if (pos)
+ arguments = pos + 3;
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+
+ ptr_channel = channel_search (server, arguments);
+ if (!ptr_channel)
+ return 0;
+
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ if (pos[0] != ':')
+ {
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "353");
+ return -1;
+ }
+ pos++;
+ if (pos[0])
+ {
+ while (pos && pos[0])
+ {
+ is_op = 0;
+ is_halfop = 0;
+ has_voice = 0;
+ while ((pos[0] == '@') || (pos[0] == '%') || (pos[0] == '+'))
+ {
+ if (pos[0] == '@')
+ is_op = 1;
+ if (pos[0] == '%')
+ is_halfop = 1;
+ if (pos[0] == '+')
+ has_voice = 1;
+ pos++;
+ }
+ pos_nick = pos;
+ pos = strchr (pos, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ }
+ if (!nick_new (ptr_channel, pos_nick, is_op, is_halfop, has_voice))
+ gui_printf (server->window,
+ _("%s cannot create nick \"%s\" for channel \"%s\"\n"),
+ WEECHAT_ERROR, pos_nick, ptr_channel->name);
+ }
+ }
+ gui_redraw_window_nick (ptr_channel->window);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s cannot parse \"%s\" command\n"),
+ WEECHAT_ERROR, "353");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_366: '366' command received (end of /names list)
+ */
+
+int
+irc_cmd_recv_366 (t_irc_server *server, char *host, char *arguments)
+{
+ char *pos, *pos2;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+ int num_nicks, num_op, num_halfop, num_voice, num_normal;
+
+ /* make gcc happy */
+ (void) host;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ if (pos2[0] == ':')
+ pos2++;
+
+ ptr_channel = channel_search (server, pos);
+ if (ptr_channel)
+ {
+
+ /* display users on channel */
+ irc_display_prefix (ptr_channel->window, PREFIX_INFO);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT,
+ _("Nicks "));
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
+ "%s", ptr_channel->name);
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT, ": ");
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK, "[");
+
+ for (ptr_nick = ptr_channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
+ {
+ irc_display_nick (ptr_channel->window, ptr_nick,
+ MSG_TYPE_INFO, 0, 0, 1);
+ if (ptr_nick != ptr_channel->last_nick)
+ gui_printf (ptr_channel->window, " ");
+ }
+ gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_DARK, "]\n");
+
+ /* display number of nicks, ops, halfops & voices on the channel */
+ nick_count (ptr_channel, &num_nicks, &num_op, &num_halfop, &num_voice,
+ &num_normal);
+ irc_display_prefix (ptr_channel->window, PREFIX_INFO);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, _("Channel "));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%s", ptr_channel->name);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT, ": ");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", num_nicks);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ (num_nicks > 1) ? _("nicks") : _("nick"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, " (");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", num_op);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ (num_op > 1) ? _("ops") : _("op"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ ", ");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", num_halfop);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ (num_halfop > 1) ? _("halfops") : _("halfop"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ ", ");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", num_voice);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ (num_voice > 1) ? _("voices") : _("voice"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ ", ");
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_CHANNEL,
+ "%d ", num_normal);
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT,
+ _("normal"));
+ gui_printf_color (ptr_channel->window,
+ COLOR_WIN_CHAT_DARK, ")\n");
+ }
+ else
+ {
+ irc_display_prefix (gui_current_window, PREFIX_INFO);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT_CHANNEL, pos);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT, ": %s\n", pos2);
+ return 0;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_recv_433: '433' command received (nickname already in use)
+ */
+
+int
+irc_cmd_recv_433 (t_irc_server *server, char *host, char *arguments)
+{
+ char hostname[128];
+
+ if (!server->is_connected)
+ {
+ if (strcmp (server->nick, server->nick1) == 0)
+ {
+ gui_printf (server->window,
+ _("%s: nickname \"%s\" is already in use, "
+ "trying 2nd nickname \"%s\"\n"),
+ WEECHAT_NAME, server->nick, server->nick2);
+ free (server->nick);
+ server->nick = strdup (server->nick2);
+ }
+ else
+ {
+ if (strcmp (server->nick, server->nick2) == 0)
+ {
+ gui_printf (server->window,
+ _("%s: nickname \"%s\" is already in use, "
+ "trying 3rd nickname \"%s\"\n"),
+ WEECHAT_NAME, server->nick, server->nick3);
+ free (server->nick);
+ server->nick = strdup (server->nick3);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s: all declared nicknames are already in use, "
+ "closing connection with server!\n"),
+ WEECHAT_NAME);
+ server_disconnect (server);
+ return 0;
+ }
+ }
+
+ gethostname (hostname, sizeof (hostname) - 1);
+ hostname[sizeof (hostname) - 1] = '\0';
+ if (!hostname[0])
+ strcpy (hostname, _("unknown"));
+ server_sendf (server,
+ "NICK %s\r\n",
+ server->nick);
+ }
+ else
+ return irc_cmd_recv_error (server, host, arguments);
+ return 0;
+}
diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c
new file mode 100644
index 000000000..d086aee29
--- /dev/null
+++ b/src/irc/irc-send.c
@@ -0,0 +1,811 @@
+/*
+ * Copyright (c) 2003 by FlashCode <flashcode@flashtux.org>
+ * Bounga <bounga@altern.org>
+ * Xahlexx <xahlexx@tuxisland.org>
+ * See README for License detail.
+ *
+ * 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
+ */
+
+
+/* irc-send.c: implementation of IRC commands (client to server),
+ according to RFC 1459,2810,2811,2812 */
+
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/utsname.h>
+
+#include "../weechat.h"
+#include "irc.h"
+#include "../command.h"
+#include "../config.h"
+#include "../gui/gui.h"
+
+
+/*
+ * irc_login: login to irc server
+ */
+
+void
+irc_login (t_irc_server *server)
+{
+ char hostname[128];
+
+ if ((server->password) && (server->password[0]))
+ server_sendf (server, "PASS %s\r\n", server->password);
+
+ gethostname (hostname, sizeof (hostname) - 1);
+ hostname[sizeof (hostname) - 1] = '\0';
+ if (!hostname[0])
+ strcpy (hostname, _("unknown"));
+ gui_printf (server->window,
+ _("%s: using local hostname \"%s\"\n"),
+ WEECHAT_NAME, hostname);
+ server_sendf (server,
+ "NICK %s\r\n"
+ "USER %s %s %s :%s\r\n",
+ server->nick, server->username, hostname, "servername",
+ server->realname);
+}
+
+/*
+ * irc_cmd_send_away: toggle away status
+ */
+
+int
+irc_cmd_send_away (t_irc_server *server, char *arguments)
+{
+ char *pos;
+ t_irc_server *ptr_server;
+
+ if (arguments && (strncmp (arguments, "-all", 4) == 0))
+ {
+ pos = arguments + 4;
+ while (pos[0] == ' ')
+ pos++;
+ if (!pos[0])
+ pos = NULL;
+
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (server->is_connected)
+ {
+ if (pos)
+ server_sendf (ptr_server, "AWAY :%s\r\n", pos);
+ else
+ server_sendf (ptr_server, "AWAY\r\n");
+ }
+ }
+ }
+ else
+ {
+ if (arguments)
+ server_sendf (server, "AWAY :%s\r\n", arguments);
+ else
+ server_sendf (server, "AWAY\r\n");
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_ctcp: send a ctcp message
+ */
+
+int
+irc_cmd_send_ctcp (t_irc_server *server, char *arguments)
+{
+ char *pos, *pos2;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ pos2 = strchr (pos, ' ');
+ if (pos2)
+ {
+ pos2[0] = '\0';
+ pos2++;
+ while (pos2[0] == ' ')
+ pos2++;
+ }
+ else
+ pos2 = NULL;
+
+ if (strcasecmp (pos, "version") == 0)
+ {
+ if (pos2)
+ server_sendf (server, "PRIVMSG %s :\01VERSION %s\01\r\n",
+ arguments, pos2);
+ else
+ server_sendf (server, "PRIVMSG %s :\01VERSION\01\r\n",
+ arguments);
+ }
+ if (strcasecmp (pos, "action") == 0)
+ {
+ if (pos2)
+ server_sendf (server, "PRIVMSG %s :\01ACTION %s\01\r\n",
+ arguments, pos2);
+ else
+ server_sendf (server, "PRIVMSG %s :\01ACTION\01\r\n",
+ arguments);
+ }
+
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_deop: remove operator privileges from nickname(s)
+ */
+
+int
+irc_cmd_send_deop (t_irc_server *server, int argc, char **argv)
+{
+ int i;
+
+ if (WIN_IS_CHANNEL(gui_current_window))
+ {
+ for (i = 0; i < argc; i++)
+ server_sendf (server, "MODE %s -o %s\r\n",
+ CHANNEL(gui_current_window)->name,
+ argv[i]);
+ }
+ else
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "deop");
+ return 0;
+}
+
+/*
+ * irc_cmd_send_devoice: remove voice from nickname(s)
+ */
+
+int
+irc_cmd_send_devoice (t_irc_server *server, int argc, char **argv)
+{
+ int i;
+
+ if (WIN_IS_CHANNEL(gui_current_window))
+ {
+ for (i = 0; i < argc; i++)
+ server_sendf (server, "MODE %s -v %s\r\n",
+ CHANNEL(gui_current_window)->name,
+ argv[i]);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "devoice");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_invite: invite a nick on a channel
+ */
+
+int
+irc_cmd_send_invite (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "INVITE %s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_join: join a new channel
+ */
+
+int
+irc_cmd_send_join (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "JOIN %s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_kick: forcibly remove a user from a channel
+ */
+
+int
+irc_cmd_send_kick (t_irc_server *server, char *arguments)
+{
+ if (string_is_channel (arguments))
+ server_sendf (server, "KICK %s\r\n", arguments);
+ else
+ {
+ if (WIN_IS_CHANNEL (gui_current_window))
+ {
+ server_sendf (server,
+ "KICK %s %s\r\n",
+ CHANNEL(gui_current_window)->name, arguments);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "kick");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_kill: close client-server connection
+ */
+
+int
+irc_cmd_send_kill (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "KILL %s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_list: close client-server connection
+ */
+
+int
+irc_cmd_send_list (t_irc_server *server, char *arguments)
+{
+ if (arguments)
+ server_sendf (server, "LIST %s\r\n", arguments);
+ else
+ server_sendf (server, "LIST\r\n");
+ return 0;
+}
+
+/*
+ * irc_cmd_send_me: send a ctcp action to the current channel
+ */
+
+int
+irc_cmd_send_me (t_irc_server *server, char *arguments)
+{
+ if (WIN_IS_SERVER(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can not be executed on a server window\n"),
+ WEECHAT_ERROR, "me");
+ return -1;
+ }
+ server_sendf (server, "PRIVMSG %s :\01ACTION %s\01\r\n",
+ CHANNEL(gui_current_window)->name, arguments);
+ irc_display_prefix (gui_current_window, PREFIX_ACTION_ME);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT_NICK, "%s", server->nick);
+ gui_printf_color (gui_current_window,
+ COLOR_WIN_CHAT, " %s\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_mode: change mode for channel/nickname
+ */
+
+int
+irc_cmd_send_mode (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "MODE %s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_msg: send a message to a nick or channel
+ */
+
+int
+irc_cmd_send_msg (t_irc_server *server, char *arguments)
+{
+ char *pos, *pos_comma;
+ t_irc_channel *ptr_channel;
+ t_irc_nick *ptr_nick;
+
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+
+ while (arguments && arguments[0])
+ {
+ pos_comma = strchr (arguments, ',');
+ if (pos_comma)
+ {
+ pos_comma[0] = '\0';
+ pos_comma++;
+ }
+ if (strcmp (arguments, "*") == 0)
+ {
+ if (WIN_IS_SERVER(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can not be executed on a server window\n"),
+ WEECHAT_ERROR, "msg *");
+ return -1;
+ }
+ ptr_channel = CHANNEL(gui_current_window);
+ ptr_nick = nick_search (ptr_channel, server->nick);
+ if (ptr_nick)
+ {
+ irc_display_nick (ptr_channel->window, ptr_nick,
+ MSG_TYPE_NICK, 1, 1, 0);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
+ }
+ else
+ gui_printf (server->window,
+ _("%s nick not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "msg");
+ server_sendf (server, "PRIVMSG %s :%s\r\n", ptr_channel->name, pos);
+ }
+ else
+ {
+ if (string_is_channel (arguments))
+ {
+ ptr_channel = channel_search (server, arguments);
+ if (ptr_channel)
+ {
+ ptr_nick = nick_search (ptr_channel, server->nick);
+ if (ptr_nick)
+ {
+ irc_display_nick (ptr_channel->window, ptr_nick,
+ MSG_TYPE_NICK, 1, 1, 0);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
+ }
+ else
+ gui_printf (server->window,
+ _("%s nick not found for \"%s\" command\n"),
+ WEECHAT_ERROR, "msg");
+ }
+ server_sendf (server, "PRIVMSG %s :%s\r\n", arguments, pos);
+ }
+ else
+ {
+ ptr_channel = channel_search (server, arguments);
+ if (!ptr_channel)
+ {
+ ptr_channel = channel_new (server, CHAT_PRIVATE, arguments);
+ if (!ptr_channel)
+ {
+ gui_printf (server->window,
+ _("%s cannot create new private window \"%s\"\n"),
+ WEECHAT_ERROR,
+ arguments);
+ return -1;
+ }
+ gui_redraw_window_title (ptr_channel->window);
+ }
+
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "<");
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_NICK_SELF,
+ "%s", server->nick);
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_NICK,
+ COLOR_WIN_CHAT_DARK, "> ");
+ gui_printf_color_type (ptr_channel->window,
+ MSG_TYPE_MSG,
+ COLOR_WIN_CHAT, "%s\n", pos);
+ server_sendf (server, "PRIVMSG %s :%s\r\n", arguments, pos);
+ }
+ }
+ arguments = pos_comma;
+ }
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s wrong argument count for \"%s\" command\n"),
+ WEECHAT_ERROR, "msg");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_names: list nicknames on channels
+ */
+
+int
+irc_cmd_send_names (t_irc_server *server, char *arguments)
+{
+ if (arguments)
+ server_sendf (server, "NAMES %s\r\n", arguments);
+ else
+ {
+ if (!WIN_IS_CHANNEL(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "names");
+ return -1;
+ }
+ else
+ server_sendf (server, "NAMES %s\r\n",
+ CHANNEL(gui_current_window)->name);
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_nick: change nickname
+ */
+
+int
+irc_cmd_send_nick (t_irc_server *server, int argc, char **argv)
+{
+ if (argc != 1)
+ return -1;
+ server_sendf (server, "NICK %s\r\n", argv[0]);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_notice: send notice message
+ */
+
+int
+irc_cmd_send_notice (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "NOTICE %s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_op: give operator privileges to nickname(s)
+ */
+
+int
+irc_cmd_send_op (t_irc_server *server, int argc, char **argv)
+{
+ int i;
+
+ if (WIN_IS_CHANNEL(gui_current_window))
+ {
+ for (i = 0; i < argc; i++)
+ server_sendf (server, "MODE %s +o %s\r\n",
+ CHANNEL(gui_current_window)->name,
+ argv[i]);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "op");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_oper: get oper privileges
+ */
+
+int
+irc_cmd_send_oper (t_irc_server *server, int argc, char **argv)
+{
+ if (argc != 2)
+ return -1;
+ server_sendf (server, "OPER %s %s\r\n", argv[0], argv[1]);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_part: leave a channel or close a private window
+ */
+
+int
+irc_cmd_send_part (t_irc_server *server, char *arguments)
+{
+ char *channel_name, *pos_args;
+ t_irc_channel *ptr_channel;
+
+ if (arguments)
+ {
+ if (string_is_channel (arguments))
+ {
+ channel_name = arguments;
+ pos_args = strchr (arguments, ' ');
+ if (pos_args)
+ {
+ pos_args[0] = '\0';
+ pos_args++;
+ while (pos_args[0] == ' ')
+ pos_args++;
+ }
+ }
+ else
+ {
+ if (WIN_IS_SERVER(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can not be executed on a server window\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+ channel_name = CHANNEL(gui_current_window)->name;
+ pos_args = arguments;
+ }
+ }
+ else
+ {
+ if (WIN_IS_SERVER(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can not be executed on a server window\n"),
+ WEECHAT_ERROR, "part");
+ return -1;
+ }
+ if (WIN_IS_PRIVATE(gui_current_window))
+ {
+ ptr_channel = CHANNEL(gui_current_window);
+ gui_window_free (ptr_channel->window);
+ channel_free (server, ptr_channel);
+ gui_redraw_window_status (gui_current_window);
+ gui_redraw_window_input (gui_current_window);
+ return 0;
+ }
+ channel_name = CHANNEL(gui_current_window)->name;
+ pos_args = NULL;
+ }
+
+ if (pos_args)
+ server_sendf (server, "PART %s :%s\r\n", channel_name, pos_args);
+ else
+ server_sendf (server, "PART %s\r\n", channel_name);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_ping: ping a server
+ */
+
+int
+irc_cmd_send_ping (t_irc_server *server, int argc, char **argv)
+{
+ if (argc == 1)
+ server_sendf (server, "PING %s\r\n", argv[0]);
+ if (argc == 2)
+ server_sendf (server, "PING %s %s\r\n", argv[0],
+ argv[1]);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_pong: send pong answer to a daemon
+ */
+
+int
+irc_cmd_send_pong (t_irc_server *server, int argc, char **argv)
+{
+ if (argc == 1)
+ server_sendf (server, "PONG %s\r\n", argv[0]);
+ if (argc == 2)
+ server_sendf (server, "PONG %s %s\r\n", argv[0],
+ argv[1]);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_quit: disconnect from all servers and quit WeeChat
+ */
+
+int
+irc_cmd_send_quit (t_irc_server *server, char *arguments)
+{
+ if (server && server->is_connected)
+ {
+ if (arguments)
+ server_sendf (server, "QUIT :%s\r\n", arguments);
+ else
+ server_sendf (server, "QUIT\r\n");
+ }
+ quit_weechat = 1;
+ return 0;
+}
+
+/*
+ * irc_cmd_send_quote: send raw data to server
+ */
+
+int
+irc_cmd_send_quote (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "%s\r\n", arguments);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_rehash: tell the server to reload its config file
+ */
+
+int
+irc_cmd_send_rehash (t_irc_server *server, char *arguments)
+{
+ /* make gcc happy */
+ (void) arguments;
+
+ server_sendf (server, "REHASH\r\n");
+ return 0;
+}
+
+/*
+ * irc_cmd_send_restart: tell the server to restart itself
+ */
+
+int
+irc_cmd_send_restart (t_irc_server *server, char *arguments)
+{
+ /* make gcc happy */
+ (void) arguments;
+
+ server_sendf (server, "RESTART\r\n");
+ return 0;
+}
+
+/*
+ * irc_cmd_send_stats: query statistics about server
+ */
+
+int
+irc_cmd_send_stats (t_irc_server *server, char *arguments)
+{
+ if (arguments)
+ server_sendf (server, "STATS %s\r\n", arguments);
+ else
+ server_sendf (server, "STATS\r\n");
+ return 0;
+}
+
+/*
+ * irc_cmd_send_topic: get/set topic for a channel
+ */
+
+int
+irc_cmd_send_topic (t_irc_server *server, char *arguments)
+{
+ char *channel_name, *new_topic, *pos;
+
+ channel_name = NULL;
+ new_topic = NULL;
+
+ if (arguments)
+ {
+ if (string_is_channel (arguments))
+ {
+ channel_name = arguments;
+ pos = strchr (arguments, ' ');
+ if (pos)
+ {
+ pos[0] = '\0';
+ pos++;
+ while (pos[0] == ' ')
+ pos++;
+ new_topic = (pos[0]) ? pos : NULL;
+ }
+ }
+ else
+ new_topic = arguments;
+ }
+
+ /* look for current channel if not specified */
+ if (!channel_name)
+ {
+ if (WIN_IS_SERVER(gui_current_window))
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can not be executed on a server window\n"),
+ WEECHAT_ERROR, "topic");
+ return -1;
+ }
+ channel_name = CHANNEL(gui_current_window)->name;
+ }
+
+ if (new_topic)
+ {
+ if (strcmp (new_topic, "-delete") == 0)
+ server_sendf (server, "TOPIC %s :\r\n", channel_name);
+ else
+ server_sendf (server, "TOPIC %s :%s\r\n", channel_name, new_topic);
+ }
+ else
+ server_sendf (server, "TOPIC %s\r\n", channel_name);
+ return 0;
+}
+
+/*
+ * irc_cmd_send_version: gives the version info of nick or server (current or specified)
+ */
+
+int
+irc_cmd_send_version (t_irc_server *server, char *arguments)
+{
+ if (arguments)
+ {
+ if (WIN_IS_CHANNEL(gui_current_window) &&
+ nick_search (CHANNEL(gui_current_window), arguments))
+ server_sendf (server, "PRIVMSG %s :\01VERSION\01\r\n",
+ arguments);
+ else
+ server_sendf (server, "VERSION %s\r\n",
+ arguments);
+ }
+ else
+ {
+ irc_display_prefix (server->window, PREFIX_INFO);
+ gui_printf (server->window, _("%s, compiled on %s %s\n"),
+ WEECHAT_NAME_AND_VERSION,
+ __DATE__, __TIME__);
+ server_sendf (server, "VERSION\r\n");
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_voice: give voice to nickname(s)
+ */
+
+int
+irc_cmd_send_voice (t_irc_server *server, int argc, char **argv)
+{
+ int i;
+
+ if (WIN_IS_CHANNEL(gui_current_window))
+ {
+ for (i = 0; i < argc; i++)
+ server_sendf (server, "MODE %s +v %s\r\n",
+ CHANNEL(gui_current_window)->name,
+ argv[i]);
+ }
+ else
+ {
+ gui_printf (server->window,
+ _("%s \"%s\" command can only be executed in a channel window\n"),
+ WEECHAT_ERROR, "voice");
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * irc_cmd_send_whois: query information about user(s)
+ */
+
+int
+irc_cmd_send_whois (t_irc_server *server, char *arguments)
+{
+ server_sendf (server, "WHOIS %s\r\n", arguments);
+ return 0;
+}
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 41591045f..0dfa33ac4 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -212,6 +212,7 @@ extern int irc_cmd_send_quit (t_irc_server *, char *);
extern int irc_cmd_send_quote (t_irc_server *, char *);
extern int irc_cmd_send_rehash (t_irc_server *, char *);
extern int irc_cmd_send_restart (t_irc_server *, char *);
+extern int irc_cmd_send_stats (t_irc_server *, char *);
extern int irc_cmd_send_topic (t_irc_server *, char *);
extern int irc_cmd_send_version (t_irc_server *, char *);
extern int irc_cmd_send_voice (t_irc_server *, int, char **);