]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: chanstat | |
5 | * CMDLEVEL: QCMD_AUTHED | |
54afc439 | 6 | * CMDARGS: 2 |
1dd6d55d | 7 | * CMDDESC: Displays channel activity statistics. |
8 | * CMDFUNC: csc_dochanstat | |
9 | * CMDPROTO: int csc_dochanstat(void *source, int cargc, char **cargv); | |
54afc439 | 10 | * CMDHELP: Usage: CHANSTAT <channel> [RESET] |
1e32d528 | 11 | * CMDHELP: Shows some statistics about a channel, including total number of joins and |
12 | * CMDHELP: maximum channel size. Two sets of statistics are displayed, a lifetime | |
13 | * CMDHELP: counter, and a trip meter counter which can be reset. Where: | |
14 | * CMDHELP: channel - channel to display statistics for. | |
15 | * CMDHELP: CHANSTAT requires master (+m) access on the named channel. | |
1dd6d55d | 16 | */ |
17 | ||
18 | #include "../chanserv.h" | |
19 | #include "../../nick/nick.h" | |
20 | #include "../../lib/flags.h" | |
21 | #include "../../lib/irc_string.h" | |
22 | #include "../../channel/channel.h" | |
23 | #include "../../parser/parser.h" | |
24 | #include "../../irc/irc.h" | |
25 | #include "../../localuser/localuserchannel.h" | |
26 | #include <string.h> | |
27 | #include <stdio.h> | |
28 | ||
29 | int csc_dochanstat(void *source, int cargc, char **cargv) { | |
30 | nick *sender=source; | |
31 | chanindex *cip; | |
32 | regchan *rcp; | |
1dd6d55d | 33 | |
34 | if (cargc<1) { | |
35 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "chanstat"); | |
36 | return CMD_ERROR; | |
37 | } | |
38 | ||
39 | if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, | |
40 | NULL, "chanstat", QPRIV_VIEWFULLCHANLEV, 0))) | |
41 | return CMD_ERROR; | |
42 | ||
43 | rcp=cip->exts[chanservext]; | |
44 | ||
45 | chanservstdmessage(sender, QM_STATSHEADER, cip->name->content); | |
46 | ||
79313d98 | 47 | chanservstdmessage(sender, QM_STATSADDED, rcp->created); |
1dd6d55d | 48 | |
49 | /* Show opers founder/addedby/type info */ | |
50 | if (cs_privcheck(QPRIV_VIEWFULLCHANLEV, sender)) { | |
51 | reguser *founder=NULL, *addedby=NULL; | |
52 | ||
79313d98 | 53 | chanservstdmessage(sender, QM_STATSLASTACTIVE, rcp->lastactive); |
1dd6d55d | 54 | |
55 | addedby=findreguserbyID(rcp->addedby); | |
56 | chanservstdmessage(sender, QM_ADDEDBY, addedby ? addedby->username : "(unknown)"); | |
57 | founder=findreguserbyID(rcp->founder); | |
58 | chanservstdmessage(sender, QM_FOUNDER, founder ? founder->username : "(unknown)"); | |
59 | chanservstdmessage(sender, QM_CHANTYPE, chantypes[rcp->chantype]->content); | |
60 | } | |
61 | ||
79313d98 | 62 | chanservstdmessage(sender, QM_STATSJOINS, rcp->created, rcp->maxusers, rcp->totaljoins, |
1dd6d55d | 63 | (float)rcp->totaljoins/ ((time(NULL)-rcp->created)/(3600*24))); |
64 | ||
79313d98 | 65 | chanservstdmessage(sender, QM_STATSJOINS, rcp->statsreset, rcp->tripusers, rcp->tripjoins, |
1dd6d55d | 66 | (float)rcp->tripjoins / ((time(NULL)-rcp->statsreset)/(3600*24))); |
54afc439 | 67 | |
68 | if (cargc>1 && !ircd_strcmp(cargv[1],"reset")) { | |
917b9b2e CP |
69 | if (!(cip=cs_checkaccess(sender, cargv[0], CA_MASTERPRIV, |
70 | NULL, "chanstat", QPRIV_RESETCHANSTAT, 0))) | |
71 | return CMD_ERROR; | |
72 | ||
54afc439 | 73 | rcp->statsreset=time(NULL); |
74 | rcp->tripusers=0; | |
75 | rcp->tripjoins=0; | |
76 | chanservstdmessage(sender, QM_STATSRESET, cip->name->content); | |
77 | csdb_updatechannel(rcp); | |
78 | } | |
1dd6d55d | 79 | |
80 | return CMD_OK; | |
81 | } |