Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dcstop;
- use strict;
- use Log qw(error warning);
- use Globals;
- use Misc;
- my ($start,$now,$work,$dcPerHour);
- my @dcs;
- my $hooks = Plugins::addHooks(
- ['disconnected', \&dc],
- ['initialized', \&conf],
- );
- my $command = Commands::register(
- ['dcstop', 'dcstop command', \&cmddcstop],
- );
- Plugins::register("dcstop", "disconnect if dc/hour > x", \&unload);
- sub conf {
- if (!$config{dcstop_dcPerHour}) {
- Misc::configModify('dcstop_dcPerHour', '15');
- }
- if (!$config{dcstop_hours}) {
- Misc::configModify('dcstop_hours', '1');
- }
- }
- sub unload {
- Plugins::delHooks($hooks);
- Commands::unregister($command);
- }
- sub cmddcstop {
- my (undef, $args) = @_;
- if ($args eq "reset") {
- Log::warning("Resetting dc counter\n");
- ($start,$now,$work,$dcPerHour) = 0;
- undef @dcs;
- $start = time;
- } elsif (!$args or $args eq "info") {
- my $dc = scalar @dcs;
- Log::warning("dc Counter: ".$dc."\ndcPerHour Counter: ".$dcPerHour."\n");
- } else {
- Log::error("Unknown argument: ".$args."\n");
- }
- }
- sub dc {
- push(@dcs, time);
- $now = time;
- my $timelimit = ($now -($config{dcstop_hours} * 3600));
- while ($dcs[0] < $timelimit) {
- shift(@dcs);
- }
- my $dc = scalar @dcs;
- $start = $startTime_EXP;
- $work = (int($now - $start))/3600;
- $dcPerHour = int($dc/$work);
- if ($config{dcstop_dcPerHour} <= $dcPerHour) {
- Log::error("Disconnect per hour greater than ".$config{dcstop_dcPerHour}." : ".$dcPerHour."\n");
- Misc::offlineMode();
- ($dc,$start,$now,$work,$dcPerHour) = 0;
- $start = time;
- }
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment