mIRC Arrays

By ProIcons on Dec 24, 2010

DESCRIPTION
mIRC Arrays Allow you to save data in variables like arrays style
and modify this variables like arrays and etc.
The value 0 of an array is the number of the bytes that array have. Well I mean
that when you have an array ports the variable of it is %ports[*] and if you
have %dos[1] asd | and %dos[2] afsd | the $dos[0] is the number 2
you can enable the alias $ + array by uncommenting the following line

 ;alias $2 var $+($chr(37),z) = $2 $chr(124) return $!_array(%z,$1) 
to
 alias $2 var $+($chr(37),z) = $2 $chr(124) return $!_array(%z,$1) 
of the alias "array" and you will able to useit like $array(0) - 
$array($1) - $array(%variable) etc

USAGE & EXAMPLES

Basic usage to get a textfile or a multitype text on arrays is 
> /array start <arrayname> and then
/array add <arrayname> <value>
and
> set %arraytarget <arrayname>
set %arraytiger start
array 1
set %arraytiger add
array <value>
To Get an array data you can do it by typing //echo -a $_array(<arrayname>,<array index>)
or if you uncomment the line
 ;alias $2 var $+($chr(37),z) = $2 $chr(124) return $!_array(%z,$1) 
to be
 alias $2 var $+($chr(37),z) = $2 $chr(124) return $!_array(%z,$1) 
on alias "array" you will be able to use it like $<arrayname>(<arrayindex)
Also you are able to change a command by typing
>  /_array <arrayname> <arrayindex> modify <value> 
or by placing and this to one of your codes
 $_array(<arrayname>,<arrayindex>,modify,<value>) 
Also (again:D) you can unset an array by typing
>  /_array <arrayname> * free 
or by placing and this to one of your codes
 $_array(<arrayname>,*,free) 
You are also able to search for an array by typing 
>  /arraysearch <arrayname> <value> 
with result in echo <arrayname>[<arrayindex>]
or by placing and this to one of your codes
 $arraysearch(<arrayname>,<value>) 
with result <arrayindex>

