]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chancmds/chanlevhistory.c
Fixed problem where you could set silly limits via CHANMODE which caused desync.
[irc/quakenet/newserv.git] / chanserv / chancmds / chanlevhistory.c
CommitLineData
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"
6b2ca929 23#include "../../pqsql/pqsql.h"
24
25#include <libpq-fe.h>
183b8e2f
P
26#include <string.h>
27#include <stdio.h>
28
6b2ca929 29void csdb_dochanlevhistory_real(PGconn *dbconn, void *arg) {
c54295ef 30 nick *np=getnickbynumeric((unsigned long)arg);
6b2ca929 31 reguser *rup, *crup1, *crup2;
32 unsigned int userID, channelID, targetID;
33 time_t changetime, authtime;
34 flag_t oldflags, newflags;
35 PGresult *pgres;
36 int i, num, count=0;
37 struct tm *tmp;
38 char tbuf[15], fbuf[18];
39
b3565978
CP
40 if(!dbconn) {
41 PQclear(pgres);
42 return;
43 }
44
6b2ca929 45 pgres=PQgetResult(dbconn);
46
47 if (PQresultStatus(pgres) != PGRES_TUPLES_OK) {
48 Error("chanserv", ERR_ERROR, "Error loading chanlev history data.");
49 return;
50 }
51
52 if (PQnfields(pgres) != 7) {
53 Error("chanserv", ERR_ERROR, "Chanlev history data format error.");
c34af51f 54 PQclear(pgres);
6b2ca929 55 return;
56 }
57 num=PQntuples(pgres);
58
59 if (!np) {
60 PQclear(pgres);
61 return;
62 }
63
64 if (!(rup=getreguserfromnick(np)) || !UHasHelperPriv(rup)) {
65 PQclear(pgres);
66 return;
67 }
68
69 chanservsendmessage(np, "Number: Time: Changing user: Changed user: Old flags: New flags:");
70 for (i=0; i<num; i++) {
71 userID=strtoul(PQgetvalue(pgres, i, 0), NULL, 10);
72 channelID=strtoul(PQgetvalue(pgres, i, 1), NULL, 10);
73 targetID=strtoul(PQgetvalue(pgres, i, 2), NULL, 10);
74 changetime=strtoul(PQgetvalue(pgres, i, 3), NULL, 10);
75 authtime=strtoul(PQgetvalue(pgres, i, 4), NULL, 10);
76 oldflags=strtoul(PQgetvalue(pgres, i, 5), NULL, 10);
77 newflags=strtoul(PQgetvalue(pgres, i, 6), NULL, 10);
78 tmp=localtime(&changetime);
79 strftime(tbuf, 15, "%d/%m/%y %H:%M", tmp);
80 strncpy(fbuf, printflags(oldflags, rcuflags), 17);
81 fbuf[17]='\0';
82 chanservsendmessage(np, "#%-6d %-15s %-15s %-15s %-15s %s", ++count, tbuf,
83 (crup1=findreguserbyID(userID))?crup1->username:"Unknown", (crup2=findreguserbyID(targetID))?crup2->username:"Unknown",
84 fbuf, printflags(newflags, rcuflags));
85 }
86 chanservstdmessage(np, QM_ENDOFLIST);
87
88 PQclear(pgres);
89}
90
91void csdb_retreivechanlevhistory(nick *np, regchan *rcp, time_t starttime) {
b3565978 92 q9c_asyncquery(csdb_dochanlevhistory_real, (void *)np->numeric,
6b2ca929 93 "SELECT userID, channelID, targetID, changetime, authtime, oldflags, newflags from chanlevhistory where "
94 "channelID=%u and changetime>%lu order by changetime desc limit 1000", rcp->ID, starttime);
95}
96
183b8e2f
P
97int csc_dochanlevhistory(void *source, int cargc, char **cargv) {
98 nick *sender=source;
99 chanindex *cip;
183b8e2f 100 regchan *rcp;
aa321230
P
101 unsigned long interval;
102
183b8e2f
P
103 if (cargc < 1) {
104 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "chanlevhistory");
105 return CMD_ERROR;
106 }
107
108 if (!(cip=cs_checkaccess(sender, cargv[0], 0, NULL, NULL, 0, 0)))
109 return CMD_ERROR;
110
111 rcp=(regchan*)cip->exts[chanservext];
112
113 if (cargc > 1)
aa321230 114 interval=durationtolong(cargv[1]);
183b8e2f 115 else
aa321230
P
116 interval=3600;
117
118 chanservstdmessage(sender, QM_SHOWINGDURATION, "chanlevhistory", longtoduration(interval,1));
119 csdb_retreivechanlevhistory(sender, rcp, getnettime()-interval);
183b8e2f
P
120
121 return CMD_OK;
122}