zNetconf v1.0b (Network manager)

By knoeki on Oct 03, 2009

Image

So.. I've wanted to write something like this for a while already, and I finally got the time to create it :_)

Usage should be simple enough, but I'll explain how it works anyways :_)

at the left of the dialog is the networks list. below it, there are 2 buttons to add/remove networks.

clicking on a network in the network list will allow you to edit settings for it on the right side of the dialog, as well as add servers for it. Don't forget to click save when you are done editing a network's settings, as soon as you click on another network in the network list, all info not saved will be GONE

Nickname and Alt nickname... should be obvious..

Identify Method is to.. well.. identify with various services out there. Just write in the box whatever you should do to identify on the network in question, but replace your password with :pass:, since you set your password in the next field.

password: see above ;_)

Auto identify on connect: This makes sure the above specified Identify Method is sent to the server as you connect.

Auto ghost nick if taken: This will 'take' your nick if, when you connect, it is not used by you. This only works when nickserv is available, I have no idea if any other services support such a function, in any event, it'll try to ghost your taken nickname using the password specified above.

Perform on conn.: Whatever you fill in here, it'll get executed when you connect.

Channels: String of channels you want to join when you connect, comma-seperated.

Connect on startup: Will let the script automatically connect you to the network using a random server.

Save: Saves settings for the currently selected network

Connect: Connects to the currently selected network. Be sure to SAVE first!

Close: closes the dialog :_)

I hope the explaination was clear ;_)

;;version 1.0b
on *:LOAD: {
    if ($file($scriptdirzn-networks.ini) == $null) {
        writeini $qt($scriptdirzn-networks.ini) P2P-NET s1 irc.p2p-network.net
        writeini $qt($scriptdirzn-networks.ini) P2P-NET channels #zomgwtfbbq
    }
}   

on *:START: {
    set %zn.ini $scriptdirzn-networks.ini
    var %count 1
    var %total $ini(%zn.ini, 0)
    while (%count <= %total) {
        var %current $ini(%zn.ini, %count)
        if ($readini(%zn.ini, %current, autoconnect) == 1) {
            server $iif(%count > 1, -m) $zn_randserv(%current) -j $readini(%zn.ini, %current, channels) -i $readini(%zn.ini, %current, nick) $readini(%zn.ini, %current, altnick)
        }
        inc %count
    }
    unset %zn.ini
}

on *:CONNECT: {
    if ($ini(%zn.ini, $network) != $null) {
        if ($me != $readini(%zn.ini, $network, nick)) {
            if ($readini(%zn.ini, $network, ident.ghost) == 1) {
                msg nickserv ghost $readini(%zn.ini, $network, nick) $readini(%zn.ini, $network, ident.pass)
                nick $readini(%zn.ini, $network, nick)
            }
        }
        if ($readini(%zn.ini, $network, ident.auto) == 1) {
            $replace($readini(%zn.ini, $network, ident.method), :pass:, $readini(%zn.ini, $network, ident.pass))
        }
        if ($readini(%zn.ini, $network, perform) != $null) {
            $readini(%zn.ini, $network, perform)
        }
    }
}

dialog z.netconf {
      title "zNetworkConfig"
      size -1 -1 222 134
      option dbu
      box "Networks", 1, 0 0 69 133
      list 2, 2 8 65 110, sort size
      button "Add...", 3, 2 119 32 12
      button "Remove", 4, 35 119 32 12
      box "", 5, 70 0 151 119
      list 6, 72 8 111 29, sort size
      button "Add...", 7, 184 8 34 12
      button "Remove", 8, 184 22 34 12
      edit "", 9, 117 37 51 10, autohs
      edit "", 10, 168 37 50 10, autohs
      text "Nick / Alt-nick", 11, 73 38 43 8
      edit "", 12, 117 47 101 10, autohs
      edit "", 13, 117 57 101 10, pass autohs
      text "Identify method", 14, 73 48 43 8
      text "Password", 15, 73 58 43 8
      check "Auto identify on connect", 16, 118 67 70 10
      check "Auto ghost nick if taken", 17, 118 77 69 10
      edit "", 18, 117 87 101 10, autohs
      text "Perform on conn.", 19, 72 89 44 8
      edit "", 20, 117 97 101 10, autohs
      text "Channels", 21, 72 98 43 8
      check "Connect on startup", 22, 118 107 69 10
      button "Save", 23, 70 120 37 12
      button "Connect", 24, 146 120 37 12
      button "Close", 25, 184 120 37 12, ok cancel
}

