2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
fe-ctcp.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "module-formats.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include "levels.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "channels.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "queries.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "ignore.h"
|
|
|
|
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "window-items.h"
|
2000-10-28 16:14:19 -04:00
|
|
|
#include "printtext.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-07 14:42:59 -05:00
|
|
|
static void ctcp_default_msg(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-13 10:31:57 -05:00
|
|
|
const char *p;
|
|
|
|
char *cmd;
|
|
|
|
|
|
|
|
p = strchr(data, ' ');
|
|
|
|
if (p == NULL) {
|
|
|
|
cmd = g_strdup(data);
|
|
|
|
data = "";
|
|
|
|
} else {
|
|
|
|
cmd = g_strndup(data, (int) (p-data));
|
|
|
|
data = p+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
|
|
|
|
IRCTXT_CTCP_REQUESTED_UNKNOWN,
|
|
|
|
nick, addr, cmd, data, target);
|
|
|
|
g_free(cmd);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-07 14:42:59 -05:00
|
|
|
static void ctcp_ping_msg(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-13 10:31:57 -05:00
|
|
|
signal_emit("message irc ctcp", 6, server, "PING",
|
|
|
|
data, nick, addr, target);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-07 14:42:59 -05:00
|
|
|
static void ctcp_version_msg(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2002-02-13 10:31:57 -05:00
|
|
|
signal_emit("message irc ctcp", 6, server, "VERSION",
|
|
|
|
data, nick, addr, target);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-07 14:42:59 -05:00
|
|
|
static void ctcp_time_msg(IRC_SERVER_REC *server, const char *data,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-05-15 11:32:27 -04:00
|
|
|
{
|
2002-02-13 10:31:57 -05:00
|
|
|
signal_emit("message irc ctcp", 6, server, "TIME",
|
|
|
|
data, nick, addr, target);
|
2000-05-15 11:32:27 -04:00
|
|
|
}
|
|
|
|
|
2000-12-05 16:12:52 -05:00
|
|
|
static void ctcp_default_reply(IRC_SERVER_REC *server, const char *data,
|
2000-09-25 15:01:40 -04:00
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-07-10 19:00:56 -04:00
|
|
|
const char *ctcpdata;
|
|
|
|
char *ctcp, *ptr;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
2000-07-10 19:00:56 -04:00
|
|
|
ctcp = g_strdup(data);
|
|
|
|
ptr = strchr(ctcp, ' ');
|
|
|
|
if (ptr == NULL)
|
|
|
|
ctcpdata = "";
|
|
|
|
else {
|
|
|
|
*ptr = '\0';
|
|
|
|
ctcpdata = ptr+1;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
|
2001-01-07 14:42:59 -05:00
|
|
|
ischannel(*target) ? IRCTXT_CTCP_REPLY_CHANNEL :
|
|
|
|
IRCTXT_CTCP_REPLY, ctcp, nick, ctcpdata, target);
|
2000-07-10 19:00:56 -04:00
|
|
|
g_free(ctcp);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-12-05 16:12:52 -05:00
|
|
|
static void ctcp_ping_reply(IRC_SERVER_REC *server, const char *data,
|
2000-09-25 15:01:40 -04:00
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
GTimeVal tv, tv2;
|
|
|
|
long usecs;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
2002-02-15 11:24:53 -05:00
|
|
|
if (sscanf(data, "%ld %ld", &tv2.tv_sec, &tv2.tv_usec) < 1) {
|
2000-09-25 15:01:40 -04:00
|
|
|
char *tmp = g_strconcat("PING ", data, NULL);
|
2000-12-05 16:12:52 -05:00
|
|
|
ctcp_default_reply(server, tmp, nick, addr, target);
|
2000-09-25 15:01:40 -04:00
|
|
|
g_free(tmp);
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
2000-09-25 15:01:40 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_get_current_time(&tv);
|
|
|
|
usecs = get_timeval_diff(&tv, &tv2);
|
|
|
|
printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
|
|
|
|
IRCTXT_CTCP_PING_REPLY, nick, usecs/1000, usecs%1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fe_ctcp_init(void)
|
|
|
|
{
|
|
|
|
signal_add("default ctcp msg", (SIGNAL_FUNC) ctcp_default_msg);
|
|
|
|
signal_add("ctcp msg ping", (SIGNAL_FUNC) ctcp_ping_msg);
|
|
|
|
signal_add("ctcp msg version", (SIGNAL_FUNC) ctcp_version_msg);
|
2000-05-15 11:32:27 -04:00
|
|
|
signal_add("ctcp msg time", (SIGNAL_FUNC) ctcp_time_msg);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("default ctcp reply", (SIGNAL_FUNC) ctcp_default_reply);
|
|
|
|
signal_add("ctcp reply ping", (SIGNAL_FUNC) ctcp_ping_reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fe_ctcp_deinit(void)
|
|
|
|
{
|
|
|
|
signal_remove("default ctcp msg", (SIGNAL_FUNC) ctcp_default_msg);
|
|
|
|
signal_remove("ctcp msg ping", (SIGNAL_FUNC) ctcp_ping_msg);
|
|
|
|
signal_remove("ctcp msg version", (SIGNAL_FUNC) ctcp_version_msg);
|
2000-05-15 11:32:27 -04:00
|
|
|
signal_remove("ctcp msg time", (SIGNAL_FUNC) ctcp_time_msg);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("default ctcp reply", (SIGNAL_FUNC) ctcp_default_reply);
|
|
|
|
signal_remove("ctcp reply ping", (SIGNAL_FUNC) ctcp_ping_reply);
|
|
|
|
}
|