/[tcldrop]/tcldrop/modules/core.tcl
ViewVC logotype

Diff of /tcldrop/modules/core.tcl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by fireegl, Fri Nov 21 22:26:34 2003 UTC revision 1.20 by fireegl, Sat Nov 22 02:52:36 2003 UTC
# Line 52  namespace eval tcldrop { Line 52  namespace eval tcldrop {
52          variable Binds          variable Binds
53          variable Timers          variable Timers
54          variable TimerIDCount 1          variable TimerIDCount 1
55            variable Traffic
56            array set Traffic {}
57          # Export all the commands that should be available to 3rd-party scripters:          # Export all the commands that should be available to 3rd-party scripters:
58          namespace export bind unbind binds timer utimer killtimer killutimer timers utimers maskhost isbotnetnick logfile          namespace export bind unbind binds timer utimer killtimer killutimer timers utimers maskhost isbotnetnick logfile traffic
59  }  }
60    
61  # Add our modules directory to the package require search path:  # Add our modules directory to the package require search path:
# Line 478  proc ::tcldrop::maskhost {x} { Line 480  proc ::tcldrop::maskhost {x} {
480    
481  proc ::tcldrop::isbotnetnick {nick} { string equal -nocase $nick ${::botnet-nick} }  proc ::tcldrop::isbotnetnick {nick} { string equal -nocase $nick ${::botnet-nick} }
482    
483    proc ::tcldrop::traffic {{type {*}} {direction {}} {bytes {0}}} {
484            variable Traffic
485            if {$type != {*}} {
486                    if {[info exists Traffic($type)]} {
487                            # Set the info array to the current counts.
488                            array set info $Traffic($type)
489                    } else {
490                            # Initialize the counts.
491                            array set info [list total-in 0 total-out 0 daily-in 0 daily-out 0 restart [unixtime]]
492                    }
493                    # Increase the counters:
494                    if {($bytes) && ($direction == {in} || $direction == {out})} {
495                            array set info [list total-$direction [incr info(total-$direction) $bytes] daily-$direction [incr info(daily-$direction) $bytes]]
496                    }
497                    # See if 24 hours have elapsed, and if it has then clear the daily counts.
498                    if {[expr { [unixtime] - $info(restart) > 86400 }]} {
499                            array set info [list daily-in 0 daily-out 0 restart [unixtime]]
500                    }
501                    # Write the new counts back to the Traffic variable:
502                    set Traffic($type) [array get info]
503                    if {$direction == {in} || $direction == {out}} {
504                            # Return either in or out for $type:
505                            list $info(daily-$direction) $info(total-$direction)
506                    } else {
507                            # Return both directions for $type:
508                            list $info(daily-in) $info(total-in) $info(daily-out) $info(total-out)
509                    }
510            } else {
511                    # Show them all the traffic stats.
512                    set out [list]
513                    foreach t [array names Traffic] {
514                            array set info $Traffic($t)
515                            lappend out [list $t $info(daily-in) $info(total-in) $info(daily-out) $info(total-out)]
516                    }
517                    return $out
518            }
519    }
520    
521    
522  # Import the core tcldrop commands to the global namespace:  # Import the core tcldrop commands to the global namespace:
523  #namespace import -force {::tcldrop::*}  #namespace import -force {::tcldrop::*}
524  namespace import {::tcldrop::*}  namespace import {::tcldrop::*}

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26