#!/usr/bin/perl -w


## if for some reason, you don't want this script to fix horrible problems
## that could prevent it from working properly with a messed up  xchat 
## config, set the var to 0 ...

$fixhorribleproblems = 1;

##
# NOTE : there are some variables you might want to edit below!

# XDCC'n'STUFF, an xdcc/channel script for x-chat, by Brad Barnett 
# bbarnett@L8R.net put this script in your home dir, and do a /load xdcc.pl 
# in xchat or better yet, put it in ~/.xchat/xdcc.pl .. and it will be autoloaded!
    
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#version check for xchat
$g = 0;
$versioning = IRC::get_info(0);
@chess = ("1", "8", "4");
@wow = split ('\.',$versioning);
foreach $look (@wow) {
if ($look > $chess[$g]) {
last;
} else {
$g = $g + 1;
}
}
if ($g =~ /3/) {
output("\002Sorry, version $chess[0].$chess[1].$chess[2] and older of xchat won't work with this script!\002");
return 1;
}

if (!($wow[0] < 1)) {
if (!($wow[1] < 1)) {
$clientversion = 1;
#output("\002You should update to the next generation of XDCC'n'STUFF, specifically designed to take\002");
#output("\002advantage of xchat 1.1.x dev tree features. \002");
}
}



### homepath kludge #######
open (FIND, "ls -d ~ |");
@test = <FIND>;
close (FIND);
chop($test[0]);
$homepath = $test[0]."/";
chomp($homepath);
######
#$homepath = '/home/hymie/'; #enter your home path here and uncomment if function above fails

# defaults not in config file
# EDIT THESE BEFORE USING THIS SCRIPT OR ELSE!
$modelength = 6; #number of modechanges allowed per line.. CHECK YOUR IRC NETWORK
$hl = "\0034"; #highlight colour
$buttons = 1; # add buttons for the script?
$ignorelog = 1; #log ignored messages to .xdcc/ignore.log?
$ignoreall = 0; #default for ignore all
$nicklength = 15; # if seen requests are > than this number, kick offender

#############

# defaults if no config file found
# everything below here is stored in your config file
# so you only have to edit it once!!

$fautogetdcc = 1; # auto get dcc's from +f users
$dccslots = 10; # number of dcc slots for downloading
$logact = 1; #log actions taken by the script?
$revenge = 1; #revenge level 0 = none, 1 = normal 2 = severe 3 = extreme
$kickreason = "What the hell?!"; #default kick reason
$notichannels = "#amiga_warez"; # default channel(s) for xdcc noti (seperate with space)
$xdccon = 0;  #default status for xdcc, 1=on, 0=off
$versioning = 1; #0 to hide this script in version responses
$pageon = 2; # set ctcp page option.. friends = 2, on = 1, off = 0
$logon = 1; # set log option.. on = 1, off = 0
$lognowin = 1; # if 1, this will stop message windows from opening while away and logging
$xdccflist = 1; # xdcc packlists as notices, or as a file... 1=file, 0=notice
$floodchannum = "10:60"; # 10 chan messages in 60 seconds will get a kick
$floodmsgnum = "5:60"; # same as above, but for privmsgs..  
$floodctcpnum = "5:60"; # same as above, but for ctcp msgs..  
$floodnotinum = "5:60"; # same as above, but for notice msgs..  
$floodmodenum = "5:60"; # same as above, but for mode changes..  
$ignoretimeout = 60;  # timeouts on ignores
$isfloodon = 1; # flood protection on or off
$soundson = 1; # action sounds on or off
$revengekick = 1; # revenge level if a p user is kicked
$revengeban = 1; # revenge level if a p user is banned
$revengedeop = 1; # revenge level if a p user is deopped
$revengemode = 1; # revenge level if a mass mode change happens
$revengeopadeop = 1; # revenge level if a +d user is opped
$revengevoiceanovoice = 1; # revenge level if a +d user is opped
$revengeunbanak = 1; # revenge level if a +k user is unbanned
$irevenge = 1; # revenge to add if user has the i flag
$prevenge = 1; # revenge to subtract if the offender is a p user
$finvite = 1; # auto join on a friend's invite?
$clearban = 1; # remove a ban and replace your ban if banlist is full
$logtypes = "1;1;1;1;1"; # script log settings
$morktimeout = 60; # timeout for revenge actions
$trytoautojoin = 1; # autojoin channels when you are banned/its +i/k/l?
$watchserver = " "; # set this to a server group if you want auto connect on
$commandonjoin = " "; # commands to execute when successfully joining a watched server 
$increaserevenge = 1; # increase personal revenge on repeated kicks?
$forceban = 1; # if someone unbans a k user, reban?
$seenliston = 1; # turn on !seen responses
$seenlistchans = " "; #list of channels that !seen will respond in
$seenlevel = 1; #seen level
$seenresponse = 0; #seen response to channel or user
$seenliststore = 1; # turn on storing of parts/quits/etc for seen replies
$seencompare = 1 ; # compare nick, username and channel a user was on and eliminate duplicates?
$floodmassnum = "5:5"; # same as above, but for mode changes..  
$dapacks = 1; # display or hide friends only packs on plist?
$awaynick = "IBEGONE"; # away nick
$awaynotice = 1; # tell people on channels when you mark yourself away?
$awaysync = 1; # sync /away on all servers
$outputlimit = 2; # number of lines to output every 4 seconds
$okpagetimes = ""; # times you want to be available for page (nothing = always)
$seentime = 30; # delete seen info if older than $seentime days
$seenlimit = 4; #more than x seen replies / request will be truncated 
$cycleforop = 1; # cycle for ops on empty channels? 
$grabnick = 0; # try to re-grab your nick if you couldn't get it on server join
$maxslotsperuser = 3; # max slots / user
$xdccpublistmethod = 1; # 0 = notice, 1 = privmsg 
$stealvertime = 0; # number of seconds to wait before changing version reply (0 = off)
$stealverper = 0; # extend version stickiness if versioned before timeout is reached
$jumpserver = 0; #default value
$amsgon = 0; #default value
$clonenumberkick = 0; #default
$revengeclonenumberkick = 1; #default
$channellistcheck = 0; #default
$seenlistsavetime = 0; #default
$getverinfo[0] = "0"; #default
$channellog[0] = "0";$channellog[1]="0";
$timeit = 0; #default
$remembertimecalled = time;

# for sounds, set to "" if you don't want anything for that trigger
$kicksound = "kick.wav"; # name of kick sound in dir $home/.xdcc/
$noticesound = "notice.wav"; # name of notice sound in dir $home/.xdcc/
$dccsound = "dcc.wav"; # name of dcc sound in dir $home/.xdcc/
$xdccsound = "xdcc.wav"; # name of xdcc sound in dir $home/.xdcc/
$ctcpsound = "ctcp.wav"; # name of ctcp sound in dir $home/.xdcc/
$privmsgsound = "privmsg.wav"; # name of privmsg sound in dir $home/.xdcc/
$chanmsgsound = "chanmsg.wav"; # name of chanmsg sound in dir $home/.xdcc/
$joinsound = "join.wav"; # name of join sound in dir $home/.xdcc/
$modesound = "mode.wav"; # name of mode sound in dir $home/.xdcc/
$pagecommand = "play"; # note, page command plays $homepath/.xdcc/page.wav
$invitesound = "invite.wav"; # name of invite sound in dir $home/.xdcc/
$partsound = "part.wav"; # name of part sound in dir $home/.xdcc/
$quitsound = "quit.wav"; # name of quit sound in dir $home/.xdcc/


IRC::add_message_handler("ERROR", "klined");
IRC::add_message_handler("TOPIC", "topic");
IRC::add_message_handler("PONG", "pong");
IRC::add_message_handler("478", "full_banlist");
IRC::add_message_handler("367", "unban_handler");
IRC::add_message_handler("368", "unban_end_handler");
#IRC::add_message_handler("315", "end_who_handler");
#IRC::add_message_handler("352", "who_handler");
IRC::add_message_handler("PRIVMSG", "privmsg_handler");
IRC::add_message_handler("NOTICE", "notice_handler");
IRC::add_message_handler("MODE", "mode_change");
IRC::add_message_handler("QUIT", "quit");
IRC::add_message_handler("KICK", "kick");
IRC::add_message_handler("JOIN", "join");
IRC::add_message_handler("PART", "part");
IRC::add_message_handler("INVITE", "invite_handler");
#IRC::add_message_handler("PRIVMSG", "test6");


IRC::add_message_handler("376", "connect_handler");
IRC::add_message_handler("NICK", "setnick_handler");
IRC::add_message_handler("306", "away");
IRC::add_message_handler("305", "back");
IRC::add_message_handler("471", "autojoin");
IRC::add_message_handler("473", "autojoin");
IRC::add_message_handler("474", "autojoin");
IRC::add_message_handler("475", "autojoin");
IRC::add_message_handler("200", "trace_garbage");
IRC::add_message_handler("206", "trace_no");
IRC::add_message_handler("205", "trace_yes");
IRC::add_message_handler("433", "grab_nick_failed");

IRC::add_command_handler("noti", "noti");
IRC::add_command_handler("addp", "add_pack");
IRC::add_command_handler("delp", "del_pack");
IRC::add_command_handler("plist", "plist_pack");
IRC::add_command_handler("packlist", "list_pack");

IRC::add_command_handler("addf", "add_friend2");
IRC::add_command_handler("listf", "list_friend");
IRC::add_command_handler("delf", "del_friend");
IRC::add_command_handler("editf", "edit_friend");

IRC::add_command_handler("gui", "gui");
IRC::add_command_handler("delaway", "delaway");

IRC::add_command_handler("xdcc", "xdcc_on");
IRC::add_command_handler("log", "log");
IRC::add_command_handler("page", "page");
IRC::add_command_handler("setaway", "set_away");
IRC::add_command_handler("ver", "setver");
IRC::add_command_handler("logwin", "setlogwin");
IRC::add_command_handler("chan", "setchan");
IRC::add_command_handler("listmode", "listmode");

IRC::add_command_handler("savec", "save_conf");
IRC::add_command_handler("loadc", "load_conf");
IRC::add_command_handler("kickreason", "set_kickreason");
IRC::add_command_handler("revenge", "set_revenge");
IRC::add_command_handler("scriptlog", "logactions");
IRC::add_command_handler("autoconnect", "autoconnect");
IRC::add_command_handler("server", "server");
IRC::add_command_handler("seen", "seen");
IRC::add_command_handler("setseen", "setseen");
IRC::add_command_handler("dpack", "dpack");
IRC::add_command_handler("away", "setaway");
IRC::add_command_handler("url", "url");
IRC::add_command_handler("stealver", "stealver");
IRC::add_command_handler("rawout", "rawout");

IRC::add_command_handler("grabnick", "grabnick");
IRC::add_command_handler("autocycle", "autocycle");
IRC::add_command_handler("mmode", "mass_something");
IRC::add_command_handler("mcom", "mass_command");
IRC::add_command_handler("mmsg", "massmessage");
IRC::add_command_handler("ajoin", "ajoin");
IRC::add_command_handler("ks", "ks");
IRC::add_command_handler("fig", "fig");
IRC::add_command_handler("reban", "reban");
IRC::add_command_handler("finvite", "finvite");
IRC::add_command_handler("sound", "sound");
IRC::add_command_handler("ikick", "ikick");
IRC::add_command_handler("wkick", "wkick");
IRC::add_command_handler("skick", "skick");
IRC::add_command_handler("ignoretime", "ignoretime");
IRC::add_command_handler("setignore", "ignore");
IRC::add_command_handler("mdeop", "mdeop");
IRC::add_command_handler("kick", "kicker");
IRC::add_command_handler("slog", "slog");
IRC::add_command_handler("unban", "unban2");
IRC::add_command_handler("ban", "ban");
IRC::add_command_handler("chanlog", "chanlog");
#IRC::add_command_handler("list", "list");
IRC::add_command_handler("amsg", "amsg");
IRC::add_command_handler("slots", "slots");
IRC::add_command_handler("flood", "flood");
IRC::add_command_handler("ignoreall", "ignoreall");
IRC::add_command_handler("autoget", "autoget");
IRC::add_command_handler("wallop", "wallop");
#IRC::add_command_handler("unload", "unload");
IRC::add_command_handler("publist", "publist");
#IRC::add_command_handler("gignore", "getignores");
IRC::add_command_handler("specs", "specs");


########## loading xchat config (check for tabnicks)

if (!(open(XCONF, $homepath.".xchat/xchat.conf"))) {
output("\002No xchat config found!\002");
} else {
@slist2 = <XCONF>;
$f = "@slist2";

$o = 0;
if ($fixhorribleproblems == 1) {
if ($f =~ /perlwarnings = 1/si) {
`perl -pi.old -e \'s/perlwarnings = 1/perlwarnings = 0/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nPerl Warning Messages are on, turning them off!\n";
IRC::command "/set perlwarnings 0";
$o = 1;
}

if ($f =~ /userhost = 0/si) {
`perl -pi.old2 -e \'s/userhost = 0/userhost = 1/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nWho on Channel Join must be on so this script can work properly!\n";
IRC::command "/set userhost 1";
$o = 1;
}
if ($f =~ /dcc_stall_timeout = 0/si) {
`perl -pi.old3 -e \'s/dcc_stall_timeout = 0/dcc_stall_timeout = 120/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nDCC stall timeout has been set to 120 seconds.  Any value is ok other than off!!!\n";
IRC::command "/set dcc_stall_timeout 120";
$o = 1;
}
if ($f =~ /(ctcp_number_limit = (\d+))/si) {
$iboohmm = $1;
if ($2 < 100) {
`perl -pi.old4 -e \'s/$iboohmm/ctcp_number_limit = 100/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nXChat's CTCP FLOOD LIMIT has been set to 100.  This script has more advanced flood protection, and xchat will interfere with it.\n";
IRC::command "/set ctcp_number_limit 100";
$o = 1;
}
}
if ($f =~ /(ctcp_time_limit = (\d+))/si) {
$iboohmm = $1;
if ($2 > 1) {
`perl -pi.old4 -e \'s/$iboohmm/ctcp_time_limit = 1/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nXChat's CTCP TIME LIMIT has been set to 1.  This script has more advanced flood protection, and xchat will interfere with it.\n";
IRC::command "/set ctcp_time_limit 1";
$o = 1;
}
}
if ($f =~ /(msg_number_limit = (\d+))/si) {
$iboohmm = $1;
if ($2 < 100) {
`perl -pi.old4 -e \'s/$iboohmm/msg_number_limit = 100/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nXChat's MSG FLOOD LIMIT has been set to 100.  This script has more advanced flood protection, and xchat will interfere with it.\n";
IRC::command "/set msg_number_limit 100";
$o = 1;
}
}
if ($f =~ /(msg_time_limit = (\d+))/si) {
$iboohmm = $1;
if ($2 > 1) {
`perl -pi.old4 -e \'s/$iboohmm/msg_time_limit = 1/g;\' $homepath/.xchat/xchat.conf`; 
IRC::print "\nXChat's MSG TIME LIMIT has been set to 1.  This script has more advanced flood protection, and xchat will interfere with it.\n";
IRC::command "/set msg_time_limit 1";
$o = 1;
}
}
if ($o == 1) {
IRC::print "\nYour xchat config file has been updated!\n\n";
}
}

$tabnicks = 1;
if ($f =~ /auto_indent = 1/gsi) {
$tabnicks = 0; #set if you have tabnicks on
}
close(XCONF);
###############
if ($tabnicks == 0) {
output("\002Tabnicks are $hl"."OFF\003\002");
} elsif ($tabnicks == 1) {
output("\002Tabnicks are $hl"."ON\003\002");
} else {
output("\002Couldn't set tabnicks var from xchat config!\002");
}
}

# check for config dir

if (!(-e $homepath.".xdcc")) {
output("\002Making .xdcc dir for config files...\002");
system "mkdir ".$homepath.".xdcc";
}

########## loading config file

if (!(open(CONFFILE, $homepath.".xdcc/config"))) {
output("\002No config file found!  Creating one!\002");
&save_conf;
&load_conf;
} else {
$list = <CONFFILE>;
  

@lister = split(';;;',$list);
($notichannels,$xdccon,$versioning,$pageon,$logon,$lognowin,$xdccflist,$kickreason,$revenge,$logact,$dccslots,$fautogetdcc,$floodchannum,$floodmsgnum,$ignoretimeout,$floodctcpnum,$floodnotinum,$floodmodenum,$isfloodon,$soundson,$revengekick,$revengeban,$revengedeop,$revengemode,$prevenge,$irevenge,$finvite,$revengeopadeop,$revengeunbanak,$clearban,$logtypes,$morktimeout,$trytoautojoin,$watchserver,$increaserevenge,$forceban,$commandonjoin,$seenliston,$kicksound,$noticesound,$dccsound,$xdccsound,$ctcpsound,$privmsgsound,$chanmsgsound,$joinsound,$modesound,$pagecommand,$seenlistchans,$seenlevel,$seenresponse,$seenliststore,$seencompare,$invitesound,$partsound,$quitsound,$floodmassnum,$dapacks,$awaynick,$awaynotice,$awaysync,$outputlimit,$okpagetimes,$seentime,$seenlimit,$cycleforop,$grabnick,$maxslotsperuser,$xdccpublistmethod,$stealvertime,$stealverper,$revengevoiceanovoice,$clonenumberkick,$revengeclonenumberkick) = @lister;
close(CONFFILE);
output("\002Config file loaded!\002");
}


if (!($revengevoiceanovoice)) {
output("\002Updating config file!\002");
$revengevoiceanovoice = 1; # default revenge if a +q user is voiced
&save_conf;
}

if (!($dccslots =~ /\d+/)) {
$dccslots = 10;
output("\002Updating config file!\002");
&save_conf;
}
if (!($logact =~ /\d/)) {
output("\002Updating config file!\002");
$logact = 1; #log actions taken by the script?
&save_conf;
}
if (!($revenge =~ /\d/)) {
output("\002Updating config file!\002");
$revenge = 1; #revenge level 0 = none, 1 = kick 2 = ban
&save_conf;
}
if (!($kickreason =~ /.+/)) {
output("\002Updating config file!\002");
$kickreason = "What the hell?!"; #default kick reason
&save_conf;
}
if (!($notichannels =~ /.+/)) {
output("\002Updating config file!\002");
$notichannels = "#change_me"; # default channel(s) for xdcc noti (seperate with space)
&save_conf;
}
if (!($xdccon =~ /\d/)) {
output("\002Updating config file!\002");
$xdccon = 0;  #default status for xdcc, 1=on, 0=off
&save_conf;
}
if (!($versioning =~ /\d/)) {
output("\002Updating config file!\002");
$versioning = 1; #0 to hide this script in version responses
&save_conf;
}
if (!($pageon =~ /\d/)) {
output("\002Updating config file!\002");
$pageon = 2; # set ctcp page option.. friends = 2, on = 1, off = 0
&save_conf;
}
if (!($logon =~ /\d/)) {
output("\002Updating config file!\002");
$logon = 1; # set log option.. on = 1, off = 0
&save_conf;
}
if (!($lognowin =~ /\d/)) {
output("\002Updating config file!\002");
$lognowin = 1; # if 1, this will stop message windows from opening while away and logging
&save_conf;
}
if (!($xdccflist =~ /\d/)) {
output("\002Updating config file!\002");
$xdccflist = 1; # xdcc packlists as notices, or as a file... 1=file, 0=notice
&save_conf;
}
if (!($fautogetdcc =~ /\d/)) {
output("\002Updating config file!\002");
$fautogetdcc = 1; # auto get dcc's from +f users
&save_conf;
}
if (!($floodchannum =~ /.+/)) {
output("\002Updating config file!\002");
$floodchannum = "10:60"; #default flood channel setting
&save_conf;
}
if (!($floodmsgnum =~ /.+/)) {
output("\002Updating config file!\002");
$floodmsgnum = "10:60"; #default msg flood setting
&save_conf;
}
if (!($ignoretimeout =~ /.+/)) {
output("\002Updating config file!\002");
$ignoretimeout = "120"; #default flood timeout
&save_conf;
}
if (!($floodctcpnum =~ /.+/)) {
output("\002Updating config file!\002");
$floodctcpnum = "10:60"; #default ctcp flood setting
&save_conf;
}
if (!($floodnotinum =~ /.+/)) {
output("\002Updating config file!\002");
$floodnotinum = "10:60"; #default notice flood setting
&save_conf;
}
if (!($floodmodenum =~ /.+/)) {
output("\002Updating config file!\002");
$floodmodenum = "4:10"; #default notice flood setting
&save_conf;
}
if (!($isfloodon =~ /.+/)) {
output("\002Updating config file!\002");
$isfloodon = 1; #default flood setting
&save_conf;
}
if (!($soundson =~ /.+/)) {
output("\002Updating config file!\002");
$soundson = 1; #default action sound setting
&save_conf;
}
if (!($revengekick =~ /.+/)) {
output("\002Updating config file!\002");
$revengekick = 1; #default revenge on p user kick
&save_conf;
}
if (!($revengeban =~ /.+/)) {
output("\002Updating config file!\002");
$revengeban = 1; #default revenge on p user ban
&save_conf;
}
if (!($revengedeop =~ /.+/)) {
output("\002Updating config file!\002");
$revengedeop = 1; #default revenge on p user deop
&save_conf;
}
if (!($revengemode =~ /.+/)) {
output("\002Updating config file!\002");
$revengemode = 1; #default revenge on mass mode change
&save_conf;
}
if (!($prevenge =~ /.+/)) {
output("\002Updating config file!\002");
$prevenge = 1; # default p user offender, decrease
&save_conf;
}
if (!($irevenge =~ /.+/)) {
output("\002Updating config file!\002");
$irevenge = 1; # default i user revenge increase
&save_conf;
}
if (!($finvite =~ /.+/)) {
output("\002Updating config file!\002");
$finvite = 1; # default join on friend invite status
&save_conf;
}
if (!($revengeopadeop =~ /.+/)) {
output("\002Updating config file!\002");
$revengeopadeop = 1; # default revenge if a +d user is opped
&save_conf;
}
if (!($revengevoiceanovoice =~ /.+/)) {
output("\002Updating config file!\002");
$revengevoiceanovoice = 1; # default revenge if a +q user is voiced
&save_conf;
}


if (!($revengeunbanak =~ /.+/)) {
output("\002Updating config file!\002");
$revengeunbanak = 1; # default revenge is a +k user is unbanned
&save_conf;
}
if (!($clearban =~ /.+/)) {
output("\002Updating config file!\002");
$clearban = 1; # clear a ban and replace your ban if banlist is full
&save_conf;
}
if (!($logtypes =~ /.+/)) {
output("\002Updating config file!\002");
$logtypes = "1;1;1;1;1"; # script log settings
&save_conf;
}
if (!($morktimeout =~ /.+/)) {
output("\002Updating config file!\002");
$morktimeout = 60; # timeout for revenge actions
&save_conf;
}
if (!($trytoautojoin =~ /.+/)) {
output("\002Updating config file!\002");
$trytoautojoin = 1; # autojoin channels when you are banned/its +i/k/l?
&save_conf;
}
if (!($watchserver =~ /.+/)) {
output("\002Updating config file!\002");
$watchserver = " "; # set this to a server group if you want auto connect on
&save_conf;
}
if (!($increaserevenge =~ /.+/)) {
output("\002Updating config file!\002");
$increaserevenge = 1; # increase personal revenge on repeated kicks?
&save_conf;
}
if (!($forceban =~ /.+/)) {
output("\002Updating config file!\002");
$forceban = 1; # if someone unbans a k user, reban?
&save_conf;
}
if (!($commandonjoin =~ /.+/)) {
output("\002Updating config file!\002");
$commandonjoin = " "; # commands to execute when successfully joining a watched server 
&save_conf;
}
if (!($seenliston =~ /.+/)) {
output("\002Updating config file!\002");
$seenliston = 1; # turn on !seen responses
&save_conf;
}
if (!($kicksound =~ /.+/)) {
output("\002Updating config file!\002");
$kicksound = "kick.wav"; # name of kick sound in dir $home/.xdcc/
&save_conf;
}
if (!($noticesound =~ /.+/)) {
output("\002Updating config file!\002");
$noticesound = "notice.wav"; # name of notice sound in dir $home/.xdcc/
&save_conf;
}
if (!($dccsound =~ /.+/)) {
output("\002Updating config file!\002");
$dccsound = "dcc.wav"; # name of dcc sound in dir $home/.xdcc/
&save_conf;
}
if (!($xdccsound =~ /.+/)) {
output("\002Updating config file!\002");
$xdccsound = "xdcc.wav"; # name of xdcc sound in dir $home/.xdcc/
&save_conf;
}
if (!($ctcpsound =~ /.+/)) {
output("\002Updating config file!\002");
$ctcpsound = "ctcp.wav"; # name of ctcp sound in dir $home/.xdcc/
&save_conf;
}
if (!($privmsgsound =~ /.+/)) {
output("\002Updating config file!\002");
$privmsgsound = "privmsg.wav"; # name of privmsg sound in dir $home/.xdcc/
&save_conf;
}
if (!($chanmsgsound =~ /.+/)) {
output("\002Updating config file!\002");
$chanmsgsound = "chanmsg.wav"; # name of chanmsg sound in dir $home/.xdcc/
&save_conf;
}
if (!($joinsound =~ /.+/)) {
output("\002Updating config file!\002");
$joinsound = "join.wav"; # name of join sound in dir $home/.xdcc/
&save_conf;
}
if (!($modesound =~ /.+/)) {
output("\002Updating config file!\002");
$modesound = "mode.wav"; # name of mode sound in dir $home/.xdcc/
&save_conf;
}
if (!($pagecommand =~ /.+/)) {
output("\002Updating config file!\002");
$pagecommand = "play"; # note, page command plays $homepath/.xdcc/page.wav
&save_conf;
}
if (!($seenlistchans =~ /.+/)) {
output("\002Updating config file!\002");
$seenlistchans = " "; #list of channels that !seen will respond in
&save_conf;
}
if (!($seenlevel =~ /.+/)) {
output("\002Updating config file!\002");
$seenlevel = 1; #seen response level
&save_conf;
}
if (!($seenresponse =~ /.+/)) {
output("\002Updating config file!\002");
$seenresponse = 0; #seen response to channel or user
&save_conf;
}
if (!($seenliststore =~ /.+/)) {
output("\002Updating config file!\002");
$seenliststore = 1; # turn on storing of parts/quits/etc for seen replies
&save_conf;
}
if (!($seencompare =~ /.+/)) {
output("\002Updating config file!\002");
$seencompare = 1 ; # compare nick, username and channel a user was on and eliminate duplicates?
&save_conf;
}
if (!($invitesound =~ /.+/)) {
output("\002Updating config file!\002");
$invitesound = "invite.wav"; # name of invite sound in dir $home/.xdcc/
&save_conf;
}
if (!($partsound =~ /.+/)) {
output("\002Updating config file!\002");
$partsound = "part.wav"; # name of part sound in dir $home/.xdcc/
&save_conf;
}
if (!($quitsound =~ /.+/)) {
output("\002Updating config file!\002");
$quitsound = "quit.wav"; # name of quit sound in dir $home/.xdcc/
&save_conf;
}
if (!($floodmassnum =~ /.+/)) {
output("\002Updating config file!\002");
$floodmassnum = "10:20"; # same as above, but for mode changes..  
&save_conf;
}

if (!($dapacks =~ /.+/)) {
output("\002Updating config file!\002");
$dapacks = 1; # display or hide friends only packs on plist?
&save_conf;
}
if (!($awaynick =~ /.+/)) {
output("\002Updating config file!\002");
$awaynick = "IBEGONE"; # away nick
&save_conf;
}
if (!($awaynotice =~ /.+/)) {
output("\002Updating config file!\002");
$awaynotice = 1; # tell people on channels when you mark yourself away?
&save_conf;
}
if (!($outputlimit =~ /.+/)) {
output("\002Updating config file!\002");
$outputlimit = 4; # number of lines to output every 4 seconds
&save_conf;
}
if (!($seentime =~ /.+/)) {
output("\002Updating config file!\002");
$seentime = 30; # delete seen info if older than $seentime days
&save_conf;
}
if (!($seenlimit =~ /.+/)) {
output("\002Updating config file!\002");
$seenlimit = 4; #more than x seen replies / request will be truncated 
&save_conf;
}
if (!($cycleforop =~ /.+/)) {
output("\002Updating config file!\002");
$cycleforop = 1; # auto cycle for ops on empty channels
&save_conf;
}
if (!($grabnick =~ /.+/)) {
output("\002Updating config file!\002");
$grabnick = 0; # try to re-grab your nick if you couldn't get it on server join
&save_conf;
}
if (!($maxslotsperuser =~ /.+/)) {
output("\002Updating config file!\002");
$dccslots = 10;
$maxslotsperuser = 3; # max slots / user
&save_conf;
}
if (!($xdccpublistmethod =~ /.+/)) {
output("\002Updating config file!\002");
$xdccpublistmethod = 1; # set pub list type to privmsg
&save_conf;
}
if (!($stealvertime =~ /.+/)) {
output("\002Updating config file!\002");
$stealvertime = 0; # number of seconds to wait before changing version reply (0 = off)
&save_conf;
}

if (!($stealverper =~ /.+/)) {
output("\002Updating config file!\002");
$stealverper = 0; # extend version stickiness if versioned before timeout is reached
&save_conf;
}


if (!($clonenumberkick =~ /\d+/)) {
output("\002Updating config file!\002");
$clonenumberkick = 0; # clone stuff
&save_conf;
}

if (!($revengeclonenumberkick =~ /\d+/)) {
output("\002Updating config file!\002");
$revengeclonenumberkick = 1; # clone stuff
&save_conf;
}



#############


# adding buttons if wanted
if ($buttons =~ /1/) {
IRC::command "/delbutton AddF";
IRC::command "/delbutton Ignore";
IRC::command "/delbutton Notify";
IRC::command "/delbutton WideBan";

IRC::command "/addbutton AddF /addf %s ofxp";
IRC::command "/addbutton Ignore /ignore *!*\@%h PRIV CTCP NOTI INVI";
IRC::command "/addbutton Notify /noti";
IRC::command "/addbutton WideBan /ban %s /w";
}




# getting who info on joined channels
#@nicks = @nullvariable;
#$whoflag = 0;
#$newwhoflag = 0;
@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;

@wow = split (';;;',$boot);
foreach $boot (@wow) {
@manofchan = split (' ',$boot);
#$comm = "/raw who $manofchan[0]";
#$whoflag = $whoflag + 1;
#$newwhoflag = $newwhoflag + 1;
#IRC::command_with_server($comm,$manofchan[1]);
$booboo = stripn($manofchan[0]);
$booboo2 = stripn($manofchan[1]);
$booboo3 = stripn($manofchan[2]);
push @listofjoinedchannels,("$booboo,,,$booboo2,,,$booboo3");
}

# some vars to initialize
$tryingserver = "NOTHING";
$userjoined = 0;
$lastmode = "blank";
$lastkick = "blank";
$revengemask = "nothing";
$maxcps = 0;
$totalsnagged = 0;
$convsnagged = "0 b";

#checking for away messages
$isaway = 0;
@tests = IRC::server_list;
foreach $tee (@tests) {
IRC::command_with_server("/raw away",$tee);
}

#initialize xdcc packlist

$xdccstat = 0;
if (open(XDCCFILE,$homepath.".xdcc/xdcclist")) {
output("\002Loading XDCCLIST... \002");

@xdcclist = <XDCCFILE>;
$totaloffer = 0;
$packs = 0;
foreach $test (@xdcclist) {
$packs++;

#$test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
@glab = split(',,,',$test);

#output("\002<\002$packs\002>\002 \002[\002$glab[3]\002:\002$glab[2]\002]\002 $glab[1]");
$totaloffer = $totaloffer + $glab[4];
}
####

$totalmegsize = byte_converter($totaloffer);

######

close(XDCCFILE);
} else {
output("XDCC file not found!");
}

$mynick = IRC::get_info(1);

$yyy = 0;
#initialize friendlist
if (open(FRIENDFILE, $homepath.".xdcc/friendslist")) {
output("\002Friends list opened...\002");
@friendlist = <FRIENDFILE>;
foreach $test (@friendlist) {

## temp to update friendslist for new formet
if (!($test =~ /:::/)) {
$friendlist[$yyy] = "$friendlist[$yyy]::::::";
}
$yyy = $yyy + 1;
###### 
#$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
}
close(FRIENDFILE);
} else {
output("Friendlist not found!");
}
#list_friend;

##### loading ignorelist

if (!(open(IGNOREFILE, $homepath.".xdcc/ignorelist"))) {
output("\002No ignore list found!\002");
} else {

$list = <IGNOREFILE>;
if ($list) {
@ignorelist = split(';;;',$list);
}
close(IGNOREFILE);

output("\002Ignore list loaded!\002");

}
##### loading wordkicks

if (!(open(IGNOREFILE, $homepath.".xdcc/wordkick"))) {
output("\002No kickword file found!\002");
} else {

$list = <IGNOREFILE>;

@wordkick = split(';;;',$list);
close(IGNOREFILE);

@test = split(' ',$list);
if (!($test[0] =~ /ban/ or $test[0] =~ /kick/)) {
if ($test[0] =~ /\S+/) {
@wordkick = @nothing;
output("\002Deleting old/corrupt kickwords!\002");
wkick("save");
}
}

output("\002Kickwords loaded!\002");

}
##### loading version info

if (!(open(IGNOREFILE, $homepath.".xdcc/version"))) {
output("\002No version file found!\002");
stealver("/save");
} else {
@stealversion = <IGNOREFILE>;
chomp @stealversion;
close(IGNOREFILE);
output("\002Version Reply Loaded!\002");
}




########## loading server list
IRC::print "a $homepath\n";
$slist = $nothing;
$foundserver = 0;
if (!(open(SERVERLIST, $homepath.".xchat/serverlist.conf"))) {
output("\002No server list found!\002");
} else {
@slist2 = <SERVERLIST>;

foreach my $ss (@slist2) {
$slist = $slist.$ss."\n";
}
@slist2 = split('\n\n\n',$slist);
@serverlist = @nothing;
foreach $f (@slist2) {
if ($f =~ / ENDSUB/) {
$foundserver = 0; 
next;
}
if ($f =~ /SUB/) {
$foundserver = 1;
@g = split(/comment = /,$f);
my @rr = split("\n",$g[1]);
$g[1] = $rr[0];
chomp($g[1]);
$holda = "$g[1];;;;;";
next;
}


if ($foundserver == 1) {
@a = split(/\n/,$f);

foreach $b (@a) {
if ($b =~ /servername/i) {
@g = split(/ = /,$b);
$hold = $hold."$g[1];;;;;";
}
if ($b =~ /port/i) {
@g = split(/ = /,$b);
$hold = $hold."$g[1];;;;;";
}
if ($b =~ /channel/i) {
@g = split(/ = /,$b);
$hold = $hold."$g[1];;;;;";
}
}
if ($holda) {
if ($hold) {
push @serverlist,("$holda$hold");
$hold = $nothing;
}
}
}
}

close(SERVERLIST);

output("\002Server list loaded!\002");
}

########## loading seen list

if (!(open(SEENLIST, $homepath.".xdcc/seenlist"))) {
output("\002No seenlist found!\002");
} else {
$slist = <SEENLIST>;
@seenlist = split(';',$slist);
close(SEENLIST);
output("\002Seenlist loaded!\002");
}

### cleaning seen list

if ($seenliststore == 1) {
sortseen();
}

##### loading awayreasons

if (!(open(AWAYREASON, $homepath.".xdcc/awayreasons"))) {
output("\002NO away reasons file found!\002");
} else {

@awayreasons = <AWAYREASON>;

close(AWAYREASON);
output("\002Away Reasons Loaded!\002");
}

##### removing any script ignores that may be left over
##### from the last time the client was run

foreach $ignorecheckup (@friendlist) {
$ignorecheckup =~ /(.*),(.*),(.*):::(.*):::(.*)/;
my $nick = $1;
my $flags = $2;
my $rest2 = $3;

my @more = split(';;;',$5);
foreach my $go (@more) {
my @ho = split(' ',$go);
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
my @flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach my $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
if ($flags =~ /f/i) {
my @boogieface = split (':',$rest2);
foreach my $rest (@boogieface) {
IRC::command "/unignore $rest";
}
}
}
IRC::command "/unignore *!*@*.*";
output("\002Removing any old script ignores\002");







#######starting timers

IRC::add_timeout_handler(2000, "timer_handler");
IRC::add_timeout_handler(5000, "dcc_send_handler");

#### setting defaults for some vars

$attempttoconnect = 11;
$timestried = @serverlist;

sl(3,"\002XDCC'N'STUFF loaded\002");


#######################################
sub notice_handler 
{
$line = shift(@_);

my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);
### away messages to file....

@woona = split(' NOTICE ',$line);
$line = shift(@woona);
if (!($line =~ /\@/)) {
return 0;
}
@hrms = split(':',$line,3);
shift(@hrms);
$from = "@hrms";
@hrms = split('!',"@hrms",2);
$dude = $hrms[0];
$hostname = $hrms[1];

$line2 = "@woona";
@woona = split(' :',$line2,2);
$part3 = shift(@woona);
$boot1 = quotemeta $part3;
$message = "@woona";
$chanster = $part3;
$schan = quotemeta $chanster;
##
$boot3 = quotemeta $dude;
my $ignorechecks = 0;
$isaway = 0;
foreach $booser (@awaylist) {
my $rr = quotemeta $booser;
if (" $r " =~ / $rr /) {
$isaway = 1;
last;
}
}

$isfriend = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/starmatch/g;
$rest =~ s/\?/questionmark/g;
$rest2 = quotemeta $rest;
$rest2 =~ s/starmatch/\.\*/go;
$rest2 =~ s/questionmark/\./go;
if (" $from " =~ / $rest2 /i) {
$isfriend = 1;
$newflags = $flags;
$newnick = $nick;
last;
}
}
}
if ($isfriend =~ /1/) {
$flags = $newflags;
$nick = $newnick;
} else {
$flags = $nothing;
$nick = $nothing;
}
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$month = $month + 1;

