]> jfr.im git - irc/quakenet/newserv.git/blame - nterface/nterfacer_chanstats.c
Disable kill.
[irc/quakenet/newserv.git] / nterface / nterfacer_chanstats.c
CommitLineData
504f62c7
CP
1/*
2 nterfacer newserv chanstats module
3 Copyright (C) 2004 Chris Porter.
4*/
5
6#include "../chanstats/chanstats.h"
16d29ce2 7#include "../core/error.h"
504f62c7
CP
8
9#include "library.h"
10#include "nterfacer_control.h"
11
12int handle_chanstats(struct rline *li, int argc, char **argv);
13struct handler *hl = NULL;
14
15void _init(void) {
16d29ce2
CP
16 if(!n_node) {
17 Error("nterfacer_chanstats", ERR_ERROR, "Unable to register chanstats as nterfacer_control isn't loaded!");
18 return;
19 }
504f62c7
CP
20 hl = register_handler(n_node, "chanstats", 1, handle_chanstats);
21}
22
23void _fini(void) {
24 if(hl)
25 deregister_handler(hl);
26}
27
28int handle_chanstats(struct rline *li, int argc, char **argv) {
29 chanstats *csp;
30 chanindex *cip;
31 int i,j,k,l;
32 int tot,emp;
33 int themax;
34 float details[13];
35
36 cip=findchanindex(argv[0]);
37
38 if (cip==NULL)
39 return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found");
40
41 csp=cip->exts[csext];
42
43 if (csp==NULL)
44 return ri_error(li, ERR_CHANSTATS_STATS_NOT_FOUND, "Stats not found");
45
46 if (uponehour==0) {
47 details[0] = -1;
48 details[1] = -1;
49 } else {
50 tot=0; emp=0;
51 for(i=0;i<SAMPLEHISTORY;i++) {
52 tot+=csp->lastsamples[i];
53 if (csp->lastsamples[i]==0) {
54 emp++;
55 }
56 }
57 details[0] = tot/SAMPLEHISTORY;
58 details[1] = emp/SAMPLEHISTORY * 100;
59
60 }
61
62 details[2] = csp->todayusers/todaysamples;
63 details[3] = ((float)(todaysamples-csp->todaysamples)/todaysamples)*100;
64 details[4] = csp->todaymax;
65
66 themax=csp->lastmax[0];
67
68 details[5] = csp->lastdays[0]/10;
69 details[6] = ((float)(lastdaysamples[0]-csp->lastdaysamples[0])/lastdaysamples[0])*100;
70 details[7] = themax;
71
72 /* 7-day average */
73 j=k=l=0;
74 for (i=0;i<7;i++) {
75 j+=csp->lastdays[i];
76 k+=csp->lastdaysamples[i];
77 l+=lastdaysamples[i];
78 if (csp->lastmax[i]>themax) {
79 themax=csp->lastmax[i];
80 }
81 }
82
83 details[8] = j/70;
84 details[9] = ((l-k)*100)/l;
85 details[10] = themax;
86
87 /* 14-day average: continuation of last loop */
88 for (;i<14;i++) {
89 j+=csp->lastdays[i];
90 k+=csp->lastdaysamples[i];
91 l+=lastdaysamples[i];
92 if (csp->lastmax[i]>themax) {
93 themax=csp->lastmax[i];
94 }
95 }
96
97 details[11] = j/140;
98 details[12] = ((l-k)*100)/l;
99 details[13] = themax;
100
101 ri_append(li, "%.1f", details[0]);
102 ri_append(li, "%.1f%%", details[1]);
103 for(j=2;j<14;) {
104 ri_append(li, "%.1f", details[j++]);
105 ri_append(li, "%.1f%%", details[j++]);
106 ri_append(li, "%d%%", details[j++]);
107 }
108
109 return ri_final(li);
110}