]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chancmds/chanlevhistory.c
Merge.
[irc/quakenet/newserv.git] / chanserv / chancmds / chanlevhistory.c
1 /* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: chanlevhistory
5 * CMDLEVEL: QCMD_HELPER
6 * CMDARGS: 2
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.
13 */
14
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"
24
25 #include <string.h>
26 #include <stdio.h>
27
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;
34 DBResult *pgres;
35 int count=0;
36 char tbuf[TIMELEN], fbuf[18];
37
38 if(!dbconn)
39 return;
40
41 pgres=dbgetresult(dbconn);
42
43 if (!dbquerysuccessful(pgres)) {
44 Error("chanserv", ERR_ERROR, "Error loading chanlev history data.");
45 dbclear(pgres);
46 return;
47 }
48
49 if (dbnumfields(pgres) != 7) {
50 Error("chanserv", ERR_ERROR, "Chanlev history data format error.");
51 dbclear(pgres);
52 return;
53 }
54
55 if (!np) {
56 dbclear(pgres);
57 return;
58 }
59
60 if (!(rup=getreguserfromnick(np)) || !UHasHelperPriv(rup)) {
61 dbclear(pgres);
62 return;
63 }
64
65 /* @TIMELEN */
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);
77 fbuf[17]='\0';
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 */
81 }
82 chanservstdmessage(np, QM_ENDOFLIST);
83
84 dbclear(pgres);
85 }
86
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);
91 }
92
93 int csc_dochanlevhistory(void *source, int cargc, char **cargv) {
94 nick *sender=source;
95 chanindex *cip;
96 regchan *rcp;
97 unsigned long interval;
98
99 if (cargc < 1) {
100 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "chanlevhistory");
101 return CMD_ERROR;
102 }
103
104 if (!(cip=cs_checkaccess(sender, cargv[0], 0, NULL, NULL, 0, 0)))
105 return CMD_ERROR;
106
107 rcp=(regchan*)cip->exts[chanservext];
108
109 if (cargc > 1)
110 interval=durationtolong(cargv[1]);
111 else
112 interval=3600;
113
114 chanservstdmessage(sender, QM_SHOWINGDURATION, "chanlevhistory", longtoduration(interval,1));
115 csdb_retreivechanlevhistory(sender, rcp, getnettime()-interval);
116
117 return CMD_OK;
118 }