# RELINKER! Written by Spike, modified by Khaytsus # Known bugs: # # When the local server unlinks, should it be logged as the hub it was on or # the local server itself? Hmm.. # The following variables will probably need changing for you. # Location of the relink statistics log (required to save relink stats) # Otherwise, the stats are only saved as long as teknap is running. assign statlog ~/.TekNap/relinkstats.log assign awollog ~/.TekNap/awol.log # If set to 0 the relinker is disabled initially. assign AUTO_RELINK 1 # Everyone likes different colors, so adjust to taste. assign TIME %B[%W$strftime(%X)%B] # Beeps four times when a server departs if set (can also be started with /notify) assign AUTO_NOTIFY 0 # The following variables shouldn't need changing necessarily unless you want adjust the timings. # How long before a server is relinked after parting. assign RELINKDELAY 300 # How long a remote server is given before it is no longer ignored, in seconds. #assign REMOTEIGNORE 1800 assign REMOTEIGNORE 1200 # How long a local server is given before it is no longer ignored, in seconds. assign LOCALIGNORE 1200 # How long before a relink is attempted *after* the normal 2 minutes. # IE: A relink is attempted at two minutes, if the server does not return # it tries again $RELINKRETRY seconds later, and once again after that. # Referred to as the extended relink period. assign RELINKRETRY 1020 # Leave these alone. Uninitialized arrays seem to not work consistantly. #@ setitem(ignorearray 0 init) #@ setitem(timedarray 0 init) assign canceled 0 assign RELINKVERSION 0.6.1b eval xecho -b Relinker is loaded ${AUTO_RELINK ? [and enabled.] : [but disabled.]} on #^msg 422 "% !enable" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK enable.) assign whoiscmd1 wallop RELINK: Auto-relink has been enabled by $0. assign whoiscmd2 a_relink on whoisfn $0 } on #^msg 422 "% !quietenable" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested a quiet RELINK enable.) assign whoiscmd1 msg $0 Auto-relink has been enabled. assign whoiscmd2 a_relink on whoisfn $0 } on #^msg 422 "% !disable" if (AUTO_RELINK) { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK disable.) assign whoiscmd1 wallop RELINK: Auto-relink has been disabled by $0. assign whoiscmd2 a_relink off whoisfn $0 } on #^msg 422 "% !cancel*" if (AUTO_RELINK) { ^assign canceled 1 if ( [$2] != [] ) ^assign lastservertmp $2 if ( [$2] == [] ) ^assign lastservertmp $lastserver ^assign timerstr $left(4 $lastservertmp)$right(4 $lastservertmp) if (finditem(timedarray $lastservertmp) < 0 && numitems(timedarray) != 0) { assign whoiscmd1 msg $0 That server is not pending a relink. 11!pending-1 will show servers to be relinked. # assign whoiscmd1 msg $0 Server $lastservertmp is not pending a relink. 11!pending-1 will show servers to be relinked. } if (numitems(timedarray) == 0) { assign whoiscmd1 msg $0 No servers pending to be relinked. } if (finditem(timedarray $lastservertmp) > -1) { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK cancel.) assign whoiscmd1 wallop RELINK: Auto-relink of $lastservertmp has been cancelled by $0. assign whoiscmd2 relinkretrydel $lastservertmp if ( [$2] == [] ) { assign whoiscmd3 msg $0 FYI, to cancel a specific server you can send 07!pending-1 to list, and 07!cancel servername-1 to cancel that specific server. } if ( [$2] == [] ) { assign whoiscmd4 msg $0 You can cancel a pending relink of a specific server at any time without disturbing other relinks by specifying the server to cancel. } timer -del ${timerstr}1 timer -del ${timerstr}2 timer -del ${timerstr}3 timer -del ${timerstr}4 timer -del ${timerstr}5 } whoisfn $0 timer 2 ^assign canceled 0 } on #^msg 422 "% !status" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK status.) assign whoiscmd1 msg $0 Auto-relinker is currently ${AUTO_RELINK ? [enabled.] : [disabled.]} whoisfn $0 } on #^msg 422 "% !help" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK help.) assign whoiscmd1 msg $0 11!enable-1 : enables the relinker either initially or after disabling. Version $relinkversion assign whoiscmd2 msg $0 11!disable-1 : disables the relinker entirely. assign whoiscmd3 msg $0 11!11cancel-1 : cancels a relink. 11!cancel server-1 will cancel specific server. assign whoiscmd4 msg $0 11!status-1 : notifies you if the relinker is enabled or disabled. assign whoiscmd5 msg $0 11!awol-1 : tells which servers are missing that we've seen before. assign whoiscmd6 msg $0 11!pending-1 : shows which servers have pending relinks. assign whoiscmd7 msg $0 11!relinkstats-1: Tells which servers have unlinked and how many times. assign whoiscmd8 msg $0 11!quietenable-1: Quietly enables the relinker. whoisfn $0 } on #^msg 422 "% !relinkstats" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested RELINK statistics.) assign whoiscmd1 relinkstats $0 whoisfn $0 } on #^msg 422 "% !awol" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested a list of missing servers.) assign whoiscmd1 awol $0 whoisfn $0 } on #^msg 422 "% !pending" { eval xecho -window public $cparse($TIME %B* RELINK: %wUser %B<%W$0%B> %whas requested a list of pending relinks.) assign whoiscmd1 pending $0 whoisfn $0 } alias whoisfn (user) { //whois -cmd { switch ($tr(/"//$1)) { (Moderator) {;} (User) {;} (Leech) {;} (*) { $whoiscmd1 $whoiscmd2 $whoiscmd3 $whoiscmd4 $whoiscmd5 $whoiscmd6 $whoiscmd7 $whoiscmd8 } } } $user timer 3 @ whoiscmd1 = whoiscmd2 = whoiscmd3 = whoiscmd4 = whoiscmd5 = whoiscmd6 = whoiscmd7 = whoiscmd8 = [] } alias rstat { xecho -b Auto-relinker is currently ${AUTO_RELINK ? [enabled.] : [disabled.]} } alias relink { xecho -b Auto-relinker has been enabled. wallop RELINK: Auto-relink has been enabled. a_relink on } alias quietrelink { xecho -b Auto-relinker has been quietly enabled. a_relink on } alias cancel (server) { if (AUTO_RELINK) { ^assign canceled 1 if ( [$server] != [] ) ^assign lastservertmp $server if ( [$server] == [] ) ^assign lastservertmp $lastserver ^assign timerstr $left(4 $lastservertmp)$right(4 $lastservertmp) if (finditem(timedarray $lastservertmp) < 0 && numitems(timedarray) != 0) { xecho -b That server is not pending a relink. 11/pending-1 will show servers to be relinked. } if (numitems(timedarray) == 0) { xecho -b No servers pending to be relinked. } if (finditem(timedarray $lastservertmp) > -1) { relinkretrydel $lastservertmp xecho -b Auto relink of server $lastservertmp has been canceled. wallop RELINK: Auto-relink of server $lastservertmp has been cancelled by $N if ( [$server] == [] ) { xecho -b FYI, to cancel a specific server you can do 07/pending-1 to list, and 07/cancel servername-1 to cancel that specific server. timer -del ${timerstr}1 timer -del ${timerstr}2 timer -del ${timerstr}3 timer -del ${timerstr}4 timer -del ${timerstr}5 } } timer 2 ^assign canceled 0 } } alias delink { if (AUTO_RELINK) { xecho -b Auto-relinker has been disabled. #wallop RELINK: Auto-relink has been disabled. a_relink off } } alias notify (arg, void) { switch ($tolower($arg)) { (0) (off) { ^assign AUTO_NOTIFY 0 } (1) (on) { ^assign AUTO_NOTIFY 1 } (*) { @ AUTO_NOTIFY = AUTO_NOTIFY ? [0] : [1] } } xecho -b Link-notify beep has been ${AUTO_NOTIFY ? [activated.] : [de-activated.]} } alias a_relink (arg, void) { switch ($tolower($arg)) { (0) (off) { ^assign AUTO_RELINK 0 } (1) (on) { ^assign AUTO_RELINK 1 statload } (*) { @ AUTO_RELINK = AUTO_RELINK ? [0] : [1] } } } alias relinkretry (server) { if (finditem(timedarray $server) > -1 && AUTO_RELINK) { ^assign hubitem ${finditem(timedarray $server)+1} ^assign hubitem2 ${finditem(timedarray $server)} ^assign -hub ^assign linkstring - ^assign hub $getitem(timedarray $hubitem) if ( [$hub] == [] ) ^assign -linkstring wallop RELINK: Requesting server link: $server $linkstring $hub in 20 seconds ^assign lastserver ${server} eval timer 20 { if (finditem(timedarray $lastserver) > -1 && AUTO_RELINK) { admin connect $lastserver $hub } } } } alias relinkretrydel (server) { if (finditem(timedarray $server) > -1) { if (canceled) { ^assign hubitem2 ${finditem(timedarray $server)} @ delitem(timedarray $hubitem2) @ delitem(timedarray $hubitem2) } if (!canceled) { wallop RELINK: Giving up on server $server after ${(RELINKRETRY*2)/60} minutes. ^assign hubitem2 ${finditem(timedarray $server)} @ delitem(timedarray $hubitem2) @ delitem(timedarray $hubitem2) } } } alias ignoredel (server) { @ delitem(ignorearray ${finditem(ignorearray $server)}) } alias showrelink { xecho 10timedarray items $numitems(timedarray) - 0:$getitem(timedarray 0) 1:$getitem(timedarray 1) 2:$getitem(timedarray 2) 3:$getitem(timedarray 3) 4:$getitem(timedarray 4) 5:$getitem(timedarray 5) 6:$getitem(timedarray 6) 7:$getitem(timedarray 7) xecho 10ignorearray items $numitems(ignorearray) - 0:$getitem(ignorearray 0) 1:$getitem(ignorearray 1) 2:$getitem(ignorearray 2) 3:$getitem(ignorearray 3) 4:$getitem(ignorearray 4) 5:$getitem(ignorearray 5) 6:$getitem(ignorearray 6) 7:$getitem(ignorearray 7) xecho 10awollist items $numitems(awollist) - 0:$getitem(awollist 0) 1:$getitem(awollist 1) 2:$getitem(awollist 2) 3:$getitem(awollist 3) 4:$getitem(awollist 4) 5:$getitem(awollist 5) 6:$getitem(awollist 6) 7:$getitem(awollist 7) } alias statadd (serverstat) { if (numitems(statlist $serverstat) > 1) { ^assign statlistnew 1 if (finditem(statlist $serverstat) < -1) { ^assign statlisttmp $numitems(statlist) @ setitem(statlist $statlisttmp $serverstat) @ statlisttmp++ @ setitem(statlist $statlisttmp 1) ^assign statlistnew 0 } if (statlistnew) { if (finditem(statlist $serverstat) > -1) { ^assign statlisttmp $finditem(statlist $serverstat) @ statlisttmp++ ^assign statlistnum $getitem(statlist $statlisttmp) @ statlistnum++ @ setitem(statlist $statlisttmp $statlistnum) } } } if (numitems(statlist) < 1) { @ setitem(statlist $numitems(statlist) $serverstat) @ setitem(statlist 1 1) } if (numitems(statlist) > 1) { ^assign return = $unlink($statlog) @ sl = open($statlog w) ^assign statlistitems 0 while ( statlistitems < numitems(statlist) ) { @ write($sl $getitem(statlist ${statlistitems})) @ statlistitems++ } @ close($sl) } } alias statload { if (fexist($statlog)) { @ delarray(statlist) @ line = 0 @ sr = open($statlog r) while (!eof($sr)) { @ ugh = read($sr) if (eof($sr)) { # done reading statlog } { @ setitem(statlist $line $ugh) @ line++ } } @ close($sr) } } alias relinkstats (nick) { ^assign cmd msg $nick if (nick == "") { ^assign cmd xecho -b } ^assign statlistitems $numitems(statlist) if ( statlistitems == 0 ) { $cmd No servers have unlinked since I was started. } while ( statlistitems > 0 ) { @ statlistitems-- $cmd Server $getitem(statlist ${statlistitems-1}) has unlinked $getitem(statlist ${statlistitems}) times. @ statlistitems-- } @ nick = [] } alias awol (nick) { ^assign cmd msg $nick if (nick == "") { ^assign cmd xecho -b } ^assign awollistitems $numitems(awollist) if ( awollistitems == 0 ) { $cmd All servers seem to be accounted for from what I've seen. } while ( awollistitems > 0 ) { $cmd Server $getitem(awollist ${awollistitems-1}) is AWOL. @ awollistitems-- } @ nick = [] } alias awolload { if (fexist($awollog)) { @ line = 0 @ sr = open($awollog r) while (!eof($sr)) { @ ugh = read($sr) if (eof($sr)) { # done reading awollog } { @ setitem(awollist $line $ugh) @ line++ } } @ close($sr) } } alias awoladd (awolserver) { if (numitems(awollist $awolserver) > 0) { ^assign statlistnew 1 if (finditem(awollist $awolserver) < -1) { ^assign awollisttmp $numitems(awollist) @ setitem(awollist $awollisttmp $awolserver) ^assign statlistnew 0 } if (statlistnew) { if (finditem(awollist $awolserver) > -1) { # xecho Server $awolserver is already in awollist } } } if (numitems(awollist) < 1) { @ setitem(awollist $numitems(awollist) $awolserver) } if (numitems(awollist) > 0) { ^assign return = $unlink($awollog) @ al = open($awollog w) ^assign awollistitems 0 while ( awollistitems < numitems(awollist) ) { @ write($al $getitem(awollist ${awollistitems})) @ awollistitems++ } @ close($al) } } alias awoldel (awolserver) { ^assign awollisttmp $finditem(awollist $awolserver) if (awollisttmp > -1) { @ delitem(awollist $awollisttmp) } if (awollisttmp < 0) { # xecho $awolserver isn't in awollist } if (numitems(awollist) > -1) { ^assign return = $unlink($awollog) @ sl = open($awollog w) ^assign awollistitems 0 while ( awollistitems < numitems(awollist) ) { @ write($sl $getitem(awollist ${awollistitems})) @ awollistitems++ } @ close($sl) } } alias pending (nick) { ^assign cmd msg $nick ^assign to to if (nick == "") { ^assign cmd xecho -b } ^assign timedarraytmp $numitems(timedarray) if ( timedarraytmp == 0 ) { $cmd No pending relinks at this time. } while ( timedarraytmp > 0 ) { if ( [$getitem(timedarray ${timedarraytmp-1})] == [] ) ^assign -to $cmd Pending relink for $getitem(timedarray ${timedarraytmp-2}) $to $getitem(timedarray ${timedarraytmp-1}) @ timedarraytmp-- @ timedarraytmp-- ^assign to to } @ nick = [] } on #^404 423 "Server * requested link" { eval xecho -window public $cparse($TIME %G* %GNETWORK: %wServer %G<%G$1%G> %whas requested link.) } on #^404 423 "Server * has joined" { ^assign server $tolower($1) eval xecho -window public $cparse($TIME %G* %GNETWORK: %wServer %G<%B$server%G> %whas joined.) awoldel $server ^assign timerstr $left(4 $server)$right(4 $server) timer -del ${timerstr}1 timer -del ${timerstr}2 timer -del ${timerstr}3 timer -del ${timerstr}4 timer -del ${timerstr}5 if (finditem(timedarray $server) > -1) { ^assign hubitem ${finditem(timedarray $server)+1} ^assign hubitem2 ${finditem(timedarray $server)} ^assign linkstring - @ hub $getitem(timedarray $hubitem) @ delitem(timedarray $hubitem2) @ delitem(timedarray $hubitem2) } } on #^404 423 "Server link to * failed" { eval xecho -window public $cparse($TIME %G* %GNETWORK: %wServer link to %G<%M$1%G> %wfailed.) if (AUTO_NOTIFY) beep if (AUTO_RELINK) wallop RELINK: Server link failed: $3 } on #^404 423 "Server % has quit: *" { awoladd $tolower($1) } on #^404 423 "Server % has quit: EOF *" { ^assign hub $tr(/\)//$tr(/\(//$5)) ^assign server $tolower($1) eval xecho -window public $cparse($TIME %G* %GNETWORK: %wServer %G<%R$server%G> %whas quit. $5) statadd $server awoladd $server if (AUTO_NOTIFY) { beep;timer 1 beep;timer 2 beep;timer 3 beep } if (AUTO_RELINK == 0) { # wallop RELINK: Server $server relink ignored, relinking disabled. } if (AUTO_RELINK == 1) { ^assign lastserver $server ^assign timerstr $left(4 $server)$right(4 $server) if (finditem(ignorearray $server) > -1) { wallop RELINK: Server $server relink delayed, unlinked less than ${REMOTEIGNORE/60} minutes ago. Will attempt retry in ${REMOTEIGNORE/60} minutes. if (finditem(timedarray $server) < 0) { @ setitem(timedarray $numitems(timedarray) $server) @ setitem(timedarray $numitems(timedarray) $hub) timer -ref ${timerstr}1 $REMOTEIGNORE relinkretry $server } } if (finditem(ignorearray $server) < 0) { @ setitem(ignorearray $numitems(ignorearray) $server) timer 1 wallop RELINK: Server split detected: $server - $hub - Requesting link in ${RELINKDELAY/60} minutes. timer 3 wallop RELINK: To cancel: /msg $N !cancel if (finditem(timedarray $server) < 0) { @ setitem(timedarray $numitems(timedarray) $server) @ setitem(timedarray $numitems(timedarray) $hub) timer -ref ${timerstr}2 $RELINKRETRY relinkretry $server timer -ref ${timerstr}3 ${RELINKRETRY*2} relinkretry $server timer -ref ${timerstr}4 ${(RELINKRETRY*2)+30} relinkretrydel $server } timer $REMOTEIGNORE ignoredel $server timer -ref ${timerstr}5 $RELINKDELAY relinkretry $server } } } on #^404 423 "Server * has quit: EOF" { ^assign server $tolower($1) eval xecho -window public $cparse($TIME %G* %GNETWORK: %wServer %G<%R$server%G> %whas quit. (local)) statadd $server awoladd $server if (AUTO_NOTIFY) { beep;timer 1 beep;timer 2 beep;timer 3 beep } if (AUTO_RELINK == 0) { # wallop RELINK: Server $server relink ignored, relinking disabled. } if (AUTO_RELINK == 1) { ^assign lastserver $server ^assign timerstr $left(4 $server)$right(4 $server) if (finditem(ignorearray $server) > -1) { wallop RELINK: Server $server relink ignored, unlinked less than ${LOCALIGNORE/60} minutes ago. Will attempt retry in ${LOCALIGNORE/60} minutes. if (finditem(timedarray $server) < 0) { @ setitem(timedarray $numitems(timedarray) $server) @ setitem(timedarray $numitems(timedarray) ) timer -ref ${timerstr}1 $REMOTEIGNORE relinkretry $server } } if (finditem(ignorearray $server) < 0) { @ setitem(ignorearray $numitems(ignorearray) $server) timer 1 if (AUTO_RELINK) wallop RELINK: Server split detected: $server - Requesting link in ${RELINKDELAY/60} minutes. timer 3 if (AUTO_RELINK) wallop RELINK: To cancel: /msg $N !cancel if (finditem(timedarray $server) < 0) { @ setitem(timedarray $numitems(timedarray) $server) @ setitem(timedarray $numitems(timedarray) ) timer -ref ${timerstr}2 $RELINKRETRY relinkretry $server timer -ref ${timerstr}3 ${RELINKRETRY*2} relinkretry $server timer -ref ${timerstr}4 ${(RELINKRETRY*2)+30} relinkretrydel $server } timer $LOCALIGNORE ignoredel $server timer -ref ${timerstr}5 $RELINKDELAY relinkretry $server } } } statload awolload