Server Manager

Information on mIRC scripts or other IRC related scripts for use by users.
1 post Page 1 of 1

Server Manager

Quote

Post by Daedalus »

To make joining multiple servers easier in case you ping out on one of them(under normal, 'perform' based connections, massive problems would be caused should one ping out). This script is to fix that.

Documentation coming

Code: Select all

;Server Manager
;$version:1.0.0
;Author: Daedalus

dialog -l server_man_conf_tbl {
  title "Server Manager Config"
  size -1 -1 200 110
  option dbu
  button "Manage", 1, 5 4 35 10, nowrap
  button $chr(9660), 2, 79 4 10 10
  button $chr(9650), 3, 89 4 10 10
  text "Servers", 4, 100 5 22 14, nowrap
  check "Connect on startup", 5, 140 4 55 10
  list 7, 5 15 190 80, vsbar
  button "Add server", 8, 5 90 40 10
  edit "", 9, 47 90 35 10
  edit "", 10, 85 90 59 10
  button "Remove selected", 11, 145 90 50 10
  text "GroupName", 12, 47 102 35 10, nowrap
  text "ServerAddrAndParams", 13, 85 102 59 10, nowrap
}

dialog -l server_man_sure_tbl {
  title "Are you sure you want to remove that?"
  size -1 -1 224 73
  option pixels notheme
  button "Yes", 1, 20 40 65 25, ok result
  button "No", 2, 130 40 65 25, cancel
  text "  Are you sure you want to", 3, 40 4 130 17 nowrap
  text "  remove the selected server?", 4, 40 20 145 17 nowrap
}

on *:DIALOG:server_man_conf:init:0: {
  var %file = $scriptdir $+ settings.ini
  did -b $dname 1
  did -b $dname 8
  did -r $dname 7
  if ($readini(%file,general,connect) == 1) {
    did -c $dname 5
  }
  sm.refresh_servers
}

on *:DIALOG:server_man_conf:*:*: {
  var %file = $scriptdir $+ settings.ini
  if (($devent == edit) && (($did == 9) || ($did == 10))) {
    if (($did($dname,9,1).text != $null) && ($did($dname,10,1).text != $null)) {
      did -e $dname 8
    }
    else {
      did -b $dname 8
    }
  }
  elseif ($devent == sclick) {
    if ($did == 1) {
      sm.toggle_server_state $did($dname,7).sel
      var %selected_server_state = $gettok($readini(%file,servers,n $+ $did($dname,7).sel),1,58)
      if (%selected_server_state == 1) {
        did -o $dname 1 1 Unmanage
      }
      elseif (%selected_server_state == 0) {
        did -o $dname 1 1 Manage
      }
    }
    elseif ($did == 2) {
      sm.move_server down $did($dname,7).sel
    }
    else if ($did == 3) {
      sm.move_server up $did($dname,7).sel
    }
    elseif ($did == 5) {
      if ($did($dname,$did).state == 1) {
        writeini $+($scriptdir,settings.ini) general connect 1
      }
      elseif ($did($dname,$did).state == 0) {
        writeini $+($scriptdir,settings.ini) general connect 0
      }
    }
    elseif ($did == 7) {
      if ($did($dname,7).sel != 0) {
        var %selected_server_state = $gettok($readini(%file,servers,n $+ $did($dname,7).sel),1,58)
        if (%selected_server_state == 1) {
          did -o $dname 1 1 Unmanage
        }
        elseif (%selected_server_state == 0) {
          did -o $dname 1 1 Manage
        }
        if ($did($dname,1).enabled == $false) {
          did -e $dname 1
        }
      }
      else {
        did -b $dname 1
      }
    }
    elseif ($did == 8) {
      sm.add_server $did($dname,9).text
    }
    elseif ($did == 11) {
      var %can_delete = $dialog(server_man_sure,server_man_sure_tbl,-3)
      if (%can_delete == Yes) {
        sm.delete_server
      }
    }
  }
}

on *:START: {
  var %file = $scriptdir $+ settings.ini
  if ($readini(%file,general,connect) == 1) {
    sm.server_connect
  }
}

alias serverman {
  if ($dialog(server_man_conf) != $null) {
    dialog -x server_man_conf
  }
  dialog -ma server_man_conf server_man_conf_tbl
}

alias -l sm.enumerate_servers {
  var %file = $scriptdir $+ settings.ini
  var %item_num = $ini(%file,servers,0) | var %item_i = 1
  while (%item_i <= %item_num) {
    var %item = $ini(%file,servers,%item_i)
    var %item_val = $readini(%file,servers,%item)
    writeini %file servers_temp n $+ %item_i %item_val
    inc %item_i 1
  }
  remini %file servers
  var %item_num = $ini(%file,servers_temp,0) | var %item_i = 1
  while (%item_i <= %item_num) {
    var %item = $ini(%file,servers_temp,%item_i)
    var %item_val = $readini(%file,servers_temp,%item)
    writeini %file servers n $+ %item_i %item_val
    inc %item_i 1
  }
  remini %file servers_temp
}

