]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/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);
12 #include "../chanserv.h"
13 #include "../../nick/nick.h"
14 #include "../../lib/flags.h"
15 #include "../../lib/irc_string.h"
16 #include "../../channel/channel.h"
17 #include "../../parser/parser.h"
18 #include "../../irc/irc.h"
19 #include "../../localuser/localuserchannel.h"
20 #include "../../pqsql/pqsql.h"
26 void csc_dorollbackchan_real(PGconn
*dbconn
, void *arg
) {
27 nick
*np
=getnickbynumeric((unsigned long)arg
);
28 reguser
*rup
, *crup1
, *crup2
;
32 unsigned int userID
, channelID
, targetID
;
33 time_t changetime
, authtime
;
34 flag_t oldflags
, newflags
;
36 int i
, j
, num
, newuser
;
42 pgres
=PQgetResult(dbconn
);
44 if (PQresultStatus(pgres
) != PGRES_TUPLES_OK
) {
45 Error("chanserv", ERR_ERROR
, "Error loading chanlev history data.");
49 if (PQnfields(pgres
) != 7) {
50 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 for (i
=0; i
<num
; i
++) {
69 userID
=strtoul(PQgetvalue(pgres
, i
, 0), NULL
, 10);
70 channelID
=strtoul(PQgetvalue(pgres
, i
, 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(PQgetvalue(pgres
, i
, 2), NULL
, 10);
94 changetime
=strtoul(PQgetvalue(pgres
, i
, 3), NULL
, 10);
95 authtime
=strtoul(PQgetvalue(pgres
, i
, 4), NULL
, 10);
96 oldflags
=strtoul(PQgetvalue(pgres
, i
, 5), NULL
, 10);
97 newflags
=strtoul(PQgetvalue(pgres
, i
, 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 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 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
);