]> PatchyGit - patchyircd.git/commitdiff
add channel log
authorEgor <egor@patchysicp.xyz>
Sun, 8 May 2022 13:22:51 +0000 (16:22 +0300)
committerEgor <egor@patchysicp.xyz>
Sun, 8 May 2022 13:22:51 +0000 (16:22 +0300)
.gitignore
irc.c
main.c

index 2a49229..5c04fc5 100644 (file)
@@ -4,3 +4,4 @@ config.mk
 setpass
 ops.txt
 init.txt
+chanlog.txt
diff --git a/irc.c b/irc.c
index e1a9341..4e2fab0 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -12,6 +12,20 @@ const char *hostname = "irc.patchysicp.xyz";
 void sendbuf(struct client_data *client) {
        send_log(client->FD, databuf.buf, databuf.len, 0);
 }
+void chanlog_time(time_t timestamp) {
+       extern FILE *fchanlog;
+       if (fchanlog) {
+               fprintf(fchanlog, "$%lu %.*s", (unsigned long)timestamp, (int)databuf.len, databuf.buf);
+               fflush(fchanlog);
+       }
+}
+void chanlog() {
+       extern FILE *fchanlog;
+       if (fchanlog) {
+               fprintf(fchanlog, "%.*s", (int)databuf.len, databuf.buf);
+               fflush(fchanlog);
+       }
+}
 void sendbuf_chan(struct channel *chan) {
        struct trie_find *f = NULL;
        if (trie_findfirst(&f, &chan->members) == 1)
@@ -322,6 +336,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                chan->topic_when = get_time();
                        }
                        msg_topic(client, chan);
+                       chanlog_time(chan->topic_when);
                        sendbuf_chan(chan);
                }
        } else if(strcmp(command, "PRIVMSG") == 0 || strcmp(command, "NOTICE") == 0) {
@@ -499,32 +514,32 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                                        break;
                                                SETBIT(chan->dmode, DMODE_PERSIST, is_plus);
                                                MSG_CHANDMODE("P");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 'i':
                                                SETBIT(chan->dmode, DMODE_INVITEONLY, is_plus);
                                                MSG_CHANDMODE("i");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 'm':
                                                SETBIT(chan->dmode, DMODE_MODERATED, is_plus);
                                                MSG_CHANDMODE("m");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 'n':
                                                SETBIT(chan->dmode, DMODE_NOEXTERNAL, is_plus);
                                                MSG_CHANDMODE("n");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 's':
                                                SETBIT(chan->dmode, DMODE_SECRET, is_plus);
                                                MSG_CHANDMODE("s");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 't':
                                                SETBIT(chan->dmode, DMODE_TOPICPROT, is_plus);
                                                MSG_CHANDMODE("t");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 'l':
                                                if (is_plus) {
@@ -539,13 +554,13 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                                                copy_strf(&databuf, ":%s!%s@%s MODE %s +l %u\r\n",
                                                                                client->nick, client->username, client->hostname,
                                                                                chan->name, x);
-                                                               sendbuf_chan(chan);
+                                                               chanlog(), sendbuf_chan(chan);
                                                                argp++;
                                                        }
                                                } else {
                                                        chan->member_limit = -1;
                                                        MSG_CHANDMODE("l");
-                                                       sendbuf_chan(chan);
+                                                       chanlog(), sendbuf_chan(chan);
                                                }
                                                break;
                                        case 'k':
@@ -573,7 +588,7 @@ int processPacket(struct client_data *client, char *source, char *command, int a
                                                copy_strf(&databuf, ":%s!%s@%s MODE %s %sk %s\r\n",
                                                                client->nick, client->username, client->hostname,
                                                                chan->name, is_plus?"+":"-", is_plus?*argp:"*");
-                                               sendbuf_chan(chan);
+                                               chanlog(), sendbuf_chan(chan);
                                                break;
                                        case 'b':
                                        case 'e':
@@ -882,6 +897,7 @@ void channel_join(struct client_data *client, const char *channel, const char *c
        strcpy(key, channel);
        stringlower(key);
        struct channel *chan = trie_get(&channel_map, key);
+       int newchan = !chan;
        if (!chan) {
                chan = malloc(sizeof(struct channel));
                if (!chan) abort();
@@ -918,6 +934,8 @@ void channel_join(struct client_data *client, const char *channel, const char *c
        chan->member_count++;
        // send JOIN to everyone
        msg_join(client, chan);
+       if (newchan)
+               chanlog_time(chan->creation);
        sendbuf_chan(chan);
        // send topic
        channel_sendtopic(client, chan, 1);
diff --git a/main.c b/main.c
index e881143..0fc3814 100644 (file)
--- a/main.c
+++ b/main.c
@@ -79,7 +79,7 @@ fd_set readfds;
        struct sockaddr_in6 serverAddrV6;
        size_t serverAddrV6len;
 #endif
-
+FILE *fchanlog = NULL;
 int main() {
        int opt = 1;
        SOCKET serverSocketV4 = 0;
@@ -228,6 +228,8 @@ int main() {
                set_time(0);
                fclose(f);
        }
+       fchanlog = fopen("chanlog.txt", "ab");
+       fprintf(fchanlog, "$0 AAA :server starting %lu\r\n", (unsigned long)get_time());
 
        // Main loop
        while(is_running){