]> jfr.im git - irc/quakenet/newserv.git/blame - chandump/chandump.c
TRUSTS: require sqlite
[irc/quakenet/newserv.git] / chandump / chandump.c
CommitLineData
48a00760 1#include <stdio.h>
1a97df68 2#include <string.h>
48a00760
CP
3
4#include "../core/schedule.h"
5#include "../channel/channel.h"
87698d77
CP
6#include "../lib/version.h"
7
70b0a4e5 8MODULE_VERSION("");
48a00760
CP
9
10void *dumpsched;
11
12void dodump(void *arg) {
13 chanindex *c;
14 int i;
1a97df68
CP
15 nick *n;
16 char buf[512];
48a00760 17
98bf5864 18 FILE *fp = fopen("chandump/chandump.txt.1", "w");
48a00760
CP
19 if(!fp)
20 return;
21
c70c04a9
CP
22 fprintf(fp, "M T %lld\n", (unsigned long long)time(NULL));
23
48a00760
CP
24 for(i=0;i<CHANNELHASHSIZE;i++)
25 for(c=chantable[i];c;c=c->next)
26 if(c->channel && !IsSecret(c->channel))
1a97df68
CP
27 fprintf(fp, "C %s %d%s%s\n", c->name->content, c->channel->users->totalusers, (c->channel->topic&&c->channel->topic->content)?" ":"", (c->channel->topic&&c->channel->topic->content)?c->channel->topic->content:"");
28
29 for(i=0;i<NICKHASHSIZE;i++)
30 for(n=nicktable[i];n;n=n->next)
31 fprintf(fp, "N %s %s %s %s %s\n", n->nick, n->ident, strchr(visibleuserhost(n, buf), '@') + 1, (IsAccount(n) && n->authname) ? n->authname : "0", n->realname->name->content);
48a00760
CP
32
33 fclose(fp);
34
98bf5864 35 rename("chandump/chandump.txt.1", "chandump/chandump.txt");
48a00760
CP
36}
37
38void _init() {
1a97df68 39 dumpsched = (void *)schedulerecurring(time(NULL), 0, 60, &dodump, NULL);
48a00760
CP
40}
41
42void _fini() {
43 deleteschedule(dumpsched, &dodump, NULL);
44}