]>
jfr.im git - irc/quakenet/newserv.git/blob - clonehistogram/clonehistogram.c
3 #include "../control/control.h"
4 #include "../lib/irc_string.h"
5 #include "../localuser/localuserchannel.h"
6 #include "../lib/version.h"
10 int ch_clonehistogram ( void * source
, int cargc
, char ** cargv
);
11 int ch_chanhistogram ( void * source
, int cargc
, char ** cargv
);
17 registercontrolhelpcmd ( "clonehistogram" , NO_OPER
, 1 , ch_clonehistogram
, "Usage: clonehistogram <hostmask> \n Shows the distribution of user clone counts of a given mask." );
18 registercontrolhelpcmd ( "chanhistogram" , NO_OPER
, 1 , ch_chanhistogram
, "Usage: chanhistogram \n Shows the channel histogram." );
22 deregistercontrolcmd ( "clonehistogram" , ch_clonehistogram
);
23 deregistercontrolcmd ( "chanhistogram" , ch_chanhistogram
);
26 void histoutput ( nick
* np
, int clonecount
, int amount
, int total
) {
28 float percentage
= (( float ) amount
/ ( float ) total
) * 100 ;
31 memset ( max
, '#' , ( int )( percentage
/ 2 ));
32 max
[( int )( percentage
/ 2 )] = '\0' ;
34 controlreply ( np
, " %s%d %0 6.2f%% %s " , ( clonecount
< 1 )? ">" : "=" , abs ( clonecount
), percentage
, max
);
37 int ch_chanhistogram ( void * source
, int cargc
, char ** cargv
) {
38 nick
* np
= ( nick
*) source
;
40 int count
[ MAX_CHANS
+ 2 ], j
, n
, total
= 0 ;
42 memset ( count
, 0 , sizeof ( count
));
44 for ( j
= 0 ; j
< NICKHASHSIZE
; j
++) {
45 for ( np2
= nicktable
[ j
]; np2
; np2
= np2
-> next
) {
47 n
= np2
-> channels
-> cursi
;
49 count
[ MAX_CHANS
+ 1 ]++;
57 for ( j
= 1 ; j
<= MAX_CHANS
; j
++)
58 histoutput ( np
, j
, count
[ j
], total
);
60 histoutput ( np
, -( MAX_CHANS
+ 1 ), count
[ MAX_CHANS
+ 1 ], total
);
65 int ch_clonehistogram ( void * source
, int cargc
, char ** cargv
) {
66 nick
* np
= ( nick
*) source
;
67 int count
[ MAX_CLONES
+ 1 ], j
, total
= 0 , totalusers
= 0 ;
76 memset ( count
, 0 , sizeof ( count
));
78 for ( j
= 0 ; j
< HOSTHASHSIZE
; j
++)
79 for ( hp
= hosttable
[ j
]; hp
; hp
= hp
-> next
)
80 if ( match2strings ( pattern
, hp
-> name
-> content
)) {
82 totalusers
+= hp
-> clonecount
;
84 if ( hp
-> clonecount
&& ( hp
-> clonecount
> MAX_CLONES
)) {
87 count
[ hp
-> clonecount
]++;
92 controlreply ( np
, "No hosts matched." );
94 for ( j
= 1 ; j
<= MAX_CLONES
; j
++)
95 histoutput ( np
, j
, count
[ j
], total
);
97 histoutput ( np
, - MAX_CLONES
, count
[ 0 ], total
);
99 controlreply ( np
, " %d hosts/ %d users matched." , total
, totalusers
);
102 controlreply ( np
, "Done." );