$notchanmsg = 1;
if ($chanster =~ /#.+/) {
$notchanmsg = 0;
if ("  $message" =~ /  \001/i) {
$notchanmsg = 1;
} 
}

### ignore all privmsgs, ctcp, etc, from everyone but +f users
if (!(" $mynick " =~ / $boot3 /i)) {
if ($ignoreall =~ /1/) {
if ($flags =~ /f/) {
} elsif ($notchanmsg == 1) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}
}

if ($message =~ /\001version/i) {
if ($getverinfo[0] ne "0") {
if (" $getverinfo[0] " =~ / $boot3 /i) {
my @beer = split('\001VERSION ',$message,2);
my @beer2 = split('\001',$beer[1],2);
push @stealversion2,($beer2[0]);
my $time = time;
$getverinfo[1] = $time + 6;
return 0;
}
}
}


#### speak kick
if ($chanster =~ /#.+/) {
if (@speakkick > 0) {
foreach $boos (@speakkick) {
@wee = split(';;;',$boos);
$grte = 0;
$hostname =~ /(.*)\@(.*)/i;
$atest4 = stripn("$mynick,,,$server,,,$chanster,,,,,,$1,,,$2,,,");
if ($atest4 =~ /$wee[2].*/i) {
$boogsta = $wee[1];
$grte = 1;
}
if ($grte == 1) {
#IRC::command "/kick $dude \002Shh!!  I told you NOT to SPEAK!\002";
push @kick, ("$dude \002Shh!!  I told you NOT to SPEAK!\002\002");

chanaction("$mynick,,,$chanster,,,$server");
sl(1,"\002Kicking $dude for speaking\002");
}
}
}
}









#### ignorelist check

foreach $test (@ignorelist) {
@woothing = split(' ',$test);
$rest = $woothing[4];
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
$rest2 = quotemeta $rest;
if (" $tryit " =~ / $rest2 /i) {
if ($woothing[3] =~ /1/) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}
}

### ignore s users routing
if (!(" $mynick " =~ / $boot3 /i)) {
if ($isfriend =~ /1/) {
if ($flags =~ /s/) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}
}
###

if ($soundson == 1) {
if ($noticesound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$noticesound &";
}
}

###
# flood protection
$invsr = 0;

if ($isfriend =~ /1/) {
if ($flags =~ /i|p|f/i) {
$invsr = 1;
}
}

if ($isfloodon =~ /1/) {
$timing = time;
# mass flood prot.
@floodmassnumber = split (':',$floodmassnum);
$overtimemass = $timing - $floodmassnumber[1];
$wowsman = 0;
foreach $little (@floodcheck) {
$little =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$settype = $4;
$blooo = $3;
if ($overtimemass < $blooo) {
if ($settype =~ /2/) {
$wowsman++;
}
}
}
if ($wowsman > $floodmassnumber[0]) {
if ($ignoreall == 0) {
$timetohappen = $timing + 120;
push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/ignoreall off");
sl(1,"\002MASS FLOOD ..\002");
ignoreall("ON");

}
}

# normal flood prot.
@floodmsgnumber = split (':',$floodmsgnum);
@floodchannumber = split (':',$floodchannum);
@floodctcpnumber = split (':',$floodctcpnum);
@floodnotinumber = split (':',$floodnotinum);

@newvars = @nothingatall;
$overtime1 = $timing - $floodmsgnumber[1];
$overtime2 = $timing - $floodchannumber[1];
$overtime3 = $timing - $floodctcpnumber[1];
$overtime4 = $timing - $floodnotinumber[1];

foreach $little (@floodcheck) {
@boosta = split(';;;',$little);
$settype = $boosta[3];
$blooo = $boosta[2];

if ($settype == 3) {
if ($overtime4 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 2) {
if ($overtime3 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 1) {
if ($overtime2 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 0) {
if ($overtime1 > $blooo) {
} else {
push @newvars, ($little);
}
} else {
push @newvars, ($little);
}

}
@floodcheck = @newvars;

if ($chanster =~ /\#/) {
$type = 1;
$endbit = $chanster;
} else {
$type = 3;
$endbit = "blank";
}

if ($invsr =~ /0/) {
push @floodcheck, ($dude.";;;".$hostname.";;;".$timing.";;;".$type.";;;".$endbit);
@floodnums = "start;;;start;;;start;;;start;;;start";
foreach $blah (@floodcheck) {
$blah =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$4.";;;".$5.";;;1";
$fgret = $addline;
@floodnums2 = @nothing;
foreach $hhh (@floodnums) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$gret = quotemeta $1.";;;".$2.";;;".$3.";;;".$4.";;;";
$newcounter = $5;
if ($newcounter =~ /^\d+$/) {$newcounter = $newcounter + 1;}
if ($fgret =~ /$gret.*/) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$3.";;;".$4.";;;".$newcounter;
}
push @floodnums2, ($addline);
}
@floodnums = @floodnums2;
}




foreach $newt (@floodnums) {
$newt =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$typer = $3;
$countitnow = $5;
$chanfrom = $4;
$nicker = $1;
if ($countitnow > $floodchannumber[0] && $typer == 1) {
#IRC::command "/kick $nicker FLOOD";   
push @kick, ("$nicker FLOOD");
chanaction("$mynick,,,$chanster,,,$server");

sl(1,"\002Channel FLOOD from $nicker, kicking!\002");
}
if ($countitnow >= $floodnotinumber[0] && $typer == 3) {
$banmask = banmask($from);
my $checker2 = quotemeta $banmask;
my @df = IRC::ignore_list;
my @f = split(':',"@df");
foreach $t (@f) {
my @aww = split(' ',$t);
if (" $aww[0] " =~ / $checker2 /) {
$ignorechecks = 1;
}
}

#
##ignore("$banmask noti");
#


if ($ignorechecks == 0) {

IRC::command "/ignore $banmask ctcp priv noti invi NOSAVE QUIET";
$timetohappen = time;
$timetohappen = $timetohappen + $ignoretimeout;
#
#push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/setignore del $banmask");
#
push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/unignore $banmask");
sl(1,"\002FLOOD from $nicker, adding to ignore list!\002");
return 1;
}
}
}
}
}
#######

## channel log
if ($channellog[0] ne "0") {
$outs1 = "$channellog[0]$channellog[1]";
$outs2 = quotemeta "$chanster$server";
if (" $outs1 " =~ / $outs2 /i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "-$dude- $message\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
@channellog = @nothing;
}
}
}
##

## away log
if (!(" $mynick " =~ / $boot3 /i)) {
if ($isaway =~ /1/) {
if ($logon =~ /1/) {
if (!($message =~ /.*\001.*/)) {
if (" $mynick " =~ / $boot1 /i) {
my $newtime = time;
my $because = ($newtime - $awaytime);
$because = doit($because);
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
unshift @rawout,("$server /raw notice $dude :I've been away for $because, your message has been logged."); 
if (open(MSGLIST, ">>".$homepath.".xdcc/msglist")) {
print MSGLIST ("$month/$monthday ::: $hour:$min ::: $from ::: $message\n");
close (MSGLIST);
output("Logging message -> \002$dude : $message\002");
if ($lognowin =~ /1/) {return 1;}
return 0;
}
}
}
}
}
}
## wordkick
if (!($invsr == 1)) {
$checka = $message;
foreach $checkwords (@wordkick) {
@checkwordk = split(/\s/,$checkwords,2);
$checkb = quotemeta $checkwordk[1];
if ($checka =~ /$checkb/i) {
if ($checkwordk[0] =~ /kick/i) {
#IRC::command "/kick $dude \002WORDKICK\002";
push @kick, ("$dude \002WORDKICK\002");
chanaction("$mynick,,,$chanster,,,$server");
return 0;
} 
if ($checkwordk[0] =~ /ban/i) {
$banmask = banmask($from);
#IRC::command "/raw mode $chanster -o+b $dude $banmask";
#IRC::command "/kick $dude \002WORDBAN\002";
push @mode, ("-o $dude","+b $banmask");
push @kick, ("$dude \002WORDKICK\002");
chanaction("$mynick,,,$chanster,,,$server");
return 0;
} 
}
}
}
}


#############################


sub privmsg_handler 
{
$line = shift(@_);
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);
@woona = split(' PRIVMSG ',$line);
$line = shift(@woona);
if (!($line =~ /\@/)) {
return 0;
}
@hrms = split(':',$line,3);
shift(@hrms);
$from = "@hrms";
@hrms = split('!',"@hrms",2);
$dude = $hrms[0];
$hostname = $hrms[1];

$line2 = "@woona";
@woona = split(' :',$line2);
$part3 = shift(@woona);
$boot1 = quotemeta $part3;
$message = "@woona";
$chanster = $part3;
$schan = quotemeta $chanster;
my $ignorechecks = 0;
$isaway = 0;
foreach $booser (@awaylist) {
my $rr = quotemeta $booser;
if ($server =~ /$rr/i) {
$isaway = 1;
last;
}
}

$isfriend = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
@more = split(';;;',$5);

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/starmatch/g;
$rest =~ s/\?/questionmark/g;
$rest2 = quotemeta $rest;
$rest2 =~ s/starmatch/\.\*/go;
$rest2 =~ s/questionmark/\./go;
if (" $from " =~ / $rest2 /i) {
## ok, is on friendlist, get flags
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}
$isfriend = 1;
$newflags = $flags;
$newnick = $nick;
last;
}
}
}
if ($isfriend =~ /1/) {
$flags = $newflags;
$nick = $newnick;
} else {
$flags = $nothingatall;
$nick = $nothingeither;
}
### ignore all privmsgs, ctcp, etc, from everyone but +f users

$notchanmsg = 1;
if ($chanster =~ /#.+/) {
$notchanmsg = 0;
if ("  $message" =~ /  \001/i) {
$notchanmsg = 1;
} 
}

if ($ignoreall =~ /1/) {
if ($flags =~ /f/) {
} elsif ($notchanmsg == 1) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$month = $month + 1;
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}

#### speak kick
if ($chanster =~ /#.+/) {
if ("@speakkick" =~ /\S+/) {
foreach $boos (@speakkick) {
@wee = split(';;;',$boos);
$grte = 0;
$hostname =~ /(.*)\@(.*)/i;
$atest4 = stripn("$mynick,,,$server,,,$chanster,,,,,,$1,,,$2,,,");
if ($atest4 =~ /$wee[2].*/i) {
$boogsta = $wee[1];
$grte = 1;
}
if ($grte == 1) {
#IRC::command "/kick $dude \002Shh!!  I told you NOT to SPEAK!\002";
push @kick, ("$dude \002Shh!!  I told you NOT to SPEAK!\002");
chanaction("$mynick,,,$chanster,,,$server");
sl(1,"\002Kicking $dude for speaking\002");
}
}
}
}


#### ignorelist check
$channelmatch = 0;
$ctcpmatch = 0;
$privmsgs = 0;
if ($chanster =~ /\#/) {
$channelmatch = 1;
} else {
$privmsgs = 1;
}
if ("  $message" =~ /  \001/i) {
$ctcpmatch = 1;
} 

foreach $test (@ignorelist) {
@woothing = split(' ',$test);
$rest = $woothing[4];
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

$rest2 = quotemeta $rest;
if ($from =~ / $rest2 /i) {
if ((($woothing[0] == 1) && ($privmsgs == 1)) || (($woothing[1] == 1) && ($channelmatch == 1)) || (($woothing[2] == 1) && ($ctcpmatch == 1))) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$month = $month + 1;
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}
}


### ignore s users routing
if ($isfriend =~ /1/) {
if ($flags =~ /s/) {
if ($ignorelog =~ /1/) {
if (open(CHANLOG2, ">>".$homepath."/.xdcc/ignore.log")) {
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$month = $month + 1;
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
print CHANLOG2 "[$month/$monthday]$hour:$min($from) $message\n";
close(CHANLOG2);
} else {
output("Warning, couldn't open $homepath".".xdcc/ignore.log for some reason!");
output("Turning ignore logging off!");
$ignorelog = 0;
}
}
return 1;
}
}
###
# flood protection
$invsr = 0;

if ($isfriend =~ /1/) {
if ($flags =~ /i|f|p/i) {
$invsr = 1;
}
}

if ($isfloodon =~ /1/) {
$timing = time;
# mass flood prot.
@floodmassnumber = split (':',$floodmassnum);
$overtimemass = $timing - $floodmassnumber[1];
$wowsman = 0;
foreach $little (@floodcheck) {
$little =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$settype = $4;
$blooo = $3;
if ($overtimemass < $blooo) {
if ($settype =~ /2/) {
$wowsman++;
}
}
}
if ($wowsman > $floodmassnumber[0]) {
if ($ignoreall == 0) {
my $timetohappen = $timing + $ignoretimeout;

push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/ignoreall off");
sl(1,"\002MASS FLOOD ..\002");
ignoreall("ON");
}
}

# normal flood prot.
@floodmsgnumber = split (':',$floodmsgnum);
@floodchannumber = split (':',$floodchannum);
@floodctcpnumber = split (':',$floodctcpnum);
@floodnotinumber = split (':',$floodnotinum);

@newvars = @nothingatall;
$overtime1 = $timing - $floodmsgnumber[1];
$overtime2 = $timing - $floodchannumber[1];
$overtime3 = $timing - $floodctcpnumber[1];
$overtime4 = $timing - $floodnotinumber[1];
foreach $little (@floodcheck) {
$little =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$settype = $4;
$blooo = $3;
if ($settype == 3) {
if ($overtime4 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 2) {
if ($overtime3 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 1) {
if ($overtime2 > $blooo) {
} else {
push @newvars, ($little);
}
} elsif ($settype == 0) {
if ($overtime1 > $blooo) {
} else {
push @newvars, ($little);
}
} else {
push @newvars, ($little);
} 


}
@floodcheck = @newvars;

if ($ctcpmatch =~ /1/) {
$type = 2;
$endbit = "blank";
} elsif ($channelmatch =~ /1/) {
$type = 1;
$endbit = $chanster;
} else {
$type = 0;
$endbit = "blank";
}

if ($invsr =~ /0/) {
push @floodcheck, ($dude.";;;".$hostname.";;;".$timing.";;;".$type.";;;".$endbit);
@floodnums = "start;;;start;;;start;;;start;;;start";
foreach $blah (@floodcheck) {
$blah =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$4.";;;".$5.";;;1";
$fgret = $addline;
@floodnums2 = @nothing;
foreach $hhh (@floodnums) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$gret = quotemeta $1.";;;".$2.";;;".$3.";;;".$4.";;;";
$newcounter = $5;
if ($newcounter =~ /^\d+$/) {$newcounter = $newcounter + 1;}
if ($fgret =~ /$gret.*/) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$3.";;;".$4.";;;".$newcounter;
}
push @floodnums2, ($addline);
}
@floodnums = @floodnums2;
}




foreach $newt (@floodnums) {
$newt =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$typer = $3;
$countitnow = $5;
$chanfrom = $4;
$nicker = $1;
if ($countitnow > $floodchannumber[0] && $typer == 1) {
#IRC::command "/kick $nicker FLOOD";   
push @kick, ("$nicker FLOOD");
chanaction("$mynick,,,$chanster,,,$server");
sl(1,"\002Channel FLOOD from $nicker, kicking!\002");
}
if ($countitnow > $floodmsgnumber[0] && $typer == 2) {
$banmask = banmask($from);
my $checker2 = quotemeta $banmask;
my @df = IRC::ignore_list;
my @f = split(':',"@df");
foreach $t (@f) {
my @aww = split(' ',$t);
if (" $aww[0] " =~ / $checker2 /) {
$ignorechecks = 1;
last;
}
}

#
#ignore("$banmask ctcp");
#
if ($ignorechecks == 0) {
IRC::command "/ignore $banmask ctcp priv noti invi NOSAVE QUIET";
$timetohappen = time;
$timetohappen = $timetohappen + $ignoretimeout;
#
#push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/setignore del $banmask");
#
push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/unignore $banmask");
sl(2,"\002FLOOD from $nicker, adding to ignore list!\002");
return 1;
}
}
if ($countitnow > $floodmsgnumber[0] && $typer == 0) {
$banmask = banmask($from);
my $checker2 = quotemeta $banmask;
my @df = IRC::ignore_list;
my @f = split(':',"@df");
foreach $t (@f) {
my @aww = split(' ',$t);
if (" $aww[0] " =~ / $checker2 /) {
$ignorechecks = 1;
last;
}
}
if ($ignorechecks == 0) {
#
#ignore("$banmask priv");
#
IRC::command "/ignore $banmask ctcp priv noti invi NOSAVE QUIET";
$timetohappen = time;
$timetohappen = $timetohappen + $ignoretimeout;
#
#push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/setignore del $banmask");
#
push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/unignore $banmask");
sl(2,"\002FLOOD from $nicker, adding to ignore list!\002");
return 1;
}
}
}
}
}
#######
## wordkick
if (!($invsr == 1)) {
$checka = " $message ";
#$checka =~ s/\*+/\:/g;
#$checka =~ s/\?+/\;/g;
foreach $checkwords (@wordkick) {
@checkwordk = split(/\s/,$checkwords,2);
$checkb = quotemeta "$checkwordk[1]";
if ($checka =~ /$checkb/i) {
if ($checkwordk[0] =~ /kick/i) {
#IRC::command "/kick $dude \002WORDKICK\002";
push @kick, ("$dude \002WORDKICK\002");
chanaction("$mynick,,,$chanster,,,$server");
return 0;
} 
if ($checkwordk[0] =~ /ban/i) {
$banmask = banmask($from);
#IRC::command "/raw mode $chanster -o+b $dude $banmask";
#IRC::command "/kick $dude \002WORDBAN\002";
push @mode, ("-o $dude","+b $banmask");
push @kick, ("$dude \002WORDKICK\002");
chanaction("$mynick,,,$chanster,,,$server");
return 0;
} 
}
}
}

##### boogie seen 

if ($seenliston == 1) { 
@testers = split(' ',$message,2);  
if (" $testers[0] " =~ / !seen /i) { 


if (!($seenlistchans =~ /\S+/)) { 
$tty = 1;  
} else { 
@ggy = split(' ',$seenlistchans);  
$tty = 0; 
foreach $hr (@ggy) {
if (" $hr " =~ / $schan /i) { 
$tty = 1;  
} 
} 
} 

if ($tty == 1) { 
my $humm = length($testers[1]);  
my @fixit = split(' ',$testers[1],2);
if ($fixit[1] =~ /\S+/) {$humm = $nicklength + 1;}
if ($humm < $nicklength) { 
seen_output("$fixit[0] 1 $chanster $dude $server"); 
} else { 
if ($invsr == 1) { 
unshift @rawout,("$server /raw PRIVMSG $chanster :$dude is lame!"); 
output("$hl<<$dude>>\003 $dude is lame!"); 
} else { 
push @kick,("$dude Lame!"); 
sl(1,"\002Kicking $dude on $chanster for lame !seen request\002");
chanaction("$mynick,,,$chanster,,,$server"); 
} 
} 
} 
}
}

## channel log
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
$outs2 = "$chanster$server";
if ($outs2 =~ /$outs1/i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "($dude) $message\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
##
if ($message =~ /\001DCC/) {
if ($soundson == 1) {
if ($dccsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$dccsound &";
}
}
}

# look for dcc send message
$westthink = 0;
if ($isfriend =~ /1/) {
if ($message =~ /\001DCC SEND/) {
if ($flags =~ /f/i) {
if ($fautogetdcc =~ /1/) {
sl(3,"\002Attempting auto dcc receive from friend $nick\002");
@ohboy = split(/ SEND /i,$message,2);
@ohboy2 = split(' ',$ohboy[1]);
$server = IRC::get_info(3);
push @dccdude, ("$dude $server $ohboy2[0]");
return 0;
}
}
}
}


# look for page message
if ($message =~ /\001page.+/i) {
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
my $isitok = 0;
if (!($okpagetimes =~ /\S+/)) {
$isitok = 1;
}
my @okpage = split(';',$okpagetimes);
foreach $cool (@okpage) {
my @doh = split(' ',$cool);
if ($doh[0] < "$hour$min") {
if ($doh[1] > "$hour$min") {
$isitok = 1;
}
}
}

if ($isitok == 0) {
if ($message =~ /\001page\001/i) {
output("\002$dude is trying to page outside of set times.\002");
} else {
$message =~ /\001\S+ (.+)\001/;
output("\002$dude is trying to page outside of set times.\002");
output("\002message :\"$hl"."$1\003\"\002");
}
push @rawout,("$server /raw notice $dude :Sorry, paging is off at this time of day.\002");
} else {
if ($pageon =~ /1/) {
if ($message =~ /\001page\001/i) {
output("\002You are being paged by $dude\002");
} else {
$message =~ /\001\S+ (.+)\001/;
output("\002$dude is paging you \"$hl"."$1\003\"\002");
}

push @rawout,("$server /raw notice $dude :Paging....\002");
system $pagecommand." ".$homepath.".xdcc/page.wav &";
return 1;
}

if ($pageon =~ /2/) {
if ($isfriend =~ /1/) {
if ($flags =~ /f/i) {
if ($message =~ /\001page\001/i) {
output("\002You are being paged by $dude\002");
} else {
$message =~ /\001\S+ (.+)\001/;	
output("\002$dude is paging you \"$hl"."$1\003\"\002");
}
push @rawout,("$server /raw notice $dude :Paging....\002");
system $pagecommand." ".$homepath.".xdcc/page.wav &";
return 1;
} 
}
output("\002$dude tried to page you, but isn't a friend, ignoring.\002");
push @rawout,("$server /raw notice $dude :Paging is restricted to friends.\002");
return 1;
}

output("\002$dude tried to page you, but paging is off....\002");
push @rawout,("$server /raw notice $dude :Paging is off.\002");
return 1;
}
}
$nick = $dude;
$fromchan = $chanster;

$message =~ /(\S+) (.*)/;
$req = $2;
$com = $1;

$fromchan = "kk".$fromchan."kk";

$clock = time;




### xdcc stuff

if ($xdccon > 0) {
$checkup = 1;
if ($xdccon == 2) {
$checkup = 0;

if ($isfriend =~ /1/) {
if ($flags =~ /x/i) {
$checkup = 1;
} 
}
}


if ($checkup == 1) {
if ($message =~ /^\!list\b/i) {
  $slotnum = &slotcount;
  $openslots = $dccslots - $slotnum;
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }

sl(5,"\002Responding to !list from $nick\002");  
if ($mess =~ /\w/) {
  push @rawout,("$server /raw NOTICE $nick :$mess");
}
  push @rawout,("$server /raw NOTICE $nick :\002$packs Pack(s) / $totalmegsize Offered! / MaxCPS [\002$maxcps\002]\002");
  push @rawout,("$server /raw NOTICE $nick :\002\"\002/ctcp $mynick XDCC list\002\" for packlist / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged\002");
return 0;
}
}
}


$message =~ /(\S+) (.*)/;
$req = $2;
if ($1) {$com = $1;} else {$com = " ";}
if ($com =~ /\001xdcc/i) {

$checkup = 1;

if ($xdccon == 2) {
$checkup = 0;
#$nick5 = $nick;
#$rest5 = $rest;
if ($isfriend =~ /1/) {
if ($flags =~ /x/i) {
#output("\002This person has the x flag.\002");
$checkup = 1;
} 
}
}
if ($soundson == 1) {
if ($xdccsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$xdccsound &";
}
}






if ($xdccon > 0) {

 if ($req =~ /list/i) {
  $slotnum = &slotcount;
$openslots = $dccslots - $slotnum;
 if ($checkup =~ /1/) {
  if ($xdccflist == 0) {
  $blue = 0;
  push @rawout,("$server /raw NOTICE $nick :\002$packs Pack(s) / $totalmegsize Offered! / MaxCPS [\002$maxcps\002]\002");
        foreach $test (@xdcclist) {
        $test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
        $blue++;
       my $a = $1;
       my $b = $2;
       my $c = $3;
       my $d = $4;
       my $e = $5;
       my $f = $6;
      if ($xdccon == 3) {
       if ($f == 1) {
       if ($flags =~ /x/i) {
        push @rawout,("$server /raw NOTICE $nick :\002<\002$blue\002>\002 \002[\002$d\002:\002$c\002]\002 $b");
        } else {
        push @rawout,("$server /raw NOTICE $nick :\002<\002$blue\002>\002 \002[\002FRIENDS\002]\002");
        }       
        } else {
        push @rawout,("$server /raw NOTICE $nick :\002<\002$blue\002>\002 \002[\002$d\002:\002$c\002]\002 $b");
        }
        } else {
        push @rawout,("$server /raw NOTICE $nick :\002<\002$blue\002>\002 \002[\002$d\002:\002$c\002]\002 $b");
        }

    }
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }
  
  push @rawout,("$server /raw NOTICE $nick :\002/ctcp $mynick xdcc send #N for pack N / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged\002");
  sl(5,"\002Sending packlist to $nick...\002");
  return 1;
  } else {

       unless (open(XDCCFLIST, ">".$homepath.".xdcc/xdcclist.txt")) {
       output("Couldn't open output file xdcclist.txt!");
       return 1;
       }

     $blue = 0;
     print XDCCFLIST "$packs Pack(s) / $totalmegsize Offered! / MaxCPS [$maxcps]\n";
         foreach $test (@xdcclist) {
         $test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
         $blue++;
       my $a = $1;
       my $b = $2;
       my $c = $3;
       my $d = $4;
       my $e = $5;
       my $f = $6;
      if ($xdccon == 3) {
       if ($f == 1) {
       if ($flags =~ /x/i) {
         print XDCCFLIST "<$blue> [$d:$c] $b\n";
        } else {
         print XDCCFLIST "<$blue> [FRIENDS]\n";
        }
        } else {
         print XDCCFLIST "<$blue> [$d:$c] $b\n";
        }
        } else {
         print XDCCFLIST "<$blue> [$d:$c] $b\n";
        }

}
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }

  print XDCCFLIST "/ctcp $mynick xdcc send #N for pack N / [$openslots] $slotnotice free / $convsnagged Snagged\n";
  close (XDCCFLIST);
  sl(5,"\002Sending packtextfile to $nick...\002");
#  IRC::command "/dcc send $nick $homepath".".xdcc/xdcclist.txt";
  
  push @qpacks,($nick.":::".$homepath.".xdcc/xdcclist.txt:::".$timing.":::".$server);
  IRC::print "sfsdfsd @qpacks\n";
  return 1;
 }
} else {
output("\002$nick tried a packlist, telling him its friends only...\002");
push @rawout,("$server /raw NOTICE $nick :Packlist is restricted to friends only");
return 1;
}
}


$req =~ /(\S+?) (.*)/;
$req = $2;
if ($1 =~ /send/i) {
my $timing = time;
if ($checkup =~ /1/i) {
$server = IRC::get_info(3);
$blue = 0;


$req =~ /.*?(\d+).*?/;
$req = $1;


if ($req =~ /#/) {
$req =~ /#(.*) */;
$req = $1;
} 

foreach $test (@xdcclist) {
 $test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
       my $a = $1;
       my $b = $2;
       my $c = $3;
       my $d = $4;
       my $e = $5;
       my $f = $6;
         $blue++;
      if ($xdccon == 3) {
       if ($f == 1) {
 if ($blue == $req) {
       if ($flags =~ /x/i) {
 @sendthing = split(":::",$1);

  foreach $blahs (@sendthing) {
###
my $oa = check_dcc_get($nick,$blahs,$server); 
if ($oa == 0) {
  push @qpacks,($nick.":::".$blahs.":::".$timing.":::".$server);
}
###
} 
 output("\002$nick is requesting pack $blue\002");
###  $slotnum = slotcount;
###  if (@outpacks > ($dccslots - $slotnum)) {
###  push @rawout,("$server /raw NOTICE $nick :Placing some file(s) into queue.");
###  output("\002Queuing some files for $nick\002");
###}

 } else {

 output("\002$nick is attempting to get pack $blue, no access\002");
push @rawout,("$server /raw NOTICE $nick :You don't have access to pack $blue!!!");
}
return 1;
        }
        } else {
 if ($blue == $req) {
 @sendthing = split(":::",$1);

  foreach $blahs (@sendthing) {
###
my $oa = check_dcc_get($nick,$blahs,$server); 
if ($oa == 0) {
  push @qpacks,($nick.":::".$blahs.":::".$timing.":::".$server);
}
###
} 
 output("\002$nick is requesting pack $blue\002");
 return 1;
 }
        }
        } else {
 if ($blue == $req) {
 @sendthing = split(":::",$1);

  foreach $blahs (@sendthing) {
###
my $oa = check_dcc_get($nick,$blahs,$server); 
if ($oa == 0) {
  push @qpacks,($nick.":::".$blahs.":::".$timing.":::".$server);
}
###
} 
 output("\002$nick is requesting pack $blue\002");
#  $slotnum = slotcount;
#  if (@outpacks > ($dccslots - $slotnum)) {
#  push @rawout,("$server /raw NOTICE $nick :Placing some file(s) into queue.");
#  output("\002Queuing some files for $nick\002");
#}
 return 1;
 }
 }




}

} else {
output("\002$nick isn't on friends list, or doesn't have the x flag, explaining\002");
push @rawout,("$server /raw NOTICE $nick :Sorry, you aren't on my friendslist!");
return 1;
}
}

push @rawout,("$server /raw NOTICE $nick :There is no such pack!");
push @rawout,("$server /raw NOTICE $nick :Are you sure you used \"/ctcp $mynick XDCC send #N\"?");
output("\002$nick doesn't seem to know how to request packs, sending help...\002");
return 1;
} else {
push @rawout,("$server /raw NOTICE $nick :Sorry, XDCC is off!");
output("\002Told $nick that XDCC is off!\002");
return 1;
}

} 

if ($message =~ /\001/i) {
if ($soundson == 1) {
if ($ctcpsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$ctcpsound &";
}
}
}
if ($message =~ /\001version/i) {
IRC::print "its $versioning its 1\n";
if ($versioning == 1) {
IRC::print "2\n";
if ("@stealversion" =~ /\S+/) {
IRC::print "3\n";
my $because = int((rand @stealversion));
@wwwt = split("\<cr\>",$stealversion[$because]);
my $checkittime = time;
if (($laststealvertime + $stealvertime) > $checkittime) {
IRC::print "4\n";
@wwwt = @laststealver;
if ($stealverper == 1) {
IRC::print "5\n";
$laststealvertime = $checkittime;
}
} else {
IRC::print "6\n";
@laststealver = @wwwt;
$laststealvertime = $checkittime;
}


IRC::print "7\n";
foreach $wtf (@wwwt) {
IRC::print "8\n";
push @rawout,("$server /raw NOTICE $dude :\001VERSION $wtf\001");
output("\002$hl"."VERSION\003 from $dude ($hl"."replying with \"\003\002VERSION $wtf\002$hl\"\003)\002");
}
return 1;
} else {
unshift @rawout,("$server /raw NOTICE $dude :\001VERSION XDCC'n'STUFF 1.3.3 for X-Chat by Hymie: http://L8R.net/xchat\001");
output("\002Sending script version info to $dude\002");
}
}
}
if (!($message =~ /\001/)) {
if ($soundson == 1) {
if (!($chanster =~ /\#/)) {
if ($privmsgsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$privmsgsound &";
}
}
if ($chanster =~ /\#/) {
if ($chanmsgsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$chanmsgsound &";
}
}
}
}
## away log
if ($isaway =~ /1/) {
if ($logon =~ /1/) {
if (!($message =~ /.*\001.*/)) {
if (" $mynick " =~ / $boot1 /i) {
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);
$month = $month + 1;
$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
my $newtime = time;
my $because = ($newtime - $awaytime);
$because = doit($because);
unshift @rawout,("$server /raw notice $dude :I've been away for $because, your message has been logged."); 
if (open(MSGLIST, ">>".$homepath.".xdcc/msglist")) {
print MSGLIST ("$month/$monthday ::: $hour:$min ::: $from ::: $message\n");
close (MSGLIST);
output("Logging message -> \002$dude : $message\002");
if ($lognowin =~ /1/) {return 1;}
return 0;
}
}
}
}
return 0;
}



# add file desc
sub add_pack
{
$allnumfiles = 0;
$alltotalsize = 0;
  if (@_ == "") {
  output("Enter a filename/pattern and description!");
  return 1; 
  }
my $info = shift(@_);
  $info =~ /(\S+) (.*)/;
$patmatch = $1;
$desc = $2;
if ($1 =~ "") {
output("Use /addp <filename/pattern> <description> /FILES /PRIV");
return 1;
}
$privatepack = 0;
if ($desc =~ /\/PRIV/) {
$privatepack = 1;
$desc =~ s/\/PRIV//g;
}

unless (open(XDCCLIST, ">".$homepath.".xdcc/xdcclist")) {
output("Couldn't open output file .xdcclist!");
return 1;
}

##################

if (-d "$patmatch") {
$patmatch = $patmatch."/*"; 
}

if ($patmatch =~ /.*\*.*\*.*/) {
output("Pattern Matching Restricted to Single * !!");
return 1;
}
open (FIND, "ls -l -d $patmatch |");
$hrrr = $1;
$numfiles = 0;
$blueperson = 0;
$bluecount = 0;
$ttt = 0;
$yyy = 0;
@test = <FIND>;
close (FIND);
$files = ",,,,,,";
foreach $bloo (@test) {$ttt++;}
$desc2 = $desc;
@new = @test;


RIGHTHERE:if ($desc2 =~ /.*\/FILES.*/) {
$files = ",,,,,,";
$numfiles = 0;
$blueperson = 1;
$yyy = 1;
@test = $new[$bluecount];
$bluecount++;
if ($bluecount > $ttt) {
output("\002Added $allnumfiles pack(s), $alltotalsize bytes...\002");
foreach $test (@xdcclist) {
print XDCCLIST ("$test\n");
}
close(XDCCLIST);
close(FIND);
return 1;
}
}



@somedirs = @nothinghere;
foreach $bloo (@test) {

$bloo =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/;
$bloo = $9;
$size = $5;

if ($bloo =~ /.*\S.*/) {
if (-r "$bloo") {
if (!($bloo =~ /,,,/)) {
if (!($bloo =~ /:::/)) {
if (!(-d "$bloo")) {

if ($numfiles == 0) {
$files = $bloo;
$totalsize = $size;
} else {
$files = $files.":::".$bloo;
$totalsize = $totalsize + $size;
}
$numfiles++;
} else {
if ($desc2 =~ /.*\/FILES.*/) {
open (FIND, "ls -l -d $bloo/* |");
@somedirs = <FIND>;
close (FIND);
$ooo = 0;
foreach $bloofer (@somedirs) {$ooo++;}
push @new, @somedirs;
$ttt = $ttt + $ooo;
} else {
output("\002Directory $bloo Ignored!\002");
}

}
} else {
output("\002Filename $bloo has ::: in its name, Ignored!\002");
}
} else {
output("\002Filename $bloo has ,,, in its name, Ignored!\002");
}
} else {
output("\002$bloo not readable by you!\002");
}
} else {
output("Found the end");
last;
}
}



 
###################
if ($files =~ /,,,,,,/) {
if ($yyy =~ /0/) {
output("\002Sorry, couldn't find any acceptable files!\002");
return 1;
} else {
#output("\002Skipping file...\002");
goto RIGHTHERE;
}
}
if ($desc2 =~ /.*\/FILES.*/) {
$allnumfiles = $allnumfiles + $numfiles;
$alltotalsize = $alltotalsize + $totalsize;
} else {
output("\002Added $numfiles file(s), $totalsize bytes...\002");
}

$size = byte_converter($totalsize);

if ($yyy =~ /1/) {
@booger = split ('\/',$files);
@booger = reverse @booger;
if ($privatepack == 1) {
push @xdcclist, "$files,,,$booger[0],,,$size,,,$numfiles,,,$totalsize,,,1,,,,,,";
} else {
push @xdcclist, "$files,,,$booger[0],,,$size,,,$numfiles,,,$totalsize,,,0,,,,,,";
}
} else {
if ($privatepack == 1) {
push @xdcclist, "$files,,,$desc,,,$size,,,$numfiles,,,$totalsize,,,1,,,,,,";
} else {
push @xdcclist, "$files,,,$desc,,,$size,,,$numfiles,,,$totalsize,,,0,,,,,,";
}
}

$totaloffer = $totaloffer + $totalsize;

$totalmegsize = byte_converter($totaloffer);

#output("Added pack OK");
$packs++;
if ($yyy =~ /1/) {goto RIGHTHERE;}
foreach $test (@xdcclist) {
print XDCCLIST ("$test\n");
}
close(XDCCLIST);
close(FIND);
return 1;
}


# list packlist
sub list_pack
{
$blue = 0;
output(" ");
output("Current Packlist :");
output("\002$packs XDCC Pack(s) / $totalmegsize Offered!\002");
foreach $test (@xdcclist) {
$test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
$blue++;
if ($6 == 0) {
output("<$blue> [$4:$3] $2");
} else {
output("<$blue> [$4:$3] $2"."(".$hl."\002PRIVATE\002\003)");
}
}
output(" ");
return 1;
}


