########################################################
#
# Add Me ! - v 2.0 - April, 2003
# Organise pickup games on IRC with ease (and your eggdrop)
#
# Please read README.TXT for more info & manual
#
# Contact stuff : 
# Ozh, ozh@planetquake, #SARL on irc.quakenet.org
#
########################################################

########################################################
#
# QUICK README that will save me about 70% of queries :
# 
# - THIS IS NOT a script for MIRC. It's intented to run
# on eggdrop (or windrop). http://www.egghelp.org for more
# info.
#
# - I CANT GIVE YOU AN EGGDROP nor lend mine. You'll
# have to have someone lend or rent you a shell. Same
# site as above for infos.
#
# - Please read the README.TXT file provided with the
# script, or get the original version of this script
# here : http://www.egghelp.org/tcl.shtml and look for
# 'ozh' in the search field
#
########################################################

################# C U S T O M I Z E ####################
#
# READ CAREFULLY :
# Here come a few sections where you configure things
#
# As an example, the script is provided with a two channel
# example configuration, #pickup1 and #pickup2.
# Each variable has also a recommended value, for those
# who are not sure what to do.
#
# For each section except very first one, you'll need as many
# variables as pickup channels.
# For example, if your bot sits in #pickup1 and #pickup2,
# each variable configured will look like : 
# addme_somevar(#pickup1) and addme_somevar(#pickup2)
# Understood ? *Each* variable is set for *each* channel :)
#
# Note for TCL beginners : to declare $myvar, the correct syntax is : 
# 	set myvar "string" 	<-- when string, use quotes
#	set myvar 99		<-- when number, use nothing
# 
# Ok then, GL & HF :)
#
########################################################

# CHANNELS MONITORED
# Channels where the bot manages topics, separated by a space
# For example :
# set addme_channels "#lame"
# set addme_channels "#lame #lamer #lamest"
#
# Note that adding channels here will not make the bot join them,
# you'll need to add them in your eggdrop.conf
#
# !!! Put channels in lowercase !!! So it wont mess between #MyPickup and #mypickup :)
# Same thing in your main eggdrop.conf file : use lowercase for channel names.
#
set addme_channels "#ra3pickup.de" 

# Note : from now on, *each* var is set for *each* channel from line above


