Half-Life Server Browser — File Browser

Half-LifeServerBrowserv1.0 / Half-LifeServerBrowserv1.0 / hlsb.mrc

hlsb.mrc — 20.79 KB — Download this file

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Half-Life Server Browser (HLSB)
;; by bobby - bobby921@gmail.com
;; irc.GameSurge.net - #script
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

on *:load:{
  if ((!$exists(" $+ $scriptdirMDX.dll $+ ")) || (!$exists(" $+ $scriptdirVIEWS.mdx $+ ")) || (!$exists(" $+ $scriptdirhl.ico $+ "))) {
    var %msg = $input(Some required files are missing! $+ $crlf $+ Please make sure they are all there $+ $chr(44) then load this script again. $+ $crlf $+ $crlf $+ These files can be: $+ $crlf $+ $crlf $+ MDX.dll $+ $crlf $+ VIEWS.mdx $+ $crlf $+ hl.ico,ow,Error!)
    .timerunload 1 1 unload -rs $+(",$script,")
  }
  else dialog -m hlsb_options hlsb_options
}

on *:unload:{
  if (%hlsb.server) unset %hlsb.server
  if ($exists(" $+ $scriptdirhlsb.ini $+ ")) {
    var %msg = $input(Do you want to remove HLSB's config file?,y)
    if (%msg = $true) .remove -b " $+ $scriptdirhlsb.ini $+ "
  }
}

alias hlsb {
  if ($dialog(hlsb)) dialog -v hlsb
  else dialog -md hlsb hlsb
}

menu status,channel,query,menubar {
  -
  HLSB:hlsb
  -
}

dialog hlsb_options {
  title "HLSB - Options"
  icon $scriptdirhl.ico
  size -1 -1 143 95
  option dbu
  text "Path to Steam.exe:", 1, 5 5 49 8
  edit "", 2, 4 13 135 10
  button "Browse..", 3, 4 24 37 10
  text "When Connecting:", 4, 5 39 47 8
  text "Edit Saved Servers:", 6, 5 60 49 8
  button "Open File", 7, 4 69 37 10
  box "", 8, 0 0 142 82
  button "Save", 9, 64 84 37 10
  button "Cancel", 10, 104 84 37 10
  radio "Minimize HLSB", 5, 5 48 50 10
  radio "Close HLSB", 11, 55 48 50 10
}

on *:dialog:hlsb_options:init:0:{
  var %steampath = $readini(" $+ $scriptdirhlsb.ini $+ ",options,steampath)
  var %connectclose = $readini(" $+ $scriptdirhlsb.ini $+ ",options,connectclose)
  if (%steampath) did -a hlsb_options 2 %steampath
  if (%connectclose == 1) did -c hlsb_options 11
  else did -c hlsb_options 5
}

on *:dialog:hlsb_options:sclick:3:{
  var %steampath = $sfile($gettok($mircdir,1,92) $+ \Steam.exe,Locate Steam.exe,Save)
  if (%steampath) {
    did -r hlsb_options 2
    did -a hlsb_options 2 %steampath
  }
}

on *:dialog:hlsb_options:sclick:7:{ if ($exists($scriptdirhlsb.ini)) run " $+ $scriptdirhlsb.ini $+ " }

on *:dialog:hlsb_options:sclick:9:{
  if ($did(hlsb_options,2)) writeini " $+ $scriptdirhlsb.ini $+ " options steampath $ifmatch
  if ($did(hlsb_options,5).state == 1) writeini " $+ $scriptdirhlsb.ini $+ " options connectclose 0
  if ($did(hlsb_options,11).state == 1) writeini " $+ $scriptdirhlsb.ini $+ " options connectclose 1
  dialog -x hlsb_options
}

on *:dialog:hlsb_options:sclick:10:{ dialog -x hlsb_options }

dialog hlsb {
  title "Half-Life Server Browser"
  icon $scriptdirhl.ico
  size -1 -1 168 91
  option dbu
  combo 1, 2 4 125 50, size edit vsbar drop
  button "Update", 2, 130 4 37 10
  text "Hostname:", 3, 2 19 28 8
  edit "", 4, 30 18 137 10, read autohs
  text "Game:", 5, 12 31 17 8
  edit "", 6, 30 30 99 10, read
  text "Type:", 7, 13 43 16 8
  edit "", 8, 30 42 99 10, read
  text "Locked?", 9, 65 67 22 8
  edit "", 10, 88 66 20 10, read
  text "Approx Ping:", 11, 114 67 33 8
  edit "", 12, 147 66 20 10, read
  text "Players:", 13, 8 67 21 8
  edit "", 14, 30 66 28 10, read
  text "Map:", 15, 15 55 14 8
  edit "", 16, 30 54 99 10, read
  button "Player Info", 17, 2 80 37 10
  button "Game Options", 18, 44 80 38 10
  button "Refresh", 19, 88 80 36 10
  button "Close", 20, 130 80 37 10, ok
  button "Connect!", 21, 131 30 36 34
  list 22, 2 95 165 54, extsel size
  button "Player Info <<", 23, 125 151 41 10
}

on *:dialog:hlsb:init:0:{
  var %x = 1
  while (%x <= $ini(" $+ $scriptdirhlsb.ini $+ ",servers,0)) {
    did -a hlsb 1 $readini(" $+ $scriptdirhlsb.ini $+ ",servers,$ini(" $+ $scriptdirhlsb.ini $+ ",servers,%x))
    if (%x == $ini(" $+ $scriptdirhlsb.ini $+ ",servers,0)) {
      did -c hlsb 1 1 $readini(" $+ $scriptdirhlsb.ini $+ ",servers,$ini(" $+ $scriptdirhlsb.ini $+ ",servers,%x))
    }
    inc %x
  }
  refreshserver
}

on *:dialog:hlsb:close:0:{
  if ($timer(unsethlquery)) .timerunsethlquery off
  if ($timer(autoretry)) .timerautoretry off
  if ($dialog(auto_retry)) dialog -x auto_retry
  if ($dialog(hlsb_options)) dialog -x hlsb_options
  unset %queryhl.*
}

on *:dialog:hlsb:sclick:1:{ refreshserver }

on *:dialog:hlsb:sclick:2:{
  if ($did(hlsb,1) == $null) return
  var %ip = $did(hlsb,1).seltext
  var %x = 1, %ip = $dll(" $+ $scriptdiripresolve2.dll $+ ",getip,$gettok(%ip,1,58)) $+ $iif($gettok(%ip,2,58),: $+ $ifmatch)
  if ($gettok($ipverify(%ip),1,32) == Valid) {
    refreshserver
    while (%x <= $ini(" $+ $scriptdirhlsb.ini $+ ",servers,0)) {
      ; checks if the ip address given is already in the past ip list
      if ($readini(" $+ $scriptdirhlsb.ini $+ ",servers,$ini(" $+ $scriptdirhlsb.ini $+ ",servers,%x)) == %ip) var %alreadythere = 1
      ; does the same, but it's a safety net for dns names so it doesn't get added twice
      if ($readini(" $+ $scriptdirhlsb.ini $+ ",servers,$ini(" $+ $scriptdirhlsb.ini $+ ",servers,%x)) == $did(hlsb,1)) var %alreadythere = 1
      inc %x
    }
    if (!%alreadythere) {
      writeini -n " $+ $scriptdirhlsb.ini $+ " servers $calc($ini(" $+ $scriptdirhlsb.ini $+ ",servers,0) + 1) $did(hlsb,1)
      did -a hlsb 1 $did(hlsb,1)
    }
  }
  else {
    did -r hlsb 4,6,8,10,12,14,16
    did -a hlsb 4 Invalid Server IP Address
  }
}

on *:dialog:hlsb:sclick:17:{
  if ($dialog(hlsb).h > 350) dialog -sb hlsb $dialog(hlsb).x $dialog(hlsb).y 168 91
  else {
    dialog -sb hlsb $dialog(hlsb).x $dialog(hlsb).y 168 163
    dll $mdx SetMircVersion $version
    dll $mdx MarkDialog $dname
    dll $mdx SetControlMDX $dname 22 ListView report grid > $views
    did -i hlsb 22 1 headerdims 150:1 50:2 110:3
    did -i hlsb 22 1 headertext Player $+ $chr(9) $+ Score $+ $chr(9) $+ Time
    var %server = $did(hlsb,1)
    var %server = $dll(" $+ $scriptdiripresolve2.dll $+ ",getip,$gettok(%server,1,58)) $+ $iif($gettok(%server,2,58),: $+ $ifmatch)
    checkplayers %server
  }
}

on *:dialog:hlsb:sclick:18:{
  if ($dialog(hlsb_options)) dialog -v hlsb_options
  else dialog -md hlsb_options hlsb_options
}

on *:dialog:hlsb:sclick:19:{ refreshserver }

on *:dialog:hlsb:sclick:21:{
  var %server = $did(hlsb,1)
  var %server = $dll(" $+ $scriptdiripresolve2.dll $+ ",getip,$gettok(%server,1,58)) $+ $iif($gettok(%server,2,58),: $+ $ifmatch)
  if ($gettok($ipverify(%server),1,32) == Valid) hlconnect %server
}

on *:dialog:hlsb:sclick:22:{ sortheader $dname $did }

on *:dialog:hlsb:sclick:23:{ dialog -sb hlsb $dialog(hlsb).x $dialog(hlsb).y 168 91 }

dialog auto_retry {
  title "Auto-Retry"
  icon $scriptdirhl.ico
  size -1 -1 79 65
  option dbu
  text "Current Players:", 1, 2 3 42 8
  edit "", 2, 49 2 27 10, read
  text "Join game when playercount is LESS than:", 3, 2 26 75 14
  edit "", 4, 2 41 23 10
  button "Refresh", 5, 2 54 37 10
  button "Cancel", 6, 41 54 37 10
  text "Approx Ping:", 7, 10 13 34 8
  edit "", 8, 49 12 27 10, read
}

on *:dialog:auto_retry:init:0:{
  did -a auto_retry 2 $did(hlsb,14)
  did -a auto_retry 4 $gettok($did(hlsb,14),2,47)
  did -a auto_retry 8 $did(hlsb,12)
  .timerautoretry 0 5 autoretry
}

on *:dialog:auto_retry:sclick:5:{
  refreshserver
}

on *:dialog:auto_retry:sclick:6:{
  dialog -x auto_retry
  if ($timer(autoretry)) .timerautoretry off
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Aliases                           ;;
;;  (the real meat of the addon :D)   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; mdx.dll alias
alias -l mdx return $nopath($scriptdirMDX.dll)
;; views.mdx alias
alias -l views return $+($scriptdir,views.mdx)

alias -l fillretryinfo {
  if ($dialog(auto_retry)) {
    if (!$did(auto_retry,4)) {
      if ($did(hlsb,14)) did -o auto_retry 4 1 $gettok($did(hlsb,14),2,47)
    }
    if ($did(auto_retry,4) > $gettok($did(hlsb,14),2,47)) did -o auto_retry 4 1 $gettok($did(hlsb,14),2,47)
    if ($gettok($did(auto_retry,2),1,47) < $did(auto_retry,4)) hlconnect %hlsb.server
    if ($did(hlsb,4) == Server timed out) {
      did -o auto_retry 2 1 -
      did -o auto_retry 8 1 -
    }
    unset %queryhl.*
  }
}

alias -l autoretry {
  if ($dialog(auto_retry)) {
    refreshserver
    .timerfillretryinfo -o 1 1 fillretryinfo
  }
  else {
    if ($timer(autoretry)) .timerautoretry off
  }
}

alias -l refreshserver {
  if ($dialog(hlsb)) did -r hlsb 4,6,8,10,12,14,16
  var %server = $did(hlsb,1)
  var %server = $dll(" $+ $scriptdiripresolve2.dll $+ ",getip,$gettok(%server,1,58)) $+ $iif($gettok(%server,2,58),: $+ $ifmatch)
  if ($gettok($ipverify(%server),1,32) == Valid) {
    unset %queryhl.*
    queryhlserver %server
    if ($dialog(hlsb).h > 350) checkplayers %server
  }
  else {
    if ($dialog(hlsb)) did -o hlsb 4 1 Invalid Server IP Address
    if ($dialog(hlsb).h > 350) did -r hlsb 22
  }
}

;; Checks for a valid ip/port
;; Usage: $ipverify(ip[:port])[.ip|port]
alias -l ipverify {
  var %regex = /((?:\d{1,3}\.){3}\d{1,3})((?::|\s)\d{1,5})*$/
  if ($regex(ip,$1,%regex)) {
    var %x = 1
    while (%x <= $gettok($regml(ip,1),0,46)) {
      if ($gettok($regml(ip,1),%x,46) > 255) return Invalid
      inc %x
    }
    if ($prop == ip) return Valid - $regml(ip,1)
    if ($prop == port) {
      if ($regml(ip,2)) {
        if ($right($ifmatch,-1) <= 65535) return Valid - $ifmatch
        else return Invalid
      }
    }
    else return Valid - $iif($regml(ip,2),$regml(ip,1) $+ $regml(ip,2),$regml(ip,1))
  }
  else return Invalid
}

alias -l queryhlserver { 
  ; function: queries a half-life server for its information using the new protocol (as of 7/25/05)
  ; usage: /queryhlserver <ip>[:port]  - (port is automatically 27015 unless otherwise specified)
  ; example: /queryhlserver 255.255.255.255
  ;          /queryhlserver 255.255.255.255:27016
  if (*.*.*.* !iswm $1) return $null
  else {
    if (($gettok($1,1,46) !isnum) || ($gettok($1,2,46) !isnum) || ($gettok($1,3,46) !isnum) || ($gettok($gettok($1,4,46),1,58) !isnum)) return $null
    else {
      if ($chr(58) isin $1) {
        var %queryhl.ip = $replace($1,$chr(58),$chr(32))
        if (($gettok(%queryhl.ip,2,32) !isnum) || ($gettok(%queryhl.ip,2,32) > 65535)) return $null
      }
      else {
        if ($2) {
          if ($2 <= 65535) var %queryhl.ip = $1 $2
          else return $null
        }
        else var %queryhl.ip = $1 27015
      }
      set %queryhl.beginticks $ticks
      .timerqueryhltimeout -o 1 2 queryhltimeout
      if ($sock(queryhlserver)) sockclose queryhlserver
      sockudp -k queryhlserver %queryhl.ip $str($chr(255),4) $+ TSource Engine Query
      sockmark queryhlserver %queryhl.ip
    }
  }
}

alias -l queryhltimeout {
  unset %queryhl.beginticks
  if ($dialog(hlsb)) did -o hlsb 4 1 Server Timed Out
  if ($dialog(hlsb).h == 351) did -r hlsb 22
  sockclose queryhlserver
  return
}

on *:udpread:queryhlserver:{
  set %queryhl.ping $calc($ticks - %queryhl.beginticks)
  sockread &query
  ;; uncomment the line below if you want to see the raw return
  ;echo -a $bvar(&query,1,$bvar(&query,0))
  breplace &query 0 254 32 160
  var %queryhl.return = $bvar(&query,1,$bvar(&query,0)).text, %x = 1
  ;; uncomment the line below if you want to see the somewhat parsed return
  ;echo -a parsed return: %queryhl.return

  if (Counter-Strike: Source isin $gettok(%queryhl.return,4,254)) {
    set %queryhl.hostname $right($gettok(%queryhl.return,1,254),-6)
    set %queryhl.map $gettok(%queryhl.return,2,254)
    set %queryhl.gamedir $gettok(%queryhl.return,3,254)
    set %queryhl.mod $ifmatch

  }
  else {
    ;; grab hostname, map, gamedir, and mod
    set %queryhl.hostname $gettok(%queryhl.return,2,254)
    set %queryhl.map $gettok(%queryhl.return,3,254)
    set %queryhl.gamedir $gettok(%queryhl.return,4,254)
    set %queryhl.mod $gettok(%queryhl.return,5,254)
  }

  ;; for position calc (prevents messed up position if mod name is in hostname)
  var %position = $regex(position,%queryhl.hostname,/ $+ %queryhl.mode $+ */g)
  if (!%position) var %position = 1
  var %positionnumber = $pos(%queryhl.return,$gettok(%queryhl.return,5,254),%position)

  ;; parsing for players
  var %gamechars = $len($gettok(%queryhl.return,5,254))
  var %charcalc = $calc(%positionnumber + %gamechars)
  var %players = $mid(%queryhl.return,%charcalc,3)

  ;; grab current connected players and maxplayers
  set %queryhl.players $iif($asc($mid(%players,2,1)) == 254,0,$ifmatch)
  set %queryhl.maxplayers $asc($right(%players,1))
  if (%queryhl.players == 160) set %queryhl.players 32
  if (%queryhl.maxplayers == 160) set %queryhl.maxplayers 32

  ;; parse next part and grab protocol number and server type (if players is 0 position it 1 back)
  var %2ndstring = $gettok(%queryhl.return,6,254)
  set %queryhl.protocolnumber $asc($mid(%2ndstring,$iif(%queryhl.players == 0,2,3),1))
  if (!%queryhl.protocolnumber) set %queryhl.protocolnumber 0
  set %queryhl.servertype $iif($mid(%2ndstring,$iif(%queryhl.players == 0,3,4),1) == d,Dedicated,Listen)

  ;; calculate the current position in the return + 1 (where the password yes/no is)
  var %pwPos = $calc(%charcalc + $pos(%2ndstring,5,1) + 1)

  ;; grab the server operating system (if players is 0 position it 1 back), password 0|1, secure 0|1, and number of bots
  set %queryhl.serveros $iif($mid(%2ndstring,$iif(%queryhl.players == 0,4,5),1) == l,Linux,Windows)
  if (%queryhl.mod == Counter-Strike: Source) {
    var %sourcestring = $gettok(%queryhl.return,-2,254)
    set %queryhl.servertype $iif($mid(%sourcestring,-2,1) == d,Dedicated,Listen)
    set %queryhl.serveros $iif($right(%sourcestring,1) == l,Linux,Windows)
  }
  set %queryhl.password $iif($right($mid(%queryhl.return,%pwPos,6),1) == $chr(254),No,Yes)
  set %queryhl.secure $iif($mid($calc($len(%queryhl.return) - 1),1) == $chr(254),No,Yes)
  set %queryhl.bots $iif($asc($right(%queryhl.return,1)) == 254,0,$ifmatch)

  ; return results
  if ($dialog(hlsb)) did -o hlsb 4 1 %queryhl.hostname
  if ($dialog(hlsb)) did -o hlsb 6 1 %queryhl.mod ( $+ %queryhl.gamedir $+ )
  if ($dialog(hlsb)) did -o hlsb 8 1 %queryhl.servertype %queryhl.serveros (VAC $iif(%queryhl.secure == yes,Enabled,Disabled) $+ )
  if ($dialog(hlsb)) did -o hlsb 10 1 %queryhl.password
  if ($dialog(hlsb)) did -o hlsb 12 1 $iif(%queryhl.ping > 1000,-,$ifmatch)
  if ($dialog(auto_retry)) did -o auto_retry 8 1 $iif(%queryhl.ping > 1000,-,$ifmatch)
  if ($dialog(hlsb)) did -o hlsb 14 1 $+(%queryhl.players,/,%queryhl.maxplayers)
  if ($dialog(auto_retry)) did -o auto_retry 2 1 $+(%queryhl.players,/,%queryhl.maxplayers)
  if ($dialog(hlsb)) did -o hlsb 16 1 %queryhl.map
  unset %queryhl.beginticks
  sockclose queryhlserver
  .timerqueryhltimeout off
}


;; returns information about players in a specified HL server
alias -l checkplayers {
  if ($sock(players)) sockclose players
  did -r hlsb 22
  sockudp -k checkplayers $gettok($1,1,58) $iif(!$gettok($1,2,58),27015,$gettok($1,2,58)) $str($chr(255),4) $+ players
}

on *:udpread:checkplayers: {
  if ($sockerr > 0) return
  sockread &players
  var %x = 1, %client_start = 8, %clients = $bvar(&players,6)
  while (%x <= %clients) {
    ; Byte format as follows: <ID> <name> <0 byte> <frags, 2x> <0 or 255 byte, 2x> <time 4x>
    var %client = $bvar(&players,%client_start,$calc($bfind(&players,%client_start,0) - %client_start)).text
    ; add a space to the name in the beginning (so it shows all names)
    var %client = $chr(160) $+ %client
    var %frag16 = $bvar(&players,$calc($bfind(&players,%client_start,0) + 1),2)
    var %time32 = $bvar(&players,$calc($bfind(&players,%client_start,0) + 3 + 2),4)
    ; Convert frag16 and time32
    var %time = $unfloat(%time32)
    var %frags = $calc($gettok(%frag16,1,32) + ($gettok(%frag16,2,32) * 256))
    ; Check for negative frags
    if ($bvar(&players,$calc($bfind(&players,%client_start,0) + 3),1) == 255) %frags = $calc(%frags - 65536)
    ; add a space to frags if not negative (better alignment)
    if ($left(%frags,1) != -) var %frags = $chr(160) $+ %frags
    ; Return the player as follows: [player name] [score] [time since connected]
    did -a hlsb 22 %client $chr(9) %frags $chr(9) $dur2(%time)
    %client_start = $calc($bfind(&players,%client_start,0) + 3 + 2 + 5)
    inc %x
  }
  sockclose checkplayers
} 

;; Converts from float32 (4 bytes) to decimal - by noob
; usage: $unfloat(<float32>)
alias -l unfloat {
  if ($gettok($1,4,32) >= 100) return error
  var %x 4, %f , %b
  while (%x > 1) { %f = %f $+ $base($gettok($1,%x,32),10,2,8) | dec %x }
  var %m 1 $+ $mid(%f,10,23) , %e $calc($base($mid(%f,2,8),2,10) -127) , %x 24
  while (%x > 0) { dec %x | %b = $calc( %b + 2 ^ $calc(%x + %e) * $mid( %m , $calc(24 - %x) , 1 ) ) }
  return $calc(%b / 2^23)
}

;; changes a given number of seconds into a short one-letter form of duration
alias -l dur2 {
  if ($1 == $null) return $null
  var %dur2 = $duration($1-)
  if (wks isin %dur2) var %dur2 = $replace(%dur2,wks,w)
  if (wk isin %dur2) var %dur2 = $replace(%dur2,wk,w)
  if (days isin %dur2) var %dur2 = $replace(%dur2,days,d)
  if (day isin %dur2) var %dur2 = $replace(%dur2,day,d)
  if (hrs isin %dur2) var %dur2 = $replace(%dur2,hrs,h)
  if (hr isin %dur2) var %dur2 = $replace(%dur2,hr,h)
  if (mins isin %dur2) var %dur2 = $replace(%dur2,mins,m)
  if (min isin %dur2) var %dur2 = $replace(%dur2,min,m)
  if (secs isin %dur2) var %dur2 = $replace(%dur2,secs,s)
  if (sec isin %dur2) var %dur2 = $replace(%dur2,sec,s)
  return %dur2
}

alias -l hlconnect {
  refreshserver
  .timerdohlconnect -o 1 1 dohlconnect
}

alias -l dohlconnect {
  var %locked = %queryhl.password, %mod = %queryhl.gamedir
  var %steampath = $readini(" $+ $scriptdirhlsb.ini $+ ",options,steampath)
  var %protocol = %queryhl.protocolnumber
  if ((%protocol < 47) && (%queryhl.mod != Counter-Strike: Source)) var %msg = $input(That server is not running at least protocol 47 so it is not compatible with HLSB.,o,Incorrect server protocol)
  else {
    var %connectclose = $readini(" $+ $scriptdirhlsb.ini $+ ",options,connectclose)
    if (%queryhl.players == %queryhl.maxplayers) {
      set %hlsb.server $1
      if (!$dialog(auto_retry)) dialog -md auto_retry auto_retry
      else dialog -v auto_retry
    }
    else {
      if (%locked == Yes) var %password = $?*="This server is locked! Please enter the password:"
      if ((%locked == Yes) && (%password == $null)) var %msg = $input(The server is locked and you did not enter a password $+ $chr(44) not launching game.,o,No password entered)
      else {
        var %password = $chr(59) $+ password %password
        if (%mod == cstrike) {
          if (%queryhl.mod == Counter-Strike: Source) var %mod = 240
          else var %mod = 10
        }
        elseif (%mod == tfc) var %mod = 20
        elseif (%mod == dod) var %mod = 30
        elseif (%mod == dmc) var %mod = 40
        elseif (%mod == gearbox) var %mod = 50
        elseif (%mod == ricochet) var %mod = 60
        else var %mod = 70
        if ($dialog(auto_retry)) {
          if ($timer(autoretry)) .timerautoretry off
          dialog -x auto_retry
        }
        if (%steampath == $null) {
          var %msg = $input(Couldn't find the path to Steam.exe - go set it in options.,o,Couldn't find path to Steam)
          if ($dialog(hlsb_options)) dialog -v hlsb_options
          else dialog -m hlsb_options hlsb_options
        }
        else {
          if (!$exists(%steampath)) var %msg = $input(Your path to Steam.exe does not exist! Try double-checking it in the game options.,o,No Steam Path Specified)
          else {
            run " $+ %steampath $+ " -applaunch %mod +connect $1 $+ %password
            if (%connectclose = 1) dialog -x hlsb hlsb 
            else dialog -i hlsb
          }
        }
      }
    }
  }
  unset %queryhl.*
}

;; Function: sorts an MDX listview by clicking on header - <3 para
;; Usage: /sortheader <dname> <did>
alias -l sortheader {
  if (headerclick headerEvent * iswm $did($1,$2,1)) {
    var %range = $+(2-,$did($1,$2).lines)
    ;; set the switch variable (backwards/forwards switch)
    inc $+(%,sh.,$1,.,$2)
    ;; determine the column to sort
    %sort.column = $gettok($did($1,$2,1),3,32)
    ;; determine sort order based on the switch variable (boolean value)
    %sort.order = $isbit( [ [ $+(%,sh.,$1,.,$2) ] ] ,1)
    filter -rcioa %range $1 $2 $1 $2 sortfilter
    unset %sort.*
  }
}

alias -l sortfilter {
  var %token = $iif(%sort.column == 1,6-,5-)
  var %item1 = $remove($gettok($gettok($1,%sort.column,9),%token,32),$chr(160))
  var %item2 = $remove($gettok($gettok($2,%sort.column,9),%token,32),$chr(160))
  if (%sort.column == 3) var %item1 = $duration(%item1), %item2 = $duration(%item2)
  if (%item1 >= %item2) return $iif(%sort.order,1,-1)
  else return $iif(%sort.order,-1,1)
}