The script is 100% written by me, today. It features an easy to use dialog interface which allows the storing and manipulation of data and settings on multiple networks, and the automation of connection to said networks and execution of given settings. To put it more simply, it is a script that makes it easy to connect to multiple networks automatically and join your favorite channels/identify to nicknames/whatever else it is you may want to do. I wrote this because mIRC's support for multiple networks is shaky, because while allowing multiple connections, automation of connection is out of reach for those not versed in mIRC script. I wrote this to give a solution to the needs of myself and hopefully someone else. This script has been tested by me and I have worked out hopefully all the errors. However, I am human, so there is always the chance that I missed one. If that is the case, please point these out to me, and I'll see if I can iron it out. Thanks for your time, and I hope you can learn something or find some use from this script (I have attempted to include helpful comments in the code).
Edit 10/30/09: Rearranged the main dialog to look more natural and aesthetically pleasing.
;Multi-Network Management Interface by Benjamin Berry (Serpentsounds) 2009
;mIRC offers support for being connected to multiple networks, but does little to assist you in automating this process, unless you are versed in mIRC script
;This script was made to fix my own problems, and hopefully those of somebody else
;Open designed autoconnect network windows when mIRC starts
on *:START:{
var %nets = $readini(nets.ini,nets,names)
if (%nets) {
var %x = 1
while (%x <= $numtok(%nets,32)) {
if ($readini(nets.ini,auto,$gettok(%nets,%x,32)) == yes) server $iif(%x != 1,-m) $readini(nets.ini,servers,$gettok(%nets,%x,32))
inc %x
}
}
}
;Returns stored info about the current connection by checking for network name and server name
alias sinfo {
if ($network) && ($readini(nets.ini,$$1,$network)) return $readini(nets.ini,$$1,$network)
var %serv = *. $+ $gettok($server,$calc($numtok($server,46) - 1) $+ -,46),%x = 1
while (%x <= $ini(nets.ini,servers,0)) {
if (%serv iswm $readini(nets.ini,servers,$ini(nets.ini,servers,%x))) return $readini(nets.ini,$$1,$ini(nets.ini,servers,%x))
inc %x
}
}
;Execute nickname changes, commands, and join channels upon connection. Looks for disconnected network windows to the right and reconnects them if they are in your list
;of networks (if all become disconnected due to an internet connection failure or the like, connections can be easily recovered regardless of mIRC's autoreconnect)
on *:CONNECT:{
var %nick = $sinfo(nicks)
if (%nick) nick %nick
var %cmds = $sinfo(cmds)
if (%cmds) {
var %x = 1
while (%x <= $numtok(%cmds,32)) {
$gettok(%cmds,%x,124)
inc %x
}
}
var %chs = $sinfo(channels)
if (%chs) {
var %x = 1
while (%x <= $numtok(%chs,32)) {
join $replace($gettok(%chs,%x,32),.KEY=,$chr(32))
inc %x
}
}
var %x = 1,%p = $false
while (%x <= $scon(0)) {
if ($scon(%x) == $cid) var %p = $true
inc %x
if (%p == $true) && ($scon(%x).status == disconnected) {
scon %x
if ($istok($readini(nets.ini,nets,names),$scon(%x).network,32) == $true) server $readini(nets.ini,servers,$network)
else {
var %y = 1,%serv = *. $+ $gettok($server,$calc($numtok($server,46) - 1) $+ -,46),%x = 1
while (%y <= $ini(nets.ini,servers,0)) {
if (%serv iswm $readini(nets.ini,servers,$ini(nets.ini,servers,%y))) server $readini(nets.ini,servers,$ini(nets.ini,servers,%y))
inc %y
}
}
}
}
}
;Dialog tables
dialog netsm {
Title "Multi-Server Management"
Size -1 -1 164 76
option dbu
button "Close", 1, 124 57 36 12, cancel
box "Networks:", 2, 2 2 76 72
list 3, 5 10 70 70, vsbar
button "Add", 4, 83 12 36 12, default
button "Remove", 5, 83 27 36 12
button "Edit", 6, 83 42 36 12
button "Move Up", 7, 124 12 36 12, default
button "Move Down", 8, 124 27 36 12
button "Connect", 9, 124 42 36 12
button "Help", 10, 83 57 36 12
box "Controls:", 11, 81 2 81 72
}
dialog netsadd {
Title "Add a Network"
Size -1 -1 105 235
option dbu
text "Name:", 1, 5 5 20 10
edit "", 2, 35 3 60 10, autohs limit 50, default
text "Server:", 3, 5 20 20 10
edit "", 4, 35 18 60 10, autohs limit 50
text "Channels:", 5, 5 35 25 10
edit "", 6, 35 33 60 10, autohs limit 50
list 7, 35 50 60 50, vsbar hsbar
button "Add", 8, 4 50 27 12
button "Remove", 9, 4 65 27 12
text "Nick:", 10, 5 105 20 10
edit "", 11, 35 103 60 10, autohs limit 30
text "Commands:", 12, 5 120 27 10
edit "", 13, 35 118 60 10, autohs limit 75
list 14, 35 135 60 50, vsbar hsbar
button "Add", 15, 4 135 27 12
button "Remove", 16, 4 150 27 12
button "OK", 17, 5 210 45 20, ok
button "Cancel", 18, 55 210 45 20, cancel
edit "", 19, 0 0 0 0
text "Autoconnect:", 20, 5 190 35 10
check "", 21, 88 189 10 10
}
dialog netshelp {
Title "MSM Help"
Size -1 -1 150 130
option dbu
text "If a channel you wish to auto join requires a key, the format you should enter is #channel.KEY=keyhere. For example, for #test with a key of secret you should enter #test.KEY=secret in the channel edit.", 1, 5 5 140 30
text "The script will automatically connect disconnected server windows to the right of any window you connect to if they are in your list (auto or not).", 2, 5 40 140 20
text "Commands entered in the command list box will be executed upon connection to the respective network.", 5, 5 70 140 20
text "Original Author: Benjamin Berry, 2009", 3, 5 100 100 10
button "Close", 4, 95 109 50 16, default cancel
}
;Reset the main dialog interface by clearing and reloading network names
alias netsres {
did -r netsm 3
var %x = 1,%names = $readini(nets.ini,nets,names)
while (%x <= $numtok(%names,32)) {
did -a netsm 3 $gettok(%names,%x,32)
inc %x
}
did -b netsm 5-9
}
;Easy access to the dialog via netsmgr command or popups menu
alias netsmgr dialog -mdb netsm netsm
menu channel,status {
Multi-Server Management:{
if (!$dialog(netsm)) netsmgr
else dialog -v netsm
}
}
;Call reset command for intialization
on *:DIALOG:netsm:init:0:netsres
;Enable appropriate buttons when a list item is selected
on *:DIALOG:netsm:sclick:3:{
if ($istok($readini(nets.ini,nets,names),$did(netsm,3).seltext,32) == $true) {
did -e netsm 5-6,9
if ($did(netsm,3).sel > 1) did -e netsm 7
else did -b netsm 7
if ($did(netsm,3).sel < $did(netsm,3).lines) did -e netsm 8
else did -b netsm 8
}
else did -b netsm 5-6
}
;Open add network dialog to add a new network
on *:DIALOG:netsm:sclick:4:{
if ($hget(nets,edit)) hdel nets edit
if (!$dialog(netsadd)) dialog -mab netsadd netsadd
}
;Open add network dialog to edit an existing network
on *:DIALOG:netsm:sclick:6:{
if (!$dialog(netsadd)) {
hadd -m nets edit $true
hadd -m nets name $did(netsm,3).seltext
dialog -mab netsadd netsadd
}
}
;Clear saved network data for removal
on *:DIALOG:netsm:sclick:5:{
var %oname = $did(netsm,3).seltext
netsudi nets names $remtok($readini(nets.ini,nets,names),%oname,32)
netsudi servers %oname
netsudi channels %oname
netsudi nicks %oname
netsudi cmds %oname
netsudi auto %oname
netsres
}
;Move items up and down in the list (changing connect order)
on *:DIALOG:netsm:sclick:7,8:{
var %name = $did(netsm,3).seltext,%line = $calc($did(netsm,3).sel $replacex($did,7,-,8,+) 1)
writeini nets.ini nets names $instok($remtok($readini(nets.ini,nets,names),%name,32),%name,%line,32)
netsres
}
;Connect to highlighted network
on *:DIALOG:netsm:sclick:9:server -m $readini(nets.ini,servers,$did(netsm,3).seltext)
;Open help dialog for a couple additional bits of info
on *:DIALOG:netsm:sclick:10:if (!$dialog(netshelp)) dialog -mab netshelp netshelp
;Add a network initialization. Will fill in current values if editing an existing network
on *:DIALOG:netsadd:init:0:{
if ($hget(nets,edit) == $true) {
var %name = $hget(nets,name)
did -a netsadd 2 %name
did -a netsadd 4 $readini(nets.ini,servers,%name)
var %x = 1
while (%x <= $numtok($readini(nets.ini,channels,%name),32)) {
did -a netsadd 7 $gettok($readini(nets.ini,channels,%name),%x,32)
inc %x
}
did -a netsadd 11 $readini(nets.ini,nicks,%name)
var %x = 1
while (%x <= $numtok($readini(nets.ini,cmds,%name),124)) {
did -a netsadd 14 $gettok($readini(nets.ini,cmds,%name),%x,124)
inc %x
}
did -a netsadd 19 %name
did $+(-,$replacex($readini(nets.ini,auto,%name),yes,c,no,u)) netsadd 21
}
else did -b netsadd 17
did -b netsadd 8,9,15,16
did -z netsadd 7 30
did -z netsadd 14 75
}
;Prevent adding a network without a name and server (essential)
on *:DIALOG:netsadd:edit:2,4:{
if ($did(netsadd,$did,1).len > 0) did -e netsadd 17
else did -b netsadd 17
}
;Enable remove buttons when list item is selected
on *:DIALOG:netsadd:sclick:7,14:{
if ($len($did(netsadd,$did).seltext) > 0) did -e netsadd $replacex($did,7,9,14,16)
else did -b netsadd $replacex($did,7,9,14,16)
}
;Enable add channel button if input is valid
on *:DIALOG:netsadd:edit:6:{
var %reg = ^#[^\s]{0,31}$
if ($regex($did(netsadd,6).text,%reg) == 1) did -e netsadd 8
else did -b netsadd 8
did -t netsadd 8
}
;Enable add command button if input is present
on *:DIALOG:netsadd:edit:13:{
if ($did(netsadd,13,1).len > 0) did -e netsadd 15
else did -b netsadd 15
did -t netsadd 15
}
;Processes clicks of add and removal buttons for channels and commands
on *:DIALOG:netsadd:sclick:8-9,15-16:{
did $+(-,$replacex($did,8,a,15,a,9,d,16,d)) netsadd $replacex($did,8,7,9,7,15,14,16,14) $replacex($did,8,$did(netsadd,6).text,15,$did(netsadd,13).text,9,$did(netsadd,7).sel,16,$did(netsadd,14).sel)
$replacex($did,8,did -r netsadd 6,15,did -r netsadd 13,9,noop,16,noop)
did -b netsadd $did
}
;Rewrites given ini values, or removes section if no value is given
alias netsudi {
if ($3) writeini nets.ini $1-
elseif ($readini(nets.ini,$1,$2)) remini nets.ini $1-2
else return
}
;Save network. If editing and network name is changed, will remove existing network data, otherwise it is overwritten. Adding a new network simply fills in the new data
on *:DIALOG:netsadd:sclick:17:{
var %name = $did(netsadd,2).text
var %oname = $did(netsadd,19).text
if ($len(%oname) > 0) && (%name != %oname) {
netsudi nets names $remtok($readini(nets.ini,nets,names),%oname,32)
netsudi servers %oname
netsudi channels %oname
netsudi nicks %oname
netsudi cmds %oname
netsudi auto %oname
}
netsudi nets names $addtok($readini(nets.ini,nets,names),%name,32)
netsudi servers %name $did(netsadd,4).text
var %chs,%x = 1
while (%x <= $did(netsadd,7).lines) {
var %chs = $addtok(%chs,$did(netsadd,7,%x).text,32)
inc %x
}
netsudi channels %name %chs
netsudi nicks %name $did(netsadd,11).text
var %cmds,%x = 1
while (%x <= $did(netsadd,14).lines) {
var %cmds = $addtok(%cmds,$did(netsadd,14,%x).text,124)
inc %x
}
netsudi cmds %name %cmds
netsudi auto %name $replacex($did(netsadd,21).state,1,yes,0,no)
netsres
}
While loops such as:
var %x = 1
while (%x <= $numtok($readini(nets.ini,channels,%name),32)) {
did -a netsadd 7 $gettok($readini(nets.ini,channels,%name),%x,32)
inc %x
}
Can be written as:
var %x = 1
while $gettok($readini(nets.ini,channels,%name),%x,32) {
did -a netsadd 7 $v1
inc %x
}
Basically any time you find yourself doing a
while (%x <= $ident(0)) looking at the total you
can often do something like the above and use
the $ifmatch or the even shorter $v1 identifier