# shroudBNC - an object-oriented framework for IRC
# Copyright (C) 2005 Gunnar Beutner
#
# Version: 1.7e
#
# Modified by Khobbits
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

internalbind client sbnc:partyline
internalbind attach sbnc:partyattach
internalbind detach sbnc:partydetach
internalbind usrdelete sbnc:partysync
internalbind command sbnc:partycom
internalbind server sbnc:partychantypes 005
variable floodcheck

#######################################################################
#### Edit this line for any unpartable partyline channels you need ####
####### Oh and you will probably want to edit the default host. #######
#######################################################################

set ::partynopart [list ~kh]
set ::partyhost "sBNC.KHobbits.net"

if {[bncgetglobaltag partyline] == ""} {
# This is the default channel created if none exist
	bncsetglobaltag partyline [list ~kh]
}

#Number of lines to break before warning
set floodcheck(settings,lowcap) 20

#How many lines between warnings
set floodcheck(settings,period) 10

#Time period to log between
set floodcheck(settings,intime) 30

#######################################################################
###### You should not need to modify anything after this section ######
######### If you make any improvments please inform khobbits. #########
#######################################################################


set ::partyban(-sbnc,-sbnc) 1
set ::partyline [bncgetglobaltag partyline]

proc sbnc:partyline_add {channel} {
	if {[lsearch -exact $::partyline $channel] == -1} {
		lappend ::partyline $channel
		bncsetglobaltag partyline $::partyline
	}

	if {![info exists ::partytopic($channel)] || ![info exists ::partyts($channel)] || ![info exists ::partywho($channel)]} {
		set ::partytopic($channel) "shroudBNC Partyline"
		set ::partyts($channel) [unixtime]
		set ::partywho($channel) "-sBNC"
	}
}

foreach chan $::partyline {
	sbnc:partyline_add $chan
}

# work around some weird "feature" in mirc, which sends a /part for channels when the channel's prefix isn't in CHANTYPES
proc sbnc:partychantypes {client params} {
	if {[lindex $params 1] != 5} { return }
	set toks [lrange $params 3 end-1]
	set i 0
	while {$i < [llength $toks]} {
		set tok [split [lindex $toks $i] "="]
		if {[string equal -nocase [lindex $tok 0] "CHANTYPES"]} {
			if {[string first "~" [lindex $tok 1]] == -1} {
				incr i 3
				set chantypes "[lindex $tok 1]~"
				setisupport CHANTYPES $chantypes
				putclient ":[join [lrange [lreplace $params $i $i "CHANTYPES=$chantypes"] 0 end-1]] :[lindex $params end]"
				haltoutput
			}
		}
		incr i
	}
}