# plist packlist
sub plist_pack
{
if ($xdccon == 0) {
$xdccon = 1;
output("\n\002XDCC was off, turning it on...\002");
}

my $mynick = IRC::get_info(1);
my $channel = IRC::get_info(2);
my $server = IRC::get_info(3);
my $info = shift(@_);

if ($info =~ /\w+/) {
my $channel = $info;
}
$slotnum = &slotcount;
$openslots = $dccslots - $slotnum;

if ($xdccpublistmethod == 1) {
$chanoutputthing = "PRIVMSG";
} else {
$chanoutputthing = "NOTICE";
}

$blue = 0;
if ($xdccon == 3) {
output("\002$packs Pack(s) / $totalmegsize Offered!\002 / SECURITY [\002PACKS\002] / MaxCPS [\002$maxcps\002]");
push @rawout,("$server /raw $chanoutputthing $channel :\002$packs Pack(s) / $totalmegsize Offered!\002 / SECURITY [\002PACKS\002] / MaxCPS [\002$maxcps\002]");
} elsif ($xdccon == 2) {
output("\002$packs Pack(s) / $totalmegsize Offered!\002 / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002]");
push @rawout,("$server /raw $chanoutputthing $channel :\002$packs Pack(s) / $totalmegsize Offered!\002 / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002]");
} else {
output("\002$packs Pack(s) / $totalmegsize Offered!\002 /SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002]");
push @rawout,("$server /raw $chanoutputthing $channel :\002$packs Pack(s) / $totalmegsize Offered! / SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002]\002");
}
foreach $test (@xdcclist) {
$test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
$blue++;
my $a = $2;
my $b = $3;
my $c = $4;
my $d = $6;
if ($xdccon == 3) {
if ($d == 1) {
if ($dapacks == 1) {
push @rawout,("$server /raw $chanoutputthing $channel :\002<\002$blue\002>\002 \002[\002$c\002:\002$b\002]\002 $a \002<FRIENDS>\002");
output("\002<\002$blue\002>\002 \002[\002$c\002:\002$b\002]\002 $a \002[$hl"."FRIENDS\003]\002");
} else {
push @rawout,("$server /raw $chanoutputthing $channel :\002<\002$blue\002>\002 \002[\002FRIENDS ONLY\002]\002");
output("\002<\002$blue\002>\002 \002[\002$c\002:\002$b\002]\002 $a \002[$hl"."FRIENDS\003]$hl\(hidden\)\003\002");
}

next;
}
}
push @rawout,("$server /raw $chanoutputthing $channel :\002<\002$blue\002>\002 \002[\002$c\002:\002$b\002]\002 $a");
output("\002<\002$blue\002>\002 \002[\002$c\002:\002$b\002]\002 $a");
}
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }

output("\002/ctcp $mynick XDCC send #N for pack N\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged");
push @rawout,("$server /raw $chanoutputthing $channel :\002/ctcp $mynick xdcc send #N for pack N\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged");
return 1;
}


# del pack from packlist
sub del_pack
{
$packs=0;
$blue=0;
$t=0;
@holdin="";
pop(@holdin);
unless (open(XDCCLIST, ">".$homepath.".xdcc/xdcclist")) {
output("Couldn't open output file .xdcclist!");
return 1;
}
$rrr = shift(@_);

if ($rrr =~ /all/i) {
$totalmegsize = 0;
$totaloffer = 0;
output("\002Deleting packlist\002");
@xdcclist = @nofieldshereman;
close (XDCCLIST);
return 1;
}

foreach $test (@xdcclist) {
$blue++;
if ($rrr != $blue) {
print XDCCLIST ("$test\n");
push @holdin, $test;
$packs++;
} else {
$t = 1;
$test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
$totaloffer = $totaloffer - $5;
###

$totalmegsize = byte_converter($totaloffer);

}
}
@xdcclist = @holdin;
close(XDCCLIST);

if ($t == 0) {
output("\002No pack deleted!\002");
} else {
output("\002Pack <$rrr> deleted!\002");
}
return 1;
}




# amsgtimer...
sub amsg 
{
$info = shift(@_);
$info =~ /(.+) (\d+) (.+)/;
@newinfo = split(' ', $info);
$fretchan = $newinfo[0];
$checkit = ";$newinfo[0];";
$soonamsgtime = $newinfo[1];
$messy = $3;
my $server = IRC::get_info(3);
my $mynick = IRC::get_info(1);

if ($checkit =~ /;clear;/i) {
output("\002Clearing auto message list\002");
@amsglist = @nothinginhere;
$amsgon = 0;
return 1;
}
if (!($soonamsgtime =~ /\d+/)) {
output("\002Use /amsg <channel/all> <time> <message> or /amsg clear\002");
return 1;
}
if (!($messy =~ /\S+/)) {
output("\002Use /amsg <channel/all> <time> <message> or /amsg clear\002");
return 1;
}

if ($checkit =~ /;all;/i) {
@amsglist = @nothinginhere;
push @amsglist, ".all. .all. $messy";
$amsgon = 1;
$amsgwaittime = $soonamsgtime * 60;
$clock = time;
$amsgtime = $clock + $amsgwaittime;
output("\002all channels->\002$messy");
########
@test = IRC::channel_list;

$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);

if ($xdccpublistmethod == 1) {
$chanoutputthing = "PRIVMSG";
} else {
$chanoutputthing = "NOTICE";
}

foreach $boot2 (@wow) {
@manofchan = split (' ',$boot2);
IRC::command_with_server("/raw $chanoutputthing $manofchan[0] :$messy",$manofchan[1]);
}
return 1;
}


if (!($fretchan =~ /\#.+/)) {
output("\002Use /amsg <channel/all> <time> <message> or /amsg clear\002");
return 1;
}


push @amsglist, "$fretchan $server $messy";
$amsgon = 1;
$amsgwaittime = $soonamsgtime * 60;
$clock = time;
$amsgtime = $clock + $amsgwaittime;
IRC::send_raw "$chanoutputthing $fretchan :$messy\n";
output("$fretchan->$messy");
return 1;
}




#xdcc notify timer...
sub noti 
{
my $channel = IRC::get_info(2);
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);
$rrr = shift(@_);
$rrr =~ /(\d*) (.*)/;
$wait = $1;
$mess = $2;
if ($1 == "") {
$rrr =~ /(\d*)/;
$wait = $1; 
} 

if ($rrr =~ /.*off.*/i) {
output("\002Turning XDCC Notification off...\002");
$xdccstat = 0;
return 1;
}

unless ($wait == "") {
$waittime = $wait * 60;
$clock = time;
@gotime = $clock;
$xdccstat = 1;
output("Setting XDCC Notice to $wait minute(s) for all channels.");
if ($xdccon == 0) {
output("\002Note : XDCC was off, turning it on...\002");
$xdccon = 1;
}
} else {
$slotnum = &slotcount;
$openslots = $dccslots - $slotnum;

if ($xdccpublistmethod == 1) {
$chanoutputthing = "PRIVMSG";
} else {
$chanoutputthing = "NOTICE";
}

if ($xdccon == 2) {
push @rawout,("$server /raw $chanoutputthing $channel :\002$packs\002 Pack(s) / $totalmegsize Offered! / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002]");
output("\002$packs\002 Packs / $totalmegsize Offered! / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002]");
} else {
push @rawout,("$server /raw $chanoutputthing $channel :\002$packs\002 Pack(s) / $totalmegsize Offered! / SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002]");
output("\002$packs\002 Packs / $totalmegsize Offered! / SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002]");
}
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }

push @rawout,("$server /raw $chanoutputthing $channel :\002\"/\002ctcp $mynick XDCC list\002\" for packlist\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged");
output("\002\"\002/ctcp $mynick XDCC list\002\" for packlist\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged");
}
return 1;
}


#xdcc mode change...
sub mode_change 
{
$line = shift(@_);
@aroundhere = split(' ',$line);
$line = shift(@aroundhere);
shift(@aroundhere);

@hrms = split(':',$line,3);
shift(@hrms);
$user = "@hrms";
@hrms = split('!',"@hrms",2);
my $anick = $hrms[0];
my $usermaybe = $hrms[1];

#$line =~ /:(.*)!(.*)\@(.*)/;
my $chan = shift(@aroundhere);

my $mode = shift(@aroundhere);
my $victim = "@aroundhere";
my $prt = 0;
my $mynick = IRC::get_info(1);
my @totalaction = @nothinghereman;
my $server = IRC::get_info(3);

my $victimnick;
my $victimun;
my $victimhost;
my $nolongerop = 0;


my $schan = quotemeta $chan;
my $testanick = quotemeta $anick;
 

if ($soundson == 1) {
if ($modesound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$modesound &";
}
}
### logging
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
if (" $chanster$server " =~ / $outs1 /i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "($user) MODE $mode $victim\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
####


#if (!($user =~ /\@/)) {
#$user = "serveraction!serveraction@".$user;
#}	
# new

$banmask = banmask($user);
#IRC::print "$banmask is it\n";

@stuffdone = split (' ',$victim);
@tinkering = split ('',$mode);
@modegroup = @nothingherevar;
foreach $worker (@tinkering) {
if ($worker =~ /\+|\-/) {
$mc = $worker;
} else {
push @modegroup, "$mc$worker";
}
}
@tinkering = @nothingheretosee;
foreach $worker (@modegroup) {
$oggq = shift @stuffdone;
if ($oggq) {
push @tinkering, "$worker ". $oggq;  
} else {
push @tinkering, "$worker ";
}
}



foreach $worker (@tinkering) {

$tracker = 0;
$worker =~ /(.*) (.*)/;
my $mode = $1;
my $victim = $2;

my $compare2 = quotemeta $victim;

if (" $mynick " =~ / $compare2 /i) {
if ($mode =~ /\+o/) {
push @scanchan,($chan);
push @scanserver,($server);
IRC::add_timeout_handler(100,"scanchan");
next;
}
if ($mode =~ /\-o/) {
$nolongerop = 1;
}
}

@victimarray = @nothing;
if (!($victim =~ /\@/)) {
my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
if (" $lister[0] " =~ / $compare2 /i) {
#IRC::print "bingo! $compare and $compare2\n";
my @hrmsa = split('\@',"$lister[1]",2);
push @victimarray, ("$lister[0]!$lister[1]");
#last;
}
}
} else {

my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");
foreach my $g (@boo) {
my @lister = split(' ',$g);
my @lister2 = split('!',$victim);
my $comparea = stripn("$lister[0]");
my $compare = stripn("$lister[1]");
my $compare2a = stripn($lister2[0]);
my $compare2 = stripn($lister2[1]);
$compare2 =~ s/\*/`/g;
$compare2 =~ s/\?/\./g;
$compare2 =~ s/`/\.\*/go;
$compare2a =~ s/\*/`/g;
$compare2a =~ s/\?/\./g;
$compare2a =~ s/`/\.\*/go;

if (" $comparea;$compare " =~ / $compare2a;$compare2 /i) {
#IRC::print "bingo! $comparea;$compare  =~ / $compare2a;$compare2\n";
my @hrmsa = split('\@',"$lister[1]",2); 
push @victimarray, ("$lister[0]!$lister[1]");
}
}
}

foreach $okmatching (@victimarray) {
my @workin = split("!",$okmatching);
my @workin2 = split("\@",$workin[1]);
$victimnick = $workin[0];
$victimun = $workin2[0];
$victimhost = $workin2[1]; 
#IRC::print "Matched $victim as $victimnick with a username of $victimun and $victimhost\n";





$invs = 0;
$prt = 0;
$invsr = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}

}

##########################


@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

if ($user =~ /$rest/i) {
if ($flags =~ /i/i) {
$invs = 1;
$invsr = 1;
}
if ($flags =~ /p/i) {
$prt = 1;
$invsr = 1;
}
}
}
}
### flood prot.
if ($isfloodon =~ /1/) {
if ($invs =~ /0/) {
if ($prt =~ /0/) {
$timing = time;
#$user =~ /(.*)!(.*)/;
push @floodcheck, ($anick.";;;".$usermaybe.";;;".$timing.";;;4;;;".$chan);
}
}
}




if (" $mynick " =~ / $testanick /i) {
next;
}

#######################################
if ($mode =~ /\+b/) {
$bah = $wowwhataride;

###########################################
$hostnm = "$victimnick!$victimun\@$victimhost";

my $boo = stripn($victim);

if (" $victim " =~ / $testanick /i) {
output("This user did this to himself");
next;
}


foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}


@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

if ($hostnm =~ /$rest/i) {
if ($flags =~ /p/i) {
if ($invs =~ /0/i) {
if ($flags =~ /p|i/i) {
push @totalaction, ("\002 0Ban protect $nick on $chan from $user\002");
@totalmodes = @nothinghere;
@totalmodes = @nothinghere;
push(@mode,"-b $victim");
$tracker = 1;
$revengetest = $revengeban;
if ($user =~ /\@/) {
if ($flags =~ /i/i) {
if (!($irevenge == 0)) {
$revengetest = $revengetest + $irevenge;
}
}
if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
}
}
if ($revengetest > 3) {$revengetest = 3;}
if ($revengetest < 0) {$revengetest = 0;}

if ($revengetest =~ /3/i) {
push(@mode,"-o $anick","+b $banmask");
push @totalaction, ("\002Ban protect $nick on $chan, adding $user to ban list\002");
## goobie!!

$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
my $lent = length($bootface);
if ($lent > 6) {
$cool = add_friend("baduser-$anick k $bootface $chan");
} else {
IRC::print "DOH!";
}

@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$anick BANNED $nick on $chan \($user\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment BANNED $nick on $chan \($user\) [$month/$monthday $hour:$min]"); 
}

if ($revengetest =~ /2/i) {
push(@mode,"-o $anick","+b $banmask");
push(@kick,"$anick");
push @totalaction, ("\002Ban protect $nick on $chan from $user\002");
}
if ($revengetest =~ /1/i) {
push(@kick,"$anick");
push @totalaction, ("\002Ban protect $nick on $chan from $user\002");
}
$tracker = 1;
last;
}
}
}
}
}
}
}
if ($tracker =~ /1/) {next;}
}



if ($mode =~ /\+b/) {

$banmask = $victim;
$banmask =~ /(.*)!(.*)\@(.*)/;
$a = "$1!$2\@";
$c = $3;
$a =~ s/\*!\*\@/\@/g;
$a =~ s/!\*\@/\@/g;
$a =~ s/\*!//g;
$banmask = "$a$c";

$banmask =~ s/\./;/g;
$banmask =~ s/\?/\./g;
$banmask =~ s/\*/\.\*/go;
$banmask2 = $banmask;
$banmask2 =~ s/\.\*//go;

foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\./;/g;
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/g;

$rest2 = $rest;

$rest2 =~ s/\.\*//go;


$rest555 = stripn($rest2);
$banmask555 = stripn($banmask);


if ($rest555 =~ /.*$banmask555.*/i) {
if ($flags =~ /p/i) {
if ($invs =~ /0/i) {
push @totalaction, ("\002Protecting $nick from ban $victim by $user on $chan\002");
push(@mode,"-b $victim");
last;
}
}
}
$rest555 = stripn($rest);
$banmask555 = stripn($banmask2);
if ($banmask555 =~ /.*$rest555.*/i) {
if ($flags =~ /p/i) {
if ($invs =~ /0/i) {
push @totalaction, ("\002$nick ban $victim on $chan by $user\002");
push(@mode,"-b $victim");
last;
}
}
}
}
}
next;
} 



if ($mode =~ /\-b/) {
$banmask = $victim;
$banmask =~ /(.*)!(.*)\@(.*)/;
$a = "$1!$2\@";
$c = $3;
$a =~ s/\*!\*\@/\@/g;
$a =~ s/!\*\@/\@/g;
$a =~ s/\*!//g;
$banmask = "$a$c";

$banmask =~ s/\./;/g;
$banmask =~ s/\?/\./g;
$banmask =~ s/\*/\.\*/go;
$banmask2 = $banmask;
$banmask2 =~ s/\.\*//go;

foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$danick = $1;
$flags = $2;
$rest2 = $3;
$thereason = $4;
@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}


@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\./;/g;
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/g;

$rest2 = $rest;

$rest2 =~ s/\.\*//go;


$t = 0;
if ($flags =~ /k/i) {
if ($invs =~ /0/i) {
if ($c =~ /\w+/) {
$rest555 = stripn($rest2);
$banmask555 = stripn($banmask);
if ($rest555 =~ /.*$banmask555.*/i) {
$t = 1;
} elsif ($banmask555 =~ /.*$rest555.*/i) {
$t = 1;
}
}
}
}
if ($t == 1) {
$revengetest = $revengeunbanak;
if ($forceban == 1) {
push @totalaction, ("\002$user unbanned k user $danick($victim) on $chan .. rebanning\002");
unshift @rawout,("$server /raw PRIVMSG $anick :$danick\($victim\) is on my permaban list $thereason!");
push(@mode,"+b $victim");
}
if ($user =~ /\@/) {
if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
if ($revengetest < 0) {$revengetest = 0;}
}
}
if ($revengetest =~ /3/i) {
push(@mode,"-o $anick","+b $banmask");
push @totalaction, ("\002PermBanning $user for unbanning a k user\002");
unshift @rawout,("$server /raw PRIVMSG $anick :$danick\($victim\) is on my permaban list $thereason! Now you are too!");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$anick k $bootface $chan");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$anick UNBANNED $victim on $chan \($user\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment UNBANNED $victim on $chan \($user\) [$month/$monthday $hour:$min]"); 
}

if ($revengetest =~ /2/i) {
push(@mode,"-o $anick","+b $banmask");
push(@kick,"$anick");
push @totalaction, ("\002KickBanning $user for unbanning a k user\002");
unshift @rawout,("$server /raw PRIVMSG $anick :$danick\($victim\) is on my permaban list $thereason!");
}
if ($revengetest =~ /1/i) {
push(@kick,"$anick");
push @totalaction, ("\002Kicking $user for unbanning a k user\002");
unshift @rawout,("$server /raw PRIVMSG $anick :$danick\($victim\) is on my permaban list $thereason!");
}
last;
}
}
}
}
next;
}

#

if ($victimhost) {
$hostnm = "$victimnick!$victimun\@$victimhost";
} else {
$hostnm = $victimnick;
}



foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

if ($hostnm =~ /$rest/i) {


# +o
if ($mode =~ /\+o/i) {


if (" $victim " =~ / $testanick /i) {
#output("This user did this to himself");
next;
}

if ($invs =~ /0/i) {
$revengetest = $revengeopadeop;
if ($flags =~ /d/i) {
if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
if ($revengetest < 0) {$revengetest = 0;}
}
}

if ($user =~ /\@/) {
if ($revengetest =~ /3/i) {
push(@mode,"-o $anick","+b $banmask");
push @totalaction, ("\002d flag $nick opped by $user on $chan, adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$anick k $bootface $chan");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$anick OPPED $nick (d flag) on $chan \($user\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment OPPED $nick (d flag) on $chan \($user\) [$month/$monthday $hour:$min]"); 
}
if ($revengetest =~ /2/i) {
push(@mode,"-o $anick","+b $banmask");
push(@kick,"$anick");
push @totalaction, ("\002$nick opped (d flag) by $user on $chan .. banning\002");
}
if ($revengetest =~ /1/i) {
push(@kick,"$anick");
push @totalaction, ("\002$nick opped (d flag) by $user on $chan .. kicking\002");
}
}
}
}
if ($flags =~ /d/i) {
if ($invs =~ /0/i) {
push(@mode,"-o $victim");
push @totalaction, ("\002Deopping $nick on $chan.. matched a d flag\002");
}
}
}



# +v
if ($mode =~ /\+v/i) {


if (" $victim " =~ / $testanick /i) {
#output("This user did this to himself");
next;
}

if ($invs =~ /0/i) {
$revengetest = $revengevoiceanovoice;
if ($flags =~ /q/i) {
if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
if ($revengetest < 0) {$revengetest = 0;}
}
}

if ($user =~ /\@/) {
if ($revengetest =~ /3/i) {
push(@mode,"-o $anick","+b $banmask");
push @totalaction, ("\002q flag $nick voiced by $user on $chan, adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$anick k $bootface $chan");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$anick VOICED $nick (q flag) on $chan \($user\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment VOICED $nick (q flag) on $chan \($user\) [$month/$monthday $hour:$min]"); 
}
if ($revengetest =~ /2/i) {
push(@mode,"-o $anick","+b $banmask");
push(@kick,"$anick");
push @totalaction, ("\002$nick voiced (q flag) by $user on $chan .. banning\002");
}
if ($revengetest =~ /1/i) {
push(@kick,"$anick");
push @totalaction, ("\002$nick voiced (q flag) by $user on $chan .. kicking\002");
}
}
}
}
if ($flags =~ /q/i) {
if ($invs =~ /0/i) {
push(@mode,"-v $victim");
push @totalaction, ("\002Devoicing $nick on $chan.. matched a q flag\002");
}
}
}



# -o
if ($mode =~ /\-o/i) {


if (" $victim " =~ / $testanick /i) {
#output("This user did this to himself");
next;
}

if ($invs =~ /0/i) {
$revengetest = $revengedeop;
if ($flags =~ /p|i/i) {
if ($flags =~ /i/i) {
if (!($irevenge == 0)) {
$revengetest = $revengetest + $irevenge;
}
}
if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
}
}
if ($user =~ /\@/) {
if ($revengetest > 3) {$revengetest = 3;}
if ($revengetest < 0) {$revengetest = 0;}

if ($revengetest =~ /3/i) {
push(@mode,"-o $anick","+b $banmask");
push @totalaction, ("\002$nick deopped by $user on $chan, adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$anick k $bootface $chan");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$anick DEOPPED $nick on $chan \($user\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment DEOPPED $nick on $chan \($user\) [$month/$monthday $hour:$min]"); 
}
if ($revengetest =~ /2/i) {
push(@mode,"-o $anick","+b $banmask");
push(@kick,"$anick");
push @totalaction, ("\002$nick deopped by $user on $chan .. banning\002");
}
if ($revengetest =~ /1/i) {
push(@kick,"$anick");
push @totalaction, ("\002$nick deopped by $user on $chan .. kicking\002");
}
}
}
}
if ($flags =~ /o/i) {
if (!(" $victim " =~ / $testanick /)) {
if ($invs =~ /0/i) {
push(@mode,"+o $victim");
push @totalaction, ("\002Reopping $nick on $chan because of $user\002");
}
}
}
}
last;
}
}
}
}
}

##########
# flood protection
$invsr = 0;

if (!($user =~ /\@/i)) {
$invsr = 1;
}

if ($isfloodon =~ /1/) {
@floodmodenumber = split (':',$floodmodenum);

$timing = time;
@newvars = @nothingatall;
$overtime5 = $timing - $floodmodenumber[1];
foreach $little (@floodcheck) {
$little =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$settype = $4;
$blooo = $3;
if ($settype == 4) {
if ($overtime4 > $blooo) {
} else {
push @newvars, ($little);
}
} else {
push @newvars, ($little);
}
}
@floodcheck = @newvars;


if ($invsr =~ /0/) {
@floodnums = "start;;;start;;;start;;;start;;;start";
foreach $blah (@floodcheck) {
$blah =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$4.";;;".$5.";;;1";
$fgret = $addline;
@floodnums2 = @nothing;
foreach $hhh (@floodnums) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$gret = quotemeta $1.";;;".$2.";;;".$3.";;;".$4.";;;";
$newcounter = $5;
if ($newcounter =~ /^\d+$/) {$newcounter = $newcounter + 1;}
if ($fgret =~ /$gret.*/) {
$hhh =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$addline = $1.";;;".$2.";;;".$3.";;;".$4.";;;".$newcounter;
}
push @floodnums2, ($addline);
}
@floodnums = @floodnums2;
}
$banmask = banmask($user);
#$user =~ /(.*)!(.*)/;
foreach $newt (@floodnums) {
$newt =~ /(.*);;;(.*);;;(.*);;;(.*);;;(.*)/;
$typer = $3;
$countitnow = $5;
$chanfrom = $4;
$nicker = $1;
$thehost = $2;
$checka = " ".$1.";;;".$2.";;;".$4." ";
$checkb = quotemeta " ".$anick.";;;".$usermaybe.";;;".$chan." ";
if ($checka =~ /$checkb/i) {
if ($countitnow >= $floodmodenumber[0] && $typer == 4) {

if ($revengemode =~ /3/i) {
push @mode,("-o $anick","+b $banmask");
sl(1,"\002Mass modechange by $user on $chan, banning and adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$anick k $bootface $chanfrom");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push @kick,("$anick MASS MODECHANGE on $chanfrom [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment MASS MODECHANGE on $chanfrom [$month/$monthday $hour:$min]"); 
}
if ($revengemode =~ /2/i) {
push @mode,("-o $anick","+b $banmask");
push @kick,("$anick MASS MODECHANGE");
sl(1,"\002Mass modechange by $user on $chan, banning\002");
}
if ($revengemode =~ /1/i) {
push @kick,("$anick MASS MODECHANGE");
sl(1,"\002Mass modechange by $user on $chan, kicking\002");
}
}
}
}
}
}
#######
if ("@kick" =~ /\S+/ || "@mode" =~ /\S+/) {
chanaction("$mynick,,,$chan,,,$server,,,$nolongerop");
}
if ("@totalaction" =~ /\S/) {
sl(1,@totalaction);
}
return 0;
}



# chanaction
sub chanaction
{
my $wow = shift(@_);
my @goo = split(',,,',$wow);
my $nick = $goo[0];
my $chan = $goo[1];
my $server = $goo[2];
my $nolongerop = $goo[3];
my $comp1 = stripn(",,,$nick,,,$server,,,$chan,,,$nick,,,");
$time = time;
$s = $nothinghere;  
$g = 0;
@totalmodes = @nothinghere;

my $amiop = amiop("$chan $server");
if ($nolongerop) {$amiop = 0;}


foreach $wow (@mode) {
$check = stripn("@totalmodes");
$wow2 = stripn($wow);
$wow2 =~ s/\*/\./g;
$wow2 =~ s/\?/\./g;

 
if (!($check =~ /.*$wow2.*/i)) {
push(@totalmodes, "$wow");
}
}
$modeba1 = "";
$modeba2 = "";
$modebb1 = "";
$modebb2 = "";
$modeoa1 = "";
$modeoa2 = "";
$modeob1 = "";
$modeob2 = "";
 
foreach $wow (@totalmodes) {
$wow =~ /(.*) (.*)/;
$test2 = $1;
$test3 = $2;
$test20 = stripn($1);
if ($test20 =~ /minussignb/i) {
$modeba1 = "$modeba1$test2";
$modeba2 = "$modeba2 $test3";
}
if ($test20 =~ /plussignb/i) {
$modebb1 = "$modebb1$test2";
$modebb2 = "$modebb2 $test3";
}
if ($test20 =~ /minussigno/i || $test20 =~ /minussignv/i) {   
$modeoa1 = "$modeoa1$test2";
$modeoa2 = "$modeoa2 $test3";
}
if ($test20 =~ /plussigno/i || $test20 =~ /plussignv/i) {
$modeob1 = "$modeob1$test2";
$modeob2 = "$modeob2 $test3";
}

$g = $g + 1;
if ($g eq $modelength) {
$mode12 = stripn("$modeob1$modebb1$modeoa1$modeba1");
if ($mode12 =~ /b|o|v/) {


# = @nick stuff
# $t = 0;
#foreach $checks (@nicks) {
#$comp2 = stripn(",,,$checks");
#if ($comp2 =~ /$comp1/i) {
#@rrr = split(',,,',$comp2);


if ($amiop == 1) {
IRC::command_with_server ("/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2",$server);
} else {
push @newmode, "/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2,,,$server,,,$nick,,,$chan,,,$time";
}
#$t = 1;
#last;
#}
#}
#if ($t == 0) {
#push @newmode, "/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2,,,$server,,,$nick,,,$chan,,,$time";
#}

}
$modeba1 = "";
$modeba2 = "";
$modebb1 = "";
$modebb2 = "";
$modeoa1 = "";
$modeoa2 = "";
$modeob1 = "";
$modeob2 = "";
$g = 0;
}
}

$timing = time;
if ($timing > $timeit) {  
$lastmode = "blank";
$lastkick = "blank";
$timeit = 0;
$userjoined = 0;
}
#hmm?
#$y = 0;
#if ($userjoined =~ /1/) {
#$tester = stripn("@mode");
#$lastmode =~ s/\*/\./g;
#$lastmode =~ s/\?/\./g;
#if ($tester =~ /.*$lastmode.*/i) {
#$y = 1;
##}
#}

#IRC::print "$y is y\n";
#if ($y =~ /0/) {
$mode12 = stripn("$modeob1$modebb1$modeoa1$modeba1");
if ($mode12 =~ /b|o|v/) {

# = @nicks stuff
#$t = 0;
#foreach $checks (@nicks) {
#$comp2 = stripn(",,,$checks");
#if ($comp2 =~ /$comp1/i) {
#@rrr = split(',,,',$comp2);


if ($amiop == 1) {
IRC::command_with_server ("/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2",$server);
} else {
push @newmode, "/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2,,,$server,,,$nick,,,$chan,,,$time";
}
#$t = 1;
#last;
#}
#}
#if ($t == 0) {
#push @newmode, "/raw MODE $chan $modeoa1$modeob1$modeba1$modebb1$modeoa2$modeob2$modeba2$modebb2,,,$server,,,$nick,,,$chan,,,$time";
#}
}
 
$lastmode = stripn("@mode");
@mode = @nothing;
@totalmodes = @nothing;





#hmm? if ($y =~ /0/) {
@totalkick = @nothinghere;
foreach $wow (@kick) {
$check = stripn("@totalkick");
$wow2 = stripn($wow);
if (!($check =~ /.*$wow2.*/i)) {
push(@totalkick, "$wow");
}
#hmm? }
}
foreach $here (@totalkick) {
@getstuff = split(/\s+/,$here,2);
$here = $getstuff[0];
if ($getstuff[1] =~ /\S+/) {
$kickreason54 = $getstuff[1];
} else {
$kickreason54 = $kickreason;
}
# = @nicks stuff
#$t = 0;
#foreach $checks (@nicks) {
#$comp2 = stripn(",,,$checks");
#if ($comp2 =~ /$comp1/i) {
#@rrr = split(',,,',$comp2);


if ($amiop == 1) {
IRC::command_with_server ("/raw KICK $chan $here :$kickreason54",$server);
} else {
$kickreason54 =~ s/,,,/.../g;
push @newkick, "/raw KICK $chan $here :$kickreason54,,,$server,,,$nick,,,$chan,,,$time";
}
#$t = 1;
#last;
#}
#}
#if ($t == 0) {
#push @newkick, "/raw KICK $chan $here :$kickreason54,,,$server,,,$nick,,,$chan,,,$time";
#}


}

$lastkick = stripn("@kick");
@kick = @nothing;
if ("@newmode" =~ /\S+/ || "@newkick" =~ /\S+/) {
IRC::add_timeout_handler(1000, "chanaction2");
}

#hmm? $userjoined = 1;
$timeit = time;
$timeit = $timeit + 5;
return 1;
}

# chanaction2
sub chanaction2
{
my @newmode2 = @nothing;
my @newkick2 = @nothing;
$currenttime = time;
if (($remembertimecalled + 1) > $currenttime) {
return 1;
}
$remembertimecalled = $currenttime;
my $amiop;
foreach $wow2 (@newmode) {
@all = split(',,,',$wow2);
my $wow = $all[0];
my $server = $all[1];
my $mynick = $all[2];
my $chan = $all[3];
my $time = $all[4];
$amiop = amiop("$chan $server");
if (($time + $morktimeout) < $currenttime) {
next;
}
my $comp1 = stripn(",,,$mynick,,,$server,,,$chan,,,$mynick,,,");


# = nicks stuff
#$trt = 0;
#foreach $checks (@nicks) {
#my $comp2 = stripn(",,,$checks");
#if ($comp2 =~ /$comp1/i) {
#@rrr = split(',,,',$comp2);
#$trt = 1;

if ($amiop) {
IRC::command_with_server("$wow",$server);
} else {
push @newmode2, "$wow2";
} 
#last;
#}
#}

#if ($trt == 0) {
#push @newmode2, "$wow2";
#}
 
}
@newmode = @newmode2;


foreach $wow2 (@newkick) {
@all = split(',,,',$wow2);
my $wow = $all[0];
my $server = $all[1];
my $mynick = $all[2];

my $chan = $all[3];
my $time = $all[4];
$amiop = amiop("$chan $server");

if (($time + $morktimeout) < $currenttime) {
next;
}
my $comp1 = stripn(",,,$mynick,,,$server,,,$chan,,,$mynick,,,");

# = @nicks stuff
#$trt2 = 0;
#foreach $checks (@nicks) {
#$comp2 = stripn(",,,$checks");
#if ($comp2 =~ /$comp1/i) {
#$trt2 = 1;
#@rrr = split(',,,',$comp2);

if ($amiop == 1) {
IRC::command_with_server("$wow",$server);
} else {
push @newkick2, "$wow2";
}
#last;
#}
#}
#if ($trt2 == 0) {
#push @newkick2, "$wow2";
#} 


}

@newkick = @newkick2;

if ("@newmode" =~ /\S+/ || "@newkick" =~ /\S+/) {
IRC::add_timeout_handler(1000, "chanaction2");
}
return 1;
}


# part
sub part 
{
$line = shift(@_);
$bbb = 0;
@holdpartstuff = split(' PART ',$line);
@holdps2 = split(':',$holdpartstuff[0],2);
@wellwe = split(' ',$holdpartstuff[1]);
my $boochans = $wellwe[0];
my $woopie = $holdps2[1];
@hrms = split('!',"$woopie",2);
my $testernick = $hrms[0];
@hrms2 = split('\@',"$hrms[1]",2);


my $server = IRC::get_info(3);
my $server2 = stripn($server);
my $mynick3 = IRC::get_info(1);
$testernick = stripn($testernick);
my $testernick2 = "$mynick3,,,$server,,,$boochans,,,$testernick,,,$hrms2[0],,,$hrms2[1]";
my $matchit = stripn($testernick2);


my $mynick = stripn($mynick3);

# play sound
if ($soundson == 1) {
if ($partsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$partsound &";
}
}


##### add to seen file


if ($seenliststore == 1) {
my $chan = $boochans;
#
#my $a = stripn($hrms2[0]);
my $a = quotemeta $hrms2[0];
#
#my $b = stripn($hrms2[1]);
my $b = quotemeta $hrms2[1];
#
my $banmask = banmask3("*!$a\@$b");
#IRC::print "$banmask is the compare thing\n";
my @brr = split('\@',$banmask);   
my $time = time;
#
#my $seennick = stripn($hrms[0]);
my $seennick = quotemeta $hrms[0];
#

my $t = 0;
my $lengthseenlist = @seenlist;
toppart:
if ($t < $lengthseenlist) {

#IRC::print "$seenlist[$t] and $seennick .+ $brr[0] $brr[1]\n";

if (" $seenlist[$t] " =~ / $seennick .+ $brr[0] $brr[1] /i) {
#IRC::print "Matched\n";
$seenlist[$t] = "$hrms[0] $time $chan $hrms2[0] $hrms2[1]";
goto endofitpart;
}
$t++;
goto toppart;
} else {
unshift @seenlist,("$hrms[0] $time $chan $hrms2[0] $hrms2[1]");
goto endofitpart;
}
}
endofitpart:


###### logging
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
if ($outs2 =~ /$outs1/i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "($woopie) PART $boochans\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
#####





$boochans = stripn($boochans);

$matchit = stripn($matchit);

if ($mynick =~ /$testernick/) {
$matchit = "$mynick,,,$server2,,,$boochans,,,";
@holdvars = @nothing;
foreach $bee (@listofjoinedchannels) {
if (" $bee " =~ / $boochans,,,$server2,,,$mynick /i) {
} else {
push @holdvars,($bee);
}
}
@listofjoinedchannels=@holdvars;
}

#$testitis = 0;
#to be removed 
###############################
#@nicks2 = @nothingvar;
#foreach $testin (@nicks) {
#$whyme = stripn($testin);

#if ($whyme =~ /.*$matchit.*/i) {
#$testitis = 1;
#} else {
#push @nicks2, "$testin";
#}
#}
#@nicks = @nicks2;
#if ($testitis == 0) {
#IRC::print "\002WARNING : Something just went wrong with the part nick buffer.\n";
#IRC::print "\002WARNING : .*$matchit.*\n";
#IRC::print "\002WARNING : Please email this, a paste of the user that just left\n";
#IRC::print "\002WARNING : and of the /test command, to bbarnett\@L8R.net\n";
#system $pagecommand." ".$homepath.".xdcc/page.wav &";



# refetching nicklist because of error
###

#my $time = time;

#if (($lastrefetchattempt + 60) < $time) {
#$lastrefetchattempt = $time; 
#@nicks = @nullvariable;
#$whoflag = 0;
#$newwhoflag = 0;
#my @test = IRC::channel_list;
#my $boot = "@test";
#$boot =~ s/ \#/;;;\#/g;

#my @wow = split (';;;',$boot);
#if (open(CHANLOG4,">>".$homepath."error.log")) { 
#print CHANLOG4 "@wow is wow\n";
#close(CHANLOG4);
#}
#foreach $boot (@wow) {
#my @manofchan = split (' ',$boot);
#my $comm = "/raw who $manofchan[0]";
#$whoflag = $whoflag + 1;
#$newwhoflag = $newwhoflag + 1;
#IRC::command_with_server($comm,$manofchan[1]);
#}
#sl(3,$hl."\002WARNING : refetching nicklist because of error\002\003");
#}
#}
#######################################
return 0;
}



# quit
sub quit 
{
$line = shift(@_);
my $server = IRC::get_info(3);
my $mynick = IRC::get_info(1);

my @blahman = split(' QUIT :',$line,2);
my $line = shift(@blahman);
my @holdps2 = split(':',$line,2);
my $hostnames = $holdps2[1];
my @hrms = split('!',"$hostnames",2);
my $testernick = $hrms[0];
my @hrms2 = split('\@',"$hrms[1]",2);



my $testernick1 = stripn("$mynick,,,$server,,,");
my $testernick2 = stripn(",,,$hrms[0],,,$hrms2[0],,,$hrms2[1]");

#IRC::print ".*$testernick1.*$testernick2.*\n";

my $testitis = 0;

# play sound
if ($soundson == 1) {
if ($quitsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$quitsound &";
}
}



###### are to find what channels that nick was on that you are on
###### on that server... :P

my @chanserv = @nothing;

my @test = IRC::channel_list;
my $boot = "@test";
$boot =~ s/ \#/;;;\#/g;
my @wow = split(';;;',$boot);
my $sserver = stripn($server);
$testernick2 = stripn($testernick);
foreach $boot2 (@wow) {
my @manofchan = split(' ',$boot2);
my $cserver = stripn($manofchan[1]);
if (" $cserver " =~ / $sserver /i) {
my @boos = IRC::user_list ( $manofchan[0], $manofchan[1] );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
$s++;
my @lister = split(' ',$g);
my $aa = stripn($lister[0]);
if (" $testernick2 " =~ / $aa /i) {
push @chanserv,($manofchan[0]);
}
}
}
}


####### logging 
if ($channellog[0] ne "0") { 
$outs1 = quotemeta "$channellog[0]$channellog[1]"; 
$outs3 = "$chanster$server";
if ($outs3 =~ /$outs1/i) { 
if (open(CHANLOG,">>".$homepath.$channellog[0].".log")) { 
print CHANLOG "($hostnames) @blahman\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!"); 
$channellog[0] = "0";$channellog[1] = "0";
}
}
} 


