Your IP : 216.73.216.224


Current Path : /home/mudbot/eggdrop-keep/scripts/
Upload File :
Current File : //home/mudbot/eggdrop-keep/scripts/xdcc_pro.tcl

######################################################### 1MAR09 ##
## XDCC SERVER PRO v2.04.2 by SpiKe^^ -  XDCC Server for Eggdrop ##
###################################################################
#                                                                 #
#  XDCC Server Pro is a Single list multi-channel XDCC serving    #
#  script.                                                        #
#  Most settings done by DCC chat.                                #
#                                                                 #
#  REQUIRED Eggdrop Conf Settings:                                #
#   1. Transfer Module MUST Be Loaded and xfer-timeout 30 or less #
#   2. CTCP Module MUST Be Loaded and Set To 0 or 2               #
#                                                                 #
#  If the bot is behind a router or firewall:                     #
#    1. Search for this line in your Eggdrop Config:              #
#       #set reserved-portrange 2010:2020                         #
#       Remove the # to turn on the setting. Change the           #
#       portrange numbers, but don't use less than 10 ports.      #
#    2. Use the ports you chose above in the router setup         #
#       port forwarding section of your router:                   #
#    3. Use the ports you chose above in the firewall setup       #
#       port forwarding section of your firewall:                 #
#    4. Help Setting Firewall & Router Rules:                     #
#       http://mytclscripts.com/troubleshoot/troubleshoot.html    #
#                                                                 #
#  Add this line:  source scripts/xdcc_pro.tcl                    #
#  to your eggdrop config and rehash to load the script.          #
#  DCC chat the bot and use the command:  .xhelp                  #
#                                                                 #
#                                                                 #
#  NOTE : This script was tested with eggdrops v1.6.16 & above.   #
#  NOTE : Script requires tcl version 8.4                         #
#                                                                 #
#      Script has been well tested, and seems to be stable.       #
#                  ! USE AT YOUR OWN RISKS !                      #
#                                                                 #
###################################################################
#     Contact Options to report bugs, comments & suggestions      #
#                http://www.mytclscripts.com                      #
#                irc: undernet: #pc-mirc-help                     #
#                email: spike@mytclscripts.com                    #
#               Screen Shots Available On My Site                 #
###################################################################
#                     New In This Release                         #
#                                                                 #
#  1. Tcl Setting Change:  Default Path to Packs:  xpro(defpath)  #
#     Can now take Any Number of Directory Paths                  #
#  2. New Advanced Tcl Options:  Automatic File Checking:         #
#     Auto-Add New Files to the Xdcc Packs List                   #
#     Auto-Delete Missing Files from the Xdcc Packs List          #
#  3. Command  .apack -all  Can now also Remove any Missing Packs #
#  4. Script now Makes any Missing Directories in Default Path    #
#                                                                 #
###################################################################
#                 XDCC Server Pro Features                        #
#  1. Multi-Channel                                               #
#  2. Unlimitied Packs                                            #
#  3. Built-In Help System                                        #
#  4. Dynamic Settings Thru DCC Chat                              #
#  5. Default or Custom Server Ads                                #
#  6. Default or Custom Public !list Trigger                      #
#  7. Select Default Add Pack List Position                       #
#  8. Extensive DCC Add Pack Command Options:                     #
#     a)  Add Multiple Packs With One DCC Command                 #
#     b)  Add Pack(s) with Default or Custom Pack Descriptions    #
#     c)  Add Pack(s) at Default or Specific List Position        #
#     d)  Add All New Packs in a Directory                        #
#  9. Move Pack(s) to Specific List Position                      #
# 10. List or Delete Packs in Queue                               #
# 11. List or Kill File Sends                                     #
# 12. Ban Users From the Server                                   #
# 13. Accurate Server Download Totals                             #
# 14. Reset Server Totals Command                                 #
###################################################################
#                Includes Server Protection                       #
#  1. Flood Protection                                            #
#  2. User Must Be On Channel                                     #
#  3. Kill Send if User is Gone X Amount of Time                  #
#  4. DCC Chat Admin +m                                           #
###################################################################


#########################################
#######   BASIC SERVER SETTINGS   #######
#########################################

## Maximum number of file sends at once.  [.xset md]
set xpro(maxdcc) "5"

## Maximum number of queued packs.  [.xset mq]
set xpro(maxque) "30"

## Maximum number of queued file per user.  [.xset um]
set xpro(usrmaxq) "5"

## For users with files in queue...  [.xset qt]
## can be gone from the channel how many minutes before removing from que
set xpro(qtimegone) "3"

## For users with active file sends...  [.xset st]
## can be gone from the channel how many minutes before killing sends
set xpro(stimegone) "1"

## Start server when the bot starts? ("0" = no auto-start)  [.xset as]
## Set to "1" or more to enable. ((auto-start delay time in minutes))
set xpro(astart) "1"

######   XDCC ADD PACKS COMMAND SETTINGS   ######

## Default path(s) to packs files..
## Used with the DCC commands:  .apack <file>,<description>
##                        and:  .apack -all
## IMPORTANT: this is the packs route(s) in braces. {./filesys/}
## This is the route relative to the bot root directory
##   {./packs/}         : .apack check the packs directory
##   {./paks/,./help/}  : multiple paths  (comma separated)
# Example: # set xpro(defpath) {./filesys/}
set xpro(defpath) {/var/www/html/eggdrop/}
# ZZZ
## Default .apack command adds new packs where..
##  "1"  :Add new packs at the beginning of the list  (pack #1)
##  "2"  :Add new packs at the end of the list  (new last pack)
set xpro(defadd) "1"

######   SERVER COLOR THEMES & LAYOUT   ######

## Server Colors On or Off ??  (0=OFF)  [.xset co]
##  "1"  :Default Colors
##  "2"  :Purple, Red and Grey
##  "3"  :Brown, Orange and Grey
##  "4"  :Dark Blue, Blue and Grey
##  "5"  :Orange, Green and Grey
##  "0"  :Server Colors Off
set xclr(color) "1"

## Server Ad/List Layout Choices  [.xset al]
##  "1"  :Default - lists use pack description only
##  "2"  :Option2 - lists use file name & description
set xpro(adlayout) "2"

####################################
#######   SERVER ADS SETUP   #######
####################################
## Send Timed Public Ads To All Server Channels ??
##   :Set This To "0" To Not Have Timed Ads.
##   :Set to "1" thru "9" to Enable Timed Ads.
## Time (minutes), to delay first ad to channel, after server start.
set xpro(firstad) "2"

## Option for Default Ad/List Layout (Ad/List Layout setting "1")
## First line of channel ads has 2 choices:
##  "1" : |XDCC PRO| XDCC Server brought to you by #<serverchannel>
##  "2" : |XDCC PRO| XDCC Server Online.
set xpro(adline1) "1"

## Option for Option2 Ad/List Layout (Ad/List Layout setting "2")
## Server Description used in this ad layout:
#example#  set xpro(srvrdesc) {Windows/mIRC Help Server}
## IMPORTANT: this is the server description in braces.
set xpro(srvrdesc) {pocketmud.com - Portal for CoffeeMUD}

#----------------------------------------------------------------------#
# XDCC Pro can do the ad a couple differents ways:                     #
#   a: Send Ad #1 to the channel erery "x" minites.                    #
#   b: Send Ad #1 the first time.                                      #
#      Then send Ad #2 the next "x" times before sending Ad #1 again.  #
#                                                                      #
# Either Ad can send the pack list or the trigger to get the pack list #
#----------------------------------------------------------------------#

## Server Ad #1 sends the packs list or the list trigger ??
##  "1"  :Send the packs list to the channel.
##  "2"  :Send the list trigger line to the channel.
##  "0"  :Write your own Ad #1 below. (in advanced setup)
set xpro(ad1how) "2"

## Enable Ad #2 ??
##   :Set This To "0" To Only Use Ad #1. (Disable Ad #2)
##   :Set to "1" or more to Enable Ad #2.
## Number of times to send Ad #2 before sending Ad #1 again.
set xpro(altad) "10"

## Server Ad #2 sends the packs list or the list trigger ??
##  "1"  :Send the packs list to the channel.
##  "2"  :Send the list trigger line to the channel.
##  "0"  :Write your own ad#1 below. (in advanced setup)
set xpro(ad2how) "0"

## Time (in minutes), between ads to a channel.
set xpro(xadtime) "60"

############################################
####  REPLY TO REQUESTS FOR PACKS LIST  ####
############################################
## Custom Public List Trigger:  (optional public list trigger)
## Can be anything but !list
#example#   set xpro(cpltrig) {!xlist}
set xpro(cpltrig) {!packs}
set xpro(cpltriglatest) {!latest}

## CustomPublicListHow: custom list trigger sends packs list how?
##  "1"  :Send the list by private message.
##  "2"  :Send the list by user notice.
##  "3"  :Send the list to the channel.
##  "0"  :Set to "0" to not use custom public list trigger.
set xpro(cplhow) "2"

## !list ListHow:  !list in the channel replys how?  6 valid settings...
##  "1"  :Send user notice, give the /ctcp command to get the list.
##  "2"  :Send user notice, give the custom public list trigger.
##  "3"  :Send the list by private message.
##  "4"  :Send the list by user notice.
##  "5"  :Send the list to the channel.
##  "0"  :Set to "0" to not reply to !list public trigger.
set xpro(listhow) "2"

## /ctcp ListHow:  "/ctcp <BotNick> XDCC list"  sends packs list how?
##  "1"  :Send the list by private message.
##  "2"  :Send the list by user notice.
##  "0"  :Don't reply to the ctcp list command.
set xpro(xlsthow) "2"


#########################################################
#######  ADVANCED SETUP!  NO NEED TO EDIT BELOW!  #######
#########################################################

######   AUTOMATIC FILE CHECKING   ######

## Auto-Add : Automaticly add new files to the packs list?  ("1" = yes) ("0" = no)
set xpro(autoadd) "1"

## Auto-Add checks what path(s) for new files?
##  {}          : check xpro(defpath)  (Default path)
##  {./packs/}  : check the packs directory
##  {./paks/,./help/}  : multiple paths  (comma separated)
set xpro(aaddpath) {/var/www/html/eggdrop}

## Auto-Delete : Automaticly remove missing files from the packs list?  ("1" = yes) ("0" = no)
set xpro(autodel) "1"

## Auto-Delete checks what path(s) for missing files?
##  {}          : same as auto-add path(s)
##  {./packs/}  : check the packs directory
##  {./paks/,./help/}  : multiple paths  (comma separated)
##  {*}         : check All packs to see if they are missing
set xpro(adelpath) {*}

## Automaticly check for new/missing files how often?  (in minutes)
set xpro(acheck) "10"


## The  .apack -all  command also checks for and removes missing packs?
##   "0"   :No, .apack -all  does not check for missing packs.
##   "1"   :Check the packs in the current .apack -all  directories for missing.
##   "2"   :Checks all current packs for missing.
set xpro(alldel) "1"

######   CUSTOM AD LINES   ######

## Write your own ad#1 here. {one line, can use mirc color codes)
#set xpro(ad1line) {%ca1 |XDCC SERVER PRO| v2.04.2 by %ca2SpiKe^^%ca1 - To see the pack list type: %ca2%lt }
set xpro(ad1line) {%ca1 To see the pack list type: %ca2%lt }

