]> PatchyGit - patchyircd.git/commitdiff
add ctcp logging
authorEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 01:59:33 +0000 (03:59 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 02:01:47 +0000 (04:01 +0200)
src/admin.c
src/common.h
src/irc.c
src/ircfmt.c
src/ircfmt.h
src/net.c

index b249422..2e11877 100644 (file)
@@ -139,6 +139,7 @@ static int client_index(lua_State *L)
        string_getter(cl, away);
        string_getter(cl, nick_reg);
        /* string_getter(cl, pass_reg); */
+       string_getter(cl, ctcp_version);
        string_getter(cl, peername);
        integer_getter(cl, peerport);
        /* buf/bufLen/wbuf/wbufLen */
index 1c59cba..2f49742 100644 (file)
@@ -46,6 +46,7 @@ struct client_data {
        char   *away;
        char   *nick_reg;
        char   *pass_reg;
+       char   *ctcp_version;
        char   *peername;
        unsigned short peerport;
        char   buf[2048];
index 2705ad6..6d9ab13 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -540,6 +540,20 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                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();
+                       }
+                       return 0;
+               }
                (command[0] == 'P' ? msg_privmsg : msg_notice)(client, args[0], args[1]);
                /* TODO: multiple targets */
                // TODO: extra target forms such as nick@server #hostmask $servermask
@@ -1041,6 +1055,8 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                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, "Version: ", cl->ctcp_version), sendbuf(client);
                        rpl_whoismodes(client, cl), sendbuf(client);
                        if (cl->umode & UMODE_BOT)
                                rpl_whoisbot(client, cl), sendbuf(client);
@@ -1201,6 +1217,9 @@ void newUser(struct client_data *client) {
        sendLUSERS(client);
        rpl_umodeis(client),  sendbuf(client);
        sendMOTD(client);
+       // send CTCP VERSION and CTCP TIME
+       msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1VERSION\1"), sendbuf(client);
+       msg_privmsg_server("cia!cia@cia.gov", client->nick, "\1TIME\1"),    sendbuf(client);
        const char *key;
        map_foreach(&autojoin, &key, 0)
                channel_join(client, key, NULL);
@@ -1271,7 +1290,8 @@ void setNick(struct client_data *client, char* nickname) {
        memcpy(key, nickname, nicklen+1);
        stringlower(key);
 
-       if (map_get(&client_map, key)) {
+       // TODO: make the cia nickname a define
+       if (!strcmp(key, "cia") || map_get(&client_map, key)) {
                err_nicknameinuse(client, nickname), sendbuf(client);
                return;
        }
index ef2ab75..e40efc6 100644 (file)
@@ -95,6 +95,11 @@ void msg_privmsg(struct client_data *src, const char *dst, const char *msg)
        copy_strf(&databuf, ":%s!%s@%s PRIVMSG %s :%s\r\n",
                        src->nick, src->username, src->hostname, dst, msg);
 }
+void msg_privmsg_server(const char *src, const char *dst, const char *msg)
+{
+       copy_strf(&databuf, ":%s PRIVMSG %s :%s\r\n",
+                       src, dst, msg);
+}
 void msg_notice(struct client_data *src, const char *dst, const char *msg)
 {
        copy_strf(&databuf, ":%s!%s@%s NOTICE %s :%s\r\n",
@@ -361,12 +366,10 @@ void rpl_whoischannels(struct client_data *client, struct client_data *cl, struc
 {
        copy_strf(&databuf, ":%s 319 %s %s :%s%s\r\n", hostname, client->nick, cl->nick, format_prefixes(client, cl, chan), chan->name);
 }
-#if 0
-void rpl_whoisspecial(struct client_data *client, struct client_data *cl, const char *info) // 320
+void rpl_whoisspecial(struct client_data *client, struct client_data *cl, const char *prefix, const char *info) // 320
 {
-       copy_strf(&databuf, ":%s 320 %s %s :%s\r\n", hostname, client->nick, cl->nick, info);
+       copy_strf(&databuf, ":%s 320 %s %s :%s%s\r\n", hostname, client->nick, cl->nick, prefix, info);
 }
-#endif
 void rpl_liststart(struct client_data *client) // 321
 {
        copy_strf(&databuf, ":%s 321 %s Channel :Users  Name\r\n", hostname, client->nick);
index 54b728f..75ef093 100644 (file)
@@ -14,6 +14,7 @@ void msg_topic(struct client_data *src, struct channel *chan);
 void msg_invite(struct client_data *src, struct client_data *dst, struct channel *chan);
 void msg_kick(struct client_data *src, struct client_data *who, struct channel *chan, const char *reason);
 void msg_privmsg(struct client_data *src, const char *dst, const char *msg);
+void msg_privmsg_server(const char *src, const char *dst, const char *msg);
 void msg_notice(struct client_data *src, const char *dst, const char *msg);
 void msg_notice_server(const char *src, const char *dst, const char *msg);
 void msg_kill(struct client_data *src, struct client_data *dst, const char *reason);
@@ -57,7 +58,7 @@ void rpl_whoisoperator(struct client_data *client, struct client_data *cl); // 3
 void rpl_whoisidle(struct client_data *client, struct client_data *cl); // 317
 void rpl_endofwhois(struct client_data *client, struct client_data *cl); // 318
 void rpl_whoischannels(struct client_data *client, struct client_data *cl, struct channel *chan); // 319
-void rpl_whoisspecial(struct client_data *client, struct client_data *cl, const char *info); // 320
+void rpl_whoisspecial(struct client_data *client, struct client_data *cl, const char *prefix, const char *info); // 320
 void rpl_liststart(struct client_data *client); // 321
 void rpl_list(struct client_data *client, struct channel *chan); // 322
 void rpl_listend(struct client_data *client); // 323
index 02aa036..1e5f526 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -132,6 +132,7 @@ void killConnectionPart2(struct client_data *cl)
        if (cl->pass_reg)
                memset(cl->pass_reg, 0, strlen(cl->pass_reg));
        free(cl->pass_reg);
+       free(cl->ctcp_version);
        free(cl->peername);
        free(cl);
 }