##### add to seen file

if ($seenliststore == 1) {
foreach my $thischantoo (@chanserv) {
#
#my $a = stripn("$hrms2[0]\@$hrms2[1]");
my $a = quotemeta "$hrms2[0]";
my $b = quotemeta "$hrms2[1]";
$a = "$a\@$b";
#
my $banmask = banmask3("*!$a");
my @brr = split('\@',$banmask);   
my $time = time;
#
#my $seennick = stripn($hrms[0]);
my $seennick = quotemeta $hrms[0];
#
#my $schan = stripn($thischantoo);
my $schan = quotemeta $thischantoo;
#
my $t = 0;
my $lengthseenlist = @seenlist;
topquit:

if ($t < $lengthseenlist) {

#IRC::print "$seenlist[$t] and $seennick .+ $brr[0] $brr[1]\n";

if (" $seenlist[$t] " =~ / $seennick .+ $schan $brr[0] $brr[1] /i) {
#IRC::print "Matched\n";
$seenlist[$t] = "$hrms[0] $time $thischantoo $hrms2[0] $hrms2[1]";
goto endofitquit;
}
$t++;
goto topquit;
} else {
unshift @seenlist,("$hrms[0] $time $thischantoo $hrms2[0] $hrms2[1]");
goto endofitquit;
}
endofitquit:
}
}
return 0;
}


# kick
sub kick 
{
$line = shift(@_);
@blahman = split(' KICK ',$line,2);
@endblahman = split(/\s+/,$blahman[1],3);
@blahman2 = split(':',$blahman[0],2);
@blahman = split('!',$blahman2[1]);

my $mynick =  IRC::get_info(1);
my $server = IRC::get_info(3);
my $aggressor = $blahman2[1];
my $agrun = $blahman[1];
my $boochans = $endblahman[0];
my $victim = $endblahman[1];
my $victim2 = stripn($endblahman[1]);
my $testthing2 = $blahman[0];
my $schan = stripn($boochans);
my $nolongerop = 0;


my $mynick2 =  stripn($mynick);
my $server2 = stripn($server);

my $victimnick;
my $victimun;
my $victimhost;

#$matchit5 = "$mynick,,,$server,,,$boochans,,,$victim,,,";
$testernick = "$mynick,,,$server,,,$boochans,,,$victim,,,";
$prt = 0;
@totalaction = @nothinghereatall;

my $wowe = userhost("$victim $boochans $server");
#output("$wowe is the hostname");

#####
if ($soundson == 1) {
if ($kicksound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$kicksound &";
}
}

### logging
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
$outs2 = "$chanster$server";
if ($outs2 =~ /$outs1/i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "($aggressor) KICK $boochans $victim\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
#####

#check for invincibility
$invs = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$chancmp = stripn($ho[0]);
if ($chancmp =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

if ($aggressor =~ /$rest/i) {
if ($flags =~ /i/i) {
$invs = 1;
}
if ($flags =~ /p/i) {
$prt = 1;
}
}
}
}

my $banmask = banmask($aggressor);

#$matchit5 = stripn($matchit5);



if ($mynick2 =~ /$victim2/) {
#$matchit5 = "$mynick2,,,$server2,,,$schan,,,";
@holdvars = @nothing;
foreach $bee (@listofjoinedchannels) {
if (" $bee " =~ / $schan,,,$server2,,,$mynick2 /i) {
} else {
push @holdvars,($bee);
}
}
@listofjoinedchannels=@holdvars;
}

my $compare2 = quotemeta $victim;

my @boos = IRC::user_list ( $boochans, $server );
my @boo = split(': ',"@boos");   

foreach $g (@boo) {
my @lister = split(' ',$g);
my $compare = $lister[0];

if (" $compare " =~ / $compare2 /i) {
$victimnick = $lister[0];
my @workin2 = split('\@',$lister[1]);
$victimun = $workin2[0];
$victimhost = $workin2[1];
#IRC::print "kbingo! $compare and $compare2 $victimnick $victimun $victimhost\n";
last;
}
}


$hostnm = "$victimnick!$victimun\@$victimhost";

my $a = $victimnick;
my $b = $victimun;
my $c = $victimhost;



##### add to seen file


if ($seenliststore == 1) {
my $chan = $boochans;
my $b1 = quotemeta $b;

my $c1 = quotemeta $c;
#IRC::print "$b1 and $c1\n";
my $banmask = banmask3("*!$b1\@$c1");
my @brr = split('\@',$banmask);   
my $time = time;
my $seennick = quotemeta $a;

my $t = 0;
my $lengthseenlist = @seenlist;
topkick:

if ($t < $lengthseenlist) {

#IRC::print "$seenlist[$t] and  $seennick .+ $brr[0] $brr[1] \n";
if (" $seenlist[$t] " =~ / $seennick .+ $brr[0] $brr[1] /i) {
#IRC::print "matched\n";
$seenlist[$t] = "$a $time $chan $b $c";
goto endofitkick;
}
$t++;
goto topkick;
} else {
unshift @seenlist,("$a $time $chan $b $c");
goto endofitkick;
}
}
endofitkick:



##########
#chanaction($boochans);
#if ("@totalaction" =~ /\S/) {
#sl(1,@totalaction);
#}
$whyme5 = stripn($victim);
$whyme6 = stripn($testthing2);
if (":$whyme5:" =~ /:$whyme6:/i) {
#IRC::print "Returning\n";
return 0;
}




foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;

if ($hostnm =~ /$rest/i) {
## found match, get flags together
foreach $go (@more) {
@ho = split(' ',$go);
$chancmp = stripn($ho[0]);
if ($chancmp =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

if ($flags =~ /p|i/i) {

$victim2 = stripn(";$mynick;");
$victim3 = stripn(";$victim;");
$testthing3 = stripn(";$testthing2;");

if (!($victim2 =~ /$testthing3/i)) {
if (!($victim3 =~ /$testthing3/i)) {
if ($invs =~ /0/i) {
$revengetest = $revengekick;
if ($flags =~ /i/i) {
if (!($irevenge == 0)) {
$revengetest = $revengetest + $irevenge;
}
}

if ($prt =~ /1/i) {
if (!($prevenge == 0)) {
$revengetest = $revengetest - $prevenge;
}
}

if ($revengetest > 3) {$revengetest = 3;}
if ($revengetest < 0) {$revengetest = 0;}

if ($revengetest =~ /3/i) {
push(@mode,"-o $testthing2","+b $banmask");
push @totalaction, ("\002$nick on $boochans kicked by $aggressor, adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$testthing2 k $bootface $boochans");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$testthing2 KICKED $nick from $boochans \($aggressor\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment KICKED $nick from $boochans \($aggressor\) [$month/$monthday $hour:$min]"); 
}
if ($revengetest =~ /2/i) {
push(@mode,"-o $testthing2","+b $banmask");
push(@kick,"$testthing2");
push @totalaction, ("\002$nick kicked on $boochans by $aggressor .. banning\002");
}
if ($revengetest =~ /1/i) {
push(@kick,"$testthing2");
push @totalaction, ("\002$nick kicked on $boochans by $aggressor .. kicking\002");
}
}
}
}
}
last;
}
}
}
$mynick2 = stripn("ppp".$mynick."ppp");
$testernick = stripn($testernick);
$matchit = $testernick;
$boochans = stripn($boochans);
$victim2 = stripn("ppp".$victim."ppp");
if ($mynick2 =~ /$victim2/) {
$nolongerop = 1;
$matchit = $boochans;
if ($invs =~ /0/i) {
if ($increaserevenge == 1) {
$revengea = $revenge;
$revengematch2 = stripn(";$testthing2;");
if ($revengematch2 =~ /$revengematch/i) {
$revengea++;
if ($revengea > 3) {$revengea = 3;}
$revengematch = $nothing;
sl(1,"\002Increased Revenge against $testthing2($agrun) on $boochans\002");
} else {
sl(1,"\002Revenge against $testthing2($agrun) on $boochans\002");
}
} else {
sl(1,"\002Revenge against $testthing2($agrun) on $boochans\002");
}
if ($revengea =~ /3/) {
$revengematch = stripn(";$testthing2;");
push @mode, ("-o $testthing2","+b $banmask");
push @totalaction, ("\002Revenge against $testhing2 ... adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$testthing2 k $bootface $boochans");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kick,"$testthing2 REVENGE $nick kicked me from $boochans \($aggressor\) [$month/$monthday $hour:$min]"); 
edit_friend("$cool comment REVENGE $nick kicked me from $boochans \($aggressor\) [$month/$monthday $hour:$min]"); 

}
if ($revengea =~ /2/) {
$revengematch = stripn(";$testthing2;");
push @mode, ("-o $testthing2","+b $banmask");
push(@kick,"$testthing2 \002REVENGE!\002");
}
if ($revengea =~ /1/) {
$revengematch = stripn(";$testthing2;");
push(@kick,"$testthing2 \002REVENGE!\002");
}
}
}
chanaction("$mynick,,,$boochans,,,$server,,,$nolongerop");
if ("@totalaction" =~ /\S+/) {
sl(1,@totalaction);
}
return 0;

}

# stripn
sub stripn 
{
$line9000 = shift(@_);
if ($line9000) {
$line9000 =~ s/\-/minussign/g;
$line9000 =~ s/\+/plussign/g;
$line9000 =~ s/\|/pipesign/g;
$line9000 =~ s/\[/squareleft/g;
$line9000 =~ s/\]/squareright/g;
$line9000 =~ s/\{/curlyleft/g;
$line9000 =~ s/\}/curlyright/g;
$line9000 =~ s/\(/normalleft/g;
$line9000 =~ s/\)/normalright/g;
$line9000 =~ s/\^/uparrow/g;
$line9000 =~ s/\\/qwerty/g;
# extra
$line9000 =~ s/\?/questionmark/g;
$line9000 =~ s/\!/exclamationmark/g;
#$line9000 =~ s/\*/star/g;
}
return $line9000;

}


# join
sub join 
{
$line = shift(@_);
my $mynick93 = IRC::get_info(1);
my $server93 = IRC::get_info(3);

$numeric = 0;
$userjoined = 0;
my $puser = 0;
@blahman = split(':',$line,3);
@blahman222 = split(' JOIN ',$blahman[1]);
$blahman[1] = $blahman222[0];
@blahman2 = split('!',$blahman[1],2);
@blahman22 = split('\@',$blahman2[1],2);

my $hostnm = $blahman[1];
my $victim = $blahman2[0];
my $vuname = $blahman22[0];
my $vhmask = $blahman22[1];
my $jchan = $blahman[2];


my $server2 = quotemeta $server93;
my $smynick = quotemeta $mynick93;
my $schan = quotemeta $jchan;

my @moder = @nothing;
my @kicker = @nothing;
my @moder2 = @nothing;




if ($soundson == 1) {
if ($joinsound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$joinsound &";
}
}

#### logging
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
$outs2 = "$chanster$server93";
if (" $outs2 " =~ / $outs1 /i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "($hostnm) JOIN $jchan\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
#####


##################### is it me?
# getting who info on joined channels
if (" $victim " =~ / $smynick /i) {
push @listofjoinedchannels,("$jchan,,,$server93,,,$mynick93");

######### check to make sure no duplicate info in @nicks
#@nicks2 = @clearvar;

@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;

@wow = split (';;;',$boot);


##### delayed check to see if anyone on the channel should be banned / etc
push @scanchan,($jchan);
push @scanserver,($server93);

IRC::add_timeout_handler(1000,"scanchan");


#########

return 0;
}
# not me, so check for friendlist stuff

foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);

$newcomment2 = $4;
@boogieface = split (':',$rest2);
my $checkit = 0;
foreach $rest (@boogieface) {

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;


if ($hostnm =~ /$rest/i) {
#### ok, matches, get flags of user
foreach $go (@more) {
@ho = split(' ',$go);
if (" $ho[0] " =~ / $schan /i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

$checkit = 1;
if ($flags =~ /k/i) {
sl(1,"\002Banning Evil $nick $hl(on $jchan)\003\002");
$banmask = banmask($hostnm);
push(@moder,"-o $victim","+b $banmask");
push(@kicker,"$victim $newcomment2");
}

if ($flags =~ /p/i) {
$puser = 1;
}
if ($flags =~ /o/i) {
sl(4,"\002Opping Friend $nick $hl(on $jchan)\003 \002");
push(@moder2,"+o $victim");
}

if ($flags =~ /v/i) {
sl(4,"\002Voicing $nick $hl(on $jchan)\003 \002");
push(@moder2,"+v $victim");
}
}
if ($checkit == 1) {
last;
}
}
}



# $puser
# check for clones 

if ($clonenumberkick > 0) {
my @boosas = IRC::user_list ( $jchan, $server93 );
my @booas = split(': ',"@boosas");
my @clonecheck = grep { /^.+?\@$vhmask /i } @booas;
my $clonenum = @clonecheck;
if ($clonenum >= $clonenumberkick) {
my $aclonechk = 0;
$revengetest = $revengeclonenumberkick;
if ($puser == 1) {
$revengetest = $revengetest - $prevenge;
}
if ($revengetest > 3) {$revengetest = 3;}
if ($revengetest < 0) {$revengetest = 0;}

$banmask = banmask("*!*\@$vhmask");
if ($revengetest =~ /3/i) {
$aclonechk = 1;
push(@moder,"-o $victim","+b $banmask");
push @totalaction, ("\002$victim has clones, adding to kick list\002");
$bootface = $banmask;
$bootface =~ s/!/!\*/g;
$bootface =~ s/\*\*/\*/g;
$cool = add_friend("baduser-$victim k $bootface $jchan");
@wowie = split (' ',$cool);
$cool = $wowie[1];
push(@kicker,"$victim Found $clonenum CLONES from $hostnm on $jchan [$month/$monthday $hour:$min]");
foreach $okdude (@clonecheck) {my @why = split(' ',$okdude);
push(@moder,"-o $why[0]");
push(@kicker,"$why[0] Found $clonenum CLONES from $hostnm on $jchan [$month/$monthday $hour:$min]"); 
}
edit_friend("$cool comment Found $clonenum CLONES from $hostnm on $jchan [$month/$monthday $hour:$min]"); 
}
if ($revengetest =~ /2/i) {
$aclonechk = 1;
push(@mode,"-o $victim","+b $banmask");
push(@kicker,"$victim Found $clonenum CLONES from $hostnm on $jchan");
foreach $okdude (@clonecheck) {my @why = split(' ',$okdude);
push(@moder,"-o $why[0]");
push(@kicker,"$why[0] Found $clonenum CLONES from $hostnm on $jchan");
}
push @totalaction, ("\002Found $clonenum CLONES from $hostnm on $jchan\002");
}
if ($revengetest =~ /1/i) {
$aclonechk = 1;
push(@kicker,"$victim Found $clonenum CLONES from $hostnm on $jchan");
foreach $okdude (@clonecheck) {my @why = split(' ',$okdude);
push(@kicker,"$why[0] Found $clonenum CLONES from $hostnm on $jchan");
}
push @totalaction, ("\002Found $clonenum CLONES from $hostnm on $jchan\002");
}

if ($aclonechk == 0) {
my $pretzel = " ";
foreach $okdude (@clonecheck) {my @why = split(' ',$okdude);$pretzel = $pretzel.$why[0].",";}
chop $pretzel;
sl(1,"\002NOTE : Found $clonenum CLONES from $hostnm on $jchan ($pretzel )\002");
}
} else {
if ($clonenum > 0) {
my $pretzel = " ";
foreach $okdude (@clonecheck) {my @why = split(' ',$okdude);$pretzel = $pretzel.$why[0].",";}
chop $pretzel;
sl(1,"\002NOTE : Found $clonenum CLONES from $hostnm on $jchan ($pretzel )\002");
}
}
}



if (@moder == 0 && @kicker == 0) {
push @mode,(@moder2);
} else {
push @mode,(@moder);
push @kick,(@kicker);
}
if (@mode > 0 || @kick > 0) {
chanaction("$mynick93,,,$jchan,,,$server93");
}
return 0;
}


# add friend
sub add_friend
{
my $info = shift(@_);
my $server4 = IRC::get_info(3);
my $chan4 = IRC::get_info(2);
my $mynick4 = IRC::get_info(1);
my $er = 0;
@cool = split(' ', $info);

$nick4 = shift(@cool);
if ($nick4 =~ /^baduser-/i) {$er = 1;}
$flags4 = shift(@cool);
$hostnm4 = shift(@cool);
$info =~ /\S+ \S+ \S+ (.*)/;
$comment4 = $1;
if ($hostnm4) {
if ($hostnm4 =~ /^\#/) {
$comment4 = $hostnm4." ".$comment4;
$hostnm4 = $nothing;
}}
if ($1) {
if ($1 =~ /.*:::.*/i) {output("\002Sorry, comments can't have ::: in them!\002");return 1;}
}

$greeneyes4 = $nothinghereman;
@blahlist4 = split('',$flags4);
foreach $bootface4 (@blahlist4) {
if ($bootface4 =~ /v|o|k|f|x|i|p|s|d|q/) {
$greeneyes4 = $greeneyes4.$bootface4;
} else {
output("\002$bootface4 is not a valid flag.. ignoring!\002");
} 
}
$flags4 = $greeneyes4;

if (!($nick4 =~ /\S+/ && $flags4 =~ /\S+/ )) {
output("\002Enter nick, flags and a hostmask! eg /addf bob [v|o|k|f|x|i|p|s|d|q] *!*bob\@209.53.20.* \002");
return 1;
}


if (!($hostnm4 =~ /\S+/)) {

my $compare2 = quotemeta $nick4;

my @boos = IRC::user_list ( $chan4, $server4 );
my @boo = split(': ',"@boos");   

foreach $g (@boo) {
my @lister = split(' ',$g);
my $compare = $lister[0];
if (" $compare " =~ / $compare2 /i) {
$hostnm4 = banmask("*!$lister[1]");
last;
}
}

output($hl."$nick4\'s\003\002 hostmask is\002$hl $hostnm4\003");
}

if (!($hostnm4 =~ /\@/)) {
output($hl."\002\"$hostnm4\"\003\002 is not a valid hostmask!\002");
return 1;
}

$snick4 = stripn(";;;".$nick4.";;;");
foreach $test4 (@friendlist) {
$test4 =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick24 = $1;
$flags24 = $2;
$rest24 = $3;
$hostnm24 = ";$hostnm4;";
$hostnm24 =~ s/\*/`/g;
$hostnm24 =~ s/\?/\./g;
$hostnm24 =~ s/`/\.\*/go;
$snick24 = stripn(";;;".$nick24.";;;");
$srest24 = stripn($rest24);
$shostnm4 = stripn($hostnm4);
$shostnm4 =~ s/\*/`/g;
$shostnm4 =~ s/\?/\'/g;
$srest24 =~ s/\*/`/g;
$srest24 =~ s/\?/\'/g;


if ($snick4 =~ /$snick24/i) {
if ($srest24 =~ /$shostnm4/i) {
output($hl."$nick4\003\002 already exists with that hostmask, aborting");
return ("1 $nick4");
} else {
output($hl."$nick4\003\002 already exists...");
edit_friend("$nick4 +$hostnm4");
if ($er == 0) {
push @scanchan,($chan4);
push @scanserver,($server4);
IRC::add_timeout_handler(200,"scanchan");
}
return ("1 $nick4");
}
}

@boogieface4 = split (':',$rest24);
foreach $rest4 (@boogieface4) {

$rest4 =~ s/\*/`/g;
$rest4 =~ s/\?/\./g;
$rest4 =~ s/`/\.\*/go;

if ($hostnm24 =~ /.*;$rest4;.*/i) {
output($hl."$nick4\003\002 exists under\002 ".$hl."$nick24\003\002, changing flags...\002");
edit_friend("$nick24 $flags4");
$nickname = $nick24;
return ("1 $nickname");
}
}
}



unless (open(FRIENDLIST, ">".$homepath.".xdcc/friendslist")) {
output("\002Couldn't open output file .friendslist!\002");
return 1;
}


if ($comment4 =~ /^(\#\S+) (.+)/) {
push @friendlist, "$nick4,,".$hostnm4.":::$2:::$1 $flags4";
output("\002Added\002 $nick4 () [$hostnm4] with $hl$1\003 flags of $hl$flags4 \003 COMMENT:$2");
} else {  
push @friendlist, "$nick4,$flags4,".$hostnm4.":::".$comment4.":::";
output("\002Added\002 $nick4 ($flags4) [$hostnm4] COMMENT:$comment4");
}
foreach $test4 (@friendlist) {
chomp($test4);
print FRIENDLIST ("$test4\n");
}
close(FRIENDLIST);
$nickname = $nick4;
if ($flags4 !~ /d|k|s/i) {
push @rawout,("$server4 /raw notice $nick4 :You have been added to my friendlist with flags $flags4");
}
if ($er == 0) {
push @scanchan,($chan4);
push @scanserver,($server4);
IRC::add_timeout_handler(200,"scanchan");
}
return ("1 $nickname");
}

# add friend
sub add_friend2
{
add_friend(@_);
return 1;
}



# list friendlist
sub list_friend
{
$blue = 0;
output(" ");
$t = 0;
$r = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$len = length($1);
$len2 = length($2);
if ($len > $t) {$t = $len;}
if ($len2 > $r) {$r = $len2;}
}
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
@blahst = split(';;;',$5);
foreach $ss (@blahst) {
@d = split(' ',$ss);
$len2 = length($d[1]);
if ($len2 > $r) {$r = $len2;}
}
}

foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$blue++;
@wow = split(':',$3);
$cool = shift(@wow);
$thingof2 = sprintf "%3s)%".$t."s %".$r."s  \002$cool\002",$blue,$1,$2;
output("$thingof2");
foreach $cool (@wow) {
$thingof2 = sprintf "    %".$t."s %".$r."s$hl  \002$cool\002\003";
output("$thingof2");
}
@wow65 = split(';;;',$5);
foreach $cool (@wow65) {
@ra = split(/\s+/,$cool);
$thingof2 = sprintf $hl."CHN)\002%".$t."s %".$r."s  $ra[0]\003\002","",$ra[1];
output("$thingof2");
}



@comment = split(' ',$4);
$coms = shift(@comment);
if ($coms) {
$thingof2 = sprintf $hl."COM)%".$t."s @comment \003",$coms;
output("$thingof2");
}
}
output(" ");
return 1;
}

# del friend from friendlist
sub del_friend
{
$blue=0;
$t=0;
@holdin="";
pop(@holdin);
unless (open(FRIENDLIST, ">".$homepath.".xdcc/friendslist")) {
output("\002Couldn't open output file .friendlist!\002");
return 1;
}
$rrr = shift(@_);
foreach $test (@friendlist) {
$blue++;
if ($rrr != $blue) {
chomp($test);
print FRIENDLIST ("$test\n");
push @holdin, $test;
} else {
$t = 1;
}
}
@friendlist = @holdin;
close(FRIENDLIST);

if ($t == 0) {
output("\002No user deleted!\002");
} else {
output("\002User $rrr deleted!\002");
}
return 1;
}

# toggle xdcc status
sub xdcc_on
{
my $blah = shift(@_);

if ($blah =~/help/i) {
output(" ");
output("\002".$hl."XDCC Script Help\002\003");
output("\002FRIENDS:\002");
output($hl."addf\003  - add a friend to your friends list");
output("      \\- o = op, v = voice, f = friend, k = kick, d = deop, q = devoice  -> /addf bud o *!*bu@*.a.com");
output("       \\- f = friend (effects paging) x = xdcc access when restricted to friends");
output("        \\- i = immunity (no revenge or reversal of any actions this user takes)");
output("         \\- p = protection from harmful actions by other users");
output("          \\- hostmask uses ? and * for single and multiple char match");
output("           \\- /addf hymie iop hostmask #channel comment will add user flags to a channel not global");
output($hl."delf\003  - delete a friend from your friends list");
output($hl."listf\003  - display your friends list");
output($hl."editf\003  - changes info about your friends");
output("       \\- add/del hostmask with + or -  -> /editf buddy -*!*buddy@*.test.com");
output("        \\- change flags (just enter them) -> /editf buddy ovfkx");
output("         \\- add a channel /editf buddy #channel ovfkx (no flags deletes a chan)");
output("          \\- add a comment /editf buddy comment blah");
output(" ");
output("\002XDCC:\002");
output($hl."addp\003  - add a pack to your xdcc list");
output("      \\ add files as INDIVIDUAL packs your xdcc list");
output("       \\ eg \"/addp /home/mp3/* /FILES\"");
output("        \\ add files as private packs your xdcc list (only good with /xdcc packs");
output("         \\ eg \"/addp /home/mp3/* /PRIV\"");
output($hl."delp\003  - delete a pack from your xdcc list - use ALL to clear list");
output($hl."slots\003  - set the number of maximum dcc files sent at once");
output($hl."packlist\003  - privately list your packs");
output($hl."plist\003  - publically list your packs to a channel -> /plist #cool");
output($hl."autoget\003  - turn auto get on for +f users");
output($hl."noti\003  - by itself will notify list to the current channel");
output("      \\- time in minutes for autolist  -> /noti 15");
output("       \\- description for packlist  -> /noti 15 This stuff is great!");
output("        \\- /noti off turns it off");
output($hl."xdcc\003  - select on, off, friends, packs or help (this).");
output($hl."chan\003  - set the default channel(s) for xdcc noti listing");
output("       include # and use a space to seperate channels");
output("  eg - /chan #cool #cooler");
output($hl."listmode\003  - if on, your packlist will be sent as a file (good for BIG packlists...)");
output($hl."dpack\003  - if on and your security is on packs, ALL users WILL see descriptions for packs");
output("that are restricted to friends only...");
output(" ");
output("\002MISC:\002");
output($hl."log\003  - toggle logging status on away (on or off)");
output($hl."page\003  - toggle page status (on or off or friends), and select when paging should be on.");
output($hl."away\003  - replaces xchat's built in away, with extra features.");
output($hl."delaway\003  - delete away messages.");
output($hl."wallop\003  - wallop command (write all ops).. works in current channel");
output($hl."flood\003  - change your settings for flood protection");
output("        /flood on, off or (t)emp (off for 60 seconds)");
output(" ");
output("\002CONFIG:\002");
output($hl."savec\003  - save config");
output($hl."loadc\003  - load config");
output($hl."ver\003  - disable version responses from this script");
output(" ");
output("\002REVENGE:\002");
output("use ".$hl."revenge\003  to set revenge mode to :");
output("   off  - no action will be taken to protect users");
output("   kick - triggering results in a kick");
output("   ban  - triggering results in a kickban");
output("   pban - triggering will add this user to your friends list"); 
output("          with a k flag, and kick ban him");
output("   Play around with the settings.  /revenge on its own will");
output("   bring up some help...");
output($hl."amsg\003  - use /amsg channel time message - This will post a message to the");
output("       channel of your choice.  Use \"all\" for all channels, and you can");
output("       clear the log with \"clear\".  Time is in minutes.");
output($hl."scriptlog\003  - set scriptlogs to none, screen, file, or file and screen");
output($hl."slog\003  - \"slog del\" will delete the log, \"slog\" alone will display it");
output($hl."chanlog\003  - toggles logging of current channel");
output($hl."ignoreall\003  - toggles ignoring of ALL messages except for channel messages and");
output("            messages from +f users");
output($hl."setignore\003  - by itself, will list current ignore masks.  You can add ignores");
output("         by supplying a hostmask or username (the user must be on a channel you are).");
output("         Valid keywords are save, load, del (number or hostmask)");
output("         Ignore types are NOTI PRIV CHAN CTCP or ALL");
output($hl."ignoretime\003  - sets the time, in seconds, that auto ignores will timeout in.");
output($hl."logwin\003  - if away is set, don't pop up privmsg window when logging the message");
output($hl."skick\003  - set a speak kick on someone... try /skick help");
output($hl."wkick\003  - set a word/phrase kick .. try /wkick");
output($hl."cycle\003  - does a /part /join on the current channel");
output($hl."sound\003  - turns on and off the playing of sounds, and defines them.");
output($hl."finvite\003  - turns on and off joining channels when friends invite you.");
output($hl."reban\003  - turns on or off automatically unbanning a ban and rebanning your ban when");
output("        the banlist is full");
output($hl."ajoin\003  - change settings and show channels you are currently trying to rejoin");
output($hl."autoconnect\003  - set a server group for autoconnect, and commands you want executed upon connect");
output($hl."server\003  - when autoconnect is used, server by itself will move to the next server");
output($hl."kickreason\003  - set your kick phrase");
output($hl."setseen\003  - set the seen settings");
output($hl."seen\003  - look up a seen nick");
output($hl."stealver\003  - steal and use someone's version info");
output($hl."url\003  - REALLY lame random url creator..");
output($hl."setaway\003  - set your away settings");
output($hl."rawout\003  - set the number of lines output from the script every 4 seconds.");
output($hl."ban\003  - <nick> or <*some!lame\@banmask.com> /w");
output("      \\ You can put multiple nicks and banmasks, and mix and match them");
output("       \\ on a single line.  If you add /w to the end of the line, the nicks are");
output("        \\ banned with a wide banmask (*!*\@127.0.0.* instead of *!username\@127.0.0.*");
output("         \\ eg $hl/ban joe pete *!*\@*.it.com *!*g*\@127.0.0.* fred /w\003");
output("          \\ anything that isn't a banmask or a nick on the chan will become part of");
output("           \\ the kick message.  All hosts matching banmasks are kicked from the chan.");
output($hl."mmsg\003  - does /notice to each user in the channel with whatever message you want.");
output($hl."mmode\003  - mass modes of any type, on any type of user.  /mmode has more help.");
output($hl."autocycle\003  - auto cycle a channel to gain ops when you are alone in it?");
output($hl."grabnick\003  - this will try to grab a nick if you were denied one on server join..");
output($hl."publist\003  - set your public channel xdcc notice method to NOTICE or PRIVMSG");
output($hl."specs\003  - print your system specs to the channel");
output($hl."mcom\003  - mass command script, somewhat like mmode.. use /mcom for help");
output(" ");
return 1;
}





if ($blah =~/send.*/i) {

my @aa = split(' ',$blah);
my $server = IRC::get_info(3);
shift(@aa);
my $nick = shift(@aa);

my $test = "@aa";
$test =~ s/ //g;
if ($test =~ /.*\D+.*/) {
output("\002Sorry, you need to use \"/xdcc send <nick> <pack> <pack> <etc>\"\002");
return 1;
}
output("\002Sending pack(s) @aa to $nick\002");
foreach my $req (@aa) {
my $blue = 0;
my $timing = time;
foreach my $test (@xdcclist) {
 $test =~ /(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*),,,(.*)/;
       my $a = $1;
       my $b = $2;
       my $c = $3;
       my $d = $4;
       my $e = $5;
       my $f = $6;
         $blue++;
 if ($blue == $req) {
 @sendthing = split(":::",$1);
  foreach $blahs (@sendthing) {
  push @qpacks,($nick.":::".$blahs.":::".$timing.":::".$server);
}
} 
}
}




return 1;
}

########################







if ($blah =~/pac.*/i) {
output("Changing XDCC security to \002PACKS\002...");
$xdccon = 3;
return 1;
}

if ($blah =~/fr.*/i) {
output("Changing XDCC to \002FRIENDS\002...");
$xdccon = 2;
return 1;
}

if ($blah =~/off/i) {
output("Turning XDCC \002off\002...");
$xdccstat = 0;
$xdccon = 0;
return 1;
}
if ($blah =~/on/i) {
output("Turning XDCC \002on\002...");
$xdccon = 1;
return 1;
}
output("XDCC commands are ON, OFF, FRIENDS, PACKS, SEND or HELP");
return 1;
}

# edit friend
sub edit_friend
{
  my $info = shift(@_);
  $info =~ /\S* \S* (.*)/;
@blahs4 = split(' ',$info);

$nick4 = $blahs4[0];
$change4 = $blahs4[1];
$newcomment4 = $1;


  if (@blahs4 < 1) {
  output("\002Enter a nick, flags and hostmask to add! eg  /editf bob ovkxf or /editf bob *!*bob\@209.53.20.* \002");
  return 1; 
  }
$g4 = 0;

#if (!($change4 =~ /\S+/)) {
#  output("\002Enter a nick and flags or hostmask to add! eg  /editf bob [v|o|k|f|x|i|p|s|d|q] or /editf bob *!*bob\@209.53.20.* \002");
#return 1;
#}

unless (open(FRIENDLIST, ">".$homepath.".xdcc/friendslist")) {
output("\002Couldn't open output file .friendslist!\002");
return 1;
}
$coolear4 = 0;
foreach $woohoo4 (@friendlist) {
$woohoo4 =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$woohoo24 = $1;
$middle4 = $2;
$rest4 = $3;
$comment4 = $4;
$endbit4 = $5;



$check24 = quotemeta $woohoo24;

$thisline4 = "$woohoo24,$middle4,".$rest4.":::".$comment4.":::".$endbit4;
if ($nick4 =~ /^$check24$/i) {
$coolear4 = 1;


if ($change4) {
if ($change4 =~ /\#.+/i) {
@newthing = @nothinghere;
@blahlist4 = split('',$newcomment4);
$greeneyes45 = $nothing;
foreach $bootface4 (@blahlist4) {
if ($bootface4 =~ /v|o|k|f|x|i|p|s|d|q/) {
$greeneyes45 = $greeneyes45.$bootface4;
} else {
output("\002$bootface4 is not a valid flag.. ignoring!\002");
} 
}
$change6 = stripn($change4);
@vr = split(';;;',$endbit4);
$foundmatch = 0; 
foreach $go (@vr) {
@vr2 = split(' ',$go);
if (";$vr2[0];" =~ /;$change6;/i) {
$foundmatch = 1; 
if ($greeneyes45 =~ /\S+/) {
push @newthing,("$vr2[0] $greeneyes45");
output("\002Changing $hl$woohoo24\003's $vr2[0] flags from $hl$vr2[1] \003to $hl$greeneyes45\003\002");
} else {
output("\002Removing $hl$woohoo24\003's Channel Record for $hl$vr2[0]\003\002");
}
} else {
push @newthing,("$go"); 
}
}
if ($foundmatch == 0) {
if ($greeneyes45 =~ /\S+/) {
push @newthing,("$change4 $greeneyes45");
output("\002Adding Channel Record to $hl$woohoo24 \003 for $hl$change4 \003with flags $hl$greeneyes45\003\002");
} else {
output("\002No flags for $hl$change4 \003... not adding\002");
}

}

$newendbit = $nothing;
foreach $rt (@newthing) {
if (!($newendbit =~ /\S+/)) {
$newendbit = $rt;
} else {
$newendbit = $newendbit.";;;".$rt;
}
}
$thisline4 = "$woohoo24,$middle4,".$rest4.":::".$comment4.":::".$newendbit;
} elsif ($change4 =~ /comment/i) {
$tnewcomment4 = stripn($newcomment4);
if ($tnewcomment4 =~ /.*:::.*/i) {output("\002Can't have ::: in comments!\002");return 1;}
$thisline4 = "$woohoo24,$middle4,".$rest4.":::".$newcomment4.":::".$endbit4;
output("\002Changed $woohoo24\'s comment to \"$hl$newcomment4\003 \"\002");
$newcomment = $newcomment4;
} elsif ($change4 =~ /\S\@\S/) {
if ($change4 =~ /\+\S/) {
$change4 =~ s/\+//;
if ($rest4 =~ /\w/) {
$thisline4 = "$woohoo24,$middle4,".$rest4.":".$change4.":::".$comment4.":::".$endbit4;
} else {
$thisline4 = "$woohoo24,$middle4,".$change4.":::".$comment4.":::".$endbit4;
}
output("\002Added $hl$change4\003 to $woohoo24\'s list of hosts\002");
} elsif ($change4 =~ /\-\S/) {
$change4 =~ s/\-//;
@bluest4 = split (':',$rest4);
$hostlist4 = "";
$t4 = 0;
foreach $fftf4 (@bluest4) {
$change24 = $change4;
$fftf24 = $fftf4;
$change24 =~ s/\*/f/g;
$fftf24 =~ s/\*/f/g;
$change24 =~ s/\?/f/g;
$fftf24 =~ s/\?/f/g;
if ($fftf24 =~ /$change24/i) {
output("\002Removed $hl$change4\003 from $woohoo24\'s list of hosts\002");
} else {
if ($t4 =~ /0/) {
$hostlist4 = $fftf4;
$t4 = 1;
} else {
$hostlist4 = $hostlist4.":".$fftf4;
}
}
}
$thisline4 = "$woohoo24,$middle4,".$hostlist4.":::".$comment4.":::".$endbit4;
} else {
output("\002Missing + or - to add or remove hostmask...\002");
return 1;
}
} else {
$greeneyes4 = "";

@blahlist4 = split('',$change4);
foreach $bootface4 (@blahlist4) {
if ($bootface4 =~ /v|o|k|f|x|i|p|s|d|q/) {
$greeneyes4 = $greeneyes4.$bootface4;
} else {
output("\002$bootface4 is not a valid flag.. ignoring!\002");
} 
}
if ($greeneyes4 =~ /\w/) {
output("\002Changing $woohoo24\'s flags from \"$hl$middle4\003\" to \"$hl$greeneyes4\003\"\002");
$thisline4 = "$woohoo24,$greeneyes4,".$rest4.":::".$comment4.":::".$endbit4;
my $server = IRC::get_info(3);
my $chan = IRC::get_info(2);
if ($chan) {
push @scanchan,($chan);
push @scanserver,($server);
IRC::add_timeout_handler(200,"scanchan");
}
} else {
}


}
} else {
output("\002Removing $hl$woohoo24\003's global flags.\002");
$thisline4 = "$woohoo24,,".$rest4.":::".$comment4.":::".$endbit4;
}
} 
chomp($thisline4);
print FRIENDLIST ("$thisline4\n");
if ($g4 =~ /0/) {
@backuplist4 = $thisline4;
$g4 = 1;
} else {
push @backuplist4, "$thisline4";
}
}
if ($coolear4 =~ /0/) {
output("\002Sorry, couldn't find $hl$nick4 \003 in the userlist...\002");
}
@friendlist = @backuplist4;
close(FRIENDLIST);
return 1;
}





