]>
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"
7 int ch_clonehistogram ( void * source
, int cargc
, char ** cargv
);
8 int ch_chanhistogram ( void * source
, int cargc
, char ** cargv
);
14 registercontrolhelpcmd ( "clonehistogram" , NO_OPER
, 1 , ch_clonehistogram
, "Usage: clonehistogram <hostmask> \n Shows the distribution of user clone counts of a given mask." );
15 registercontrolhelpcmd ( "chanhistogram" , NO_OPER
, 1 , ch_chanhistogram
, "Usage: chanhistogram \n Shows the channel histogram." );
19 deregistercontrolcmd ( "clonehistogram" , ch_clonehistogram
);
20 deregistercontrolcmd ( "chanhistogram" , ch_chanhistogram
);
23 void histoutput ( nick
* np
, int clonecount
, int amount
, int total
) {
25 float percentage
= (( float ) amount
/ ( float ) total
) * 100 ;
28 memset ( max
, '#' , ( int )( percentage
/ 2 ));
29 max
[( int )( percentage
/ 2 )] = '\0' ;
31 controlreply ( np
, " %s%d %0 6.2f%% %s " , ( clonecount
< 1 )? ">" : "=" , abs ( clonecount
), percentage
, max
);
34 int ch_chanhistogram ( void * source
, int cargc
, char ** cargv
) {
35 nick
* np
= ( nick
*) source
;
37 int count
[ MAX_CHANS
+ 2 ], j
, n
, total
= 0 ;
39 memset ( count
, 0 , sizeof ( count
));
41 for ( j
= 0 ; j
< NICKHASHSIZE
; j
++) {
42 for ( np2
= nicktable
[ j
]; np2
; np2
= np2
-> next
) {
44 n
= np2
-> channels
-> cursi
;
46 count
[ MAX_CHANS
+ 1 ]++;
54 for ( j
= 1 ; j
<= MAX_CHANS
; j
++)
55 histoutput ( np
, j
, count
[ j
], total
);
57 histoutput ( np
, -( MAX_CHANS
+ 1 ), count
[ MAX_CHANS
+ 1 ], total
);
62 int ch_clonehistogram ( void * source
, int cargc
, char ** cargv
) {
63 nick
* np
= ( nick
*) source
;
64 int count
[ MAX_CLONES
+ 1 ], j
, total
= 0 , totalusers
= 0 ;
73 memset ( count
, 0 , sizeof ( count
));
75 for ( j
= 0 ; j
< HOSTHASHSIZE
; j
++)
76 for ( hp
= hosttable
[ j
]; hp
; hp
= hp
-> next
)
77 if ( match2strings ( pattern
, hp
-> name
-> content
)) {
79 totalusers
+= hp
-> clonecount
;
81 if ( hp
-> clonecount
&& ( hp
-> clonecount
> MAX_CLONES
)) {
84 count
[ hp
-> clonecount
]++;
89 controlreply ( np
, "No hosts matched." );
91 for ( j
= 1 ; j
<= MAX_CLONES
; j
++)
92 histoutput ( np
, j
, count
[ j
], total
);
94 histoutput ( np
, - MAX_CLONES
, count
[ 0 ], total
);
96 controlreply ( np
, " %d hosts/ %d users matched." , total
, totalusers
);
99 controlreply ( np
, "Done." );