#!/usr/bin/perl -w # # This code is copyright (c) $Date: 2003/03/24 18:18:23 $ by # Soenke J. Peters # and licensed under the GNU GPL version 2 # # $Id: emulestats.pl,v 1.10 2003/03/24 18:18:23 soenke Exp $ # # /emule print statistics from the onlinesig.dat file # ### use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); use File::Basename; my $version = '$Revision: 1.10 $'; if ($version =~ m/ ([\w\d\.]*) /) { $version=$1; } else { $version = "1.1"; } IRC::register("eMule Stats", "$version", "", ""); IRC::add_command_handler("emule", "emulestats_announce"); # make filesize human-readable sub txtbyte{ local($bytes)=@_; $bytes=abs($bytes); if ($bytes < 1024) { return sprintf "%.2f B", $bytes; } elsif ($bytes < 1024 ** 2) { return sprintf "%.2f KB", ($bytes / (1024.0)); } elsif ($bytes < 1024 ** 3) { return sprintf "%.2f MB", ($bytes / (1024.0 ** 2)); } elsif ($bytes < 1024 ** 4) { return sprintf "%.2f GB", ($bytes / (1024.0 ** 3)); } elsif ($bytes < 1024 ** 5) { return sprintf "%.2f TB", ($bytes / (1024.0 ** 4)); } else { return $bytes; } } my $emulereg; $emulereg=$Registry->{"HKEY_CLASSES_ROOT/ed2k/shell/open/command//"}; $emulereg =~ s/\"(.*?)\".*/$1/; $emulereg =~ tr/\\/\//; my $onlinesigpath = dirname($emulereg)."/onlinesig.dat"; my $preferencesinipath = dirname($emulereg)."/preferences.ini"; IRC::print("\n\002\0034eMule statistics $version loaded\n"); IRC::print("\002\0033 reading stats from $onlinesigpath\n"); IRC::print("\002\0033 /emule print statistics from the onlinesig.dat\n"); sub emulestats_announce { open(ONLINESIG, "$onlinesigpath") || return 1; foreach () { chomp $_; push @Onlinesig, $_; } close(ONLINESIG); ($emulestats_status, $emulestats_servername, $emulestats_serverip, $emulestats_serverport) = split(/\|/,$Onlinesig[0]); ($emulestats_downspeed, $emulestats_upspeed, $emulestats_queuesize) = split(/\|/,$Onlinesig[1]); open(PREFERENCESINI, "$preferencesinipath") || return 1; foreach () { if (m/TotalDownloadedBytes\s*\=\s*(\d+)/i) { $totaldlbytes=$1; $totaldlbytes++; } if (m/TotalUploadedBytes\s*\=\s*(\d+)/i) { $totalulbytes=$1; } $totaldl=&txtbyte($totaldlbytes); $totalul=&txtbyte($totalulbytes); } close(PREFERENCESINI); if ($emulestats_status==1) { # Be consistent and convert decimal commata in onlinesig to points... $emulestats_downspeed =~ tr/,/./; $emulestats_upspeed =~ tr/,/./; IRC::command("/me has his eMule connected to \'".$emulestats_servername."\' (ed2k://|server|".$emulestats_serverip."|".(int($emulestats_serverport)). "|/), currently downloading at ".$emulestats_downspeed." kB/s and uploading at ".$emulestats_upspeed. " kB/s with ".$emulestats_queuesize." clients in queue. Totally uploaded $totalul and downloaded $totaldl."); } else { IRC::command("/me is currently offline with his eMule"); } undef @Onlinesig; return 1; }