alias -l sm.render_server {
  var %state_icon = $iif($gettok($1,1,58) == 1,$chr(9678),$chr(9675))
  return %state_icon $gettok($1,2,58) $gettok($1,3,58)
}

alias -l sm.refresh_servers {
  var %file = $scriptdir $+ settings.ini
  var %item_num = $ini(%file,servers,0) | var %item_i = 1
  did -r server_man_conf 7
  while (%item_i <= %item_num) {
    var %item = n $+ %item_i
    var %item_val = $readini(%file,servers,%item)
    did -a server_man_conf 7 $sm.render_server(%item_val)
    inc %item_i 1
  }
}

alias -l sm.move_server {
  var %file = $scriptdir $+ settings.ini
  var %direction = $1
  var %num = $2
  if ((%direction == up) && (%num == 1)) {
    return
  }
  elseif ((%direction == down) && (%num == $ini(%file,servers,0))) {
    return
  }
  elseif ((%direction == down) || (%direction == up)) {
    var %current_item = n $+ %num
    var %current = $readini(%file,servers,%current_item)
    var %target_item = n $+ $iif(%direction == down,$calc(%num + 1),$calc(%num - 1))
    var %target = $readini(%file,servers,%target_item)
    remini %file servers %target_item
    remini %file servers %current_item
    writeini %file servers %target_item %current
    writeini %file servers %current_item %target
  }
  sm.enumerate_servers
  sm.refresh_servers
  if ((%direction == down) || (%direction == up)) {
    did -c server_man_conf 7 $iif(%direction == down,$calc(%num + 1),$calc(%num - 1))
  }
}

alias -l sm.add_server {
  var %file = $scriptdir $+ settings.ini
  sm.enumerate_servers
  writeini %file servers n $+ $calc($ini(%file,servers,0) + 1) $+(0,:,$did(server_man_conf,9).text,:,$did(server_man_conf,10).text)
  sm.refresh_servers
}

alias -l sm.toggle_server_state {
  var %file = $scriptdir $+ settings.ini
  var %server_i = $1
  var %server_state = $gettok($readini(%file,servers,n $+ %server_i),1,58)
  var %server_state_new = $iif(%server_state == 1,0,1)
  var %server = $readini(%file,servers,n $+ %server_i)
  writeini %file servers n $+ %server_i $puttok(%server,%server_state_new,1,58)
  sm.refresh_servers
  did -c server_man_conf 7 %server_i
}

alias -l sm.delete_server {
  var %file = $scriptdir $+ settings.ini
  remini %file servers n $+ $did(server_man_conf,7).sel 
  sm.enumerate_servers
  sm.refresh_servers
  did -b server_man_conf 1
}

alias -l sm.server_connect {
  var %file = $scriptdir $+ settings.ini
  var %server_i = 1 | var %server_num = $ini(%file,servers,0)
  while (%server_i <= %server_num) {
    var %server_item = n $+ %server_i
    var %server = $readini(%file,servers,%server_item)
    var %option = $null
    if (%server_i > 1) {
      var %option = -m
    }
    if ($gettok(%server,1,58) == 1) {
      if (%option == $null) {
        var %option = -
      }
      var %option = %option $+ p
    }
    .timersmconnect $+ %server_i 1 $calc(%server_i * 2) /server %option $gettok(%server,3,58)
    inc %server_i 1
  }
}

on *:CONNECT: {
  var %file = $scriptdir $+ settings.ini
  var %server_i = 1 | var %server_num = $ini(%file,servers,0)
  while (%server_i <= %server_num) {
    var %server_item = $ini(%file,servers,%server_i)
    var %server = $readini(%file,servers,%server_item)
    if ($gettok(%server,2,58) == $network) {
      break
    }
    inc %server_i 1
  }
  var %perform_i = 0 | var %perform_group_i = 1 | var %perform_num = $ini($mircdir $+ perform.ini,perform,0)
  if ($gettok(%server,1,58) == 1) {
    autojoin -s
    while (%perform_i < %perform_num) {
      var %perform_item = $ini($mircdir $+ perform.ini,perform,%perform_i)
      var %perform = $readini($mircdir $+ perform.ini,perform,%perform_item)
      if ($gettok(%perform,1,44) == $network) {
        .timersmperform $+ %server_i $+ %perform_i -d 1 $calc(%perform_group_i * 4) $gettok(%perform,2,44)
        inc %perform_group_i 1
      }
      inc %perform_i 1
    }
  }
}

Daedalus
Dragon Coder
Posts: 165
Joined: October 9th, 2008, 5:15 am

1 post Page 1 of 1