+sub countryStats {
+ if (exists $cache{countryStats}) {
+ &msg($who,"countrystats is already running!");
+ return;
+ }
+
+ if ($chan eq "") {
+ $chan = $_[0];
+ }
+
+ if ($chan eq "") {
+ &help("countrystats");
+ return;
+ }
+
+ $conn->who($chan);
+ $cache{countryStats}{chan} = $chan;
+ $cache{countryStats}{mtype} = $msgType;
+ $cache{countryStats}{who} = $who;
+ $cache{on_who_Hack} = 1;
+}
+
+sub do_countrystats {
+ $chan = $cache{countryStats}{chan};
+ $msgType = $cache{countryStats}{mtype};
+ $who = $cache{countryStats}{who};
+
+ my $total = 0;
+ my %cstats;
+ foreach (keys %{ $cache{nuhInfo} }) {
+ my $h = $cache{nuhInfo}{$_}{Host};
+
+ if ($h =~ /^.*\.(\D+)$/) { # host
+ $cstats{$1}++;
+ } else { # ip
+ $cstats{unresolve}++;
+ }
+ $total++;
+ }
+ my %count;
+ foreach (keys %cstats) {
+ $count{ $cstats{$_} }{$_} = 1;
+ }
+
+ my @list;
+ foreach (sort {$b <=> $a} keys %count) {
+ my $str = join(", ", sort keys %{ $count{$_} });
+# push(@list, "$str ($_)");
+ my $perc = sprintf("%.01f", 100 * $_ / $total);
+ $perc =~ s/\.0+$//;
+ push(@list, "$str ($_, $perc %)");
+ }
+
+ # todo: move this into a scheduler like nickometer
+ $msgType = "private";
+ &pSReply( &formListReply(0, "Country Stats ", @list) );
+
+ delete $cache{countryStats};
+ delete $cache{on_who_Hack};
+}