# setnick handler
sub setnick_handler
{
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);

my $info = shift(@_);

my @splitvar = split(' NICK :',$info);
my $newnick = $splitvar[1];
@splitvar = split('\@',$splitvar[0]);
my $thehost = $splitvar[1];
@splitvar = split('!',$splitvar[0]);
my $theuser = $splitvar[1];
@splitvar = split(':',$splitvar[0]);
my $thenick = $splitvar[1];


my $geepart1 = "$theuser\@$thehost";
my $mynick2 = stripn($mynick);

my $server4 = stripn($server);
my $testblah4 = stripn($thenick);

my $newestnick = stripn($newnick);

if ($mynick2 =~ /$testblah4/i) {

@holdvars = @nothing;
foreach $bee (@listofjoinedchannels) {
if (" $bee " =~ /,,,$server4,,,$testblah4 /i) {
@splitvar = split(',,,',$bee);
my $wella = stripn($splitvar[0]);
my $wellb = stripn($splitvar[1]);
if ($newestnick) {
push @holdvars,("$wella,,,$wellb,,,$newestnick");
} else {
push @holdvars,("$wella,,,$wellb,,,$mynick2");
}
} else {
push @holdvars,($bee);
}
}
@listofjoinedchannels=@holdvars;
}


#######
## channel log
if ($channellog[0] ne "0") {
$outs1 = quotemeta "$channellog[0]$channellog[1]";
$outs2 = "$3$server";
if ($outs2 =~ /$outs1/i) {
if (open(CHANLOG, ">>".$homepath.$channellog[0].".log")) {
print CHANLOG "$thenick($geepart1) is now known as \"$newestnick\"\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog[0].log for some reason!");
$channellog[0] = "0";$channellog[1] = "0";
}
}
}
##
######







return 0;
}


# connect handler
sub connect_handler
{
my $clockset = time;
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);

output("\002Setting away status.\002");
if ("@awaylist" =~/\S+/) {
if ($awaysync == 1) {
@awaylist = IRC::server_list;
}
}
$isaway = 0;
my $r = stripn ($server);
foreach $booser (@awaylist) {
my $rr = stripn ($booser);
if (" $r " =~ / $rr /) {
$isaway = 1;
last;
}
}
if ($isaway =~ /1/) {
IRC::command "/raw away :$awaymessage";
if ($awaynick ne "0") {
$backnick = $mynick;
my $cs2 = $clockset + 4;
if ($awaynick =~ /^\*(.+)/) {
push @delayedcommand, ($cs2.";;;".$server.";;;"."/raw nick $mynick$1");
} else {
push @delayedcommand, ($cs2.";;;".$server.";;;"."/raw nick $awaynick");
}
}
}
$clockset = time;
if ($channeltojoin =~ /\S+/) {
IRC::command "/join $channeltojoin";
@listme = split(';',$commandonjoin); 
foreach $itisit (@listme) {
if ($itisit =~ /\S+/) {
push @delayedcommand, ($clockset.";;;".$server.";;;"."$itisit");
$clockset = $clockset + 4;
}
}
$channeltojoin = $nothing;
}
return 0;
}


# away handler
sub away
{
my $server = IRC::get_info(3);
$awaytime = time;
push @awaylist,($server);

output("Now logging messages...");
return 0;
}



# del away handler
sub delaway
{
output("\002Now deleting away log...\002");
open (FIND, ">".$homepath.".xdcc/msglist");
close (FIND);
return 1;
}

# slog handler
sub slog
{

my $info = shift(@_);

if ($info =~ /del.*/i) {
output("\002Now deleting script log...\002");
open (FIND, ">".$homepath.".xdcc/scriptlog");
close (FIND);
return 1;
}


if (open(SFILE,$homepath.".xdcc/scriptlog")) {
@list2 = "";
@list2 = <SFILE>;

close(SFILE);

if (!(@list2 == "")) {
output("Your script log (use del to delete) :");

foreach $list3 (@list2) {
$list3 =~ /(.*) ::: (.*) ::: (.*)/;
output($hl." \002[$1]\003 ($2)\002$hl$3\003");
}

} else {
output("\002You have nothing in the scriptlog...\002");
}

}
return 1;
}

# back handler
sub back
{
my $server = IRC::get_info(3);
my $server2 = stripn($server);
my $gr = @awaylist;
for ($x = 0; $x < $gr; $x++) {
my $joe = stripn($awaylist[$x]);
if ($joe =~ /$server2/) {
splice(@awaylist, $x, 1);
$x--;$gr--;
}
}

if (open(AWAYFILE,$homepath.".xdcc/msglist")) {
@list2 = "";
@list2 = <AWAYFILE>;

close(AWAYFILE);

if (@list2 > 0) {
output(" ");
output("Your away messages :");
foreach $list3 (@list2) {
$list3 =~ /(.*) ::: (.*) ::: (.*)!(.*) ::: (.*)/;
output("[$1]".$hl."($2)\003 \002$3\002$hl($4)\003 \002$5\002");
}
} else {
output("\002You have no messages...\002");
}
return 0;
}
return 0;
}



# page on / off handler
sub page
{
  my $info = shift(@_);

my @borg = split(' ',$info,2);
$info = $borg[0];
my $info2 = $borg[1];
$info2 =~ s/ //g;
if ($info =~ /off/i) {
output("Setting PAGE to \002OFF\002");
$pageon = 0;
return 1;
}

if ($info =~ /friend/i) {
output("Setting PAGE to \002FRIENDS\002");
$pageon = 2;
return 1;
}

if ($info =~ /on/i) {
output("Setting PAGE to \002ON\002");
$pageon = 1;
return 1;
}

if ($info =~ /del/i) {
if ($info2 =~ /\d+/) {
my $g = 0;
my @holdpagetimes = @nothing;
my $tr = 0;
my @okpage = split(';',$okpagetimes);
$okpagetimes = $nothing;
foreach $blahs (@okpage) {
$g++;
if ($g == $info2) {
$tr = 1;
output("\002Page$hl $info2\003 deleted!\002");
next;
}
$okpagetimes = $blahs.";".$okpagetimes;
}
if ($tr == 0) {
output("\002Sorry,$hl $info2\003 was not found as a page number!\002");
}
} else {
output("\002Enter a page number to delete!\002");
}
}

if ($info =~ /time/i) {
if (!($info2 =~ /\-/)) {
output("\002You need to enter a range eg /page time 1000-1200 (10 am to 12 pm)\002");
return 1;
}

my @g = split('-',$info2);
if ("$g[0]$g[1]" =~ /\D+/) {
output("\002Come on, it has to be a number at least!\002");
return 1;
}
if ($g[0] > $g[1]) {
output("\002Sorry, the end time has to be a higher number than the start time\002");
output("\002If you want to have a time span over midnight, do the following :\002");
output("\002/page time 1800-2359\002");
output("\002/page time 0000-0400\002");
return 1;
}
if ($g[0] < 0 || $g[0] > 2359 || $g[1] < 0 || $g[1] > 2359) {
output("\002Errm, valid times are in the 0000-2359 range ONLY\002");
return 1;
}
my $len = length($g[0]);
my @cool = ("0","0","00","000");
if ($len < 4) {
my $ok = 4 - $len; 
$g[0] = $cool[$ok].$g[0];
}

$len = length($g[1]);
if ($len < 4) {
my $ok = 4 - $len; 
$g[1] = $cool[$ok].$g[1];
}
my @test = split('',$g[0]);
if ($test[2] > 5) {
output("\002$g[0] isn't a valid time!\002");
return 1;
}
@test = split('',$g[1]);
if ($test[2] > 5) {
output("\002$g[1] isn't a valid time!\002");
return 1;
}
if ($okpagetimes =~ /\S+/) {
$okpagetimes = $okpagetimes.";$g[0] $g[1]";
} else {
$okpagetimes = "$g[0] $g[1]";
}
}
&output;
output("Current page status is $pageon. (0 = off, 1 = on, 2 = friends)");
output("\002Current page times are :\002");
my $count = 0;
my @okpage = split(';',$okpagetimes);
if (@okpage > 0) {
foreach $blahs (@okpage) {
$count++;
my @gra = split(' ',$blahs);
output("\002$hl $count\003) $gra[0]$hl hrs\003 - $gra[1]$hl hrs\003\002");
}
} else {
output("\002<$hl"."ANY TIME\003>\002");
}

output("Use \002ON\002, \002OFF\002 or \002FRIENDS\002, or use");
output("either \002TIME\002 1200-2220, or \002DEL\002 <page number>, to set allowed page times.");
return 1;
}

# log on / off handler
sub log
{

if ($logon =~ /1/) {
output("Turning away logging \002OFF\002");
$logon = 0;
return 1;
}

if ($logon =~ /0/) {
output("Turning away logging \002ON\002");
$logon = 1;
return 1;
}
return 1;
}


# save config
sub save_conf
{
my $info = shift(@_);
if (!(open(CONFFILE, ">".$homepath.".xdcc/config"))) {
output("Couldn't open save file!!");
return 1;
}
@saveconf =
("$notichannels","$xdccon","$versioning","$pageon","$logon","$lognowin","$xdccflist","$kickreason","$revenge","$logact","$dccslots","$fautogetdcc","$floodchannum","$floodmsgnum","$ignoretimeout","$floodctcpnum","$floodnotinum","$floodmodenum","$isfloodon","$soundson","$revengekick","$revengeban","$revengedeop","$revengemode","$prevenge","$irevenge","$finvite","$revengeopadeop","$revengeunbanak","$clearban","$logtypes","$morktimeout","$trytoautojoin","$watchserver","$increaserevenge","$forceban","$commandonjoin","$seenliston","$kicksound","$noticesound","$dccsound","$xdccsound","$ctcpsound","$privmsgsound","$chanmsgsound","$joinsound","$modesound","$pagecommand","$seenlistchans","$seenlevel","$seenresponse","$seenliststore","$seencompare","$invitesound","$partsound","$quitsound","$floodmassnum","$dapacks","$awaynick","$awaynotice","$awaysync","$outputlimit","$okpagetimes","$seentime","$seenlimit","$cycleforop","$grabnick","$maxslotsperuser","$xdccpublistmethod","$stealvertime","$stealverper","$revengevoiceanovoice","$clonenumberkick","$revengeclonenumberkick");
output("\002Saved config!\002");

foreach $blahblah (@saveconf) {
print CONFFILE ("$blahblah;;;");
}
close(CONFFILE);
return 1;
}

# load config
sub load_conf
{

my $info = shift(@_);

if (!(open(CONFFILE, $homepath.".xdcc/config"))) {
output("\002No config file found!\002");
return 1;
}

$list = <CONFFILE>;

@lister = split(';;;',$list);

($notichannels,$xdccon,$versioning,$pageon,$logon,$lognowin,$xdccflist,$kickreason,$revenge,$logact,$dccslots,$fautogetdcc,$floodchannum,$floodmsgnum,$ignoretimeout,$floodctcpnum,$floodnotinum,$floodmodenum,$isfloodon,$soundson,$revengekick,$revengeban,$revengedeop,$revengemode,$prevenge,$irevenge,$finvite,$revengeopadeop,$revengeunbanak,$clearban,$logtypes,$morktimeout,$trytoautojoin,$watchserver,$increaserevenge,$forceban,$commandonjoin,$seenliston,$kicksound,$noticesound,$dccsound,$xdccsound,$ctcpsound,$privmsgsound,$chanmsgsound,$joinsound,$modesound,$pagecommand,$seenlistchans,$seenlevel,$seenresponse,$seenliststore,$seencompare,$invitesound,$partsound,$quitsound,$floodmassnum,$dapacks,$awaynick,$awaynotice,$awaysync,$outputlimit,$okpagetimes,$seentime,$seenlimit,$cycleforop,$grabnick,$maxslotsperuser,$xdccpublistmethod,$stealvertime,$stealverper,$revengevoiceanovoice,$clonenumberkick,$revengeclonenumberkick) = @lister;
close(CONFFILE);

output("\002Config file loaded!\002");
return 1;
}



# set kick reason
sub set_kickreason
{
my $info = shift(@_);

if (!($info =~ /\w/)) {
output("\002Current kick reason is :\002 $kickreason");
return 1;
} else {

$kickreason = $info;
output("\002Default kick reason now set to -->$kickreason<--\002");
return 1;
}
}







# set default channel
sub setchan
{
my $info = shift(@_);

if (!($info =~ /\w/)) {
output("\002Current channels for xdcc noti :\002 $notichannels");
return 1;
} else {

$notichannels = $info;
output("\002Default channels now set to -->$notichannels<--\002");
return 1;
}
}

# level
sub level
{
$boo = shift(@_);
if ($boo == 0) {
$return = "OFF";
}
if ($boo == 1) {
$return = "KICK";
}
if ($boo == 2) {
$return = "BAN";
}
if ($boo == 3) {
$return = "PBAN";
}
return($return);
}

