diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2003-10-12 17:03:38 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2003-10-12 17:03:38 +0000 |
commit | 836d7a139a0c60e66bd003bcce299f23065ca75a (patch) | |
tree | 797a9ea1fc5649932cefe34df595fd02d176afee /src | |
parent | c67cfeaa87ea30747c0dbfe1737b7ff43b12cf0e (diff) | |
download | weechat-836d7a139a0c60e66bd003bcce299f23065ca75a.zip |
Added CTCP Ping command (and display correctly when reply is received).
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/Makefile | 12 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 129 | ||||
-rw-r--r-- | src/irc/irc-send.c | 9 |
3 files changed, 120 insertions, 30 deletions
diff --git a/src/irc/Makefile b/src/irc/Makefile index 09ca6dc0d..245a59213 100644 --- a/src/irc/Makefile +++ b/src/irc/Makefile @@ -23,6 +23,18 @@ OUTPUT=irc.a 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 +ifeq ($(GUI), curses) +DEFINES=WEE_CURSES +endif +ifeq ($(GUI), gtk) +INCLUDES=`pkg-config --cflags gtk+-2.0` +DEFINES=WEE_GTK +endif +ifeq ($(GUI), qt) +DEFINES=WEE_QT +endif + + all: $(OBJS) ar r $(OUTPUT) $(OBJS) diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index e2ec08e6c..8ac1ea50a 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -28,6 +28,7 @@ #include <unistd.h> #include <stdio.h> #include <string.h> +#include <sys/time.h> #include <time.h> #include <sys/utsname.h> @@ -522,7 +523,10 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *arguments) int irc_cmd_recv_notice (t_irc_server *server, char *host, char *arguments) { - char *pos, *pos2; + char *pos, *pos2, *pos_usec; + struct timeval tv; + struct timezone tz; + long sec1, usec1, sec2, usec2, difftime; if (host) { @@ -548,13 +552,13 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *arguments) 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'; + irc_display_prefix (server->window, PREFIX_SERVER); 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")); @@ -562,7 +566,48 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *arguments) gui_printf_color (server->window, COLOR_WIN_CHAT, ": %s\n", pos); } else - gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", pos); + { + if (strncmp (pos, "\01PING", 5) == 0) + { + pos += 5; + while (pos[0] == ' ') + pos++; + pos_usec = strchr (pos, ' '); + if (pos_usec) + { + pos_usec[0] = '\0'; + pos_usec++; + pos2 = strchr (pos_usec, '\01'); + if (pos2) + { + pos2[0] = '\0'; + + gettimeofday (&tv, &tz); + sec1 = atol (pos); + usec1 = atol (pos_usec); + sec2 = tv.tv_sec; + usec2 = tv.tv_usec; + + difftime = ((sec2 * 1000000) + usec2) - ((sec1 * 1000000) + usec1); + + irc_display_prefix (server->window, PREFIX_SERVER); + gui_printf_color (server->window, COLOR_WIN_CHAT, "CTCP "); + gui_printf_color (server->window, COLOR_WIN_CHAT_CHANNEL, "PING "); + 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, + _(": %ld.%ld seconds\n"), + difftime / 1000000, + (difftime % 1000000) / 1000); + } + } + } + else + { + irc_display_prefix (server->window, PREFIX_SERVER); + gui_printf_color (server->window, COLOR_WIN_CHAT, "%s\n", pos); + } + } return 0; } @@ -784,6 +829,7 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments) if (pos[0] == ':') pos++; + /* version asked by another user => answer with WeeChat version */ if (strcmp (pos, "\01VERSION\01") == 0) { buf = (struct utsname *) malloc (sizeof (struct utsname)); @@ -808,38 +854,61 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments) } else { - /* private message received */ - ptr_channel = channel_search (server, host); - if (!ptr_channel) + /* ping request from another user => answer */ + if (strncmp (pos, "\01PING", 5) == 0) { - ptr_channel = channel_new (server, CHAT_PRIVATE, host); + pos += 5; + while (pos[0] == ' ') + pos++; + pos2 = strchr (pos, '\01'); + if (pos2) + pos2[0] = '\0'; + else + pos = NULL; + if (pos && !pos[0]) + pos = NULL; + if (pos) + server_sendf (server, "NOTICE %s :\01PING %s\01\r\n", + host, pos); + else + server_sendf (server, "NOTICE %s :\01PING\01\r\n", + host); + } + else + { + /* private message received => display it */ + ptr_channel = channel_search (server, host); if (!ptr_channel) { - gui_printf (server->window, - _("%s cannot create new private window \"%s\"\n"), - WEECHAT_ERROR, host); - return -1; + 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); } - 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 diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c index f27edbf72..c672f7fbb 100644 --- a/src/irc/irc-send.c +++ b/src/irc/irc-send.c @@ -28,6 +28,7 @@ #include <unistd.h> #include <stdio.h> #include <string.h> +#include <sys/time.h> #include <time.h> #include <sys/utsname.h> @@ -126,6 +127,8 @@ int irc_cmd_send_ctcp (t_irc_server *server, char *arguments) { char *pos, *pos2; + struct timeval tv; + struct timezone tz; pos = strchr (arguments, ' '); if (pos) @@ -163,6 +166,12 @@ irc_cmd_send_ctcp (t_irc_server *server, char *arguments) server_sendf (server, "PRIVMSG %s :\01ACTION\01\r\n", arguments); } + if (strcasecmp (pos, "ping") == 0) + { + gettimeofday (&tv, &tz); + server_sendf (server, "PRIVMSG %s :\01PING %d %d\01\r\n", + arguments, tv.tv_sec, tv.tv_usec); + } } return 0; |