-- ctcp probe module
+local servicename = "cia!cia@cia.gov"
function commands.refreshctcp(client, source, command, args)
local flags = args[2] and tonumber(args[2]) or 3
if args[1] and args[1] ~= "*" then
- if flags&1 ~= 0 then client_privmsg(client_map[args[1]], "\1VERSION\1", "cia!cia@cia.gov") end
- if flags&2 ~= 0 then client_privmsg(client_map[args[1]], "\1TIME\1", "cia!cia@cia.gov") end
+ if flags&1 ~= 0 then client_privmsg(client_map[args[1]], "\1VERSION\1", servicename) end
+ if flags&2 ~= 0 then client_privmsg(client_map[args[1]], "\1TIME\1", servicename) end
else
for k, v in pairs(client_map) do
- if flags&1 ~= 0 then client_privmsg(v, "\1VERSION\1", "cia!cia@cia.gov") end
- if flags&2 ~= 0 then client_privmsg(v, "\1TIME\1", "cia!cia@cia.gov") end
+ if flags&1 ~= 0 then client_privmsg(v, "\1VERSION\1", servicename) end
+ if flags&2 ~= 0 then client_privmsg(v, "\1TIME\1", servicename) end
end
end
end
hook_add("newuser", "ctcp_probe", function(hook, cl1, cl2, chan, txt)
- client_privmsg(cl1, "\1VERSION\1", "cia!cia@cia.gov")
- -- TODO: a delay mechanism to avoid getting ratelimited
- client_privmsg(cl1, "\1TIME\1", "cia!cia@cia.gov")
+ client_privmsg(cl1, "\1VERSION\1", servicename)
+ client_data[cl1.key].ctcp_probe_wait = true
+end)
+hook_add("noticetoservice", "ctcp_logger", function(hook, cl1, cl2, chan, txt)
+ if txt:sub(1, 9) == "\1VERSION " then
+ client_data[cl1.key].ctcp_version = txt:sub(10, (txt:find("\1", 10, true) or 0)-1)
+ if client_data[cl1.key].ctcp_probe_wait then
+ client_data[cl1.key].ctcp_probe_wait = nil
+ client_privmsg(cl1, "\1TIME\1", servicename)
+ end
+ elseif txt:sub(1, 6) == "\1TIME " then
+ client_data[cl1.key].ctcp_time = string.format("%s (received on %s UTC)",
+ txt:sub(7, (txt:find("\1", 7, true) or 0)-1),
+ os.date("!%Y-%m-%d %H:%M:%S"))
+ end
+end)
+hook_add("whois", "ctcp_whois", function(hook, cl1, cl2, chan, txt)
+ if cl1.umode & 2 ~= 0 then -- UMODE_OPER
+ if client_data[cl2.key].ctcp_version then
+ rpl_whoisspecial(cl1, cl2, "CTCP VERSION: ".. client_data[cl2.key].ctcp_version)
+ end
+ if client_data[cl2.key].ctcp_time then
+ rpl_whoisspecial(cl1, cl2, "CTCP TIME: ".. client_data[cl2.key].ctcp_time)
+ end
+ end
end)
hook_setfold("nickadd", fold_sendtox)
hook_setfold("nickdel", fold_sendtox)
hook_setfold("nickchange", fold_sendtox)
+hook_setfold("privmsgtoservice", fold_sendtox)
+hook_setfold("noticetoservice", fold_sendtox)
+hook_setfold("whois", fold_sendtox)
if not client_data then
client_data = {}
end
string_getter(cl, away);
string_getter(cl, nick_reg);
/* string_getter(cl, pass_reg); */
- string_getter(cl, ctcp_version);
- string_getter(cl, ctcp_time);
string_getter(cl, peername);
integer_getter(cl, peerport);
/* buf/bufLen/wbuf/wbufLen */
client_chghost(cl, newusername, newhostname);
return 0;
}
+static int fn_rpl_whoisspecial(lua_State *L) {
+ struct client_data *cl1 = *(struct client_data **)luaL_checkudata(L, 1, "client");
+ struct client_data *cl2 = *(struct client_data **)luaL_checkudata(L, 2, "client");
+ const char *text = luaL_checkstring(L, 3);
+ rpl_whoisspecial(cl1, cl2, "", text), sendbuf(cl1);
+ return 0;
+}
void admin_init(void)
{
lua_setglobal(L, "channel_part");
lua_pushcfunction(L, fn_client_chghost);
lua_setglobal(L, "client_chghost");
+ lua_pushcfunction(L, fn_rpl_whoisspecial);
+ lua_setglobal(L, "rpl_whoisspecial");
}
void admin_fini(void)
{
char *away;
char *nick_reg;
char *pass_reg;
- char *ctcp_version;
- char *ctcp_time;
char *peername;
unsigned short peerport;
char buf[2048];
if (argc < 2)
return err_needmoreparams(client, command), sendbuf(client), 0;
client->lastactivity = get_time();
- if (command[0] == 'N' && !strcmp(args[0], "cia")) {
- // CTCP response logger
- if (!strncmp(args[1], "\1VERSION ", 9)) {
- args[1] += 9;
- char *p = strchr(args[1], '\1');
- if (p)
- *p = '\0';
- free(client->ctcp_version);
- client->ctcp_version = mystrdup(args[1]);
- if (!client->ctcp_version)
- abort();
- }
- if (!strncmp(args[1], "\1TIME ", 6)) {
- args[1] += 6;
- char *p = strchr(args[1], '\1');
- if (p)
- *p = '\0';
- free(client->ctcp_time);
- time_t current = get_time();
- char buf[20];
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", gmtime(¤t));
- client->ctcp_time = malloc(strlen(args[1])+sizeof(" (received on UTC)")+sizeof(buf));
- if (!client->ctcp_time)
- abort();
- sprintf(client->ctcp_time, "%s (received on %s UTC)", args[1], buf);
- }
+ if (!strcmp(args[0], "cia")) {
+#ifdef HAS_LUA
+ admin_hook(command[0] == 'P' ? "privmsgtoservice" : "noticetoservice", client, 0, 0, args[1]);
+#endif
return 0;
}
(command[0] == 'P' ? msg_privmsg : msg_notice)(client, args[0], args[1]);
rpl_whoisaccount(client, cl), sendbuf(client);
if (client == cl || client->umode & UMODE_OPER)
rpl_whoisactually(client, cl), sendbuf(client);
- if (cl->ctcp_version && client->umode & UMODE_OPER)
- rpl_whoisspecial(client, cl, "CTCP VERSION: ", cl->ctcp_version), sendbuf(client);
- if (cl->ctcp_time && client->umode & UMODE_OPER)
- rpl_whoisspecial(client, cl, "CTCP TIME: ", cl->ctcp_time), sendbuf(client);
rpl_whoismodes(client, cl), sendbuf(client);
if (cl->umode & UMODE_BOT)
rpl_whoisbot(client, cl), sendbuf(client);
+#ifdef HAS_LUA
+ admin_hook("whois", client, cl, 0, 0);
+#endif
rpl_endofwhois(client, cl), sendbuf(client);
} else {
err_nosuchnick(client, nick);
if (cl->pass_reg)
memset(cl->pass_reg, 0, strlen(cl->pass_reg));
free(cl->pass_reg);
- free(cl->ctcp_version);
- free(cl->ctcp_time);
free(cl->peername);
free(cl);
}