# revenge level
sub set_revenge
{
my $info = shift(@_);
@inform = split(/\s+/,$info,2);
$info = $inform[0];
$extrainfo = $inform[1];

if (!($info =~ /\S+/)) {
helpishere:
output("\002Current revenge levels :\002");
output(" ");
output("                            P FLAG    P FLAG  \002< -$hl OFFENDER\003 \002");
output("TRIGGER   P FLAG  P+I FLAG  P FLAG  P+I FLAG  \002< -$hl VICTIM\003 \002");
output("$hl-------   ------  --------  ------  --------\003");

$level = level($revengekick);
$level2 = $revengekick + $irevenge;
if ($level2 > 3) {$level2 = 3;}
$level2 = level($level2);
$level3 = $revengekick - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$level4 = $revengekick - $prevenge + $irevenge;
if ($level4 < 0) {$level4 = 0;}
if ($level4 > 3) {$level4 = 3;}
$level4 = level($level4);
$thingof2 = sprintf "KICK    %8s    %6s  %6s    %6s",$level,$level2,$level3,$level4;
output($thingof2);

$level = level($revengeban);
$level2 = $revengeban + $irevenge;
if ($level2 > 3) {$level2 = 3;}
$level2 = level($level2);
$level3 = $revengeban - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$level4 = $revengeban - $prevenge + $irevenge;
if ($level4 < 0) {$level4 = 0;}
if ($level4 > 3) {$level4 = 3;}
$level4 = level($level4);
$thingof2 = sprintf "BAN     %8s    %6s  %6s    %6s",$level,$level2,$level3,$level4;
output($thingof2);

$level = level($revengedeop);
$level2 = $revengedeop + $irevenge;
if ($level2 > 3) {$level2 = 3;}
$level2 = level($level2);
$level3 = $revengedeop - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$level4 = $revengedeop - $prevenge + $irevenge;
if ($level4 < 0) {$level4 = 0;}
if ($level4 > 3) {$level4 = 3;}
$level4 = level($level4);
$thingof2 = sprintf "DEOP    %8s    %6s  %6s    %6s",$level,$level2,$level3,$level4;
output($thingof2);


output($hl."--------------------------------------------\003");
output("         NO FLAG    P FLAG  \002< -$hl OFFENDER\003 \002");
output("$hl         -------    ------\003");

$level = level($revengeopadeop);
$level3 = $revengeopadeop - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$thingof2 = sprintf "OP      %8s    %6s  \002< -$hl OP d flag\003 \002",$level,$level3;
output($thingof2);


$level = level($revengeunbanak);
$level3 = $revengeunbanak - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$thingof2 = sprintf "UNBAN   %8s    %6s  \002< -$hl UNBAN k flag\003 \002",$level,$level3;
output($thingof2);

$level = level($revengevoiceanovoice);
$level3 = $revengevoiceanovoice - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$thingof2 = sprintf "VOICE   %8s    %6s  \002< -$hl VOICE q flag\003 \002",$level,$level3;
output($thingof2);


$level = level($revengeclonenumberkick);
$level3 = $revengeclonenumberkick - $prevenge;
if ($level3 < 0) {$level3 = 0;}
$level3 = level($level3);
$thingof2 = sprintf "CLONEKICK  %5s    %6s  \002< -$hl If clones found, do what?\003 \002",$level,$level3;
output($thingof2);



output($hl."--------------------------------------------\003");
if ($forceban == 1) {
$level = "ON";
} else {
$level = "OFF";
}
$thingof2 = sprintf "FORCEBAN    %4s  (Reban a k user ban if unbanned)",$level;
output($thingof2);
$level = level($revengemode);
$thingof2 = sprintf "MASSMODE    %4s",$level;
output($thingof2);
$level = level($revenge);
$thingof2 = sprintf "REVENGE    %5s",$level;
output($thingof2);


output($hl."--------------------------------------------\003");
output("I USER        +$irevenge  (effects shown above)");
output("P OFFENDER    -$prevenge  (effects shown above)");
$thingof2 = sprintf "TIMEOUT     %4s  (revenge timeout)",$morktimeout;
output($thingof2);
if ($increaserevenge == 1) {$level = "ON";} else {$level = "OFF";}
$thingof2 = sprintf "INREVENGE  %5s  (Increase personal revenge on repeated kicks)",$level;
output($thingof2);

if ($clonenumberkick == 0) {$level = "OFF";} else {$level = $clonenumberkick;}
$thingof2 = sprintf "CLONES    %6s  (If X or more clones, act as above)",$level;
output($thingof2);

output(" ");
output("You can change the above settings with one of the following keywords : ");
output($hl."kick ban deop op unban mode revenge iuser puser timeout\003");
output($hl."inrevenge forceban clonekick clones\003");
output(" ");
output("\002NOTE: Mass modechange sensitivity is under $hl/flood \003 settings\002");
return 1;
}

$info2 = ";$info";
if ($info2 =~ /;KICK/i) {
$revengekick++;
if ($revengekick > 3) {$revengekick = 0;}
if ($revengekick < 0) {$revengekick = 0;}
$level = level($revengekick);
output("\002Kick revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;BAN/i) {
$revengeban++;
if ($revengeban > 3) {$revengeban = 0;}
if ($revengeban < 0) {$revengeban = 0;}
$level = level($revengeban);
output("\002Ban revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;DEOP/i) {
$revengedeop++;
if ($revengedeop > 3) {$revengedeop = 0;}
if ($revengedeop < 0) {$revengedeop = 0;}
$level = level($revengedeop);
output("\002DEOP revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;MODE/i) {
$revengemode++;
if ($revengemode > 3) {$revengemode = 0;}
if ($revengemode < 0) {$revengemode = 0;}
$level = level($revengemode);
output("\002Mass mode change revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;OP/i) {
$revengeopadeop++;
if ($revengeopadeop > 3) {$revengeopadeop = 0;}
if ($revengeopadeop < 0) {$revengeopadeop = 0;}
$level = level($revengeopadeop);
output("\002OP d user revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;VOICE/i) {
$revengevoiceanovoice++;
if ($revengevoiceanovoice > 3) {$revengevoiceanovoice = 0;}
if ($revengevoiceanovoice < 0) {$revengevoiceanovoice = 0;}
$level = level($revengevoiceanovoice);
output("\002VOICE q user revenge level ->\002$level\002<-\002");
return 1;
}

if ($info2 =~ /;CLONEKICK/i) {
$revengeclonenumberkick++;
if ($revengeclonenumberkick > 3) {$revengeclonenumberkick = 0;}
if ($revengeclonenumberkick < 0) {$revengeclonenumberkick = 0;}
$level = level($revengeclonenumberkick);
output("\002Clone revenge level ->\002$level\002<-\002");
return 1;
}


if ($info2 =~ /;UNBAN/i) {
$revengeunbanak++;
if ($revengeunbanak > 3) {$revengeunbanak = 0;}
if ($revengeunbanak < 0) {$revengeunbanak = 0;}
$level = level($revengeunbanak);
output("\002Unban k user revenge level ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;IUSER/i) {
$irevenge++;
if ($irevenge > 3) {$irevenge = 0;}
if ($irevenge < 0) {$irevenge = 0;}
output("\002Increase protection for i users by ->\002$irevenge\002<-\002");
return 1;
}
if ($info2 =~ /;PUSER/i) {
$prevenge++;
if ($prevenge > 3) {$prevenge = 0;}
if ($prevenge < 0) {$prevenge = 0;}
output("\002Decrease revenge against p users by ->\002$prevenge\002<-\002");
return 1;
}
if ($info2 =~ /;REVE/i) {
$revenge++;
if ($revenge > 3) {$revenge = 0;}
if ($revenge < 0) {$revenge = 0;}
$level = level($revenge);
output("\002Revenge if I get kicked from the channel ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;INREVE/i) {
$increaserevenge++;
if ($increaserevenge > 1) {$increaserevenge = 0;}
if ($increaserevenge < 0) {$increaserevenge = 0;}
if ($increaserevenge == 1) {
$level = "ON";
} else {
$level = "OFF";
}
output("\002Increase Revenge if I get kicked from the channel repeatedly ->\002$level\002<-\002");
return 1;
}
if ($info2 =~ /;FORC/i) {
$forceban++;
if ($forceban > 1) {$forceban = 0;}
if ($forceban < 0) {$forceban = 0;}
if ($forceban == 1) {
$level = "ON";
} else {
$level = "OFF";
}
output("\002Reban a k user ban if unbanned by someone ->\002$level\002<-\002");
return 1;
}

if ($info2 =~ /;TIME/i) {
if (!($extrainfo =~ /\d+/)) {
output("\002You need to enter a time in seconds...\002");
return 1;
}
$morktimeout = $extrainfo;
output("\002Setting revenge memory to ->\002$morktimeout\002<- seconds.\002");
return 1;
}

if ($info2 =~ /;CLONES/i) {
if (!($extrainfo =~ /\d+/)) {
output("\002You need to enter the clone limit...\002");
return 1;
}
$clonenumberkick = $extrainfo;
if ($clonenumberkick == 0) {
output("\002Setting clone kick off.\002");
} else {
output("\002Setting clone kick at ->\002$clonenumberkick\002<- clones.\002");
}
return 1;
}










goto helpishere;

return 1;
}


# logging of script actions  on / off
sub logactions
{

my $info = shift(@_);
@test3 = ("AG","FL","ST","FR","XD");
@test2 = ("AGGRESSIVE ACTIONS","FLOOD/IGNORES     ","STATUS/NORMAL     ","FRIENDLY ACTS     ","XDCC/PACKLISTS    ");
@test = split(';',$logtypes);
$t = 0;
@f = split(' ',$info);
foreach $tester (@test3) {
if ($f[0] =~ /$tester/i) {
if ($test[$t] =~ /3/) {
output("Setting $test2[$t] Logging to \002OFF\002");
$test[$t] = 0;
last;
}
if ($test[$t] =~ /2/) {
output("Setting $test2[$t] Logging to \002LOG AND SCREEN\002");
$test[$t] = 3;
last;
}
if ($test[$t] =~ /1/) {
output("Setting $test2[$t] Logging to \002LOG\002");
$test[$t] = 2;
last;
}
if ($test[$t] =~ /0/) {
output("Setting $test2[$t] Logging to \002SCREEN\002");
$test[$t] = 1;
last;
}
}
$t++;
}
$logtypes = $test[0].";".$test[1].";".$test[2].";".$test[3].";".$test[4];
output($hl."Current Log Settings : \002 \003");
$t = 0;
foreach $bah (@test) {
if ($bah == 3) {
$bah2 = $hl."LOG AND SCREEN \003";
} elsif ($bah == 2) {
$bah2 = $hl."LOG \003";
} elsif ($bah == 1) {
$bah2 = $hl."SCREEN \003";
} elsif ($bah == 0) {
$bah2 = "OFF";
}
output("\002".$test2[$t]." : ".$bah2."\002");
$t++;
}
output(" ");
output("\002Use$hl /scriptlog type \003 to change logging...\002");
output("\002eg \"$hl/scriptlog agg\003\" will change aggressive action logging...\002");
return 1;
}

# version on / off handler
sub setver
{

if ($versioning =~ /1/) {
output("Turning XDCC script version reply \002OFF\002");
$versioning = 0;
return 1;
}

if ($versioning =~ /0/) {
output("Turning XDCC script version reply \002ON\002");
$versioning = 1;
return 1;
}
output("Something wrong with version var $versioning");
return 1;
}


# logwin on / off handler
sub setlogwin
{

if ($lognowin =~ /1/) {
output("Message windows disabled when away\002OFF\002");
$lognowin = 0;
return 1;
}

if ($lognowin =~ /0/) {
output("Message windows disabled when away\002ON\002");
$lognowin = 1;
return 1;
}
return 1;
}


# xdcc file listing on / off handler
sub listmode {

if ($xdccflist =~ /1/) {
output("Turning xdcc file listing \002OFF\002");
$xdccflist = 0;
return 1;
}

if ($xdccflist =~ /0/) {
output("Turning xdcc file listing \002ON\002");
$xdccflist = 1;
return 1;
}
output("Config file corrupt!");
return 1;
}


# who_handler
sub who_handler {
  my $info = shift(@_);
if ($whoflag > 0) {
#  $info =~ /:(\S+) 352 (\S+) (#\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (:\S+) (.*)/;

@splitvar2 = split(' ',$info);


my $server = IRC::get_info(3);
my $mynick = IRC::get_info(1);

$mychan = $splitvar2[3];
$mynick2 = $splitvar2[7];
$myun = $splitvar2[4];
$myhn = $splitvar2[5];
$mymode = $splitvar2[8];
$compareme = stripn("$mynick2,,,$server,,,$splitvar2[3],,,$splitvar2[7],,,$splitvar2[4],,,$splitvar2[5]");
$compareme2 = stripn("$revengemask");
$compareme3 = stripn(",,,$mynick2,,,$server,,,");
$compareme4 = stripn(",,,$mynick,,,$server,,,");
$schan = stripn($mychan);

$mymodevoice = 0;
$mymodeop = 0;

if ($mymode =~ /\@/) {
$mymodeop = 1;
}
if ($mymode =~ /\+/) {
$mymodevoice = 1;
}
push @nicks, "$mynick,,,$server,,,$mychan,,,$mynick2,,,$myun,,,$myhn,,,$mymodeop,,,$mymodevoice";

$hostnm = "$mynick2!$myun\@$myhn";
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$chancmp = stripn($ho[0]);
if ($chancmp =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

$newcomment2 = $4;
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
if ($hostnm =~ /$rest/i) {
if ($flags =~ /k/i) {
sl(1,"\002Banning k flag user $nick on $mychan\002");
$banmask = banmask($hostnm);
push @mode, ("-o $mynick2","+b $banmask");
push @kick, ("$mynick2 $newcomment2");
chanaction("$mynick,,,$mychan,,,$server");
}
if ($mymodeop == 1) {
if ($flags =~ /d/i) {
sl(1,"\002Deopping d flag user $nick on $mychan\002");
push @mode, ("-o $mynick2");
chanaction("$mynick,,,$mychan,,,$server");
}
}

if (!($compareme3 =~ /$compareme4/i)) {
if ($mymodeop == 0) {
if ($flags =~ /o/i) {
sl(4,"\002Opping o flag user $nick on $mychan\002");
push @mode, ("+o $mynick2");
chanaction("$mynick,,,$mychan,,,$server");
}
}
if ($mymodevoice == 0) {
if ($flags =~ /v/i) {
sl(4,"\002Voicing v flag user $nick on $mychan\002");
push @mode, ("+v $mynick2");
chanaction("$mynick,,,$mychan,,,$server");
}
}
}
}
}
}
if ($newwhoflag > 0) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}


# end_who_handler
sub end_who_handler {
if ($whoflag > 0) {
$whoflag = $whoflag - 1;
if ($newwhoflag > 0) {
$newwhoflag = $newwhoflag - 1;
return 1;
} else {
return 0;
}
} else {
return 0;
}
}


sub byte_converter 
{
$line = shift(@_);
$totalmegsize2 = $line;
if ($totalmegsize2 > 1000000000000000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000000000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"." Yottabytes";
} elsif ($totalmegsize2 > 1000000000000000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000000000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"." Zettabytes";
} elsif ($totalmegsize2 > 1000000000000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"." Exabytes";
} elsif ($totalmegsize2 > 1000000000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"." Petabytes";
} elsif ($totalmegsize2 > 1000000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"."T";
} elsif ($totalmegsize2 > 1000000000) {
$totalmegsize2 = $totalmegsize2 / 1000000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"."G";
} elsif ($totalmegsize2 > 1000000) {
$totalmegsize2 = $totalmegsize2 / 1000000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"."M";
} elsif ($totalmegsize2 > 1000) {
$totalmegsize2 = $totalmegsize2 / 1000;
$totalmegsize2 =~ /(.*)\.(.*)/;
$begin = $1;
$end = (substr ($2, 0, 1));
$totalmegsize2 = "$begin.$end"."k";
} else {
$totalmegsize2 = $totalmegsize2."b";
}
return $totalmegsize2;
}

# output
sub output
{
$line = shift(@_);
if ($tabnicks =~ /1/) {
IRC::print "          | $line\n";
} else {
IRC::print "$line\n";
}
return 1;
}


# sl
sub sl
{
@line2 = @_;
$type = shift(@line2);
@test = split(';',$logtypes);
$check = $type - 1;


$logact = $test[$check];

foreach $line (@line2) {
$newtime = time;
($sec, $min, $hour, $monthday, $month, $year, $weekday, $yearday, $isdist) = localtime(time);

$len = length $min;
if ($len =~ /1/) {$min = "0"."$min";}
$month = $month + 1; 
if ($logact =~ /3/) {
if (open(SCRIPTL, ">>".$homepath.".xdcc/scriptlog")) {
print SCRIPTL ("$month/$monthday ::: $hour:$min ::: $line\n");
close (SCRIPTL);
if ($tabnicks =~ /1/) {
IRC::print "          | $line\n";
} else {
IRC::print "$line\n";
}
next;
}
}
if ($logact =~ /2/) {
if (open(SCRIPTL, ">>".$homepath.".xdcc/scriptlog")) {
print SCRIPTL ("$month/$monthday ::: $hour:$min ::: $line\n");
close (SCRIPTL);
next;
}
}
if ($logact =~ /1/) {
if ($tabnicks =~ /1/) {
IRC::print "          | $line\n";
} else {
IRC::print "$line\n";
}
next;
}
if ($logact =~ /0/) {
next;
}
}
return 1;
}




# ban
sub ban
{
my $line = shift(@_);
my $ro = 0;
my $server = IRC::get_info(3);
my $chan = IRC::get_info(2);
my $nick = IRC::get_info(1);
my @whats = split(' ',$line);
my @newwhats = @nothing;
my $banr = $nothing;
my @kick2 = @nothing;
my $check = 0;

foreach $grrty (@whats) {
if ($grrty =~ /.+\@.+/) {
push @mode, ("+b $grrty");

my $rest = $grrty;
my @test = split('!',$rest,2);
$rest = stripn($test[0])."!".stripn($test[1]);

$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;



my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
my $compare = stripn($lister[0])."!".stripn($lister[1]);

#IRC::print "$compare and $rest\n";
if (" $compare " =~ / $rest /i) {
sl(1,"\002Kicking $lister[0]!$lister[1] $hl($grrty)\003\002");
push(@kick2,"$lister[0]");
}
}
$ro = 1;
} else {
push @newwhats,($grrty);
}
}

@whats = @newwhats;

my $endpart = pop(@whats);
if (!($endpart =~ /\/w.*/i)) {
push @whats,($endpart);
}


if (!("@whats" =~ /\S+/)) {
if ($ro == 0) {
output("No Name Given!");
}
}


foreach $line (@whats) {
my $stuff = userhost("$line $chan $server");
my @splitvar3 = split(' ',$stuff);
$user = "$splitvar3[0]!$splitvar3[1]\@$splitvar3[2]";
$hmmm = $splitvar3[0];


if ($splitvar3[2] =~ /NOMATCH/) {
$check = 1;
}
if ($check == 1) {
#output("\002User \"$hl$line\003\" is not the nickbuffer\002");
if (!($line =~ /\/w/i)) {
$banr = $banr." ".$line;
}
next;
} else {
$banmask = banmask($user);
if ($endpart =~ /\/w.*/i) {
@splitvar4 = split('\@',$banmask);
$banmask = "*!*\@$splitvar4[1]";
}
push @mode, ("-o $hmmm","+b $banmask");
push @kick2, ("$hmmm");
}
}

if (!($banr)) {
$banr = $kickreason;
}

foreach $g (@kick2) {
push @kick, ("$g $banr");
}
chanaction("$nick,,,$chan,,,$server");
return 1;
}

# unload
sub unload
{
output("Unloading script");
IRC::command "/delbutton AddF";
IRC::command "/delbutton Ignore";
IRC::command "/delbutton Notify";
IRC::command "/delbutton WideBan";
IRC::command "/unloadall";
}




# chanlog
sub chanlog
{

my $chan = IRC::get_info(2);
my $server = IRC::get_info(3);

if (!($chan =~ /\S+/)) {
output("Not on a channel.");
return 1;
}
if ($channellog[0] ne "0") {
output("Logging $chan to $homepath$chan".".log");
@channellog = ($chan, $server);
if (open(CHANLOG, ">".$homepath.$channellog[0].".log")) {
print CHANLOG "Nicks on $channellog[0]($server) :\n\n";
foreach $testin (@nicks) {
$whyme = stripn($testin);

@splitvar5 =  split(',,,',$testin);


$hostferbud = "$splitvar5[3]($splitvar5[4]\@$splitvar5[5])";
$matchit45 = stripn("$splitvar5[2]$splitvar5[1]");
$showstat = $nothing;
$t4 = $splitvar5[6];
$t5 = $splitvar5[7];
if ($t4 == 1) {
$showstat = $showstat."@";
}
if ($t5 == 1) {
$showstat = $showstat."+";
}

if ($channellog[0] ne "0") {
$outs1 = stripn("$channellog[0]$channellog[1]");
if ($matchit45 =~ /$outs1/i) {
$thingof2 = sprintf "%2s $hostferbud",$showstat;
print CHANLOG "$thingof2\n";
}
}
##
}
print CHANLOG "\n";
close(CHANLOG);
} else {
output("Warning, couldn't open $homepath$channellog.log for some reason!");
$channellog[0]="0";$channellog[1] = "0";
}
return 1;
} else {
output("Stopped logging to $homepath$channellog".".log");
$channellog[0]="0";$channellog[1] = "0";
}
return 1;
}

# find list
sub list
{
$line = shift(@_);
if ($line =~ /force/i) {
IRC::command "/raw list";
return 1;
} else {
output("This command will list ALL THE CHANNELS ON THE SERVER!");
output("This can take eons, so this script has added the force");
output("keyword.  If you REALLY want to list all the servers,");
output("then use /list force");
return 1;
}
}



# gui
sub gui
{
#use Gtk;
#init Gtk;
#$main_window = new Gtk::Window -toplevel;
#$main_window->set_title("Samples for Perl/Gtk+");
#$win_main = MainWindow->new();
#$win_main->title ("XDCC Prefs");
#window
#MainLoop();
}

# banmask
sub banmask
{
$line = shift(@_);
$numeric = 0;
my @boot = split('\@',$line);
if (@boot > 1) {
my @boots = split('\.',$boot[1]);
@boot = reverse @boots;
if (!($boot[0] =~ /\D+/)) {
$numeric = 1;
}
if (!($line =~ /\!/)) {
$line = "*!$line";
}
$line =~ /.*!(.*)@(.*)/;
$username55 = $1;
$host55 = $2;
$username55 =~ s/~/\*/g;
if ($numeric == 1) {
$host55 =~ /(.*\..*\..*\.).*/;
$host55 = $1."*";
$banmask = "*!$username55\@$host55";
} else {
@testsi = split('\.',$host55);

if (@testsi > 2) {
shift (@testsi);
$host55 = "*";
} else {
$host55 = $nothinginhereman;
}
$tras = @testsi - 2;
if ($tras > 0) {
$torsa = 0;
book:
if (!($torsa == $tras)) {
$testsi[$torsa] =~ s/\d+/\*/g;
$torsa++;
goto book;
}
}
foreach $bhe (@testsi) {
if ($host55) {
$host55 = "$host55.$bhe";
} else {
$host55 = "$bhe";
}
}
$banmask = "*!$username55\@$host55";
}
} else {
$banmask = $line;
}
return ($banmask);
}



# banmask2
sub banmask2
{
$line = shift(@_);
$numeric = 0;
my @boot = split('\@',$line);
my @boots = split('\.',$boot[1]);
@boot = reverse @boots;
if (!($boot[0] =~ /\D+/)) {
$numeric = 1;
}
$line =~ /.*!(.*)@(.*)/;
$username55 = "\\W*$1";
$host55 = $2;
$username55 =~ s/\\~//g;
$username55 =~ s/~//g;
if ($numeric == 1) {
$host55 =~ /(.*\..*\..*\.).*/;
$host55 = $1."\\d+";
$banmask = "$username55\@$host55";
} else {
@testsi = split('\.',$host55);
if (@testsi > 2) {
shift (@testsi);
$host55 = ".+";
} else {
$host55 = $nothinginhereman;
}
$tras = @testsi - 2;
if ($tras > 0) {
$torsa = 0;
book:
if (!($torsa == $tras)) {
$testsi[$torsa] =~ s/\d+/\\\d\+/g;
$torsa++;
goto book;
}
}


foreach $bhe (@testsi) {
if ($host55 =~ /\S+/) {
$host55 = "$host55.$bhe";
} else {
$host55 = "$bhe";
}
}
$banmask = "$username55\@$host55";
}
return ($banmask);
}




# banmask3

sub banmask3
{
$line = shift(@_);
$numeric = 0;
my @boot = split('\@',$line);
my @boots = split('\.',$boot[1]);
@boot = reverse @boots;
if (!($boot[0] =~ /\D+/)) {
$numeric = 1;
}
$line =~ /.*!(.*)@(.*)/;
$username55 = "\\W*$1";
$host55 = $2;
$username55 =~ s/\\~//g;
$username55 =~ s/~//g;

if ($numeric == 1) {
$host55 =~ /(.*\..*\..*\.).*/;
$host55 = $1."\\d+";
$banmask = "$username55\@$host55";

} else {
@testsi = split('\.',$host55);
if (@testsi > 3) {
@testsi = reverse(@testsi);
@testsi = ($testsi[2],$testsi[1],$testsi[0]);
$host55 = ".+";
} elsif (@testsi > 2) {
@testsi = reverse(@testsi);
@testsi = ($testsi[1],$testsi[0]);
$host55 = ".+";
} else {
$host55 = $nothinginhereman;
}

$tras = @testsi - 2;
if ($tras > 0) {
$torsa = 0;
book:
if (!($torsa == $tras)) {
$testsi[$torsa] =~ s/\d+/\\\d\+/g;
$torsa++;
goto book;
}
}


foreach $bhe (@testsi) {
if ($host55 =~ /\S+/) {
$host55 = "$host55.$bhe";
} else {
$host55 = "$bhe";
}
}
$banmask = "$username55\@$host55";
}
return ($banmask);
}


# set dcc slots
sub slots
{
my $info = shift(@_);
my @info2 = split(":",$info);
$info = 0;
if ($info2[0] < $info2[1]) {$info = 2;}
if ($info2[0] == 0 || $info2[1] == 0) {$info = 2;}
if (@info2 < 2 || @info2 > 2) {$info = 1;}
if ("@info2" =~ /\D+ \D+/) {$info = 1;}


if (!($info2[0] =~ /\S+/)) {
output("\002Current number of slots\002 $dccslots:$maxslotsperuser\003");
return 1;
}
if ($info == 1) {
output("\002Use $hl<max slots\003:$hl"."max slots / user>\003");
output("eg $hl/slots 10:2\003 would set it to 10 total available");
output("slots, but only 2 / user.");
return 1;
}
if ($info == 2) {
output("\002Use $hl<max slots\003:$hl"."max slots / user>\003");
output("You can not have more user slots than total slots, and");
output("the number of each must be more than 0.  If you want");
output("to just have normal slots, set user slots and total slots");
output("to the same thing (eg /slots 10:10)");
return 1;
}

$dccslots = $info2[0];
$maxslotsperuser = $info2[1];

output("\002Current number of slots\002 $dccslots:$maxslotsperuser\003");
return 1;
}

# auto get files from +f on/off
sub autoget {

if ($fautogetdcc =~ /1/) {
output("Turning autoget from +f users \002OFF\002");
$fautogetdcc = 0;
return 1;
}

if ($fautogetdcc =~ /0/) {
output("Turning autoget from +f users \002ON\002");
$fautogetdcc = 1;
return 1;
}
output("Config file corrupt!");
return 1;
}

# ignore all but +f and chan messages on/off
sub ignoreall {
my $info = shift(@_);

if ($info =~ /ON/i || $info =~ //) {
if ($ignoreall =~ /0/) {
sl(1,"\002 Now ignoring everything but channel messages and +f users\002");


foreach my $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
my $nick = $1;
my $flags = $2;
my $rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
if ($flags =~ /f/i) {
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
IRC::command "/ignore $rest PRIV CTCP INVI NOTI unignore NOSAVE QUIET";
}
}
}
IRC::command "/ignore *!*@*.* PRIV CTCP INVI NOTI NOSAVE QUIET";
$ignoreall = 1;
return 1;
}
}

if ($info =~ /OFF/i || $info =~ //) {
if ($ignoreall =~ /1/) {
sl(1,"Ignore everything \002OFF\002");

foreach my $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
my $nick = $1;
my $flags = $2;
my $rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
if ($flags =~ /f/i) {
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
IRC::command "/unignore $rest QUIET";
}
}
}
IRC::command "/unignore *!*@*.* QUIET";
$ignoreall = 0;
return 1;
}
}
output("Config file corrupt!");
return 1;
}


sub slotcount 
{
#IRC::print "Mark2\n";
sl(5,"Test4 ... @qpacks"); ######
my @test = IRC::dcc_list;
my $rrr2 = 0;
my $holder = $nothingatall;
my @realhold = @nothing;

if (@outpacks == 0) {
$slotcount = 0;
foreach $t (@test) {
$holder = $holder.":::".$t;
$rrr2++;
if ($rrr2 > 8) {
push @realhold, $holder;
$rrr2 = 0;
$holder = $nothingatall;
}
# output("w : $t");
}
$timing = time;
my @packs2 = @packs;
@packs = @nothinghereman;
foreach $t1 (@packs2) {
sl(5,"Test5"); ######
$keepitclean = 0;
foreach $t (@realhold) {
$t =~ /:::(.*):::(.*):::(.*):::(.*):::(.*):::(.*):::(.*):::(.*):::(.*)/;
$type = $3;
$status = $4;
$cps = $5;
$pos = $6;
my $gfiler = quotemeta $1.":::".$2.":::";
$benick = $1;
$coolfile = $2;

$t2 = $t1;
$t2 =~ s/ /_/g;


if ($t2 =~ /$gfiler/) {
$t2 =~ /.*:::.*:::(\d+)/;
$checkthetime = $1;

if ($status =~ /0/) {
if (($timing - $checkthetime) > 180) {
output("\002DCC SEND timeout on file $coolfile to $benick\002");
IRC::command "/dcc close send $benick $coolfile";
} else {
$keepitclean = 1;
}

} elsif ($status =~ /1/) {
$keepitclean = 1;
} else {
if ($status =~ /3/) {
if ($maxcps < $cps) {
$maxcps = $cps;
output("New max cps record ->$cps<- set by $benick"); 
}
$totalsnagged = $totalsnagged + $pos; 
$convsnagged = byte_converter($totalsnagged);
}
IRC::command "/dcc close send $benick $coolfile";
}
last;

}

}
if ($keepitclean =~ /1/) {
$slotcount++;
push @packs, "$t1";
}

}
}

#####
my @hold = @nothing;
foreach my $check (@packs) {
my @or = split(':::',$check);
$check = quotemeta $or[0];
my $er = 0;
if (!("@hold" =~ /.*$check\,.*/i)) {
my $r = "@packs";
while ($r =~ /$check\:\:\:/g) { $er++ }
push @hold,("$or[0],$er");
}
}
@userslotcount = @hold;
@hold = @nothing;
foreach my $check (@qpacks) {
my @or = split(':::',$check);
$checkwq = quotemeta $or[0];
my $er = 0;
if (!("@hold" =~ /.*$checkwq\,.*/i)) {
my $r = "@qpacks";
while ($r =~ /$checkwq/g) { $er++ }
push @hold,("$or[0],$er");
}
}
@userslotcountq = @hold;


#IRC::print "@hold\n";
return $slotcount;
}


# kicker
sub kicker
{
my $line = shift(@_);
my $chan = IRC::get_info(2);

@hold = split(/\s/,$line,2);

$namer = shift(@hold);
$reasonbe = "@hold";

if (!($reasonbe =~ /\S+/)) {
IRC::command "/raw kick $chan $line :$kickreason"; 
return 1;
}
IRC::command "/raw kick $chan $namer :$reasonbe"; 
return 1;
}
# wallop
sub wallop
{
$wallopmessage = shift(@_);
@wallopr = @nothing;
my $chan = IRC::get_info(2);
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);
my $mynick2 = stripn(":::".$mynick.":::");


my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   
foreach $g (@boo) {
my @lister = split(' ',$g);
if ($lister[2] == 1) {
push @wallopr,("$lister[0]");
}
}

push @wallopto,("@wallopr".";;;$server;;;$wallopmessage");
output("\002Sending \"".$hl.$wallopmessage."\003\" to"." @wallopr\002");
return 1;
}

# set flood
sub flood
{
my $info = shift(@_);
my $server = IRC::get_info(3);
@floodmsgnumber = split (':',$floodmsgnum);
@floodchannumber = split (':',$floodchannum);
@floodctcpnumber = split (':',$floodctcpnum);
@floodnotinumber = split (':',$floodnotinum);
@floodmodenumber = split (':',$floodmodenum);
@floodmassnumber = split (':',$floodmassnum);

if ($info =~ /on/i) {
output("\002Turning flood protection$hl ON \003\002");
$isfloodon = 1;
return 1;
}
if ($info =~ /off/i) {
output("\002Turning flood protection$hl OFF \003\002");
$isfloodon = 0;
return 1;
}
if ($info =~ /t/i) {
if ($isfloodon == 1) {
output("\002Turning flood protection$hl OFF \003 for 60 seconds.\002");
$isfloodon = 0;
$time = time;
$timetohappen = $time + 60;
push @delayedcommand, ($timetohappen.";;;".$server.";;;"."/flood on");
return 1;
} else {
output("\002Flood protection is already$hl OFF \003\002");
return 1;
}
}

if (!($info =~ /\w/)) {
if ($isfloodon == 1) {
$wordit = "ON";
} else {
$wordit = "OFF";
}
output("\002".$hl."Set flood protection with :\003(# of messages):(# of seconds)\002");
output(" ");
output("\002 $hl             CHAN  PRIV   CTCP   NOTICE MODE \003 \002");
output("\002eg --> /flood 10:60 10:120 10:120 10:120 4:20");
output(" ");
output("\002$hl"."Current Settings :\002 \003");
output("\002".$hl."Flood Protection is\003  $wordit \002");
output("\002Channel >$hl $floodchannumber[0] \003 messages in$hl $floodchannumber[1] \003 seconds\002");
output("\002Private >$hl $floodmsgnumber[0] \003 messages in$hl $floodmsgnumber[1] \003 seconds\002");
output("\002CTCP    >$hl $floodctcpnumber[0] \003 messages in$hl $floodctcpnumber[1] \003 seconds\002");
output("\002NOTICE  >$hl $floodnotinumber[0] \003 messages in$hl $floodnotinumber[1] \003 seconds\002");
output("\002MODE    >$hl $floodmodenumber[0] \003 mode changes in$hl $floodmodenumber[1] \003 seconds\002");
output("\002MASS    >$hl $floodmassnumber[0] \003 ctcp's in$hl $floodmassnumber[1] \003 seconds is a mass host flood\002");
return 1;
} else {
$info =~ /(\d+):(\d+) (\d+):(\d+) (\d+):(\d+) (\d+):(\d+) (\d+):(\d+)/; 
@glob = split(' ',$info);
$x = 0;
do {
if (!($glob[$x] =~ /\d+:\d+/)) {
output("\002".$hl."Set flood protection with :\003(# of messages):(# of seconds)\002");
output(" ");
output("\002 $hl             CHAN  PRIV   CTCP   NOTICE MODE MASS\003 \002");
output("\002eg --> /flood 10:60 10:120 10:120 10:120 4:20 4:20");
return 1;
}
$x++;
} while ($x < 5);

$floodchannum = "$glob[0]";
$floodmsgnum = "$glob[1]";
$floodctcpnum = "$glob[2]";
$floodnotinum = "$glob[3]";
$floodmodenum = "$glob[4]";
$floodmassnum = "$glob[5]";
@floodmsgnumber = split (':',$floodmsgnum);
@floodchannumber = split (':',$floodchannum);
@floodctcpnumber = split (':',$floodctcpnum);
@floodnotinumber = split (':',$floodnotinum);
@floodmodenumber = split (':',$floodmodenum);
@floodmassnumber = split (':',$floodmassnum);
output("\002".$hl."Current Flood Settings :\002 \003");
output("\002Channel >$hl $floodchannumber[0] \003 messages in$hl $floodchannumber[1] \003 seconds\002");
output("\002Private >$hl $floodmsgnumber[0] \003 messages in$hl $floodmsgnumber[1] \003 seconds\002");
output("\002CTCP    >$hl $floodctcpnumber[0] \003 messages in$hl $floodctcpnumber[1] \003 seconds\002");
output("\002NOTICE  >$hl $floodnotinumber[0] \003 messages in$hl $floodnotinumber[1] \003 seconds\002");
output("\002MODE    >$hl $floodmodenumber[0] \003 mode changes in$hl $floodmodenumber[1] \003 seconds\002");
output("\002MASS    >$hl $floodmassnumber[0] \003 mode changes in$hl $floodmassnumber[1] \003 seconds\002");
return 1;
}
}


# unban_handler
sub unban_handler {

my $info = shift(@_);
if ($unbanmask) {
  $info =~ /:(\S+) 367 (\S+) (#\S+) (\S+) (\S+) (\S+)/;
my $userbanned = $5;
my $theban = $4;
my $mychan2 = $3;
my $myserver2 = $1;
my $mynick = IRC::get_info(1);
if (@unbanlast > 15) {
shift @unbanlast;
}
if (@evilban2 > 0) {
my $clearban = quotemeta $theban;
foreach $comptheban (@unbanlast) {
if (" $comptheban " =~ / $clearban /i) {
goto bottom;
}
}
my $compare2 = quotemeta $userbanned;
if (" $mynick " =~ / $compare2 /i) {
$skipbancount++;
if ($skipbancount < 10) {
goto bottom;
}
}
$evilban = shift(@evilban2);
if (!("@evilban2" =~ /\S+/)) {
$unbanmask = $nothingman;
}
IRC::command "/raw mode $mychan2 -b $theban";
push @unbanlast,($theban);
IRC::command "/raw mode $mychan2 +b $evilban";
$skipbancount = 0;
bottom:
$didiunban = 1;
} else {
my $comparethings1 = stripn(" $mychan2,,,$myserver2,,,$theban ");
my $comparethings2 = stripn(" $unbanmask ");
if ($comparethings1 =~ /$comparethings2/i) {
push @banlisting, "-b $theban"; 
$didiunban = 1;
}
}
return 1;
} else {
if ($didiunban) {
return 1;
} else {
return 0;
}
}
}


# unban_end_handler
sub unban_end_handler {
if ($unbanmask) {
$unbanmask = $nothingman;
@mode = @banlisting;
$coolest = "@banlisting";
$coolest =~ s/\-b //g;
#output("\002Removing :\002$hl $coolest\003");
@banlisting = @nothinghereman;
chanaction("$nickunban,,,$chanunban,,,$serverunban");
$chanunban = $nothing;
$serverunban = $nothing;
$nickunban = $nothing;
if ($didiunban =~ /0/) {
output("\002Sorry, nothing matches your banmask!\002");
}
return 1;
} else {
if ($didiunban) {
$didiunban = 0;
return 1;
}
return 0;
}
}

# unban2
sub unban2
{
my $line = shift(@_);
my $server = IRC::get_info(3);
my $chan = IRC::get_info(2);
my $nick = IRC::get_info(1);

if ($line =~ /\S+/) {
if (!($line =~ /\@|\*|\?/)) {
$line = "*".$line."*";
}
$line =~ s/\?/./g;
$line =~ s/\*/.*/g;
$unbanmask = "$chan,,,$server,,,$line";
$chanunban = $chan;
$serverunban = $server;
$nickunban = $nick;
$didiunban = 0;
IRC::command_with_server ("/raw mode $chan +b",$server);
} else {
output("Sorry, you must enter a pattern to unban!");
}
return 1;
}

# mdeop
sub mdeop
{
$line5 = shift(@_);
my $server = IRC::get_info(3);
my $chan = IRC::get_info(2);
my $mynick = IRC::get_info(1);
my $mynick2 = stripn(":::".$mynick.":::");
#@mode = @nothing;
$wallopto = $nothing;
$schan = stripn($chan);









my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   

foreach $g (@boo) {
my @lister = split(' ',$g);
$anop = $lister[2];
$wallopname = $lister[0];
$wallop2 = stripn(":::".$lister[0].":::");
$from = "$lister[0]!$lister[1]";

$isfriend = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;

@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$chancmp = stripn($ho[0]);
if ($chancmp =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
$tryit = stripn($from);
$rest2 = stripn($rest);
if ($tryit =~ /$rest2/i) {
$isfriend = 1;
$newflags = $flags;
$newnick = $nick;
last;
}
}
}
if ($isfriend =~ /1/) {
$flags = $newflags;
$nick = $newnick;
} else {
$flags = $nothing;
$nick = $nothing;
}

$watchit = 0;
if ($line5 =~ /fr.*/i) {
if ($isfriend =~ /1/) {
if ($flags =~ /p|o|f|i/i) {
$watchit = 1;
}
}
} elsif ($line5 =~ /all/i) {
} else {
output("\002Use \"ALL\" for all ops or \"FR\" to leave friends opped \(any of oipf\)");
return 1;
}

if ($anop =~ /1/) {
if (!($mynick2 =~ /$wallop2/i)) {
if ($watchit =~ /0/) {
push @mode, "-o $wallopname";
$wallopto = $wallopto." ".$wallopname;
}
}
}
}
if ("@mode" =~ /.+/) {
chanaction("$mynick,,,$chan,,,$server");
output("\002Deopping\002$hl$wallopto\003");
} else {
output("\002No one to deop!\002");
}
return 1;
}



# timer_handler
sub timer_handler
{
#IRC::print "Mark : ";
@test6 = IRC::channel_list;
$blahschans = "@test6";
$blahschans =~ s/ \#/;;;\#/g;
@wowchanthing = split (';;;',$blahschans);

$clock = time;


##
## use trace to see if my nick is free?

if ($grabnick == 1) {
if (@nickcheck > 0) {
if ($lastnickchecktime < $clock) {
$lastnickchecktime = $clock + 30;
my @holdnickcheck = @nothing;
my $bleh = "bah";
foreach my $erg (@nickcheck) {
my @g = split(' ',$erg);
my $tryserver = quotemeta $g[1];
foreach $moviechan (@wowchanthing) {
my @blueface = split (' ',$moviechan);
my $server2 = $blueface[1];
if (" $server2 " =~ / $tryserver /i) {
my $boo = quotemeta $mynick2;
if (!($bleh =~ /.*$tryserver.*/i)) {
if (!(" $g[0] " =~ / $boo /i)) {
$bleh = "$bleh$g[1]";
IRC::command_with_server("/raw trace $g[0]",$server2);
push @holdnickcheck,("$g[0] $g[1]");
}
}
}
}
}
@nickcheck = @holdnickcheck;
}
}
}





##
## cycle a channel for ops?
if ($cycleforop == 1) {
foreach $moviechan (@wowchanthing) {
my @blueface = split (' ',$moviechan);
my $chans = $blueface[0];
my $serverat = $blueface[1];
$amiop = amiop("$chans $serverat");
if ($amiop) {next;}
my @boos = IRC::user_list ( $chans, $serverat );
my @boo = split(': ',"@boos");
if (@boo == 1) {
sl(3,"Cycling $hl$chans\002 to gain ops");
IRC::command_with_server("/raw part $chans",$serverat);
IRC::command_with_server("/raw join $chans",$serverat);
}
}
}

####### check ignore list for left over ignores 
####### from the script
if ($ignoreall == 1) {
my @df = IRC::ignore_list;

my @f = split(':',"@df");
foreach $t (@f) {
}

}




###### slow out to stop floods

if ("@rawout" =~ /\S+/) {
my $gr = @rawout;
if ($gr > $outputlimit) {
$gr = $outputlimit;
}
for ($x = 0; $x < $gr; $x++) {
my $pusher = shift(@rawout);
my @push = split(' ',$pusher,2);
IRC::command_with_server($push[1],$push[0]);
}
}

### check if stealver timed out
if ($getverinfo[0] ne "0") {
if ($getverinfo[1] < $clock) {
if ("@stealversion2" =~ /\S+/) {
output("\002Successfully grabbed version info from $hl$getverinfo[0]\002\003");
my $putithere = "";
foreach $ugh32 (@stealversion2) {
chomp $ugh32;
$putithere = $putithere.$ugh32."<cr>";
}
chop $putithere;chop $putithere;chop $putithere;chop $putithere;
push @stealversion,("$putithere");
@stealversion2 = @nothing;
} else {
output("\002Didn't find any version info from $hl$getverinfo[0]\002\003");
}
$getverinfo[0] = "0";
} 
}

#### check channels
if ($channellistcheck < $clock) {
$channellistcheck = $clock + 16;

@listhold = @nothing;
@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;

@wow = split (';;;',$boot);
foreach $wowit (@listofjoinedchannels) {
$gr = 0;
$wowsit = stripn($wowit);

foreach $boot (@wow) {
@manofchan = split (' ',$boot);
$compthing = stripn("$manofchan[0],,,$manofchan[1],,,$manofchan[2]");


if (" $wowsit " =~ / $compthing /i) {
#$gr = 1;
push @listhold,($wowit);
}
}

#if ($gr == 0) {
#@holdnick = @nothing;
#foreach $wowh (@nicks) {
#$boota = stripn($wowh);
#@grrs = split(',,,',$wowsit);
#if ($boota =~ /$grrs[2],,,$grrs[1],,,$grrs[0],,,/i) {
#} else {
#push @holdnick,($wowh);
#}
#}
#@nicks = @holdnick;
#}
}
@listofjoinedchannels = @listhold;
}




### save seen list
if ($seenliststore == 1) {
if ($seenlistsavetime < $clock) {
if (!(open(SEENLIST, ">".$homepath.".xdcc/seenlist"))) {
output("Couldn't open seenlist!!  Fix it!!");
goto blahs;
}

foreach $blahblah (@seenlist) {
print SEENLIST ("$blahblah;");
}
#output("\002Saved seenlist!\002");
close(SEENLIST);
$seenlistsavetime = $clock + 300;
}
}
blahs:



##### check servers
#IRC::print "sdfsdf $watchserver\n";
if ($watchserver =~ /\S+/) {
$onthisserver = 0;
$t2 = stripn($watchserver);
$t4 = IRC::get_info(3);
$t4 = stripn($t4);
@tests = IRC::server_list;
#IRC::print "$t4 and $t2 and $onthisserver\n";
foreach $tee (@tests) {
$t1 = stripn($tee);
#IRC::print "its $t1 and $tee\n";
foreach $t (@serverlist) {
#IRC::print "$t as well\n";
@c = split(/;;;;;/,$t);
$r1 = stripn($c[1]);
$r2 = stripn($c[0]);
#IRC::print "$t1 = $t2  or \($r1 = $t1 and $r2 = $t2\)\n";
if (($r1 =~ /$t1/i && $r2 =~ /$t2/i) || $t1 =~ /.+$t2.+/i) {
#IRC::print "OK\n";
$onthisserver = 1;
$attempttoconnect = 0; 
$oldserver = $c[1];
$timestried = @serverlist;
last;
}
}
}
if ($jumpserver == 1) {
$attempttoconnect = 11;
$onthisserver = 0;
$jumpserver = 0;
}
#IRC::print "Delay?  $onthisserver and $attempttoconnect\n";
if ($onthisserver == 0) {
$attempttoconnect++;
if ($attempttoconnect > 10) {
if ($servnum) {$servnumtest = $servnum;} else {$servnumtest = 0;}
hereweare:
@c = split(/;;;;;/,$serverlist[$servnumtest]);
$servnumtest++;
$timestried = $timestried - 1;
if ($timestried < 0) {
output("\002Couldn't find server group matching $hl$watchserver\003!!!\002");
output("\002Use \"$hl/autoconnect set <word_that_matches_a_server_comment>\003\"\002");
output("\002Then do a \"$hl/savec\003\" to save your config!\002");
$attempttoconnect = 0; 
$timestried = @serverlist;
goto endit;
}
if ($servnumtest >= @serverlist) {$servnumtest = 0;}
$r2 = stripn($c[0]);
if (";;$t2;;" =~ /;;$r2;;/i) {
if (!(";;$c[1];;" =~ /;;$t4;;/i)) {
$servnum = $servnumtest;
sl(3,"\002Trying server $c[1] port $c[2]\002");
$timestried = @serverlist;
IRC::command ("/server $c[1] $c[2]");
#$timetohappen = $clock + 30;
$channeltojoin = $c[3];
$attempttoconnect = 0; 
goto endit;
}
}
goto hereweare;
}
}
}
endit:


###### wallop send
if ("@wallopto" =~ /\S+/) {
$testme = shift(@wallopto);
@splitit = split(';;;',$testme,3);
$wall = shift(@splitit);
@walls = split(' ',$wall);
$server55a = shift(@splitit);
$wallopmessage = shift(@splitit);
$sendnumber = length($wallopmessage);
if ($sendnumber > 25) {
$sendnumber = (1 / ($sendnumber / 25)) * 10;
} else {
$sendnumber = 6;
}
$t = 0;
@wallopto2 = @walls;
foreach $wallopname (@walls) {
IRC::command_with_server ("/raw notice $wallopname :[WALLOP] $wallopmessage",$server55a); 
shift(@wallopto2);
$t++;
if ($t > $sendnumber) {
last;
}
}
if ("@wallopto2" =~ /\S+/) {
unshift(@wallopto,"@wallopto2".";;;$wallopmessage");
}	
}


##########


### ping keepalive thing
#$pingcheck++;
#if ($pingcheck > 6) {
#if ($sentping == 1) {
##output("\002Server Ping Timeout!\002");
#}
#$pingcheck = 0;
#@testblah = @wowchanthing;
#$moviechan = shift(@testblah);
#@blueface = split (' ',$moviechan);
#$server = $blueface[1];

#output("Pinging $server!");
#IRC::command_with_server ("/raw PING $server",$server);
#$sentping = 1;
#}
##############

### speak kick removal?
if ("@speakkick" =~ /\S+/) {
@brr = @nothing;
foreach $boos (@speakkick) {
@wee = split(';;;',$boos);
if ($wee[0] < $clock) {
output("\002Speak kick on $wee[1] timed out, removing.\002");
@ggg = split(',,,',$boos);
IRC::command_with_server("/raw notice $ggg[2] :Speak kick on \002$boogsta\002 is over.",$ggg[1]);
} else {
push @brr,($boos);
}
}
@speakkick = @brr;
}


## delayed command

if ("@delayedcommand" =~ /\S+/) {
@holddelay = @nothinghere;
foreach $dothis (@delayedcommand) {
@donow = split(';;;',$dothis);
if ($donow[0] < $clock) {
if ($donow[1] =~ /\S+/) {
IRC::command_with_server("$donow[2]",$donow[1]);
} else {
IRC::command("$donow[2]");
}

} else {
push @holddelay, ($dothis);
}
}
@delayedcommand = @holddelay;
}
## try to join a channel?

if (@joinchannel > 0) {
$trytojoin++;
if($trytojoin > 6) {
$trytojoin = 0;
foreach $dothis (@joinchannel) {
@donow = split(';;;',$dothis);
IRC::command_with_server("/raw join $donow[0]",$donow[1]);
}
@joinchannel = @nothing;
}
}


### time to send a queued pack?

#my $me = @outpacks;
#IRC::print "outpacks $me and @outpacks\n";

if (@outpacks == 0) {
if (@qpacks > 0) {
   sl(5,"Test1 ... @qpacks"); ######

  $slotnum = slotcount;
  my $freespots = $dccslots - $slotnum;
  if ($freespots > 0) {
  $timing = time;
  my @outdude = @nothing;

  foreach my $wowa (@userslotcount) {
  my @art = split(",",$wowa);
  my $tot = $maxslotsperuser - $art[1];
  for ($tot2 = 0; $tot2 < $tot ; $tot2++) {$freespots--;}
  if ($tot2 > 0) {push @outdude,("$art[0],$tot");}
 }

  while (@userslotcountq > 0) {
  my $ra = shift(@userslotcountq);
  my @art = split(",",$ra);
  my $checka = quotemeta $art[0];
  if (!("@userslotcount" =~ /$checka\,/i)) {
  my $numslotsforme = $freespots;
  if ($numslotsforme > $maxslotsperuser) {$numslotsforme = $maxslotsperuser;} 
  if ($numslotsforme > $art[1]) {$numslotsforme = $art[1];} 
  push @outdude,("$art[0],$numslotsforme");
  $freespots = $freespots - $numslotsforme;
  }
  }    

#IRC::print "Out : @outdude\n";
#
  foreach my $holdout (@outdude) {
   sl(5,"Test2 ... @qpacks"); ######
  my @newqpacks = @nothinghereman;
  my $counter = @qpacks;
  my @st = split(',',$holdout);

  while ($st[1] > 0) {
   sl(5,"Test3"); ######
  $thenick = quotemeta $st[0];
  my $holdpack = shift(@qpacks);
  $counter--;
  if ($holdpack =~ /$thenick\:\:\:/i) {
  $st[1]--;
  $holdpack =~ /(.*):::(.*):::.*:::(.*)/;

  push @outpacks,($1.":::".$2.":::".$3);

  } else {
  IRC::print "aaah : $holdpack\n";
  push @newqpacks,($holdpack);
  }
  if ($counter < 1 || $st[1] < 1) {
  unshift @qpacks,(@newqpacks);
  last;
  }
  }
  }
IRC::print "@qpacks\nsss";


}
}
}
#########

### xdcc noti stuff
# noti on and time check 

if ($xdccstat == 1) {
if ($xdccon == 1 | $xdccon == 2) {


@chanlist = split (' ',$notichannels);
$t = 0;

foreach $channel (@chanlist) {
foreach $moviechan (@wowchanthing) {
@blueface = split (' ',$moviechan);
$chans = $blueface[0];
my $serverout = $blueface[1];
my $mynicker = $blueface[2];
$comp1 = stripn(";;;;".$chans.";;;;");
$comp2 = stripn(";;;;".$channel.";;;;");

if ($comp1 =~ /$comp2/i) {

if (!($gotime[$t] =~ /\w/)) {
output("Note : $channel didn't have a noti time, setting");
$gotime[$t] = $clock-1;
}
if ($xdccpublistmethod == 1) {
$chanoutputthing = "PRIVMSG";
} else {
$chanoutputthing = "NOTICE";
}

if ($clock > $gotime[$t]) {
if ($mess =~ /\w/) {
push @rawout,("$serverout /raw $chanoutputthing $chans :$mess");
output("$mess $hl\003");
}

$slotnum = slotcount;
$openslots = $dccslots - $slotnum;

if ($xdccon == 2) {
push @rawout,("$serverout /raw $chanoutputthing $chans :\002$packs\002 Pack(s) / $totalmegsize Offered! / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002]");
output("\002$packs\002 Packs / $totalmegsize Offered! / SECURITY [\002ON\002] / MaxCPS [\002$maxcps\002] $hl(to $chans)\003");
} else {
push @rawout,("$serverout /raw $chanoutputthing $chans :\002$packs\002 Pack(s) / $totalmegsize Offered! / SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002]");
output("\002$packs\002 Packs / $totalmegsize Offered! / SECURITY [\002OFF\002] / MaxCPS [\002$maxcps\002] $hl(to $chans)\003");
}
  $slotnotice = "slots";
  if ($openslots == 1) {
  $slotnotice = "slot";
  }

push @rawout,("$serverout /raw $chanoutputthing $chans :\002\"\002/ctcp $mynicker XDCC list\002\" for packlist\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged");
output("\002\"\002/ctcp $mynicker XDCC list\002\" for packlist\002 / [\002$openslots\002] $slotnotice free / \002$convsnagged\002 Snagged $hl\003");
$gotime[$t] = $clock + $waittime;
}
#}
$t = $t+1;
}
}
}
}
}
###########
#### amsg check

if ($amsgon == 1) {
if ($clock > $amsgtime) {
foreach $channel (@amsglist) {
$channel =~ /(\S+) (\S+) (.*)/;
output("channel $channel 1 = $1 2 = $2");
$putmess = $3;
my $server = $2;
$wherechan = $1;
if ($wherechan =~ /\.all\./i) {
$server = IRC::get_info(3);

@test = IRC::channel_list;
output("@test");
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);

if ($xdccpublistmethod == 1) {
$chanoutputthing = "PRIVMSG";
} else {
$chanoutputthing = "NOTICE";
}

foreach $boot2 (@wow) {
@manofchan = split(' ',$boot2);
push @rawout,("$manofchan[1] /raw $chanoutputthing $manofchan[0] :$putmess");
}
output("\002all channels->\002$putmess");
} elsif ($putmess =~ /.+/) {
push @rawout,("$server /raw $chanoutputthing $wherechan :$putmess");
output("\002$wherechan->\002$putmess");
}

}
$amsgtime = $clock + $amsgwaittime;
}
}
############


# workaround kludge for return function in dcc autoget
while (@dccdude > 0) {
$wowdccdude = shift(@dccdude);
@hrm54 = split(' ',$wowdccdude);
IRC::command_with_server("/dcc get $hrm54[0] $hrm54[2]",$hrm54[1]);
output("\002Auto receiving file $hrm54[2] from $hrm54[0]\002");
}
#####
IRC::add_timeout_handler(4000, "timer_handler");
return 0;
}

sub check_dcc_get {

my $nick = shift(@_);
my $blahs = shift(@_);
my $server = shift(@_);

#######
$matchingit = quotemeta $nick.":::".$blahs.":::"; 

foreach my $checkferstuff (@packs) {
if ($checkferstuff =~ /$matchingit/i) {
output("\002$nick tried to re-request a file\002");
push @rawout,("$server /raw NOTICE $nick :That file is already being offered to you!");
return 1;
}
}
foreach my $checkferstuff (@qpacks) {
if ($checkferstuff =~ /$matchingit/i) {
output("\002$nick tried to request a file that's already queued!\002");
push @rawout,("$server /raw NOTICE $nick :You already have that file queued!");
return 2;
}
}
#######
return 0;
}

# dcc_send_handler (sends files out slowly)
sub dcc_send_handler
{
#sl(5,"Woha");
#IRC::print "@outpacks\n";
if (@outpacks > 0) {
IRC::print "Mark\n";
   sl(5,"Test8"); ######
##$slotnum = slotcount;
$timing = time;
$boobread = 0;
$blahker = pop(@outpacks);
@betthings = split(':::',$blahker);
$nick = $betthings[0];
$blahs = $betthings[1];
my $server = $betthings[2];



sl(5,"Here we are");
IRC::command_with_server("/dcc send $nick \"".$blahs."\"",$server);
push @packs, ($nick.":::".$blahs.":::".$timing);

sl(5,"Sending $blahs to $nick");


IRC::add_timeout_handler(300, "dcc_send_handler");
} else {
IRC::add_timeout_handler(5000, "dcc_send_handler");
}
return 0;
}


# ignore
sub ignore
{
$line = shift(@_);
if (!($line =~ /\S+/)) {
ignorelist:
output(" ");
output("Current ignore list is :");
output("# PRIV  CHAN  CTCP  NOTICE  HOST");
output("$hl- ----  ----  ----  ------  ----\003");
$counting = 0;
foreach $bler (@ignorelist) {
@bahs = split(' ',$bler);
$t = 0;
until ($t == 4) {
$bahs[$t] =~ s/1/YES/g;
$bahs[$t] =~ s/0/NO/g;
$t++;
}
$counting++;
$thingof2 = sprintf "$counting %4s  %4s  %4s  %6s  $bahs[4]",$bahs[0],$bahs[1],$bahs[2],$bahs[3];
output($thingof2);
}
return 1;
}


@input = split(' ',$line);

if ($input[0] =~ /save/i) {
if (!(open(IGNOREFILE, ">".$homepath.".xdcc/ignorelist"))) {
output("Couldn't open ignore list!!");
return 1;
}
output("\002Saved Ignore list!\002");

foreach $blahblah (@ignorelist) {
print IGNOREFILE ("$blahblah;;;");
}
close(IGNOREFILE);

return 1;
} elsif ($input[0] =~ /load/i) {

if (!(open(IGNOREFILE, $homepath.".xdcc/ignorelist"))) {
output("\002No ignore list found!\002");
return 1;
}

$list = <IGNOREFILE>;

@ignorelist = split(';;;',$list);

close(IGNOREFILE);

output("\002Ignore list loaded!\002");

return 1;
} elsif ($input[0] =~ /del/i) {
$freeth = 0;
$gr = 0;
@holdignore = @nothing;
foreach $beeface (@ignorelist) {
$freeth++;
if ($input[1] =~ /$freeth/) {
@gets = split(' ',$beeface);
output("\002Removed ignore on $gets[4]\002");
$gr = 1;
} else {
push @holdignore, ($beeface);
}
}
if ($gr =~ /1/) {
@ignorelist = @holdignore;
} else {
$gr = 0;
@holdignore = @nothing;

foreach $beeface (@ignorelist) {
@checkthingsout = split(' ',$beeface);
$ctout = stripn($checkthingsout[4]);
$ctout2 = stripn($input[1]);
$ctout =~ s/\*/minussign/g;
$ctout =~ s/\?/minussign2/g;
$ctout2 =~ s/\*/minussign/g;
$ctout2 =~ s/\?/minussign2/g;
if ($ctout2 =~ /$ctout/) {
$gr = 1;
} else {
push @holdignore, ($beeface);
}
}
if ($gr =~ /1/) {
@ignorelist = @holdignore;
output("\002Deleted ignore on $input[1]\002");
} else {
output("\002No ignore on $input[1] to remove\002");
}
}
return 1;
} elsif (!($input[0] =~ /\@/i)) {
my $server4 = IRC::get_info(3);
my $chan4 = IRC::get_info(2);
my $mynick4 = IRC::get_info(1);
my $checkit4 = stripn("$mynick4,,,$server4,,,$chan4,,,$input[0],,,");
$boogsta = $input[0];
my $hoster = userhost("$boogsta $chan4 $server4");
my @bah = split(' ',$hoster);
if (!($hoster =~ /NOMATCH/i)) {
$mask4 = "*!$bah[1]\@$bah[2]";
$input[0] = banmask($mask4);
output($hl."$boogsta\'s\003 \002 hostmask is\002$hl $input[0]\003");
} else {
output("\002Enter ignore mask, and type.. eg : \002");
output("\002/ignore *!annoying@*.person.com priv chan noti ctcp\002");
output("\002/ignore NICK all\002");
output("\002If a nick was entered, and not found, maybe the userlist\002");
output("\002hasn't been buffered yet, try again!\002");
return 1;
}

}
my $grte = 0;
my $one = 0;
my $two = 0;
my $three = 0;
my $four = 0;

foreach $gooey (@input) {
my $gooey2 = stripn($gooey);
if ($gooey2 =~ /priv/i) {
$one = 1;
$grte = 1;
}
if ($gooey2 =~ /chan/i) {
$two = 1;
$grte = 1;
}
if ($gooey2 =~ /ctcp/i) {
$three = 1;
$grte = 1;
}
if ($gooey2 =~ /noti/i) {
$four = 1;
$grte = 1;
}
if ($gooey2 =~ /all/i) {
$one = 1;
$two = 1;
$three = 1;
$four = 1;
$grte = 1;
last;
}
}
if ($grte =~ /0/) {
output("\002Enter ignore mask, and type.. eg : \002");
output("\002/ignore *!annoying@*.person.com priv chan noti ctcp\002");
return 1;
}
push @ignorelist, "$one $two $three $four $input[0]";
goto ignorelist;
return 1;
}