dialog zn.error {
      title "Dude, you're getting an error!"
      size -1 -1 130 44
      option dbu
      button "Ok", 2, 48 31 37 12
      text "", 1, 2 5 0 23, center
}

alias z.netconf {
    dialog -m z.netconf z.netconf
}

alias -l zn_error {
    dialog -m zn.error zn.error
    did -o $dname 1 $1-
}

alias -l zn_randserv {
    var %network $1
    echo network: %network
    var %total $wini(%zn.ini, %network, s*, 0)
    echo total: %total
    var %count 1
    while (%count <= %total) {
        echo count %count
        var %result $addtok(%result, $readini(%zn.ini, %network, $wini(%zn.ini, %network, s*, %count)), 32)
        inc %count
    }
    return $gettok(%result, $rand(0, $numtok(%result, 32)), 32)
}

alias -l wini {
    var %file $1
    var %topic $2
    if ($3 != $null) {
        if ($3 !isnum) {
            var %item $3
            if ($4 != $null) {
                var %return $4
            }
        }
        else {
            var %return $3
        }
    }
    var %count 1
    var %total $iif(%item == $null, $ini(%file, 0), $ini(%file, %topic, 0))
    while (%count <= %total) {
        var %current $iif(%item == $null, $ini(%file, %count), $ini(%file, %topic, %count))
        if ($iif(%item == $null, %topic, %item) iswm %current) {
            var %result $addtok(%result, %current, 32)
        }
        inc %count
    }
    if (%return != $null) {
        return $gettok(%result, %return, 32)
    }
    else {
        return $numtok(%result, 32)
    }
}

on *:DIALOG:z.netconf:init:0: {
    set %zn.ini $scriptdirzn-networks.ini
    var %count 1
    var %total $ini(%zn.ini, 0)
    while (%count <= %total) {
        did -a $dname 2 $ini(%zn.ini, %count)
        inc %count
    }
}

on *:DIALOG:z.netconf:close: {
    unset %zn.*
}

on *:DIALOG:z.netconf:sclick:2: {
    if (%zn.active != $did($dname, 2).seltext) {
        did -r $dname 5,6,9,10,12,13,18,20
        did -u $dname 16,17,22
        set %zn.active $did($dname, 2).seltext
        did -o $dname 5 1 Settings for %zn.active
        var %count 1
        var %total $wini(%zn.ini, %zn.active, s*)
        while (%count <= %total) {
            did -a $dname 6 $readini(%zn.ini, %zn.active, $wini(%zn.ini, %zn.active, s*, %count))
            inc %count
        }
        if ($readini(%zn.ini, %zn.active, nick) != $null) {
            did -o $dname 9 1 $readini(%zn.ini, %zn.active, nick)
        }
        if ($readini(%zn.ini, %zn.active, altnick) != $null) {
            did -o $dname 10 1 $readini(%zn.ini, %zn.active, altnick)
        }
        if ($readini(%zn.ini, %zn.active, ident.method) != $null) {
            did -o $dname 12 1 $readini(%zn.ini, %zn.active, ident.method)
        }
        if ($readini(%zn.ini, %zn.active, ident.pass) != $null) {
            did -o $dname 13 1 $readini(%zn.ini, %zn.active, ident.pass)
        }
        if ($readini(%zn.ini, %zn.active, ident.auto) != $null) {
            did $iif($readini(%zn.ini, %zn.active, ident.auto) == 1, -c, -u) $dname 16
        }
        if ($readini(%zn.ini, %zn.active, ident.ghost) != $null) {
            did $iif($readini(%zn.ini, %zn.active, ident.ghost) == 1, -c, -u) $dname 17
        }
        if ($readini(%zn.ini, %zn.active, perform) != $null) {
            did -o $dname 18 1 $readini(%zn.ini, %zn.active, perform)
        }
        if ($readini(%zn.ini, %zn.active, channels) != $null) {
            did -o $dname 20 1 $readini(%zn.ini, %zn.active, channels)
        }
        if ($readini(%zn.ini, %zn.active, autoconnect) != $null) {
            did $iif($readini(%zn.ini, %zn.active, autoconnect) == 1, -c, -u) $dname 22
        }
    }
}

