###################
### DieAuth.tcl	###
### Version 1.0	###
### By Wcc	###
### irc.dal.net	###
###################

#####################################################################################################
## This script makes owners (+n users) to enter an authorization code to use ".die"  This also     ##
## disables /msg <bot> die. 									   ##
#####################################################################################################

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

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

bind dcc - die dcc:die
bind dcc - dieauth dcc:dieauth
unbind msg n|- die *msg:die

proc dcc:die {hand idx text} {
	global diecode_dcc diehand_dcc
	if {![matchattr $hand B]} {
			putserv "notice $nick :This command requires botnet administrator access. Your attempt has been logged."
			putlog "\002DIEAUTH:\002 Invalid die attempt from $hand, no access."
	} else {
		set arg1 [string tolower [lrange $text 2 end]]
		set diecode_dcc [md5 [encrypt [encrypt [userlist] 515D48484548ghftryf7codeDG] [rand 82574]]]
		set diehand_dcc $hand
		dccbroadcast "\002DIEAUTH:\002 Shutdown initiated by $hand. A confirmation code has been sent. Please type .dieauth <code> now to confirm shutdown. All attempts are logged"
		putidx $idx "\002DIEAUTH:\002 The confirmation code is: $diecode_dcc"
		putlog "\002DIEAUTH:\002 Shutdown initiated by $hand. A confirmation code has been sent."
	}
}
proc dcc:dieauth {hand idx text} {
	global diecode_dcc diehand_dcc
	if {![matchattr $hand B]} {
		putidx $idx "This command requires botnet administrator access. Your attempt has been logged."
		putlog "\002DIEAUTH:\002 Invalid die attempt from $hand, no access."
	} elseif {$diehand_dcc != $hand} {
		putidx $idx "\002DIEAUTH:\002 Your hand did not initiate the die command. The die code has been reset, and the atempt logged."
		putlog "\002DIEAUTH:\002 Invalid die attempt from $hand, invalid hand."
	} else {
		if {[lindex $text 0] == $diecode_dcc} {
			putserv "QUIT :[lrange $text 1 end] ($hand)"
			die "Shutdown by $hand."
		} else {
			putidx $idx "Invalid die code. Die code has been reset, you must now reinitiate the shutdown processes."
			unset diecode_dcc
			unset diehand_dcc
			set diecode_dcc [encrypt [encrypt [userlist] 515D48484548ghftryf7codeDG] [rand 8254]]
			set diehand_dcc [encrypt [encrypt [userlist] 515D48484548ghftryf7codeDG] [rand 8254]]
		}
	}
}
putlog "\002DIEAUTH:\002 DieAuth.tcl 1.0 by Wcc is loaded."