# set ignoretime
sub ignoretime
{
my $info = shift(@_);

if (!($info =~ /\d+/)) {
output("\002Current ignore timout is :\002 $ignoretimeout \002seconds\002");
return 1;
} else {

$ignoretimeout = $info;
output("\002Default ignore timeout set to -->$ignoretimeout<-- seconds.\002");
return 1;
}
}

# set skick
sub skick
{
my $info = shift(@_);
@input = split(' ',$info);
if ($input[0] =~ /del/) {
if ($input[1] =~ /\d+/) {
$t = 0;
$p = 0;
@bbbbb = @nothing;
foreach $bbb (@speakkick) {
$t++;
if ($t == $input[1]) {
$p = 1;
@oh = split(';;;',$bbb);
$named = $oh[1];
} else {
push @bbbbb,($bbb);
}
}
@speakkick = @bbbbb;
if ($p == 1) {
IRC::command "/me removed the speak kick on \002$named\002";
} else {
output("\002No speak kick number $input[1]\002");
}
return 1;
}
}



if (!($input[0] =~ /\S+/)) {
output("#  KICKNICK  TIME LEFT");
output("$hl-  --------  ---------\003");
$t = 1;
$time = time;
foreach $listitman (@speakkick) {
@bags = split(';;;',$listitman);
$lefttime = $bags[0] - $time;
$thingof2 = sprintf "$t %9s  $lefttime sec.",$bags[1];
output("$thingof2");
$t++;
} 
output(" ");
output("\002Use $hl/skick <\003nick$hl> <\003time$hl> \003 to set a speak kick\002");
output("\002Use $hl/skick <\003nick$hl> \003 to remove a speak kick\002");
output("\002You can delete by number as well.. $hl/skick del <\003number$hl>\003\002");
return 1;
} else {
my $server4 = IRC::get_info(3);
my $chan4 = IRC::get_info(2);
my $mynick4 = IRC::get_info(1);
$boogsta = $input[0];
my $hoster = userhost("$boogsta $chan4 $server4");
my @bah = split(' ',$hoster);
$grte = 0;
if (!($hoster =~ /NOMATCH/i)) {
$mask4 = "*!$bah[1]\@$bah[2]";
$input[0] = banmask($mask4);
# output($hl."$boogsta\'s\003 \002 hostmask is\002$hl $input[0]\003");
$grte = 1;
} 

if ($grte == 1) {
$time = time;
$timer = $time + $input[1];
$addtoit = ";;;".$atest42;

if (!($input[1] =~ /\d+/)) {
@gggg = @nothing;

$ohyeah = 0;
foreach $brrr (@speakkick) {
if ($brrr =~ /$addtoit/) {
IRC::command "/me removed the speak kick on \002$boogsta\002";
$ohyeah = 1;
} else {
push @gggg,($brrr);
}
}

@speakkick = @gggg;
if ($ohyeah == 0) {
output("\002Use $hl/skick <\003nick$hl> <\003time$hl> \003 to set a speak kick\002");
output("\002Use $hl/skick <\003nick$hl> \003 to remove a speak kick\002");
output("\002You can delete by number as well.. $hl/skick del <\003number$hl>\003\002");
}
return 1;
}
if (!($input[1] =~ /\D+/)) {
push @speakkick, ($timer.";;;".$boogsta.";;;".$atest42);
IRC::command "/me is setting a speak kick on \002$boogsta\002 for $input[1] second(s)";
} else {
output("\002".$hl."$input[1] \003 isn't a number!\002");
}
} else {
output("\002".$hl."$boogsta \003 isn't on $chan4\002");
output("\002Use $hl/skick <\003nick$hl> <\003time$hl> \003 to set a speak kick\002");
output("\002Use $hl/skick <\003nick$hl> \003 to remove a speak kick\002");
output("\002You can delete by number as well.. $hl/skick del <\003number$hl>\003\002");
}
return 1;
}
return 1;
}

# set wkick
sub wkick
{
my $inputs = shift(@_);
@input = split(/\s/,$inputs,3);
$info = shift(@input);

if ($info =~ /load/i) {
if (!(open(IGNOREFILE, $homepath.".xdcc/wordkick"))) {
output("\002No kickword file found!\002");
} else {
$list = <IGNOREFILE>;
@wordkick = split(';;;',$list);
close(IGNOREFILE);
output("\002Kickwords loaded!\002");
}
return 1;
}
if ($info =~ /save/i) {
if (!(open(IGNOREFILE, ">".$homepath.".xdcc/wordkick"))) {
output("Couldn't open wordkick file!!");
return 1;
}
output("\002Saved Wordkick list!\002");

foreach $blahblah (@wordkick) {
print IGNOREFILE ("$blahblah;;;");
}
close(IGNOREFILE);
return 1;
}

if ($info =~ /del/) {
@grr = @nothing;
$beecom2 = stripn(" @input ");
$beecom2 =~ s/\*/\.\*/g;
$beecom2 =~ s/\?/\./g;
foreach $bee2 (@wordkick) {
@bee1 = split(' ',$bee2,2);
$bee = $bee1[1];
if (" $bee " =~ /$beecom2/i) {
output("\002Removing...\002");
} else {
push @grr,($bee2);
}
}
@wordkick = @grr;
return 1;
}
if ($info =~ /add/) {
$type = shift(@input);
$brrt = stripn("@input");
$brrt =~ s/\*/\.\*/g;
$brrt =~ s/\?/\./g;
if ($type =~ /ban/i) {
push @wordkick,("ban $brrt");
output("\002Added \"$hl"."$brrt\003\" as a ban word.\002");
return 1;
}
if ($type =~ /kick/i) {
push @wordkick,("kick $brrt");
output("\002Added \"$hl"."$brrt\003\" as a kick word.\002");
return 1;
}
}
output($hl." \002Use \003/wkick add <ban|kick> <phrase>$hl to add a wordkick phrase\002");
output($hl." \002Use \003 /wkick del <phrase>$hl to delete a wordkick phrase\002");
output($hl." \002Use \003 /wkick$hl to show the current kickwords\002");
output($hl." \002If you only want a word targeted by itself, put spaces around it.\002");
output($hl." \002You can use \003*$hl and \003?$hl for pattern matching...\002");
output($hl." \002eg. \003/wkick add  test $hl will add \003 \" test \"$hl as a kickword.\002");
output($hl." \002Use \003/wkick load$hl or \003save$hl to load or save..\002 \003");
output(" ");
output("\002Current KickPhrases :\002");
foreach $bee1 (@wordkick) {
@bee2 = split(/\s/,$bee1,2);
$bee = $bee2[1];
$bee =~ s/minussign/\-/g;
$bee =~ s/plussign/\+/g;
$bee =~ s/pipesign/\|/g;
$bee =~ s/squareleft/\[/g;
$bee =~ s/squareright/\]/g;
$bee =~ s/curlyleft/\{/g;
$bee =~ s/curlyright/\}/g;
$bee =~ s/normalleft/\(/g;
$bee =~ s/normalright/\)/g;
$bee =~ s/uparrow/\^/g;
$bee =~ s/qwerty/\\/g;
$bee =~ s/\.\*/\*/g;
$bee =~ s/\./\?/g;
output("\002\"$hl$bee\003\"\002");
}
return 1;
}

# set ikick
sub ikick
{
my $info = shift(@_);
my $gte = 0;
if (!($info =~ /\S/)) {
output("\002Enter a nick to kick!\002");
return 1;
}
@where = split(' ',$info);
$info = shift(@where);
$somekickr = "@where";
my $server4 = IRC::get_info(3);
my $chan4 = IRC::get_info(2);

my @boos = IRC::user_list ( $chan4, $server4 );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
my $compare = stripn($lister[0]);
my $compare2 = stripn($info);

if (" $compare " =~ / $compare2 /i) {
IRC::command "/raw mode $chan4 +i";

if ($somekickr =~ /\S/) {
IRC::command "/kick $info $somekickr";
} else {
IRC::command "/kick $info $kickreason";
}

$time = time;
$timetohappen = $time + 5;
push @delayedcommand, ($timetohappen.";;;".$server4.";;;"."/raw mode $chan4 -i");
$gte = 1;
last;
}
}
if ($gte == 0) {
output("\002Couldn't find $info on $chan4!\002");
}
return 1;
}

# invite
sub invite_handler
{
my $line = shift(@_);
@aroundhere = split(' ',$line);
$line = shift(@aroundhere);
shift(@aroundhere);

# play sound
if ($soundson == 1) {
if ($invitesound =~ /\S+/) {
system $pagecommand." ".$homepath.".xdcc/$invitesound &";
}
}


@hrms = split(':',$line,3);
shift(@hrms);
$from = "@hrms";
@blahchans = split(':',$aroundhere[1]);
$blahchan = $blahchans[1];
$isfriend = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
$tryit = stripn($from);
$rest2 = stripn($rest);
if ($tryit =~ /$rest2/i) {
$isfriend = 1;
$newflags = $flags;
$newnick = $nick;
last;
}
}
}
if ($isfriend =~ /1/) {
$flags = $newflags;
$nick = $newnick;
} else {
$flags = $nothingatall;
$nick = $nothingeither;
}
if ($finvite == 1) {
if ($isfriend == 1) {
if ($flags =~ /f/) {
output("\002Auto Joining $blahchan at $nick"."'s request.\002");
IRC::command "/join $blahchan";
}
}
}
return 0;
}


# friend invite
sub finvite
{
my $info = shift(@_);
if ($finvite == 1) {
output("Turning auto join on friend invite \002OFF\002");
$finvite = 0;
return 1;
}
if ($finvite == 0) {
output("Turning auto join on friend invite \002ON\002");
$finvite = 1;
return 1;
}
return 1;
}

# full_banlist
sub full_banlist
{
my $info = shift(@_);
if ($clearban == 1) {
@cutup = split('478',$info);
@cutup2 = split(' ',"@cutup");
my $server = shift(@cutup2);
$server =~ s/://go;
my $mynick = shift(@cutup2);
my $chan = shift(@cutup2);
my $bah = shift(@cutup2);
push @evilban2,($bah);
output("\002Banlist full, removing a ban and rebanning your ban...\002");
if (!($unbanmask =~ /UNBANNUMBER1/)) {
IRC::command "/raw mode $chan +b";
}
$unbanmask = "UNBANNUMBER1";
return 1;
}
return 0;
}

# friend reban
sub reban
{
my $info = shift(@_);
if ($clearban == 1) {
output("If the banlist is full, remove a ban and reban your ban? \002NO\002");
$clearban = 0;
return 1;
}
if ($clearban == 0) {
output("If the banlist is full, remove a ban and reban your ban? \002YES\002");
$clearban = 1;
return 1;
}
return 1;
}

# friend pong
sub pong
{
my $info = shift(@_);
return 0;
}



# topic
sub topic
{
my $info = shift(@_);
@woona = split(' TOPIC ',$info);
@hrms = split(':',"$woona[0]",2);
shift(@hrms);
$from = "@hrms";
@hrms2 = split('!',"$from",2);
$dude = $hrms2[0];
$hostname = $hrms2[1];
@hrms = split(' :',"$woona[1]",2);
$fromchan = $hrms[0];
$message = $hrms[1];
$schan = stripn($fromchan);

##

$isfriend = 0;
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
@more = split(';;;',$5);
foreach $go (@more) {
@ho = split(' ',$go);
$chancmp = stripn($ho[0]);
if ($chancmp =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
$tryit = stripn($from);
$rest2 = stripn($rest);
if ($tryit =~ /$rest2/i) {
$isfriend = 1;
$newflags = $flags;
$newnick = $nick;
last;
}
}
}
if ($isfriend =~ /1/) {
$flags = $newflags;
$nick = $newnick;
} else {
$flags = $nothingatall;
$nick = $nothingeither;
}
####
$invsr = 0;

if ($isfriend =~ /1/) {
if ($flags =~ /i|p|f/i) {
$invsr = 1;
}
}

## wordkick
if (!($invsr == 1)) {
$checka = stripn(" $message ");
foreach $checkwords (@wordkick) {
@checkwordk = split(/\s/,$checkwords,2);
$checkb = stripn("$checkwordk[1]");
if ($checka =~ /$checkb/i) {
if ($checkwordk[0] =~ /kick/i) {
IRC::command "/kick $dude \002WORDKICK\002";
IRC::command "/topic  ";
return 0;
} 
if ($checkwordk[0] =~ /ban/i) {
$banmask = banmask($from);
IRC::command "/raw mode $fromchan -o+b $dude $banmask";
IRC::command "/kick $dude \002WORDBAN\002";
IRC::command "/topic  ";
return 0;
} 
}
}
}
return 0;
}




# fig
sub fig
{
my $info = shift(@_);
my $server = IRC::get_info(3);

if (!($info =~ /\S+/)) {
open (FIND, "figlet -I2 |");
$path = <FIND>;
close (FIND);
if (!($path =~ /\S+/)) {
output("\002Hmm, figlet doesn't seem to be installed!!\002");
return 1;
}
open (FIND, "ls -1 -f $path |");
@test = <FIND>;
close (FIND);
@list = @nothing;
foreach $cool (@test) {
chomp($cool);
if ($cool =~ /\.flf/) {
@hmms = split(/\.flf/,$cool); 
push @list,($hmms[0]);
}
}
output("\002Current figlet fonts available : \002");
$g = 0;
$alist = $nothing;
$fin = $nothing;
foreach $alist (@list) {
$fin = $fin." ".$alist;
$g++;
if ($g > 6) {
output($hl." \002$fin\002\003");
$g = 0;
$fin = $nothing;
}
}
output($hl." \002$fin\002\003");
output("\002Use \"".$hl."fig HELLO!\003\" for the default font or\002");
output("\002Use \"".$hl."fig -f <fontname> <%B|%Cxx|etc> HELLO!\003\" to select your font\002");
return 1;
} else {
@testit = split(/\s/,$info);
if ($testit[0] =~ /\-f/) {
shift(@testit);
$fontname = shift(@testit);
$info ="@testit";
} else {
$fontname = "standard";
}
$info =~ s/^(%[^ ]+) (.*)$/$2/;
my $bob = "$1";
my $chan = IRC::get_info(2);
open (FIND, "figlet -f $fontname $info |");
@test = <FIND>;
close (FIND);
if (!("@test" =~ /\S+/)) {
output("\002Hmm, figlet doesn't seem to be installed!!\002");
return 1;
}
@test2 = reverse @test;
foreach $out (@test2) {
chomp($out);
unshift @rawout,("$server /MSG $chan $bob$out");
}
return 1;
}
}


# ks
sub ks
{
my $info = shift(@_);
@test = split(/\s/,$info);
$type = $test[0];
$victim = $test[1];
$subtype = $test[2];
if ($type =~ /greet/) {
open (FIND, "ls -1 -f $path |");
@test = <FIND>;
close (FIND);
}
return 1;
}


# autojoin
sub autojoin
{
if ($trytoautojoin == 1) {
my $info = shift(@_);
@woona = split(/ 47. /,$info);
@hrms = split(':',"$woona[0]",2);
shift(@hrms);
my $server = "@hrms";
@hrms = split(' :',"$woona[1]",2);
@hrms2 = split(' ',"$hrms[0]",2);
$chan = $hrms2[1];
$nick = $hrms2[0];	
if ($info =~ /473/) {
sl(3,"\002$chan $hl"."is +i, will try again in 30 seconds.\003\002");
} elsif ($info =~ /471/) {
sl(3,$hl."\002$chan $hl"."limit is reached, will try again in 30 seconds.\003\002");
} elsif ($info =~ /474/) {
sl(3,"\002$hl"."You are banned from\003 $chan$hl will try again in 30 seconds.\003\002");
} elsif ($info =~ /475/) {
sl(3,"\002$chan$hl requires a keyword, will try again in 30 seconds.\003\002");
}




push @joinchannel,("$chan;;;$server");
return 1;
} else {
return 0;
}
}
# ajoin
sub ajoin
{
my $info = shift(@_);
if ($info =~ /\S+/) {
if ($info =~ /off/i) {
output("\002Auto Rejoin on Ban is now $hl"."OFF\002 \003");
$trytoautojoin = 0;
return 1;
}
if ($info =~ /on/i) {
$trytoautojoin = 1;
output("\002Auto Rejoin on Ban is now $hl"."ON\002 \003");
return 1;
}

$newinfo = stripn($info);
@newjoinchannel = @nothing;
$tt = 0;
foreach $showit (@joinchannel) {
$newinfo2 = stripn($showit);
@hmm = split(';;;',$newinfo2);
if ($newinfo =~ /$hmm[0]/i) {
output("\002Stopped trying to join $hmm[0]");
$tt = 1;
} else {
push @newjoinchannel,($showit);
} 
}
if ($tt == 0) {
output("\002Sorry, $newinfo doesn't seem to match anything!\002");
}
@joinchannel = @newjoinchannel;
} else {
if ($trytoautojoin == 1) {
$out = "ON";
} else {
$out = "OFF";
}
if ("@joinchannel" =~ /\S+/) {
output("\002Currently trying to join :\002");
foreach $showit (@joinchannel) {
@hmm = split(';;;',$showit);
output("\002$hl"."$hmm[0] \003 on server $hl$hmm[1]\003\002");
}
output("\002Auto join is currently $hl$out\003 \002");
output("\002Use /ajoin $hl"."ON \003 or /ajoin $hl"."OFF \003 to change\002");
output("\002Type $hl/ajoin #channel \003 to cease attempts to join that channel\002");
} else {
output("\002I'm not currently trying to join any channels!\002");
output("\002Auto join is currently $hl$out\003 \002");
output("\002Use /ajoin $hl"."ON \003 or /ajoin $hl"."OFF \003 to change\002");
}
}
return 1;
}

# autoconnect
sub autoconnect
{
my $info = shift(@_);
if ($info =~ /\S+/) {
@info2 = split(/\s+/,$info,2);
if ($info2[0] =~ /com/i) {
output("\002Setting command list to execute when joined to :\002");
@itisit = split(';',$info2[1]);
foreach $rr (@itisit) {
output("\002\"$hl"."$rr\003\"\002");
}
if (!($info2[1] =~ /\S+/)) {
output("\002$hl"."NOTHING\003\002");
$commandonjoin = " ";
} else {
$commandonjoin = $info2[1];
}
return 1;
}
if ($info2[0] =~ /set/i) {
if ($info2[1] =~ /\S+/) {
output("\002Setting autoconnect server group / pattern to $hl"."$info2[1]\002 \003");
$watchserver = $info2[1];
} else {
output("\002Setting autoconnect $hl"."OFF\002 \003");
$watchserver = " ";
}
return 1;
}
if ($info =~ /off/i) {
output("\002Setting autoconnect $hl"."OFF\002 \003");
$watchserver = " ";
return 1;
}
}
if ($watchserver =~ /\S+/) {
output("\002Current autoconnect server group / pattern is $hl"."$watchserver\002 \003");
} else {
output("\002Current autoconnect server group / pattern is $hl"."OFF\002 \003");
}
output("\002Command list to execute once on a channel :\002");
if ($commandonjoin =~ /\S+/) {
@itisit = split(';',$commandonjoin);
foreach $rr (@itisit) {
output("\002\"$hl"."$rr\003\"\002");
}
} else {
output("\002$hl"."NOTHING\003\002");
}
output(" ");
output("\002Use $hl"."/autoconnect set <match>\003 or $hl"."OFF\003 to turn it off\002");
output("\002Match will take a server group in your serverlist and make sure you stay\002");
output("\002connected to a server on that net.  It will also try to match the pattern\002");
output("\002in the name of the server you are connected to.\002");
output("\002Use $hl"."/autoconnect com <list of ; seperated commands>\003\002");
output("\002Example $hl"."/autoconnect com /msg bot authme goos;/msg bot opme #boo\003\002");
return 1;
}


# klined

sub klined
{
my $info = shift(@_);
@tube = split(' 465 ',$info);
$r = IRC::get_info(3);
#IRC::print "$tryingserver \n $r   dfgd";
my $t2 = stripn($watchserver);
my $gr = 0;
my $gra = 0;
if ($watchserver =~ /\S+/) {

my $ts = stripn($tryingserver);
foreach my $temp (@serverlist) {
my $temp2 = stripn($temp);
my @ok = split(';;;;;',$temp2);
if (" $ts " =~ / $ok[1] /i || $ts =~ /$t2/i) {
$gr = 1;
last;
}
}
if ($gr == 1) {
$servnumtest = $servnum;
hereweare:
@c = split(/;;;;;/,$serverlist[$servnumtest]);
$servnumtest++;
if ($servnumtest >= @serverlist) {$servnumtest = 0;}
$r2 = stripn($c[0]);
if (";;$t2;;" =~ /;;$r2;;/i) {
$gra = 1;
$servnum = $servnumtest;
sl(3,"\002Doh!: $info\002");
sl(3,"\002Trying server $c[1]\002");
output("\002NOTE : This function is works better with\002"); 
output("\002\"$hl"."auto reconnect to server\003\" off in xchat's menu\002");
push @delayedcommand, ($clock.";;;;;;/server $c[1] $c[2] $c[3]");
$timetohappen = $clock + 30;
#push @delayedcommand, ($timetohappen.";;;".$c[0].";;;"."/join $c[3]");
push @delayedcommand, ($timetohappen.";;;;;;"."/join $c[3]");
$attempttoconnect = 0; 
goto endit;
}
goto hereweare;
endit:
}
}
if ($gra == 1) {
return 1;
} else {
return 0;
}
}

# server
sub server
{
my $info = shift(@_);
my @test = split(' ',$info);
$tryingserver = $test[0];

if ($info =~ /\S+/) {
return 0;
} else {
if ($watchserver =~ /\S+/) {
output("\002Trying next autoconnect server\002");
$jumpserver = 1;
$tryingserver = "NOTHING";
return 1;
} else {
return 0;
}
}
}


# setseen
sub setseen
{
my $info = shift(@_);

@boos = split(/\s+/,$info,2);
$info2 = ";$boos[0]";
$info = $boos[1];

if ($info2 =~ /;res/i) {
if ($seenresponse == 0) {
output("\002Seen responses are now set to $hl"."NOTICE USER \003 \002");
$seenresponse = 1;
return 1;
} else {
output("\002Seen responses are now set to $hl"."CHANNEL \003\002");
$seenresponse = 0;
return 1;
}
}

if ($info2 =~ /;le/i) {
if ($seenlevel == 0) {
output("\002Seen responses are now set to display $hl"."ALL \003 matches.\002");
$seenlevel = 1;
return 1;
} else {
output("\002Seen responses are now set to display $hl"."FIRST \003 match.\002");
$seenlevel = 0;
return 1;
}
}
if ($info2 =~ /;comp/i) {
if ($seencompare == 0) {
output("\002Compare nick, username and channel a user was seen on\002");
output("\002and filter out older matches $hl"."ON \003\002");
$seencompare = 1;
return 1;
} else {
output("\002Compare nick, username and channel a user was seen on\002");
output("\002and filter out older matches $hl"."OFF \003\002");
$seencompare = 0;
return 1;
}
}
if ($info2 =~ /;store/i) {
if ($seenliststore == 1) {
output("\002Storing of !seen data $hl"."OFF\002 \003");
$seenliststore = 0;
return 1;
} else {
output("\002Storing of !seen data $hl"."ON\002 \003");
$seenliststore = 1;
return 1;
}
}

if ($info2 =~ /;OFF/i) {
output("\002Replies to !seen requests are now $hl"."OFF\002 \003");
$seenliston = 0;
return 1;
}
if ($info2 =~ /;ON/i) {
output("\002Replies to !seen requests are now $hl"."ON\002 \003");
$seenliston = 1;
if ($seenliststore == 0) {
output("\002Storing of !seen data forced $hl"."ON\002 \003");
$seenliststore = 1;
return 1;
}
}

if ($info2 =~ /;time/i) {
if ($info =~ /\S+/) {
$seentime = $info; # time in days
output("\002Nicks older than$hl $seentime \003days will be deleted.\002");
return 1;
} else {
output("\002Nicks older than$hl $seentime \003days are currently being deleted.\002");
return 1;
}
}
if ($info2 =~ /;lim/i) {
if ($info =~ /\S+/) {
$seenlimit = $info; 
output("\002Seen responses with more than$hl $seenlimit \003replies will be truncated.\002");
return 1;
} else {
output("\002Seen responses with more than$hl $seenlimit \003replies will be truncated.\002");
return 1;
}
}





if ($info2 =~ /;chan/i) {
if ($info =~ /\S+/) {
$seenlistchans = $info; #list of channels that !seen will respond in
@bbr = split(' ',$seenlistchans);
output("\002Seen Channel list :\002");
foreach $f (@bbr) {
output("\002$hl$f\003\002");
}
return 1;
} else {
$seenlistchans = " "; #list of channels that !seen will respond in
output("\002Seen Channel list is on for $hl"."all channels\003\002");
return 1;
}
}

output("\002Use /setseen $hl"."LIM\003IT to set the limit of responses to one seen request\002");
output("\002$hl"."TIME\003 sets when old nicks are deleted from the seenlist\002");
output("\002$hl"."COMP\003ARE to turn on or off comparing nick, username\002");
output("\002and channel a user was seen on and display only the most recent seen record.\002");
output("\002With this on, John!john\@194.3.2.3 matches to john!john\@132.23.2.3 if both\002");
output("\002were seen on the same channel.\002");
output("\002$hl"."RES\003PONSE to set output to a channel message,\002");
output("\002or to a notice a user directly with the seen response.\002");
output("\002$hl"."LE\003VEL to set seen match response level.\002");
output("\002$hl"."STORE\003 to turn on saving of seen data.  You can use this\002");
output("\002to allow the storing of seen data if you want to keep seen records for use with /seen,\002");
output("\002but want channel seen responses off.  This is forced on when you turn seen responses on.\002");
output("\002$hl"."ON\003 or $hl"."OFF\003 to turn on or off responses to !seen queries\002");
output("\002$hl"."CHAN\003 <channel list>\002");
output("\002EG $hl/setseen chan #it #itisit\003\002");
output("\002$hl/setseen chan \003 allows responses to all channels\002 ");
output(" ");

if ($seencompare == 1) {
output("\002Compare nick, username and channel a user was seen on\002");
output("\002and filter out older matches $hl"."ON \003\002");
} else {
output("\002Compare nick, username and channel a user was seen on\002");
output("\002and filter out older matches $hl"."OFF \003\002");
}
if ($seenliststore == 1) {
output("\002Storing of /part /quit /kick messages for seen responses is $hl"."ON\002 \003");
} else {
output("\002Storing of /part /quit /kick messages for seen responses is $hl"."OFF\002 \003");
}
if ($seenliston == 1) {
output("\002Reply to !seen requests : $hl"."ON\002 \003");
} else {
output("\002Reply to !seen requests : $hl"."OFF\002 \003");
}
if ($seenresponse == 1) {
output("\002Seen responses are now set to $hl"."NOTICE USER \003\002");
} else {
output("\002Seen responses are now set to $hl"."CHANNEL \003\002");
}
if ($seenlevel == 1) {
output("\002Seen responses are set to display $hl"."ALL \003matches.\002");
} else {
output("\002Seen responses are now set to display $hl"."FIRST \003match.\002");
}

if ($seenlistchans =~ /\S+/) {
@bbr = split(' ',$seenlistchans);
output("\002Seen Channel list :\002");
foreach $f (@bbr) {
output("\002$hl$f\003\002");
}
} else {
output("\002Seen Channel list is on for $hl"."all channels\003\002");
}
output("\002Deleting seen nicks older than$hl $seentime\003 days\002");
output("\002Seen responses with more than$hl $seenlimit \003replies will be truncated.\002");
return 1;
}


# sound
sub sound
{
my $info = shift(@_);
@boos = split(/\s+/,$info,2);
$info2 = ";$boos[0]";
$info = $boos[1];

if ($info2 =~ /;kick/i) {
$kicksound = $info; # name of kick sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002Kick sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002Kick sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;noti/i) {
$noticesound = $info; # name of notice sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002Notice sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002Notice sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;dcc/i) {
$dccsound = $info; # name of dcc sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002DCC sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002DCC sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;xdcc/i) {
$xdccsound = $info; # name of xdcc sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002XDCC sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002XDCC sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;ctcp/i) {
$ctcpsound = ""; # name of ctcp sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002CTCP sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002CTCP sound is now $hl"."OFF\003\002");
}
return 1;
}

if ($info2 =~ /;PRIV/i) {
$privmsgsound = $info; # name of privmsg sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002Private Message sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002Private Message sound is now $hl"."OFF\003\002");
}
return 1;
}


if ($info2 =~ /;chan/i) {
$chanmsgsound = $info; # name of chanmsg sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002Channel Message sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002Channel Message sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;join/i) {
$joinsound = $info; # name of join sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002Join sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002Join sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;mode/i) {
$modesound = $info; # name of mode sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002MODE sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002MODE sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;invite/i) {
$invitesound = $info; # name of mode sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002INVITE sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002INVITE sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;part/i) {
$partsound = $info; # name of mode sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002PART sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002PART sound is now $hl"."OFF\003\002");
}
return 1;
}
if ($info2 =~ /;quit/i) {
$quitsound = $info; # name of mode sound in dir $home/.xdcc/
if ($info =~ /\S+/) {
output("\002QUIT sound is now set to \"$hl~/.xdcc/$info\"\003\002");
} else {
output("\002QUIT sound is now $hl"."OFF\003\002");
}
return 1;
}

if ($info2 =~ /;on/i) {
output("\002Turning action sounds $hl"."ON\003\002");
$soundson = 1;
return 1;
}
if ($info2 =~ /;off/i) {
output("\002Turning action sounds $hl"."OFF\003\002");
$soundson = 0;
return 1;
}


if ($info2 =~ /;path/i) {
$pagecommand = $info;
output("\002Play command path is set to \"$hl$info\"\003\002");
return 1;
}




output("\002$hl"."List of current settings\003\002");
output("\002$hl"."------------------------\003\002");
if ($kicksound =~ /\S+/) {
output("\002KICK             \"$hl$kicksound\003\"\002");    
} else {
output("\002KICK              $hl"."OFF\003\002");    
}
if ($noticesound =~ /\S+/) {
output("\002NOTICE           \"$hl$noticesound\003\"\002");    
} else {
output("\002NOTICE            $hl"."OFF\003\002");    
}
if ($dccsound =~ /\S+/) {
output("\002DCC              \"$hl$dccsound\003\"\002");    
} else {
output("\002DCC               $hl"."OFF\003\002");    
}
if ($xdccsound =~ /\S+/) {
output("\002XDCC             \"$hl$xdccsound\003\"\002");    
} else {
output("\002XDCC              $hl"."OFF\003\002");    
}
if ($ctcpsound =~ /\S+/) {
output("\002CTCP             \"$hl$ctcpsound\003\"\002");    
} else {
output("\002CTCP              $hl"."OFF\003\002");    
}
if ($privmsgsound =~ /\S+/) {
output("\002PRIVMSG          \"$hl$privmsgsound\003\"\002");    
} else {
output("\002PRIVMSG           $hl"."OFF\003\002");    
}
if ($chanmsgsound =~ /\S+/) {
output("\002CHANMSG          \"$hl$chanmsgsound\003\"\002");    
} else {
output("\002CHANMSG           $hl"."OFF\003\002");    
}
if ($joinsound =~ /\S+/) {
output("\002JOIN             \"$hl$joinsound\003\"\002");    
} else {
output("\002JOIN              $hl"."OFF\003\002");    
}
if ($modesound =~ /\S+/) {
output("\002MODE             \"$hl$modesound\003\"\002");    
} else {
output("\002MODE              $hl"."OFF\003\002");    
}
if ($invitesound =~ /\S+/) {
output("\002INVITE           \"$hl$invitesound\003\"\002");    
} else {
output("\002INVITE          $hl"."OFF\003\002");    
}
if ($partsound =~ /\S+/) {
output("\002PART             \"$hl$partsound\003\"\002");    
} else {
output("\002PART              $hl"."OFF\003\002");    
}
if ($quitsound =~ /\S+/) {
output("\002QUIT             \"$hl$quitsound\003\"\002");    
} else {
output("\002QUIT              $hl"."OFF\003\002");    
}
output(" ");
output("\002Sound cmd path   \"$hl$pagecommand\003\"\002");    
if ($soundson == 1) {
output("\002Action Sounds are $hl"."ON\003\002");
} else {
output("\002Action Sounds are $hl"."OFF\003\002");
}
output(" ");
output("\002$hl"."/sound mode <path> \003 would set the sound for a mode change\002");
output("\002To set actions sounds, use $hl"."/sound ON \003 or $hl"."OFF\003\002");
output("\002Use $hl"."/sound path <path to sound command> \003 to set your play command\002");

return 1;
}

