# DALnet links script written by Wizzu # Extensively based on the version written by FireMyst # and modified by Data # Although written for DALnet, it could probably be easily modified for # other IRC nets (as long as the first part of each server name is # unique). # This script uses an external server list file and an # exec command to read it. # Load a list of DALnet servers from the file specified below. if ([$dalservfile]==[]) { ^assign dalservfile \${HOME}/.dalservers } # Handle transforming the list of servers from file to a list on ^exec "dservgrep*" { if ([$1]) { if ([$index(. $1)]>[0]) { @ server_list = [$server_list] ## [$left($index(. $1) $1) ] ^assign serverinfo[$encode($left($index(. $1) $1))][fullname] $1 ^assign serverinfo[$encode($left($index(. $1) $1))][IP] #eval echo ### Adding $left($index(. $1) $1) to server list [$dserv_count]. } { @ server_list = [$server_list] ## [$1 ] #echo ### Adding $1 to server list [$dserv_count]. } @dserv_count = dserv_count + 1 } } on ^exec_exit "dservgrep*" { echo ### DALnet server list loaded, $dserv_count servers. ^on ^exec -"dservgrep*" ^on ^exec_exit -"dservgrep*" ^assign -dserv_count } @ dserv_count = 0 # Check whether given server is a hub or not (in the hub list) alias ishub { if (match($0 $hub_list)) { if ([$0] == [$left($index(. $S) $S)]) { # current server is not considered a hub # even though it could be, that is handled elsewhere @function_return=[0] } { @function_return=[1] } } { @function_return=[0] } } # Clear all hub (/links list) info alias clear_hubs { ^assign -links_time ^assign -start_hub ^assign -extrastr ^assign -missingstr ^assign -longest_hubname @ hub_list = [] foreach hub curr_hub { eval foreach hub.$curr_hub curr_part { if ([$curr_part]==[leafs]) { eval foreach hub.${curr_hub}.leafs curr_leaf { ^assign -hub[$curr_hub][leafs][$curr_leaf] } } { ^assign -hub[$curr_hub][$curr_part] } } } ^assign -curr_hub ^assign -curr_part ^assign -curr_leaf ^assign -hub_count ^assign -leaf_count } # Show line for hub alias show_hub { # $0 = hub name for which to show line to # $1 = hub index number @ hoppies = [<] ## [$hub[$encode($0)][hops]] ## [>] @ hub_uplink = [$serverinfo[$hub[$encode($0)][uplink]][shortname]] @ hub_name = [$serverinfo[$encode($tolower($0))][shortname]] eval foreach hub.$encode($0).leafs curr_leaf { @ leaf = [$serverinfo[$curr_leaf][shortname]] if (rmatch($leaf $matchserver)) { @ leaf = [\$leaf\] } { if (ishub($leaf)) { @ leaf = [\$leaf\] } { if ([$leaf]==[$left($index(. $S) $S)]) { @ leaf = [\($leaf\)] } { if ([$leaf]==[services]) { @ leaf = [\$leaf\] } } } } if (rmatch($decode($curr_leaf) jupe:*)) { @ leaf = [\[Jupe: $mid(5 99 $leaf)\]] } @ leafs = [$leafs] ## [$leaf ] } if ([$hub[$encode($0)][count]] > [1]) { @ leafs = [$leafs] ## [\[$hub[$encode($0)][count]\]] } if ([$show_uplink]) { eval xecho -level crap ### $$[$longest_hubname]{hub_uplink}$$[-3]1 $$[$longest_hubname]{hub_name} $$[-4]{hoppies} $leafs } { eval xecho -level crap ### $$[-2]1 $$[$longest_hubname]{hub_name} $$[-4]{hoppies} $leafs } ^assign -leaf ^assign -curr_leaf ^assign -hub_name ^assign -hub_uplink ^assign -hoppies ^assign -leafs } # Show the links list alias showlinks { # Show header line @ tmphubstr = [Hubs ${hub_count}] @ tmpuplinkstr = [Uplink] if ([$show_uplink]) { eval xecho -level crap ### $$[$longest_hubname]{tmpuplinkstr}  # $$[$longest_hubname]{tmphubstr} Hops Leaves ${leaf_count} - Current server: $links_server } { eval xecho -level crap ###  # $$[$longest_hubname]{tmphubstr} Hops Leaves ${leaf_count} - Current server: $links_server } ^assign -tmphubstr ^assign -tmpuplinkstr # Show hub lines @ hub_counter = 0 @ show_hubs = [$start_hub] while ([$word($hub_counter $show_hubs)]!=[]) { @ curr_hub = [$word($hub_counter $show_hubs)] @ hub_counter = [$hub_counter] + 1 show_hub $curr_hub $hub_counter eval foreach hub.$encode($curr_hub).leafs cserv { if (ishub($decode($cserv))) { @ hub[$cserv][uplink] = [$encode($curr_hub)] @ show_hubs = [$show_hubs ] ## [$decode($cserv)] } } #^assign -hub[$encode($curr_hub)][hops] #^assign -hub[$encode($curr_hub)][count] #^assign -hub[$encode($curr_hub)][leafs] #^assign -hub[$encode($curr_hub)][uplink] } # Show trailing summary line xecho -level crap ### Servers Connected: $servct\ $missingstr $extrastr ^assign -cserv ^assign -curr_hub ^assign -hub_counter ^assign -show_hubs } ### User commands # Show known information for each server (not /links related) alias si serverinfo alias serverinfo { if ([$0]) { @ siserv = [$encode($tolower($0))] if ([$serverinfo[$siserv][fullname]]) { xecho -level crap ### Full name: $serverinfo[$siserv][fullname] IP address: $serverinfo[$siserv][IP] xecho -level crap ### $serverinfo[$siserv][tagline] if ([$hub[$siserv][leaflist]]) { if ([$hub[$siserv][uplink]]) { xecho -level crap ### Is a hub, uplink: $decode($hub[$siserv][uplink]), leafs: $hub[$siserv][leaflist] } { xecho -level crap ### Is a hub, leafs: $hub[$siserv][leaflist] } } { xecho -level crap ### Is a leaf } } { xecho -level crap ### Sorry, no info on server $0. } } { eval xecho -level crap ### Usage: ${K}serverinfo  will show info on server based on the ${K}links list. } } # Toggle showing of uplink in the /links display alias uplink { if ([$0]==[ON]) { ^assign show_uplink YES eval xecho -level crap ### Showing uplinks in ${K}links display. } { if ([$0]==[OFF]) { ^assign -show_uplink eval xecho -level crap ### Hiding uplinks in ${K}links display. } { if ([$show_uplink]) { eval xecho -level crap ### Show/hide the uplink column in the ${K}links list output. Currently ON. } { eval xecho -level crap ### Show/hide the uplink column in the ${K}links list output. Currently OFF. } eval xecho -level crap ### Usage: ${K}uplink ON or ${K}uplink OFF } } } # Show again the latest /links list alias relinks { if ([$0]) { ^assign matchserver $0- } if ([$links_time]) { eval xecho -level crap ### The ${K}links list is $tdiff(${time() - links_time}) old showlinks } { eval xecho -level crap ### Sorry, but there is no ${K}links list to show again. } } # The actual links alias. alias links { clear_hubs @ matchserver = [$0-] @ current_servers = [] @ extra = [] @ servct = 0 @ extract = 0 @ longest_hubname = 0 @ hub_count = 0 @ leaf_count = 0 ^assign status_user1_old $status_user1 ^set status_user1 [Links starting...] ${K}${K}links } ### The handlers for parsing /links output ^on ^364 "*" { ^assign shortserv $left($index(. $1) $1) if (rmatch($4 jupiter* jupe*) || rmatch($5 jupiter* jupe*)) { ^assign shortserv jupe:${shortserv} } ^assign eserv $encode($tolower($shortserv)) ^assign serverinfo[$eserv][fullname] $1 ^assign serverinfo[$eserv][shortname] $shortserv if ([$strip(0123456789.[] $4)]==[]) { ^assign serverinfo[$eserv][IP] $4 ^assign serverinfo[$eserv][tagline] $5- } { ^assign serverinfo[$eserv][tagline] $4- } ^set status_user1 [Links: $[10]shortserv] if ([$server_list]) { if (!rmatch($shortserv $server_list)) { @ extra = [$extra] ## [$shortserv ] @ extract = [$extract] + 1 } } # else there is no server list, and we don't keep track of "extra" servers @ current_servers = [$current_servers] ## [$shortserv ] @ servct = [$servct] + 1 if ([$3]>[0]) { eval assign shub $tolower($left($index(. $2) $2)) @ ehub = [$encode($shub)] if ([$hub[$ehub][count]]!=[]) { @ hub[$ehub][count] = [$hub[$ehub][count]] + 1 @ hub[$ehub][leafs][$eserv] = [$1] @ hub[$ehub][leaflist] = [$hub[$ehub][leaflist]] ## [ $shortserv] @ leaf_count = leaf_count + 1 #echo ??? Adding $shortserv as leaf of $shub - $hub[$ehub][count] leafs } { @ hub[$ehub][hops] = [$3] @ hub[$ehub][count] = [1] @ hub[$ehub][leafs][$eserv] = [$1] @ hub[$ehub][leaflist] = [$shortserv] @ hub_list = [$hub_list] ## [$shub ] if ([$@shub] > [$longest_hubname]) { @ longest_hubname = [$@shub] } @ hub_count = hub_count + 1 #echo ??? New hub $shub, leaf $shortserv - $hub[$ehub][count] leaf } assign last_leaf $tolower($shortserv) } { assign last_hub $tolower($left($index(. $2) $2)) @ leaf_count = leaf_count + 1 } } ^on ^365 "*" { ^set status_user1 [Links showing... ] # Save source server name @ links_server = [$0] @ links_time = [$time()] # Figure out missing servers @ misscounter = 0 @ missing = [] @ missct = 0 while ([$word($misscounter $server_list)]!=[]) { if (!rmatch($word($misscounter $server_list) $current_servers)) { @ missing = [$missing] ## [$word($misscounter $server_list) ] @ missct = [$missct] + 1 } @ misscounter = misscounter + 1 } # See if current server is really a hub (has more than 1 leaf) # if not, check if the "leaf" has any leafs # - if yes, it's a hub # - if no, there's really just 2 servers if ([$hub[$encode($last_hub)][count]]==[1]) { if ([$hub[$encode($last_leaf)][count]]>[0]) { @ real_hub = [$encode($last_leaf)] ^assign -hub[$encode($last_hub)][leafs][$real_hub] ^assign -hub[$encode($last_hub)][leaflist] ^assign -hub[$encode($last_hub)][count] ^assign -hub[$encode($last_hub)][hops] @ hub[$real_hub][count] = [$hub[$real_hub][count]] + 1 #@ hub[$real_hub][uplink] = [$encode($last_hub)] @ hub[$real_hub][uplink] = [] @ hub[$real_hub][leafs][$encode($last_hub)] = [$last_hub] @ hub[$real_hub][leaflist] = [$hub[$real_hub][leaflist]] ## [ $last_hub] @ last_leaf = [$last_hub] @ last_hub = [$decode($real_hub)] ^assign -real_hub @ hub_count = hub_count - 1 @ leaf_count = leaf_count + 1 } } @ start_hub = [$last_hub] # Put the trailing summary together. if ([$server_list]!=[]) { if ([$missing] != []) { @ missingstr = [ Missing: $missct\ - $missing] } { @ missingstr = [ (all present)] } if ([$extra] != []) { @ extrastr = [Extra: $extract\ - $extra] } } # Show links info showlinks ^assign -last_hub ^assign -last_leaf ^assign -counter ^assign -ehub ^assign -eserv ^assign -shortserv ^assign -misscounter ^assign -missing ^assign -extra ^assign -missct ^assign -extract if ([$status_user1_old]!=[]) { ^set status_user1_old $status_user1 } { ^set -status_user1 } ^assign -status_user1_old } ### Serverping commands -- require a valid "serverping" alias # To be used with the serverping.irc script # Ping given server and all servers on route to that server with /serverping alias rping routeping alias rp routeping alias routeping { if ([$0]) { # figure out the route here; add servers to ping_servers ^assign -hubs foreach hub curr_serv { @ hubs = [$hubs] ## [$curr_serv ] } @ curr_serv = [$word(0 $hub_list)] @ servidx = 0 #echo looking for hub of server matching $0... ##echo starting with $curr_serv while (([$curr_serv]!=[]) && ([$targethub]==[])) { ##echo checking leafs of hub $curr_serv # check leafs of hub $curr_serv if (match($0 $hub[$encode($curr_serv)][leaflist])) { # found matching server @ targethub = [$encode($curr_serv)] #@ targetserv = [$word(${match($0 $hub[$encode($curr_serv)][leaflist])-1} $hub[$encode($curr_serv)][leaflist])] #@ ping_servers = [$serverinfo[$encode($targetserv)][fullname]] @ ping_servers = [$serverinfo[$encode($tolower($word(${match($0 $hub[$encode($curr_serv)][leaflist])-1} $hub[$encode($curr_serv)][leaflist])))][fullname]] #echo found matching server $targetserv, hub is $curr_serv } @ servidx = servidx + 1 @ curr_serv = [$word($servidx $hub_list)] } if ([$targethub]) { # then we have a hub for starting to check for a "route" ##echo serverping list has $ping_servers - figuring out other servers to ping... @ curr_hub = [$targethub] while ([$curr_hub]) { if ([$ishub($decode($curr_hub))]) { ##echo adding $decode($curr_hub) to list @ ping_servers = [$serverinfo[$curr_hub][fullname] ] ## [$ping_servers] @ curr_hub = [$hub[$curr_hub][uplink]] ##echo next hub to check is $decode($curr_hub) if ([$decode($curr_hub)]==[$left($index(. $S) $S)]) { ^assign -curr_hub } } { ^assign -curr_hub } } #echo serverpings list: $ping_servers - doing serverpings... # do the actual serverpings @ servidx = 0 @ curr_serv = [$word(0 $ping_servers)] while ([$curr_serv]) { @ servidx = servidx + 1 timer $servidx serverping $curr_serv @ curr_serv = [$word($servidx $ping_servers)] } ^assign -targethub ^assign -ping_servers } { # no server was found to be hub with a leaf matching $0 xecho -level crap ### Sorry, couldn't find a server matching $0 } ^assign -servidx ^assign -curr_serv } { eval xecho -level crap ### Usage: ${K}routeping  - serverping server and each server on route to server eval xecho -level crap ### You must have a valid ${K}serverping command. } } # Ping all hubs with /serverping alias pinghubs hubping alias hping hubping alias hubping { xecho -level crap ### Pinging all current hubs. spingexpand $hub_list } # Ping all current servers with /serverping alias allping allservping alias aping allservping alias allservping { xecho -level crap ### Pinging all current servers. spingexpand $current_servers } # Expand server to server.dal.net (using serverinfo data) alias spingexpand { @ servidx = 0 @ curr_serv = [$word($servidx $0-)] while ([$curr_serv]) { @ servidx = servidx + 1 @ spingdelay = servidx * 3 if ([$curr_serv]!=[$left($index(. $S) $S)]) { timer $spingdelay serverping $serverinfo[$encode($curr_serv)][fullname] } @ curr_serv = [$word($servidx $0-)] } ^assign -servidx ^assign -spingdelay ^assign -curr_serv } ### Executed at load time # Load the server list from the file specified if (rmatch($S *.dal.net)) { ^assign -server_list #eval exec -name dservgrep grep -v '^#' $dalservfile | sed 's/\\\\..*\\\$//' exec -name dservgrep grep -v '^#' $dalservfile } xecho -level crap ### YALinks 3.2.4 by Wizzu , 26-Oct-1997 eval xecho -level crap ### Usage: ${K}links [highlight servers] ${K}relinks [highlight servers] eval xecho -level crap ### ${K}serverinfo  ${K}uplink  eval xecho -level crap ### With ${K}serverping: ${K}routeping  ${K}hubping ${K}allping