on *:DIALOG:z.netconf:sclick:3: {
    var %input $?="Add new network"
    if (%input != $null) {
        writeini $qt(%zn.ini) %input s1 newserver
        did -a $dname 2 %input
    }
}

on *:DIALOG:z.netconf:sclick:4: {
    var %total $did($dname, 2, 0).sel
    if (%total == 1) {
        if ($?!="Are you sure you want to remove %zn.active and all it's settings?" == $true) {
            remini $qt(%zn.ini) $did($dname, 2).sel
            did -d $dname 2 $did($dname, 2).sel
            unset %zn.active
        }
    }
}

on *:DIALOG:z.netconf:sclick:7: {
    if (%zn.active != $null) {
        var %input $?="Add new server"
        if (%input != $null) {
            writeini $qt(%zn.ini) %zn.active $+(s,$calc($wini(%zn.ini, %zn.active, s*) + 1)) %input
            did -a $dname 6 %input
        }
    }
    else {
        zn_error No network selected.
    }
}

on *:DIALOG:z.netconf:sclick:8: {
    if (%zn.active != $null) {
        var %active $did($dname, 6, 1).sel
        if ($?!="Are you sure you want to remove this server?" == $true) {
            var %count 1
            var %total $wini(%zn.ini, %zn.active, s*)
            while (%count <= %total) {
                if ($readini(%zn.ini, %zn.active, $+(s,%count)) == $did($dname, 6, %active)) {
                    remini $qt(%zn.ini) %zn.active $+(s,%count)
                    did -d $dname 6 %active
                }
                inc %count
            }
        }
    }
    else {
        zn_error No Network selected.
    }
}

on *:DIALOG:z.netconf:sclick:23: {
    if ($did($dname, 9) != $null) {
        writeini $qt(%zn.ini) %zn.active nick $did($dname, 9)
    }
    if ($did($dname, 10) != $null) {
        writeini $qt(%zn.ini) %zn.active altnick $did($dname, 10)
    }
    if ($did($dname, 12) != $null) {
        writeini $qt(%zn.ini) %zn.active ident.method $did($dname, 12)
    }
    if ($did($dname, 13) != $null) {
        writeini $qt(%zn.ini) %zn.active ident.pass $did($dname, 13)
    }
    writeini $qt(%zn.ini) %zn.active ident.auto $did($dname, 16).state
    writeini $qt(%zn.ini) %zn.active ident.ghost $did($dname, 17).state
    if ($did($dname, 18) != $null) {
        writeini $qt(%zn.ini) %zn.active perform $did($dname, 18)
    }
    if ($did($dname, 20) != $null) {
        writeini $qt(%zn.ini) %zn.active channels $did($dname, 20)
    }
    writeini $qt(%zn.ini) %zn.active autoconnect $did($dname, 22).state
}

on *:DIALOG:z.netconf:sclick:24: {
    set %current $did($dname, 2, $did($dname, 2).sel)
    server -m $zn_randserv(%current) -j $readini(%zn.ini, %current, channels) -i $readini(%zn.ini, %current, nick) $readini(%zn.ini, %current, altnick)
}

on *:DIALOG:z.netconf:sclick:25: {
    unset %zn.*
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.