proc sbnc:partyline {client parameters} {
	global botnick botname server partyline partytopic partyts partywho partyban partyhost partynopart

	set thisctx [getctx 1]

	set cmd [lindex $parameters 0]
	set chan [string tolower [lindex $parameters 1]]
	set serv [lindex [split $server ":"] 0]
	set chans [split [string tolower [getbncuser $client tag partyline]] ","]

	if {[lsearch -exact [string tolower $partyline] $chan] == -1} {
		if [string match {-*} $chan] {
			flood $client $parameters
			sbnc:privateparty $client $parameters
		}
		return
	}
	haltoutput
	flood $client $parameters
	if {[string equal -nocase "join" $cmd]} {
		if {[info exists partyban($chan,$client)]} {
			putclient ":$serv 484 $botnick $chan :Cannot join channel (You have been banned, repeated attempts to join will get you punished.)"
			sbnc:bcpartybutone $client ":-sBNC!user@$partyhost PRIVMSG $chan :User -$client attempted to join $chan, but is banned."
		} else {
			if {[lsearch $chans $chan] == -1} {
				lappend chans $chan
				setbncuser $client tag partyline [join $chans ","]

				set oldctx [getctx 1]
				setctx [getctx]
				putclient ":$botname JOIN $chan"
				setctx $oldctx

				sbnc:partyline $client "NAMES $chan"
				sbnc:partyline $client "TOPIC $chan"

				sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost JOIN $chan"

				if {[getbncuser $client admin] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +o $botnick"
					sbnc:bcpartybutone $thisctx ":-sBNC!core@shroudbnc.org MODE $chan +o -$client"
				} elseif {[getbncuser $client tag reseller] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +v $botnick"
					sbnc:bcpartybutone $thisctx ":-sBNC!core@shroudbnc.org MODE $chan +v -$client"
				}
			} else {
				set oldctx [getctx 1]
				setctx [getctx]
				putclient ":$botname JOIN $chan"
				setctx $oldctx
				sbnc:partyline $client "NAMES $chan"
				sbnc:partyline $client "TOPIC $chan"
				if {[getbncuser $client admin] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +o $botnick"
				} elseif {[getbncuser $client tag reseller] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +v $botnick"
				}
			}
		}
	}

	if {[string equal -nocase "part" $cmd]} {
		set idx [lsearch $chans $chan]

		if {$idx != -1 && [lsearch $partynopart $chan] == -1} {
			setbncuser $client tag partyline [join [lreplace $chans $idx $idx] ","]

			set oldctx [getctx]
			setctx [getctx 0]
			putclient ":$botname PART $chan"
			setctx $oldctx

			sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost PART $chan"
		}
	}


	if {[string equal -nocase "names" $cmd]} {
		set idents "@-sBNC @Any-Abuse/Spam @Risks-Your-BNC"
		foreach user [bncuserlist] {
			if {[lsearch [split [string tolower [getbncuser $user tag partyline]] ","] $chan] != -1 && [getbncuser $user hasclient]} {
				if {[getbncuser $user admin] == 1} {
					set acc "@"
				} elseif {[getbncuser $user tag reseller] == 1} {
					set acc "+"
				} else {
					set acc ""
				}
				if {$client == $user} {
					lappend idents "$acc$botnick"
				} else {
					lappend idents "$acc\-$user"
				}
			}
		}

		putclient ":$serv 353 $botnick @ $chan :[join $idents]"
		putclient ":$serv 366 $botnick $chan :End of /NAMES list."
	}

	if {[string equal -nocase "mode" $cmd]} {
		if {[llength $parameters] < 3} {
			putclient ":$serv 324 $botnick $chan +n"
			putclient ":$serv 329 $botnick $chan 0"
		} elseif {[lindex $parameters 2] == "+b"} {
			putclient ":$serv 368 $botnick $chan :End of Channel Ban List"
		} else {
			putclient ":$serv 482 $botnick $chan :You can't change modes on $chan"
		}
	}

	if {[string equal -nocase "topic" $cmd]} {
		if {[llength $parameters] < 3} {
			putclient ":$serv 332 $botnick $chan :$partytopic($chan)"
			putclient ":$serv 333 $botnick $chan $partywho($chan) $partyts($chan)"
		} else {
			set partytopic($chan) [lindex $parameters 2]
			set partyts($chan) [unixtime]
			set partywho($chan) "-$client"
			sbnc:bcparty ":-$client!user@$partyhost TOPIC $chan :$partytopic($chan)"
		}
	}

	if {[string equal -nocase "kick" $cmd]} {
		if {[llength $parameters] < 3} {
			putclient ":$serv 461 $botnick KICK :Not enough parameters"
		} elseif {[getbncuser $client admin] == 1} {
			partyline "[string trimleft [lindex $parameters 2] {-}] kick [lindex $parameters 1]"
		} else {
			putclient ":$serv 482 $botnick $chan :You can't kick users from $chan"
			if {[lsearch $partynopart $chan] == -1} {
				set idx [lsearch $chans [string tolower $chan]]
				if {$idx != -1} {
					setbncuser $client tag partyline [join [lreplace $chans $idx $idx] ","]
					putclient ":$botnick!user@$partyhost KICK $chan $botnick :You kicked yourself."
					sbnc:bcpartybutone $thisctx ":-$client!noob@$partyhost KICK $chan -$client :I am noob, watch me kick myself."
				}
			} else {
				putclient ":$botnick!user@$partyhost KICK $chan $botnick :You kicked yourself."
				sbnc:bcpartybutone $thisctx ":-$client!noob@$partyhost KICK $chan -$client :I am noob, watch me kick myself."
				sbnc:partyline $client "join $chan 1"
			}
		}
	}

	if {[string equal -nocase "privmsg" $cmd]} {
		if {[llength $parameters] < 3} {
			putclient ":$serv 461 $botnick PRIVMSG :Not enough parameters"
		} else {
			if {[lsearch [split [string tolower [getbncuser $client tag partyline]] ","] $chan] != -1} {
				sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost PRIVMSG $chan :[lindex $parameters 2]"
			} else {
				putclient ":$serv 404 $botnick $chan :Cannot send to channel"
			}
		}
	}
	if {[string equal -nocase "notice" $cmd]} {
		if {[llength $parameters] < 3} {
			putclient ":$serv 461 $botnick NOTICE :Not enough parameters"
		} else {
			if {[lsearch [split [string tolower [getbncuser $client tag partyline]] ","] $chan] != -1} {
				sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost NOTICE $chan :[lindex $parameters 2]"
			} else {
				putclient ":$serv 404 $botnick $chan :Cannot send to channel"
			}
		}
	}
}

