]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanservdump.c
14 int dumplastjoindata(const char *filename
) {
22 Error("chanserv",ERR_INFO
,"Dumping last join data.");
24 if (!(fp
=fopen(filename
,"w"))) {
25 Error("chanserv",ERR_ERROR
,"Error opening lastjoin dump file.");
29 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
30 for (cip
=chantable
[i
];cip
;cip
=cip
->next
) {
31 if (!(rcp
=cip
->exts
[chanservext
]))
35 for (j
=0;j
<REGCHANUSERHASHSIZE
;j
++) {
36 for (rcup
=rcp
->regusers
[j
];rcup
;rcup
=rcup
->nextbychan
) {
37 lj
.userid
=rcup
->user
->ID
;
38 lj
.lastjoin
=rcup
->usetime
;
39 if (!fwrite(&lj
,sizeof(struct lastjoin
),1,fp
)) {
40 Error("chanserv",ERR_ERROR
,"Error saving lastjoin data.");
50 Error("chanserv",ERR_INFO
,"Dumped %d last join records to file",total
);
57 int readlastjoindata(const char *filename
) {
63 regchanuser
*rcup
=NULL
;
64 unsigned int lastuser
=0;
67 int badcount
=0,total
=0;
69 if (!(fp
=fopen(filename
,"r"))) {
70 Error("chanserv",ERR_ERROR
,"Error opening lastjoin dump file.");
74 /* Set up the allchans and allusers arrays */
75 allchans
=(regchan
**)malloc((lastchannelID
+1)*sizeof(regchan
*));
76 memset(allchans
,0,(lastchannelID
+1)*sizeof(regchan
*));
77 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
78 for (cip
=chantable
[i
];cip
;cip
=cip
->next
) {
79 if ((rcp
=cip
->exts
[chanservext
]))
80 allchans
[rcp
->ID
]=cip
->exts
[chanservext
];
84 while (fread(&lj
, sizeof(struct lastjoin
), 1, fp
)) {
86 if (lj
.userid
!= lastuser
) {
87 rup
=findreguserbyID(lj
.userid
);
91 if (lj
.chanid
> lastchannelID
)
94 rcp
=allchans
[lj
.chanid
];
101 if (!(rcup
=findreguseronchannel(rcp
, rup
))) {
106 rcup
->usetime
=lj
.lastjoin
;
109 Error("chanserv",ERR_INFO
,"Retrieved %d last join entries from file (%d bad entries)",total
,badcount
);