I've Made some example codes that you can retrive data either from
dos either from text file. 
[Note: from dos you need exec.dll (http://www.mircscripts.org/comments.php?cid=3950)]

Text File to Arrays
> /textfile <filename>
Will Have as result the arrays on variables list and the echo of the arrays.
Example: asd.txt
asd1
asd2
asd3
> /textfile asd.txt
Echo Result:
> asd1

asd2
asd3
Variable Result:

    %text[0] 3
%text[1] asd1
%text[2] asd2
%text[3] asd3
Dos Command to Arrays
> /dos <command>
Will Have as result the dos command result saves to arrays on variables list and the echo of the arrays.
Example
>  /dos netstat -an |find /i "listening" 
Echo Result:
> 
stdout TCP 0.0.0.0:59 0.0.0.0:0 LISTENING

stdout TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:400 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:554 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:990 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:5938 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:10243 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:10665 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:37676 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49152 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49153 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49154 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49158 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49159 0.0.0.0:0 LISTENING
stdout TCP 0.0.0.0:49160 0.0.0.0:0 LISTENING
stdout TCP 127.0.0.1:5679 0.0.0.0:0 LISTENING
stdout TCP 127.0.0.1:5939 0.0.0.0:0 LISTENING
stdout TCP 127.0.0.1:7438 0.0.0.0:0 LISTENING
stdout TCP 127.0.0.1:10000 0.0.0.0:0 LISTENING
stdout TCP 127.0.0.1:55175 0.0.0.0:0 LISTENING
stdout TCP 192.168.1.65:139 0.0.0.0:0 LISTENING
stdout TCP [::]:135 [::]:0 LISTENING
stdout TCP [::]:445 [::]:0 LISTENING
stdout TCP [::]:554 [::]:0 LISTENING
stdout TCP [::]:990 [::]:0 LISTENING
stdout TCP [::]:2869 [::]:0 LISTENING
stdout TCP [::]:3389 [::]:0 LISTENING
stdout TCP [::]:3587 [::]:0 LISTENING
stdout TCP [::]:5357 [::]:0 LISTENING
stdout TCP [::]:10243 [::]:0 LISTENING
stdout TCP [::]:49152 [::]:0 LISTENING
stdout TCP [::]:49153 [::]:0 LISTENING
stdout TCP [::]:49154 [::]:0 LISTENING
stdout TCP [::]:49158 [::]:0 LISTENING
stdout TCP [::]:49159 [::]:0 LISTENING
stdout TCP [::]:49160 [::]:0 LISTENING
stdout TCP [::1]:5679 [::]:0 LISTENING

Variable Result
%ports[0] 41
%ports[1] stdout TCP 0.0.0.0:59 0.0.0.0:0 LISTENING
%ports[2] stdout TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
%ports[3] stdout TCP 0.0.0.0:400 0.0.0.0:0 LISTENING
%ports[4] stdout TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
%ports[5] stdout TCP 0.0.0.0:554 0.0.0.0:0 LISTENING
%ports[6] stdout TCP 0.0.0.0:990 0.0.0.0:0 LISTENING
%ports[7] stdout TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
%ports[8] stdout TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING
%ports[9] stdout TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
%ports[10] stdout TCP 0.0.0.0:5938 0.0.0.0:0 LISTENING
%ports[11] stdout TCP 0.0.0.0:10243 0.0.0.0:0 LISTENING
%ports[12] stdout TCP 0.0.0.0:10665 0.0.0.0:0 LISTENING
%ports[13] stdout TCP 0.0.0.0:37676 0.0.0.0:0 LISTENING
%ports[14] stdout TCP 0.0.0.0:49152 0.0.0.0:0 LISTENING
%ports[15] stdout TCP 0.0.0.0:49153 0.0.0.0:0 LISTENING
%ports[16] stdout TCP 0.0.0.0:49154 0.0.0.0:0 LISTENING
%ports[17] stdout TCP 0.0.0.0:49158 0.0.0.0:0 LISTENING
%ports[18] stdout TCP 0.0.0.0:49159 0.0.0.0:0 LISTENING
%ports[19] stdout TCP 0.0.0.0:49160 0.0.0.0:0 LISTENING
%ports[20] stdout TCP 127.0.0.1:5679 0.0.0.0:0 LISTENING
%ports[21] stdout TCP 127.0.0.1:5939 0.0.0.0:0 LISTENING
%ports[22] stdout TCP 127.0.0.1:7438 0.0.0.0:0 LISTENING
%ports[23] stdout TCP 127.0.0.1:10000 0.0.0.0:0 LISTENING
%ports[24] stdout TCP 127.0.0.1:55175 0.0.0.0:0 LISTENING
%ports[25] stdout TCP 192.168.1.65:139 0.0.0.0:0 LISTENING
%ports[26] stdout TCP [::]:135 [::]:0 LISTENING
%ports[27] stdout TCP [::]:445 [::]:0 LISTENING
%ports[28] stdout TCP [::]:554 [::]:0 LISTENING
%ports[29] stdout TCP [::]:990 [::]:0 LISTENING
%ports[30] stdout TCP [::]:2869 [::]:0 LISTENING
%ports[31] stdout TCP [::]:3389 [::]:0 LISTENING
%ports[32] stdout TCP [::]:3587 [::]:0 LISTENING
%ports[33] stdout TCP [::]:5357 [::]:0 LISTENING
%ports[34] stdout TCP [::]:10243 [::]:0 LISTENING
%ports[35] stdout TCP [::]:49152 [::]:0 LISTENING
%ports[36] stdout TCP [::]:49153 [::]:0 LISTENING
%ports[37] stdout TCP [::]:49154 [::]:0 LISTENING
%ports[38] stdout TCP [::]:49158 [::]:0 LISTENING
%ports[39] stdout TCP [::]:49159 [::]:0 LISTENING
%ports[40] stdout TCP [::]:49160 [::]:0 LISTENING
%ports[41] stdout TCP [::1]:5679 [::]:0 LISTENING
* IMPORTANT: DO NOT EVER MODIFY THE "0" INDEX VALUE
             OF AN ARRAY. THIS MAY CAUSE PROBLEMS IN SCRIPT
             FUNCTIONALITY
;;Sample Code -> Retrive Data From DOS
alias dos {
  set %arraytarget dos
  set %Arraytiger start
  ; You have not this dll but this is just an example :D
  dll $shortfn($mircdirexec.dll) execA array $1-
  var %i = 1
  while (%i <= $_array(%arraytarget,0) ) {
    echo -a $_array(%arraytarget,%i)
    inc %i
  }
}
;;Sample Code END

;;Sample Code -> Retrive Data From Text File
alias textfile {
  set %arraytarget text
  set %Arraytiger start
  var %z = 1
  if ($exists($1-) {
    while (%z <= $lines($1-) ) {
      array $read($1-,%z)
      inc %z
    }
    var %i = 1
    while (%i <= $_array(text,0) ) {
      echo -a $_array(text,%i)
      inc %i
    }
  }
}
;;Sample Code END

;Do Not Modify Here unless you know what are you doing :D
alias -l _array {
  if (!$3) return % [ $+ [ $1 ] ] [ $+ [ $chr(91) ] ] [ $+ [ $2 ] ] [ $+ [ $chr(93) ] ]
  elseif ($3 == free) unset % [ $+ [ $1 ] ] [ $+ [ $chr(91) ] ] [ $+ [ * ] ] [ $+ [ $chr(93) ] ]
  elseif ($3 == modify) set % [ $+ [ $1 ] ] [ $+ [ $chr(91) ] ] [ $+ [ $2 ] ] [ $+ [ $chr(93) ] ] $4
}
alias array {
  if ($1 != start) && ($1 != add) {
    tokenize 32 %arraytiger %arraytarget $1-
  }
  if ($1 == start) {
    set %nocheck 1
    $_array($2,*,free)
    unset %arraynum
    ;alias $2 var $+($chr(37),z) = $2 $chr(124) return $!_array(%z,$1)
  }
  if (!%nocheck) {
    if (!%arraynum) { set %arraynum 1 }
    inc % [ $+ [ $2 ] ] [ $+ [ $chr(91) ] ] [ $+ [ 0 ] ] [ $+ [ $chr(93) ] ]
    set % [ $+ [ $2 ] ] [ $+ [ $chr(91) ] ] [ $+ [ %arraynum ] ] [ $+ [ $chr(93) ] ] $3-
    inc %arraynum
  }
  else { unset %nocheck }
}
alias arraysearch {
  var %i = 1
  while (%i <= $_array($1,0) ) {
    if ($_array($1,%i) == $2-) { 
      if ($isid) {
        return %i
      }
      else { echo -a $+($1,[,%i,]) } 
    }
    inc %i
  }
}

Comments

Sign in to comment.
sunslayer   -  Dec 26, 2010

/set %array[0][0] could be used to create an array but you wouldn't be able to do anything with it without first having something to parse it with

while our value would ordinarily pass through a hash function to yield an integerkeys do not have to be integers as in associative arrays where the key can also be a string, however, in mIRC there is no difference between (int)1 and "1" because as you said, there is only one data type so any extra processing of the key value would have to be handled by mIRC and not by the coder

and even though it wouldn't offer much scripting wise, it would still benefit by acting as a starter for more powerful languages like C/C++ which understanding arrays is quite important

 Respond  
jaytea   -  Dec 26, 2010

sunslayer, there is no distinction to be drawn between one dimensional and multi-dimensional arrays; both of these would be implemented in mIRC by way of naming elements uniquely using commands such as /set %array[0][0] or /hadd -m array [0][0] value. by the way, i'm sure you'll agree that defining and referencing variables named %array[X] or %array[X][Y][Z] does not require this snippet, and this snippet just provides extra higher level functions for such array management :P

if execution time is an issue then you're certainly right: mIRC's hash tables are faster for any reasonably sized data set. but, of course, you wouldn't want to use a scripted interface (these pseudo-arrays) for simple data management if that were the case. so, while this snippet may not be geared towards those who wish to create quick and optimal code, it can provide various luxuries to scripters who wish to use more intuitive array syntax.

as for array support in mIRC, it sounds like a good idea in principle but really it wouldn't be something that is likely to add any significant benefit - even to those who purport to need it! recall that mIRC script is typeless, thus the creation of int or char arrays at the script level is not feasible. an array in mSL would necessarily be an array of (wide character) strings.

ignoring multiple dimensions for the moment, suppose /amake , /aadd [value] and $aget(, ) were introduced to manipulate and return information on these arrays. notice that this resembles the syntax for mIRC's hash tables. while our value would ordinarily pass through a hash function to yield an integer through which the low-level array can be accessed randomly, here it needs to pass through a function resembling atoi() for wide character strings to yield that same integer - i would imagine the difference between these operations to be negligible, especially at the scripter's level. and yes, while a hash table is populated by linked lists that need to be traversed, this again is an operation that none but the most pedantic scripter is likely to complain about.

so basically, a native interface for arrays in mIRC script would offer so little with regards to performance gain that we shouldn't expect to find it in the client any time soon.

 Respond  
ProIcons   -  Dec 25, 2010

Well i didn't use Hash Tables because when i was 12 years old , when i was made it, i didn't new how to scripting with hash tables. Anyway indeed it doesn't support multi-dimensional arrays. However this is very simple approach to C Arrays, but in no case is not equal or better level. Anyway i just still use this and i would want to post it here for your review, a thing i don't see atm.

Have a nice Day :)

 Respond  
sunslayer   -  Dec 25, 2010

@jaytea for multi-dimensional arrays i could see how using variables would be "better" but for basic one dimensional arrays i don't see why you wouldn't use mIRC's built in hash functions which would be faster then variables and wouldn't require this snippet, which in all of his examples this would be the case

regardless actual array support would be something i'd like to see in mirc

edit: this snippet doesn't support multi-dimensional arrays, atleast not that i see from reading the code

 Respond  
jaytea   -  Dec 25, 2010

sunslayer, similar in what way? there are layers of abstraction and overhead between low level arrays and both of these implementations. a hash table in mIRC is essentially an array but, of course, each element points to a linked list of key and data associations. using a collection of variables as in this snippet restricts mIRC to the use of a single linked list (think: a hash table with 1 slot) wherein performance could take a hit as the size of the data set increases. syntax-wise however, %var[0], %var[1] etc. is just about the closest you're going to get to the naming convention of low level arrays - even if the items are not contiguous in memory and no more related (as far as the scripting engine is concerned) than %abc and %def.

they are still a far cry from arrays in C, which is unsurprising and understandable given the nature of mIRC script. it is futile to try and replicate these low level constructs as you don't get the performance gains that you otherwise would; instead, try to use the features of the language in an efficient way on a case by case basis :P

as for the construct in mIRC most similar to low level arrays: anything involving a collection of bytes would probably be as close as you're going to get. a &binvar is basically a char array.

 Respond  
sunslayer   -  Dec 24, 2010

why not use hash tables instead of vars? they are the most similar to arrays

 Respond  
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.