proc sbnc:bcparty {text} {
	set chan [lindex [split $text] 2]

	foreach user [bncuserlist] {
		set chans [split [string tolower [getbncuser $user tag partyline]] ","]

		if {[lsearch $chans $chan] != -1} {
			setctx $user
			putclient "$text"
		}
	}
}

proc sbnc:bcpartybutone {clientctx text} {
	set chan [string tolower [lindex [split $text] 2]]

	setctx $clientctx
	set clientname [getctx]

	global botnick
	foreach user [bncuserlist] {
		set chans [split [string tolower [getbncuser $user tag partyline]] ","]

		if {[lsearch $chans $chan] == -1} {
			continue
		}

		if {[string equal -nocase $clientname $user]} {
			foreach session [getbncuser $clientname sessions] {
				if {![string equal -nocase $clientctx $session]} {
					setctx $session
					putclient [string map "{-$clientname} {$botnick}" $text]
				}
			}
		} else {
			setctx $user
			putclient "$text"
		}
	}
	setctx $clientctx
}

proc sbnc:bcpartyone {client nick text} {

	setctx $nick
	putclient "$text"
	setctx $client
}

proc sbnc:partyattach {client} {
	global botnick botname partyline server partyhost
	set chans [split [string tolower [getbncuser $client tag partyline]] ","]

	set thisctx [getctx 1]
	putclient ":[lindex [split $server ":"] 0] 005 $botnick CHANTYPES=[getisupport chantypes]~ :are supported by this server."
	foreach chan $partyline {
		if {[lsearch $chans [string tolower $chan]] != -1} {
			setctx $thisctx
			putclient ":$botname JOIN $chan"
			sbnc:partyline $client "NAMES $chan"
			sbnc:partyline $client "TOPIC $chan"

			if {[getbncuser $client clientcount] == 1} {
				sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost JOIN $chan"
				if {[getbncuser $client admin] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +o $botnick"
					sbnc:bcpartybutone $thisctx ":-sBNC!core@shroudbnc.org MODE $chan +o -$client"
				} elseif {[getbncuser $client tag reseller] == 1} {
					putclient ":-sBNC!core@shroudbnc.org MODE $chan +v $botnick"
					sbnc:bcpartybutone $thisctx ":-sBNC!core@shroudbnc.org MODE $chan +v -$client"
				}
			}
		}
	}
}

proc sbnc:partydetach {client} {
	global partyline partyhost
	set chans [split [string tolower [getbncuser $client tag partyline]] ","]
	set thisctx [getctx 1]
	foreach chan $partyline {
		if {[lsearch $chans [string tolower $chan]] != -1 && [getbncuser $client clientcount] == 0} {
			sbnc:bcpartybutone $thisctx ":-$client!user@$partyhost PART $chan :Disconnected from BNC"
		}
	}
}

proc sbnc:partysync {client} {
	global partyline partyhost

	set chans [split [string tolower [getbncuser $client tag partyline]] ","]

	foreach chan $partyline {
		if {[lsearch $chans [string tolower $chan]] != -1} {
			sbnc:bcparty $client ":-$client!user@$partyhost PART $chan :Removing user"
		}
	}
}