# GREET ON JOIN
# Do you want the bot to welcome everyone on join ? (welcome & help message)
# 0 means no welcome message, 1 means welcome message
# Suggested : 1 if your channel is new and your bot not too busy, 0 if not or
# if you can have another bot or service (X, Q, L etc...) welcome users on join
# Remember, one var per channel :)
# Here again, and everywhere else, channels in lowercase !! :)
#
set addme_welcomemsg(#ra3pickup.de) 0



# WEB PAGE
# Web pages where the channel rules are explained, when someone asks
# the bot for help
#
set addme_rules(#ra3pickup.de) "http://www.KekSfabrik.eu/pickup"



# TOPIC LIST LENGTH
# Number of players wanted for a game, set for each channel (8 for 4v4, 10 for euro
# Q3CTF etc...)
# For example : set addme_number(#mypickup) 6 if you need 6 players to start a game
# Can be any number from 1 (silly) to any number (messy)
#
set addme_number(#ra3pickup.de) 10



# MAP PICKING
# How many maps do you want to be picked from maplist (if any) ?
# 0 means "dont pay attention to maplist, if any", N means "pick N maps from maplist"
# This can be used to prevent players from playing always the same 2 or 3 maps, and
# "forcing" them to chose from a short list (2 or even 1 map)
set addme_pickNmaps(#ra3pickup.de) 2



# MAP ANNOUNCING
# Do you want random map to be announced in advance ?
# If so, player can check what map is next with !nextmap
# If not, random maps (if any) are revealed only once topic is full and game ready to go.
# 0 means "dont announce in advance", 1 means "announce when asked with !nextmap"
# If activated and if the above rule is enforced, people can still decide to add or not,
# depending on wether they like or dislike the map selection :)
#
set addme_announcemaps(#ra3pickup.de) 0



# CAPTAIN PICKING
# Do you want to pick 2 players (eg team captains) when topic is full ?
# 0 means "pick no one", 1 means "pick 2 players"
#
set addme_pick2players(#ra3pickup.de) 1



# AUTOREMOVEALL MODE
# You have two ways of life :
# 1) Once topic is full, the bot announces game starting, and clears topic, so that other players
# can !add asap
# 2) Once topic is full, the bot announces the game, but topic remains unchanged till someone authorized
# calls "!removeall". In this mode, as long as topic is full, you can !recall players, which will make
# the bot privmsg players in topic again (usefull if you often get late joiners idling on irc)
# Mode 1 (autoremoveall) means you need a bit of discipline in your channel, since you cant use the
# !recall trigger, but games can start faster on populated channels with a bit of discipline :)
# (autoremoveall mode is Echbot's default style on Quakenet)
# 0 means "dont auto removeall", 1 means "removeall automatically once topic is full"
#
set addme_autoremoveall(#ra3pickup.de) 1



# SERVER SWITCH
# When enabled, topic will auto cycle through servers, so that when a topic is completed, a new
# game can start asap on another server. Use this if you have at least *2* servers dedicated to pickups,
# 3 servers might be the minimum on populated & active pickup channels
# If not, server will have to be "hand picked" (put a new one manually, if needed, with !server command)
# Suggested : 0 unless you have a few dedicated servers
#
set addme_serverswitch(#ra3pickup.de) 1



# PROMOTE : RESTRICTION TO ADDED PLAYERS
# !promote displays in a channel notice how many players are still required to have a game starting.
# You can limit this command to people added in topic, to prevent from annoying people not even playing
# to abuse it (if restricted, ops will still be able to use it, no matter if they are in topic or not)
# Suggested : 1
#
set addme_promote_added(#ra3pickup.de) 1



# PROMOTE : MINIMUM PLAYERS
# You can also set a minimum limit. XX means "under XX players in topic, !promote will be disabled"
# Be sure to set this limit under your number of needed players :)
# Set to 0 if you dont wish to use this feature (i.e. allow !promote even when topic is empty)
# Suggested : half of your needed players
#
set addme_promote_mini(#ra3pickup.de) 5



# PUBLIC / OPS PRIVILEGES : !removeall
# Do you want the "!removeall" command to be available to ops only ?
# 1 means "needs to be op", 0 means "anyone can do it"
# Suggested : 1 if you use autoremoveall mode
# Suggested : 0 otherwise, unless you are very sure you *always* have active ops in your channel :)
#
set addme_removeallop(#ra3pickup.de) 1



# PUBLIC / OPS PRIVILEGES : !add someone
# Do you want the "!add <name>" command to be available to ops only ?
# 1 means "needs to be op", 0 means "anyone can do it"
# Suggested : 1, so users wont add friends who may not be there when game starts
#
set addme_addop(#ra3pickup.de) 1



# PUBLIC / OPS PRIVILEGES : !remove someone
# Do you want !remove <name> command to be available to ops only ?
# 1 means "needs to be op", 0 means "anyone can do it"
# Suggested : 1
#
set addme_removeop(#ra3pickup.de) 1



# PUBLIC / OPS PRIVILEGES : !server
# Do you want "!server <server ip>" command to be available to ops only ?
# 1 means "needs to be op", 0 means "anyone can do it"
# Suggested : 1 if you have dedicated servers and use serverswitch, 0 otherwise
#
set addme_serverop(#ra3pickup.de) 0



# PUBLIC / OPS PRIVILEGES : !motd
# Do you want !motd <motd> command to be available to ops only ?
# 1 means "needs to be op", 0 means "anyone can do it"
# Suggested : 1
#
set addme_motdop(#ra3pickup.de) 1



####################################################################
####################################################################
#
#                PLEASE READ THIS OR I KILL THE DOG
#
# Your script is now fully functionnal. You can add it to your
# eggdrop config (add "source scripts/addme.tcl" at the end)
# without further editing.
#
# Then, restart your bot with the script loaded, ERASE TOPIC and
# type !removeall so it starts working with a valid topic.
# Please read the above sentence twice. I'll kill you if you
# query me asking what's wrong and you didnt clear topic first.
#
# If you plan to use server list (server switch option activated)
# or map list (map picking activated), start giving info to your
# bot with "/msg yourbot addmap" and "/msg yourbot addserver" once it's online.
#
# The script is heavily commented for documentation & learning purpose
# (my learning purpose :), so feel free to read it and modify what you want.
#
# Even if you wont modifying things, I suggest you read all the comments,
# as they will enlight you about how the script works, and what event will
# happen in this or that case.
#
# From now on, you may customize a few things (mostly translate
# bot messages to suit your language & humor) but DONT MODIFY anything
# else. Or dont ask for support, and learn a bit of TCL & regexp before :)
#
# One thing you'll want to customize are the topic colors. This can be
# done in a procedure below, named "addme_updatetopic"
# For infos about colors and bold control caracters, please read in this proc,
# everything gets explained.
#
# If you happen to modify the script and make something interesting
# with it, I'll be glad to here about you
# If you happen to modify it so it bugg0rz, *dont* leave me a word, I *wont* help :)
# Please read the above sentence twice. I'll kill you if you
# query me asking what's wrong after you modified your script.
#
####################################################################
####################################################################
#
#   DO NOT MODIFY BELOW UNLESS YOU READ THE LINES ABOVE AND YOU ARE
#   OK WITH ALL YOUR INSURANCE POLICIES.
#
####################################################################

# BINDS
#
# Binds are words triggered commands, like "!add"
#
# Format is : bind <type> <flag> <trigger> <command to execute>
# Example   : bind   pub    -     !hello   proc_answering_to_hello
# "pub" is a public message (something typed in the channel window)
# "msg" is a private /msg to the bot
#
# Modify here if you want to customize / translate the script
# Tip : bind the same proc to several similar words (look below
# for examples) so it's more user & guess friendly :) (for example,
# !ip and !ips to change server ip)

bind msg - !help addme_help
bind msg - help addme_help
bind pub - !help addme_help_pub

bind msg - !removeall addme_removeall
bind msg - removeall addme_removeall
bind pub - !removeall addme_removeall_pub

bind pub - !add addme_addname
bind pub - !addme addme_addname

bind pub - !remove addme_removename
bind pub - !removeme addme_removename
bind pub - !del addme_removename

bind pub - !rappel addme_recall
bind pub - !recall addme_recall

bind pub - !promote addme_promote

bind pub - !server addme_server
bind pub - !serveur addme_server
bind pub - !ip addme_server

bind pub - !nextmap addme_tellmaps
bind pub - !nextmaps addme_tellmaps
bind pub - !map addme_tellmaps
bind pub - !maps addme_tellmaps

bind pub - !motd addme_updatemotd

bind pub - !stats addme_gamecount

bind msg - saveservers addme_serverlist_write
bind msg - savemaps addme_maplist_write
bind msg - readservers addme_serverlist_read
bind msg - readmaps addme_maplist_read
bind msg - addmap addme_maplist_add
bind msg - addserver addme_serverlist_add
bind msg - removemap addme_maplist_remove
bind msg - removeserver addme_serverlist_remove

bind join - * addme_welcome
# on very populated channels, you may want to comment out this line,
# so the bot wont keep looking at people joining.
# If so, add a static welcome message to another bot, or to channel service
# (ie X on undernet, Q or L on quakenet ...)

bind part - * addme_part
bind sign - * addme_part

bind kick - * addme_kick

bind nick - * addme_nick

bind msg - addme_version addme_version

# bind pub - !debug addme_debug
# just prints a few vars, you can comment this line out :)

################################################################

# Procs
# Now the real core of the script. If you want to modify things other than just translating
# some sentences, do learn a bit of TCL and regular expressions first


proc addme_tellmaps {nick mask hand chan text} {
# Announce maps in channel, if supposed to do so (ie if there is a maplist, and if addme_pickNmaps set)

	global addme_channels
	global addme_maps
	global addme_randommaps
	global addme_pickNmaps
	global addme_announcemaps
	global addme_begin
	global botnick

	if {![regexp $chan $addme_channels]} {
		return tellmaps:not_valid_channel
	}

	# no maps to be picked
	if {$addme_maps($chan) == "" || ![info exists addme_maps($chan)] || $addme_pickNmaps($chan) == 0 } {
		if {$nick != $botnick} {
			putnick $nick "Sorry $nick, maps are not randomly picked here in $chan."
		}
		if {[info exists chan] && [info exists nick] && $addme_pickNmaps($chan) && [isop $nick $chan]} {
			if {$nick != $botnick} {
				putnick $nick "Since you seem to be op... time to add some maps now. Try /msg $botnick addmap"
			}
		}
		return tellmaps:no_maps
	}

	# maps picked, but not announced until topic is full
	if {$addme_announcemaps($chan) == 0 && $addme_begin($chan) == 0} {
		if {$nick != $botnick} {
			putnick $nick "Sorry $nick, maps in $chan are chosen only once topic is full :)"
		}
		return tellmaps:notannounced
	}

	# case when bot "has forgotten" random maps (eg rejoining channel after quit or crash)
	if {![info exists addme_randommaps($chan)] || $addme_randommaps($chan) == "" } {
		addme_pickmaps $chan
	}

	regsub "^\\(" $addme_randommaps($chan) "" announce
	regsub "\\)$" $announce "" announce
	putchan $chan "\0033Next $announce !"

}


proc addme_updatemotd {nick mask hand chan text} {
# Changes MOTD in topic with arguments given : !motd this is the new MOTD

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_motdop

	if {![regexp $chan $addme_channels]} {
		return motd:not_valid_channel
	}

	if {$addme_motdop($chan)} {
		if {![isop $nick $chan]} {
			putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
			return updatemotd:not_op
		}
	}

	# the following crap trims {} and spaces, so that "motd" and " motd" and "motd   "
	# will return "motd"
	# I've discovered the "string trim" function after I wrote these lines, could be simplified :>
	regsub "{" $text "" text
	regsub "}" $text "" text
	regsub -all "^\[ ]*" $text "" text
	regsub -all "\[ ]*$" $text "" text
	regsub -all "\[ ]{1,}" $text " " text
	if {$text == "" || $text == "{}" || ![info exists text] || $text == " "} {
		return updatemotd:no_args
	}

	addme_getvars $chan

	addme_updatetopic $chan $addme_list($chan) $addme_server($chan) $text

}


proc addme_server {nick mask hand chan text} {
# Changes ip server in topic : !ip 127.128.129.130 pass lame

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_serverop

	if {![regexp $chan $addme_channels]} {
		return server:not_valid_channel
	}

	if {$addme_serverop($chan)} {
		if {![isop $nick $chan]} {
			putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
			return server:notop
		}
	}

	addme_getvars $chan

	regsub "{" $text "" text
	regsub "}" $text "" text
	regsub -all "^\[ ]*" $text "" text
	regsub -all "\[ ]*$" $text "" text
	regsub -all "\[ ]{1,}" $text " " text
	if {$text == "" || $text == "{}" || ![info exists text] || $text == " "} {
		return server:no_args
	}

	addme_updatetopic $chan $addme_list($chan) $text $addme_motd($chan)

}


proc addme_recall {nick mask hand chan text} {
# Proc calling the addme_noticeall if supposed to do so when someone types !recall

	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_leaders
	global addme_autoremoveall
	global addme_channels

	if {![regexp $chan $addme_channels]} {
		return recall:not_valid_channel
	}

	if {$addme_autoremoveall($chan)} {
		putnick $nick "Command not available in channel\002 $chan"
		return recall:not_available
	}

	addme_getvars $chan

	if {$addme_begin($chan)} {
		addme_noticeall $chan
	} else {putnick $nick "More players needed yuo faggot !!!1"}
}


proc addme_noticeall {chan} {
# Privmsg each player in topic list
# Tell them : channel, server ip, plus maps to be played and random leaders, if supposed to do so

	global addme_list
	global addme_leaders
	global addme_randommaps
	global addme_server

	putchan $chan "\002\0034weeeeeeee !!\0033 Game to begin !\0036 GET READY \0037!\0038!\0039!\0033! \0034$addme_leaders($chan) \0033$addme_randommaps($chan) \0035 Players : [join [split $addme_list($chan) "/"] ", "]"
	# Please note the very subtle use of colors here :>

	foreach i [split $addme_list($chan) "/"] {
		putquery $i "\002$i\002 !! Get ready for pickup in \002$chan\002 ! $addme_server($chan) ! \0033NOW ! "
	}

}


proc addme_promote {nick mask hand chan text} {
# Advertise via channel notice the remaining number of players needed

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_leaders
	global addme_promote_added
	global addme_promote_mini

	if {![regexp $chan $addme_channels]} {
		return promote:not_valid_channel
	}

	addme_getvars $chan

	if {$addme_begin($chan)} {
		putnick $nick "Topic full you faggot ..."
		return promote:topic_full
	}

	if {([addme_isintopic $chan $nick] == -1) && $addme_promote_added($chan) && ![isop $nick $chan]} {
		putnick $nick "What about trying !addme first ? ..."
		return promote:unauthorized
	}

	set needed [expr ($addme_number($chan) - $addme_current($chan))]

	if {($needed > $addme_promote_mini($chan)) && ![isop $nick $chan]} {
		putnick $nick "Sorry, !promote not enabled below $addme_promote_mini($chan) players needed"
		return promote:belowlimit
	}

	putnick $chan "\0039Wake up ! \0034\002$needed\002\003 more needed in \0036$chan\003 !!"
}


proc addme_2leaders {chan} {
# Internal proc (no output printed) selecting 2 leaders from topic list, if supposed to do so

	global addme_list
	global addme_leaders
	global addme_pick2players

	if {$addme_pick2players($chan) == 0} {
		set addme_leaders($chan) " "
		return 2leaders:no_leader_picking
	}
	
	set nicklist [split $addme_list($chan) "/"]
	set pif1 [rand [llength $nicklist]]
	set pif2 [rand [llength $nicklist]]
	while {$pif1 == $pif2} {set pif2 [rand [llength $nicklist]]}
	set leader1 [lindex $nicklist $pif1]
	set leader2 [lindex $nicklist $pif2]
	set addme_leaders($chan) "(Random leaders : $leader1 & $leader2)"
}


proc addme_pickmaps {chan} {
# Internal proc (no output printed) selecting maps from map list, if supposed to do so

	global addme_maps
	global addme_randommaps
	global addme_pickNmaps

	if {$addme_maps($chan) == "" || ![info exists addme_maps($chan)] || $addme_pickNmaps($chan) == 0} {
		set addme_randommaps($chan) ""
		return pickmaps:no_map_picking
	}

	# Ah, now, how to chose X items in a list without picking twice the same ? :)
	set maplist [split $addme_maps($chan) " "]
	set maps ""
	for {set x 0} {$x < $addme_pickNmaps($chan)} {incr x} {
		set pif ""
		while {[regexp $pif $maps ]} {
			set pif [lindex $maplist [rand [llength $maplist]]]
		}
		set maps [concat $pif " " $maps ]		
	}
	set howmanymaps "Maps"
	if {$addme_pickNmaps($chan) == 1} {set howmanymaps "Map"}
	set addme_randommaps($chan) "($howmanymaps : $maps)"
}


proc addme_debug {nick mask hand chan text} {
# Useless proc printing out a few vars
# You can comment the "bind pub !debug" line at the beginning of the script
# to turn this proc off

	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_randommaps
	global addme_maps
	global addme_ips
	global addme_channels

	if {![regexp $chan $addme_channels]} {
		return debug:not_valid_channel
	}

	addme_getvars $chan

	putchan $chan "addme_list($chan): $addme_list($chan)\0035*"
	putchan $chan "addme_server($chan) : $addme_server($chan)\0035*"
	putchan $chan "addme_motd($chan) : $addme_motd($chan)\0035*"
	putchan $chan "addme_current($chan) : $addme_current($chan)\0035*"
	putchan $chan "addme_randommaps($chan) : $addme_randommaps($chan)\0035*"
	putchan $chan "addme_begin($chan) : $addme_begin($chan)\0035*"
	putchan $chan "addme_maps($chan) : $addme_maps($chan)\0035*"
	putchan $chan "addme_ips($chan) : $addme_ips($chan)\0035*"
}


proc addme_removeall_pub {nick mask hand chan text} {
# proc triggered by !removeall and calling the following (internal) one

	global addme_channels

	if {![regexp $chan $addme_channels]} {
		return removeall:not_valid_channel
	}

	addme_removeall $nick $mask $hand $chan
}


proc addme_removeall {nick host hand text} {
# Internal proc clearing players list in topic
# If called once topic is full and game ready :
#	- cycle through server list if supposed to do so
#	- pick next maps to be played if supposed to do so 

	global botnick
	global addme_channels
	global addme_joueur
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_removeallop
	global addme_autoremoveall
	global addme_ips
	global addme_serverswitch
	set chan $text
	
	if {![regexp $text $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick !removeall <channel>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return removeall:no_channel_specified
	}

	if {$addme_removeallop($chan)} {
		if {![isop $nick $chan] && $nick != $botnick} {
			putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
			return removeall:notop
		}
	}

	addme_getvars $text

	# Now, cycle through servers ip list if any, and if autoswitch is activated
	if {[info exists addme_ips($chan)] && $addme_ips($chan) != "" && $addme_serverswitch($chan) && $addme_begin($chan) == 1} {
		# compare addme_server with each addme_ips :
		# if matches, use next one, and if no match, use random one
		set serverlist [split $addme_ips($chan) ","]
		set found 0
		set i 0
		while {!$found && $i < [llength $serverlist]} {
			if {[regexp $addme_server($chan) [lindex $serverlist $i]]} {
				set found 1
			}
			incr i
		}
		if {!$found} {
			set addme_server($chan) [lindex $serverlist [rand [llength $serverlist]]]
		} else {
			if {$i < [llength $serverlist]} {
				set addme_server($chan) [lindex $serverlist $i]
			} else {
				set addme_server($chan) [lindex $serverlist 0]
			}
		}
		regsub "\[ ]*$" $addme_server($chan) "" addme_server($chan)
		regsub "^\[ ]*" $addme_server($chan) "" addme_server($chan)

	}

	# rebuild a clean topic with empty list
	set liste [addme_buildlist $addme_number($text)]

	addme_updatetopic $chan $liste $addme_server($chan) $addme_motd($chan)

	# pick random maps, if removeall occurs after a topic was complete
	if {$addme_begin($chan) == 1} {
		addme_pickmaps $chan
		addme_tellmaps $botnick asdf asdf $chan asdf
	}

	set addme_begin($chan) 0

}


proc addme_welcome {nick uhost hand chan} {
# Greet & short help message on join

	global botnick
	global addme_channels
	global addme_rules
	global addme_welcomemsg

	if {$nick==$botnick} {
		return welcome:botjoined
	}

	if {[regexp $chan $addme_channels] && $addme_welcomemsg($chan) == 1 } {
		if {[info exists addme_rules($chan)]} {
			putnick $nick "Hello $nick ! \002/msg $botnick !help\002 for help. Read rules here : \002$addme_rules($chan)\002"
		} else {
			putnick $nick "Hello $nick ! \002/msg $botnick !help\002 for help."
		}
	}
}


proc addme_help {nick uhost hand chan} {
# Detailed help message, when someone types !help
# Help message will matches public/admin commands with requester's op/not op status

	global botnick
	global addme_channels
	global addme_rules
	global addme_motdop
	global addme_serverop
	global addme_removeallop
	global addme_addop
	global addme_removeop
	global addme_maps
	global addme_ips

	if {![info exists chan]} {
		putnick $nick "Usage : \002/msg $botnick help <chan>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return help:no_chan_specified
	}

	if {![regexp $chan $addme_channels]} {
		return help:not_valid_channel
	}

	set helpmsg "Public commands : !add, !remove"

	if {!$addme_addop($chan)} {set helpmsg [concat $helpmsg ", !add <name>"]}
	if {!$addme_removeop($chan)} {set helpmsg [concat $helpmsg ", !remove <name>"]}
	set helpmsg [concat $helpmsg ", !map"]
	if {!$addme_serverop($chan)} {set helpmsg [concat $helpmsg ", !server"]}
	if {!$addme_removeallop($chan)} {set helpmsg [concat $helpmsg ", !removeall"]}
	if {!$addme_motdop($chan)} {set helpmsg [concat $helpmsg ", !motd"]}

      putquery $nick $helpmsg

	if {[isop $nick $chan]} {
		set helpmsg "Admin commands : "
		if {$addme_addop($chan)} {set helpmsg [concat $helpmsg "!add <name>"]}
		if {$addme_removeop($chan)} {set helpmsg [concat $helpmsg ", !remove <name>"]}
		if {$addme_serverop($chan)} {set helpmsg [concat $helpmsg ", !server"]}
		if {$addme_removeallop($chan)} {set helpmsg [concat $helpmsg ", !removeall"]}
		if {$addme_motdop($chan)} {set helpmsg [concat $helpmsg ", !motd"]}
		putquery $nick $helpmsg
		putquery $nick "Private admin commands : \002via /msg $botnick only\002, where commands are :"
		if {[info exists addme_maps($chan)]} {
			putquery $nick "Map list : readmaps <chan> | addmap <chan> <map> | removemap <chan> <map>"
		} else {putnick $nick "non $chan : [info exists addme_maps($chan)]"}
		if {[info exists addme_ips($chan)]} {
			putquery $nick "Server list : readservers <chan> | addserver <chan> <server infos> | removeserver <chan> <server number>"
		} else {putnick $nick "non plus $chan :/"}
		
	}
	        
	putquery $nick "Please no alias. Read rules : \002$addme_rules($chan). Suggestions or bug report : ozh@planetquake.com - Ozh on #sarl (irc.quakenet.org)"
}


proc addme_help_pub {nick mask hand chan text} {
# Proc calling the internal help proc above

	addme_help $nick $mask $hand $chan
}


proc addme_getvars {chan} {
# this is the only (a bit) tricky proc of the script, and the main one :
# the one that reads topic and gets variables from it (players list, server infos, motd)
# Really dont touch anything unless you can make your own way through regexps

	global botnick
	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_motd

	set tt [topic $chan]
	regsub -all "\[ ]{1,}" $tt " " tt

	if {$tt == ""} {
		set tt "Next : [addme_buildlist $addme_number($chan)] | Server : 127.0.0.1 pass toto | HF & CVC"
	}

	# filter out all bold caracters
	regsub -all "\002" $tt "" tt
	# filter out all color caracters
	regsub -all "\003\[0-9](\[0-9])*" $tt "" tt

	regexp "^Next : (.*) \[ \|\] Server" $tt tmp addme_list($chan)

	regexp "Server : (\[^\|\]*)" $tt tmp addme_server($chan)
	regsub "\[ ]*$" $addme_server($chan) "" addme_server($chan)

	regexp "${tmp}\[ \|]*(.*)" $tt tmp addme_motd($chan)
	regsub "\[ ]*$" $addme_motd($chan) "" addme_motd($chan)

	set addme_current($chan) [expr $addme_number($chan) - [regsub -all "\\." $addme_list($chan) "" tmp]]
}


proc addme_addname {nick mask hand chan text} {
# Add a player into topic list, if supposed to do so (ie list not full, player in channel and not already listed)
# If player added fulfills topic :
#	- call proc picking 2 leaders from list
#	- call proc noticing every player
#	- increment game counter
#	- autoremoveall if supposed to do so

	global botnick
	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_addop
	global addme_autoremoveall

	if {![regexp $chan $addme_channels]} {
		return addname:not_a_valid_channel
	} 

	if {$text == "" || $text == "{}" || ![info exists text]} {set text $nick}

	if {$text == $botnick} {
		putnick $nick "Ahah."
		return addname:add_bot
	}

	if {$addme_addop($chan) && $text != $nick} {
		if {![isop $nick $chan]} {
			putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
			return addname:not_op
		}
	}

	regsub "{" $text "" text
	regsub "}" $text "" text

	if {($text != $nick) &&([lsearch -exact [split [chanlist $chan] " "] $text ] == -1)} {
		putnick $nick "Hmmmm $nick... I see no \002$text\002 here :/ (mIxeD CasE ?)"
		return addname:add_nobody
	}
	
	addme_getvars $chan

	set isin [addme_isintopic $chan $text]
	if {$isin > -1} {
		if {$nick != $text} {
			putnick $nick "Tsss $nick... \002$text\002 is in already !"
		} else {
			putnick $nick "$nick yuo faggot !!1 Already in !"
		}
		return addname:already_added
	}
	

	if {[regsub "\\." $addme_list($chan) $text addme_list($chan)] != 1} {
		putnick $nick "Too late $nick, list full !"
		return addname:too_late
	}

	incr addme_current($chan)
	
	addme_updatetopic $chan $addme_list($chan) $addme_server($chan) $addme_motd($chan)

	if {!$addme_begin($chan) && $addme_current($chan) == $addme_number($chan)} {
		set addme_begin($chan) 1
		addme_2leaders $chan
		addme_noticeall $chan
		addme_addgamecount $chan
		if {$addme_autoremoveall($chan) == 1} {
			addme_removeall $botnick blah bleh $chan
		}
	}

}


proc addme_addgamecount {chan} {
# Increment game counter. Each channel has its own counter file

	if {![file exists "scripts/addme_count.$chan"]} {
		set file [open "scripts/addme_count.$chan" w]
		puts $file "0"
		close $file
	}
	set file [open "scripts/addme_count.$chan" r]
	gets $file count
	close $file

	incr count
	set file [open "scripts/addme_count.$chan" w]
	puts $file $count
	close $file
}


proc addme_gamecount {nick mask hand chan text} {
# Read channel counter file and displays it

	global addme_channels

	if {![regexp $chan $addme_channels]} {
		return gamecount:not_a_valid_channel
	} 

	if {![file exists "scripts/addme_count.$chan"]} {
		putchan $chan "No pickup games launched yet in $chan ..."
		return gamecount:no_counter_file
	}

	set file [open "scripts/addme_count.$chan" r]
	gets $file count
	close $file

	putchan $chan "Number of pickup games launched : \002$count\002 \\o/"

}


proc addme_removename  {nick mask hand chan text} {
# Call the internal proc addme_removename_func when someone types !remove, if supposed to do so

	global botnick
	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_removeop

	if {![regexp $chan $addme_channels]} {
		return removename:not_valid_channel
	}

	if {$text == "" || $text == "{}" || ![info exists text]} {set text $nick}

	if {$addme_removeop($chan) && $text != $nick} {
		if {![isop $nick $chan]} {
			putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
			return removename:not_op
		}
	}

	set isin [addme_isintopic $chan $text]
	if {$isin > -1} {
		set addme_begin($chan) 0
		addme_deleteintopic $chan $isin
	} else {
		if {$nick != $botnick} {
			putnick $nick "There's no $text I can remove here."
		}
	}
}


proc addme_nick {nick host hand chan newnick} {
# When someone listed in topic changes nick (Tom -> Tom|AFK), changes topic to match new nick

	global botnick
	global addme_channels

	if {[regexp $chan $addme_channels]} {
		addme_getvars $chan

		set isin [addme_isintopic $chan $nick]
		if {$isin > -1} {
			addme_replaceintopic $chan $isin $newnick
		}
	}
}


proc addme_part {nick host hand chan text} {
# Remove nick from players list if they leave channel or irc server

	global botnick
	global addme_channels

	if {[regexp $chan $addme_channels]} {
		addme_getvars $chan

		set isin [addme_isintopic $chan $nick]
		if {$isin > -1} {
			addme_deleteintopic $chan $isin
		}
	}
}

proc addme_kick {nick host hand chan target reason} {
# Remove nick from players list if they leave channel or irc server

	global botnick
	global addme_channels

	if {[regexp $chan $addme_channels]} {
		addme_getvars $chan

		set isin [addme_isintopic $chan $target]
		if {$isin > -1} {
			addme_deleteintopic $chan $isin
		}
	}
}


proc addme_updatetopic {chan list server motd} {
# Internal proc modify topic with new arguments (players list, server info and motd)

# Here is the customisation you probably want : modify topic colors
# WARNING : you can change the COLORS, but not the LAYOUT of the topic (ie words & their orders)
# It *MUST* be : "Next : " then some "././." then " | Server : " etc... Spaces are important
# In another words, I insist, modify the COLORS if you wish, but nothing else :)
#
# Color code in TCL are just like in mIRC, except that the ctrl-k is replaced by \003
# Ex : ctrl-k 4 in mIRC is \0034 in TCL
# Ex : ctrl-k 11,3 in mIRC is \00311,3 in TCL
# Ex : ctrl-k in mIRC (to set color defaults) is \003 in TCL
#
# Bold code in TCL is \002, and works like ctrl-b in mIRC (Hello \002my friend\002 wassup)
#
# WARNING : depending on irc networks, topic lengths are limited to a number of caracters. Each
# color control code counts for one caracters
# Ex : "ABCD" is 4 caracters long, "\0031ABCD" is 6 caracters long (control code + color number + ABCD)
# Then, using too many colors may truncate your MOTD
# 
# Here are a few examples of topics :
#
# Original one :
# set newtopic "Next :\0034 $list \0033| Server : $server |\0037 $motd"
#
# Black and red on light grey topic :
# set newtopic "\0031,15Next :\0034 $list \0031| Server : $server |\0034 $motd
#
# Black background, "Next" and ip in white, list and motd in green, "Server" in bold and purple :
# set newtopic "\0030,1Next :\0033 $list \0030| \00313\002Server\002\0030 : $server |\0033 $motd
#

	set newtopic "Next :\0034 $list \0033| Server : $server |\0037 $motd"
	puttopic $chan $newtopic
}


# BOT CREATED FILES
# The bot will create a few files in your scripts directory.
# For channel #lame, it'll be : # addme_count.#lame, addme_maps.#lame, addme_ips.#lame
# containing : game counter, map list to pick from, server info to pick from
# Map list and server list remain in bot's memory, these files are used so that bot wont
# forget anything when he crashes and restarts


proc addme_serverlist_write {nick host hand chan} {
# proc writing to disk the channel servers list, and telling user this list

	global addme_ips
	global addme_channels
	global botnick

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return serverlist_write:not_op
	}

	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick !saveserver <channel>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return serverlist_write:no_channel_specified
	}

	set saved ""
	set file [open "scripts/addme_ips.$chan" w]
	foreach i [split $addme_ips($chan) ","] {
		regsub "\[ ]*$" $i "" i
		regsub "^\[ ]*" $i "" i
		puts $file $i
		lappend saved $i
	}
	close $file

	putnick $nick "Server list for \002$chan\002 saved : [join $saved " \0033,\003 "]"
}


proc addme_maplist_write {nick host hand chan} {
# Proc writing map list to disk, and telling user map list

	global addme_maps
	global addme_channels
	global botnick

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return maplist_write:not_op
	}

	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick !savemap <channel>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return maplist_write:no_channel_specified
	}

	set saved ""
	set file [open "scripts/addme_maps.$chan" w]
	foreach i [split $addme_maps($chan) " "] {
		puts $file $i
		lappend saved $i
	}
	close $file

	putnick $nick "Map list for \002$chan\002 saved : [join $saved " \0033,\003 "]"
}


proc addme_serverlist_read {nick host hand chan} {
# Proc reading serverlist from disk, and telling it to user

	global addme_ips
	global addme_channels
	global botnick

	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick readserver <channel>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return serverlist_read:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return serverlist_read:not_op
	}
	
	set iplist ""
	set file [open "scripts/addme_ips.$chan" r]
	while {![eof $file]} {
		gets $file ip
		if {[string length $ip] > 1} {lappend iplist $ip}
	}
	close $file

	set iplist2 ""
	for {set x 0} {$x < [llength $iplist]} {incr x} {
		lappend iplist2 "\0033\002[expr $x + 1]\002:\003 [lindex $iplist $x]"
	}

	set addme_ips($chan) [join $iplist ", "]
	
	if {$nick != $botnick} {
		if {[llength $iplist2]} {
			set list [join $iplist2 " , "]
		} else {
			set list " <no server> "
		}
		putnick $nick "Servers for \002$chan\002 : $list"
	}
}


proc addme_maplist_read {nick host hand chan} {
# Proc reading map list from disk, and telling it to user

	global addme_maps
	global addme_channels
	global botnick

	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick readmaps <channel>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return maplist_read:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return maplist_read:not_op
	}
	
	set maplist ""
	set file [open "scripts/addme_maps.$chan" r]
	while {![eof $file]} {
		gets $file map
		if {[string length $map] > 1} {lappend maplist $map}
	}
	close $file

	set addme_maps($chan) [join $maplist " "]

	if {$nick != $botnick} {
		if {[llength $maplist]} {
			set list [join $maplist " \0033,\003 "]
		} else {
			set list "<no map>"
		}
		putnick $nick "Map list for \002$chan\002 : $list"
		if {$list == "<no map>"} {
			putnick $nick "To start adding new maps : /msg $botnick addmap $chan <mapname>"
		}
	}

}


proc addme_maplist_add {nick host hand text} {
# Add one map to channel map list, and prints whole list
# NOTE : you can add several times the same map. This is not a bug, it's really a feature :)
# Doing so, you can (secretly:) bias random picking, giving more importance to a particular map
# Ex : if map list is "map1 map2 map3, each map will have 33% probability to be picked
# Ex : if map list is "map1 map2 map3 map3", map1 and map2 have 25% probability, map3 has 50%

	global addme_maps
	global addme_channels
	global botnick

	regsub "{" $text "" text
	regsub "}" $text "" text

	set arglist [split $text " "]
	set chan [lindex $arglist 0]
	set text [lindex $arglist 1]

	# no or wrong channel
	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick addmap <channel> <mapname>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return maplist_add:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return maplist_read:not_op
	}

	# no map
	if {$text == "" || $text == "{}" || ![info exists text]} {
		putnick $nick "Usage : \002/msg $botnick addmap $chan <mapname>\002"
		addme_maplist_read $nick $host $hand $chan
		return maplist_add:no_map_specified
	}

	set file [open "scripts/addme_maps.$chan" a+]
	puts $file $text
	close $file

	putnick $nick "Map\002 $text \002added to\002 $chan"
	addme_maplist_read $nick $host $hand $chan
}


proc addme_serverlist_add {nick host hand text} {
# Add one server to server list, and prints whole line
# NOTE : as above, you can add several times the same server. Although it may be
# useless here, since there's probably no reason to do it... :)

	global addme_ips
	global addme_channels
	global botnick

	regsub "{" $text "" text
	regsub "}" $text "" text

	regexp "(\[^ ]*)(.*)" $text var1 chan newserver

	set newserver [string trim $newserver]

	# no or wrong chan
	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick addserver <channel> <server infos>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		return serverlist_add:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return maplist_read:not_op
	}

	# no server
	if {$newserver == "" || $newserver == "{}" || ![info exists newserver]} {
		putnick $nick "Usage : \002/msg $botnick addserver $chan <server infos>\002"
		addme_serverlist_read $nick $host $hand $chan
		return serverlist_add:no_server_specified
	}

	set file [open "scripts/addme_ips.$chan" a+]
	puts $file $newserver
	close $file

	putnick $nick "Server\002 $newserver \002added to\002 $chan"
	addme_serverlist_read $nick $host $hand $chan
}


proc addme_maplist_remove {nick host hand text} {
# Remove one map from channel map list

	global addme_maps
	global addme_channels
	global botnick

	regsub "{" $text "" text
	regsub "}" $text "" text

	set arglist [split $text " "]
	set chan [lindex $arglist 0]
	set text [lindex $arglist 1]

	# no channel or wrong channel
	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick removemap <channel> <mapname>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		putnick $nick "To list maps : \002/msg $botnick readmaps <channel>\002
		return maplist_remove:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return maplist_remove:not_op
	}

	# channel, but no map
	if {$text == "" || $text == "{}" || ![info exists text] } {
		putnick $nick "Usage : \002/msg $botnick removemap $chan <mapname>\002"
		addme_maplist_read $nick $host $hand $chan
		return maplist_remove:no_map_specified
	}

	# channel, but wrong map
	if {![regexp $text $addme_maps($chan)]} {
		putnick $nick "Map \002$text\002 not in \002$chan\002 list."
		addme_maplist_read $nick $host $hand $chan
		return maplist_remove:wrong_map
	}

	set saved ""
	set found 0
	set file [open "scripts/addme_maps.$chan" w]
	foreach i [split $addme_maps($chan) " "] {
		if {$i != $text || $found == 1} {
			puts $file $i
			lappend saved $i
		}
		if {$i == $text} {
			set found 1
		}
	}
	close $file

	putnick $nick "Map\002 $text \002deleted from\002 $chan\002."
	addme_maplist_read $nick $host $hand $chan

}


proc addme_serverlist_remove {nick host hand text} {
# Remove one server from channel server list

	global addme_ips
	global addme_channels
	global botnick

	regsub "{" $text "" text
	regsub "}" $text "" text

	set arglist [split $text " "]
	set chan [lindex $arglist 0]
	set text [lindex $arglist 1]

	# no channel, or wrong channel
	if {$chan == "" || $chan == "{}" || ![info exists chan] || ![regexp $chan $addme_channels]} {
		putnick $nick "Usage : \002/msg $botnick removeserver <channel> <server number>\002 where channel can be : [join [split $addme_channels " "] " or "]"
		putnick $nick "To list servers : \002/msg $botnick readservers <channel>"
		return serverlist_remove:no_channel_specified
	}

	if {![isop $nick $chan] && $nick != $botnick} {
		putnick $nick "Sorry \002$nick\002, admin command : you need to be op"
		return serverlist_remove:not_op
	}

	# channel, but no server
	if {$text == "" || $text == "{}" || ![info exists text]} {
		putnick $nick "Usage : \002/msg $botnick removeserver $chan <server number>\002"
		addme_serverlist_read $nick $host $hand $chan
		return serverlist_remove:no_server_specified
	}

	# wrong server number
	set serverlist [split $addme_ips($chan) ","]
	if {$text > [llength $serverlist] || $text < 1} {
		putnick $nick "Server number out of range."
		addme_serverlist_read $nick $host $hand $chan
		return serverlist_remove:not_a_valid_server
	}

	set saved ""
	set file [open "scripts/addme_ips.$chan" w]
	for {set x 0} {$x < [llength $serverlist]} {incr x} {
		if {[expr $x +1] != $text} {
			set i [lindex $serverlist $x]
			regsub "\[ ]*$" $i "" i
			regsub "^\[ ]*" $i "" i
			puts $file $i
		}
	}
	close $file

	putnick $nick "Server\002 #$text \002deleted from\002 $chan\002."
	addme_serverlist_read $nick $host $hand $chan

}


proc addme_buildlist {nbre} {
# Internal proc generating empty player list (././././.)

	set point "."
	set slash "/"
	set liste $point
	for {set x 0} {$x < [expr $nbre - 1]} {incr x} {set liste [concat ${liste}${slash}${point}] }
	return $liste
}


proc addme_isintopic {chan text} {
# proc testing if $text is listed in $chan topic. Return -1 if not, or position if yes

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_addop
	global addme_autoremoveall

	addme_getvars $chan

	if {[lsearch -exact [split $addme_list($chan) "/"] $text ] > -1} {
		return [lsearch -exact [split $addme_list($chan) "/"] $text ]
	} else {
		return -1
	}

}

proc addme_replaceintopic {chan position newtext} {
# proc replacing slot number $position in $chan's topic with $newtext

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_addop
	global addme_autoremoveall

	addme_getvars $chan

	set addme_list($chan) [join [lreplace [split $addme_list($chan) "/"] $position $position $newtext] "/"]

	addme_updatetopic $chan $addme_list($chan) $addme_server($chan) $addme_motd($chan)

}

proc addme_deleteintopic {chan position} {
# proc deleting slot number $position

	global addme_channels
	global addme_list
	global addme_server
	global addme_motd
	global addme_number
	global addme_current
	global addme_begin
	global addme_addop
	global addme_autoremoveall

	addme_getvars $chan

	set addme_list($chan) [join [lreplace [split $addme_list($chan) "/"] $position $position] "/"]
	set addme_list($chan) "$addme_list($chan)/."

	addme_updatetopic $chan $addme_list($chan) $addme_server($chan) $addme_motd($chan)

}


proc addme_version {nick uhost hand chan} {
# proc to check version of the script running
# Please dont delete this one, when I happen to come in a pickup channel
# using my script, I like to verify which version is used so I can notify
# channel owner if a new version is available

	global botnick
	global addme_channels

	putnick "$botnick on $addme_channels, running Addme script v 2 - April 2003"

}


# Common procs : say, msg, topic, notice
# You shouldnt even need these, there here just in case

proc putchan {chan msg} { putserv "PRIVMSG $chan :$msg" }
proc putquery {nick msg} { putserv "PRIVMSG $nick :$msg" }
proc putnick {nick msg} { putserv "NOTICE $nick :$msg" }
proc puttopic {chan topic} { putserv "TOPIC $chan :$topic" }



##############################################

# First init :
# This is read only once, when bot loads this script file
# Inits temporary stuffs to default values of temporary stuff, and read
# channel files (map list and server list)

foreach i [split $addme_channels " "] {
	set addme_randommaps($i) ""
	set addme_current($i) 0
	set addme_list($i) ""
	set addme_begin($i) 0
	set addme_maps($i) ""
	set addme_ips($i) ""
	set addme_server($i) "127.0.0.1 pass lame"
	# (default server when bot restarts after crash or die)
	set addme_motd($i) "HF & GL"
	# (default motd when bot restarts after crash or die)
	set addme_leaders($i) ""

	if {![file exists "scripts/addme_maps.$i"]} {
		set file [open "scripts/addme_maps.$i" w]
		close $file
	}

	if {![file exists "scripts/addme_ips.$i"]} {
		set file [open "scripts/addme_ips.$i" w]
		close $file
	}

	addme_maplist_read $botnick bleh bleh $i
	addme_pickmaps $i

	addme_serverlist_read $botnick bleh bleh $i

}

# Last init :
# This is read only once, when bot loads this script file
# Reads infos from channels topic, if any

foreach i [array names addme_channels] {
	addme_getvars $i
}

##############################################
#
# TEMP VARS - BORING SECTION
#
# Notes on temp vars, and example of value, for those interested in really modifying the script
# (remember : if you modify it, it's your problem:) or just understanding
# how it works.
#
# Topic format is : Next : Tom/Dude/Joe/././. | Server : 127.0.0.1 pass toto | This is the MOTD
# The topic *needs* to keep this format, so the script can parse it. Otherwise, it *wont* work.
#
# Each of the following var exists for each channel, eg $addme_list(#here) and $addme_list(#there)
#
# addme_list : the list of players registered (Tom/Dude/Joe/././.)
# addme_current : number of players currently registered for a game, as read in addme_list (3)
# addme_begin : 0 or 1 if the game if ready to begin and has already been announced (0)
# addme_server : server mentionned in topic (127.0.0.1 pass toto)
# addme_motd : message of the day mentionned in topic
# addme_leaders : random leaders picked from topic list when complete
# addme_randommaps : random maps picked from channel maplist, if feature enabled (see above)
#
##############################################



# w00t ! That's it :)

putlog "***** ADDME by Ozh : loaded *****"

