]> PatchyGit - patchyircd.git/commitdiff
add ctcp time logging
authorEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 03:21:16 +0000 (05:21 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 03:21:16 +0000 (05:21 +0200)
src/admin.c
src/common.h
src/irc.c
src/net.c

index 2e11877..e2b7a5b 100644 (file)
@@ -140,6 +140,7 @@ static int client_index(lua_State *L)
        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 */
index 2f49742..f2c73c9 100644 (file)
@@ -47,6 +47,7 @@ struct client_data {
        char   *nick_reg;
        char   *pass_reg;
        char   *ctcp_version;
+       char   *ctcp_time;
        char   *peername;
        unsigned short peerport;
        char   buf[2048];
index 1c0bc46..de7f133 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -549,6 +549,20 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                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(&current));
+                               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);
+                       }
                        return 0;
                }
                (command[0] == 'P' ? msg_privmsg : msg_notice)(client, args[0], args[1]);
@@ -1053,7 +1067,9 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                        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_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);
index 1e5f526..834baa5 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -133,6 +133,7 @@ void killConnectionPart2(struct client_data *cl)
                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);
 }