proc sbnc:privateparty {client parameters} {
	global botnick botname server partyline partytopic partyts partywho partyhost
	set thisctx [getctx 1]
	if {![string match {-*} [lindex $parameters 1]]} {
		return
	}
	set cmd [lindex $parameters 0]
	if {[string tolower [lindex $parameters 1]] != {--}} {
		set nick [string tolower [string trimleft [lindex $parameters 1] {-}]]
		if {[string tolower $nick] == "sbnc"} { return }
	} else {
		set nick {--}
	}

	set serv [lindex [split $server ":"] 0]

	if {[string equal -nocase "privmsg" $cmd]} {
	haltoutput
		if {[llength $parameters] < 3} {
			putclient ":$serv 461 $botnick PRIVMSG :Not enough parameters"
		} else {
			if {$nick == {--}} {
				foreach user [bncuserlist] {
						sbnc:privateparty $client "$cmd -$user {[lindex $parameters 2]}"
				}
				setctx $thisctx
			} elseif {[lsearch [string tolower [bncuserlist]] $nick] != -1} {

				if {![getbncuser $nick hasclient]} {
					putclient ":$serv 301 $botnick -$nick :Disconnected from BNC"
					setctx $nick
					putlog "-$client (Partyline): [lindex $parameters 2]"
					setctx $thisctx
				} else {
					sbnc:bcpartyone $thisctx $nick ":-$client!user@$partyhost PRIVMSG $nick :[lindex $parameters 2]"
				}
			} elseif {[string match #* $nick ] != 0} {
			set chan [string tolower [string trimleft [lindex $parameters 1] {-}]]
			set network [getisupport NETWORK]
				foreach x [bncuserlist] {
					   if { [getbncuser $x hasclient] } {
						set user_channel_list [split [string tolower [getbncuser $x channels]] {,}]
						setctx $x
						if {[lsearch $user_channel_list $chan] != -1 && [string match $network [getisupport NETWORK]] == 1} {
							putclient ":-$client!user@$partyhost PRIVMSG $chan :[lindex $parameters 2]"
						}
						setctx $client
					}
				}
			} else {
				putclient ":$serv 401 $botnick $nick :No such user on the BNC"
			}
		}
	}
	if {[string equal -nocase "notice" $cmd]} {
	haltoutput
		if {[llength $parameters] < 3} {
			putclient ":$serv 411 $botnick :Not enough parameters"
		} else {
			if {$nick == {--}} {
				foreach user [bncuserlist] {
						sbnc:privateparty $client "$cmd -$user {[lindex $parameters 2]}"
				}
				setctx $thisctx
			} elseif {[lsearch [string tolower [bncuserlist]] $nick] != -1} {
				if {![getbncuser $nick hasclient]} {
					putclient ":$serv 301 $botnick -$nick :Disconnected from BNC"
					setctx $nick
					putlog "-$client (Partyline:Notice): [lindex $parameters 2]"
					setctx $thisctx
				} else {
					sbnc:bcpartyone $thisctx $nick ":-$client!user@$partyhost NOTICE $nick :[lindex $parameters 2]"
				}
			} elseif {[string match #* $nick ] != 0} {
				set chan [string tolower [string trimleft [lindex $parameters 1] {-}]]
				set network [getisupport NETWORK]
				foreach x [bncuserlist] {
					   if { [getbncuser $x hasclient] } {
						set user_channel_list [split [string tolower [getbncuser $x channels]] {,}]
						setctx $x
						if {[lsearch $user_channel_list $chan] != -1 && [string match $network [getisupport NETWORK]] == 1} {
							putclient ":-$client!user@$partyhost NOTICE $chan :[lindex $parameters 2]"
						}
						setctx $thisctx
					}
				}
			} else {
				putclient ":$serv 401 $botnick $nick :No such user on the BNC"
			}
		}
	}
	if {[string equal -nocase "whois" $cmd]} {
		haltoutput
		if {[llength $parameters] < 2} {
			putclient ":$serv 431 $botnick :No nickname given"
		} else {
			if {$nick == {--}} {
				foreach user [bncuserlist] {
						sbnc:privateparty $client "$cmd -$user {[lindex $parameters 2]}"
				}
				setctx $thisctx
			} elseif {[lsearch [string tolower [bncuserlist]] $nick] != -1} {
				putclient ":$serv 311 $botnick -$nick user $partyhost * :[getbncuser $nick realname]"
				if {[info procs vhost:ip2host] == "vhost:ip2host"} {
					putclient ":$serv 378 $botnick -$nick :is connecting from [vhost:ip2host [getbncuser $nick vhost]] [getbncuser $nick vhost]"
				} else {
					putclient ":$serv 378 $botnick -$nick :is connecting from [getbncuser $nick vhost]"
				}

				putclient ":$serv 319 $botnick -$nick :[split [getbncuser $nick tag partyline] ,]"
				putclient ":$serv 312 $botnick -$nick $partyhost :KH BNC - Shroudbnc based goodness"
				if {![getbncuser $nick hasclient]} {
					putclient ":$serv 301 $botnick -$nick :Disconnected from BNC"
				}
				if {[getbncuser $nick tag reseller] == "1"} {
					putclient ":$serv 310 $botnick -$nick :is a BNC Virtual Admin"
				}
				if {[getbncuser $nick admin] == 1} {
					putclient ":$serv 313 $botnick -$nick :is an IRC Operator - BNC Admin"
				}
				putclient ":$serv 307 $botnick -$nick :IRC nickname is [getbncuser $nick nick]"
				putclient ":$serv 317 $botnick -$nick :[getbncuser $nick uptime] [getbncuser $nick seen] :seconds connected, last bnc login"

				putclient ":$serv 318 $botnick -$nick :End of /WHOIS list."

			} else {
				putclient ":$serv 401 $botnick -$nick :No such user on the BNC"
			}
		}
	}
}

proc sbnc:partycom {client parameters} {
	set command [lindex $parameters 0]
	if {[string equal -nocase $command "help"]} {
		if {[getbncuser $client admin]} {
			set help "Syntax: partyline <command> \[values/params\]\n
				Commands:
				join <user> <chan> - same as the user typing /join <chan>
				part <user> <chan> - same as the user typing /part <chan>
				set <user> <chan1,chan2,chan3> - sets the partyline channels the user is on
				show <user> - lists the partyline channels the user is on
				kick <user> <chan> - kicks this user from the partyline channel
				ban <user> <chan> - prevents a user from rejoining the channel
				unban <user> <chan> - undoes the above action
				add <chan> - adds a partyline channel (not user related)
				del <chan> - removes a partyline channel
				list - lists the active partyline channels
				sync - Removes disconnected users from the partyline"

			bncaddcommand "partyline" "KHAdmin" "Allows the admin of the partyline channels" $help
			bncaddcommand "mpartyline" "KHAdmin" "Allows mass admin of the partyline channels" "Syntax: mpartyline <command> \[values/params\]\nThis command has the same syntax and commands as partyline, except it will automatically replace the user feild, so skip it.\nUse /sbnc help partyline for a command list."
		}
	}
	if {![getbncuser $client admin]} { return }
	if {[string equal -nocase $command "partyline"]} { khz:partycommands $client $parameters }
	if {[string equal -nocase $command "mpartyline"]} { khz:mpartycommands $client $parameters }
}

proc khz:mpartycommands {client arg} {
	foreach user [bncuserlist] {
		khz:partycommands $client "partyline [lindex $arg 1] $user [join [lrange $arg 2 end]]"
	}
	haltoutput
	return
}

proc khz:partycommands {client parameters} {

	if { [string equal -nocase "partyline" [lindex $parameters 0]] && [getbncuser $client admin] } {
		catch {partyline [join [lrange $parameters 1 end]]} result
		setctx $client
		if {$result == ""} { set result "<null>" }
		foreach sline [split $result \n] {
			bncreply "$sline"
		}
		haltoutput
	}
	return
}

proc partyline {parameters} {
  global partyban botnick partyline botname partyhost

	variable ctx [getctx]

	set command [lindex $parameters 0]
	set user [lindex $parameters 1]
	set params [join [lrange $parameters 2 end]]
	set paramsnouser [join [lrange $parameters 1 end]]

	set result ""
	switch -- $command {
		join {
			setctx $user
			sbnc:partyline $user "join [lindex $params 0]"
			set result "$user joining [lindex $params 0]"
		}
		part {
			setctx $user
			sbnc:partyline $user "part [lindex $params 0] :Parted by admin."
			set result "$user parting [lindex $params 0]"
		}
		kick {
			setctx $user
			set chans [split [string tolower [getbncuser $user tag partyline]] ","]
			set idx [lsearch $chans [string tolower [lindex $params 0]]]
			if {$idx != -1} {
				setbncuser $user tag partyline [join [lreplace $chans $idx $idx] ","]
				putclient ":-sBNC!core@shroudbnc.org KICK [lindex $params 0] $botnick :Kicked by admin."
				sbnc:bcpartybutone $user ":-sBNC!core@shroudbnc.org KICK [lindex $params 0] -$user :Kicked by admin."
			}
			set result "$user kicked from [lindex $params 0]"
		}
		set {
			setbncuser $user tag partyline "[join [string tolower [lindex $params 0]] ","]"
			set result "$user is now on: [split [string tolower [getbncuser $user tag partyline]] ","]"
		}
		show {
			set result "$user is on: [split [string tolower [getbncuser $user tag partyline]] ","]"
		}
		sync {
			set chans [split [string tolower [getbncuser $user tag partyline]] ","]
			foreach chan $partyline {
				if {[lsearch $chans [string tolower $chan]] == -1} {
					sbnc:bcpartybutone $user ":-$user!user@$partyhost PART $chan :Resyncing BNC: User isnt on channel."
				}
				if {[lsearch $chans [string tolower $chan]] != -1 && ![getbncuser $user hasclient]} {
					sbnc:bcpartybutone $user ":-$user!user@$partyhost PART $chan :Resyncing BNC: User isnt connected to BNC."
				}
				if {[lsearch $chans [string tolower $chan]] != -1 && [getbncuser $user hasclient]} {
					setctx $user
					sbnc:partyline $user "join $chan 1"
				}
			}
			set result "Sync complete."
		}
		ban {
			set partyban([lindex $params 0],$user) 1
			set result "$user banned on [lindex $params 0]"
		}
		unban {
			unset partyban([lindex $params 0],$user)
			set result "$user unbanned on [lindex $params 0]"
		}
		add {
			sbnc:partyline_add [lindex $paramsnouser 0]
			set result "Added partyline channel [lindex $paramsnouser 0]"
		}
		del {
			set idx [lsearch [string tolower $partyline] [string tolower [lindex $paramsnouser 0]]]
			set partyline [lreplace $partyline $idx $idx]
			bncsetglobaltag partyline $::partyline

			foreach x [bncuserlist] {
				set chans [split [string tolower [getbncuser $x tag partyline]] ","]
				set idx [lsearch $chans [string tolower [lindex $params 0]]]
				if {$idx != -1} {
					setctx $x
					putclient ":$botnick PART [lindex $params 0]"
					setbncuser $x tag partyline [join [lreplace $chans $idx $idx] ","]
				}
			}
			set result "Removed partyline channel [lindex $paramsnouser 0]"
		}
		list {
			set result "Active partyline channels: $partyline"
		}
		default {
			set command "Help"
			set result "Syntax: partyline <command> \[values/params\]
			/sbnc help partline for more information and a list of valid commands."
		}
	}
	setctx $ctx
	return "partyline $command - $result"
}

proc flood {client msg} {
	global floodcheck
	if { [info exists floodcheck($client,start)] == 0} {
		set floodcheck($client,start) [unixtime]
		set floodcheck($client,lines) 0
	}
	if { [expr {$floodcheck($client,start) + $floodcheck(settings,intime)}] < [unixtime]} {
		set floodcheck($client,start) [unixtime]
		set floodcheck($client,lines) 0
	}
	incr floodcheck($client,lines)
	if {$floodcheck($client,lines) >= $floodcheck(settings,lowcap)} {
		set i [expr {$floodcheck($client,lines) - $floodcheck(settings,lowcap)}]
		if {[expr {$i % $floodcheck(settings,period)}] == 0 } {
			putmainlog "User $client reached $floodcheck($client,lines) lines in $floodcheck(settings,intime) seconds.  Triggered by: [join $msg]"
		}
	}
}
