###########################
### KillLog.tcl		###
### Version 1.3		###
### By Wcc		###
### irc.dal.net		###
###########################

#############################################################################
## This script logs kills/klines/akills seen in the channel to a log file, ##
## and generates an html file.						   ##
#############################################################################

##########################################################
## Just load the script, set the variables, and rehash. ##
##########################################################

###############################
# Set the html filename here. #
###############################

set killpage "./web/kills.html"

##############################
# Set the log filename here. #
##############################

set killlog "./web/kills.log"

###################################
# Set the database filename here. #
###################################

set killlogdb "./web/kills.db"

####################
# Code begins here #
####################

bind sign - * killlog

proc killlog {nick host hand chan kill} {
	if {([string match "killed*" [string tolower $kill]])} {
		putkilllog $nick $host $kill $chan
	}
}

proc putkilllog {nick host kill chan} {
	global killpage killlog killlogdb
	set databaseid [open $killlogdb a+]
	puts $databaseid "<tr>"
	puts $databaseid "<td align=left bgcolor=#c0c0c0><font size=\"4\">[clock format [clock seconds] -format "%I:%M:%S %p %x"]</font></td>"
	puts $databaseid "<td align=left bgcolor=#e0e0e0><font size=\"4\"><center>$nick</center></font></td>"
	puts $databaseid "<td align=left bgcolor=#c0c0c0><font size=\"4\"><center>$host</center></font></td>"
	puts $databaseid "<td align=left bgcolor=#e0e0e0><font size=\"4\"><center>$kill</center></font></td>"
	puts $databaseid "<td align=left bgcolor=#c0c0c0><font size=\"4\"><center>$chan</center></font></td>"
	puts $databaseid "</tr>"
	close $databaseid
	set logid [open $killlog a+]
	puts $logid "KILL: $nick - $host - $kill"
	close $logid
	set killpageid [open $killpage w]	
	set databaseid [open $killlogdb r]
	puts $killpageid "<html>"
	puts $killpageid "<head>"
	puts $killpageid "<title>Kill Log</title>"
	puts $killpageid "</head>"
	puts $killpageid "<body>"
	puts $killpageid "<font size=\"6\" color=000000><center>Kill Log</center></font><br>"
	puts $killpageid "<center>"
	puts $killpageid "<table>"
	puts $killpageid "<tr>"
	puts $killpageid "<td align=left bgcolor=8080c0><font size=\"5\"><center>Time</center></font></td>"
	puts $killpageid "<td align=left bgcolor=8080e0><font size=\"5\"><center>Nick</center></font></td>"
	puts $killpageid "<td align=left bgcolor=8080c0><font size=\"5\"><center>Host</center></font></td>"
	puts $killpageid "<td align=left bgcolor=8080e0><font size=\"5\"><center>Kill</center></font></td>"
	puts $killpageid "<td align=left bgcolor=8080c0><font size=\"5\"><center>Channel</center></font></td>"
	puts $killpageid "</tr>"
	while {![eof $databaseid]} {
		gets $databaseid line
		puts $killpageid $line
	}
	puts $killpageid "</center>"
	puts $killpageid "</table>"
	puts $killpageid "</body>"
	puts $killpageid "</html>"
	close $killpageid
	close $databaseid
	putlog "KILLLOG: $nick has been killed. Logs updated."
}

putlog "KILLLOG: KillLog.tcl Version 1.3 by wcc is loaded."
putlog "KILLLOG: Loging kills as html to $killpage."
putlog "KILLLOG: Logging kills as text to $killlog."