1 /* Automatically generated by refactor.pl.
4 * CMDNAME: chanlevhistory
5 * CMDLEVEL: QCMD_HELPER
7 * CMDDESC: View user access changes on a channel.
8 * CMDFUNC: csc_dochanlevhistory
9 * CMDPROTO: int csc_dochanlevhistory(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: chanlevhistory <channel> [<duration>]
11 * CMDHELP: Shows you recent modifications to a channels user access entries.
12 * CMDHELP: Default duration is one hour.
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 csdb_dochanlevhistory_real(DBConn
*dbconn
, void *arg
) {
29 nick
*np
=getnickbynumeric((unsigned long)arg
);
30 reguser
*rup
, *crup1
, *crup2
;
31 unsigned int userID
, channelID
, targetID
;
32 time_t changetime
, authtime
;
33 flag_t oldflags
, newflags
;
36 char tbuf
[TIMELEN
], fbuf
[18];
41 pgres
=dbgetresult(dbconn
);
43 if (!dbquerysuccessful(pgres
)) {
44 Error("chanserv", ERR_ERROR
, "Error loading chanlev history data.");
49 if (dbnumfields(pgres
) != 7) {
50 Error("chanserv", ERR_ERROR
, "Chanlev history data format error.");
60 if (!(rup
=getreguserfromnick(np
)) || !UHasHelperPriv(rup
)) {
66 chanservsendmessage(np
, "Number: Time: Changing user: Changed user: Old flags: New flags:");
67 while(dbfetchrow(pgres
)) {
68 userID
=strtoul(dbgetvalue(pgres
, 0), NULL
, 10);
69 channelID
=strtoul(dbgetvalue(pgres
, 1), NULL
, 10);
70 targetID
=strtoul(dbgetvalue(pgres
, 2), NULL
, 10);
71 changetime
=strtoul(dbgetvalue(pgres
, 3), NULL
, 10);
72 authtime
=strtoul(dbgetvalue(pgres
, 4), NULL
, 10);
73 oldflags
=strtoul(dbgetvalue(pgres
, 5), NULL
, 10);
74 newflags
=strtoul(dbgetvalue(pgres
, 6), NULL
, 10);
75 q9strftime(tbuf
, sizeof(tbuf
), changetime
);
76 strncpy(fbuf
, printflags(oldflags
, rcuflags
), 17);
78 chanservsendmessage(np
, "#%-6d %-19s %-15s %-15s %-15s %s", ++count
, tbuf
,
79 (crup1
=findreguserbyID(userID
))?crup1
->username
:"Unknown", (crup2
=findreguserbyID(targetID
))?crup2
->username
:"Unknown",
80 fbuf
, printflags(newflags
, rcuflags
)); /* @TIMELEN */
82 chanservstdmessage(np
, QM_ENDOFLIST
);
87 void csdb_retreivechanlevhistory(nick
*np
, regchan
*rcp
, time_t starttime
) {
88 q9c_asyncquery(csdb_dochanlevhistory_real
, (void *)np
->numeric
,
89 "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanserv.chanlevhistory where "
90 "channelID=%u and changetime>%lu order by changetime desc limit 1000", rcp
->ID
, starttime
);
93 int csc_dochanlevhistory(void *source
, int cargc
, char **cargv
) {
97 unsigned long interval
;
100 chanservstdmessage(sender
, QM_NOTENOUGHPARAMS
, "chanlevhistory");
104 if (!(cip
=cs_checkaccess(sender
, cargv
[0], 0, NULL
, NULL
, 0, 0)))
107 rcp
=(regchan
*)cip
->exts
[chanservext
];
110 interval
=durationtolong(cargv
[1]);
114 chanservstdmessage(sender
, QM_SHOWINGDURATION
, "chanlevhistory", longtoduration(interval
,1));
115 csdb_retreivechanlevhistory(sender
, rcp
, getnettime()-interval
);