]>
Commit | Line | Data |
---|---|---|
183b8e2f P |
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); | |
d6ee9055 | 10 | * CMDHELP: Usage: chanlevhistory <channel> [<duration>] |
94e4d2f4 | 11 | * CMDHELP: Shows you recent modifications to a channels user access entries. |
d6ee9055 | 12 | * CMDHELP: Default duration is one hour. |
183b8e2f P |
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" | |
ee8cd7d0 | 23 | #include "../../dbapi/dbapi.h" |
6b2ca929 | 24 | |
183b8e2f P |
25 | #include <string.h> |
26 | #include <stdio.h> | |
27 | ||
ee8cd7d0 | 28 | void csdb_dochanlevhistory_real(DBConn *dbconn, void *arg) { |
c54295ef | 29 | nick *np=getnickbynumeric((unsigned long)arg); |
6b2ca929 | 30 | reguser *rup, *crup1, *crup2; |
31 | unsigned int userID, channelID, targetID; | |
32 | time_t changetime, authtime; | |
33 | flag_t oldflags, newflags; | |
ee8cd7d0 CP |
34 | DBResult *pgres; |
35 | int count=0; | |
b7eebdcc | 36 | char tbuf[TIMELEN], fbuf[18]; |
6b2ca929 | 37 | |
09cb349b | 38 | if(!dbconn) |
b3565978 | 39 | return; |
b3565978 | 40 | |
ee8cd7d0 | 41 | pgres=dbgetresult(dbconn); |
6b2ca929 | 42 | |
ee8cd7d0 | 43 | if (!dbquerysuccessful(pgres)) { |
6b2ca929 | 44 | Error("chanserv", ERR_ERROR, "Error loading chanlev history data."); |
ee8cd7d0 | 45 | dbclear(pgres); |
6b2ca929 | 46 | return; |
47 | } | |
48 | ||
ee8cd7d0 | 49 | if (dbnumfields(pgres) != 7) { |
6b2ca929 | 50 | Error("chanserv", ERR_ERROR, "Chanlev history data format error."); |
ee8cd7d0 | 51 | dbclear(pgres); |
6b2ca929 | 52 | return; |
53 | } | |
6b2ca929 | 54 | |
55 | if (!np) { | |
ee8cd7d0 | 56 | dbclear(pgres); |
6b2ca929 | 57 | return; |
58 | } | |
59 | ||
60 | if (!(rup=getreguserfromnick(np)) || !UHasHelperPriv(rup)) { | |
ee8cd7d0 | 61 | dbclear(pgres); |
6b2ca929 | 62 | return; |
63 | } | |
64 | ||
b7eebdcc CP |
65 | /* @TIMELEN */ |
66 | chanservsendmessage(np, "Number: Time: Changing user: Changed user: Old flags: New flags:"); | |
ee8cd7d0 CP |
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); | |
b7eebdcc | 75 | q9strftime(tbuf, sizeof(tbuf), changetime); |
6b2ca929 | 76 | strncpy(fbuf, printflags(oldflags, rcuflags), 17); |
77 | fbuf[17]='\0'; | |
b7eebdcc | 78 | chanservsendmessage(np, "#%-6d %-19s %-15s %-15s %-15s %s", ++count, tbuf, |
6b2ca929 | 79 | (crup1=findreguserbyID(userID))?crup1->username:"Unknown", (crup2=findreguserbyID(targetID))?crup2->username:"Unknown", |
b7eebdcc | 80 | fbuf, printflags(newflags, rcuflags)); /* @TIMELEN */ |
6b2ca929 | 81 | } |
82 | chanservstdmessage(np, QM_ENDOFLIST); | |
83 | ||
ee8cd7d0 | 84 | dbclear(pgres); |
6b2ca929 | 85 | } |
86 | ||
87 | void csdb_retreivechanlevhistory(nick *np, regchan *rcp, time_t starttime) { | |
b3565978 | 88 | q9c_asyncquery(csdb_dochanlevhistory_real, (void *)np->numeric, |
522e2b8c | 89 | "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanserv.chanlevhistory where " |
6b2ca929 | 90 | "channelID=%u and changetime>%lu order by changetime desc limit 1000", rcp->ID, starttime); |
91 | } | |
92 | ||
183b8e2f P |
93 | int csc_dochanlevhistory(void *source, int cargc, char **cargv) { |
94 | nick *sender=source; | |
95 | chanindex *cip; | |
183b8e2f | 96 | regchan *rcp; |
aa321230 P |
97 | unsigned long interval; |
98 | ||
183b8e2f P |
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) | |
aa321230 | 110 | interval=durationtolong(cargv[1]); |
183b8e2f | 111 | else |
aa321230 P |
112 | interval=3600; |
113 | ||
114 | chanservstdmessage(sender, QM_SHOWINGDURATION, "chanlevhistory", longtoduration(interval,1)); | |
115 | csdb_retreivechanlevhistory(sender, rcp, getnettime()-interval); | |
183b8e2f P |
116 | |
117 | return CMD_OK; | |
118 | } |