## Write your own ad#2 here. {one line, can use mirc color codes)
set xpro(ad2line) {%ca1 Got a scooter? Want a scooter? We have owners and service manuals for various scooters. Get more information at https://BayScooter.org. To see the list of files available for download, type: %ca2%lt %ca1 or %ca2 !latest %ca1 for the five newest files. }

######   LIST/AD SEND TIMING/FLOOD PROTECTION   ######

## Time (in minutes), to delay ads to additional channels past the first.
## to keep from sending long ads to more than 1 channel at a time.
##   valid settings:  1 to 4 minutes.
set xpro(adtonextch) "1"

## ListFlood:  This timer only applies to packs lists sent to a channel !!
## Wait this long after sending a packs list to a channel,
## before sending another list request reply to that same channel.
## valid settings: "1" to "5" minutes  (1 digit setting = minutes)
##          :or:  "60" to "300" seconds  (2 & 3 digit setting = seconds)
set xpro(listflud) "90"

######   LIST SEND QUEUE   ######

## Maximum number of package list requests in listqueue ??
##   valid settings:  1 or more
set xpro(lqcmax) "6"

## If there are lists in listqueue...
## the server will try to send one list from que every "x" seconds
##   valid settings:  (10-15 sec minimun... 120 max)
set xpro(lquetime) "18"

######   MISC SERVER STUFF    ######

## ServerLogo: used in server replys to users.
## IMPORTANT: this is the logo in braces, {ServerLogo}
#example# set xpro(logo) {|XDCC PRO|}
set xpro(logo) {|XDCC PRO|}

## AdLogo: used at beginning of 1st line in ads (opt1).  (( can be "" ))
##   "<adlogo> XDCC Server brought to you by #<channel>"
## IMPORTANT: this is the logo in braces, {ServerLogo}
#example#  set xpro(logo) {|XDCC PRO|}
set xpro(adlogo) {|XDCC PRO|}

## AdLogo2: used at beginning of last line in ads (opt1).
##   "<adlogo2> Serving 5 packages | Sent 773 meg's (16 packs)"
set xpro(infologo) {|XDCC PRO by SpiKe^^|}

##################################################
####  ADVANCED SETUP!  CUSTOM SERVER COLORS!  ####
##################################################
## Use "Custom Colors" below or, "Server Colors" from above ??  [.xset cu]
##   "0"  : use server colors settings from above
##   "1"  : use custom server colors setup below
set xclr(custom) "0"

## Custom Server Colors:  (( standard mirc color codes ))
## Color settings for items below can be set in 3 ways:  
## 1) one number:  like "06" : for text in purple
## 2) two numbers: like "04,12" : for red text, blue background (1st# = text, 2nd# = background)
## 3) no numbers:  like "" : no color code for this item.. text will be user default colors.
#------------------------------------------------------------------------------------#
# 00=white 01=black 02=dkblue 03=green 04=red 05=brown 06=purple 07=orange 08=yellow #
# 09=lightgreen 10=darkgreen 11=bluegreen 12=blue 13=pink 14=darkgrey 15=lightgrey   #
#------------------------------------------------------------------------------------#
set xclr(c0) "10"    ;# Logo color
set xclr(c1) "10"    ;# Text color
set xclr(c2) "04"    ;# Highlight
set xclr(c3) "04"    ;# Triggers
set xclr(c4) "14"    ;# Dividers
set xclr(c5) "10"    ;# Pack descriptions
set xclr(c6) "10"    ;# Other color 1
set xclr(c7) "04"    ;# Other color 2
set xclr(c8) "04"    ;# Other color 3
set xclr(c9) "10"    ;# Other color 4
set xclr(c10) "10"   ;# Other color 5

## Custom Alt Ad Colors for the default alt ad ?
##   valid settings: (one line alt ad looks good with a background:)
## :set both "" to use the Server Colors from above
## :one number:  like "06" : for text in purple
## :two numbers: like "04,12" : for red text, blue background (1st# = text, 2nd# = background)
set xclr(custalt1) "10,15"    ;# text color & background #'s
set xclr(custalt2) "04,15"    ;# trigger text color & background #'s


## ! STOP ! ## ! STOP ! ## ! STOP ! ## ! STOP ! ## ! STOP ! ## ! STOP ! ##

# -------------------------------------------------------------------
# DO NOT EDIT BELOW THESE LINES UNLESS YOU KNOW WHAT YOU ARE DOING !!
# -------------------------------------------------------------------

# upgrade hook #
if {[info exists xinf(ver)] && $xinf(ver)!="2.03" && $xinf(ver)!="2.04" && $xinf(ver)!="2.04.2"} {
 die "UPGRADE ERROR! Bot must be killed & restarted with the new script! Start the bot now."
}

bind dcc m xhelp xhelp
bind dcc m xinfo xinfos
bind dcc m xstatus xstatus
bind dcc m xstart xstart
bind dcc m xstop xstop
bind dcc m xset xset
bind dcc m xreset xreset
bind dcc m lpack xlistpacks
bind dcc m apack xaddpk
bind dcc m dpack xdelpack
bind dcc m mpack xmovepk
bind dcc m lchan xlistchans
bind dcc m achan xaddchan
bind dcc m dchan xdelchan
bind dcc m lque xlistque
bind dcc m dque delfromque
bind dcc m lsend listsends
bind dcc m dsend xkillsend
bind dcc m lban xlistbans
bind dcc m aban xaddban
bind dcc m dban xdelban

bind ctcp - xdcc xctcpevent
bind sent - * xupdate
bind lost - * xlosttransfer
bind tout - * xtimeout
bind pub -|- !list xpublist
bind pub -|- !xdcc xpubxdcc


#### EDIT ####
if {$xpro(cplhow)!="0" && ($xpro(cpltrig) ne "" || $xpro(cpltriglatest) ne "")} {
  if {$xpro(cpltrig) ne ""} {	 bind pub -|- $xpro(cpltrig) xpublis2  }
  if {$xpro(cpltriglatest) ne ""} {	 bind pub -|- $xpro(cpltriglatest) xpublislatest  }
} else {  set xpro(cplhow) 0  ;  set xpro(cpltrig) ""  ;  set xpro(cpltriglatest) ""  }
#### END EDIT ####


# ---------------------------------- #
# !! DO NOT CHANGE THESE SETTINGS !! #
# ---------------------------------- #
#[File that stores the server channels]
set xfil(chans) ./scripts/xdcc.chan
#[File that stores the packages offered]
set xfil(packs) ./scripts/xdcc.pack
#[File that stores the number of times a pack has been downloaded]
set xfil(cpack) ./scripts/xdcc.cpack
#[File that stores the trigger server list]
set xfil(trigs) ./scripts/xdcc.trig
#[File that stores the number of times a trigger has been downloaded]
set xfil(ctrig) ./scripts/xdcc.ctrig
#[File that stores the total amount downloaded on the server]
set xfil(totals) ./scripts/xdcc.total
#[File that stores the queues]
set xfil(que) ./scripts/xdcc.queue
#[File that stores the server bans]
set xfil(bans) ./scripts/xdcc.bans
#[File that stores the dynamic settings]
set xfil(dset) ./scripts/xdcc.dset

proc xreset {handle idx text} {  global xpro xclr xfil  ;  set err 0  ;  set do ""  ;  set did 0
 if {$text ne ""} {  set text [xstrtsp [xstrlow $text]]  }
 set dlogo $xclr(dcc)$xpro(dlogo)
 if {$text eq ""} {   set err 1
 } else {  set texls [split $text]  ;  set y [string trimleft [lindex $texls 0] -]
   if {[regexp {^(s(e(r(v(e(r)?)?)?)?)?)$} $y] || $y eq "srv" || $y eq "srvr"} {  set do s
   } elseif {[regexp {^(p(a(c(k(s)?)?)?)?)$} $y] || [regexp {^(pak(s)?)$} $y] || [regexp {^(pk(s)?)$} $y]} {  set do p
   } elseif {[regexp {^(a(l(l)?)?)$} $y]} {  set do a
   } elseif {[regexp {^(h(e(l(p)?)?)?)$} $y]} {   set err 1  } else {  set err 2  }
 }
 if {$do eq "a"} {  putdcc $idx "$dlogo Reset ALL Server & Download Stats ..."  }
 if {$do eq "s" || $do eq "a"} {
   if {$do eq "s"} {  putdcc $idx "$dlogo Reset Server Download Totals ..."  }
   if {[file exists $xfil(totals)]} {  file delete $xfil(totals)  }
   if {$xpro(bytecount)>"0" || $xpro(sentcount)>"0"} {  set xpro(bytecount) 0  ;  set xpro(sentcount) 0  ;  incr did
     if {$do eq "s"} {  putdcc $idx "$dlogo$xclr(dcce) Set files and bytes sent to none."  }
   } elseif {$do eq "s"} {  putdcc $idx "$dlogo$xclr(dcce) No download totals to reset."  }
 }
 if {$do eq "p" || $do eq "a"} {
   if {$do eq "p"} {  putdcc $idx "$dlogo Reset Current Pack Sent Stats ..."  }
   if {[file exists $xfil(cpack)]} {  file delete $xfil(cpack)  }
   if {$xpro(packssent)>"0" || $xpro(bytessent)>"0"} {  incr did
     if {$do eq "p"} {  putdcc $idx "$dlogo$xclr(dcce) Set all package sent stats to none."  }
   } elseif {$do eq "p"} {  putdcc $idx "$dlogo$xclr(dcce) No package sent stats to reset."  }
 }
 if {$do eq "p" || $do eq "t" || $do eq "a"} {  readpackinfos  }
 if {$do eq "a" && $did>"0"} {  putdcc $idx "$dlogo$xclr(dcce) Set All server and download stats to none."
 } elseif {$do eq "a"} {  putdcc $idx "$dlogo$xclr(dcce) No server or download stats to reset."  }
 if {$err>"0"} {
   putdcc $idx [set hbar ---------------------------------------------------------]
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Reset Stats command \[.xreset <option>\]"
   if {$err=="2"} {  putdcc $idx "INPUT ERROR:  Invalid .xreset option given: [lindex $texls 0]"  }
   putdcc $idx ".xreset usage : .xreset <option>"
   putdcc $idx "Options:  -server -packs and -all"
   putdcc $idx "Reset Stats Command Examples:"
   putdcc $idx " $xclr(dcc).xreset -server$xclr(dcce)   (set total server downloads to none)"
   putdcc $idx " $xclr(dcc).xreset -packs$xclr(dcce)    (set all current packs to 0 downloads)"
   putdcc $idx " $xclr(dcc).xreset -all$xclr(dcce)      (set all file download stats to none)"
   putdcc $idx $hbar
 }
}

proc xset {handle idx text} {  global xpro xclr xfil
 if {![file exists $xfil(dset)]} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Missing Settings File. Rehash the bot."
   return 0
 }
 set text [xstrtsp $text]  ;  set texls [split $text]  ;  set xscmd [lindex $texls 0]
 set err1 ""  ;  set err2 ""  ;  set xlsall 0  ;  set hlpopts ""
 set dowhat ""  ;  set dotmp ""  ;  set newsets ""  ;  set remsets ""
 if {$text == ""} {  set dowhat listall
 } elseif {[regexp -- {-(li(s(t)?)?)$} $xscmd]} {
   set dowhat listall  ;  set xlsall 1
 } elseif {$xscmd=="-ra" || [regexp -- {-(rem(o(v(e(a(l(l)?)?)?)?)?)?)$} $xscmd]} {
   set dowhat remove
 } elseif {[llength $texls]=="1" && [regexp -- {-(h(e(l(p)?)?)?)$} $xscmd]} {
  set dowhat help
 } else {
  set error 0  ;  set dovar ""  ;  set inpcnt 0
  foreach input $texls {  incr inpcnt
   if {[regexp -- {-(h(e(l(p)?)?)?)$} $input]} {
     if {$inpcnt=="1"} {  set dowhat help  }
     set input -help
   } else {
    if {$dowhat!="help"} {
      if {$dotmp == ""} {  set dovar $input  }
    } else {  set dovar $input  }
    set rmset ""
    if {[string match -* $dovar]} {  set rmset -  ;  set dovar [string trimleft $dovar -]  }
    if {[regexp {^(md|ms)$} $dovar] || [regexp {^(maxd(c(c)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts maxdcc
      } elseif {$rmset=="-"} {  lappend remsets maxdcc
      } elseif {$dotmp == "maxdcc"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:9]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp maxdcc  }
    } elseif {$dovar=="mq" || [regexp {^(maxq(u(e)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts maxque
      } elseif {$rmset=="-"} {  lappend remsets maxque
      } elseif {$dotmp == "maxque"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:+]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp maxque  }
    } elseif {[regexp {^(um|umq|mu|muq|uq)$} $dovar] || [regexp {^(us(r(m(a(x(q)?)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts usrmaxq
      } elseif {$rmset=="-"} {  lappend remsets usrmaxq
      } elseif {$dotmp == "usrmaxq"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:+]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp usrmaxq  }
    } elseif {[regexp {^(as(t(a(r(t)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} { lappend hlpopts astart
      } elseif {$rmset=="-"} { lappend remsets astart
      } elseif {$dotmp == "astart"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 0:+]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp astart  }
    } elseif {[regexp {^(co(l(o(r)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts color
      } elseif {$rmset=="-"} {  lappend remsets color
      } elseif {$dotmp == "color"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 0:5]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp color  }
    } elseif {$dovar=="al" || [regexp {^(adl(a(y(o(u(t)?)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts adlayout
      } elseif {$rmset=="-"} {  lappend remsets adlayout
      } elseif {$dotmp == "adlayout"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:2]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp adlayout  }
    } elseif {$dovar=="qtg" || [regexp {^(qt(i(m(e(g(o(n(e)?)?)?)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts qtimegone
      } elseif {$rmset=="-"} {  lappend remsets qtimegone
      } elseif {$dotmp == "qtimegone"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:15]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp qtimegone  }
    } elseif {$dovar=="stg" || [regexp {^(st(i(m(e(g(o(n(e)?)?)?)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts stimegone
      } elseif {$rmset=="-"} {  lappend remsets stimegone
      } elseif {$dotmp == "stimegone"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 1:15]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp stimegone  }
    } elseif {[regexp {^(cu(s(t(o(m)?)?)?)?)$} $dovar]} {
      if {$dowhat=="help"} {  lappend hlpopts custom
      } elseif {$rmset=="-"} {  lappend remsets custom
      } elseif {$dotmp == "custom"} {
        if {$input == "-"} {  lappend remsets $dotmp
        } elseif {[xstrvar $input 0:1]} {  lappend newsets $dotmp [xstrvar $input]
        } else {  lappend err2 $dotmp:$input  ;  lappend hlpopts $dotmp  }
        set dotmp ""
      } else {  set dotmp custom  }
    } else {  lappend err1 $input  }
   }
  }
 }
 if {$dowhat=="" && $newsets=="" && $remsets==""} {  set dowhat help  }
 if {$dotmp != ""} {  lappend hlpopts $dotmp  ;  set dotmp ""  }
 set avarls ""  ;  set xremcnt 0
 if {$dowhat != "help"} {  set sholin ""  ;  set shocnt 0  ;  set aslines ""
  if {$dowhat == "listall"} {  set sholin 1
   if {$xlsall=="0"} {  putdcc $idx "$xclr(dcc)$xpro(dlogo) List All Active DynamicSettings..."
   } else {  putdcc $idx "$xclr(dcc)$xpro(dlogo) List All Possible DynamicSettings..."  }
  } elseif {$dowhat == "remove"} {  set sholin 2
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Remove All Active DynamicSettings..."
  } else {
    if {$remsets != ""} {
     if {[llength $remsets]=="1"} {  putdcc $idx "$xclr(dcc)$xpro(dlogo) Remove DynamicSetting: [join $remsets]..."
     } else { putdcc $idx "$xclr(dcc)$xpro(dlogo) Remove DynamicSettings: [join [lrange $remsets 0 end-1]] & [lindex $remsets end]..." }
     set sholin "3"
    }
    if {$newsets != ""} {
     if {$sholin==""} {  set sholin 4  } else {  set sholin 5  }
    }
  }
  set xdsetfile [open $xfil(dset) r]
  if {$dowhat!="listall"} {
    set dstmprute ./scripts/xdset.tmp  ;  set xdstmpfil [open $dstmprute w]
  }
  while {![eof $xdsetfile]} {  set xvarlin [gets $xdsetfile]
   if {$xvarlin != ""} {
     foreach {xvar cset cdat snow sdat sby range} $xvarlin { break }
     set addrem ""
     if {$sholin=="3" || $sholin=="5"} {
      if {[set xrvidx [lsearch -exact $remsets [xsplitv $xvar]]]!="-1"} {
       set addrem rem
      }
     }
     if {$sholin=="4" || $sholin=="5"} {
      if {[set xavidx [lsearch -exact $newsets [xsplitv $xvar]]]!="-1"} {
       if {$addrem==""} {  set addrem add  } else {  set addrem both  }
      }
     }
     if {($sholin<"3" && [xstrvar $cset]!=$snow) || $xlsall=="1" || $addrem=="rem" || $addrem=="both"} {
      incr shocnt
      if {$xlsall=="1"} {
       if {$sby==":error:"} {  set xtsby "(Error: Bad tcl setting)"
       } elseif {$sby==":conf:"} {  set xtsby "(Tcl Setting)"
       } else {  set xtsby "(Set by: [xfmtnik $sby])"  }
       putdcc $idx " $xclr(dcc)[xstrpad [xsplitv $xvar] 9]$xclr(dcce) is set to: [xstrpad [xstrpad $snow 2] 3 l] $xtsby"
      } elseif {$sholin<"3"} {
       putdcc $idx "[xfrmtnum 1 $shocnt][xsplitv $xvar] is currently set to:  $snow"
      } else {
       putdcc $idx " $xclr(dcc)[xsplitv $xvar]$xclr(dcce) is currently set to:  $snow"
       if {[xstrvar $cset]==$snow} {
        if {$sby==":conf:"} {  putdcc $idx "     Not set dynamicly.  Tcl setting: \"$cset\""  }
       }
      }
      if {$xlsall=="1"} {  putdcc $idx "     Valid settings are:  [xvrange [xsplitv $xvar]]"
      } elseif {$sby==":error:"} {
       putdcc $idx "     Set by Error:  Invalid tcl setting: \"$cset\" "
       if {$sholin=="1"} {  putdcc $idx "     Valid settings are: [xvrange [xsplitv $xvar]]"
       } else { putdcc $idx "     Can't be removed until the tcl is fixed." }
      } elseif {$sby!=":conf:"} {
       if {$sholin=="1"} {
        putdcc $idx "     Set by [xfmtnik $sby] [xtimeago $sdat] ago."
        putdcc $idx "     [xsplitv $xvar] is set to \"$cset\" in the tcl."
       } else {
        putdcc $idx "     Set by [xfmtnik $sby] [xtimeago $sdat] ago. (Setting Removed)"
        if {[xstrvar $cset $range]} {
         set snow [xstrvar $cset]  ;  set sby :conf:
         putdcc $idx "     Now using the tcl setting:  \"$snow\" "
        } else {
         set snow [xvardef [xsplitv $xvar]]  ;  set sby :error:
         putdcc $idx "     Invalid tcl setting:  \"$cset\" "
         putdcc $idx "     Now using ServerDefault for [xsplitv $xvar]:  $snow"
        }
        set sdat [unixtime]  ;  incr xremcnt
       }
      }
     }
     if {$addrem=="add" || $addrem=="both"} {
      set tmp1 [lindex $newsets $xavidx]  ;  set tmp2 [lindex $newsets [expr {$xavidx+1}]]
      lappend aslines [list $tmp1 $cset $snow $tmp2 $sby $sdat]
      lappend avarls $tmp1
      set snow $tmp2  ;  set sby [xstrlow $handle]  ;  set sdat [unixtime]
      set newsets [lreplace $newsets $xavidx [expr {$xavidx+1}]]
     }
     if {$dowhat!="listall"} {
      puts $xdstmpfil [list $xvar $cset $cdat $snow $sdat $sby $range]
     }
   }
  }
  close $xdsetfile
  if {$dowhat!="listall"} {
    close $xdstmpfil  ;  file delete $xfil(dset)
    file rename $dstmprute $xfil(dset)  ;  file delete $dstmprute
  }
  if {$sholin<"3"} {
   if {$shocnt=="0"} {
    if {$sholin=="1"} {  set tmp1 List.  } else {  set tmp1 Remove.  }
    putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No DynamicSettings to $tmp1"
    putdcc $idx " "
   } elseif {$sholin=="2"} {
    putdcc $idx " "
    if {$xremcnt=="0"} {  putdcc $idx " No DynamicSettings were Removed."
    } elseif {$xremcnt=="1"} {  putdcc $idx " Removed One DynamicSetting."
    } else {  putdcc $idx " Removed $xremcnt DynamicSettings."  }
   } else {  putdcc $idx " "  }
  } else {
   if {$aslines!=""} {
    if {$remsets!=""} {  putdcc $idx " "  }
    if {[llength $avarls]=="1"} {  putdcc $idx "$xclr(dcc)$xpro(dlogo) Add/Change DynamicSetting: [join $avarls]..."
    } else { putdcc $idx "$xclr(dcc)$xpro(dlogo) Add/Change DynamicSettings: [join [lrange $avarls 0 end-1]] & [lindex $avarls end]..." }
    foreach {xasline} $aslines {
     foreach {avar tset oset nset osby osdt} $xasline { break }
     putdcc $idx " $xclr(dcc)$avar$xclr(dcce) is currently set to:  $oset"
     if {$osby==":error:"} {  putdcc $idx "     Set by Error:  Invalid tcl setting: \"$tset\""
     } elseif {$osby==":conf:"} {  putdcc $idx "     Set by tcl setting: [xtimeago $osdt] ago."
     } else {  putdcc $idx "     Set by [xfmtnik $osby] : [xtimeago $osdt] ago."  }
     putdcc $idx "     Now using DynamicSetting for $avar:  $nset"
    }
    putdcc $idx " "
   } else {  putdcc $idx " "  }
  }
 }
 if {$dowhat != "help" && $hlpopts == ""} {
  if {$err1 != ""} {
   if {[llength $err1]=="1"} {  putdcc $idx "INPUT ERROR:  Invalid .xset option given: [join $err1]"
   } else {  putdcc $idx "INPUT ERROR:  Invalid .xset options given: [join $err1]"  }
  }
  putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).xset -help$xclr(dcce) for help with .xset"
 } else {
  if {$hlpopts == ""} {
   putdcc $idx [set hbar --------------------------------------------------------]
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Dynamic Settings  \[.xset <option(s)>\]"
   if {$err1 != ""} {
    if {[llength $err1]=="1"} {  putdcc $idx "INPUT ERROR:  Invalid .xset option given: [join $err1]"
    } else {  putdcc $idx "INPUT ERROR:  Invalid .xset options given: [join $err1]"  }
   }
   putdcc $idx ".xset usage : .xset  :or:  .xset <setting> <new value>"
   putdcc $idx "Options: -removeall (-rem), -list and -help"
   putdcc $idx "Dynamic Settings Command Examples:"
   putdcc $idx " $xclr(dcc).xset$xclr(dcce)              (list all active dynamic settings)"
   putdcc $idx " $xclr(dcc).xset -list$xclr(dcce)        (list all possible dynamic settings)"
   putdcc $idx " $xclr(dcc).xset -rem$xclr(dcce)         (remove all active dynamic settings)"
   putdcc $idx " $xclr(dcc).xset maxdcc 3$xclr(dcce)     (change maxdcc value to 3)"
   putdcc $idx " $xclr(dcc).xset maxque -$xclr(dcce)     (remove dynamic setting for maxque)"
   putdcc $idx " $xclr(dcc).xset -maxque$xclr(dcce)      (remove dynamic setting for maxque)"
   putdcc $idx " $xclr(dcc).xset -help$xclr(dcce)        (show this server help)"
   putdcc $idx " $xclr(dcc).xset -help color$xclr(dcce)  (show help for the color setting)"
   putdcc $idx $hbar
  } else {
   putdcc $idx "-----------------------------------------------------"
   foreach dsetng $hlpopts {
    putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) DynamicSetting $dsetng..."
    if {$err2!="" && [set xvidx [lsearch $err2 $dsetng:*]]!="-1"} {
     set xbadset [lindex [split [lindex $err2 $xvidx] :] 1]
     putdcc $idx "INPUT ERROR:  Invalid $dsetng setting given: $xbadset"
     set err2 [lreplace $err2 $xvidx $xvidx]
    }
    set tmp1 1  ;  set tmp2 ""
    if {$dsetng=="maxdcc"} {
     putdcc $idx "   Maximum number of file sends at once."
     set xcurrent $xpro(maxdcc)
    } elseif {$dsetng=="maxque"} {
     putdcc $idx "   Maximum number of files in queue."
     set xcurrent $xpro(maxque)
    } elseif {$dsetng=="usrmaxq"} {
     putdcc $idx "   Maximum number of queued files per user."
     set xcurrent $xpro(usrmaxq)
    } elseif {$dsetng=="astart"} {
     putdcc $idx "   Auto-Start the server when the bot starts?"
     putdcc $idx "   Set to 0 for No Auto-Start."
     putdcc $idx "   1 or more to enable (autostart delay in minutes)"
     if {$xpro(astart)=="0"} {  set tmp2 "  (Off)"
     } else {  set tmp2 " minute"  }
     set xcurrent $xpro(astart)  ;  set tmp1 0
    } elseif {$dsetng=="color"} {
     putdcc $idx "   Server Colors: Off or Choose a color scheme."
     putdcc $idx "     0  :Server Colors Off"
     putdcc $idx "     1  :Green, Red and Grey  (default)"
     putdcc $idx "     2  :Purple, Red and Grey"
     putdcc $idx "     3  :Brown, Orange and Grey"
     putdcc $idx "     4  :Dark Blue, Blue and Grey"
     putdcc $idx "     5  :Orange, Green and Grey"
     if {$xclr(color)=="0"} {  set tmp2 "  (Colors Off)" }
     set xcurrent $xclr(color)  ;  set tmp1 0
    } elseif {$dsetng=="adlayout"} {
     putdcc $idx "   Server Ad/List Layout Choices."
     putdcc $idx "     1  :Lists use pack description only"
     putdcc $idx "     2  :Lists use file name & description"
     set xcurrent $xpro(adlayout)  ;  set tmp1 0
    } elseif {$dsetng=="qtimegone"} {
     putdcc $idx "   Remove Queues for users gone this long."
     set xcurrent $xpro(qtimegone)  ;  set tmp2 " minute"
    } elseif {$dsetng=="stimegone"} {
     putdcc $idx "   Kill Sends for users gone this long."
     set xcurrent $xpro(stimegone)  ;  set tmp2 " minute"
    } elseif {$dsetng=="custom"} {
     putdcc $idx "   Use CustomColors setup?  (0 = Off | 1 = On)"
     set xcurrent $xclr(custom)
     if {$xcurrent=="0"} {  set tmp2 "  (Off)"  } else {  set tmp2 "  (On)"  }
    }
    if {$tmp1=="1"} {
     putdcc $idx "   Valid settings for $dsetng are: [xvrange $dsetng]"
    }
    if {$tmp2!="" && $xcurrent>"1"} {  set tmp3 s  } else {  set tmp3 ""  }
    putdcc $idx "   $dsetng is currently set to:  $xcurrent$tmp2$tmp3"
   }
   putdcc $idx " "
   if {$err1 != ""} {
    if {[llength $err1]=="1"} {  putdcc $idx "INPUT ERROR:  Invalid .xset option given: [join $err1]"
    } else {  putdcc $idx "INPUT ERROR:  Invalid .xset options given: [join $err1]"  }
   }
   putdcc $idx "Use: $xclr(dcc).xset -help$xclr(dcce) for more help with the .xset command"
   putdcc $idx "-----------------------------------------------------"
  }
 }
 if {$xremcnt>"0" || $avarls!=""} {  xchkvars 1  }
}

proc xstrpad {str len {phow r} } {  set temp [string length $str]  ;  set tmp2 ""
 while {$temp<$len} {  append tmp2 " "  ;  incr temp  }
 if {$phow=="r"} {  return $str$tmp2  } else {  return $tmp2$str  }
}

proc xvrange {xvr {xvopt 0} } {  set rng ""
 if {$xvr=="maxdcc"} {  set rng 1:9
 } elseif {$xvr=="maxque"} {  set rng 1:+
 } elseif {$xvr=="usrmaxq"} {  set rng 1:+
 } elseif {$xvr=="astart"} {  set rng 0:+
 } elseif {$xvr=="color"} {  set rng 0:5
 } elseif {$xvr=="adlayout"} {  set rng 1:2
 } elseif {$xvr=="qtimegone"} {  set rng 1:15
 } elseif {$xvr=="stimegone"} {  set rng 1:15
 } elseif {$xvr=="custom"} {  set rng 0:1  }
 if {$rng==""} {  return unknown
 } elseif {$xvopt=="1"} {  return $rng
 } else {  set rls [split $rng :]
  if {$rng=="0:1" || $rng=="1:2"} {  return [join $rls " and "]
  } elseif {[lindex $rls 1]!="+"} {  return [join $rls " through "]
  } else {  return "any number [lindex $rls 0] or more"  }
 }
}

proc xsplitv {xvr} {
 if {[string match "*(*)" $xvr]} {
  return [string trim [lindex [split $xvr "("] end] )]
 } else {  return $xvr  }
}

proc xvardef {xvr} {
 if {$xvr=="maxdcc"} {  return 2
 } elseif {$xvr=="maxque"} {  return 10
 } elseif {$xvr=="usrmaxq"} {  return 2
 } elseif {$xvr=="astart"} {  return 0
 } elseif {$xvr=="color"} {  return 1
 } elseif {$xvr=="adlayout"} {  return 1
 } elseif {$xvr=="qtimegone"} {  return 3
 } elseif {$xvr=="stimegone"} {  return 1
 } elseif {$xvr=="custom"} {  return 0
 } else {  return 0  }
}

proc xstrvar {str {sthow trim0} } {
 if {[xstrint $str]} {  set sisneg ""
  if {[string match -* $str]} {  set sisneg -  }
  set str [string trimleft $str -+0]
  if {$str == ""} {  set str 0  ;  set sisneg ""  }
  set str $sisneg$str
  if {$sthow=="trim0"} {  return $str  }
  set hlow [lindex [set hls [split $sthow :]] 0]
  if {$hlow != "-" && $str < $hlow} {  return 0  }
  if {[lindex $hls 1]!="+" && $str>[lindex $hls 1]} {  return 0  }
  return 1
 } else {
  if {$sthow=="trim0"} {  return not  } else {  return 0  }
 }
}

proc xfmtnik {nik} {  set nickls [split $nik]
 foreach nik $nickls {  set tnik ""
  if {[regexp {^[a-z]} $nik]} {  set tnik [string totitle $nik]
  } else {  set nkls [split $nik {}]  ;  set dcnt "-1"
   foreach ndig $nkls {  incr dcnt
    if {[regexp {^[a-z]+$} $ndig]} {
     set tnik [string replace $nik $dcnt $dcnt [string toupper $ndig]]
     break
    }
   }
  }
  if {$tnik == ""} {  set tnik $nik  }
  if {[llength $nickls]=="1"} {  return $tnik
  } else {  lappend retls $tnik  }
 }
 set nik "[join [lrange $retls 0 end-1]] & [lindex $retls end]"
 return $nik
}

proc xfrmtnum {fhow num} {  global xclr
 if {$fhow == "1"} {
   if {[string length $num] == "1"} {  set num " $num"  }
   if {[string length $num] == "2"} {  set num " \[$num\]"  } else {  set num "\[$num\]"  }
 } elseif {$fhow == "2"} {
 } elseif {$fhow == "3"} {  set num -$num
   if {[string length $num] == "2"} {  set num " $num"  }
   if {[string length $num] == "3"} {  set num " \[$num\]"  } else {  set num "\[$num\]"  }
 } elseif {$fhow == "-1"} {
   if {[string length $num] == "1"} {  set num " $num"  }
 }
 if {$fhow > "0"} {  set num "$xclr(dcc)$num$xclr(dcce) "  }
 return $num
}

proc xstrlow {str} { return [string tolower $str] }
proc xstrdig {str} { return [string is digit -strict $str] }
proc xstrint {str} { return [string is integer -strict $str] }
proc xstrtsp {str} { return [string trim [string map {"  " " "} [string map {"    " " " "   " " " "  " " "} $str]]] }

proc xhelp {hand idx text} {  global xpro xinf xclr  ;  set err 0  ;  set do ""
 if {$text ne ""} {  set text [xstrtsp [xstrlow $text]]  }
 set dlogo $xclr(dcc)$xpro(dlogo)
 if {$text eq ""} {   set err 1
 } else {  set texls [split $text]  ;  set ctxls ""
   foreach item $texls {  set input 1  ;  set iscmd 0  ;  set y $item
    if {[info exists period]} {  unset period  ;  lappend do .  ;  lappend ctxls .  }
    if {[regexp {^\.+$} $y]} {  lappend do .  ;  lappend ctxls .  ;  continue  }
    if {[regexp {^\?+$} $y]} {  lappend do .  ;  lappend ctxls .  ;  continue  }
    if {[string match *. $y]} {  set period 1  ;  set y [string trimright $y .]  }
    if {[string index $y end] eq "?"} {  set period 1  ;  set y [string trimright $y ?]  }
    if {[string match .* $y]} {  incr iscmd  ;  set y [string trimleft $y .]  }
    if {[regexp {^(do|how|i|is|it|the|that|this|we|what|would||you)$} $y]} {  lappend ctxls $y  ;  continue  }
    if {[regexp {^(a|ad|at|cancels|deletes|help|inf|info|information|lists|of|off|on|removes|reset|set|start|stat|stats|status|stop)$} $y]} {
      if {$y eq "a" && $iscmd=="0"} {  set y :a  } elseif {$y eq "a"} {  set y .a  }
      if {$iscmd=="0"} {  lappend do :$y  } else {  lappend do .$y  }
      continue
    }
    set z [string index $y 0]
    if {$z eq "a" || $z eq "+"} {
      if {[regexp {^(add|adds|adding|\+)$} $y]} {  lappend do add
      } elseif {[regexp {^(a|ad|add|adds|adding|\+)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do ap
      } elseif {[regexp {^(a|ad|add|adds|adding|\+)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do at
      } elseif {[regexp {^(a|ad|add|adds|adding|\+)(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do ac
      } elseif {[regexp {^(a|ad|add|adds|adding|\+)(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do ab
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "b"} {
      if {[regexp {^(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do ban
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "c"} {
      if {[regexp {^(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do chn
      } elseif {[regexp {^(canc|cance|cancel|canceling|cancelling)$} $y]} {  lappend do del
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do dp
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do dt
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do dc
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(q|qs|qu|qus|que|ques|queu|queue|queues)$} $y]} {  lappend do dq
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do db
      } elseif {[regexp {^(canc|cance|cancel|cancels|canceling|cancelling)(s|se|sen|send|sends|sn|sns|sens|snd|snds)$} $y]} {  lappend do ds
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "d" || $z eq "-"} {
      if {[regexp {^(d|de|del|dels|dele|delet|delete|deleting|\-)$} $y]} {  lappend do del
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do dp
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do dt
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do dc
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(q|qs|qu|qus|que|ques|queu|queue|queues)$} $y]} {  lappend do dq
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do db
      } elseif {[regexp {^(d|de|del|dels|dele|delet|delete|deletes|deleting|\-)(s|se|sen|send|sends|sn|sns|sens|snd|snds)$} $y]} {  lappend do ds
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "l"} {
      if {[regexp {^(l|li|lis|list|listing|ls)$} $y]} {  lappend do lis
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do lp
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do lt
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do lc
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(q|qs|qu|qus|que|ques|queu|queue|queues)$} $y]} {  lappend do lq
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do lb
      } elseif {[regexp {^(l|li|lis|list|lists|listing|ls)(s|se|sen|send|sends|sn|sns|sens|snd|snds)$} $y]} {  lappend do ls
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "m"} {
      if {[regexp {^(m|mo|mov|move|moves|moving)$} $y]} {  lappend do mov
      } elseif {[regexp {^(m|mo|mov|move|moves|moving)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do mp
      } elseif {[regexp {^(m|mo|mov|move|moves|moving)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do mt
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "p"} {
      if {[regexp {^(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do pak
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "q"} {
      if {[regexp {^(q|qs|qu|qus|que|ques|queu|queue|queues)$} $y]} {  lappend do que
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "r"} {
      if {[regexp {^(rem|remo|remov|remove|removing|rm)$} $y]} {  lappend do del
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(p|pa|pac|pacs|pack|packs|pk|pks|pak|paks|package|packages)$} $y]} {  lappend do dp
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do dt
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(c|ch|chs|cha|chan|chans|cn|cns|chn|chns|channel|channels)$} $y]} {  lappend do dc
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(q|qs|qu|qus|que|ques|queu|queue|queues)$} $y]} {  lappend do dq
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(b|ba|ban|bn|bns|bans)$} $y]} {  lappend do db
      } elseif {[regexp {^(rem|remo|remov|remove|removes|removing|rm)(s|se|sen|send|sends|sn|sns|sens|snd|snds)$} $y]} {  lappend do ds
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "s"} {
      if {[regexp {^(s|se|sen|send|sends|sn|sns)$} $y]} {  lappend do snd
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "t"} {
      if {[regexp {^(t|tr|trs|tri|trig|trigs|tg|tgs|trg|trgs|trigger|triggers)$} $y]} {  lappend do trg
      } else {  lappend ctxls $y  ;  continue  }
    } elseif {$z eq "x"} {
      if {[regexp {^(xh|xhe|xhel|xhelp|xhlp)$} $y]} {  lappend do xh
      } elseif {[regexp {^(xi|xin|xinf|xinfo)$} $y]} {  lappend do xi
      } elseif {[regexp {^(xr|xre|xres|xrese|xreset)$} $y]} {  lappend do xr
      } elseif {[regexp {^(xse|xset)$} $y]} {  lappend do se
      } elseif {[regexp {^(xstar|xstart)$} $y]} {  lappend do on
      } elseif {[regexp {^(xstat|xstatu|xstatus)$} $y]} {  lappend do us
      } elseif {[regexp {^(xsto|xstop)$} $y]} {  lappend do of
      } else {  lappend ctxls $y  ;  continue  }
    } else {  lappend ctxls $y  ;  continue  }
   }
   if {$do ne "" && [lindex $do end] eq "." && [lindex $ctxls end] eq "."} {
     set do [lreplace $do end end]  ;  set ctxls [lreplace $ctxls end end]
   }
   if {$do eq "" || $do eq "xh" || [string match {[.:]help} $do]} {   set err 1  }
   if {$err=="0"} {  set dls $do  ;  set tls $ctxls  ;  set cnt 0  ;  set dun 0  ;  set did ""
     while {$dun=="0"} {  incr cnt  ;  set noun ""  ;  set verb ""  ;  set othr ""  ;  set this ""
      if {[set y [lsearch -exact $dls .]]>"-1"} {
        if {$y=="0"} {  set now ""  ;  set dls [lreplace $dls 0 0]
        } else {  set now [lrange $dls 0 [expr {$y-1}]]  ;  set dls [lreplace $dls 0 $y]  }
        if {[set y [lsearch -exact $tls .]]=="0"} {  set tnow ""  ;  set tls [lreplace $tls 0 0]
        } else {  set tnow [lrange $tls 0 [expr {$y-1}]]  ;  set tls [lreplace $tls 0 $y]  }
      } else {  set now $dls  ;  set dls ""  ;  set tnow $tls  ;  set tls ""  ;  set dun 1  }
      lappend now .  ;  lappend tnow .
      if {$now ne "."} {
        foreach y $now {
         if {[string length $y]>"2"} {
           if {[string match {[.:]*} $y]} {  lappend othr $y
           } elseif {[regexp {^(add|del|mov|lis)$} $y]} {  lappend verb $y
           } elseif {[regexp {^(pak|trg|chn|que|snd|ban)$} $y]} {  lappend noun $y  }
           continue
         }
         if {$noun ne "" || $verb ne "" || $othr ne ""} {
           if {$noun eq "" && $verb eq ""} {
             if {[lsearch $othr .cancels]>"-1" || [lsearch $othr .deletes]>"-1" || [lsearch $othr .removes]>"-1"} {  set y [linsert $y 0 ds]
             } elseif {[lsearch $othr .at]>"-1"} {  set y [linsert $y 0 at]
             } elseif {[lsearch $othr .lists]>"-1"} {  set y [linsert $y 0 ls]  }
           } else {
             if {$noun ne "" && $verb eq "" && $othr ne ""} {
               if {[lsearch $othr *cancels]>"-1" || [lsearch $othr *deletes]>"-1" || [lsearch $othr *removes]>"-1"} {  lappend verb del
               } elseif {[lsearch $othr *a]>"-1" || [lsearch $othr *ad]>"-1"} {  lappend verb add
               } elseif {[lsearch $othr *lists]>"-1"} {  lappend verb lis  }
             }
             if {$noun ne "" && $verb ne ""} {  set adthis ""
               if {[llength $noun]!=[llength $verb]} {
                 if {[llength $noun]>[llength $verb]} {  set tmp 1  ;  set tm2 [llength $noun]  ;  set tm3 $verb
                 } else {    set tmp 2  ;  set tm2 [llength $verb]  ;  set tm3 $noun  }
                 set tm4 [lindex $tm3 end]
                 while {[llength $tm3]<$tm2} {  lappend tm3 $tm4  }
                 if {$tmp=="1"} {  set verb $tm3  } else {  set noun $tm3  }
               }
               foreach nn $noun vb $verb {
                if {$nn eq "ban"} {
                  if {$vb eq "add"} {  lappend adthis ab
                  } elseif {$vb eq "del"} {  lappend adthis db
                  } elseif {$vb eq "lis"} {  lappend adthis lb  }
                } elseif {$nn eq "chn"} {
                  if {$vb eq "add"} {  lappend adthis ac
                  } elseif {$vb eq "del"} {  lappend adthis dc
                  } elseif {$vb eq "lis"} {  lappend adthis lc  }
                } elseif {$nn eq "pak"} {
                  if {$vb eq "add"} {  lappend adthis ap
                  } elseif {$vb eq "del"} {  lappend adthis dp
                  } elseif {$vb eq "lis"} {  lappend adthis lp
                  } elseif {$vb eq "mov"} {  lappend adthis mp   }
                } elseif {$nn eq "que"} {
                  if {$vb eq "del"} {  lappend adthis dq
                  } elseif {$vb eq "lis"} {  lappend adthis lq  }
                } elseif {$nn eq "snd"} {
                  if {$vb eq "del"} {  lappend adthis ds
                  } elseif {$vb eq "lis"} {  lappend adthis ls  }
                } elseif {$nn eq "trg"} {
                  if {$vb eq "add"} {  lappend adthis at
                  } elseif {$vb eq "del"} {  lappend adthis dt
                  } elseif {$vb eq "lis"} {  lappend adthis lt
                  } elseif {$vb eq "mov"} {  lappend adthis mt  }
                }
               }
               set y [concat $adthis $y]
             }
           }
           set noun ""  ;  set verb ""  ;  set othr ""
           if {[llength $y]>"1" && [lindex $y end] eq "."} {  set y [lreplace $y end end]  }
         }
         if {$y eq "."} {  continue  }
         foreach z $y {  lappend this $z
          if {$z eq "ab" && [lsearch $did ab]=="-1"} {  lappend did ab  ;  xaddban $hand $idx ""
          } elseif {$z eq "ac" && [lsearch $did ac]=="-1"} {  lappend did ac  ;  xaddchan $hand $idx ""
          } elseif {$z eq "ap" && [lsearch $did ap]=="-1"} {  lappend did ap  ;  xaddpk $hand $idx ""
          } elseif {$z eq "at" && [lsearch $did at]=="-1"} {  lappend did at  ;  xaddtg $hand $idx ""
          } elseif {$z eq "db" && [lsearch $did db]=="-1"} {  lappend did db  ;  xdelban $hand $idx ""
          } elseif {$z eq "dc" && [lsearch $did dc]=="-1"} {  lappend did dc  ;  xdelchan $hand $idx ""
          } elseif {$z eq "dp" && [lsearch $did dp]=="-1"} {  lappend did dp  ;  xdelpack $hand $idx ""
          } elseif {$z eq "dq" && [lsearch $did dq]=="-1"} {  lappend did dq  ;  delfromque $hand $idx ""
          } elseif {$z eq "ds" && [lsearch $did ds]=="-1"} {  lappend did ds  ;  xkillsend $hand $idx ""
          } elseif {$z eq "dt" && [lsearch $did dt]=="-1"} {  lappend did dt  ;  xdeltrig $hand $idx ""
          } elseif {$z eq "mp" && [lsearch $did mp]=="-1"} {  lappend did mp  ;  xmovepk $hand $idx ""
          } elseif {$z eq "mt" && [lsearch $did mt]=="-1"} {  lappend did mt  ;  xmovetg $hand $idx ""  }
         }
        }
      }
     }
   }
 }
 if {$err>"0"} {
   putdcc $idx "$xclr(dcc)XDCC SERVER PRO version $xinf(ver) for Eggdrops -HELP-"
   putdcc $idx "------------------------------------------------"
   putdcc $idx "$xclr(dcc)Package commands :"
   putdcc $idx "  .lpack                      : List the packages offered"
   putdcc $idx "  .apack <file>,<description> : Add a pack (for files in default path)"
   putdcc $idx "  .apack </route/file>,<desc> : Add a pack (file in a different route)"
   putdcc $idx "  .mpack <pack> <destination> : Move a pack to different list position"
   putdcc $idx "  .dpack <packnumber>         : Delete a package"
   putdcc $idx "$xclr(dcc)Channels commands :"
   putdcc $idx "  .lchan                : List the server channels"
   putdcc $idx "  .achan <channel>      : Add a server channel"
   putdcc $idx "  .dchan <channel>      : Delete a server channel"
   putdcc $idx "$xclr(dcc)Server commands :"
   putdcc $idx "  .xstart                : Start the server"
   putdcc $idx "  .xstop                 : Stop the server"
   putdcc $idx "  .xset <option> <value> : Change value of many tcl settings"
   putdcc $idx "  .xstatus               : Server status"
   putdcc $idx "  .xreset <option>       : Reset file download totals"
   putdcc $idx "$xclr(dcc)Queues commands :"
   putdcc $idx "  .lque                 : List the files in queue"
   putdcc $idx "  .dque <que# or nick>  : Delete file from que OR all ques for nick"
   putdcc $idx "$xclr(dcc)Sends commands :"
   putdcc $idx "  .lsend                : List the active sends"
   putdcc $idx "  .dsend <snd# or nick> : Kill a file send"
   putdcc $idx "$xclr(dcc)Server Bans commands :"
   putdcc $idx "  .lban                 : List the server bans"
   putdcc $idx "  .aban <mask or nick>  : Add a ban to the server ban list"
   putdcc $idx "  .dban <ban# or nick>  : Delete a ban from the server ban list"
   putdcc $idx "$xclr(dcc)Other commands :"
   putdcc $idx "  .xhelp                : This help"
   putdcc $idx "  .xinfo                : The infos"
   putdcc $idx "------------------------------------------------"
   putdcc $idx "For help with a command, do the command by itself."
   putdcc $idx "example: $xclr(dcc).apack$xclr(dcce) (get help for the add pack command)"
   putdcc $idx " "
   putdcc $idx "$xclr(dcc)XDCC SERVER PRO by $xinf(auth)"
 }
}

proc xinfos {handle idx text} {  global xinf xclr
 putdcc $idx "$xclr(dcc)XDCC SERVER PRO version $xinf(ver) by SpiKe^^"
 putdcc $idx "Contact Options to report bugs, comments & suggestions:"
 putdcc $idx "    webpage: $xclr(dcc)www.mytclscripts.com"
 putdcc $idx "        irc: $xclr(dcc)undernet: #pc-mIRC-help"
 putdcc $idx "      email: $xclr(dcc)spike@mytclscripts.com"
 putdcc $idx "Use: $xclr(dcc).xhelp$xclr(dcce) for help running XDCC SERVER PRO"
}

proc xmovepk {h i t} {  xaddpk $h $i $t 1  }

# ---------------------------------------------------
# PACKAGE COMMANDS CODE  (DCC: LIST/ADD/DEL PACKAGES)
# ---------------------------------------------------
proc xlistpacks {handle idx text {from 0} } {  global xpro xfil xclr
 if {$from=="0"} {  set flname $xfil(packs)  ;  set flnam2 $xfil(cpack)
   putdcc $idx "$xclr(dcc)$xpro(dlogo) List all packs offered..."
 } else {  set flname $xfil(trigs)  ;  set flnam2 $xfil(ctrig)
   putdcc $idx "$xclr(dcc)$xpro(dlogo) List all public file triggers..."
 }
 set count 0
 if {[file exists $flname]} {
   set xpkfile [open $flname r]  ;  set xcpkfile [open $flnam2 r]
   while {![eof $xpkfile]} {  set temp [gets $xpkfile]  ;  set temp2 [gets $xcpkfile]
    if {$temp != ""} {  incr count  ;  set size [xfrmtsize 2 [lindex $temp 3]]
      if {[string length $count]=="1"} {  set pcnt " $count"  } else {  set pcnt $count  }
      if {[string length $pcnt]=="2"} {  set putthis " "  } else {  set putthis ""  }
      putdcc $idx "$putthis$xclr(dcc)\[$pcnt\]$xclr(dcce)  [lindex $temp 2]  $xclr(dcc)($size|$temp2\X)$xclr(dcce)"
      if {$from=="0"} {  putdcc $idx "      [lindex $temp 1]"
      } else {  putdcc $idx "      $xclr(dcc)[lindex $temp 0]$xclr(dcce)  [lindex $temp 1]"  }
    }
   }
   close $xpkfile  ;  close $xcpkfile
   if {$count>"0"} {  set stuffsent "Nothing sent yet"
     if {$from=="0"} {  set frmtbtotal "[xfrmtsize 2 $xpro(packbytes)]"
       if {$xpro(packssent) == "1"} {  set stuffsent "Sent one pack ([xfrmtsize 2 $xpro(bytessent)])"
       } elseif {$xpro(packssent) > "1"} { set stuffsent "Sent $xpro(packssent) packs ([xfrmtsize 2 $xpro(bytessent)])" }
       if {$count == "1"} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Serving one package ($frmtbtotal) | $stuffsent"
       } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Serving $count packages ($frmtbtotal) | $stuffsent" }
     } else {  set frmtbtotal "[xfrmtsize 2 $xpro(trigbytes)]"
       if {$xpro(trigssent) == "1"} {  set stuffsent "Sent one file ([xfrmtsize 2 $xpro(tbytesent)])"
       } elseif {$xpro(packssent) > "1"} { set stuffsent "Sent $xpro(trigssent) files ([xfrmtsize 2 $xpro(tbytesent)])" }
       if {$count == "1"} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) One active public file trigger ($frmtbtotal) | $stuffsent"
       } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) $count active public file triggers ($frmtbtotal) | $stuffsent" }
     }
   }
 }
 if {$count=="0"} {
   if {$from=="0"} {  putdcc $idx "No packs offered."
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).apack$xclr(dcce) for help adding packs"
   } else {  putdcc $idx "No public file triggers."
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).atrig$xclr(dcce) for help adding triggers"
   }
 }
}

proc xaddpk {handle idx text {from 0} } {  global iso xpro xfil xclr
 set text [string trimleft $text]  ;  set putat ""
 if {$from<"2"} {  set ficnt $xpro(packcount)
   if {[file exists $xfil(packs)]} {  set have 1  }
   set fnam1 $xfil(packs)  ;  set fnam2 $xfil(cpack)
 } else {  set ficnt $xpro(trigcount)
   if {[file exists $xfil(trigs)]} {  set have 1  }
   set fnam1 $xfil(trigs)  ;  set fnam2 $xfil(ctrig)
 }
 if {$from=="1" || $from=="3"} {  set do ""  ;  set merls ""
   if {$text eq ""} {  set err 1
   } else {   set txls [split [string map {# ""} [xstrlow $text]]]
     if {[llength $txls]>"1"} {  set tmp [lindex $txls end]
       if {[regexp {^(e(n(d)?)?)$} $tmp]} {  set tmp $ficnt  }
       if {[xstrdig $tmp]} {
         if {$tmp<"1"} {  set tmp 1  }
         if {$tmp>$ficnt} {  set tmp $ficnt  }
         set putat $tmp
         set txls [lrange $txls 0 end-1]
       }
     }
     if {![info exists have]} {  set err 2
     } else {
       set fils [split [xstrtsp [string map {, " "} [join $txls]]]]
       foreach file $fils {
        if {[string match *+* $file]} {  set file [string trim $file +]
          if {[xstrdig $file] && $file>"1" && $file<=$ficnt} {
            if {$file<$ficnt} {  append file -$ficnt  }
          }
        } elseif {[string match -* $file] || [string match *- $file]} {  set file [string trim $file -]
          if {[xstrdig $file] && $file>"1" && $file<$ficnt} {  set file 1-$file  }
        }
        set file [split $file -]  ;  foreach {t1 t2} $file { break }
        if {[xstrdig $t1] && $t1>"0" && $t1<=$ficnt} {
          if {[set tmp [lsearch -exact $do $t1]]>"-1"} {  set do [lreplace $do $tmp $tmp]  }
          lappend do $t1
          if {$t1<$ficnt && $t2 ne ""} {
            if {[regexp {^(e(n(d)?)?)$} $t2]} {  set t2 $ficnt  }
            if {[xstrdig $t2] && $t2>$t1} {
	      if {$t2>$ficnt} {  set t2 $ficnt  }
	      while {$t1<$t2} {  incr t1
	       if {[set tmp [lsearch -exact $do $t1]]>"-1"} {  set do [lreplace $do $tmp $tmp]  }
               lappend do $t1
              }
            }
          }
        } else {  lappend merls [join $file -]  }
       }
       if {$do eq ""} {  set err 3  }
     }
   }
 } else {
   if {[string match -nocase {[-#+][0-9aelsu]*} $text]} {
     set txls [split $text]  ;  set do [lrange $txls 0 0]
     if {$from=="0" && [llength $txls]>"1" && [string match -nocase {[-#][0-9elsua]*} [lindex $txls 1]]} {
       lappend do [lindex $txls 1]
     }
     foreach item $do {  set isarg 0  ;  set temp [xstrlow [string range $item 1 end]]
      if {[string match {[-#][0-9]*} $item] && [xstrdig $temp]} {  set putat $temp  ;  set isarg 1
      } elseif {[string match -nocase {[-+]a*} $item] && [regexp {^(a(l(l)?)?)$} $temp]} {
        if {$from=="0"} {  set all 1  ;  set isarg 1  }
      } elseif {[string match -nocase {[-#]l*} $item] && [regexp {^(l(a(s(t)?)?)?)$} $temp]} {
        set putat e  ;  set isarg 1
      } elseif {[string match -nocase {[-#]e*} $item] && [regexp {^(e(n(d)?)?)$} $temp]} {
        set putat e  ;  set isarg 1
      } elseif {[string match -nocase {[-#]s*} $item] && [regexp {^(s(a(m(e)?)?)?)$} $temp]} {
        if {[info exists have]} {  set putat s  }   ;  set isarg 1
      } elseif {[string match -nocase {[-#]u*} $item] && [regexp {^(u(p(d(a(t(e)?)?)?)?)?)$} $temp]} {
        if {[info exists have]} {  set putat s  }   ;  set isarg 1
      }
      if {$isarg=="1"} {  set txls [lreplace $txls 0 0]  } else {  break  }
     }
     set text [string trimleft [join $txls]]  ;  unset do
   }
   if {[info exists all] && $putat eq "s"} {  set putat ""  }
   set pakls ""  ;  set edir ""
   if {$text eq ""} {
     if {[info exists all]} {  set etmp ""  ;  set gtmp ""  ;  set chkgone $xpro(defpath)
       foreach dtmp $xpro(defpath) {
        if {![file isdirectory $dtmp]} {  lappend etmp $dtmp  } else {  lappend gtmp $dtmp  }
       }
       if {$gtmp eq ""} {  set err 2  ;  set edir $etmp  } else {  set adir $gtmp  }
     } else {  set err 1  }
   } else {  set new ""
     if {[info exists all]} {  set text [string map {, ,,} [string map {,,, , ,, ,} $text]]  }
     if {[set next [string first ,, $text]]>"-1"} {  set erls ""
       lappend new [string range $text 0 [expr {$next-1}]]
       while {$next>"-1"} {  set start [expr {$next+2}]
        set next [string first ,, $text $start]
	if {$next=="-1"} {  lappend new [string trimleft [string range $text $start end]]  ;  break
	} else {  lappend new [string trimleft [string range $text $start [expr {$next-1}]]]  }
       }
     } else {  lappend new $text  }
     if {[info exists all]} {  set chkgone $new  }
     foreach text $new {
      if {$from=="2"} {  set temp [split $text]
        if {[llength $temp]=="1"} {
          if {[info exists erls]} {  lappend erls $text  } else {  set err 3  }   ;  continue
        } else {  set trig [lindex $temp 0]  ;  set text [join [lrange $temp 1 end]]  }
      }
      set pkinfotmplist [split $text ,]  ;  set pktmp [string trim [lindex $pkinfotmplist 0]]
      if {[info exists all]} {
        if {![file isdirectory $pktmp]} {  set err 2  ;  lappend edir $pktmp
        } else {  lappend adir $pktmp  }
      } else {
        if {![string match */* $pktmp]} {  set xindef 1
          foreach ptmp $xpro(defpath) {  set pack $ptmp$pktmp
           if {[file exists $pack] && [file isfile $pack]} {  break  }
          }
        } else {  set pack $pktmp  ;  set xindef 0  }
        if {![file exists $pack] || ![file isfile $pack]} {
	  if {[info exists erls]} {  lappend erls $pack  } else {  set err 2  }
        } else {
          if {$from=="2"} {  set pack "$trig $pack"  }
          if {[llength $pkinfotmplist]=="1" || [lindex $pkinfotmplist 1] eq ""} {
	    lappend pakls $pack ""
          } else {  lappend pakls $pack [join [lrange $pkinfotmplist 1 end] ,]  }
        }
      }
     }
     if {[info exists all]} {
       if {[info exists adir] && [info exists err]} {  unset err  }
     } elseif {[info exists erls] && $pakls eq ""} {  set err 2  }
   }
   if {![info exists err] && [info exists all]} {  set newadir ""  ;  set etmp ""  ;  set gtmp ""
     foreach dtmp $adir {
      set dirls [glob -directory $dtmp -types f -nocomplain *]
      if {$dirls eq ""} {  lappend etmp $dtmp
      } else {  lappend newadir $dtmp
        foreach y $dirls {  lappend gtmp $y  }
      }
     }
     set adir $newadir
     if {$gtmp eq ""} {  set err 3  ;  set edir $etmp
     } else {
       foreach temp $gtmp {  lappend pakls $temp ""  }
     }
   }
   if {[info exists all] && $idx ne "*" && $xpro(alldel) ne "0"} {
     if {$xpro(alldel) eq "2"} {  set deled [xremgone 0 * $idx *]
     } else {  set deled [xremgone 0 * $idx [join $chkgone ,]]  }
     if {$deled=="0"} {  unset deled  }
   }
 }
 set plogo $xclr(dcc)$xpro(dlogo)
 if {[info exists err]} {  set hbar ---------------------------------------------------------
   if {$from=="0"} {
     if {[info exists all]} {
       if {$idx ne "*"} {  set tpre ""
         if {![info exists deled]} {  set tpre "$plogo$xclr(dcce) "  }
         putdcc $idx "$plogo Add All New Packs In: [join $edir] ..."
         if {$err=="2"} {
           if {[llength $edir]>"1"} {  putdcc $idx "${tpre}Those Directories Do Not Exist."
           } else {  putdcc $idx "${tpre}That Directory Does Not Exist."  }
         } else {
           if {[llength $edir]>"1"} {  putdcc $idx "${tpre}No Files In Those Directories."
           } else {  putdcc $idx "${tpre}No Files In That Directory."  }
         }
         if {[info exists deled]} {
           if {$iso=="1" && $deled==$xpro(packcount)} {  putdcc $idx "  "
             putdcc $idx "Removed All packs!  Turning server OFF...."
             xstop $handle $idx $text  ;  readpackinfos
           } else {  readpackinfos  ;  set ftot "[xfrmtsize 2 $xpro(packbytes)]"
             if {$xpro(packcount)=="0"} {  putdcc $idx "$plogo$xclr(dcce) Removed ALL packs!"
             } elseif {$xpro(packcount)=="1"} {  putdcc $idx "$plogo$xclr(dcce) Now serving one package ($ftot)"
             } else {  putdcc $idx "$plogo$xclr(dcce) Now serving $xpro(packcount) packages ($ftot)"  }
           }
         }
       }
     } else {  set help 1
       if {$err=="1"} {  putdcc $idx $hbar--
         putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Add Pack command  \[.apack <file>,<desc>\]"
       } elseif {[info exists erls]} {  putdcc $idx $hbar---
         putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Files don't exist or wrong use of command"
         putdcc $idx "Files given:  [join $erls "  "]"
       } else {  set help 0  ;  putdcc $idx $hbar----
         putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) File doesn't exist or wrong use of command"
         if {$xindef=="1"} {
           putdcc $idx "File name given was:  $pktmp"
           putdcc $idx "DefPath for this command is currently set to: [join $xpro(defpath)]"
         } else {  putdcc $idx "Filename & route given was:  $pack"  }
       }
       putdcc $idx ".apack usage : .apack <filename>,<description>"
       if {$help=="1"} {
         putdcc $idx " for files in <defpath>.  (now set to: [join $xpro(defpath)])"
         putdcc $idx ".apack usage : .apack <./route/filename>,<description>"
         putdcc $idx " for files not in <defpath>. (must be in the bot directory)"
       } else {  putdcc $idx "          or : .apack <./route/filename>,<description>"  }
       putdcc $idx "Put ONE comma between the <filename> and the <description>"
       putdcc $idx "NO other comma's allowed in the file name or route !!"
       putdcc $idx "example : $xclr(dcc).apack file name.txt,Description of the file"
       putdcc $idx "Advanced Add Pack Command Examples:"
       putdcc $idx " $xclr(dcc).apack file1.gz,Desc,,file2.gz,Desc$xclr(dcce)  (add 2 or more packs)"
       putdcc $idx " $xclr(dcc).apack #3 file.gz,Desc$xclr(dcce)    (add a pack at list position #3)"
       putdcc $idx " $xclr(dcc).apack #end file.gz,Desc$xclr(dcce)   (add a pack at end of the list)"
       putdcc $idx " $xclr(dcc).apack #same file,Desc$xclr(dcce)  (update pack desc, at same list #)"
       putdcc $idx " $xclr(dcc).apack #1 -all$xclr(dcce)     (add all new packs in <defpath>, at #1)"
       putdcc $idx " $xclr(dcc).apack #e -a ./pak/$xclr(dcce)  (add all new packs in ./pak/, at end)"
       putdcc $idx " $xclr(dcc).apack -a ./pak/,./irc/$xclr(dcce)  (multiple paths, comma separated)"
       if {$err=="1"} {  putdcc $idx $hbar--
       } elseif {[info exists erls]} {  putdcc $idx $hbar---
       } else {  putdcc $idx $hbar----  }
     }
   } elseif {$from=="1"} {
     if {$err=="2"} {  set tmp :
       if {[llength $txls]>"1" || ![xstrdig [lindex $txls 0]]} {  set tmp (s):  }
       putdcc $idx "$plogo Move Pack$tmp [string map {, " "} [join $txls]] ..."
       putdcc $idx "No packs offered."
       putdcc $idx "$plogo$xclr(dcce) Use: $xclr(dcc).apack$xclr(dcce) for help adding packs"
     } else {  putdcc $idx $hbar-----
       putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Move Pack command \[.mpack <pack(s)> <dest>\]"
       if {$err=="3"} {
         putdcc $idx ".mpack given was:  [join $merls]  (Not valid input!)"
       }
       putdcc $idx ".mpack usage : .mpack <packnumber(s)> <destination>"
       putdcc $idx "example : $xclr(dcc).mpack 4 2$xclr(dcce)  (move pack #4 to new list position #2)"
       putdcc $idx "Advanced Move Pack Command Examples:"
       putdcc $idx " $xclr(dcc).mpack 5$xclr(dcce)    (move pack 5 to the current default add position)"
       putdcc $idx " $xclr(dcc).mpack 3 7 4 1$xclr(dcce)  (move packs 3 7 & 4 to beginning of the list)"
       putdcc $idx " $xclr(dcc).mpack 3-5 end$xclr(dcce)  (move packs 3 4 & 5 to the end of the list)"
       putdcc $idx " $xclr(dcc).mpack 3- e$xclr(dcce)     (move packs 1 2 & 3 to the end of the list)"
       putdcc $idx " $xclr(dcc).mpack 6+ 1$xclr(dcce)     (move all packs numbered 6 and higher to #1)"
       putdcc $idx " $xclr(dcc).mpack 2 4-6 1$xclr(dcce)  (move packs 2 4 5 & 6 to beginning of list)"
       putdcc $idx " $xclr(dcc).mpack 2,4-6,1$xclr(dcce)  (move 2 4 5 6 & 1 to default add position)"
       if {$err=="3"} {
         if {$xpro(packcount)=="1"} {  set tmp "one package."  ;  set tm2 "that pack."
         } else {  set tmp "$xpro(packcount) packages."  ;  set tm2 "all packs."  }
         putdcc $idx "Serving $tmp  Use: $xclr(dcc).lpack$xclr(dcce) :to list $tm2"
       }
       putdcc $idx $hbar-----
     }
   }
   return 0
 }
 if {$putat eq ""} {
   if {$xpro(defadd) eq "2"} {  set putat e  } else {  set putat 1  }
 }
 set pat $putat
 if {$pat eq "e"} {  set pat end  } elseif {$pat eq "s"} {  set pat same  }
 if {[info exists pakls]} {  set logadd ""  ;  set logupd ""  ;  set logall ""
   set adnum [expr {[llength $pakls]/2}]
   if {$from=="0"} {
     if {[info exists erls] && $erls ne ""} {
       if {[llength $erls]=="1"} {  set tmp "This file doesn't exist:  [join $erls]"
       } else {  set tmp "These files don't exist:  [join $erls "  "]"  }
       putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) $tmp"  ;  putdcc $idx " "
     }
     if {[info exists all]} {
       if {$idx ne "*"} {  putdcc $idx "$plogo Add All New Packs In: [join $adir] ..."  }
     } elseif {[info exists erls] && $adnum>"1"} {
       if {$putat eq "s"} {  putdcc $idx "$plogo Update $adnum Packs ..."
       } else {  putdcc $idx "$plogo Add $adnum Packs at Position #$pat ..."  }
     } else {
       if {[info exists erls]} {  set pack [lindex $pakls 0]  }
       if {$putat eq "s"} {  putdcc $idx "$plogo Update Pack: $pack ..."
       } else {  putdcc $idx "$plogo Add Pack: $pack ..."  }
     }
   } else {
     if {[info exists erls] && $adnum>"1"} {
       if {$putat eq "s"} {  putdcc $idx "$plogo Update File/Description for $adnum Triggers ..."
       } else {  putdcc $idx "$plogo Add $adnum Download Triggers at Position #$pat ..."  }
     } else {
       if {[info exists erls]} {  set trig [lindex [split [lindex $pakls 0]] 0]  }
       if {$putat eq "s"} {  putdcc $idx "$plogo Update File/Description for: $trig ..."
       } else {  putdcc $idx "$plogo Add Public Download Trigger: $trig ..."  }
     }
   }
   set new ""
   foreach {pack dsc} $pakls {
    if {$dsc eq ""} {  set fileonly [lindex [split $pack /] end]
      if {[string match "*.*" $fileonly]} {  set filelist [split $fileonly .]
        if {[string length [lindex $filelist end]] < "5"} {
          if {[llength $filelist] == "2"} {  set fileonly [lindex $filelist 0]
          } else {  set fileonly [join [lrange $filelist 0 end-1] .]  }
        }
      }
      set desc [string map {_ " "} $fileonly]
    } else {  set desc $dsc  }
    lappend new $pack $desc
   }
   set pakls $new
 } else {  set logmov ""
   if {$from=="1"} {
     if {[llength $do]=="1"} {  putdcc $idx "$plogo Move Pack #$do ..."
     } else {  putdcc $idx "$plogo Move Packs: $do ..."  }
   }
 }
 set xists ""  ;  set xpkls ""  ;  append plogo $xclr(dcce)
 if {[info exists have]} {  set count 0  ;  set tg ""
   if {$putat eq "s"} {  set samls $pakls  }
   set xpkfile [open $fnam1 r]  ;  set xcpkfile [open $fnam2 r]
   while {![eof $xpkfile]} {  set temp [gets $xpkfile]  ;  set tmp2 [gets $xcpkfile]
    if {$temp != ""} {  incr count
      foreach {pn pk dc bt} $temp {  break  }
      if {$from>"1"} {  set tg $pn  }
      set pn $count  ;  set lt [list $pn $pk [list $dc $bt $tmp2] $tg]
      if {[info exists pakls]} {
        if {$from=="0"} {  set sthis $pk  } else {  set sthis "$tg *"  }
        set tidx [lsearch $pakls $sthis]
        if {$tidx>"-1"} {
          if {$putat eq "s"} {  set id2 [lsearch $samls $sthis]
            set samls [lreplace $samls $id2 [expr {$id2+1}]]
          }
          if {![info exists all]} {  lappend xists $lt
          } else {  lappend xpkls $lt  ;  set pakls [lreplace $pakls $tidx [expr {$tidx+1}]]  }
        } else {  lappend xpkls $lt  }
      } else {
        if {[lsearch $do $pn]>"-1"} {  lappend xists $lt  } else {  lappend xpkls $lt  }
      }
    }
   }
   close $xpkfile  ;  close $xcpkfile
   if {[info exists pakls] && $pakls eq ""} {
     if {[info exists all] && $idx ne "*"} {  set tpre ""
       if {![info exists deled]} {  set tpre "$plogo "  }
       if {[llength $adir]=="1"} {  putdcc $idx "${tpre}No NEW Packs in that Directory."
       } else {  putdcc $idx "${tpre}No NEW Packs in those Directorys."  }
       if {[info exists deled]} {
         if {$iso=="1" && $deled==$xpro(packcount)} {  putdcc $idx "  "
           putdcc $idx "Removed All packs!  Turning server OFF...."
           xstop $handle $idx $text  ;  readpackinfos
         } else {  readpackinfos  ;  set ftot "[xfrmtsize 2 $xpro(packbytes)]"
           if {$xpro(packcount)=="0"} {  putdcc $idx "$plogo Removed ALL packs!"
           } elseif {$xpro(packcount)=="1"} {  putdcc $idx "$plogo Now serving one package ($ftot)"
           } else {  putdcc $idx "$plogo Now serving $xpro(packcount) packages ($ftot)"  }
         }
       }
     }
     return 0
   }
   if {$putat eq "s" && $samls ne ""} {  set notsame $samls
     foreach {pk dc} $notsame {  set tidx [lsearch $pakls $pk]
      set pakls [lreplace $pakls $tidx [expr {$tidx+1}]]
     }
     if {$pakls eq ""} {  set pakls $notsame  ;  unset notsame
       if {$xpro(defadd) eq "2"} {  set putat e  } else {  set putat 1  }
     }
   }
 }
 if {[info exists all]} {  set ainfo ""
   foreach {y z} $pakls {  set y [file dirname $y]
    if {[lsearch $ainfo $y]=="-1"} {
      if {$ainfo ne ""} {  lappend ainfo $cnt  }
      lappend ainfo $y  ;  set cnt 1
    } else {  incr cnt  }
   }
   lappend ainfo $cnt
 }
 set xpkfile [open $fnam1 w]  ;  set xcpkfile [open $fnam2 w]
 set trucnt 0  ;  set count 0  ;  set dun 0
 if {$putat eq "s"} {  set same 1  ;  set putat ""  }
 if {[info exists pakls]} {  set input $pakls  } else {  set input ""  }
 if {[llength $xists]=="1"} {  set logwas [lindex $xists 0 0]  }
 while {$dun=="0"} {  incr count
  if {[info exists same] && $putat eq "" && $xists ne ""} {  set putat [lindex $xists 0 0]  }
  if {$xpkls eq ""} {  set putat $count  }
  if {$trucnt=="0" && [info exists notsame] && $xpro(defadd) ne "2"} {
    set dun 2
  } elseif {$putat eq $count} {
    if {[info exists same]} {  set putat ""  ;  incr trucnt
      foreach {pn pk ols tg} [lindex $xists 0] {  break  }
      foreach {dc bt tb} $ols {  break  }
      set xists [lreplace $xists 0 0]
      if {$from=="0"} {  set sthis $pk  } else {  set sthis "$tg *"  }
      set tidx [lsearch $input $sthis]
      set ptmp [lindex $input $tidx]  ;  set dc [lindex $input [expr {$tidx+1}]]
      set input [lreplace $input $tidx [expr {$tidx+1}]]
      if {$from=="2"} {  set pk [join [lrange [split $ptmp] 1 end]]  }
      set bt [file size $pk]
      if {$from=="0"} {  set i0 $trucnt  } else {  set i0 $tg  }
      puts $xpkfile [list $i0 $pk $dc $bt]  ;  puts $xcpkfile $tb
      lappend logupd $trucnt $tg $pk $dc $bt $tb  ;  lappend logall $trucnt $tg $pk $dc $bt $tb
    } else {
      if {[info exists pakls]} {  set tg ""
        foreach {pk dc} $input {  incr trucnt  ;  set tb 0
         if {$from=="2"} {  set pk [split $pk]
           set i0 [lindex $pk 0]  ;  set tg $i0  ;  set pk [join [lrange $pk 1 end]]
         } else {  set i0 $trucnt  }
         set bt [file size $pk]  ;  set fnd 0  ;  set licnt -1
         foreach item $xists {  incr licnt
          foreach {pn epk ols etg} $item {  break  }
          if {$from=="0"} {
            if {$epk eq $pk} {  set fnd 1
              foreach {edc ebt tb} $ols {  break  }
              break
            }
          } else {
            if {$etg eq $tg} {  set fnd 1
              foreach {edc ebt tb} $ols {  break  }
              if {$epk ne $pk} {  set tb 0  }
              break
            }
          }
         }
         lappend logall $trucnt $tg $pk $dc $bt $tb
         if {$fnd=="1"} {  set xists [lreplace $xists $licnt $licnt]
           lappend logupd $trucnt $tg $pk $dc $bt $tb
         } else {  lappend logadd $trucnt $tg $pk $dc $bt $tb  }
         puts $xpkfile [list $i0 $pk $dc $bt]  ;  puts $xcpkfile $tb
         incr count
        }
        incr count -1  ;  set xists ""  ;  set input ""
      } else {
        foreach pknum $do {  set fnd 0  ;  set licnt -1
         foreach item $xists {  incr licnt
          foreach {pn pk ols tg} $item {  break  }
          if {$pn==$pknum} {  set fnd 1
            foreach {dc bt tb} $ols {  break  }
            break
          }
         }
         if {$fnd=="1"} {  set xists [lreplace $xists $licnt $licnt]  ;  incr trucnt
           if {$from=="1"} {  set i0 $trucnt  } else {  set i0 $tg  }
           puts $xpkfile [list $i0 $pk $dc $bt]  ;  puts $xcpkfile $tb  ;  incr count
           lappend logmov $trucnt $tg $pk $dc $bt $tb
         }
        }
        set xists ""  ;  incr count -1
      }
    }
  } else {
    if {$xpkls ne ""} {  incr trucnt
      foreach {pn pk ols tg} [lindex $xpkls 0] {  break  }
      foreach {dc bt tb} $ols {  break  }
      set xpkls [lreplace $xpkls 0 0]
      if {$from<"2"} {  set i0 $trucnt  } else {  set i0 $tg  }
      puts $xpkfile [list $i0 $pk $dc $bt]  ;  puts $xcpkfile $tb
    }
  }
  if {$xpkls eq "" && $xists eq "" && $input eq ""} {  set dun 1  }
  if {$dun>"0" && [info exists notsame]} {
    foreach {pk dc} $notsame {  incr trucnt
     if {$from=="0"} {  set i0 $trucnt
     } else {  set pk [split $pk]  ;  set i0 [lindex $pk 0]  ;  set pk [join [lrange $pk 1 end]]  }
     set bt [file size $pk]
     puts $xpkfile [list $i0 $pk $dc $bt]  ;  puts $xcpkfile 0
     lappend logadd $trucnt $tg $pk $dc $bt 0  ;  lappend logall $trucnt $tg $pk $dc $bt 0
    }
    if {$dun=="2"} {  set dun 0  ;  incr count -1  ;  unset notsame  }
  }
 }
 close $xpkfile  ;  close $xcpkfile
 if {$idx ne "*"} {  readpackinfos  }
 if {[info exists pakls]} {
   set added [expr {[llength $logadd]/6}]  ;  set upded [expr {[llength $logupd]/6}]
   set adtot [expr {$added+$upded}]
   if {$from=="0"} {
     if {[info exists all]} {
       if {$idx eq "*"} {
         foreach {y z} $ainfo {
          if {$z=="1"} {  putlog "\[XPro Auto-Add\] Added one new pack in $y ..."
          } else {  putlog "\[XPro Auto-Add\] Added $z new packs in $y ..."  }
         }
         return $added
       }
       if {$added=="1"} {  putdcc $idx "Added one new pack"
       } else {  putdcc $idx "Added $added new packs"  }
       lappend dopks $logadd  ;  set close 1
     } elseif {[info exists erls] && $adtot>"1"} {  set puttx ""  ;  set close 1
       if {[info exists same]} {
         if {$added=="1"} {  set atmp "one new pack"  } else {  set atmp "$added new packs"  }
         if {$upded=="1"} {  set utmp "one pack"  } else {  set utmp "$upded packs"  }
         if {$added>"0" && $xpro(defadd) ne "2"} { set puttx "Added $atmp" ; lappend dopks $logadd }
         lappend dopks $logupd
         if {$puttx eq ""} {  set puttx "Updated $utmp"  } else {  set putt2 "Updated $utmp"  }
         if {$added>"0" && $xpro(defadd) eq "2"} { set putt2 "Added $atmp" ; lappend dopks $logadd }
         putdcc $idx $puttx
       } else {  lappend dopks $logall
         if {$added>"0"} {  set puttx Added  }
         if {$upded>"0"} {
           if {$puttx ne ""} {  append puttx /Updated  } else {  set puttx Updated/Moved  }
         }
         append puttx " $adtot"
         if {$upded=="0"} {  append puttx " new"  }   ;  putdcc $idx "$puttx packs"
       }
     } else {  set close 1
       foreach {pn tg pk dc bt tb} $logall {  break  }
       if {$added>"0"} {  putdcc $idx "Added new pack #$pn  Desc: $dc"
       } else {  set puttx ""
         if {![info exists same]} {  set puttx "Pack already offered. "  }
         append puttx "Updated description"
         if {$logwas!=$pn} {  putdcc $idx "$puttx & moved to pack #$pn"
         } else {  append puttx " for pack #$pn"
           if {[info exists same]} {  append puttx "  Desc: $dc"  }
           putdcc $idx $puttx
         }
       }
     }
   }
   if {[info exists dopks]} {  set loop 1
     foreach files $dopks {
      if {$loop>"1"} {  putdcc $idx $putt2  }
      foreach {pn tg pk dc bt tb} $files {  set bt [xfrmtsize 2 $bt]  ;  set pn [xstrpad $pn 2 l]
       if {[string length $pn]=="2"} {  set putthis " "  } else {  set putthis ""  }
       if {$upded>"0"} {  set temp |$tb\X  } else {  set temp ""  }
       putdcc $idx "$putthis$xclr(dcc)\[$pn\]$xclr(dcce)  $dc  $xclr(dcc)($bt$temp)$xclr(dcce)"
       if {$from=="0"} {  putdcc $idx "      $pk"
       } else {  putdcc $idx "      $xclr(dcc)$tg$xclr(dcce)  $pk"  }
      }
      incr loop
     }
   }
   if {[info exists close]} {
     if {$from=="0"} {  set frmtbtotal "[xfrmtsize 2 $xpro(packbytes)]"
       if {$added>"0"} {  set temp Now  } else {  set temp Still  }
       if {$trucnt=="1"} { putdcc $idx "$plogo $temp serving one package ($frmtbtotal)"
       } else { putdcc $idx "$plogo $temp serving $trucnt packages ($frmtbtotal)" }
     } else {  set frmtbtotal "[xfrmtsize 2 $xpro(trigbytes)]"
       if {$trucnt=="1"} { putdcc $idx "$plogo One active public file trigger ($frmtbtotal)"
       } else { putdcc $idx "$plogo $trucnt active public file triggers ($frmtbtotal)" }
     }
   }
 } else {
   set moved [expr {[llength $logmov]/6}]
   if {$from=="1"} {
     if {$merls ne ""} {
       putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Not valid mpack input! \[[join $merls]\]"
     }
     if {$moved=="1"} {  putdcc $idx "Moved one pack"
     } else {  putdcc $idx "Moved $moved packs"  }
   }
   foreach {pn tg pk dc bt tb} $logmov {  set bt [xfrmtsize 2 $bt]  ;  set pn [xstrpad $pn 2 l]
    if {[string length $pn]=="2"} {  set putthis " "  } else {  set putthis ""  }
    putdcc $idx "$putthis$xclr(dcc)\[$pn\]$xclr(dcce)  $dc  $xclr(dcc)($bt|$tb\X)$xclr(dcce)"
    if {$from=="1"} {  putdcc $idx "      $pk"
    } else {  putdcc $idx "      $xclr(dcc)$tg$xclr(dcce)  $pk"  }
   }
   if {$from=="1"} {  set frmtbtot "[xfrmtsize 2 $xpro(packbytes)]"
     if {$trucnt=="1"} {  putdcc $idx "$plogo Serving one package ($frmtbtot)"
     } else {  putdcc $idx "$plogo Serving $trucnt packages ($frmtbtot)"  }
   }
 }
}

proc xdelpack {handle idx text {from 0} } {  global iso xpro xfil xclr
 if {$text ne ""} {  set text [xstrtsp [string map {, " " # ""} [xstrlow $text]]]  }
 set delwhat [split $text]  ;  set error 0  ;  set delall 0  ;  set delcount 0
 set delpacks ""  ;  set errlist ""  ;  set id0 [lindex $delwhat 0]
 if {$from=="0"} {  set ficnt $xpro(packcount)
   if {[file exists $xfil(packs)]} {  set have 1  }
   set fnam1 $xfil(packs)  ;  set fnam2 $xfil(cpack)
  } else {  set ficnt $xpro(trigcount)
   if {[file exists $xfil(trigs)]} {  set have 1  }
   set fnam1 $xfil(trigs)  ;  set fnam2 $xfil(ctrig)
 }
 if {![info exists have]} {  set error 1
 } elseif {$text == ""} {  set error 2
 } elseif {[regexp -- {-(a(l(l)?)?)$} $id0] || $id0 eq "1+" || $id0 eq "+1"} {
   set delall 1  ;  set delcount all
 } else {  set count 0
   foreach delthis $delwhat {  set delpk [string trimleft $delthis 0]  ;  set iserr 0  ;  incr count
    if {$delpk eq ""} {  set delpk 0  }
    if {[string match *+* $delpk]} {  set delpk [string trim $delpk +]
      if {[xstrdig $delpk] && $delpk>"1" && $delpk<=$ficnt} {
        if {$delpk<$ficnt} {  append delpk -$ficnt  }
      } else {  set iserr 1  }
    } elseif {[string match -* $delpk] || [string match *- $delpk]} {  set delpk [string trim $delpk -]
      if {[xstrdig $delpk]} {
        if {$count=="1" && $delpk>=$ficnt} {  set delall 1  ;  set delcount all  ;  break
        } elseif {$delpk>"1" && $delpk<$ficnt} {  set delpk 1-$delpk
        } else {  set iserr 1  }
      } elseif {$count=="1" && [regexp {^(e(n(d)?)?)$} $delpk]} {
        set delall 1  ;  set delcount all  ;  break
      } else {  set iserr 1  }
    }
    if {$iserr>"0"} {  lappend errlist $delthis
    } else {  set delpk [split $delpk -]  ;  foreach {t1 t2} $delpk { break }
      if {[xstrdig $t1] && $t1>"0" && $t1<=$ficnt} {
        if {[lsearch -exact $delpacks $t1]=="-1"} {  lappend delpacks $t1  }
        if {$t1<$ficnt && $t2 ne ""} {
          if {[regexp {^(e(n(d)?)?)$} $t2]} {  set t2 $ficnt  }
          if {[xstrdig $t2] && $t2>$t1} {
	    if {$t2>$ficnt} {  set t2 $ficnt  }
	    while {$t1<$t2} {  incr t1
             if {[lsearch -exact $delpacks $t1]=="-1"} {  lappend delpacks $t1  }
            }
          }
        }
      } else {  lappend errlist $delthis  }
    }
   }
   if {$delpacks ne ""} {
     if {$delcount eq "0"} {  set delcount [llength $delpacks]  }
     if {$delcount==$ficnt && $ficnt>"1"} {  set delall 1  ;  set delcount all  }
     if {[llength $delpacks]>"1"} {  set delpacks [lsort -integer $delpacks]  }
   }
 }
 set dlogo $xclr(dcc)$xpro(dlogo)
 if {$delcount ne "0"} {
   if {$delall=="1"} {
     putdcc $idx "$dlogo Delete All Current XDCC Packs! ..."
   } elseif {[llength $delpacks]=="1"} {
     putdcc $idx "$dlogo Delete XDCC Pack #[join $delpacks] ..."
   } else {
     putdcc $idx "$dlogo Delete Packs: [join $delpacks] ..."
   }
   if {$errlist ne ""} {
     putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Not valid dpack input! \[[join $errlist]\]"
   }
 }
 set count 0  ;  set deleted 0  ;  set newpaknum 0  ;  set gonepacks ""
 if {$errlist eq "" && $delcount eq "0" && $delwhat ne ""} {
   foreach input $delwhat {
    set errinput [string trimleft $input #0]
    if {$errinput eq ""} {  set errinput 0  }
    if {[lsearch -exact $errlist $errinput]=="-1"} {  lappend errlist $errinput  }
   }
 }
 if {$error=="1" && $errlist ne ""} {  set tmp :
   if {[llength $errlist]>"1" || ![xstrdig [lindex $errlist 0]]} {  set tmp (s):  }
   putdcc $idx "$dlogo Delete Pack$tmp [string map {, " "} [join $errlist]] ..."
   putdcc $idx "No packs offered."
   putdcc $idx "$dlogo$xclr(dcce) Use: $xclr(dcc).apack$xclr(dcce) for help adding packs"
 } elseif {$error=="2" || $delcount eq "0"} {
   putdcc $idx [set hbar -----------------------------------------------------------]
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Delete Pack command  \[.dpack <pack#(s)>\]"
   set reason "(Not valid input!)"
   if {$ficnt=="1"} { set packsnow "Serving one pack. "
   } else { set packsnow "Serving $ficnt packs. " }
   if {$error!="2" && $errlist eq ""} {
     set reason "(NO Packs offered!)" ;  set packsnow ""
   }
   if {$error!="2" && $errlist ne ""} {
     putdcc $idx ".dpack given was:  [string map {, " "} [join $errlist]]  $reason"  }
   putdcc $idx ".dpack usage : .dpack <packnumber(s)>"
   putdcc $idx "example : $xclr(dcc).dpack 2$xclr(dcce)  (this will delete pack #2)"
   putdcc $idx "Advanced Delete Pack Command Examples:"
   putdcc $idx " $xclr(dcc).dpack 1 3 4 7$xclr(dcce)     (delete packs numbered 1 3 4 and 7)"
   putdcc $idx " $xclr(dcc).dpack 3-6$xclr(dcce)         (delete packs 3 4 5 and 6)"
   putdcc $idx " $xclr(dcc).dpack 4-$xclr(dcce)          (delete packs 1 2 3 and 4)"
   putdcc $idx " $xclr(dcc).dpack 5+$xclr(dcce)          (delete all packs numbered 5 & higher)"
   putdcc $idx " $xclr(dcc).dpack 1 5-7 9+ 3$xclr(dcce)  (delete packs 1 3 5 6 7 and 9+)"
   putdcc $idx "$packsnow\Use: $xclr(dcc).dpack -all$xclr(dcce) :to delete ALL packs!"
   putdcc $idx $hbar
 } elseif {$delall=="1"} {  set delall 2
 } else {  set xpktemp ./scripts/xpack.tmp  ;  set xcpktemp ./scripts/xcpk.tmp
   set xpacktemp [open $xpktemp w]  ;  set xcpacktemp [open $xcpktemp w]
   set xpkfile [open $fnam1 r]  ;  set xcpkfile [open $fnam2 r]
   while {![eof $xpkfile]} {  set temp [gets $xpkfile]  ;  set temp2 [gets $xcpkfile]
    if {$temp ne ""} {  incr count
      if {[lsearch -exact $delpacks $count]!="-1"} {  incr deleted
        set paktmp "$temp $temp2" ;  lappend gonepacks $paktmp
      } else {  incr newpaknum
        puts $xpacktemp "$newpaknum [lrange $temp 1 end]"
        puts $xcpacktemp "$temp2"
      }
    }
   }
   close $xpkfile  ;  close $xcpkfile  ;  close $xpacktemp  ;  close $xcpacktemp
   file delete $fnam1  ;  file delete $fnam2
   file rename $xpktemp $fnam1  ;  file rename $xcpktemp $fnam2
   file delete $xpktemp  ;  file delete $xcpktemp
 }
 if {$delcount eq "all"} {  file delete $fnam1  ;  file delete $fnam2
   if {$from=="0"} {  set xpro(packcount) 0  ;  set xpro(packbytes) 0
     set xpro(packssent) 0  ;  set xpro(bytessent) 0
     if {$iso=="1"} {
       putdcc $idx "Removed ALL packs!  Turning server OFF...."
       xstop $handle $idx $text
     } else {  putdcc $idx "$dlogo$xclr(dcce) Removed ALL packs!"  }
   }
 } elseif {$deleted=="1"} {  set fgon [lindex $gonepacks 0]
   if {$from=="0"} {
     putdcc $idx "Removed pack [lindex $fgon 0]: [lindex $fgon 1] ([lindex $fgon 4]X)"
   }
 } elseif {$deleted>"1"} {
   if {$from=="0"} {  putdcc $idx "Removed these packs..."  }
   foreach fgon $gonepacks {
    putdcc $idx "[lindex $fgon 0]: [lindex $fgon 1] ([lindex $fgon 4]X)"
   }
 }
 if {$deleted>"0"} {
   if {$newpaknum=="0"} {  file delete $fnam1  ;  file delete $fnam2
     if {$from=="0"} {  set xpro(packcount) 0  ;  set xpro(packbytes) 0
       set xpro(packssent) 0  ;  set xpro(bytessent) 0
       if {$iso=="1"} {
         putdcc $idx "Removed ALL packs!  Turning server OFF...."
         xstop $handle $idx $text
       } else {  putdcc $idx "$dlogo$xclr(dcce) Removed ALL packs!"  }
     }
   } else {
     if {$newpaknum=="1"} {
       if {$from=="0"} {  putdcc $idx "$dlogo$xclr(dcce) Now serving one pack."  }
     } else {
       if {$from=="0"} {  putdcc $idx "$dlogo$xclr(dcce) Now serving $newpaknum packs."  }
     }
     readpackinfos
   }
 }
}

# -----------------------------------------------------------
# CHANNELS COMMANDS CODE  (DCC: LIST/ADD/DEL SERVER CHANNELS)
# -----------------------------------------------------------
proc xlistchans {handle idx text} {  global xpro xfil xclr  ;  set count 0
 putdcc $idx "$xclr(dcc)$xpro(dlogo) List all server channels..."
 if {[file exists $xfil(chans)]} {  set xchfile [open $xfil(chans) r]
   while {![eof $xchfile]} {  set temp [gets $xchfile]
    if {$temp != ""} {  incr count
     putdcc $idx "  $xclr(dcc)$count:$xclr(dcce)  [lindex $temp 0]"
    }
   }
   if {$count == "1"} {
    putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Serving in one channel."
   } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Serving in $count channels." }
   close $xchfile
 } else {  putdcc $idx "No server channels set."
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).achan$xclr(dcce) for help adding server channels."
 }
}

proc xaddchan {handle idx text} {  global iso xpro xfil xclr
 if {$text != ""} {
   set achanlist [split [xstrlow $text]] ; set achanfirst [lindex $achanlist 0]
   if {[string match +a* $achanfirst]=="0" && [string match -a* $achanfirst]=="0"} {
    set achantmp ""
    foreach chanadd $achanlist {
     if {[string match #?* $chanadd] == "0"} { set chanadd "#$chanadd" }
     if {[lsearch -exact $achantmp $chanadd]=="-1"} { lappend achantmp $chanadd }
    }
    set achanlist "$achantmp"
   }
 }
 set error "0" ; set toaddlist "" ; set errlist "" ; set moreerrs ""
 if {$text == ""} { set error "1"
 } else {  set chrecordlst [xstrlow [channels]] ;  set toaddtemp ""
   if {[string match +a* $achanfirst]=="1" || [string match -a* $achanfirst]=="1"} {
     set toaddlist "$chrecordlst" ;  set achanlist "+all" 
   } else {
     foreach chanadd $achanlist {
      if {[lsearch -exact $chrecordlst $chanadd] == "-1"} {
        lappend errlist $chanadd
      } else { lappend toaddtemp $chanadd }
     }
     set toaddlist "$toaddtemp"
   }
   if {$toaddlist != ""} {  set alisttmp ""
     foreach addchan $toaddlist {
      if {[botonchan $addchan] == "1"} { lappend alisttmp $addchan
      } else { lappend moreerrs $addchan }
     }
     if {$alisttmp != ""} { set toaddlist "$alisttmp"
     } else { set error "3" ;  set toaddlist "" }
   } else { set error "2" }
   set isservchan ""
   if {$toaddlist != "" && $xpro(servchans) != ""} {  set alisttmp ""
     foreach addchan $toaddlist {
      if {[lsearch -exact $xpro(servchans) $addchan] == "-1"} {
        lappend alisttmp $addchan
      } else { lappend isservchan $addchan }
     }
     if {$alisttmp != ""} { set toaddlist "$alisttmp"
     } else { set toaddlist "" ;  set error "4" }
   }
   if {$achanlist == "+all"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Add All channels: [join $chrecordlst] ..."
   } elseif {[llength $achanlist] == "1" && $toaddlist != ""} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Add channel: [lindex $achanlist 0] ..."
   } elseif {[llength $achanlist] > "1" && $toaddlist != ""} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Add channels: [join $achanlist] ..."
   }
   if {$toaddlist != ""} {
     if {![file exists $xfil(chans)]} { set xchfile [open $xfil(chans) w]
     } else { set xchfile [open $xfil(chans) a] }
     set channum "$xpro(chancount)"
     foreach achannow $toaddlist {  incr channum
      puts $xchfile "[list $achannow]" ; lappend xpro(servchans) $achannow
      putdcc $idx "  Added channel $xclr(dcc)$achannow$xclr(dcce) at position $channum"
     }
     close $xchfile ;  set xpro(chancount) "$channum"
   }
   set allerrs ""
   if {$errlist != "" || $moreerrs != "" || $isservchan != ""} {
     if {$errlist != ""} {
       set norecord "No channel record for: [join $errlist]"
       lappend allerrs $norecord
     }
     if {$moreerrs != ""} {
       set notonchan "Bot not on: [join $moreerrs]"
       lappend allerrs $notonchan
     }
     if {$isservchan != ""} {
       set wassrvchan "Already serving on: [join $isservchan]"
       lappend allerrs $wassrvchan
     }
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) [join $allerrs "  :"] !"
   } else {
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now serving in $xpro(chancount) channels."
   }
   if {$iso == "1" && $xpro(firstad) != "0" && $toaddlist != ""} {
     foreach {tid chan} $xpro(adtimerids) { killtimer $tid }
     set xpro(adtimerids) ""
     set dtime "0" ; set calledby "addchan" ; set adcount "0" ; set fromlque "0"
     foreach ch $xpro(servchans) {
      set tmrid [timer [expr $xpro(firstad)+$dtime] "[list xchanad $ch $calledby $adcount $fromlque]"]
      lappend xpro(adtimerids) $tmrid $ch
      incr dtime $xpro(adtonextch)
     }
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Channel ads restarted."
   }
 }
 if {$error == "1" || $toaddlist == ""} {
   putdcc $idx "------------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Add Channel command \[.achan <channel(s)>\]"
   if {$error != "1"} { putdcc $idx ".achan given was:  [join $achanlist]  (Not valid input!)" }
   putdcc $idx ".achan usage : .achan #<channel>  :or:  .achan <channel>"
   putdcc $idx "example : $xclr(dcc).achan lamer$xclr(dcce) (this will add the channel #lamer)"
   putdcc $idx "example : $xclr(dcc).achan lame #lamer$xclr(dcce) (add channels #lame & #lamer)"
   putdcc $idx "example : $xclr(dcc).achan +all$xclr(dcce) (add all channels in bot's channel record)"
   putdcc $idx "------------------------------------------------------------"
 }
}

proc xdelchan {handle idx text} {  global iso xpro xfil xclr
 set error "0" ; set errlist "" ; set dchanlist "-" ; set dchannums "-"
 if {$text == ""} { set error "1"
 } elseif {![file exists $xfil(chans)]} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete channels $text..."
   putdcc $idx "Can't delete channel! No server channels set!"
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).achan$xclr(dcce) for help adding channels"
 } else {  set dchanlist [split [xstrlow $text]]
   set chanrem [lindex $dchanlist 0] ;  set dchannums ""
   if {[string match -a* $chanrem] == "1"} {
     set chanrem "-all" ;  set dchanlist "$xpro(servchans)"
   } else {  set dchantmp ""
     foreach dwhat $dchanlist {
      if {[string is digit -strict $dwhat] == "1"} {
        if {[string index $dwhat 0] != "0" && $dwhat <= $xpro(chancount)} {
          if {[lsearch -exact $dchannums $dwhat] == "-1"} { lappend dchannums $dwhat }
        } else {  set dwhat "$dwhat"
          if {[lsearch -exact $dchantmp $dwhat] == "-1"} { lappend dchantmp $dwhat }
        }
      } else {
        if {[string match #?* $dwhat] == "0"} { set dwhat "#$dwhat" }
        if {[lsearch -exact $dchantmp $dwhat] == "-1"} { lappend dchantmp $dwhat }
      }
     }
     set dchanlist ""
     if {$dchantmp != ""} {
       foreach dchn $dchantmp {
        if {[lsearch -exact $xpro(servchans) $dchn] == "-1"} {
          lappend errlist $dchn
        } else { lappend dchanlist $dchn }
       }
     }
   }
   if {$chanrem  == "-all"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Remove All server channels ..."
     file delete $xfil(chans)
     set xpro(servchans) "" ;  set xpro(chancount) "0"
     putdcc $idx "  Removed : [join $dchanlist "  "]"
   } elseif {$dchanlist != "" || $dchannums != ""} {  set dthis ""
     if {$dchannums != ""} { set dthis "[join $dchannums ": "]:" }
     if {$dchanlist != ""} {
       if {$dthis == ""} { set dthis [join $dchanlist]
       } else { append dthis " [join $dchanlist]" }
     }
     set dthis [split $dthis]
     if {[llength $dthis] == "1"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete Channel:  [lindex $dthis 0] ..."
     } elseif {[llength $dthis] == "2"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete Channels:  [join $dthis " and "] ..."
     } else { putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete Channels:  [join [lrange $dthis 0 end-1]] & [lindex $dthis end] ..." }
     set xchtemproute "./scripts/xchan.tmp"
     set xchtempfile [open $xchtemproute w] ; set xchfile [open $xfil(chans) r]
     set count "0" ; set goncount "0" ; set newcount "0" ; set newchlist ""
     while {![eof $xchfile]} {  set temp [gets $xchfile]
      if {$temp != ""} {  incr count ;  set temp [lindex $temp 0]
        set dbynum [lsearch -exact $dchannums $count]
        set dbychan [lsearch -exact $dchanlist $temp]
        if {$dbynum != "-1" || $dbychan != "-1"} {
          incr goncount ;  putdcc $idx "  Removed Channel $count: $temp"
        } else {  incr newcount
          lappend newchlist $temp ;  puts $xchtempfile "[list $temp]"
        }
      }
     }
     close $xchfile ;  close $xchtempfile ;  file delete $xfil(chans)
     if {$newcount != "0"} {  file rename $xchtemproute $xfil(chans)
       set xpro(servchans) "$newchlist" ; set xpro(chancount) "$newcount"
     } else { set xpro(servchans) "" ;  set xpro(chancount) "0" }
     file delete $xchtemproute
     if {$errlist != ""} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Not serving in [join $errlist] !"
     } else {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now serving in $xpro(chancount) channels."
     }
   }
   if {$xpro(chancount) == "0"} {
     if {$iso == "1"} {
       putdcc $idx "Removed All channels. Turning server Off..."
       xstop $handle $idx $text
     } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Removed All server channels!" }
   }
 }
 if {$error == "1" || ($dchanlist=="" && $dchannums=="")} {
   putdcc $idx "---------------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Delete Channel command \[.dchan <channel(s)>\]"
   if {$error != "1"} { putdcc $idx ".dchan given was:  [join $errlist]  (Not valid input!)" }
   putdcc $idx ".dchan usage : .dchan #<channel>  :or:  .dchan <channel>"
   putdcc $idx "example : $xclr(dcc).dchan lamer$xclr(dcce) (this will remove the channel #lamer)"
   putdcc $idx "example : $xclr(dcc).dchan lame #lamer$xclr(dcce) (remove channels #lame & #lamer)"
   putdcc $idx "example : $xclr(dcc).dchan 1 4$xclr(dcce) (remove channels currently numbered 1 & 4)"
   putdcc $idx "example : $xclr(dcc).dchan -all$xclr(dcce) (remove all server channels!)"
   putdcc $idx "---------------------------------------------------------------"
 }
}

# -----------------------------------------------------------
# QUEUE COMMANDS CODE  (DCC: LIST/DELETE FILES IN SEND QUEUE)
# -----------------------------------------------------------
proc xlistque {handle idx text} {  global iso xpro xfil xclr
 set count "0" ;  set xpro(queinfo) ""
 if {[file exists $xfil(que)]} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) List all queues..."
   set xqufile [open $xfil(que) r]
   while {![eof $xqufile]} {  set temp [gets $xqufile]
    if {$temp != ""} {  incr count
      set qnick [lindex $temp 2] ;  set qhost [lindex $temp 4]
      set qfile [lindex $temp 0]
      set qinfotmp [list $count $qnick $qhost "$qfile"]
      lappend xpro(queinfo) $qinfotmp
      set putdgone ""
      if {[lindex $temp 6] != "0"} { set putdgone "Gone [lindex $temp 6]+ minutes" }
      putdcc $idx " $count: $qnick $qhost $qfile $putdgone"
    }
   }
   close $xqufile
   set xpro(qinfocount) "$count"
   if {$count == "0"} {  putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No files in queue."
   } else {
     putdcc $idx "----------------------------------------------------------------------"
     putdcc $idx "Queues can be removed by nick (removes all for nick) or que# from this list"
     putdcc $idx "Delete from que command: .dque <nick or que#>  ($xclr(dcc).dque -all$xclr(dcce)  :to clear que)"
     putdcc $idx "example: $xclr(dcc).dque 3$xclr(dcce) (this will delete que #3 from the queue)"
     putdcc $idx " :note: if file is no longer in que & is being sent, this will kill the send!"
     putdcc $idx "example: $xclr(dcc).dque nick$xclr(dcce) (removes all ques & kills all sends for nick!)"
   }
 } else {  putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No queue file exists."  }
}

proc delfromque {handle idx text} {  global iso xpro xfil xclr
 set querem [xstrlow [lindex [split $text] 0]]
 set error "0" ;  set chksends "0"
 if {$querem == ""} { set error "1"
 } elseif {[string match -a* $querem] == "1"} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete All files from queue..."
   if {$xpro(quecnt) == "0"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No files in queue."
   } else {  set count "0"
     if {$xpro(quecnt) == "1"} { putdcc $idx "Removing one file from queue..."
     } else { putdcc $idx "Removing $xpro(quecnt) files from queue..." }
     set xqufile [open $xfil(que) r]
     while {![eof $xqufile]} {  set qtemp [gets $xqufile]
      if {$qtemp != ""} {  incr count
       set qnick [lindex $qtemp 2] ;  set qhost [lindex $qtemp 4]
       set qfile [lindex $qtemp 0]
       putdcc $idx "$xclr(dcc)$count:$xclr(dcce) $qnick $qhost $qfile"
      }
     }
     close $xqufile ;  file delete $xfil(que)
     set xpro(quecnt) "0" ; set xpro(qinfocount) "0" ; set xpro(queinfo) ""
     if {$xpro(sendcnt) == "0"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending No files at this time."
     } else {
       if {$xpro(sendcnt) == "1"} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Currently sending one file..."
       } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Currently sending $xpro(sendcnt) files..." }
       putdcc $idx "Use $xclr(dcc).dsend -all$xclr(dcce) to kill all sends or $xclr(dcc).lsend$xclr(dcce) to list sends."
     }
   }
 } elseif {[string is digit -strict $querem] == "1"} {
   if {$xpro(qinfocount) == "0"} {
     putdcc $idx "-----------------------------------------------------------------"
     putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) NO .lque results in memory.  Values not set."
     putdcc $idx "The .dque <que#> cmd works with the results of the last .lque cmd."
     putdcc $idx "Running the .lque command now...."
     putdcc $idx "-----------------------------------------------------------------"
     if {$xpro(quecnt) == "0"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No files in queue."
     } else { xlistque $handle $idx $text }
   } elseif {[string index $querem 0] == "0" || $querem > $xpro(qinfocount)} {
     putdcc $idx "-----------------------------------------------------------------"
     putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Wrong use of the .dque <que#> command."
     putdcc $idx "$querem is not a valid que#..."
     putdcc $idx "Use a que# from the last .lque cmd or do .lque now for current list."
     putdcc $idx "Or use $xclr(dcc).dque$xclr(dcce) for help with the delete from queue command."
     putdcc $idx "-----------------------------------------------------------------"
   } else {
     set count "0" ; set gone "0" ; set stillonque "0" ; set stillonqlist ""
     set quetodel [lsearch -inline $xpro(queinfo) "$querem *"]
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete queue #$querem..."
     if {[file exists $xfil(que)]} {  set xqutemproute "./scripts/dque.tmp"
       set xqutmpfile [open $xqutemproute w] ; set xqufile [open $xfil(que) r]
       while {![eof $xqufile]} {  set qtemp [gets $xqufile]
        if {$qtemp != ""} {
         set qnick [lindex $qtemp 2] ;  set qhost [lindex $qtemp 4]
         set qfile [lindex $qtemp 0]
         if {[lindex $quetodel 1]==$qnick && [lindex $quetodel 3]==$qfile} {
           incr gone ; set quegone "$qnick $qhost : $qfile"
         } else {  puts $xqutmpfile "$qtemp"
           incr count ;  set stlonqutmp ""
           if {$qnick==[lindex $quetodel 1] || $qhost==[lindex $quetodel 2]} {
             incr stillonque
             foreach quinfos $xpro(queinfo) {
              set quinfonick [lindex $quinfos 1] ; set quinfohost [lindex $quinfos 2]
              set quinfofile [lindex $quinfos 3]
              if {($qnick==$quinfonick || $qhost==$quinfohost) && $qfile==$quinfofile} {
                set stlonqutmp "$quinfos"
              }
             }
             if {$stlonqutmp != ""} {
               set stillontmp [list [lindex $stlonqutmp 0] $qnick $qhost $qfile]
             } else {
               set noton "-1" ; set stillontmp [list $noton $qnick $qhost $qfile]
             }
             lappend stillonqlist $stillontmp
           }
         }
        }
       }
       close $xqufile ;  close $xqutmpfile ;  file delete $xfil(que)
       file rename $xqutemproute $xfil(que) ; file delete $xqutemproute
     }
     if {$gone == "0"} {
       putdcc $idx "File no longer in queue. Checking sends..."
       set notherdamnvar ""
       set kilnick [lindex $quetodel 1] ; set kilfile [lindex $quetodel 3]
       set filetmpls [split $kilfile /] ; set fileonly [lindex $filetmpls end]
       if {[string match "* *" $fileonly] == "1"} {
         set fileonly [string map {" " _} $fileonly]
       }
       foreach dsend [dcclist GET] {
        if {$dsend != ""} {  set dlidx [lindex $dsend 0]
          set dlnick [xstrlow [lindex $dsend 1]]
          set dlfile [string trim [lindex [split [lindex $dsend 4] ":"] 1]]
          if {$dlnick == $kilnick && $dlfile == $fileonly} {
            killdcc $dlidx
            incr xpro(sendcnt) -1 ; lappend notherdamnvar $dlidx
            set fidx [lsearch -exact $xpro(sendingto) $dlnick]
            set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
            foreach {fnik fhst fgone ftime} $foundinfo {
             set tooksecs [expr round([unixtime]-${ftime}.0)]
            }
            set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
          }
        }
       }
       if {$notherdamnvar == ""} {
         putdcc $idx "File $kilfile not being sent to $kilnick either."
       } else { putdcc $idx "Killed send: $kilfile to $kilnick !" }
     } else {  set xpro(quecnt) "$count"
       putdcc $idx "Removed $quegone from queue!"
     }
     if {$stillonque != "0"} {  putdcc $idx " "
       putdcc $idx "$xclr(dcc)[lindex $quetodel 1] has these files in queue..."
       set notinlque "" ;  set inlquecount "0"
       foreach qusameperson $stillonqlist {
        if {[lindex $qusameperson 0] == "-1"} {
          lappend notinlque $qusameperson
        } else {  incr inlquecount
          putdcc $idx "$xclr(dcc)[lindex $qusameperson 0]:$xclr(dcce) [join [lrange $qusameperson 1 3]]"
        }
       }
       if {$notinlque != ""} {  set lcount "$xpro(qinfocount)"
         foreach filenotinlque $notinlque {  incr lcount
          set lnick [lindex $filenotinlque 1] ; set lfile [lindex $filenotinlque 3]
          set stillontmp [list $lcount $lnick [lindex $filenotinlque 2] $lfile]
          lappend xpro(queinfo) $stillontmp
          putdcc $idx "$xclr(dcc)$lcount:$xclr(dcce) $lnick [lindex $filenotinlque 2] $lfile"
         }
         set xpro(qinfocount) "$lcount"
       }
       putdcc $idx "These queues can be removed by que# from this list"
       putdcc $idx "example : $xclr(dcc).dque 2$xclr(dcce) (remove que# 2 from lists above)"
       putdcc $idx "example : $xclr(dcc).dque [lindex $quetodel 1]$xclr(dcce) (remove all ques & kill sends for [lindex $quetodel 1])"
     } else {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) [lindex $quetodel 1] has no other files in queue."
     }
   }
 } else {  set chhost ""
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete queues & kill sends for $querem..."
   foreach chan $xpro(servchans) {
    set qnikuhost [getchanhost $querem $chan]
    if {$chhost == "" && $qnikuhost != ""} {
      set chhost [xstrlow [lindex [split $qnikuhost @] 1]]
    }
   }
   if {$chhost == ""} {
     putdcc $idx "$querem isn't on any server channels!"
     set searchlist [join $xpro(queinfo)]
     set nikidx [lsearch -exact $searchlist $querem]
     if {$nikidx != "-1"} {
       set chhost [lindex $searchlist [expr $nikidx+1]]
     } else {
       putdcc $idx "Doesn't look like $querem has any queues.  Checking quefile..."
     }
   }
   set count "0" ;  set gone "0" ;  set gontmplist ""
   if {[file exists $xfil(que)]} {  set xqutemproute "./scripts/dque.tmp"
     set xqutmpfile [open $xqutemproute w] ; set xqufile [open $xfil(que) r]
     while {![eof $xqufile]} {  set qtemp [gets $xqufile]
      if {$qtemp != ""} {
        if {$querem == [lindex $qtemp 2]} {  incr gone
          if {[lindex $qtemp 6] == "0"} { set gonelast [lindex $qtemp 0]
          } else {
            set gonelast "[lindex $qtemp 0] Gone [lindex $qtemp 6] minutes."
          }
          set gonadd [list [lindex $qtemp 2] [lindex $qtemp 4] $gonelast]
          lappend gontmplist $gonadd
          if {$chhost == ""} { set chhost [lindex $qtemp 4] }
        } elseif {$chhost != "" && $chhost == [lindex $qtemp 4]} {  incr gone
          if {[lindex $qtemp 6] == "0"} { set gonelast [lindex $qtemp 0]
          } else {
            set gonelast "[lindex $qtemp 0] Gone [lindex $qtemp 6] minutes."
          }
          set gonadd [list [lindex $qtemp 2] [lindex $qtemp 4] $gonelast]
          lappend gontmplist $gonadd
        } else { puts $xqutmpfile "$qtemp" ;  incr count }
      }
     }
     close $xqufile ;  close $xqutmpfile ;  file delete $xfil(que)
     file rename $xqutemproute $xfil(que) ; file delete $xqutemproute
   }
   if {$gone == "0"} {
     putdcc $idx "$querem has no files in queue. Checking for sends..."
   } else {  set xpro(quecnt) "$count"
     if {$gone == "1"} { putdcc $idx "$querem had one file in queue. Removed..."
     } else { putdcc $idx "$querem had $gone files in queue. Removed..." }
     foreach removd $gontmplist { putdcc $idx "[join $removd]" }
     putdcc $idx "Checking for sends..."
   }
   set chksends "1"
 }
 if {$chksends != "0"} {
   if {$xpro(sendcnt) == "0"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending No files at this time."
   } else {  set sndkilled ""
     foreach dsend [dcclist GET] {
      if {$dsend != ""} {
        set dlidx [lindex $dsend 0] ; set dlnick [xstrlow [lindex $dsend 1]]
        set dlfile [string trim [lindex [split [lindex $dsend 4] ":"] 1]]
        if {$chksends == "1" && $dlnick == $querem} {
          killdcc $dlidx
          incr xpro(sendcnt) -1 ; lappend sndkilled $dlfile
          set fidx [lsearch -exact $xpro(sendingto) $dlnick]
          set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
          foreach {fnik fhst fgone ftime} $foundinfo {
           set tooksecs [expr round([unixtime]-${ftime}.0)]
          }
          set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
        }
      }
     }
     if {$sndkilled == ""} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending No files to $querem."
     } else {
       foreach ksend $sndkilled {
        if {$ksend != ""} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Killed send to $querem : $ksend" }
       }
     }
   }
 }
 if {$error != "0"} {
   putdcc $idx "--------------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Delete Queue command \[.dque <que# or nick>\]"
   putdcc $idx ".dque usage : .dque <que#>  :or:  .dque <nick>"
   putdcc $idx "example : $xclr(dcc).dque 2$xclr(dcce) (delete que# 2 from last .lque list)"
   putdcc $idx "example : $xclr(dcc).dque lamer$xclr(dcce) (delete all ques & kill sends for Lamer)"
   putdcc $idx "example : $xclr(dcc).dque -all$xclr(dcce) (delete all files from queue)"
   putdcc $idx "--------------------------------------------------------------"
 }
}

# ------------------------------------------------
# SENDS COMMANDS CODE  (DCC: LIST/KILL FILE SENDS)
# ------------------------------------------------
proc listsends {handle idx text} {  global xpro xclr
 putdcc $idx "$xclr(dcc)$xpro(dlogo) List all file sends..."
 foreach dsend [dcclist GET] {
  if {$dsend != ""} {
    set dlidx [lindex $dsend 0] ;  set dlnick [lindex $dsend 1]
    set dlhost ""
    foreach chan $xpro(servchans) {
     set dlnikuhost [getchanhost $dlnick $chan]
     if {$dlnikuhost != ""} { set dlhost "$dlnikuhost" }
    }
    set dlfile [string trim [lindex [split [lindex $dsend 4] ":"] 1]]
    putdcc $idx "$dlidx $dlnick $dlhost $dlfile"
  }
 }
 if {$xpro(sendcnt) == "1"} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending one file."
 } elseif {$xpro(sendcnt) == "0"} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending no files."
 } else {
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sending $xpro(sendcnt) files."
 }
}

proc xkillsend {handle idx text} {  global xpro xclr
 set klist [split [xstrlow $text]] ;  set ksend [lindex $klist 0]
 set error "0" ;  set dlcount "0" ;  set dltemp ""
 foreach dsend [dcclist GET] {
  if {$dsend != ""} {  incr dlcount
    set dlidx [lindex $dsend 0] ;  set dlnick [xstrlow [lindex $dsend 1]]
    set dlfile [string trim [lindex [split [lindex $dsend 4] ":"] 1]]
    lappend dltemp $dlidx $dlnick $dlfile
  }
 }
 if {$ksend == ""} { set error "1"
 } elseif {[string match -a* $ksend] == "1"} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete All file sends..."
   if {$dlcount == "0"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No active file sends."
   } else {
     if {$dlcount == "1"} { putdcc $idx "Killing one file send..."
     } else { putdcc $idx "Killing $dlcount file sends..." }
     foreach {didx dnik dfile} $dltemp {
      putdcc $idx "  $xclr(dcc)$didx$xclr(dcce) $dnik : $dfile"
      killdcc $didx
     }
     set xpro(sendcnt) "0" ;  set xpro(sendingto) ""
   }
 } else {  set kcount "0" ;  set ecount "0"
   set knumlist "" ; set kniklist "" ; set numerr "" ; set nikerr ""
   if {[llength $klist] == "1"} {
     if {[string is digit -strict $ksend] == "1"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete file send# $ksend..."
     } else {
       putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete file sends to $ksend..."
     }
   } else {
     putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete file sends: [join $klist] ..."
   }
   if {$dlcount == "0"} {
     putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No active file sends."
   } else {
     foreach kthis $klist {
      if {[string is digit -strict $kthis] == "1"} {
        set kelemt [lsearch -exact $dltemp $kthis]
        if {$kelemt == "-1"} {  lappend numerr $kthis ;  incr ecount
        } else {  incr kelemt ;  set knik [lindex $dltemp $kelemt]
          incr kelemt ;  set kfile [lindex $dltemp $kelemt]
          lappend knumlist $kthis $knik $kfile ;  incr kcount
        }
      } else {  set kelemt [lsearch -exact $dltemp $kthis]
        if {$kelemt == "-1"} {  lappend nikerr $kthis ;  incr ecount
        } else {  incr kelemt ;  set kfile [lindex $dltemp $kelemt]
          incr kelemt -2 ;  set kidx [lindex $dltemp $kelemt]
          lappend kniklist $kidx $kthis $kfile ;  incr kcount
        }
      }
     }
     if {$kcount == "0"} { putdcc $idx "No files sends killed."
     } elseif {$kcount == "1"} { putdcc $idx "Killing one file send..."
     } else { putdcc $idx "Killing $kcount file sends..." }
     if {$kcount != "0"} {
       if {$knumlist != ""} {
         foreach {kidx knik kfile} $knumlist {  killdcc $kidx
          set fidx [lsearch -exact $xpro(sendingto) $knik]
          set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
          foreach {fnik fhst fgone ftime} $foundinfo {
           set tooksecs [expr round([unixtime]-${ftime}.0)]
          }
          set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
          putdcc $idx "  $xclr(dcc)$kthis:$xclr(dcce) $knik : $kfile"
         }
       }
       if {$kniklist != ""} {
         foreach {kidx knik kfile} $kniklist {
          killdcc $kidx
          set fidx [lsearch -exact $xpro(sendingto) $knik]
          set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
          foreach {fnik fhst fgone ftime} $foundinfo {
           set tooksecs [expr round([unixtime]-${ftime}.0)]
          }
          set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
          putdcc $idx "  $xclr(dcc)$knik :$xclr(dcc) $kfile"
         }
       }
       incr xpro(sendcnt) -$kcount
     } else { set error "2" }
     if {$ecount != "0"} {
       if {$numerr != ""} {
         if {[llength $numerr] == "1"} {
          putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Not a valid send# : $numerr !"
         } else {
          putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Not valid send #'s : $numerr !"
         }
       }
       if {$nikerr != ""} {
         if {[llength $nikerr] == "1"} {
          putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No file sends to [lindex $nikerr 0] !"
         } else {
          putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No sends to: [join $nikerr] !"
         }
       }
       if {$error != "2"} {
         putdcc $idx "Use: $xclr(dcc).lsend$xclr(dcce) to list sends or: $xclr(dcc).dsend$xclr(dcce) for help with .dsend"
       }
     }
   }
 }
 if {$error != "0"} {
   putdcc $idx "----------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Delete Send command \[.dsend <value(s)>\]"
   putdcc $idx ".dque usage : .dsend <send#(s)>  :or:  .dsend <nick(s)>"
   putdcc $idx "example : $xclr(dcc).dsend 2$xclr(dcce) (kill file send# 2)"
   putdcc $idx "example : $xclr(dcc).dsend lamer$xclr(dcce) (kill all sends to Lamer)"
   putdcc $idx "example : $xclr(dcc).dsend 7 lamer 4$xclr(dcce) (kill sends 4, 7 & sends to Lamer)"
   putdcc $idx "example : $xclr(dcc).dsend -all$xclr(dcce) (kill all file sends)"
   putdcc $idx "----------------------------------------------------------"
 }
}

# ---------------------------------------------------
# BANS COMMANDS CODE  (DCC: LIST/ADD/DEL SERVER BANS)
# ---------------------------------------------------
proc xlistbans {handle idx text} {  global xpro xfil xclr
 putdcc $idx "$xclr(dcc)$xpro(dlogo) List all server bans..."
 set count "0" ;  set xpro(baninfo) "" ;  set xpro(baninfc) "0"
 if {![file exists $xfil(bans)]} {
   putdcc $idx "No server bans set."
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).aban$xclr(dcce) for help adding bans"
   return 0 }
 putdcc $idx " "
 set cutime [unixtime] ;  set xbanfile [open $xfil(bans) r]
 while {![eof $xbanfile]} {  set temp [gets $xbanfile]
  if {$temp != ""} {  incr count
    foreach {mask nik creat lused req resn} $temp {
     lappend xpro(baninfo) $count $mask
     if {[string length $count]=="1"} { set bcnt " $count" } else { set bcnt "$count" }
     if {[string length $bcnt] == "2"} {
       putdcc $idx " $xclr(dcc)\[$bcnt\]$xclr(dcce) $mask"
     } else { putdcc $idx "$xclr(dcc)\[$bcnt\]$xclr(dcce) $mask" }
     if {$resn == "-"} { putdcc $idx "      $req:  Requested ban"
     } else { putdcc $idx "      $req:  Banned nick: $resn" }
     set crtime [expr round($cutime-${creat}.0)]
     if {$crtime < "86400"} {  set ctemp [duration $crtime]
       if {[string match *second* $ctemp] == "1"} {  set tmp2 [split $ctemp]
         if {[llength $tmp2] == "2"} { set cago "Created $ctemp ago"
         } else { set cago "Created [join [lrange $tmp2 0 end-2]] ago" }
       } else { set cago "Created $ctemp ago" }
     } else {  set ctemp [expr round(${crtime}.0/86400)]
       if {$ctemp == "1"} { set cago "Created 1 day ago"
       } else { set cago "Created $ctemp days ago" }
     }
     if {$lused != "0"} {  set lutime [expr round($cutime-${lused}.0)]
       if {$lutime < "86400"} {  set ltemp [duration $lutime]
         if {[string match *second* $ltemp] == "1"} {  set tmp2 [split $ltemp]
           if {[llength $tmp2] == "2"} { set lago "last used $ltemp ago by $nik"
           } else { set lago "last used [join [lrange $tmp2 0 end-2]] ago by $nik" }
         } else { set lago "last used $ltemp ago by $nik" }
       } else {  set ltemp [expr round(${lutime}.0/86400)]
         if {$ltemp == "1"} { set lago "last used 1 day ago by $nik"
         } else { set lago "last used $ltemp days ago by $nik" }
       }
     } else { set lago " Never Used" }
     putdcc $idx "      $cago, $lago"
    }
  }
 }
 close $xbanfile ;  set xpro(baninfc) "$count"
 putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).dban$xclr(dcce) for help deleting bans or: $xclr(dcc).dban -all$xclr(dcce) to delete all bans."
}

proc xaddban {handle idx text} {  global xpro xfil xclr
 set error "0" ;  set errls "" ;  set errl2 "" ;  set addbls ""
 if {$text == ""} { set error "1"
 } else {  set newbanls [split [xstrlow $text]]
   foreach newbn $newbanls {  set banmask "" ;  set banednik "-"
    set fste [string first ! $newbn] ; set fsta [string first @ $newbn]
    if {$fste == "-1" && $fsta == "-1"} {  set usrhst ""
      foreach chan $xpro(servchans) {
       set bannickuhost [xstrlow [getchanhost $newbn $chan]]
       if {$bannickuhost != ""} { set usrhst "$bannickuhost" ;  break }
      }
      if {$usrhst != ""} {  set nikusrhst "$newbn!$usrhst"
        set banmask [maskhost $nikusrhst] ;  set banednik "$newbn"
      } else { lappend errls $newbn }
    } elseif {$fste != "-1" && $fsta == "-1"} {
      if {[string index $newbn 0] == "!"} { set banmask "*$newbn@*"
      } elseif {[string index $newbn end] == "!"} { set banmask "$newbn*@*"
      } else { set banmask "$newbn@*" }
    } elseif {$fste == "-1" && $fsta != "-1"} {
      if {[string index $newbn 0] == "@"} { set banmask "*!*$newbn"
      } elseif {[string index $newbn end] == "@"} { set banmask "*!$newbn*"
      } else { set banmask "*!$newbn" }
    } else {
      if {[string index $newbn 0] == "!" && [string index $newbn end] == "@"} {
        set banmask "*$newbn*"
      } elseif {[string index $newbn 0] == "!"} { set banmask "*$newbn"
      } elseif {[string index $newbn end] == "@"} { set banmask "$newbn*"
      } else { set banmask "$newbn" }
    }
    if {[string index $banmask 0] == "!"} { set banmask "*$banmask" }
    if {[string index $banmask end] == "@"} { set banmask "$banmask*" }
    set banmask "[string map {!@ !*@ *** * ** * !! ! @@ @} $banmask]"
    if {$banmask != "" && $banmask != "*!*@*"} {
      if {[lsearch -exact $xpro(srvrbans) $banmask] == "-1"} {
        if {[lsearch -exact $addbls $banmask] == "-1"} {
          lappend addbls $banmask $banednik }
      } else { lappend errl2 $banmask }
    }
   }
   if {$addbls != ""} {
     if {[llength $addbls] == "2"} {
       if {[lindex $addbls 1] == "-"} {
         putdcc $idx "$xclr(dcc)$xpro(dlogo) Add server ban: [lindex $addbls 0]"
       } else { putdcc $idx "$xclr(dcc)$xpro(dlogo) Add server ban for [lindex $addbls 1]" }
     } else { putdcc $idx "$xclr(dcc)$xpro(dlogo) Add server bans..." }
     set addtime [unixtime] ;  set bancnt [llength $xpro(srvrbans)]
     if {![file exists $xfil(bans)]} { set xbanfile [open $xfil(bans) w]
     } else { set xbanfile [open $xfil(bans) a] }
     set count "$xpro(baninfc)"
     foreach {banmask banednik} $addbls {
      incr bancnt ;  incr count
      puts $xbanfile "[list $banmask $banednik $addtime 0 $handle $banednik]"
      lappend xpro(srvrbans) $banmask
      lappend xpro(baninfo) $count $banmask
      if {[string length $count]=="1"} { set bcnt " $count" } else { set bcnt "$count" }
      if {[string length $bcnt] == "2"} {
        putdcc $idx " $xclr(dcc)\[$bcnt\]$xclr(dcce) $banmask"
      } else { putdcc $idx "$xclr(dcc)\[$bcnt\]$xclr(dcce) $banmask" }
     }
     close $xbanfile ;  set xpro(baninfc) "$count"
   }
   if {$errls == "" && $errl2 == ""} {
     if {[llength $xpro(srvrbans)] == "1"} {
       putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now banning one host mask."
     } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now banning [llength $xpro(srvrbans)] host masks." }
   } else {
     if {$errls != ""} {
       if {[llength $errls] == "1"} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) [join $errls] isn't on any server channels."
       } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Nicks not on a server channel: [join $errls]" }
     }
     if {$errl2 != ""} {
       foreach bmask $errl2 {
        putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Ban already exists: $bmask"
       }
     }
   }
 }
 if {$error == "1" || $addbls == ""} {
   putdcc $idx "----------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Add Server Ban command \[.aban <ban(s)>\]"
   putdcc $idx ".aban usage : .aban <hostmask>  :or:  .aban <nick>"
   putdcc $idx "example : $xclr(dcc).aban *!*@*aol.com$xclr(dcce) (add hostmask to server ban list)"
   putdcc $idx "example : $xclr(dcc).aban lamer$xclr(dcce) (add mask on nick, lamer, ex. *!usern*@*.aol.com)"
   putdcc $idx "example : $xclr(dcc).aban ted! ted$xclr(dcce) (add banmasks ted!*@* and *!usern*@*.aol.com)"
   putdcc $idx "example : $xclr(dcc).aban !ted @*bart.nl$xclr(dcce) (add masks *!ted@* and *!*@*bart.nl)"
   putdcc $idx "----------------------------------------------------------"
 }
}

proc xdelban {handle idx text} {  global xpro xfil xclr
 set errls ""  ;  set nikerrls "" ;  set numerrls "" ;  set error "0"
 set delbls "" ;  set delnls "" ;  set delnumls ""
 set deldbls "" ; set deldnls "" ; set goncount "0" ; set newcount "0"
 set delbanls [split [xstrlow $text]] ; set firstdel [lindex $delbanls 0]
 if {$text == ""} { set error "1"
 } elseif {![file exists $xfil(bans)]} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete bans $text..."
   putdcc $idx " Can't delete ban.  No server bans set."
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Use: $xclr(dcc).aban$xclr(dcce) for help adding bans"
 } elseif {[string match -a* $firstdel] == "1"} {
   putdcc $idx "$xclr(dcc)$xpro(dlogo) Remove All server bans..."
   file delete $xfil(bans)
   putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Removed $xpro(baninfc) server bans."
   set xpro(baninfo) "" ; set xpro(baninfc) "0" ; set xpro(srvrbans) ""
 } else {
  foreach delbn $delbanls {
   set fste [string first ! $delbn] ;  set fsta [string first @ $delbn]
   if {[string is digit -strict $delbn]} {
     set tmp2 [lsearch -exact $xpro(baninfo) $delbn]
     set tmp3 [lsearch -exact $delnumls $delbn]
     if {[string index $delbn 0] != "0" && $delbn <= $xpro(baninfc)} {
       if {$tmp2 != "-1" && $tmp3 == "-1"} {
         lappend delnumls $delbn [lindex $xpro(baninfo) [expr $tmp2+1]]
       } else {
         if {[lsearch -exact $numerrls $delbn]=="-1" && $tmp3=="-1"} {
           lappend numerrls $delbn }
       }
     } else {
       if {[lsearch -exact $numerrls $delbn] == "-1" && $tmp3=="-1"} {
         lappend numerrls $delbn }
     }
   } elseif {$fste == "-1" && $fsta == "-1"} {  set usrhst ""
     foreach chan $xpro(servchans) {  set tmp4 [getchanhost $delbn $chan]
      if {$tmp4 != ""} {  set delnickuhost [xstrlow $tmp4]
        set usrhst "$delnickuhost" ;  break
      }
     }
     if {$usrhst != ""} { set nikusrhst "$delbn!$usrhst"
     } else { set nikusrhst "$delbn!*@*" }
     if {[lsearch -exact $delnls $delbn] == "-1"} {
       lappend delnls $delbn $nikusrhst }
   } else {
     if {$fste != "-1" && $fsta == "-1"} {
       if {[string index $delbn 0] == "!"} { set banmask "*$delbn@*"
       } elseif {[string index $delbn end] == "!"} { set banmask "$delbn*@*"
       } else { set banmask "$delbn@*" }
     } elseif {$fste == "-1" && $fsta != "-1"} {
       if {[string index $delbn 0] == "@"} { set banmask "*!*$delbn"
       } elseif {[string index $delbn end] == "@"} { set banmask "*!$delbn*"
       } else { set banmask "*!$delbn" }
     } else {
       if {[string index $delbn 0] == "!" && [string index $delbn end] == "@"} {
         set banmask "*$delbn*"
       } elseif {[string index $delbn 0] == "!"} { set banmask "*$delbn"
       } elseif {[string index $delbn end] == "@"} { set banmask "$delbn*"
       } else { set banmask "$delbn" }
     }
     if {[string index $banmask 0] == "!"} { set banmask "*$banmask" }
     if {[string index $banmask end] == "@"} { set banmask "$banmask*" }
     set banmask "[string map {!@ !*@ *** * ** * !! ! @@ @} $banmask]"
     if {$banmask != "" && $banmask != "*!*@*"} {
       if {[lsearch -exact $xpro(srvrbans) $banmask] != "-1"} {
         if {[lsearch -exact $delbls $banmask] == "-1"} {
           lappend delbls $banmask }
       } else { lappend errls $banmask }
     }
   }
  }
  if {$delbls != "" || $delnls != "" || $delnumls != ""} {
    set xbantmproute "./scripts/xban.tmp"
    set xbantmpfile [open $xbantmproute w] ; set xbanfile [open $xfil(bans) r]
    set count "0"
    while {![eof $xbanfile]} {  set temp [gets $xbanfile]
     if {$temp != ""} {  incr count ;  set gone "0"
       foreach {mask nik creat lused req resn} $temp {
        set remidx [lsearch -exact $xpro(baninfo) $mask]
        set delnumb [lindex $xpro(baninfo) [expr $remidx-1]]
        if {[set nikidx [lsearch -exact $delnls $nik]] != "-1"} {
         set tmp2 [lindex $delnls $nikidx] ;  set gone "1"
         set sby "$req:$creat:$resn" ;  set lusd "$lused:$nik"
         lappend deldnls $tmp2 $delnumb $mask $sby $lusd
        } elseif {$resn!="-" && [set nikidx [lsearch -exact $delnls $resn]]!="-1"} {
         set tmp2 [lindex $delnls $nikidx] ;  set gone "1"
         set sby "$req:$creat:$resn" ;  set lusd "$lused:$nik"
         lappend deldnls $tmp2 $delnumb $mask $sby $lusd
        } elseif {[set hstidx [lsearch -exact $delnls $mask]] != "-1"} {
         set tmp2 [lindex $delnls [expr $hstidx-1]] ;  set gone "1"
         set sby "$req:$creat:$resn" ;  set lusd "$lused:$nik"
         lappend deldnls $tmp2 $delnumb $mask $sby $lusd
        } elseif {[set hstidx [lsearch -glob $delnls $mask]] != "-1"} {
         set tmp2 [lindex $delnls [expr $hstidx-1]] ;  set gone "1"
         set sby "$req:$creat:$resn" ;  set lusd "$lused:$nik"
         lappend deldnls $tmp2 $delnumb $mask $sby $lusd
        } elseif {[lsearch -exact $delnumls $delnumb] != "-1"} {
         set gone "1" ; set sby "$req:$creat:$resn" ; set lusd "$lused:$nik"
         lappend deldbls $delnumb $mask $sby $lusd
        } elseif {[lsearch -exact $delbls $mask] != "-1"} {
         set gone "1" ; set sby "$req:$creat:$resn" ; set lusd "$lused:$nik"
         lappend deldbls $delnumb $mask $sby $lusd
        } else {  incr newcount ;  puts $xbantmpfile "$temp"  }
        if {$gone == "1"} { incr goncount
         if {$remidx != "-1"} {
           set xpro(baninfo) [lreplace $xpro(baninfo) [expr $remidx-1] $remidx]
         } else { putlog "xdamn error 47" }
        }
       }
     }
    }
    close $xbanfile ;  close $xbantmpfile ;  file delete $xfil(bans)
    if {$newcount != "0"} {  file rename $xbantmproute $xfil(bans)
      if {$goncount != "0"} { readbaninfos }
    } else { set xpro(srvrbans) "" ; set xpro(baninfo) "" ; set xpro(baninfc) "0" }
    file delete $xbantmproute
  }
  if {$goncount != "0"} {
    if {$deldnls != ""} {
      foreach {nick nikusrhst} $delnls {
       set tmpls [lsearch -all -exact $deldnls $nick]
       if {$tmpls == ""} { lappend nikerrls $nick $nikusrhst
       } else {
         putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete bans for $nick: $nikusrhst..."
         foreach numbr $tmpls {  set tmp2ls [lrange $deldnls $numbr [expr $numbr+4]]
          foreach {bnik bnum rmask sby lused} $tmp2ls {
           if {$lused == "0:-"} { set lusd " Never Used"
           } else {  set tmp3ls [split $lused :] ;  set lutime [lindex $tmp3ls 0]
             set lusd "last used [xtimeago $lutime] ago by [lindex $tmp3ls 1]" }
           if {[string length $bnum]=="1"} { set bcnt " $bnum" } else { set bcnt "$bnum" }
           if {[string length $bcnt] == "2"} {
             putdcc $idx " $xclr(dcc)\[$bcnt\]$xclr(dcce) $rmask"
           } else { putdcc $idx "$xclr(dcc)\[$bcnt\]$xclr(dcce) $rmask" }
           set tmp4ls [split $sby :]
           foreach {sbnik stime resn} $tmp4ls {
            if {$resn == "-"} { putdcc $idx "      $sbnik:  Requested ban"
            } else { putdcc $idx "      $sbnik:  Banned nick: $resn" }
            putdcc $idx "      Created [xtimeago $stime] ago, $lusd"
           }
          }
         }
       }
      }
      if {$nikerrls != ""} {  set tmp5ls ""
        foreach {nick nikusrhst} $nikerrls { lappend tmp5ls $nick }
        putdcc $idx "No bans found for: [join $tmp5ls]"
        putdcc $idx ".dban <nick> works best if the user is on a server channel!"
        set nikerrls ""
      }
      if {$deldbls != ""} { putdcc $idx " " }
    } else { if {$delnls != ""} { set nikerrls "$delnls" } }
    if {$deldbls != ""} {
      putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete server bans..."
      foreach {bnum rmask sby lused} $deldbls {
       if {$lused == "0:-"} { set lusd " Never Used"
       } else {  set tmp3ls [split $lused :] ;  set lutime [lindex $tmp3ls 0]
         set lusd "last used [xtimeago $lutime] ago by [lindex $tmp3ls 1]" }
       if {[string length $bnum]=="1"} { set bcnt " $bnum" } else { set bcnt "$bnum" }
       if {[string length $bcnt] == "2"} {
         putdcc $idx " $xclr(dcc)\[$bcnt\]$xclr(dcce) $rmask"
       } else { putdcc $idx "$xclr(dcc)\[$bcnt\]$xclr(dcce) $rmask" }
       set tmp4ls [split $sby :]
       foreach {sbnik stime resn} $tmp4ls {
        if {$resn == "-"} { putdcc $idx "      $sbnik:  Requested ban"
        } else { putdcc $idx "      $sbnik:  Banned nick: $resn" }
        putdcc $idx "      Created [xtimeago $stime] ago, $lusd"
       }
      }
      if {$numerrls != ""} {
        if {[llength $numerrls] == "1"} {
          putdcc $idx "Invalid ban number: [join $numerrls]"
        } else { putdcc $idx "Invalid ban numbers: [join $numerrls]" }
        if {$errls == ""} { putdcc $idx "Use: $xclr(dcc).lban$xclr(dcce) for a current list of server bans." }
        set numerrls ""
      }
      if {$errls != ""} {
        if {[llength $errls] == "1"} {
          putdcc $idx "Banmask doesn't exist: [join $errls]"
        } else { putdcc $idx "Banmasks don't exist: [join $errls]" }
        putdcc $idx "Use: $xclr(dcc).lban$xclr(dcce) for a current list of server bans."
        set errls ""
      }
    }
  } else { set error "2" ; if {$delnls != ""} { set nikerrls "$delnls" } }
  if {$errls != "" || $nikerrls != "" || $numerrls != ""} {
    if {$goncount != "0"} { putdcc $idx " " }
    if {$nikerrls != ""} {  set tmp5ls ""
      foreach {nick nikusrhst} $nikerrls { lappend tmp5ls $nick }
      putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No bans found for: [join $tmp5ls]"
      putdcc $idx ".dban <nick> works best if the user is on a server channel!"
    }
    if {$numerrls != ""} {
      if {[llength $numerrls] == "1"} {
        putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Invalid ban number: [join $numerrls]"
      } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Invalid ban numbers: [join $numerrls]" }
      if {$errls == ""} { putdcc $idx "Use: $xclr(dcc).lban$xclr(dcce) for a current list of server bans." }
    }
    if {$errls != ""} {
      if {[llength $errls] == "1"} {
        putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Banmask doesn't exist: [join $errls]"
      } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Banmasks don't exist: [join $errls]" }
      putdcc $idx "Use: $xclr(dcc).lban$xclr(dcce) for a current list of server bans."
    }
  }
  if {$error == "0"} {
    if {$newcount == "0"} {
      putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Removed all server bans."
    } elseif {$newcount == "1"} { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now banning one host mask."
    } else { putdcc $idx "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now banning $newcount host masks." }
  }
 }
 if {$error != "0"} {
   putdcc $idx "-------------------------------------------------------------"
   putdcc $idx "$xclr(dcc)XDCC SERVER HELP :$xclr(dcce) Delete Server Ban command \[.dban <ban(s)>\]"
   putdcc $idx ".dban usage : .dban <banmask> :or: .dban <ban#> :or: .dban <nick>"
   putdcc $idx "example : $xclr(dcc).dban *!*@*aol.com$xclr(dcce) (delete mask from server ban list)"
   putdcc $idx "example : $xclr(dcc).dban 7 4$xclr(dcce) (delete bans currently numbered 4 & 7)"
   putdcc $idx "example : $xclr(dcc).dban lamer$xclr(dcce) (delete all bans on nick, lamer)"
   putdcc $idx "example : $xclr(dcc).dban ted! ted$xclr(dcce) (delete mask ted!*@* and all bans on ted)"
   putdcc $idx "example : $xclr(dcc).dban 2 !ted 8$xclr(dcce) (delete mask *!ted@* and ban #'s 2 & 8)"
   putdcc $idx "-------------------------------------------------------------"
 }
}

# ------------------------------------------
# SERVER COMMANDS CODE  (DCC: SERVER ON/OFF)
# ------------------------------------------
proc xresetstart {handle idx text} {  global xpro
 if {$xpro(xstartpaus)=="2"} {
   set xpro(xstartpaus) 0  ;  xstart $handle $idx $text
 } else {  set xpro(xstartpaus) 0  }
}

proc xstop {handle idx text} {  global iso xpro xclr
 if {$iso=="0" && $xpro(xstartpaus)=="2"} {  set xpro(xstartpaus) 1
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Server restart cancelled."
 } elseif {$iso=="0"} {
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) The server is already stopped."
 } else {  set iso 0  ;  set xpro(xstartpaus) 1
  timer 2 "[list xresetstart $handle $idx $text]"
  if {$xpro(adtimerids) != ""} {
    foreach {tid chan} $xpro(adtimerids) { killtimer $tid }
    set xpro(adtimerids) ""
  }
  if {$xpro(fluddafterad) != ""} {
    foreach {tid chan} $xpro(fluddafterad) { killutimer $tid }
    set xpro(fluddafterad) ""
  }
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) The server is now stopped."
 }
}

proc xstart {handle idx text} {  global iso xpro xfil xclr
 if {$iso == "1"} {  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) The server is already started."
 } else {
   if {![file exists $xfil(chans)]} {
     putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No server channels.  Use: $xclr(dcc).achan$xclr(dcce) for help adding channels."
   } elseif {![file exists $xfil(packs)]} {
     putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) No packages offered.  Use: $xclr(dcc).apack$xclr(dcce) for help adding packs."
   } else {
     if {$xpro(xstartpaus) != "0"} {  set xpro(xstartpaus) 2
       putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Server restart pause running.  Server starting shortly..."
     } else {  set iso 1
       if {$xpro(firstad) != "0"} {
         set dtime 0  ;  set calledby xstart  ;  set adcount 0  ;  set fromlque 0
         foreach ch $xpro(servchans) {
          set tmrid [timer [expr $xpro(firstad)+$dtime] "[list xchanad $ch $calledby $adcount $fromlque]"]
          lappend xpro(adtimerids) $tmrid $ch
          incr dtime $xpro(adtonextch)
         }
       }
       putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) The server is now started on: [join $xpro(servchans)] "
       processqueue
     }
   }
 }
}

# -------------------------------------
# SERVER COMMANDS CODE  (DCC:  XSTATUS)
# -------------------------------------
proc xstatus {handle idx text} {  global iso xpro xinf xfil xclr
 set count 0  ;  set totcb 0
 if {$iso == "1"} {
  putdcc $idx "$xclr(dcc)XDCC Server Status  ::  The server is ON"
 } else {
  putdcc $idx "$xclr(dcc)XDCC Server Status  ::  The server is OFF"
 }
 putdcc $idx "-----------------------------------------------------------"
 putdcc $idx "Current queues   : $xpro(quecnt)/$xpro(maxque)"
 putdcc $idx "Current sends    : $xpro(sendcnt)/$xpro(maxdcc)"
 if {[file exists $xfil(packs)]} {  set packcount "0" ;  set packbytes "0"
  set packssent "0" ;  set bytessent "0"
  set xpfile [open $xfil(packs) r] ; set xcpkfile [open $xfil(cpack) r]
  while {![eof $xpfile]} {
   set readpk1 [gets $xpfile] ;  set readpk2 [gets $xcpkfile]
   if {$readpk1 != ""} {
     incr packcount  ;  set pbytes [lindex $readpk1 3]
     set packbytes [expr round($packbytes+${pbytes}.0)]
     set packssent [expr round($packssent+${readpk2}.0)]
     set pbytessent [expr round($readpk2*${pbytes}.0)]
     set bytessent [expr round($bytessent+${pbytessent}.0)]
   }
  }
  close $xpfile ;  close $xcpkfile
  if {$packcount == "1"} {
   putdcc $idx "Package info     : $packcount pack : [xfrmtsize 1 $packbytes] | Sent $packssent pack ([xfrmtsize 2 $bytessent])"
  } else {
   putdcc $idx "Package info     : $packcount packs : [xfrmtsize 1 $packbytes] | Sent $packssent packs ([xfrmtsize 2 $bytessent])" }
 } else {
  putdcc $idx "Package info     : No packs offered  (no pack file)" }
 if {![file exists $xfil(totals)]} {
  putdcc $idx "Server totals    : Nothing has been transfered yet (no cbyte file)"
 } else { set tbytes "0" ;  set tfiles "0"
  set xcbfile [open $xfil(totals) r] ;  set totals [gets $xcbfile]
  if {$totals != ""} {
   set tbytes [lindex $totals 0] ;  set tfiles [lindex $totals 1] }
  close $xcbfile ;  set size [xfrmtsize 1 $tbytes]
  putdcc $idx "Server totals    : Sent $tfiles packs | $size"
 }
 if {[file exists $xfil(chans)]} {
  set xchfile [open $xfil(chans) r] ; set ch [lindex [gets $xchfile] 0]
  putdcc $idx "Serving in       : $ch"
  while {![eof $xchfile]} {  set ch [lindex [gets $xchfile] 0]
   if {$ch != ""} {  putdcc $idx "                 : $ch"  }
  }
  close $xchfile
 } else { putdcc $idx "Serving in       : No channels." }
 putdcc $idx "-----------------------------------------------------------"
 putdcc $idx "$xclr(dcc)Configuration (To make configuration changes, edit xdcc_pro.tcl)"
 putdcc $idx "Max que per user : $xpro(usrmaxq) packs"
 putdcc $idx "Server logo      : $xpro(logo)"
 if {$xpro(astart) == "0"} {
  putdcc $idx "AutoStart server : No autostart"
 } else {
  putdcc $idx "AutoStart server : Server AutoStarts $xpro(astart) min after bot starts"
 }
 if {$xpro(firstad) == "0"} {
  putdcc $idx "FirstAd delay    : No ads to server channels"
 } else {
  putdcc $idx "ChannelAd Time   : $xpro(xadtime) minutes between ads to a channel"
  putdcc $idx "FirstAd delay    : Ad to first channel starts $xpro(firstad) min after server start"
  putdcc $idx "NextChan delay   : Wait $xpro(adtonextch) min before sending an ad to next server chan"
  if {$xpro(altad) == "0"} {
   putdcc $idx "Channel Ad #2    : No Ad #2 ads between the Ad #1 channel ads"
  } elseif {$xpro(altad) == "1"} {
   putdcc $idx "Channel Ad #2    : Run the Ad #2 ad once between the Ad #1 channel ads"
  } else {
   putdcc $idx "Channel Ad #2    : Run the Ad #2 ad $xpro(altad) times between the Ad #1 channel ads"
  }
 }
 putdcc $idx "-----------------------------------------------------------"
 putdcc $idx "Running $xclr(dcc)XDCC SERVER PRO$xclr(dcce) ver $xinf(ver) by $xinf(auth)"
}

#------------------------------
# SEND A PACK LIST OR AD NOW ## 
#------------------------------
proc showxdcc {nikorchn runnow other} {  global iso xpro xfil xclr xlists botnick

#putlog "proc showxdcc: nikorchn($nikorchn) runnow($runnow) other($other)"

 if {$iso == "0"} { return 0 }
 if {$runnow == "listreq"} {
   if {$xpro(listhow) == "4"} { set beginning "NOTICE $nikorchn"
   } else { set beginning "PRIVMSG $nikorchn" }
   set listlines "$xlists(listreq)"


#### EDIT ####
 } elseif {$runnow in {lsreq2 lslatest}} {
#### END EDIT ####


   if {$xpro(cplhow) == "2"} { set beginning "NOTICE $nikorchn"
   } else { set beginning "PRIVMSG $nikorchn" }
   set listlines "$xlists(lsreq2)"

 } elseif {$runnow == "xlstreq"} {
   if {$xpro(xlsthow) == "2"} { set beginning "NOTICE $nikorchn"
   } else { set beginning "PRIVMSG $nikorchn" }
   set listlines "$xlists(xlstreq)"
 } else {  set beginning "PRIVMSG $nikorchn"
   if {$runnow == "mainad"} { set listlines "$xlists(mainad)"
   } else { set listlines "$xlists(altad)" }
 }
 set other [join $other] ;  set tb1 [xfrmtsize 1 $xpro(bytecount)]
 set tb2 [xfrmtsize 2 $xpro(bytecount)] ;  set tb3 ""
 if {$xpro(packcount) == "1"} { set opt1pcnt "one package"
 } else { set opt1pcnt "$xpro(packcount) packages" }
 if {$xpro(sentcount) == "0"} { set opt1snt "nothing"
 } elseif {$xpro(sentcount) == "1"} { set opt1snt "$tb1 (1 pack)"
 } else { set opt1snt "$tb1 ($xpro(sentcount) packs)" }
 if {$xclr(color) != "0" || $xclr(custom) == "1"} {
   set xclr(bold) "" ;  set xclr(ul) ""
 } else { set xclr(bold) "" ;  set xclr(ul) "" }
 foreach lline $listlines {
  if {[string match :packlist:* $lline] == "0"} {
    set lline [string map [list %nikorch $nikorchn %other $other %bn $botnick %sc $xpro(sendcnt) %ms $xpro(maxdcc) %qc $xpro(quecnt) %mq $xpro(maxque) %pc $xpro(packcount) %tp $xpro(sentcount) %tb1 $tb1 %tb2 $tb2 %tb3 $tb3 %opt1pcnt $opt1pcnt %opt1snt $opt1snt %ca1 $xclr(custalt1) %ca2 $xclr(custalt2) %bo $xclr(bold) %ul $xclr(ul) %lt $xpro(defltrig)] $lline]
    puthelp "$beginning :$lline"
  } else {  set packline [string range $lline 10 end] ;  set count "0"
    set xpfile [open $xfil(packs) r] ;  set xcpfile [open $xfil(cpack) r]
    while {![eof $xpfile]} {  set pak [gets $xpfile] ;  set cpak [gets $xcpfile]
     if {$pak != ""} {  incr count ;  set pdesc [lindex $pak 2]
       set pfile [lindex [split [lindex $pak 1] /] end]
       set pgets [lindex $cpak 0] ;  set ps1 [xfrmtsize 1 [lindex $pak 3]]
       set ps2 [xfrmtsize 2 [lindex $pak 3]] ;  set ps3 ""
       set pline [string map [list %pn $count %pd $pdesc %pf $pfile %ps1 $ps1 %ps2 $ps2 %ps3 $ps3 %pg $pgets %bo $xclr(bold) %ul $xclr(ul)] $packline]
       puthelp "$beginning :$pline"


#### EDIT ####
       if {$runnow eq "lslatest" && $count == 5} {  break  }  ;## <= set number of latest files to show #
#### END EDIT ####


     }
    }
    close $xpfile  ;  close $xcpfile
  }
 }
}

# -------------------
# CHANNEL AD CODE  ##
#--------------------
proc xchanad {channel calledby adcount fromlque} {  global iso xpro
 if {$fromlque == "0"} { set xpro(adtimerids) [lreplace $xpro(adtimerids) 0 1] }
 if {$iso == "0"} { putlog "\00304|XDCC ERROR|\003 proc xchanad: err#416: ad shouldnt stop here!" ; return 0 }
 if {[lsearch -exact $xpro(servchans) $channel] == "-1"} { return 0 }
 if {$fromlque == "0"} {
   if {$xpro(altad) == "0"} { set runnow "mainad" ; set newacount "0"
   } else {
     if {$adcount == "0"} { set runnow "mainad"
     } else { set runnow "altad" }
     if {$adcount < $xpro(altad)} { set newacount [expr $adcount+1]
     } else { set newacount "0" }
   }
   set tmrid [timer $xpro(xadtime) "[list xchanad $channel $runnow $newacount $fromlque]"]
   lappend xpro(adtimerids) $tmrid $channel  ;  set fludcheck ""
   if {$runnow == "mainad" && $xpro(lfludonad) == "1" && $xpro(lwaiton) == "1"} {
     set fludcheck "1"
   } elseif {$runnow=="altad" && $xpro(lfludonalt)=="1" && $xpro(lwaiton)=="1"} {
     set fludcheck "2"
   }
   if {$fludcheck != ""} {
     lappend xpro(priority) $channel $runnow ;  set runnow "nothing"
     if {[lsearch -exact $xpro(listque) $channel] == "-1"} {  incr xpro(lqcount)
     } else {  set chanidx [lsearch -exact $xpro(listque) $channel]
       set xpro(listque) [lreplace $xpro(listque) $chanidx [expr $chanidx+2]]
     }
   }
 } else { set runnow "$calledby" }
 if {$runnow == "nothing"} { return 0 }
 if {($runnow=="mainad" && $xpro(lfludonad)=="1") || ($runnow=="altad" && $xpro(lfludonalt)=="1")} {
   if {$fromlque == "0"} {
     set xpro(lwaiton) "1" ;  utimer $xpro(lquetime) "processlque"
   }
   set tid [utimer $xpro(listflud) "[list adresetlcmd $channel]"]
   lappend xpro(fluddafterad) $tid $channel
 }
 set other ""  ;  showxdcc $channel $runnow $other
}

proc adresetlcmd {channel} {  global xpro
 set xpro(fluddafterad) [lreplace $xpro(fluddafterad) 0 1]
}

# ----------------------------
# PUBLIC !LIST COMMAND CODE ##
# ----------------------------
proc xpublist {nick host hand chan arg} {  global iso xpro xclr botnick
 if {$iso == "0" || $xpro(listhow) == "0"} { return 0 }
 if {$xpro(lqcount) >= $xpro(lqcmax)} { return 0 }
 set chlowr [xstrlow $chan] ;  set niklwr [xstrlow $nick]
 if {[lsearch -exact $xpro(servchans) $chlowr] == "-1"} { return 0 }
 set nikusrhst [xstrlow $nick!$host]
 if {$xpro(srvrbans) != ""} {
   foreach banmask $xpro(srvrbans) {
    if {[string match $banmask $nikusrhst] == "1"} {
      lappend xpro(updatbls) $niklwr $banmask ;  set temp3 [updatban]
      return 0
    }
   }
 }
 if {$xpro(listhow) == "1"} {
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) $nick : XDCC Server Active."
   puthelp "NOTICE $nick :$xclr(c0)Type: $xclr(c3)/ctcp $botnick XDCC list$xclr(c0) to see the packs."
 } elseif {$xpro(listhow) == "2"} {
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) $nick : XDCC Server Active."
   puthelp "NOTICE $nick :$xclr(c0)Type: $xclr(c3)$xpro(cpltrig)$xclr(c0) to see the pack list."
 } else {
   if {$xpro(listhow) == "5"} { set nikorchn "$chlowr" ; set other "$niklwr"
   } else { set nikorchn "$niklwr" ;  set other "$chlowr" }
   set runnow "listreq"
   if {$xpro(lwaiton) == "1"} {
    if {[lsearch -exact $xpro(listque) $nikorchn]=="-1" && [lsearch -exact $xpro(priority) $nikorchn]=="-1"} {
      lappend xpro(listque) $nikorchn $runnow $other ; incr xpro(lqcount) }
    set runnow "nothing"
   }
   if {$runnow=="listreq"} { set zer "0" ; xpubls $nikorchn $runnow $other $zer }
 }
}

proc xpubls {nikorchn runnow other fromlq} {  global xpro
 if {$fromlq == "0"} {
   set xpro(lwaiton) "1" ;  utimer $xpro(lquetime) "processlque" }
 if {$xpro(listhow) == "5"} {
   set tid [utimer $xpro(listflud) "[list adresetlcmd $nikorchn]"]
   lappend xpro(fluddafterad) $tid $nikorchn }
 showxdcc $nikorchn $runnow $other
}

# -----------------------------------------
# CUSTOM TRIGGERED PUBLIC !XLIST COMMAND ##
# -----------------------------------------
proc xpublis2 {nick host hand chan arg} {  global iso xpro
 if {$iso == "0" || $xpro(cplhow) == "0"} { return 0 }
 if {$xpro(lqcount) >= $xpro(lqcmax)} { return 0 }
 set chlowr [xstrlow $chan] ;  set niklwr [xstrlow $nick]
 if {[lsearch -exact $xpro(servchans) $chlowr] == "-1"} { return 0 }
 set nikusrhst [xstrlow $nick!$host]
 if {$xpro(srvrbans) != ""} {
   foreach banmask $xpro(srvrbans) {
    if {[string match $banmask $nikusrhst] == "1"} {
      lappend xpro(updatbls) $niklwr $banmask
      set temp3 "[updatban]" ;  return 0
    }
   }
 }
 if {$xpro(cplhow) == "3"} { set nikorchn "$chlowr" ;  set other "$niklwr"
 } else { set nikorchn "$niklwr" ;  set other "$chlowr" }
 set runnow "lsreq2"
 if {$xpro(lwaiton) == "1"} {
  if {[lsearch -exact $xpro(listque) $nikorchn]=="-1" && [lsearch -exact $xpro(priority) $nikorchn]=="-1"} {
    lappend xpro(listque) $nikorchn $runnow $other ;  incr xpro(lqcount) }
  set runnow "nothing"
 }
 if {$runnow == "lsreq2"} { set zer "0" ; xpubli2 $nikorchn $runnow $other $zer }
}



#### EDIT ####
proc xpublislatest {nick host hand chan arg} {  global iso xpro
 if {$iso == "0" || $xpro(cplhow) == "0"} { return 0 }
 if {$xpro(lqcount) >= $xpro(lqcmax)} { return 0 }
 set chlowr [xstrlow $chan] ;  set niklwr [xstrlow $nick]
 if {[lsearch -exact $xpro(servchans) $chlowr] == "-1"} { return 0 }
 set nikusrhst [xstrlow $nick!$host]
 if {$xpro(srvrbans) != ""} {
   foreach banmask $xpro(srvrbans) {
    if {[string match $banmask $nikusrhst] == "1"} {
      lappend xpro(updatbls) $niklwr $banmask
      set temp3 "[updatban]" ;  return 0
    }
   }
 }
 if {$xpro(cplhow) == "3"} { set nikorchn "$chlowr" ;  set other "$niklwr"
 } else { set nikorchn "$niklwr" ;  set other "$chlowr" }

 set runnow "lslatest"

 if {$xpro(lwaiton) == "1"} {
  if {[lsearch -exact $xpro(listque) $nikorchn]=="-1" && [lsearch -exact $xpro(priority) $nikorchn]=="-1"} {
    lappend xpro(listque) $nikorchn $runnow $other ;  incr xpro(lqcount) }
  set runnow "nothing"
 }

 if {$runnow == "lslatest"} { set zer "0" ; xpubli2 $nikorchn $runnow $other $zer }

}
#### END EDIT ####



proc xpubli2 {nikorchn runnow other fromlq} {  global xpro
 if {$fromlq == "0"} {
   set xpro(lwaiton) "1" ;  utimer $xpro(lquetime) "processlque"
 }
 if {$xpro(cplhow) == "3"} {
   set tid [utimer $xpro(listflud) "[list adresetlcmd $nikorchn]"]
   lappend xpro(fluddafterad) $tid $nikorchn
 }
 showxdcc $nikorchn $runnow $other
}

## reply to public !xdcc ##
proc xpubxdcc {nick host hand chan arg} {  global botnick xpro xclr iso
 set chlowr [xstrlow $chan] ;  set niklwr [xstrlow $nick]
 if {$iso == "1" && [lsearch -exact $xpro(servchans) $chlowr] != "-1"} {
   set nikusrhst [xstrlow $nick!$host]
   if {$xpro(srvrbans) != ""} {
     foreach banmask $xpro(srvrbans) {
      if {[string match $banmask $nikusrhst] == "1"} {
        lappend xpro(updatbls) $niklwr $banmask
        set temp3 [updatban] ;  return 0
      }
     }
   }
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) $nick : XDCC Server Active."
   puthelp "NOTICE $nick :$xclr(c0)Type: $xclr(c3)/ctcp $botnick XDCC help$xclr(c0) to get started."
 }
}

# ----------------------
# \CTCP COMMANDS CODE ##
# ----------------------
proc xctcpevent {nick uhost handle dest keyword arg} {  global xpro xclr
 set onasrvch "0" ;  set onchls ""
 foreach chan $xpro(servchans) {
  if {[onchan $nick $chan] == "1"} { incr onasrvch ; lappend onchls $chan }
 }
 if {$onasrvch != "0"} {
   putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) CTCP from $nick (OnChan: [join $onchls]) handle: $handle"
   xctcpmonitor $nick $uhost $handle $arg $onchls
 } else { putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) CTCP from $nick (NOT on any serv chans!) handle: $handle" }
}

proc xctcpmonitor {nick uhost handle command onchanls} {
 global iso xpro xinf xclr botnick numversion
 if {$iso == "0"} { return 0 }
 set nicklower [xstrlow $nick]  ;  set nikusrhst [xstrlow $nick!$uhost]
 if {$xpro(srvrbans) != ""} {
   foreach banmask $xpro(srvrbans) {
    if {[string match $banmask $nikusrhst] == "1"} {
      lappend xpro(updatbls) $nicklower $banmask ;  set temp3 [updatban]
      putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) $nick banned by banmask: $banmask"
      return 0
    }
   }
 }
 if {$command == ""} { set command "help" }
 set clist [split [xstrlow $command]] ;  set cmd [lindex $clist 0]
 if {$cmd == "list"} {
   if {$xpro(xlsthow) == "0" || $xpro(lqcount) >= $xpro(lqcmax)} { return 0 }
   set calledby "xlstreq"
   if {$xpro(lwaiton) == "0"} {
     set xpro(lwaiton) "1" ;  utimer $xpro(lquetime) "processlque"
     showxdcc $nicklower $calledby $onchanls
   } else {
     if {[lsearch -exact $xpro(listque) $nicklower] == "-1"} {
       lappend xpro(listque) $nicklower $calledby $onchanls ; incr xpro(lqcount)
     }
   }
 } elseif {$cmd == "info"} {  set tmp2 [string range $numversion 1 2]
   if {[string index $tmp2 0] == "0"} { set tmp2 [string index $tmp2 1] }
   set eggver "[string index $numversion 0].$tmp2.[string range $numversion 3 4]"
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) I'm $botnick, an eggdrop bot v$eggver"
   puthelp "NOTICE $nick :$xclr(c0)Running XDCC SERVER PRO v$xinf(ver) by SpiKe^^ (#pc-mIRC-help on undernet)"   
 } elseif {$cmd == "send"} {
   if {[lindex $clist 1] == ""} {
     puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Which package do you want?"
     puthelp "NOTICE $nick :$xclr(c0)example (get pack 4):$xclr(c3) /ctcp $botnick XDCC send #4"
   } else {  set getpack [string trimleft [lindex $clist 1] #]
     if {[string is digit -strict $getpack] == "1"} {
       if {[string index $getpack 0] != "0"} {
         pushqueue $nicklower $getpack $uhost $handle
       } else { set cmd "help" }
     } else { set cmd "help" }
   }
 } else { set cmd "help" }
 if {$cmd == "help"} {
   puthelp "NOTICE $nick :$xclr(c0)XDCC SERVER PRO version $xinf(ver) for Eggdrops -HELP-"
   puthelp "NOTICE $nick :$xclr(c0)Command usage:$xclr(c3) /ctcp $botnick XDCC <command>"
   puthelp "NOTICE $nick :$xclr(c0)Commands are: help, list, info, send #<packnumber>"
   puthelp "NOTICE $nick :$xclr(c0)example:$xclr(c3) /ctcp $botnick XDCC list $xclr(c0)(see the packs list)"
   puthelp "NOTICE $nick :$xclr(c0)example:$xclr(c3) /ctcp $botnick XDCC send #4 $xclr(c0)(get pack #4)"
   puthelp "NOTICE $nick :$xclr(c0)XDCC SERVER PRO by $xinf(auth)"
 }
}

#### add a pack to the quefile..
proc pushqueue {nick packnumber uhost handle} {  global xpro xfil xclr
 set packindex "0" ;  set isonqueue "0" ;  set isonqlist ""
 set nicklwr [xstrlow $nick]  ;  set uhsttmplist [split [xstrlow $uhost] @]
 set usrnme [lindex $uhsttmplist 0] ;  set usrhst [lindex $uhsttmplist 1]
 if {$xpro(quecnt) >= $xpro(maxque)} {
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Maximum number of queues reached. Try again later."
 } elseif {$packnumber > $xpro(packcount)} {
   puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) The specified package doesn't exist."
 } else {
   if {![file exists $xfil(que)]} { set xqfile [open $xfil(que) w]
   } else {  set qnum "0" ;  set xqfile [open $xfil(que) r+]
     while {![eof $xqfile]} {  set onquenow [gets $xqfile]
      if {$onquenow != ""} { incr qnum
       if {[lindex $onquenow 2]==$nicklwr || [lindex $onquenow 3]==$usrnme || [lindex $onquenow 4]==$usrhst} {
         incr isonqueue ;  lappend isonqlist [lindex $onquenow 0] $qnum
       }
      }
     }
   }
   if {$isonqueue < $xpro(usrmaxq)} {  set xpfile [open $xfil(packs) r]
     while {![eof $xpfile] && $packindex!=$packnumber} {
      set temp [gets $xpfile] ;  if {$temp != ""} { incr packindex }
     }
     close $xpfile
     if {$packindex != $packnumber} {
       puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Specified package doesn't exist ! (error #672)"
       putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) |ERROR| specified package doesn't exist ! (error #672)"
     } else {  set pfile [lindex $temp 1] ;  set psize [lindex $temp 3]
       if {[set nikidx [lsearch -exact $isonqlist $pfile]] == "-1"} {
         set gonecount "0" ;  incr xpro(quecnt)
         puts $xqfile "[list $pfile $psize $nicklwr $usrnme $usrhst $handle $gonecount]"
         puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Your request has been placed on queue $xpro(quecnt)/$xpro(maxque)"
         puthelp "NOTICE $nick :$xclr(c0)You'll receive your pack when a send is available. Stay in the channel & don't change nick or your queue will be removed !"
       } else { puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) You have that pack in queue at position [lindex $isonqlist [expr $nikidx+1]]." }
     }
   } else {
     if {$xpro(usrmaxq) == "1"} {
       puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) You can only get $xpro(usrmaxq) package at a time."
     } else { puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) You can only get $xpro(usrmaxq) packages at a time." }
   }
   close $xqfile
 } 
}

# -------------------
# PROCESS SEND QUE ##
# -------------------
proc processqueue {} {  global iso xpro xfil xclr
 set dccsndcount "0" ;  set dccsndlist "" ;  set lubanls ""
 set cutime [unixtime]
 foreach dsend [dcclist GET] {
  if {$dsend != ""} {
   set dlidx [lindex $dsend 0] ; set dlnick [xstrlow [lindex $dsend 1]]
   set dlhost "-" ;  set banned "0"
   foreach chan $xpro(servchans) {  set dlnikuhost [getchanhost $dlnick $chan]
    if {$dlnikuhost != ""} {
      if {$xpro(srvrbans) != ""} {  set tmp2 [xstrlow $dlnick!$dlnikuhost]
        foreach banmask $xpro(srvrbans) {
         if {[string match $banmask $tmp2] == "1"} {
           putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Send killed by new ban: $banmask"
           killdcc $dlidx ;  set banned "1" ;  incr xpro(sendcnt) -1
           if {[lsearch -exact $lubanls $banmask] == "-1"} {
             lappend lubanls $dlnick $banmask }
           break
         }
        }
      }
      set dlhost [xstrlow [lindex [split $dlnikuhost @] 1]] ; break
    }
   }
   if {$banned == "0"} {
     incr dccsndcount ;  lappend dccsndlist $dlidx $dlnick $dlhost
   }
  }
 }
 if {$lubanls != ""} {
   set xpro(updatbls) "$lubanls" ; set tmp3 [updatban] ; set lubanls ""
 }
 if {$xpro(sendcnt) != $dccsndcount} { set xpro(sendcnt) "$dccsndcount" }
 if {$dccsndcount != "0"} {  set sendintotmp ""
  foreach {dlidx dlnick dlhost} $dccsndlist {
   set fidx [lsearch -exact $xpro(sendingto) $dlnick]
   set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
   foreach {fnik fhst fgone ftime} $foundinfo {
    if {$dlhost == "-"} {
     if {$fgone < $xpro(stimegone)} {
      incr fgone ;  lappend sendintotmp $fnik $fhst $fgone $ftime
      putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Activesendnick $dlnick ($fhst) not on channel. (gonecount $fgone)"
     } else {  killdcc $dlidx ;  incr xpro(sendcnt) -1
      putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Killed send to $dlnick ($fhst) : gone over $fgone minutes"
     }
    } else { set fgone "0" ; lappend sendintotmp $fnik $fhst $fgone $ftime }
   }
  }
  set xpro(sendingto) "$sendintotmp"
 } else {
  if {$xpro(sendingto) != ""} { set xpro(sendingto) "" }
 }
 if {$iso == "1"} {
  if {$xpro(quecnt) != "0"} {
   set sendsstarted "" ;  set xqfile [open $xfil(que) r]
   set xtemp "./scripts/xdccque.tmp" ;  set xtfile [open $xtemp w]
   while {![eof $xqfile]} {  set queinfo [gets $xqfile]
    if {$queinfo != ""} {
      foreach {file sz qnik usrn qhst hand gcnt} $queinfo {
       set onaservchan "0" ;  set onchannel "" ;  set banned "0"
       if {$xpro(srvrbans) != ""} {  set tmp2 [xstrlow $qnik!$usrn@$qhst]
         foreach banmask $xpro(srvrbans) {
          if {[string match $banmask $tmp2] == "1"} {
            set banned "1" ;  break
          }
         }
       }
       if {$banned == "1"} {  incr xpro(quecnt) -1
         if {[lsearch -exact $lubanls $banmask] == "-1"} {
           lappend lubanls $qnik $banmask
         }
         putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Send removed from que by new ban: $banmask"
       } else {
         foreach chan $xpro(servchans) {
          if {$onchannel == "" && [onchan $qnik $chan] == "1"} {
            incr onaservchan ;  set onchannel $chan
          }
         }
         if {$onaservchan == "0"} {  set gonecount "$gcnt"
           if {$gonecount < $xpro(qtimegone)} {
             incr gonecount ; puts $xtfile "[lrange $queinfo 0 5] $gonecount"
           } else {  incr xpro(quecnt) -1
             putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) File removed from que: $file to $qnik (left servchans, gone over $gonecount min)"
           }
         } else {
           if {$xpro(sendcnt) < $xpro(maxdcc)} {  set error "0"
             foreach {fnik fhst fgone ftime} $xpro(sendingto) {
              if {$fnik == $qnik || $fhst == $qhst} { incr error }
             }
             set err2 "0"
             foreach {nikandhst} $sendsstarted {
              set sendinnik [lindex $nikandhst 0] ; set sendinhst [lindex $nikandhst 1]
              if {$sendinnik == $qnik || $sendinhst == $qhst} { incr err2 }
             }
             if {$error == "0" && $err2 == "0"} {
              putserv "NOTICE $qnik :$xclr(c0)$xpro(logo) |$qnik| Now sending you your requested package -|RESUME SUPPORTED|-"
              set size [xfrmtsize 1 [lindex $queinfo 1]]
              putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Now sending file [lindex $queinfo 0] ($size) to $qnik (on: $onchannel)"
              incr xpro(sendcnt) ;  incr xpro(quecnt) -1
              set sending [list $qnik $qhst]
              lappend sendsstarted $sending
              xdccsend [lindex $queinfo 0] $qnik $qhst
             } else {
              set gonecount "0" ; puts $xtfile "[lrange $queinfo 0 5] $gonecount"
             }
           } else {
             set gonecount "0" ; puts $xtfile "[lrange $queinfo 0 5] $gonecount"
           }
         }
       }
      }
    }
   }
   close $xqfile ;  close $xtfile ;  file delete $xfil(que)
   file rename $xtemp $xfil(que)  ;  file delete $xtemp
   timer 1 "processqueue"
  } else { timer 1 "processqueue" }
 }
 if {$lubanls != ""} {
   set xpro(updatbls) "$lubanls" ; set tmp3 [updatban] ; set lubanls ""
 }
 if {$xpro(sendcnt) != "0" && $iso == "0"} {  timer 1 "processqueue"
   putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Sends are still active!!  Monitoring sends for gone from servchans"
   putlog "Use $xclr(dcc).dsend -all$xclr(dcce) to kill all sends, or $xclr(dcc).lsend$xclr(dcce) to list all active sends."
 }
}

## send a file now.. if no send catch the error.. 
proc xdccsend {xfile nick host} {  global xpro xclr
 set status [dccsend $xfile $nick]
 if {$status == "2"} { incr xpro(sendcnt) -1 
  puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Unable to open a socket for the transfer"
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Unable to open a socket for the transfer to $nick"
 }
 if {$status == "1"} { incr xpro(sendcnt) -1
  puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) DCC Table Full (too many connections)"
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) DCC Table full (too many connections) for $nick"
 }
 if {$status != "0"} { incr xpro(sendcnt) -1
  puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) An error occured when trying to send requested package"
  putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) An error occured when trying to send requested package for $nick"
 }
 if {$status == "0"} {
  set goncnt "0" ; lappend xpro(sendingto) $nick $host $goncnt [unixtime]
 }
}

## bind sent.. ##
proc xupdate {handle nick path} {  global xpro xfil xclr
 set temp "0" ;  set count "0" ;  set count2 "0"
 set xtemp "./scripts/xdcc.tmp" ;  set xpfile [open $xfil(packs) r]
 while {![eof $xpfile] && [lindex $temp 1]!=$path} {  set temp [gets $xpfile]
  if {$temp != ""} { incr count }
 }
 close $xpfile
 set xcpfile [open $xfil(cpack) r] ;  set xttfile [open $xtemp w]
 while {![eof $xcpfile]} {  set downpack [gets $xcpfile]
  if {$downpack != ""} {  incr count2
   if {$count == $count2} { incr downpack ;  puts $xttfile "$downpack"
   } else { puts $xttfile "$downpack" }
  }
 }
 close $xcpfile ;  close $xttfile ;  file delete $xfil(cpack)
 file rename $xtemp $xfil(cpack)  ;  file delete $xtemp
 set dlpacksize [lindex $temp 3]
 if {![file exists $xfil(totals)]} {
   set xcbfile [open $xfil(totals) w] ;  set totsends "1"
   puts $xcbfile "$dlpacksize $totsends"
 } else {
   set xcbfile [open $xfil(totals) r] ;  set amounts [gets $xcbfile]
   close $xcbfile
   set totbytes [lindex $amounts 0] ;  set totpacks [lindex $amounts 1]
   set totbytes [expr round($totbytes+${dlpacksize}.0)]
   set totpacks [expr round(1+${totpacks}.0)]
   set xcbfile [open $xfil(totals) w] ; puts $xcbfile "$totbytes $totpacks"
 }
 close $xcbfile
 set xpro(packssent) [expr round(1+${xpro(packssent)}.0)]
 set xpro(bytessent) [expr round($dlpacksize+${xpro(bytessent)}.0)]
 set xpro(bytecount) [expr round($dlpacksize+${xpro(bytecount)}.0)]
 set xpro(sentcount) [expr round(1+${xpro(sentcount)}.0)]
 incr xpro(sendcnt) -1 ;  set filename [lindex [split $path /] end]
 putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Successfully sent Pack #[lindex $temp 0] : $path to $nick"
 puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Successfully sent Pack #[lindex $temp 0] : $filename"
 set nicklower [xstrlow $nick]
 set fidx [lsearch -exact $xpro(sendingto) $nicklower]
 set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
 foreach {fnik fhst fgone ftime} $foundinfo {
  set tooksecs [expr round([unixtime]-${ftime}.0)]
 }              
 set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
}

proc xlosttransfer {handle nick path bytes lenght} {  global xpro xfil xclr
 incr xpro(sendcnt) -1  ;  set pathtmplist [split $path /]
 set filename [lindex $pathtmplist end]  ;  set temp "0"
 set xpfile [open $xfil(packs) r]
 while {![eof $xpfile] && [lindex $temp 1]!=$path} {
  set temp [gets $xpfile]
 }
 close $xpfile
 puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) An error occured when sending you Pack #[lindex $temp 0] : $filename"
 puthelp "NOTICE $nick :$xclr(c0)Transfer lost at : $bytes of $lenght"
 putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) An error occured when sending $nick Pack #[lindex $temp 0] : $path ($bytes/$lenght)"
 set nicklower [xstrlow $nick]
 set fidx [lsearch -exact $xpro(sendingto) $nicklower]
 set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
 foreach {fnik fhst fgone ftime} $foundinfo {
  set tooksecs [expr round([unixtime]-${ftime}.0)]
 }
 set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
}

proc xtimeout {handle nick path bytes lenght} {  global xpro xfil xclr
 incr xpro(sendcnt) -1  ;  set pathtmplist [split $path /]
 set filename [lindex $pathtmplist end]  ;  set temp "0"
 set xpfile [open $xfil(packs) r]
 while {![eof $xpfile] && [lindex $temp 1]!=$path} {
  set temp [gets $xpfile]
 }
 close $xpfile
 puthelp "NOTICE $nick :$xclr(c0)$xpro(logo) Filesend Pack #[lindex $temp 0] : $filename timed out !!"
 puthelp "NOTICE $nick :$xclr(c0)Timed out at : $bytes of $lenght"
 putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Time out on send Pack #[lindex $temp 0] : $path to $nick ($bytes/$lenght)"
 set nicklower [xstrlow $nick]
 set fidx [lsearch -exact $xpro(sendingto) $nicklower]
 set foundinfo [lrange $xpro(sendingto) $fidx [expr $fidx+3]]
 foreach {fnik fhst fgone ftime} $foundinfo {
  set tooksecs [expr round([unixtime]-${ftime}.0)]
 }
 set xpro(sendingto) [lreplace $xpro(sendingto) $fidx [expr $fidx+3]]
}

# -------------------
# PROCESS LIST QUE ##
# -------------------
proc processlque {} {  global iso xpro
 if {$iso == "0" || ($xpro(lqcount) == "0" && $xpro(fluddafterad) == "")} {
   set xpro(priority) "" ;  set xpro(listque) ""
   set xpro(lqcount) "0" ;  set xpro(lwaiton) "0" ;  return 0 }
 set lst2send "" ;  set chanoff ""
 if {$xpro(priority) != ""} {  set plindex "-2" ;  set p2go ""
   foreach {chan runnow} $xpro(priority) {
    if {$lst2send == ""} {  incr plindex 2
      if {[lsearch -exact $xpro(servchans) $chan] != "-1"} {
        if {[lsearch -exact $xpro(fluddafterad) $chan] == "-1"} {
          lappend lst2send $chan $runnow ;  incr xpro(lqcount) -1
          set xpro(priority) [lreplace $xpro(priority) $plindex [expr $plindex+1]]
        }
      } else { lappend chanoff $chan ; lappend p2go $plindex [expr $plindex+1] }
    }
   }
   if {$p2go != ""} {
     set delthis [lsort -integer -decreasing $p2go] ;  set gonecnt "0"
     foreach {larger smallr} $delthis {
      incr gonecnt -1 ; set xpro(priority) [lreplace $xpro(priority) $smallr $larger]
     }
     incr xpro(lqcount) $gonecnt
   }
 }
 if {$lst2send == "" && $xpro(listque) != ""} {
   set qlindex "-3" ;  set q2go "" ;  set lubanls ""
   foreach {nikorchn runnow other} $xpro(listque) {
    if {$lst2send == ""} {  incr qlindex 3

#### EDIT ####

      if {($runnow=="listreq" && $xpro(listhow)=="5") || ($runnow in {lsreq2 lslatest} && $xpro(cplhow)=="3")} {

#### END EDIT ####


        if {$chanoff != "" && [lsearch -exact $chanoff $nikorchn] != "-1"} {
          lappend q2go $qlindex [expr $qlindex+2]
        } elseif {[lsearch -exact $xpro(servchans) $nikorchn] != "-1"} {  set usrhost ""
          foreach channel $xpro(servchans) {
           if {[onchan $other $channel] == "1"} {
             set chost [getchanhost $other $channel]
             set usrhost [xstrlow $other!$chost]
             break
           }
          }
          if {$usrhost != ""} {  set banned "0"
            if {$xpro(srvrbans) != ""} {
              foreach banmask $xpro(srvrbans) {
               if {[string match $banmask $usrhost] == "1"} {
                 set banned "$banmask" ;  break
               }
              }
            }
            if {$banned == "0"} {
              if {[lsearch -exact $xpro(fluddafterad) $nikorchn] == "-1"} {
                lappend lst2send $nikorchn $runnow $other ; incr xpro(lqcount) -1
                set xpro(listque) [lreplace $xpro(listque) $qlindex [expr $qlindex+2]]
              }
            } else {  lappend q2go $qlindex [expr $qlindex+2]
              if {[lsearch -exact $lubanls $banned] == "-1"} {
                lappend lubanls $other $banned
              }
            }
          } else { lappend q2go $qlindex [expr $qlindex+2] }
        } else {
          lappend chanoff $nikorchn ; lappend q2go $qlindex [expr $qlindex+2]
        }
      } else { set onachan "0" ;  set banned "0"
        foreach channel $xpro(servchans) {
         if {$onachan == "0" && [onchan $nikorchn $channel] == "1"} {
          incr onachan
          set usrhost [xstrlow $nikorchn![getchanhost $nikorchn $channel]]
         }
        }
        if {$onachan != "0"} {
          if {$xpro(srvrbans) != ""} {
            foreach banmask $xpro(srvrbans) {
             if {$banned == "0" && [string match $banmask $usrhost] == "1"} {
               set banned "$banmask"
             }
            }
          }
          if {$banned == "0"} {
            lappend lst2send $nikorchn $runnow $other ;  incr xpro(lqcount) -1
            set xpro(listque) [lreplace $xpro(listque) $qlindex [expr $qlindex+2]]
          } else {  lappend q2go $qlindex [expr $qlindex+2]
            if {[lsearch -exact $lubanls $banned]} {
              lappend lubanls $nikorchn $banned
            }
          }
        } else { lappend q2go $qlindex [expr $qlindex+2] }
      }
    }
   }
   if {$q2go != ""} {
     set delthis [lsort -integer -decreasing $q2go] ;  set gonecnt "0"
     foreach {larger smallr} $delthis {
      incr gonecnt -1 ; set xpro(listque) [lreplace $xpro(listque) $smallr $larger]
     }
     incr xpro(lqcount) $gonecnt
   }
   if {$lubanls != ""} {
     set xpro(updatbls) "$lubanls" ;  set temp3 [updatban]
   }
 }
 if {$lst2send != ""} {
   set nikorchn [lindex $lst2send 0] ;  set runnow [lindex $lst2send 1]
   set adcount "0" ;  set fromlque "1"
   if {[llength $lst2send] == "3"} { set other [lindex $lst2send 2] }
   if {$runnow == "listreq"} { xpubls $nikorchn $runnow $other $fromlque


#### EDIT ####
   } elseif {$runnow in {lsreq2 lslatest}} { xpubli2 $nikorchn $runnow $other $fromlque
#### END EDIT ####


   } elseif {$runnow == "xlstreq"} { showxdcc $nikorchn $runnow $other
   } else { xchanad $nikorchn $runnow $adcount $fromlque }
 }
 utimer $xpro(lquetime) processlque
}

## --------------------
### MISC SERVER CODE ##
## --------------------

proc updatban {} {  global xpro xfil
 set cutime [unixtime] ;  set xbantmproute "./scripts/xbans.tmp"
 set xbantmpfile [open $xbantmproute w] ; set xbanfile [open $xfil(bans) r]
 set count "0" ;  set updatbcnt [expr [llength $xpro(updatbls)]/2]
 while {![eof $xbanfile]} {  set temp [gets $xbanfile]
  if {$temp != ""} { 
    foreach {mask nik creat lused req resn} $temp {
     set tmp2 [lsearch -exact $xpro(updatbls) $mask]
     if {$tmp2 == "-1"} { puts $xbantmpfile "$temp"
     } else {  incr count
       set lastbnik [lindex $xpro(updatbls) [expr $tmp2-1]]
       puts $xbantmpfile "[list $mask $lastbnik $creat $cutime $req $resn]"
     }
    }
  }
 }
 close $xbanfile ;  close $xbantmpfile ;  file delete $xfil(bans)
 file rename $xbantmproute $xfil(bans) ; file delete $xbantmproute
 if {$count != $updatbcnt} { putlog "/00304!!! proc updatban ERROR #762 !!!" }
 set xpro(updatbls) "" ;  return 1
}

proc xtimeago {time} {
 if {$time == "0"} { return 0 }
 set cutime [unixtime]
 set crtime [expr round($cutime-${time}.0)]
 if {$crtime < "86400"} {  set ctemp [duration $crtime]
   if {[string match *second* $ctemp] == "1"} {
     set tmp2 [split $ctemp]
     if {[llength $tmp2] == "2"} { set cago "$ctemp"
     } else { set cago [join [lrange $tmp2 0 end-2]] }
   } else { set cago "$ctemp" }
 } else {  set ctemp [expr round(${crtime}.0/86400)]
   if {$ctemp=="1"} { set cago "1 day" } else { set cago "$ctemp days" }
 }
 return $cago
}

proc xfrmtsize {fmthow sz} {
 set si0 [string index $sz 0] ;  set si1 [string index $sz 1]
 set si2 [string index $sz 2] ;  set si3 [string index $sz 3]
 set sizelenght [string length $sz] ;  set fmtd "0"
 if {$sizelenght == "1" && $si0 == "0"} {
  if {$fmthow == "1"} { set fmtd "nothing" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "nothing" ; return "$fmtd"
  } elseif {$fmthow == "3"} { set fmtd "nothing" ; return "$fmtd" }
 }
 if {$sizelenght <= "3"} {
  if {$fmthow == "1"} { set fmtd "$sz bytes" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd " <1Kb" ; return "$fmtd"
  } elseif {$fmthow == "3"} { set fmtd "<1kB" ; return "$fmtd" }
 }
 if {$sizelenght == "4"} {
  if {$fmthow == "1"} {
    if {$si0 == "1"} { set fmtd "1 kb" ;  return "$fmtd"
    } else { set fmtd "$si0 kb's" ;  return "$fmtd" }
  } elseif {$fmthow == "2"} { set fmtd "$si0.$si1$si2\Kb" ; return "$fmtd" }
 } 
 if {$sizelenght == "5"} {
  if {$fmthow == "1"} { set fmtd "$si0$si1 kb's" ;  return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0$si1.$si2\Kb" ; return "$fmtd" }
 }
 if {$sizelenght == "6"} {
  if {$fmthow == "1"} { set fmtd "$si0$si1$si2 kb's" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0$si1$si2\Kb" ; return "$fmtd" }
 }
 if {$sizelenght == "7"} {
  if {$fmthow == "1"} {
    if {$si0 == "1"} { set fmtd "1 meg" ;  return "$fmtd"
    } else { set fmtd "$si0 meg's" ;  return "$fmtd" }
  } elseif {$fmthow == "2"} { set fmtd "$si0.$si1$si2\Mb" ; return "$fmtd" }
 }
 if {$sizelenght == "8"} {
  if {$fmthow == "1"} { set fmtd "$si0$si1 meg's" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0$si1.$si2\Mb" ; return "$fmtd" }
 }
 if {$sizelenght == "9"} {
  if {$fmthow == "1"} { set fmtd "$si0$si1$si2 meg's" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0$si1$si2\Mb" ; return "$fmtd" }
 }
 if {$sizelenght == "10"} {
  if {$fmthow == "1"} { set fmtd "$si0.$si1$si2$si3 gig's" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0.$si1$si2\Gb" ; return "$fmtd" }
 }
 if {$sizelenght == "11"} {
  if {$fmthow == "1"} {
    set fmtd "$si0$si1.$si2$si3 gig's" ;  return "$fmtd"
  } elseif {$fmthow == "2"} {
    set fmtd "$si0$si1.$si2\Gb" ;  return "$fmtd"
  }
 }
 if {$sizelenght == "12"} {
  if {$fmthow == "1"} { set fmtd "$si0$si1$si2 gig's (WOW:)" ; return "$fmtd"
  } elseif {$fmthow == "2"} { set fmtd "$si0$si1$si2\Gb" ; return "$fmtd" }
 }
 return "WOW"
}

##########  FUTURE NEW SETTINGS  ##########
set xpro(customad) "0"
set xpro(customalt) "0"
set xpro(customls) "0"
set xpro(customl2) "0"
set xpro(customxls) "0"

# ------------------------------------
# SERVER SETTINGS VARIABLE PROOVING ##
# ------------------------------------
##  XPRO(adtonextch)  ## keep this set 1 - 4 ## default = 1 min ####
if {[string is digit -strict $xpro(adtonextch)]=="0"||[string length $xpro(adtonextch)]>"1"} {
  set xpro(adtonextch) "1"
} elseif {$xpro(adtonextch) > "4"} { set xpro(adtonextch) "4"
} elseif {$xpro(adtonextch) == "0"} { set xpro(adtonextch) "1" }
##  XPRO(listflud)  ## keep this set 60 - 300 ## default = 120 sec ####
## take minute numbers 1 - 5 and convert to seconds 60 - 300 ##
if {[string is digit -strict $xpro(listflud)]=="0" || [string index $xpro(listflud) 0]=="0"} {
  set xpro(listflud) "120"
} elseif {$xpro(listflud) > "300"} { set xpro(listflud) "300" 
} elseif {[string length $xpro(listflud)] == "1"} {
  if {$xpro(listflud) > "5"} { set xpro(listflud) "300" 
  } else { set xpro(listflud) "[expr $xpro(listflud) * 60]" }
} elseif {$xpro(listflud) < "60"} { set xpro(listflud) "120" }
##  XPRO(firstad)  ## keep this set 0 - 9 ## default = 5 min ####
if {[string is digit -strict $xpro(firstad)]=="0"||[string length $xpro(firstad)]>"1"} {
  set xpro(firstad) "5" }
##  XPRO(listhow)  ## keep this set 0 - 5 ## default = 5 (chan) ####
if {[string is digit -strict $xpro(listhow)]=="0"||[string length $xpro(listhow)]>"1"} {
  set xpro(listhow) "5"
} elseif {$xpro(listhow) > "5"} { set xpro(listhow) "5" }
##  XPRO(cplhow)  ## keep this set 0 - 3 ## default = 3 (chan) ####
if {[string is digit -strict $xpro(cplhow)]=="0"||[string length $xpro(cplhow)]>"1"} {
  set xpro(cplhow) "3"
} elseif {$xpro(cplhow) > "3"} { set xpro(cplhow) "3" }
##  XPRO(xlsthow)  ## keep this set 0 - 2 ## default = 1 (msg) ####
if {[string is digit -strict $xpro(xlsthow)]=="0"||[string length $xpro(xlsthow)]>"1"} {
  set xpro(xlsthow) "1"
} elseif {$xpro(xlsthow) > "2"} { set xpro(xlsthow) "1" }
##  XPRO(defpath)  ## split to a list at the commas ## make any missing default dirs ####
set xpro(defpath) [split $xpro(defpath) ,]  ;  set xnew ""
foreach xtmp $xpro(defpath) {  set xtmp [string trim $xtmp]  ;  lappend xnew $xtmp
 if {![file isdirectory $xtmp]} {  file mkdir $xtmp  }
}
set xpro(defpath) $xnew

# ------------------------------------------
# NON-SETTENG VARIABLE SET-UP ##
# ------------------------------------------
# store info from last .lque #
if {![info exists xpro(queinfo)]} { set xpro(queinfo) "" ; set xpro(qinfocount) "0" }
# store info from last .lban #
if {![info exists xpro(baninfo)]} { set xpro(baninfo) "" ; set xpro(baninfc) "0" }
set xpro(updatbls) "" ;# set this then call proc updatban #
#[Ad timers id#s & chan (lappend tid chan) ]#
if {![info exists xpro(adtimerids)]} { set xpro(adtimerids) "" }
#[Chans with after chan list delay timers running (lappend tid chan) ]#
#         IMPORTANT: was "chan chan"  (NOW: "tid chan tid chan")!!! ###
if {![info exists xpro(fluddafterad)]} { set xpro(fluddafterad) "" }
#[2 minute pause after .xstop or any server stop (set 0 at idle) ]#
#     [ .xstop sets it to 1 ][ .xstart when running sets it to 2 ]#
if {![info exists xpro(xstartpaus)]} { set xpro(xstartpaus) "0" }
#[Lists waiting to send (lappend nikorchn callthis other) ]#
if {![info exists xpro(listque)]} { set xpro(listque) "" }
#[Channel Ads waiting to send (lappend nikorchn callthis) ]#
if {![info exists xpro(priority)]} { set xpro(priority) "" }
#[List Que count (start at "0") ]#
if {![info exists xpro(lqcount)]} { set xpro(lqcount) "0" }
#[Lwaiton: (start at "0") any list send changes this to "1"
#          and timer calls proc processlque...
#          stays "1" til lqcount gets to "0" and the que resets
if {![info exists xpro(lwaiton)]} { set xpro(lwaiton) "0" }
#[My infos!]
set xinf(auth) "SpiKe^^ (undernet: #pc-mIRC-help)"
#[Version Number]
set xinf(ver) "2.04.2"
#[Dcc Logo]
set xpro(dlogo) "|XDCC PRO|"
#[Force Dcc Colors] [set a 2 digit color code :example: "10"]
# [set "none" for no colors in dcc chat/putlog]
# [or "" to follow server colors. uses logo color w/o bg]
set xpro(forcedclr) ""
#[Server open ? 1=open | 0=closed]
if {![info exists iso]} { set iso "0" }
#[Auto-start timer running now ? 0=no | 1=yes]
if {![info exists xpro(astarted)]} { set xpro(astarted) "0" }
#[How many sends at the moment ?]
if {![info exists xpro(sendcnt)]} { set xpro(sendcnt) "0" }
#[How many queues at the moment ?]
if {![info exists xpro(quecnt)]} { set xpro(quecnt) "0" }
#[Sending to var.. ]
if {![info exists xpro(sendingto)]} { set xpro(sendingto) "" }
#[Ad #1 triggers the ListFlood wait time for new list sends ?]
# [enabled only if Ad #1 includes the packs list!]
set xpro(lfludonad) "0"
#[Ad #2 triggers the ListFlood wait time for new list sends ?]
# [enabled only if Ad #2 includes the packs list!]
set xpro(lfludonalt) "0"


proc xchkvars { {chopt 0} } {  global xpro xfil xclr xinf xlists
### Begin proc xchkvars:  read/write dset file and set up vars ####

if {$chopt == "0"} {
 set xstmprute "./scripts/xsets.tmp" ; set xstmpfil [open $xstmprute w]
 set oldsls "" ;  set xut [unixtime]
}
if {[file exists $xfil(dset)]} {  set xsetfile [open $xfil(dset) r]
 while {![eof $xsetfile]} {  set xsetline [gets $xsetfile]
  if {$xsetline != ""} {
   foreach {xvar cset cdat xnow sdat xsby range} $xsetline { break }
   if {$chopt == "1"} {  set $xvar $xnow
   } else {
    if {![xstrdig $cdat]} { set cdat "$xut" }
    if {![xstrdig $sdat]} { set sdat "$xut" }
    if {$xsby == ""} { set xsby "unknown" }
    lappend oldsls [list $xvar $cset $cdat $xnow $sdat $xsby $range]
   }
  }
 }
 close $xsetfile
}
#
if {$chopt == "0"} {
 set xdvarls [list xpro(maxdcc) 2 1:9 xpro(maxque) 10 1:+ xpro(usrmaxq) 2 1:+]
 lappend xdvarls xpro(astart) 0 0:+ xclr(color) 1 0:5 xpro(adlayout) 1 1:2
 lappend xdvarls xpro(qtimegone) 3 1:15 xpro(stimegone) 1 1:15 xclr(custom) 0 0:1
 foreach {dvar ddef drng} $xdvarls {  set dval [set $dvar]
  if {[set oldsln [lsearch -inline $oldsls $dvar*]] != ""} {
   foreach {xvar cset cdat xnow sdat xsby range} $oldsln { break }
  }
  if {$oldsln == "" || $dval != $cset} {
   if {[xstrvar $dval $drng]} {
    set xnow [xstrvar $dval] ;  set xsby ":conf:"
   } else { set xnow "$ddef" ;  set xsby ":error:" }
   set cdat "$xut" ;  set sdat "$xut"
  } else {
   if {![xstrvar $xnow $drng]} {
    if {[xstrvar $dval $drng]} {
     set xnow [xstrvar $dval] ;  set xsby ":conf:"
    } else { set xnow "$ddef" ;  set xsby ":error:" }
    set sdat "$xut"
   }
  }
  puts $xstmpfil "[list $dvar $dval $cdat $xnow $sdat $xsby $drng]"
  set $dvar "$xnow"
 }
 if {[file exists $xfil(dset)]} { file delete $xfil(dset) }
 close $xstmpfil
 file rename $xstmprute $xfil(dset) ;  file delete $xstmprute
}
# --------------------------------
# Server colors variable setup  ##
# --------------------------------
if {$xclr(custom) == "0"} {
 if {$xclr(color) == "1"} {
  if {$xpro(adlayout) == "1"} {
   set xcolorls [list c0 10 c1 10 c2 04 c3 04 c4 14 c5 10 c6 10 c7 04]
   lappend xcolorls c8 04 c9 10 c10 10 custalt1 10,15 custalt2 04,15
  } elseif {$xpro(adlayout) == "2"} {
   set xcolorls [list c0 10 c1 14 c2 10 c3 04 c4 14 c5 10 c6 14 c7 10]
   lappend xcolorls c8 10 c9 10 c10 10 custalt1 10,15 custalt2 04,15
  }
 } elseif {$xclr(color) == "2"} {
  if {$xpro(adlayout) == "1"} {
   set xcolorls [list c0 06 c1 06 c2 04 c3 04 c4 14 c5 06 c6 06 c7 04]
   lappend xcolorls c8 04 c9 06 c10 06 custalt1 06,15 custalt2 04,15
  } elseif {$xpro(adlayout) == "2"} {
   set xcolorls [list c0 06 c1 14 c2 06 c3 04 c4 14 c5 06 c6 14 c7 06]
   lappend xcolorls c8 06 c9 06 c10 06 custalt1 06,15 custalt2 04,15
  }
 } elseif {$xclr(color) == "3"} {
  if {$xpro(adlayout) == "1"} {
   set xcolorls [list c0 05 c1 05 c2 07 c3 07 c4 14 c5 05 c6 05 c7 07]
   lappend xcolorls c8 07 c9 05 c10 05 custalt1 05,15 custalt2 07,15
  } elseif {$xpro(adlayout) == "2"} {
   set xcolorls [list c0 05 c1 14 c2 05 c3 07 c4 14 c5 05 c6 14 c7 05]
   lappend xcolorls c8 05 c9 05 c10 05 custalt1 05,15 custalt2 07,15
  }
 } elseif {$xclr(color) == "4"} {
  if {$xpro(adlayout) == "1"} {
   set xcolorls [list c0 02 c1 02 c2 12 c3 12 c4 12 c5 02 c6 02 c7 12]
   lappend xcolorls c8 12 c9 02 c10 02 custalt1 02,15 custalt2 12,15
  } elseif {$xpro(adlayout) == "2"} {
   set xcolorls [list c0 02 c1 14 c2 02 c3 12 c4 14 c5 02 c6 14 c7 02]
   lappend xcolorls c8 02 c9 02 c10 02 custalt1 02,15 custalt2 12,15
  }
 } elseif {$xclr(color) == "5"} {
  if {$xpro(adlayout) == "1"} {
   set xcolorls [list c0 07 c1 07 c2 03 c3 03 c4 14 c5 07 c6 07 c7 03]
   lappend xcolorls c8 03 c9 07 c10 07 custalt1 07,15 custalt2 03,15
  } elseif {$xpro(adlayout) == "2"} {
   set xcolorls [list c0 07 c1 14 c2 07 c3 03 c4 14 c5 07 c6 14 c7 07]
   lappend xcolorls c8 07 c9 07 c10 07 custalt1 07,15 custalt2 03,15
  }
 }
 array set xclr $xcolorls
}
##
if {$xclr(color) != "0" || $xclr(custom) == "1"} {
 if {$xclr(c0)==""} { set xclr(dcc) "\00310" } else { set xclr(dcc) "\003[string range $xclr(c0) 0 1]" }
 set xclr(dcce) "\003"
 if {$xclr(c0) == ""} { set xclr(c0) "\003" } else { set xclr(c0) "\003$xclr(c0)" }
 if {$xclr(c1) == ""} { set xclr(c1) "\003" } else { set xclr(c1) "\003$xclr(c1)" }
 if {$xclr(c2) == ""} { set xclr(c2) "\003" } else { set xclr(c2) "\003$xclr(c2)" }
 if {$xclr(c3) == ""} { set xclr(c3) "\003" } else { set xclr(c3) "\003$xclr(c3)" }
 if {$xclr(c4) == ""} { set xclr(c4) "\003" } else { set xclr(c4) "\003$xclr(c4)" }
 if {$xclr(c5) == ""} { set xclr(c5) "\003" } else { set xclr(c5) "\003$xclr(c5)" }
 if {$xclr(c6) == ""} { set xclr(c6) "\003" } else { set xclr(c6) "\003$xclr(c6)" }
 if {$xclr(c7) == ""} { set xclr(c7) "\003" } else { set xclr(c7) "\003$xclr(c7)" }
 if {$xclr(c8) == ""} { set xclr(c8) "\003" } else { set xclr(c8) "\003$xclr(c8)" }
 if {$xclr(c9) == ""} { set xclr(c9) "\003" } else { set xclr(c9) "\003$xclr(c9)" }
 if {$xclr(c10)==""} { set xclr(c10) "\003" } else { set xclr(c10) "\003$xclr(c10)" }
 set xclr(end) "\003"
 if {$xclr(custalt1)==""} { set xclr(custalt1) "$xclr(c1)" } else { set xclr(custalt1) "\003$xclr(custalt1)" }
 if {$xclr(custalt2)==""} { set xclr(custalt2) "$xclr(c3)" } else { set xclr(custalt2) "\003$xclr(custalt2)" }
} else {
 set xclr(dcc) "\00310" ;  set xclr(dcce) "\003"
 set xclr(c0) "" ; set xclr(c1) "" ; set xclr(c2) "" ; set xclr(c3) "" ; set xclr(c4) "" ; set xclr(c5) ""
 set xclr(c6) "" ; set xclr(c7) "" ; set xclr(c8) "" ; set xclr(c9) "" ; set xclr(c10) "" ; set xclr(end) ""
 set xclr(custalt1) "" ;  set xclr(custalt2) ""
}
##
if {$xpro(forcedclr) != ""} {
 if {$xpro(forcedclr) == "none"} { set xclr(dcc) "" ;  set xclr(dcce) ""
 } else { set xclr(dcc) "\003$xpro(forcedclr)" ; set xclr(dcce) "\003" }
}
## set common logos for server layout 2 ##
if {$xpro(adlayout) == "2"} {  set xpro(logo) "|XdccPro|"
 set xpro(adlogo) "$xclr(c2)|$xclr(c1)X$xclr(c2)dcc$xclr(c1)P$xclr(c2)r$xclr(c1)o by SpiKe^^$xclr(c2)|"
 set xpro(infologo) "|XdccPro by SpiKe^^|" ; set xpro(dlogo) "|XdccPro|"
}
# -------------------------------------
# DEFAULT LISTS/ADS : ALL LINE TEXTS ##
# -------------------------------------
set xlists(dln01) "$xclr(c6) $xpro(adlogo) $xclr(c7)XDCC Server brought to you by$xclr(c8) %nikorch "
set xlists(dln02) "$xclr(c1) $xclr(c4)|$xclr(c1)STATUS$xclr(c4)|$xclr(c1) Sends : $xclr(c9)(%sc/%ms) $xclr(c4)|$xclr(c1) Queues : $xclr(c9)(%qc/%mq) "
set xlists(dln03) "$xclr(c1) To request a pack type: $xclr(c3)/ctcp %bn XDCC send #<packnumber>$xclr(c1)  Failed Gets? $xclr(c3)Use: /dccallow +%bn "
set xlists(dln04) "$xclr(c10) $xpro(infologo) $xclr(c1)Serving %opt1pcnt $xclr(c4)|$xclr(c1) Sent %opt1snt "
#
set xlists(dln05) "$xclr(c0) $xpro(adlogo) $xclr(c1)package list..."
#
if {$xpro(cplhow) != "0"} { set xpro(defltrig) "$xpro(cpltrig)"
} elseif {$xpro(listhow) > "2"} { set xpro(defltrig) "!list"
} elseif {$xpro(xlsthow) != "0"} { set xpro(defltrig) "/ctcp %bn XDCC list"
} else { set xpro(defltrig) ":none set:" }
set xlists(dln06) "$xclr(custalt1) XDCC Server Online. To see the pack list type:$xclr(custalt2) $xpro(defltrig) "
#
set xlists(dln07) "$xclr(c6) .�$xclr(c7)�$xclr(c8)XDCC Active$xclr(c7)�$xclr(c6)�. $xclr(c2) S$xclr(c1)ends:($xclr(c9)%sc/%ms$xclr(c1)) $xclr(c2)Q$xclr(c1)ueues:($xclr(c9)%qc/%mq$xclr(c1)) $xclr(c2)F$xclr(c1)iles $xclr(c2)S$xclr(c1)ent:($xclr(c9)%tp$xclr(c1)) $xclr(c2)D$xclr(c1)escription:($xclr(c9)$xpro(srvrdesc)$xclr(c1)) $xclr(c2)|$xclr(c1)X$xclr(c2)dcc$xclr(c1)P$xclr(c2)r$xclr(c1)o$xclr(c2)| $xclr(c1)v$xclr(c2)$xinf(ver) "
set xlists(dln08) "-=XDCC Active=-  Sends:(%sc/%ms) Queues:(%qc/%mq) Files Sent:(%tp) Description:($xpro(srvrdesc)) |XdccPro| v$xinf(ver)"
set xlists(dln09) "$xclr(c2) %boU%bo$xclr(c1)sage: $xclr(c10)/ctcp %bn XDCC send #<packnumber> "
set xlists(dln10) "$xclr(c0) $xpro(adlogo) $xclr(c2)%boP%bo$xclr(c1)ackage $xclr(c2)%boL%bo$xclr(c1)ist..."
#
set xlists(dln11) "$xclr(c6) $xpro(adlogo) $xclr(c7)XDCC Server Online."
set xlists(dln12) ""
#
set xlists(pln01) ":packlist:$xclr(c1) Pack $xclr(c2)#%pn$xclr(c1):$xclr(c5) %pd $xclr(c4)|$xclr(c1) %ps1 $xclr(c4)|$xclr(c1) %pg gets "
set xlists(pln02) ":packlist:$xclr(c1) ($xclr(c10)#%pn$xclr(c1)) ($xclr(c9)%ps2$xclr(c1)) $xclr(c4)%ul%pf%ul$xclr(c2) - $xclr(c5)%pd$xclr(c1) ($xclr(c9)%pg Gets$xclr(c1)) "
set xlists(pln03) ""
# ---------------------------------------------------
# LISTS/ADS : SETUP ALL LIST/AD LISTLINE VARIABLES ##
# ---------------------------------------------------
set xlists(xlstreq) ""
if {$xpro(xlsthow) != "0"} {
  if {$xpro(customxls) == "0"} {
    if {$xpro(adlayout) == "1"} {
      lappend xlists(xlstreq) $xlists(dln05) $xlists(pln01) $xlists(dln03) $xlists(dln02)
    } elseif {$xpro(adlayout) == "2"} {
      lappend xlists(xlstreq) $xlists(dln10) $xlists(pln02) $xlists(dln09)
    }
  }
}
set xlists(listreq) "" ;  set xlists(lsreq2) ""
if {$xpro(listhow) != "0"} {
  if {$xpro(customls) == "0"} {
    if {$xpro(adlayout) == "1"} {
      lappend xlists(listreq) $xlists(dln05) $xlists(pln01) $xlists(dln03) $xlists(dln02)
    } elseif {$xpro(adlayout) == "2"} {
      lappend xlists(listreq) $xlists(dln10) $xlists(pln02) $xlists(dln09)
    }
  }
}


#### EDIT #### no edit here yet #
if {$xpro(cplhow) != "0"} {
  if {$xpro(customl2) == "0"} {
    if {$xpro(adlayout) == "1"} {
      lappend xlists(lsreq2) $xlists(dln05) $xlists(pln01) $xlists(dln03) $xlists(dln02)
    } elseif {$xpro(adlayout) == "2"} {
      lappend xlists(lsreq2) $xlists(dln10) $xlists(pln02) $xlists(dln09)
    }
  }
}
#### END EDIT ####


set xlists(mainad) "" ;  set xlists(altad) ""
if {$xpro(firstad) != "0"} {
  if {$xpro(customad) == "0"} {
    if {$xpro(ad1how) == "2"} { lappend xlists(mainad) $xlists(dln06)
    } elseif {$xpro(ad1how) == "0"} {
      if {[string match /ctcp* $xpro(defltrig)] == "1"} {
        set xpro(ad1line) [string map [list %lt $xpro(defltrig)] $xpro(ad1line)] }
      lappend xlists(mainad) $xpro(ad1line)
    } else {  set xpro(lfludonad) "1"
      if {$xpro(adlayout) == "1"} {
       if {$xpro(adline1) == "2"} {
        lappend xlists(mainad) $xlists(dln11) $xlists(dln02) $xlists(pln01) $xlists(dln03) $xlists(dln04)
       } else { lappend xlists(mainad) $xlists(dln01) $xlists(dln02) $xlists(pln01) $xlists(dln03) $xlists(dln04) }
      } elseif {$xpro(adlayout) == "2"} {
        if {$xclr(color) != "0" || $xclr(custom) == "1"} {
          lappend xlists(mainad) $xlists(dln07) $xlists(pln02) $xlists(dln09)
        } else { lappend xlists(mainad) $xlists(dln08) $xlists(pln02) $xlists(dln09) }
      }
    }
  }
  if {$xpro(altad) != "0"} {
    if {$xpro(customalt) == "0"} {
      if {$xpro(ad2how) == "2"} { lappend xlists(altad) $xlists(dln06)
      } elseif {$xpro(ad2how) == "0"} {
        if {[string match /ctcp* $xpro(defltrig)] == "1"} {
          set xpro(ad2line) [string map [list %lt $xpro(defltrig)] $xpro(ad2line)] }
        lappend xlists(altad) $xpro(ad2line)
      } else {  set xpro(lfludonalt) "1"
        if {$xpro(adlayout) == "1"} {
         if {$xpro(adline1) == "2"} {
          lappend xlists(altad) $xlists(dln11) $xlists(dln02) $xlists(pln01) $xlists(dln03) $xlists(dln04)
         } else { lappend xlists(altad) $xlists(dln01) $xlists(dln02) $xlists(pln01) $xlists(dln03) $xlists(dln04) }
        } elseif {$xpro(adlayout) == "2"} {
          if {$xclr(color) != "0" || $xclr(custom) == "1"} {
            lappend xlists(altad) $xlists(dln07) $xlists(pln02) $xlists(dln09)
          } else { lappend xlists(altad) $xlists(dln08) $xlists(pln02) $xlists(dln09) }
        }
      }
    }
  }
}
### END proc xchkvars:  read/write dset file and set up vars ####
}

xchkvars

## Read channels in ChanFile.. ##
set xpro(chancount) 0  ;  set xpro(servchans) ""
proc readchaninfos {} {  global iso xpro xfil
 if {[file exists $xfil(chans)]} {
   set chancounttmp 0  ;  set servchantmp ""
   set xchanfile [open $xfil(chans) r]
   while {![eof $xchanfile]} {  set readchan [gets $xchanfile]
    if {$readchan != ""} {  incr chancounttmp
      if {$servchantmp == ""} {  set servchantmp $readchan
      } else {  append servchantmp " $readchan"  }
    }
   }
   close $xchanfile
   if {$chancounttmp == "0"} {  file delete $xfil(chans)
     if {$iso == "1"} {  set iso 0  }
     if {$xpro(chancount)!="0" || $xpro(servchans)!=""} {
       set xpro(chancount) 0  ;  set xpro(servchans) ""
     }
   } else {
     set xpro(chancount) $chancounttmp  ;  set xpro(servchans) $servchantmp
   }
 } else {
   if {$xpro(chancount)!="0" || $xpro(servchans)!=""} {
     set xpro(chancount) 0  ;  set xpro(servchans) ""
   }
 }
}

readchaninfos

## Read PacksFile.. ##
proc readpackinfos {} {  global iso xpro xfil
 foreach {file fil2 from} [list $xfil(packs) $xfil(cpack) 0 $xfil(trigs) $xfil(ctrig) 1] {
  if {[file exists $file]} {  set packcounttmp 0  ;  set packbytestmp 0
    set packssenttmp 0  ;  set bytessenttmp 0  ;  set xpfile [open $file r]
    if {[file exists $fil2]} {  set y 1  ;  set xcpkfile [open $fil2 r]
    } else {  set y 0  ;  set xcpkfile [open $fil2 w]  }
    while {![eof $xpfile]} {  set readpk1 [gets $xpfile]
     if {$readpk1 != ""} {
       if {$y=="1"} {  set readpk2 [gets $xcpkfile]
       } else {  set readpk2 0  ;  puts $xcpkfile 0  }
       incr packcounttmp  ;  set pkbytes [lindex $readpk1 3]
       set packbytestmp [expr round($packbytestmp+${pkbytes}.0)]
       set packssenttmp [expr round($packssenttmp+${readpk2}.0)]
       set pbytessent [expr round($pkbytes*${readpk2}.0)]
       set bytessenttmp [expr round($bytessenttmp+${pbytessent}.0)]
     }
    }
    close $xpfile  ;  close $xcpkfile
    if {$packcounttmp=="0"} {  file delete $file
      if {[file exists $fil2]} {  file delete $fil2  }
      if {$from=="0"} {  array set xpro {packcount 0 packbytes 0 packssent 0 bytessent 0}
      } else {  array set xpro {trigcount 0 trigbytes 0 trigssent 0 tbytesent 0}  }
    } else {
      if {$from=="0"} {
       array set xpro [list packcount $packcounttmp packbytes $packbytestmp packssent $packssenttmp bytessent $bytessenttmp]
      } else {
       array set xpro [list trigcount $packcounttmp trigbytes $packbytestmp trigssent $packssenttmp tbytesent $bytessenttmp]
      }
    }
  } else {
    if {$from=="0"} {  array set xpro {packcount 0 packbytes 0 packssent 0 bytessent 0}
    } else {  array set xpro {trigcount 0 trigbytes 0 trigssent 0 tbytesent 0}  }
  }
 }
 if {$iso=="1" && $xpro(packcount)=="0" && $xpro(trigcount)=="0"} {  set iso 0  }
}

readpackinfos

## Read total bytes & total files from CountByteFile.. ##
set xpro(bytecount) 0  ;  set xpro(sentcount) 0
proc readservrtotals {} {  global xpro xfil
 set bytetmp 0  ;  set filetmp 0
 if {[file exists $xfil(totals)]} {
   set xcbyfile [open $xfil(totals) r]  ;  set totals [gets $xcbyfile]
   if {$totals != ""} {
     set bytetmp [lindex $totals 0]  ;  set filetmp [lindex $totals 1]
   }
   close $xcbyfile
   set xpro(bytecount) $bytetmp  ;  set xpro(sentcount) $filetmp
 } else {
   if {$xpro(bytecount)!="0" || $xpro(sentcount)!="0"} {
     set xpro(bytecount) 0  ;  set xpro(sentcount) 0
   }
 }
}

readservrtotals

## Read BanFile.. ##
set xpro(srvrbans) ""
proc readbaninfos {} {  global iso xpro xfil  ;  set count "0"
 if {$xpro(baninfo) == ""} { set doinfo "1" } else { set doinfo "0" }
 if {[file exists $xfil(bans)]} {  set xpro(srvrbans) ""
   set xbfile [open $xfil(bans) r]
   while {![eof $xbfile]} {  set baninfo [gets $xbfile]
    if {$baninfo != ""} {  incr count
      foreach {mask nik cre luse req rsn} $baninfo {
       lappend xpro(srvrbans) $mask
       if {$doinfo == "1"} { lappend xpro(baninfo) $count $mask }
      }
    }
   }
   close $xbfile
   if {$doinfo == "1"} { set xpro(baninfc) $count }
 } else { set xpro(srvrbans) "" ; set xpro(baninfo) "" ; set xpro(baninfc) "0" }
}

readbaninfos

# --------------------------
# AUTOMATIC FILE CHECKING ##
# --------------------------
set xpro(autoadd) [string trimleft $xpro(autoadd) 0]
if {![xstrdig $xpro(autoadd)]} {  set xpro(autoadd) 0  } else {  set xpro(autoadd) 1  }
set xpro(autodel) [string trimleft $xpro(autodel) 0]
if {![xstrdig $xpro(autodel)]} {  set xpro(autodel) 0  } else {  set xpro(autodel) 1  }

foreach xtmp [timers] {
 if {[lindex $xtmp 1] eq "xautoadd"} {  killtimer [lindex $xtmp 2]  }
}
if {[info exists xpro(-auttimr)]} {  unset xpro(-auttimr)  }

proc xremgone {from nk idx {dir ""} } {  global xpro xfil xclr
 if {$dir eq ""} {  set dir $xpro(adelpath)
 } elseif {$dir ne "*"} {  set dir [split $dir ,]  }
 if {$dir ne "*"} {  set dsls ""
   foreach d $dir {  lappend dsls [string tolower [string trim $d ./]]  }
 }
 if {$from=="0"} {  set flname $xfil(packs)  ;  set flnam2 $xfil(cpack)
 } else {  set flname $xfil(trigs)  ;  set flnam2 $xfil(ctrig)  }
 set trucnt 0  ;  set count 0   ;  set deletd 0
 if {[file exists $flname]} {  set xpktemp ./scripts/xpack.tmp  ;  set xcpktemp ./scripts/xcpk.tmp
   set xpacktemp [open $xpktemp w]  ;  set xcpacktemp [open $xcpktemp w]
   set xpkfile [open $flname r]  ;  set xcpkfile [open $flnam2 r]
   while {![eof $xpkfile]} {  set temp [gets $xpkfile]  ;  set temp2 [gets $xcpkfile]
    if {$temp != ""} {  incr count  ;  set good 1
      if {![file isfile [lindex $temp 1]]} {  set ddir [string tolower [string trim [file dirname [lindex $temp 1]] ./]]
        if {$dir eq "*" || [lsearch $dsls $ddir]>"-1"} {
          if {$from=="0"} {  set temp [linsert $temp 1 *]  } else {  set temp [linsert $temp 0 $count]  }
          lappend temp $temp2  ;  lappend dls $temp  ;  incr deletd  ;  set good 0
        }
      }
      if {$good=="1"} {  incr trucnt
        if {$from=="0"} {  set temp [lreplace $temp 0 0 $trucnt]  }
        puts $xpacktemp $temp  ;  puts $xcpacktemp $temp2
      }
    }
   }
   close $xpkfile  ;  close $xcpkfile  ;  close $xpacktemp  ;  close $xcpacktemp
   file delete $flname  ;  file delete $flnam2
   file rename $xpktemp $flname  ;  file rename $xcpktemp $flnam2
   file delete $xpktemp  ;  file delete $xcpktemp
   if {[info exists dls]} {
     if {$idx eq "*"} {  set in "..."
       if {$dir ne "*" && [llength $dir]=="1"} {  set in " in [join $dir] ..."  }
     } else {
       if {$from=="0"} {
         if {$dir eq "*"} {  putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete All Missing Packs...."
         } else {  putdcc $idx "$xclr(dcc)$xpro(dlogo) Delete All Missing Packs In: [join $dir] ..." }
         if {$deletd>"1"} {  putdcc $idx "Removed these packs..."  }
       }
     }
     foreach dfl $dls {
      foreach {num trg file desc byte dlcnt} $dfl {  break  }
      if {$idx eq "*"} {
        if {$deletd>"5"} {
          if {$from=="0"} {  putlog "\[XPro Auto-Delete\] Removed $deletd missing packs$in"  }
          break
        }
        if {$from=="0"} {  putlog "\[XPro Auto-Delete\] Removed missing pack #$num:  $file"  }
      } else {
        if {$from=="0"} {
          if {$deletd=="1"} {  putdcc $idx "Removed pack $num: $file (${dlcnt}X)"  ;  break  }
          putdcc $idx "$num: $file (${dlcnt}X)"
        }
      }
     }
     if {$idx ne "*"} {  putdcc $idx " "  }
   }
 }
 return $deletd
}

if {$xpro(autoadd)=="1" || $xpro(autodel)=="1"} {
##
proc xautoadd {} {  global iso xpro xfil xclr   ;  set added 0  ;  set deled 0
 if {$xpro(autoadd)=="0" && $xpro(autodel)=="0"} {
   if {[info exists xpro(-auttimr)]} {  unset xpro(-auttimr)  }   ;  return 0
 }
 if {$xpro(autodel)=="1"} {
   if {$xpro(adelpath) eq "*"} {  set deled [xremgone 0 * * *]
   } else {
     foreach p $xpro(adelpath) {  set dcnt [xremgone 0 * * $p]
      if {$dcnt>"0"} {  incr deled $dcnt  }
     }
   }
 }
 if {$xpro(autoadd)=="1"} {
   foreach p $xpro(aaddpath) {
    if {![file isdirectory $p]} {  continue  }  ;  set tx "-a $p"  ;  set acnt [xaddpk * * $tx]
    if {$acnt>"0"} {  incr added $acnt  }
   }
 }
 if {$added=="0" && $deled>"0" && $deled==$xpro(packcount)} {
   if {$iso=="1"} {  putlog "Removed All packs!  Turning server OFF...."  ;  xstop * * *
   } else {  putlog "Removed All packs!"  }
   readpackinfos
 } elseif {$added>"0" || $deled>"0"} { readpackinfos  ; set frmtbtotal "[xfrmtsize 2 $xpro(packbytes)]"
   if {$xpro(packcount)=="1"} {  putlog "Now serving one package ($frmtbtotal)"
   } else {  putlog "Now serving $xpro(packcount) packages ($frmtbtotal)"  }
 }
 if {[info exists xpro(-auttimr)]} {  set xpro(-auttimr) [timer $xpro(acheck) xautoadd]  }
}
##
}

if {$xpro(autoadd)=="1" || $xpro(autodel)=="1"} {
  set xpro(acheck) [string trimleft $xpro(acheck) 0]
  if {![xstrdig $xpro(acheck)]} {  set xpro(acheck) 10  }
  if {$xpro(aaddpath) eq ""} {  set xpro(aaddpath) $xpro(defpath)
  } else {  set xpro(aaddpath) [split $xpro(aaddpath) ,]  }
  if {$xpro(adelpath) eq ""} {  set xpro(adelpath) $xpro(aaddpath)
  } elseif {$xpro(adelpath) ne "*"} {  set xpro(adelpath) [split $xpro(adelpath) ,]  }
  xautoadd
  if {$xpro(acheck)=="1"} {  set xpro(-auttimr) [timer 2 xautoadd]
  } else {  set xpro(-auttimr) [timer $xpro(acheck) xautoadd]  }
}

putlog "Loaded $xclr(dcc)XDCC SERVER PRO$xclr(dcce) version $xinf(ver) by $xinf(auth)"

# -------------------------
# SERVER AUTO-START CODE ##
# -------------------------
if {$xpro(astart) != "0" && $xpro(astarted) == "0" && $iso == "0"} {
 timer $xpro(astart) "xstart temp temp temp"
 putlog "$xclr(dcc)$xpro(dlogo)$xclr(dcce) Server starting in $xpro(astart) minutes."
 set xpro(astarted) "1"
}