]>
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; | |
6b2ca929 | 36 | struct tm *tmp; |
37 | char tbuf[15], fbuf[18]; | |
38 | ||
09cb349b | 39 | if(!dbconn) |
b3565978 | 40 | return; |
b3565978 | 41 | |
ee8cd7d0 | 42 | pgres=dbgetresult(dbconn); |
6b2ca929 | 43 | |
ee8cd7d0 | 44 | if (!dbquerysuccessful(pgres)) { |
6b2ca929 | 45 | Error("chanserv", ERR_ERROR, "Error loading chanlev history data."); |
ee8cd7d0 | 46 | dbclear(pgres); |
6b2ca929 | 47 | return; |
48 | } | |
49 | ||
ee8cd7d0 | 50 | if (dbnumfields(pgres) != 7) { |
6b2ca929 | 51 | Error("chanserv", ERR_ERROR, "Chanlev history data format error."); |
ee8cd7d0 | 52 | dbclear(pgres); |
6b2ca929 | 53 | return; |
54 | } | |
6b2ca929 | 55 | |
56 | if (!np) { | |
ee8cd7d0 | 57 | dbclear(pgres); |
6b2ca929 | 58 | return; |
59 | } | |
60 | ||
61 | if (!(rup=getreguserfromnick(np)) || !UHasHelperPriv(rup)) { | |
ee8cd7d0 | 62 | dbclear(pgres); |
6b2ca929 | 63 | return; |
64 | } | |
65 | ||
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); | |
79313d98 CP |
75 | tmp=gmtime(&changetime); |
76 | strftime(tbuf, sizeof(tbuf), Q9_FORMAT_TIME, tmp); | |
6b2ca929 | 77 | strncpy(fbuf, printflags(oldflags, rcuflags), 17); |
78 | fbuf[17]='\0'; | |
79 | chanservsendmessage(np, "#%-6d %-15s %-15s %-15s %-15s %s", ++count, tbuf, | |
80 | (crup1=findreguserbyID(userID))?crup1->username:"Unknown", (crup2=findreguserbyID(targetID))?crup2->username:"Unknown", | |
81 | fbuf, printflags(newflags, rcuflags)); | |
82 | } | |
83 | chanservstdmessage(np, QM_ENDOFLIST); | |
84 | ||
ee8cd7d0 | 85 | dbclear(pgres); |
6b2ca929 | 86 | } |
87 | ||
88 | void csdb_retreivechanlevhistory(nick *np, regchan *rcp, time_t starttime) { | |
b3565978 | 89 | q9c_asyncquery(csdb_dochanlevhistory_real, (void *)np->numeric, |
522e2b8c | 90 | "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanserv.chanlevhistory where " |
6b2ca929 | 91 | "channelID=%u and changetime>%lu order by changetime desc limit 1000", rcp->ID, starttime); |
92 | } | |
93 | ||
183b8e2f P |
94 | int csc_dochanlevhistory(void *source, int cargc, char **cargv) { |
95 | nick *sender=source; | |
96 | chanindex *cip; | |
183b8e2f | 97 | regchan *rcp; |
aa321230 P |
98 | unsigned long interval; |
99 | ||
183b8e2f P |
100 | if (cargc < 1) { |
101 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "chanlevhistory"); | |
102 | return CMD_ERROR; | |
103 | } | |
104 | ||
105 | if (!(cip=cs_checkaccess(sender, cargv[0], 0, NULL, NULL, 0, 0))) | |
106 | return CMD_ERROR; | |
107 | ||
108 | rcp=(regchan*)cip->exts[chanservext]; | |
109 | ||
110 | if (cargc > 1) | |
aa321230 | 111 | interval=durationtolong(cargv[1]); |
183b8e2f | 112 | else |
aa321230 P |
113 | interval=3600; |
114 | ||
115 | chanservstdmessage(sender, QM_SHOWINGDURATION, "chanlevhistory", longtoduration(interval,1)); | |
116 | csdb_retreivechanlevhistory(sender, rcp, getnettime()-interval); | |
183b8e2f P |
117 | |
118 | return CMD_OK; | |
119 | } |