# This script is intended for use with 2.8 servers on all sites.
# It's an extension of the 2.8script but with much much nicer 
# formatting.


@ RCS.newformat = [$$Header: /home/cvs/ircii/script/newformat,v 1.3 2001/08/12 15:44:17 mrg Exp $$]
# An operator command. ESC-t turns this option on and off.
# It allows one to see users or not see them in a TRACE.
# It also effects the output of STAT l

^bind meta1-t parse_command tt
^alias tt if (trace) { assign -trace } { assign trace x }

# Stores the output of a trace for use with conall
^alias trace ^cleantr;//trace $0-

^alias storetrace {
    if (index([ $0)>-1) 
      { assign trace.$strip([].-0123456789/* $0) $left($index([ $0) $0) }
      { assign trace.$strip([].-0123456789/* $0) $0 }
}

^alias cleantr foreach trace ii { assign -trace[$ii] }
# connect to all the servers listed in the last trace
# food for when you restart the server.
^alias conall foreach trace ii { connect $trace[$ii] }

^alias topic if ([#]==[$[1]0]) { //topic $* } { //topic $C $* }
^alias invite if ([$1]) { //invite $0 $1 } { //invite $0 $C }

# Don't EVER screw with the format() or lformat() commands
# as many other things may use them.
^alias format {
	@ IRCII.word = [$1-]
	if (@IRCII.word < [$0]) 
		{ @ function_return = [$([-$0]IRCII.word)] } 
		{ @ function_return = [$IRCII.word] } 
}
^alias lformat {
	@ IRCII.word = [$1-]
	if (@IRCII.word < [$0]) 
		{ @ function_return = [$([$0]IRCII.word)] } 
		{ @ function_return = [$IRCII.word] } 
}


# Trace information
# -----------------

# define RPL_TRACELINK        200
^on ^200 * echo $[7]0 $1 $lformat(23 [$2]) ==> $3-

# define RPL_TRACECONNECTING  201
^on ^201 * echo $[7]0 $1 Class$format(7 [$2]) trying...  ==> $3-

# define RPL_TRACEHANDSHAKE   202
^on ^202 * echo $[7]0 $1 Class$format(7 [$2]) handshake  ==> $3-

# define RPL_TRACEUNKNOWN     203
^on ^203 * echo $[7]0 $1 Class$format(7 [$2]) *unknown*  ==> $3-

# define RPL_TRACEOPERATOR    204
^on ^204 * echo $[7]0 $1 Class$format(7 [$2])  $format(9 1C) ==> $left(35 $3)

# define RPL_TRACEUSER        205
^on ^205 * if (trace) { echo $[7]0 $1 Class$format(7 [$2])  $format(9 1C) ==> $left(35 $3) }

# define RPL_TRACESERVER      206
^on ^206 * storetrace $5;echo $[7]0 $1 Class$format(7 [$2]) $format(4 $3) $format(5 $4) ==> $left(35 $5)


# define RPL_TRACESERVICE     207
^on ^207 * echo $[7]0 $1 Class[$format(7 $2)] service    ==> $3-

# define RPL_TRACENEWTYPE     208
^on ^208 * echo $[7]0 $1 Class[$format(7 $2)] newtype    ==> $3-

# define RPL_TRACECLASS       209
^on ^209 * echo $[7]0 -==- $1$format(7 [$2]) Entries linked: $3

# numeric 261   A debug file type in a trace
^on ^261 * echo $[7]0 $1 Level$format(7 [$3])  $[9]xbogus ==> $2


# Stats information
# -----------------

alias statsltime {
	if ([$1] != [])
		{@function_return = left(19 $*)}
		{@function_return = left(16 $shorttime($tdiff($0)))}
}

# takes time as returned from $tdiff() e.g. 23 days 1 hour 32 minutes 10 seconds
#  and puts it in the format   23d 1h 32m 10s
alias shorttime {
	@ function_return = [$0] ## left(1 $1) ## [ $2] ## left(1 $3) ## [ $4] ## left(1 $5) ## [ $6] ## left(1 $7)
}

alias stats {
	if ([$0] == [l])
	{
		echo $lformat(17 Server) $lformat(40 Link) $lformat(16 Connect Time)
        if (vercomp($R 2.8.20) >= 0)
		{
			echo $lformat(10 SendQ) $lformat(10 SendM) $lformat(10 SendKBytes) $lformat(10 RcveM) $lformat(7 RcveKBytes)
		}
		{
		    echo $lformat(10 SendQ) $lformat(10 SendM) $lformat(10 SendBytes) $lformat(10 RcveM) $lformat(7 RcveBytes)
		}
	}
	//stats $*
}

# define RPL_STATSLINKINFO    211
^on ^211 * ^echo $[17]0 $[40]1 $statsltime($7-);echo $[10]2 $[10]3 $[10]4 $[10]5 $[7]6
^on ^211 "% *.*[*.*] *" ^echo $[17]0 $[40]1 $statsltime($7-);echo $[10]2 $[10]3 $[10]4 $[10]5 $[7]6
^on ^211 "% *[*" if (trace) {^echo $[17]0 $[40]1 $statsltime($7-);echo $[10]2 $[10]3 $[10]4 $[10]5 $[7]6}
# ^on ^211 * ^echo $[7]0 $[20]1 $[10]3 $[10]5 $7-

# define RPL_STATSCOMMANDS    212
^on ^212 * ^echo $[7]0 $[10]1 :  $[-10]2 $[-10]3

# define RPL_STATSCLINE       213
# ^on ^213 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# define RPL_STATSNLINE       214
# ^on ^214 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# define RPL_STATSILINE       215
^on ^215 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# define RPL_STATSKLINE       216
^on ^216 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# define RPL_STATSQLINE      217
^on ^217 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# define RPL_STATSYLINE      218
# ^on ^218 * ^echo $[7]0 $1:$[5]2:$[5]3:$[5]4:$[5]5:$6-

#
# 220 is used by .troy versions to return information on
# host masks being enforced locally.
#
^on ^220 * ^echo $[7]0 $1: $[25]2:$3: $[25]4:$5:$6-

# User Mode (2.1.5 actually knows about this. This is for 2.1.4e)
# define RPL_UMODEIS          221
^on ^221 * ^echo  $[7]0 Your user mode is $1

^comment Service list:
^on ^231 * ^echo  $[7]0 Service $1 ($0)

^comment Ban list:
^on ^367 * ^echo $[7]0 ban in [ $[15]1 ] for [ $[30]2- ]

^on ^369 * if (SHOW_END_OF_MSGS==[ON])
	{
		if (SHOW_NUMERICS==[ON]) {echo 369 $1-} {echo *** $1-}	
	}

alias vercomp {
	@ vc.one = [$0]
    @ vc.two = [$1]

  if (vc.one == vc.two) {
	@function_return = 0
  }
  {
	# Mika totally broke the version syntax.. annoying SOB
	if (match(2.8/dog3* $vc.one)) { @ vc.one = [2.8.16.dog3] }
	if (match(2.8/dog3* $vc.two)) { @ vc.two = [2.8.16.dog3] }

	while (left($index(. $vc.one) $vc.one) == left($index(. $vc.two) $vc.two))
	{
		@ vc.one = mid(${index(. $vc.one) +1} 30 $vc.one)
		@ vc.two = mid(${index(. $vc.two) +1} 30 $vc.two)
	}
    if (vc.one > vc.two)
		{ @function_return = 1 }
		{ @function_return = -1 }
  }
  ^assign -vc.one
  ^assign -vc.two
}
	
