;
; Author: FiberOPtics - mirc.fiberoptics@gmail.com
;
; Usage: $findcid( network|server|wildcard, N|range [,channel|1-15])
;
; --> Third parameter is optional, and defaults to 1 if not specified.
;
; Purpose: Returns the $cid's of the server windows that match the specified network/server.
;
; During the examples we will assume the following:
;
; We are connected to a few servers, two of which are connected to network DALnet,
; but on different servers with different $cid's.
;
; Server 1: irc.dal.net with $cid 3
; Server 2: broadway.ny.us.dal.net with $cid 6
;
;
; - The first parameter is either the name of a network, the name of a server,
; or a wildcarded parameter. The snippet will look through all server windows,
; and see if it can match the server/network with the specified parameter.
;
; If the parameter is a wildcard, then it will try to match this wildcard to the server name.
; Consequently, when specifying just * as parameter, it will match all server names.
;
; - The second parameter is either a number or a range as used in $gettok
;
; N = 0 --> returns total amount cid's
; N > 0 --> returns the N'th cid
; range = 1- --> returns all cid's
;
; $findcid(dalnet,0) --> 2
; $findcid(*.dal.*,0) --> 2
; $findcid(dalnet,1-) --> 3 6
; $findcid(dalnet,1) --> 3
; $findcid(dalnet,2) --> 6
; $findcid(dalnet,3) --> (empty)
;
; $findcid(irc.dal.net,1) --> 3
; $findcid(broadway.*,1) --> 6
;
; Note you can also specify a negative number or a range. It supports anything $gettok supports.
;
; $findcid(dalnet,-1) --> get the last matching cid = 6
; $findcid(dalnet,-2) --> get 2nd to last matching cid = 3
;
; - The third parameter is either a channel, or a number between 1-15.
;
; 1) Channel
; ----------
;
; If a channel is specified, it will only return the $cid if you are on this channel.
; This helps you when you want to relay messages from one channel to another channel
; on another server window. This way you don't need to check yourself if you are on
; the channel before messaging.
;
; Let's assume the following (server windows in order of position in switchbar):
;
; irc.dal.net --> #mirc (cid 3)
; broadway.ny.us.dal.net --> #mirc #FOP (cid 6)
; irc.rizon.net --> #mirc (cid 4)
;
; $findcid(dalnet,1-,#mirc) --> 3 6
; $findcid(irc.dal.net,1,#FOP) --> (empty)
; $findcid(*.us.dal.net,1,#FOP) --> 6
; $findcid(*,1-,#mirc) --> 3 6 4
;
; Let's say that my current active network is DALnet, and I want to relay something
; to network Undernet in channel &scripting. I would do this:
;
; if ($findcid(undernet,1,&scripting)) {
; scid $ifmatch
; msg &scriping <my message>
; scid -r
; }
; else echo -a You are not on channel &scripting on network Undernet
;
; I specified a 1 for the second parameter, because I only want to return the first matching cid. Suppose I had
; put 1-, then it would have returned all cid's that match the criteria. We don't want this, because if the
; result would be 3 and 5 for example, it would have resulted in "scid 3 5", which would set the connection
; to server window 3, and execute the command 5 there, which results in an error.
;
;
; 2) Number between 1-15
; ----------------------
;
; If the third parameter is a number between 1-15 it defines the connection state that the server
; windows must have in order to be a succesful match.
;
; This digit should be a combination of the following numbers:
;
; 1 = connected
; 2 = not connected (= disconnected or connecting = 8 or 4)
; 4 = connecting
; 8 = disconnected
;
; These digits are the same as when using /scon or /scid with the tM flag
;
; The $cid is only stored if the specified connection status matches that of the server window.
;
; $findcid(rizon,1,1) --> return the 1st cid that is on rizon with connection status : connected
; $findcid(efnet,1,2) --> " " " efnet " " : not connected
; $findcid(dalnet,1,4) --> " " " dalnet " " : connecting
; $findcid(undernet,1,8) --> " " " undernet " " : disconnected
;
;
; Note: If you don't specify a connection state identifier, the snippet will use 1 as default, in other words
; it will look for matches on connected servers only. Logically if you specify a channel as third parameter,
; it will also look for matches only on connected servers, because you cannot be on a channel without
; being connected to the server. If you specify a number outside the range 1-15 it will also use 1 as default.
;
; You can specify multiple connection states by taking the sum of the digits "1, 2, 4, and 8"
; This makes a total of 15 different numbers you can use (there is some overlapping though)
;
; $findcid(dalnet,1,3)
; --> 3 = 1 + 2 = connected, not connected
; --> looks for server windows on network dalnet, where $status is either:
; connected or not connected.
;
; $findcid(quakenet,1-,5)
; --> 5 = 1 + 4 = connected, connecting
; --> looks for server windows on network quakenet, where $status is either:
; connected or connecting
;
; $findcid(rizon,1,12)
; --> 12 = 4 + 8 = connecting, disconnected
; --> looks for server windows on network rizon, where $status is either:
; connecting or disconnected
;
; If you want to cover all connection states, then specify 15.
;
;
; Install: This alias goes into the Remote section of the Scripts Editor.
; Either put the file findcid.mrc into your main mIRC folder and type /load -rs findcid.mrc
; or hold alt+r in mIRC, navigate to tab "Remote", and copy paste the snippet there.
;
; Required: mIRC 6.0 because multi-server capabilities were only added then.
;
;
alias findcid {
if ($isid) {
var %e = return $+($chr(3),$color(info),$!findcid: Error -)
if ($version < 6.0) %e multi-server capability was only added in version 6.0
if (!$len($1)) %e you must specify a network, server, or wildcarded string as first parameter.
if (!$regex($ticks,$2,/^-?\d+-?(?:-\d+)?$/)) %e second param should either be a number or a range.
var %n = $iif($3 isnum 1-15,$3,1), %params = $1 $iif($3 !isnum,$3)
set -u %result
scon -at $+ %n findcid % $+ params
return $gettok(%result,$2,32)
}
if ($1 iswm $server) || ($istok($server $network,$1,32)) {
if ($2) && ($me !ison $2) return
set -u %result %result $cid
}
}