]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/disabledcmds/rollbackchan.c
1 /* Automatically generated by refactor.pl.
4 * CMDNAME: rollbackchan
7 * CMDDESC: Roll back access changes on a channel.
8 * CMDFUNC: csc_dorollbackchan
9 * CMDPROTO: int csc_dorollbackchan(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: rollbackchan <channel> [<username>] <duration>
11 * CMDHELP: Reverts a channel's user access entries to a point in the past.
12 * CMDHELP: If username is specified only changes to that user will be made.
15 #include "../chanserv.h"
16 #include "../../nick/nick.h"
17 #include "../../lib/flags.h"
18 #include "../../lib/irc_string.h"
19 #include "../../channel/channel.h"
20 #include "../../parser/parser.h"
21 #include "../../irc/irc.h"
22 #include "../../localuser/localuserchannel.h"
23 #include "../../dbapi/dbapi.h"
28 void csc_dorollbackchan_real(DBConn
*dbconn
, void *arg
) {
29 nick
*np
=getnickbynumeric((unsigned long)arg
);
30 reguser
*rup
, *crup1
, *crup2
;
31 chanindex
*cip
= NULL
;
34 unsigned int userID
, channelID
, targetID
;
35 time_t changetime
, authtime
;
36 flag_t oldflags
, newflags
;
44 pgres
=dbgetresult(dbconn
);
46 if (!dbquerysuccessful(pgres
)) {
47 Error("chanserv", ERR_ERROR
, "Error loading chanlev history data.");
51 if (dbnumfields(pgres
) != 7) {
52 Error("chanserv", ERR_ERROR
, "Chanlev history data format error.");
58 Error("chanserv", ERR_ERROR
, "No nick pointer in rollback.");
62 if (!(rup
=getreguserfromnick(np
)) || !UHasOperPriv(rup
)) {
63 Error("chanserv", ERR_ERROR
, "No reguser pointer or oper privs in rollback.");
68 while(dbfetchrow(pgres
)) {
69 userID
=strtoul(dbgetvalue(pgres
, 0), NULL
, 10);
70 channelID
=strtoul(dbgetvalue(pgres
, 1), NULL
, 10);
73 for (j
=0; j
<CHANNELHASHSIZE
&& !rcp
; j
++) {
74 for (cip
=chantable
[j
]; cip
&& !rcp
; cip
=cip
->next
) {
75 if (!cip
->exts
[chanservext
])
78 if (((regchan
*)cip
->exts
[chanservext
])->ID
== channelID
)
79 rcp
=(regchan
*)cip
->exts
[chanservext
];
84 Error("chanserv", ERR_ERROR
, "No regchan pointer or oper privs in rollback.");
91 chanservsendmessage(np
, "Attempting to roll back %s:", cip
->name
->content
);
93 targetID
=strtoul(dbgetvalue(pgres
, 2), NULL
, 10);
94 changetime
=strtoul(dbgetvalue(pgres
, 3), NULL
, 10);
95 authtime
=strtoul(dbgetvalue(pgres
, 4), NULL
, 10);
96 oldflags
=strtoul(dbgetvalue(pgres
, 5), NULL
, 10);
97 newflags
=strtoul(dbgetvalue(pgres
, 6), NULL
, 10);
98 strncpy(fbuf
, printflags(newflags
, rcuflags
), 17);
100 crup1
=findreguserbyID(userID
);
101 crup2
=findreguserbyID(targetID
);
104 chanservsendmessage(np
, "Affected user (ID: %d) is no longer in database, continuing...", targetID
);
108 if (!(rcup
=findreguseronchannel(rcp
, crup2
))) {
109 rcup
=getregchanuser();
113 rcup
->changetime
=time(NULL
);
120 csdb_chanlevhistory_insert(rcp
, np
, rcup
->user
, rcup
->flags
, oldflags
);
121 rcup
->flags
=oldflags
;
122 chanservsendmessage(np
, "%s user flags for %s (%s -> %s)", newflags
?oldflags
?"Restoring":"Deleting":"Readding",
123 crup2
->username
, fbuf
, printflags(oldflags
, rcuflags
));
127 addregusertochannel(rcup
);
128 csdb_createchanuser(rcup
);
131 csdb_updatechanuser(rcup
);
135 csdb_deletechanuser(rcup
);
136 delreguserfromchannel(rcp
, crup2
);
139 freesstring(rcup
->info
);
140 freeregchanuser(rcup
);
143 for (j
=0; j
<REGCHANUSERHASHSIZE
; j
++)
144 if (rcp
->regusers
[j
])
147 if (j
==REGCHANUSERHASHSIZE
) {
148 cs_log(np
, "DELCHAN %s (Cleared chanlev from rollback)", cip
->name
->content
);
149 chanservsendmessage(np
, "Rollback cleared chanlev list, channel deleted.");
154 chanservstdmessage(np
, QM_DONE
);
159 void csdb_rollbackchanlevhistory(nick
*np
, regchan
*rcp
, reguser
* rup
, time_t starttime
) {
161 q9c_asyncquery(csc_dorollbackchan_real
, (void *)np
->numeric
,
162 "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanserv.chanlevhistory where "
163 "userID=%u and channelID=%u and changetime>%lu order by changetime desc limit 1000", rup
->ID
, rcp
->ID
, starttime
);
165 q9c_asyncquery(csc_dorollbackchan_real
, (void *)np
->numeric
,
166 "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanserv.chanlevhistory where "
167 "channelID=%u and changetime>%lu order by changetime desc limit 1000", rcp
->ID
, starttime
);
170 int csc_dorollbackchan(void *source
, int cargc
, char **cargv
) {
173 reguser
*rup
, *trup
=NULL
;
175 time_t starttime
=getnettime();
178 if (!(rup
=getreguserfromnick(sender
)))
182 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "rollbackchan");
186 if (!(cip
=cs_checkaccess(sender
, cargv
[0], 0, NULL
, NULL
, 0, 0)))
189 rcp
=(regchan
*)cip
->exts
[chanservext
];
192 duration
=durationtolong(cargv
[2]);
193 if (!(trup
=findreguser(sender
, cargv
[1])))
197 duration
=durationtolong(cargv
[1]);
200 chanservsendmessage(sender
, "Invalid duration.");
205 cs_log(sender
,"ROLLBACKCHAN %s #%s %s", cip
->name
->content
, rup
->username
, cargv
[1]);
207 csdb_rollbackchanlevhistory(sender
, rcp
, trup
, starttime
);