## seen output
sub seen_output 
{


my $info = shift(@_);
my $mynick = IRC::get_info(1);
my @argsnstuff = split(' ',$info);
my $localseen = $argsnstuff[1];
my $chanster55 = $argsnstuff[2];
@outs = @nothing;
my @compit = @nothing;
my $schan2 = stripn($chanster55);
my $dude22 = $argsnstuff[3];
my $server = $argsnstuff[4];
my $server22 = stripn($argsnstuff[4]);
my $comparechan = stripn($woofaces[2]);
my $time = time; 
my $yyy = 0;
my $yy = 0;
my $ttt = 0; 
my $testseennick = stripn($argsnstuff[0]); 

if ($seenresponse == 1) { 
$outputline = "/raw notice $dude22 :"; 
} else { 
$outputline = "/raw privmsg $chanster55 :$dude22:"; 
}
$dudedude = stripn($dude22); 

@hrmsa = split('\@',"$hostname");

my $a = stripn($hrmsa[0]);
my $b = stripn($hrmsa[1]);
$seennicker = stripn("$a\@$b");
$seennicker = banmask3("*!$seennicker");
@brr = split('\@',$seennicker);
##################################


my @boos = IRC::user_list ( $chanster55, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
my @hrmsa = split('\@',"$lister[1]",2);

my $looser = stripn($lister[0]);
my $matchit45 = stripn ("$mynick,,,$server,,,,,,$lister[0],,,"); 

my $victim55 = stripn("$mynick,,,$server,,,,,,$testseennick,,,");

########################
if (" $testseennick " =~ / $dudedude /i) { 
if ($seenlevel == 0) {
push @outs,("$server22;;;;;$argsnstuff[0] Who the hell do you think you are then!"); 
$ttt = 1; 
last;
}
} elsif ($matchit45 =~ /$victim55/i) {
if ($seenlevel == 0) {
if (" $comparechan " =~ / $schan2 /i) {
push @outs,("$server22;;;;;$argsnstuff[0] is on this channel right now!");
} else {
push @outs,("$server22;;;;;$argsnstuff[0] is on another channel right now!");
}
$ttt = 1;
last;
}
}
}

if ($ttt == 0) {
foreach $blahblah (@seenlist) {
@woofaces = split(' ',$blahblah);
$testseennick2 = stripn($woofaces[0]);
if (" $testseennick " =~ / $testseennick2 /i) {
my $a = stripn($woofaces[3]);
my $b = stripn($woofaces[4]);
$testitman = "$a\@$b";
$testitman = banmask3("*!$testitman");
@brr = split('\@',$testitman);
$lastseen = $time - $woofaces[1]; 
$days = $lastseen / 86400;
if ($days >= 1) {
$days =~ s/\./\.\./g;
@hl = split('\.',$days,2);
$days = $hl[0];  
} else {
$hl[1] = $days;
$days = $nothing;
}
$hours = $hl[1] * 24;
$hours =~ s/\./\.\./g;
@hl = split('\.',$hours,2);
$hours = $hl[0];
$minutes = $hl[1] * 60;
$minutes =~ s/\./\.\./g;
@hl = split('\.',$minutes,2);
$minutes = $hl[0];
$seconds = $hl[1] * 60;
$seconds =~ s/\./\.\./g;
@hl = split('\.',$seconds,2);
$seconds = $hl[0];
if ($hl[1] > .4999999) {
$seconds++;
}
$phrase = $nothing;

if ($days > 0) {
if ($days > 1) {
$phrase = "$days days ";
} else {
$phrase = "$days day ";
}
}
if ($hours > 0) {
if ($hours > 1) {
$phrase = $phrase."$hours hours ";
} else {
$phrase = $phrase."$hours hour ";
}
}
if ($minutes > 0) {
if ($minutes > 1) {
$phrase = $phrase."$minutes minutes ";
} else { 
$phrase = $phrase."$minutes minute ";
}
}
if ($seconds > 0) {
if ($seconds > 1) {
$phrase = $phrase."$seconds seconds ";
} else {
$phrase = $phrase."$seconds second ";
}
}
$phrase = $phrase."ago.";

$checkitoutman = stripn("$argsnstuff[0] $woofaces[3] $woofaces[4]");

$holdchecks5 = stripn($woofaces[0]);
$holdchecks3 = stripn($testseennick);
$victim55 = stripn("$mynick,,,$server,,,");


#########################################
my @boos = IRC::user_list ( $chanster55, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
my @hrmsa = split('\@',"$lister[1]",2);

my $holdchecks = $lister[0];
my $hmmchans1 = $chanster55;
my $nonicks = $server;

$hmmchans = stripn($chanster55);
$holdchecks2 = stripn($lister[0]);
$against = stripn(" $lister[0] $hrmsa[0] $hrmsa[1] ");
$nickserver = stripn($server);
$matchit456 = stripn(",,,$hrmsa[0],,,$hrmsa[1],,,");

###############################

if ($seencompare == 1) {
$check1a = stripn("$woofaces[0] $woofaces[3] $hmmchans1");
$okt = 0;
foreach $checkthing (@compit) {
$check2a = stripn("$checkthing");
if (" $check1a " =~ / $check2a /i) {
$okt = 1;
last;
}
}
if ($okt == 1) {
$cyc = 1;
next;
}
}

$rre = 0;
if (" $nickserver " =~ / $server22 /) { 
$rre = 1;
} 
if (" $matchit456 " =~ / ,,,$brr[0],,,$brr[1],,, /i) { 
if (" $schan2 " =~ / $hmmchans /i) { 
#same chan
if (" $holdchecks2 " =~ / $holdchecks3 /i) { 
# same nick
if (" $holdchecks3 " =~ / $dudedude /i) { 
if ($rre == 1) {
push @outs,("$server22;;;;;Uhhh... $woofaces[0]($woofaces[3]\@$woofaces[4]) is you.");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;Uhhh... $woofaces[0]($woofaces[3]\@$woofaces[4]) on $hmmchans1 $nonicks is you.");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
} else { 
if ($rre == 1) {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) is on the channel right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) is on $hmmchans1 $nonicks right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
} 
$yyy = 1;
if ($seenlevel == 0) {last;}else{next;}
} else { 
# diff nick
if ($rre == 1) {
push @outs,("$server22;;;;;$woofaces[0] is $holdchecks($woofaces[3]\@$woofaces[4]) and is on the channel now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;$woofaces[0] is $holdchecks($woofaces[3]\@$woofaces[4]) and is on $hmmchans1 $nonicks right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
$yyy = 1;
if ($seenlevel == 0) {last;}else{next;}
} 
} else { 
#diff chan
if (" $holdchecks2 " =~ / $holdchecks3 /i) { 
#same nick
if ($rre == 1) {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) is on $hmmchans1 right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) is on $hmmchans1 $nonicks right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
$yyy = 1;
if ($seenlevel == 0) {last;}else{next;}
} else { 
if ($rre == 1) {
push @outs,("$server22;;;;;$woofaces[0] is $holdchecks($woofaces[3]\@$woofaces[4]) and is on $hmmchans1 right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;$woofaces[0] is $holdchecks($woofaces[3]\@$woofaces[4]) and is on $hmmchans1 $nonicks right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
$yyy = 1;
if ($seenlevel == 0) {last;}else{next;}
} 
} 
}
} 
if ($cyc == 1) {
$cyc = 0;
next;
}

if ($yyy == 0) {
if (" $holdchecks5 " =~ / $holdchecks3 /i) {
if (" $comparechan " =~ / $schan2 /i) {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) was on this channel $phrase");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
$yy = 1;
if ($seenlevel == 0) {last;}else{next;}
} else {
push @outs,("$server22;;;;;$woofaces[0]($woofaces[3]\@$woofaces[4]) was on $woofaces[2] $phrase");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
$yy = 1;
if ($seenlevel == 0) {last;}else{next;}
}
}
}
}
}
if ($yyy == 0) {
$ry = 0;
##################

my @boos = IRC::user_list ( $chanster55, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);
my @hrmsa = split('\@',"$lister[1]",2);
my $victim = $lister[0];
my $victimun = $hrmsa[0];
my $victimhost = $hrmsa[1];
my $nonicks = $server;
my $boodude = "$lister[0]($hrmsa[0]\@$hrmsa[1])";

my $matchit457 = stripn(",,,$lister[0],,,");
my $chancc = stripn($chanster55);
my $nickserver = stripn($server);

###########################

$chanster555 = stripn($chanster55);
$victim55 = stripn(",,,$testseennick,,,");

if (" $victim55 " =~ / $matchit457 /i) {
$chancc1 = $chancc;
$ry = 1;
#last;

if (" $nickserver " =~ / $server22 /) { 
if (" $chancc " =~ / $chanster555 /i) {
push @outs,("$server22;;;;;$boodude is on the channel right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
} else {
push @outs,("$server22;;;;;$boodude is on $chancc1 right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
} else {
push @outs,("$server22;;;;;$boodude is on $chancc1 $nonicks right now!");
push @compit,("$woofaces[0] $woofaces[3] $hmmchans1");
}
}
}



if ($ry == 0 && $yy == 0) {
push @outs,("$server22;;;;;I haven't seen $argsnstuff[0].");
}

}
}
$countitnow = 0;
out("$localseen","$dude22");
return 0;
}
}


# seen
sub seen 
{
my $info = shift(@_);
if ($seenliststore == 0) {
output("\002Warning : seen data isn't been stored, responses may be inaccurate!\002");
output("\002Use $hl"."/setseen store \003 to turn storage on\002");
}
seen_output("$info 0 nochan SEEN"); 
return 1;
}




sub out
{

my $localseen = shift(@_);
my $dude22 = shift(@_);

$ra = 0;
@newlist2 = @nothing;

$gop = @outs;

foreach $a1 (@outs) {
if ($ra == 0) {
$ra = 1;
push @newlist2,($a1);
next;
}
$t = 0;

foreach $b1 (@newlist2) {
$a2 = stripn($a1);
$b2 = stripn($b1);
if ($a2 =~ /$b2/i) {
$t = 1;
last;
}
}
if ($t == 0) {
push @newlist2,($a1);
}
}

@outs = @newlist2;
$gop1 = @outs;
my $totalout = 0;
foreach $wow (@outs) {
if ($localseen == 0 || $totalout < $seenlimit) {
$totalout++;
@r = split(';;;;;',$wow,2);
$time = time; 
if ($localseen == 1) {
push @rawout,("$r[0] $outputline $r[1]\n");
}
output("$hl<<$dude22>>\003 $r[1]");
} else {
my $h = @outs;
push @rawout,("$r[0] $outputline \002List truncated, $h matches total.\n");
output("$hl<<$dude22>>\003 \002List trucated, $h matches total.\002");
last;
}
}
return 0;
}


sub sortseen { 
## delete nicks older than $seentime if seenlist is on
my $time = time; 
@newseenlist = @nothing; 
my $tr = 0; 
my $timecheck = $seentime * 86400;
foreach $blahblah (@seenlist) { 
@woofaces = split(' ',$blahblah); 
$sitaround = $time - $woofaces[1]; 
if ($sitaround > $timecheck) {
$tr++; 
} else { 
push @newseenlist,($blahblah); 
} 
}
@seenlist = @newseenlist; 
sl(3,"\002Cleaned seen list,$hl"." $tr\003 nicks have expired!\002");  

output("\002Sorting Seenlist\002"); 
my @sort = sort coolsort @seenlist; 
@seenlist = reverse(@sort); 
IRC::add_timeout_handler(43200000, "sortseen");
return;
}

sub coolsort 
{
my @a = split(' ',$a);
my @b = split(' ',$b);
$a[1] <=> $b[1];
}


# dpack displayallpacks
sub dpack 
{

if ($dapacks =~ /1/) {
output("Displaying friend only packs on a /plist now. \(/xdcc packs must be set\)");
$dapacks = 0;
return 1;
}

if ($dapacks =~ /0/) {
output("Hiding friend only packs on a /plist now. \(/xdcc packs must be set\)");
$dapacks = 1;
return 1;
}
return 1;
}


# set away
sub setaway
{
my $info = shift(@_);
my $channel = IRC::get_info(2);
my $server = IRC::get_info(3);
my $mynick = IRC::get_info(1);
my $info2 = $info;
my $s = 0;

if ($pageon =~ /1/) {
$rest = "Page \002[ON]\002";
} elsif ($pageon =~ /0/) {
$rest = "Page \002[OFF]\002";
} elsif ($pageon =~ /2/) {
$rest = "Page \002[FRIENDS]\002";
}
if ($logon =~ /1/) {
$rest = $rest." Log \002[ON]\002  ";
} else {
$rest = $rest." Log \002[OFF]\002  ";
}
if ($awaysync == 1) {
@awayservers = IRC::server_list;
} else {
@awayservers = ("$server");
}

foreach $server (@awayservers) {
$isaway = 0;
my $r = stripn ($server);
foreach $booser (@awaylist) {
my $rr = stripn ($booser);
if (" $r " =~ / $rr /) {
$isaway = 1;
last;
}
}
if (!($info =~ /\S+/)) {
if ($isaway == 1) {
if ($awaynick ne "0") {
IRC::command_with_server ("/raw nick $backnick",$server);
}
IRC::command_with_server ("/raw away",$server);
if ($awaynotice == 1) {
@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);

foreach $boot2 (@wow) {
@manofchan = split(' ',$boot2);
if ($manofchan[1] =~ /$server/i) {
my $newtime = time;
my $because = ($newtime - $awaytime);
$because = doit($because);
push @rawout,("$manofchan[1] /raw PRIVMSG $manofchan[0] :\001ACTION is back.. gone $because.\001");
if ($s == 0) {
$s = 1;
output("\002You are back.. gone $because.\002");
}
}
}
}
next;
} 
$info2 = $awayreasons[(rand @awayreasons)];
chomp $info2;
}
if ($awaynick ne "0") {
$backnick = $mynick;
if ($awaynick =~ /^\*(.+)/) {
IRC::command_with_server ("/raw nick $mynick$1",$server);
} else {
IRC::command_with_server ("/raw nick $awaynick",$server);
}
}

IRC::command_with_server ("/raw away :".$rest.$info2."\n",$server);
$awaymessage = $rest.$info2;
output("\002You are away ->$hl $info2 \003<- $rest\002");




if ($awaynotice == 1) {
@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);

foreach $boot2 (@wow) {
@manofchan = split(' ',$boot2);
if ($manofchan[1] =~ /$server/i) {
push @rawout,("$manofchan[1] /raw PRIVMSG $manofchan[0] :\001ACTION is away -> $info2 <- $rest\001");
}
}
}
}
return 1;
}

# set away
sub set_away
{
#
my $info = shift(@_);
#
if (!($info =~ /\S+/)) {
output("\002Use the commands $hl"."notify\003, $hl"."nick\003 and $hl"."sync\003 to set\002");
output("\002your awaynick (if any), whether or not you want the script\002");
output("\002to notify channels you are on when you set yourself away, and if you want\002");
output("\002an /away on one server to set you away on all servers you are on.\002");
output("\002eg .. /setaway nick IBEAWAY or /setaway nick *^zz or /setaway nick to turn it off\002");
}
#
@botfa = split(' ',$info);

if ($botfa[0] =~ /syn/i) {
if ($awaysync == 0) {
$awaysync = 1;
output("\002/away is now synced on all servers.!\002");
}
if ($awaysync == 1) {
$awaysync = 0;
output("\002/away now effects only the server you are on..\002");
}
}

if ($botfa[0] =~ /NOT/i) {
if ($awaynotice == 0) {
$awaynotice = 1;
output("\002I will now notify channels you are in when you set yourself away!\002");
}
if ($awaynotice == 1) {
$awaynotice = 0;
output("\002I will no longer notify channels you are in when you set yourself away!\002");
}
}

if ($botfa[0] =~ /nick/i) {
if ($botfa[1] =~ /\S+/) {
$awaynick = $botfa[1];
if ($botfa[1] =~ /^\*(.+)/) {
output("\002Your nick will now be set to >$hl CURRENTNICK$1 \003< when you mark yourself away\002");
} else {
output("\002Your nick will now be set to >$hl $awaynick \003< when you mark yourself away\002");
}
} else {
$awaynick = "0";
output("\002Your nick will remain the same when you mark yourself away\002");
}
}
output("\002Current Status :\002");
if ($awaysync == 1) {
$awaysyncstatus = "ON";
} else {
$awaysyncstatus = "OFF";
}
output("\002AWAY SYNC   : $hl$awaysyncstatus\003\002"); 
if ($awaynotice == 1) {
$awaynoticestatus = "ON";
} else {
$awaynoticestatus = "OFF";
}
output("\002AWAY NOTICE : $hl$awaynoticestatus\003\002"); 
if ($awaynick ne "0") {
if ($awaynick =~ /^\*(.+)/) {
output("\002AWAY NICK   : $hl"."CURRENTNICK$1\003\002");
} else {
output("\002AWAY NICK   : $hl$awaynick\003\002"); 
}
} else {
output("\002AWAY NICK   : $hl"."NO CHANGE\003\002"); 
}


return 1;
}

# url
sub url 
{
my $info = shift(@_);
my $channel = IRC::get_info(2);
my $server = IRC::get_info(3);
if (!($info =~ /\d+/)) {
$info = 1;
}
if ($info =~ /\D+/) {
$info = 1;
}

if (!(open(AWAYREASON, $homepath.".xdcc/textfile"))) {
output("\002Unable to open ~/.xdcc/textfile\002");
return 1;
} else {

@list = <AWAYREASON>;
@boos = split('\n',"@list");
@boos = split(' ',"@boos");
close(AWAYREASON);
#output("\002Loaded!\002");
}
my $url = "http://www.";
@bootie = @nothing;
for ($x1 = 0; $x1 < $info; $x1++) {
my $because = int((rand 3)+1);
my $out = $url;
for ($x = 0; $x < $because; $x++) {

my $info2 = $boos[(rand @boos)];
#$info2 =~ s/[\"\,\'\.\:\;\?\!\`\(\)\[\]//g;
$info2 =~ s/\W+//eg;
my $len = length $info2;
if ($len > 3) {
$out = $out.$info2.".";
} else {
$x = $x - 1;
}
}
my @ends = ("com","net","ca","org","de","jp","co.uk");
my $end = $ends[(rand @ends)];
$out = $out.$end;
push @bootie,($out);
}
foreach $g (@bootie) {
push @rawout,("$server /raw PRIVMSG $channel :$g");
output("\002$hl$g\003\002");
}

return 1;
}

# seconds to real time
sub doit {
my $info = shift(@_);
my @phrase = @nothing;
my $years = 0;
my $days = 0;
my $hours = 0;
my $minutes = 0;
my $seconds = 0;
my $wholeline = $nothing;

if ($info > 100000000000) {
return("TOO LONG TO COMPUTE");
}


for ( ; $info > 31557600; $info = $info - 31557600) {
$years++;
}
for ( ; $info > 86400; $info = $info - 86400) {
$days++;
}
for ( ; $info > 3600; $info = $info - 3600) {
$hours++;
}
for ( ; $info > 60; $info = $info - 60) {
$minutes++;
}
$seconds = $info;

if ($years > 0) {
if ($years > 1) {
push @phrase, ("$years years");
} else {
push @phrase, ("$years year");
}
}
if ($days > 0) {
if ($days > 1) {
push @phrase, ("$days days");
} else {
push @phrase, ("$days day");
}
}
if ($hours > 0) {
if ($hours > 1) {
push @phrase, ("$hours hours");
} else {
push @phrase, ("$hours hour");
}
}
if ($minutes > 0) {
if ($minutes > 1) {
push @phrase, ("$minutes minutes");
} else {
push @phrase, ("$minutes minute");
}
}
if ($seconds > 0) {
if ($seconds > 1) {
push @phrase, ("$seconds seconds");
} else {
push @phrase, ("$seconds second");
}
}
my $end = pop(@phrase);
foreach $gty (@phrase) {
$wholeline = $wholeline.$gty.", ";
}
if ($wholeline) {
$wholeline = $wholeline."and ".$end;
} else {
$wholeline = $end;
}

return($wholeline);
}


# stealver
sub stealver 
{
my $info = shift(@_);
my $time = time;
my $aaal;
my $t;

if ($info =~ /load/i) {
if (!(open(IGNOREFILE, $homepath.".xdcc/version"))) {
output("\002No version file found!\002");
} else {
@stealversion = <IGNOREFILE>;
chomp @stealversion;
close(IGNOREFILE);
output("\002Version Reply Loaded!\002");
}
return 1;
}


if ($info =~ /save/i) {
if (!(open(IGNOREFILE, ">".$homepath.".xdcc/version"))) {
output("\002No version file found!\002");
return 1;
}
output("\002Saved version file!\002");

foreach my $outmanout (@stealversion) {
print IGNOREFILE ($outmanout."\n");
}
close(IGNOREFILE);
return 1;
}

if ($info =~ /clear/i) {
output("\002Clearing any stolen $hl"."VERSION\003 info, returning to normal version replies\002");
@getverinfo = @nothing;
@stealversion = @nothing;
@stealversion2 = @nothing;
return 1;
}
if ($info =~ /add /i) {
output("\002Adding version response:\002");
my @sv = split(' ',$info,2);
push @stealversion,("$sv[1]");
@stt = split(/<cr>/i,$sv[1]);
my $gr = @stt;
for ($x = 0; $x < $gr; $x++) {
output("$stt[$x]");
}
return 1;
}
if ($info =~ /del /i) {
my @sv = split(' ',$info,2);
if (@stealversion >= $sv[1]) {
$goobaby = splice(@stealversion,($sv[1]-1),1);
}
my @oha = split("<cr>",$goobaby);
my $acher = shift @oha;
output("\002Removing :$hl\"\003\002$acher$hl\002\"\003\002");
foreach my $nowaytt (@oha) {
output("\002          $hl\"\003\002$nowaytt$hl\002\"\003\002");
}
return 1;
}


if ($info =~ /nick /i) {
my @sv = split(' ',$info,2);
IRC::command "/version $sv[1]";
$getverinfo[1] = $time + 60;
$getverinfo[0] = $sv[1];
@stealversion2 = @nothing;
output("\002Trying to grab version info from $hl$sv[1]\002\003");
return 1;
}

if ($info =~ /time /i) {
my @sv = split(' ',$info,2);
$stealvertime = $sv[1];
output("\002Random Version Replies will stay the same for$hl $sv[1]\003 Seconds\002");
output("\002Use /savec to save");
return 1;
}

if ($info =~ /per/i) {

if ($stealverper =~ /1/) {
output("Repeated Version Requests Extend TIME Variable \002OFF\002");
$stealverper = 0;
return 1;
}

if ($stealverper =~ /0/) {
output("Repeated Version Requests Extend TIME Variable \002ON\002");
$stealverper = 1;
return 1;
}
}



output("\002Valid commands are $hl"."load, save, clear, add, del, per, time, nick\003\002");
output("\002Use /stealver $hl"."nick\003 <ircnick> to steal a user's version string\002");
output("\002You can also do /stealver $hl"."add\003 <something> .. split lines with \"$hl<cr>\003\".\002");
output($hl."eg : /stealver add This is a %Btest%B<cr>of a version response.");
output(" ");
output("\002StealVer Time = $stealvertime  | Persistant Replies = $stealverper");
output("\002$hl"."Fake Version List:");
if (@stealversion > 0) {
$t = 0; foreach $aaal (@stealversion) {
my $r = 0;
my @oha = split("<cr>",$aaal);
my $at = shift @oha;
$t++; output("$hl\002".$t.".$r\003\)\002 $at");
foreach my $reaa (@oha) {
$r++;
output("$hl\002".$t.".$r\003\)\002 $reaa");
}
}
} else {
output("$hl\002EMPTY");
}
return 1;
}

# rawout
sub rawout 
{
my $info = shift(@_);

if (!($info =~ /\S+/)) {
output("\002Use this to set the number of lines the script will output\002");
output("\002every 4 seconds when doing xdcc lists, seen responses, and\002");
output("\002so on to the channel or private individuals.\002");
output("\002This will prevent you from getting flooded off a server..\002");
}
if (!($info =~ /\D+/)) {
if ($info =~ /\d+/) {
$outputlimit = $info;
}
output;
output("\002RAW-OUTPUT is currently set to >$hl $outputlimit\003 < lines every 4 seconds.\002");
} else {
output("\002Enter a number!\002");
}
return 1;
}

# time to work on a unified hostname snatcher
sub userhost {
my $info = shift(@_);
my @stuff = split(' ',$info);
my $nick = $stuff[0];
my $channel = $stuff[1];
my $server = $stuff[2];

my $matchb = stripn($nick);

my @boos = IRC::user_list ( $channel, $server );
my @boo = split(': ',"@boos");
foreach $g (@boo) {
my @lister = split(' ',$g);

my $matcha = stripn($lister[0]);
if (" $matcha " =~ / $matchb /i) {
my @split = @nothing;
@split = split('\@',$lister[1]);
if ($split[1] =~ /\S+/) {
#IRC::print "returning $lister[0] $split[0] $split[1] $lister[2] $lister[3]\n";
return("$lister[0] $split[0] $split[1] $lister[2] $lister[3]");
} else {
#IRC::print "returning $lister[0] FETCHING FETCHING $lister[2] $lister[3]\n";
return("$lister[0] $split[0] $split[1] $lister[2] $lister[3]");
}
}
}

return ("NOMATCH NOMATCH NOMATCH NOMATCH NOMATCH");
}


# am I an op?
sub amiop {
my $info = shift(@_);
my @stuff = split(' ',$info);
my $chan = $stuff[0];
my $server = $stuff[1];
my $mynick;

@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);
foreach $boot2 (@wow) {
@manofchan = split(' ',$boot2);
if (" $manofchan[1] " =~ / $server /) {
$mynick = stripn($manofchan[2]);
last;
}
}

my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   
foreach $g (@boo) {
my @lister = split(' ',$g);
my $compare = stripn($lister[0]);
if (" $compare " =~ / $mynick /i) {
return($lister[2]);
last;
}
}
return;
}

# scan channel for friendlist action

sub scanchan {
my $info = shift(@_);


my $chan = shift @scanchan;
my $server = shift @scanserver;
#
my $schan = quotemeta $chan;
#
my $nick;
my $flags;
my $rest2;
my $mynick;
my @amode = @nothing;
my @akick = @nothing;
my $retry = 0;
my @sl1 = @nothing;
my @sl4 = @nothing;

@test = IRC::channel_list;
$boot = "@test";
$boot =~ s/ \#/;;;\#/g;
@wow = split (';;;',$boot);
foreach $boot2 (@wow) {
@manofchan = split(' ',$boot2);
if (" $manofchan[1] " =~ / $server /) {
$mynick = $manofchan[2];
last;
}
}

my $compareme3 = ",,,$mynick,,,";

my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");
 

#IRC::print "$boo[0]\n$boo[1]\n";

#IRC::print "$boos[0]\n$boos[1]\n";

if (grep { / FETCHING / } @boo) {
#IRC::print "Matched it!!\n";
push @scanchan,($chan);
push @scanserver,($server);
IRC::add_timeout_handler(4000,"scanchan");
return 0;
}



###########################################



my @okihold = @nothing;

foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
$newcomment2 = $4;

my @more = split(';;;',$5);
foreach $go (@more) {
my @ho = split(' ',$go);

#IRC::print "$ho[0] and $schan\n";

if ($ho[0] =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}

my $testhost = 0;
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
$rest =~ s/\!/ /go;

my @matching = grep { /^$rest / } @boo;
push @okihold,(@matching);
@matching = @nothing;
}
}
############################################

foreach $g (@okihold) {
my @lister = split(' ',$g);
my @hrmsa = split('\@',"$lister[1]",2);
my $victim = $lister[0];
my $victimun = $hrmsa[0];
my $victimhost = $hrmsa[1];
my $mymodeop = $lister[2];
my $mymodevoice = $lister[3];


my $compareme4 = quotemeta $victim;
$compareme4 = ",,,$compareme4,,,";
$hostnm = "$nick!$victimun\@$victimhost";
foreach $test (@friendlist) {
$test =~ /(.*),(.*),(.*):::(.*):::(.*)/;
$nick = $1;
$flags = $2;
$rest2 = $3;
$newcomment2 = $4;

my @more = split(';;;',$5);
foreach $go (@more) {
my @ho = split(' ',$go);


if ($ho[0] =~ /$schan/i) {
$flags = $flags.$ho[1];
if ($flags =~ /d|k/) {
@flager = split(/o|p|f/,$flags);
$flags = $nothing;
foreach $gtr (@flager) {
$flags = $flags.$gtr;
}
}
}
}
my $testhost = 0;
@boogieface = split (':',$rest2);
foreach $rest (@boogieface) {
$rest =~ s/\*/`/g;
$rest =~ s/\?/\./g;
$rest =~ s/`/\.\*/go;
if ($hostnm =~ /$rest/i) {
$testhost = 1;
}
}
if ($testhost == 1) {
if ($flags =~ /k/i) {
$banmask = banmask($hostnm);
push @mode, ("-o $victim","+b $banmask");
push @kick, ("$victim $newcomment2");
sl(1,"\002Banning k flag user $nick on $chan\002");
}
if ($mymodeop == 1) {
if ($flags =~ /d/i) {
sl(1,"\002Deopping d flag user $nick on $chan\002");
push @mode, ("-o $victim");
}
}
#IRC::print "$compareme3 and $compareme4 and $mymodevoice\n";
if ($compareme3 !~ /$compareme4/i) {
if ($mymodeop == 0) {
if ($flags =~ /o/i) {
sl(4,"\002Opping o flag user $nick on $chan\002");
push @mode, ("+o $victim");
}
}
if ($mymodevoice == 0) {
if ($flags =~ /v/i) {
sl(4,"\002Voicing v flag user $nick on $chan\002");
push @mode, ("+v $victim");
}
}
if ($mymodevoice == 1) {
if ($flags =~ /q/i) {
sl(4,"\002DeVoicing q flag user $nick on $chan\002");
push @mode, ("-v $victim");
}
}
}
}
}
}
if (@mode > 0 || @kick > 0) {
chanaction("$mynick,,,$chan,,,$server");
}
return 0;
}






sub getignores {
my $info = shift(@_);
my @df = IRC::server2_list;
foreach $t (@df) {
output("a: $t");
}

my @f = split(':',"@df");
foreach $t (@f) {
output("b: $t");
}
return 1;
}
sub massmessage
{
my $wallopmessage = shift(@_);
if (!($wallopmessage =~ /\S+/)) {
output("This command simply notices the entire channel with whatever you type");
return 1;
}
my @wallopr = @nothing;
my $chan = IRC::get_info(2);
my $mynick = IRC::get_info(1);
my $server = IRC::get_info(3);
my $mynick2 = stripn(":::".$mynick.":::");


my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   
foreach $g (@boo) {
my @lister = split(' ',$g);
push @wallopr,("$lister[0]");
}

push @wallopto,("@wallopr".";;;$server;;;$wallopmessage");
output("\002Sending \"".$hl.$wallopmessage."\003\" to"." @wallopr\002");
return 1;
}

sub mass_something { 
my $uhh = shift(@_); 
my @something = split(' ',$uhh);
if (@something < 2) {
output("Use \"+o,+v,-o,-v\" for WHO you want the action to take");
output("place on, and use \"+k,+b,+o,-o,+v,-v\" for what action");
output("you want the script to take.  Aside from the obvious op");
output("and voice functions, +k is kick, and +b is ban.");
output("You can link multiple commands in groups if you want, such");
output("as : /mmode +o -o+k+b -o +o -o+v -v");
output("The above would do the following :");
output("All +o users are to be deopped, kicked and banned");
output("All -o users are to be opped");
output("All +v users without ops are to be devoiced");
output("Its a very powerful, and an open-ended way to do a mass mode script... enjoy!");

return 1;
}

my $chan = IRC::get_info(2); 
my $mynick = IRC::get_info(1); 
my $server = IRC::get_info(3); 
my $mynick2 = quotemeta $mynick;
my @mode1 = @nothing;
my @kick1 = @nothing;

for ($x = 0; @something > 0; $x++) {
my $test1 = 1; 
my $test2 = 1; 
my $bancatch = 0; 
my $kickcatch = 0; 
my @hold = @nothing;

my @doit = @nothing;

if ($something[1] =~ /\-v/i) {push @doit,("-v");}
if ($something[1] =~ /\+v/i) {push @doit,("+v");}
if ($something[1] =~ /\-o/i) {push @doit,("-o");}
if ($something[1] =~ /\+o/i) {push @doit,("+o");}


if ($something[0] =~ /\-v/i) {
$test2 = 0;
}
if ($something[0] =~ /\+v/i) {
$test2 = 2;
}
if ($something[0] =~ /\-o/i) {
$test1 = 0;
}
if ($something[0] =~ /\+o/i) {
$test1 = 2;
}

my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   
foreach $g (@boo) {
my @lister = split(' ',$g);
if (!(" $lister[0] " =~ / $mynick2 /i)) {
if ((($test1 > 0 && $lister[2] == 1) || ($test1 < 2 && $lister[2] == 0)) && (($test2 > 0 && $lister[3] == 1) || ($test2 < 2 && $lister[3] == 0))) {

foreach $bbbc (@doit) {
push @mode,("$bbbc $lister[0]");
}
if ($something[1] =~ /\+b/i) {
my $boo = banmask("*!$lister[1]");
push @mode,("+b $boo");
}
if ($something[1] =~ /\+k/i) {
push @kick,("$lister[0]");
}

}
}
}
shift @something;
shift @something;
}
#IRC::print "@mode and @kick\n";
if (@mode > 0  || @kick > 0) {
chanaction("$mynick,,,$chan,,,$server,,,$nolongerop");
}

return 1;
}


# log on / off handler
sub autocycle
{

if ($cycleforop =~ /1/) {
output("Turning auto cycle to gain ops \002OFF\002");
$cycleforop = 0;
return 1;
}

if ($cycleforop =~ /0/) {
output("Turning auto cycle to gain ops \002ON\002");
$cycleforop = 1;
return 1;
}
return 1;
}

# trace success / found nick
sub trace_garbage
{
my $wo = shift(@_);
foreach my $ff (@nickcheck) {
my @ab = split(' ',$ff);
my $woo = quotemeta $ab[0];
if ($wo =~ /.+$woo.*/i) {
return 1;
} else {
}
}
return 0;
}

# trace success / found nick
sub trace_yes
{
my $wo = shift(@_);
foreach my $ar (@nickcheck) {
my @ab = split(' ',$ar);
my $boo = quotemeta $ab[0];
if ($wo =~ /.+$boo.*/i) {
return 1;
} else {
}
}
return 0;
}

# trace fail / try to get nick
sub trace_no
{
my $ok = shift(@_);
my $w = 0;
if (@nickcheck > 0) {
my @newthing = @nothing;
my @a = split(' ',$ok);
my @b = split(':',$a[0]);
foreach my $aa (@nickcheck) {
my @ae = split(' ',$aa);
$boo = quotemeta $ae[1];
if (" $b[1] " =~ / $boo /i) {
$desirednick = $ae[0];
output("Desired Nick $hl$desirednick\003 seems free, trying to get it.");
IRC::command_with_server("/nick $desirednick",$b[1]);
$w = 1;
} else {
push @newthing,($aa);
}
@nickcheck = @newthing;
}
}
return $w;
}

# your nick is in use, bastards!!
sub grab_nick_failed
{
if ($grabnick == 1) {
my $ok = shift(@_);
my @oh = split(' ',$ok);
if ($oh[2] =~ /\*/) {
my @get = split(':',$oh[0]);
push @nickcheck,("$oh[3] $get[1]");
}
}
return 0;
}

# grabnick on / off handler
sub grabnick
{

if ($grabnick =~ /1/) {
output("Auto-attempt to re-grab your nick \002OFF\002");
$grabnick = 0;
return 1;
}

if ($grabnick =~ /0/) {
output("Auto-attempt to re-grab your nick \002ON\002");
$grabnick = 1;
return 1;
}
return 1;
}

# xdcc file listing on / off handler
sub publist {

if ($xdccpublistmethod =~ /1/) {
output("XDCC Pub List Set to \002NOTICE\002");
$xdccpublistmethod = 0;
return 1;
}

if ($xdccpublistmethod =~ /0/) {
output("XDCC Pub List Set to \002PRIVMSG\002");
$xdccpublistmethod = 1;
return 1;
}
output("Config file corrupt!");
return 1;
}


# machine specs output 
sub specs {
my $mynick = IRC::get_info(1);
my $chan = IRC::get_info(2);
my $server = IRC::get_info(3);
my @bob = `cat /proc/cpuinfo`;
$cpucount = 0;
$cpumips = 0;
foreach (@bob) {
if (/vendor_id.+?: ?(.+)/i) {$cpuvendor = $1;}
if (/model name.+?: ?(.+)/i) {$cpumodel = $1;}
if (/cpu MHz.+?: ?(.+)/i) {$cpumhz = $1;}
if (/cache size.+?: ?(.+)/i) {$cpucache = $1;}
if (/bogomips.+?: ?(.+)/i) {$cpumips = $cpumips+$1;}
if (/^processor/i) {$cpucount++;}
}
@bob = `uptime`;
foreach (@bob) {
/.*?up *(.*),.*?users?.*?load average: ([\d\.]+).*/i;
$uptime = $1;
$load = $2;
}

@bob = `free -m`;
foreach (@bob) {
/mem.+?[ ]+([\d\.]+)[ ]+([\d\.]+)/i;
$memtot = $1;
$memused = $2;
}

$osver = `uname -s -r`;
chomp $osver;

@bob = `xwininfo -root`;
foreach (@bob) {
if (/^ +?Width: (.+)/i) {$scrwidth = $1;}
if (/^ +?Height: (.+)/i) {$scrheight = $1;}
if (/^ +?Depth: (.+)/i) {$scrdepth = $1;}
}
@bob = `cat /proc/pci`;
foreach (@bob) {
if (/VGA compatible controller: (.+).$/i) {$scrcard = $1;last;}
}

@bob = `cat /proc/partitions`;
$disksize = 0;

foreach (@bob) {
if (/^\D+\d+\D+0\D+(\d+)/i) {$disksize = $disksize + $1;}
}
$disksize = $disksize * 1000;
$disksize = byte_converter($disksize);
#$disksize = $disksize / 1048576;
#$disksize =~ s/(\d*\.\d\d).+/$1/;

@bob = `cat /proc/ide/ide*/hd*/m*`;
$i = 0;
$diskfound = "";
foreach $er (@bob) {
chomp $er;
if ($i == 1) {$diskfound = "$diskfound:$er "};
if ($i == 0) {$diskfound = "$diskfound$er"};
$i++;if ($i > 1) {$i = 0;}
}
chop $diskfound;
$cputemp = "";
if (@bob = `cat /proc/sys/dev/sensors/*/temp*`) {
$x = 1;
while ($x < $cpucount + 1) {
$erg1 = shift(@bob);
@oh = split(' ',$erg1);
$cputemp = $cputemp . "CPU".$x." $oh[2]C ";
$x++;
}
chop $cputemp;
$cputemp = "%C2temp\003[$cputemp]";
}
push @rawout,("$server /msg $chan %C2%Bcpu%B\003 %C2count\003[$cpucount] %C2vendor\003[$cpuvendor] %C2model\003[$cpumodel] %C2speed\003[$cpumhz MHz] %C2total bogomips\003[$cpumips] %C2cache\003[$cpucache]");
push @rawout,("$server /msg $chan %C2%Bsys%B\003 %C2os\003[$osver] %C2memory\003[$memused/$memtot"."MB] %C2uptime\003[$uptime] %C2load\003[$load] $cputemp");

push @rawout,("$server /msg $chan %C2%Bvideo%B\003 %C2card\003[$scrcard] %C2res\003[$scrwidth"."x$scrheight $scrdepth bit]");

push @rawout,("$server /msg $chan %C2%Bdisk%B\003 %C2total space\003[$disksize] %C2found\003 [$diskfound]");





return 1;
}




sub mass_command { 
my $uhh = shift(@_); 
my @something = split(' ',$uhh);
my $moderestrict = shift @something;
my $ber = "@something";

if (@something < 2) {
output("Use /mcom mode command");
output("eg $hl/mcom +v kick \$n later!\003 or $hl/mcom * mode +b \$b\003 (* = all users on chan)");
output("Use \"$hl+o,+v,-o,-v\003\" for what users to match");
output("$hl\$b\003 = banmask $hl\$bh\003 = host banmask only $hl\$u\003 = username $hl\$h\003 = host $hl\$n\003 = nick $hl\$c\003 = channel");
output("Its a very powerful, and an open-ended way to do a mass command script... enjoy!");

return 1;
}

my $chan = IRC::get_info(2); 
my $mynick = IRC::get_info(1); 
my $server = IRC::get_info(3); 
my $mynick2 = quotemeta $mynick;

my @boos = IRC::user_list ( $chan, $server );
my @boo = split(': ',"@boos");   
foreach $g (@boo) {
my @lister = split(' ',$g);
if (" $lister[0] " !~ / $mynick2 /i) {
$banthing = banmask("*!$lister[1]");
$ber2 = $ber;
@bog = split('@',$lister[1]);
@bog2 = split('@',$banmask);
$ber2 =~ s/\$b/$banthing/i;
$ber2 =~ s/\$n/$lister[0]/i;
$ber2 =~ s/\$c/$chan/i;
$ber2 =~ s/\$u/$bog[0]/i;
$ber2 =~ s/\$h/$bog[1]/i;
$ber2 =~ s/\$bh/$bog2[1]/i;

if ($moderestrict =~ /\*/) {
IRC::command_with_server("/$ber2",$server);
next;
}

if ($lister[2] == 1 && $moderestrict =~ /\+o/i) {
IRC::command_with_server("/$ber2",$server);
next;
}
if ($lister[2] == 0 && $moderestrict =~ /\-o/i) {
IRC::command_with_server("/$ber2",$server);
next;
}
if ($lister[3] == 1 && $moderestrict =~ /\+v/i) {
IRC::command_with_server("/$ber2",$server);
next;
}
if ($lister[3] == 0 && $moderestrict =~ /\-v/i) {
IRC::command_with_server("/$ber2",$server);
next;
}
}
}
return 1;
}
