Scripting Accessories for mIRC, UNIT 1 — File Browser

ScriptingAccessoriesformIRCUNIT1v1.0 / ScriptingAccessoriesformIRCUNIT1v1.0 / scptaccs.mrc

scptaccs.mrc — 22.32 KB — Download this file

; ================================ Scripting Accessories ====================================
;
; Scripting Accessories UNIT 1 (1.0) by Plaza, Copyrighted © 1998 to Regev Schweiger.
; For more information, suggestions, comments and flames can be sent to Plaza@A-VIP.com.
; No parts of this script can be copied without the author's explicit authorazation.
; 
; "In order to understand recursion, you must first understand recursion. " 
;                                                                                               -- 1998.
;
; ======================================================================================
;
; -- Script uses file ScptAccs.ini by default. To change that value, change the filename in the following code, and
;    next time you will operate mIRC it will be updated:

on 1:START:{
  %scp.FileName = ScptAccs.ini
  
  echo 2 -s *** Loaded Scripting Accessories UNIT 1 10(1.0).
}

; NOTES:
;  All new unchanged array and record values are prefixed with ***.
;  For loop allow one command only because of mIRC's capability.
;  
;
; -- Ini file structure:
;
;    Array Handler sections are perfixed with 'arr'.
;    Every 'arr' section divides into 2 parts: the cells ('N'-'M') and  'Exist' - to ensure existance.
;    Records are prefixed with 'rec'.
;    Every 'rec' section is divided into 2 parts: <Field-1>...<Field-N> names and 'Exist' - to ensure existance.
;    Section 'vars' is for variable watch. Includes 'current' for current used variable, and serial numbers.
;
; -- Variable preferences:
;        All variables start with %scp. The continues are as mentioned:
;
;        %scp.* - Script internal variables.
;        %scp.arhand.* - Array Handler internal variables.
;        %scp.rec* - Record variable.
;        %scp.rchand.* - Record Handler internal variables.
;        %scp.pwht.* - Picture Windows Helpful Tools internal variables.
;        %scp.varw.* - Variable Watch internal variables.
;        %scp.sock.* - Sockets Control internal variables.
;
;
; -- Timers:
;      SCPUnsetVar - Timer to unset variable.
;
; -- Groups:
;      #Scp.SocketControl - Group for the socket control.

; ================= Various Procedures ============

; -- Saves the @Windows coordinates.

on 1:CLOSE:@:{
  if ($target = @Watch) {
    
    ; -- Save settings.
    
    %scp.varw.WatchWindowX = $window($target).x
    %scp.varw.WatchWindowY = $window($target).y
    %scp.varw.WatchWindowW = $window($target).w
    %scp.varw.WatchWindowH = $window($target).h
  }
  elseif ($target = @Sockets) {
    .disable #scp.SocketControl
    
    %scp.sock.SocketWindowX = $window($target).x
    %scp.sock.SocketWindowY = $window($target).y
    %scp.sock.SocketWindowW = $window($target).w
    %scp.sock.SocketWindowH = $window($target).h
  }
}

; INTERNAL (Greetings to MarkP)
; -- $Tab(<Text>,<Field width>)

alias Tab return $$1 $+ $str($calc($$2 - $len($$1)), )

; ================== Design Tools ================================

; -- $Space( [Number] )
;   Used to produce one or "Number" spaces.

alias Space {
  if ($1 = $null) { return $chr(160) }
  else { return $str($chr(160),$1) }
}

; -- $CSpace(<Colour Number>,[Number] )
;   Used to procude one or "Number" coloured spaces.

alias CSpace {
  if ($2 = $null) { return 0, $+ $1 $+ $chr(160) $+  }
  else { return 0, $+ $1 $+ $str($chr(160),$2) $+  }
}

; -- $incirc(x,y,x,y,r)
;   Finds whether a dot (x,y) is in the circle whose center is in the second (x,y), radius r.

alias incirc {
  if ($calc(($1 - $3)^2 + ($2 - $4)^2) > $calc($5 ^ 2)) { return $true }
else { return $false }
}


; -- /WinMes <@Window Name>
;   Returns @Window measurements.

alias WinMes {
  if ($1 = $null) { echo 2 -s *** /WinMes: Insufficient Parameters. | return }
  echo 2 -s *** Window $1 measurements (x,y,w,h): $window($1).x $window($1).y  $window($1).w $window($1).h 
}

; ================== Picture @Windows Helpful Tools ================

; Cut and paste the following sections in your @Window's menu. 

; -- Get mouse coordinates.

sclick { 
  echo 2 -s *** Clicked $active at ( $+ $mouse.x $+ , $+ $mouse.y $+ ). 
  unset %scp.pwht.XClick %scp.pwht.YClick
  %scp.pwht.XClick = $mouse.x
  %scp.pwht.YClick = $mouse.y    
  ; -- PUT YOUR SCRIPT HERE   
}

; -- Get starting and ending coordinates, plus rectange width and height.

drop {
  echo 2 -s *** Rectangle formed at $active $+ , starting at ( $+ %scp.pwht.XClick $+ , $+ %scp.pwht.YClick $+ ) ending ( $+ $mouse.x $+ , $+ $mouse.y $+ ) width $calc($mouse.x - %scp.pwht.XClick) height $calc($mouse.y - %scp.pwht.YClick) $+ .
  ; -- PUT YOUR SCRIPT HERE 
}

; ================== CheckPoint ============

; -- /Check [Text]
;    Echos script name and message to status window.

alias Check echo 2 -s *** CheckPoint: $nopath($script) $+ , $1-

; ================== FOR ===================

; -- /For <Minimum Limit> <Maximum Limit> <One Command>
;
; NOTE: This loop was originally coded by Hawkee. Of course, I coded it again on my own, but
;             He deserves the credit for the idea.

alias For {
  
  if ($1 = $null) || ($2 = $null) || ($3 = $null) { echo 2 -s *** /For: Insufficient Parameters. | return }
  
  %scp.For = $1
  :Next
  if (%scp.For > $2) { goto Done }
  *2
  inc %scp.For
  goto Next
  :Done
  
}

; ================== Status Window Auto '/'ing ============

on 1:INPUT:*:{
  if (status isin $active) && ($left($1-,1) != /) {
    // $+ $1-
    halt
  }
}

; =================== Array Handler =================

; -- /Array <Array Name> <Minimum Cell Value> <Maximum Cell Value>

alias Array {
  
  ; -- Check for syntax errors:
  
  if ($1 = $null) || ($2 = $null) || ($3 = $null) { echo 2 -s *** /Array: Insufficient Parameters. | return }
  
  ; -- Save Settings.
  
  unset %scp.arhand.UsingParms
  if ($left($1,1) = -) {
    
    ; -- Mark parameters usage.
    %scp.arhand.UsingParms = True
    
    %scp.arhand.ArrayName = $2
    %scp.arhand.CellLimits1 = $3
    %scp.arhand.CellLimits2 = $4
  }
  else {
    %scp.arhand.ArrayName = $1
    %scp.arhand.CellLimits1 = $2
    %scp.arhand.CellLimits2 = $3
  }
  
  ; -- Check for logical errors.
  
  if (%scp.arhand.CellLimits1 >= %scp.arhand.CellLimits2) { echo 2 -s *** /Array: Cell range invalid. | return }
  
  ; -- Prepare file for enterances.
  
  remini %scp.FileName arr $+ %scp.arhand.ArrayName
  writeini %scp.FileName arr $+ %scp.arhand.ArrayName Exist True
  
  %scp.Counter = %scp.arhand.CellLimits1
  :NextValue
  if (%scp.Counter > %scp.arhand.CellLimits2) { goto DoneValue }
  writeini %scp.FileName arr $+ %scp.arhand.ArrayName %scp.Counter ***
  inc %scp.Counter 
  goto NextValue
  :DoneValue
  
  unset %scp.Counter
  
}

; -- /ArrayInsert <Array Name> <Cell Number> <Value> 

alias ArrayInsert {
  
  ; -- Check for syntax errors:
  
  if ($1 = $null) || ($2 = $null) || ($3 = $null) { echo 2 -s *** /ArrayInsert: Insufficient Parameters. | return }
  
  ; -- Check if such array is operative.
  if ($readini %scp.FileName arr $+ $1 Exist != True) { echo 2 -s *** /ArrayInsert: No such array ' $+ $1 $+ '. }
  else {
    
    ; -- Check if there is such cell in the given array.
    if ($readini %scp.FileName arr $+ $1 $2 = $null) { echo 2 -s ***  /ArrayInsert: No such cell ( $+ $2 $+ ) in array ' $+ $1 $+ '. }
    else {
      
      ; -- Store the value.
      writeini %scp.FileName arr $+ $1 $2 $3
    }
  }
}

; -- $ArrayRead(<Array Name>,<Cell>)

alias ArrayRead {
  
  if ($1 = $null) || ($2 = $null) { echo 2 -s *** $ $+ ArrayRead: Insufficient parameters. | return }
  
  ; -- Check if such array is operative.
  if ($readini %scp.FileName arr $+ $1 Exist != True) { echo 2 -s *** $ $+ ArrayRead: No such array ' $+ $1 $+ '. | return }
  
  ; -- Check if there is such cell in the given array.
  if ($readini %scp.FileName arr $+ $1 $2 = $null) { echo 2 -s ***  $ $+ ArrayRead: No such cell ( $+ $2 $+ ) in array ' $+ $1 $+ '. | return }
  return $readini %scp.FileName arr $+ $1 $2 
  
}

; -- /ArrayDelete <Array Name>

alias ArrayDelete {
  
  ; -- Check for syntax errors.
  if ($1 = $null) { echo 2 -s *** /ArrayDelete: Insufficient Parameters. | return }
  
  ; -- Check if array exists.
  if ($readini %scp.FileName arr $+ $1 Exist = $null) { echo 2 -s *** /ArrayDelete: Array ' $+ $1 $+ ' does not exist. }
  else { remini %scp.FileName arr $+ $1 }
}

; ================== Record Handler ===============

; -- /Record [-v] <Record Name> <Field-1> <Field-2>...<Field-N>
;       Use the -v switch to base the record on variable.

alias Record {
  
  ; -- Check for syntax errors: 
  
  if ($1 = $null) || ($2 = $null) || (($left($1,1) = -) && ($3 = $null)) { echo 2 -s *** /Record: Insufficient Parameters. | return }
  
  ; -- Check for number of Fields.
  
  unset %scp.rchand.UsingParms  
  if ($left($1,1) = -) { %scp.rchand.UsingParms = True }
  
  if (%scp.rchand.UsingParms = True) { 
    %scp.rchand.RecordName = $2
    %scp.rchand.NumOfFields = $3- 
  }
  else { 
    %scp.rchand.RecordName = $1
    %scp.rchand.NumOfFields = $2- 
  }
  %scp.rchand.NumOfFields = $gettok(%scp.rchand.NumOfFields,0,32)
  
  ; -- Check for method of record.
  
  if (%scp.rchand.UsingParms = True) {
    if (v isin $1) {
      
      ; -- Variable Based Record.
      
      set % $+ scp.rec $+ $2 $+ .Exist True
      
      ; -- Fix places <1>/<2>...<N> in variable.
      %scp.Counter = 1
      :NextIndex
      if (%scp.Counter > %scp.rchand.NumOfFields) { goto DoneIndex }
      set % $+ scp.rec $+ %scp.rchand.RecordName $+ . $+ $ [ $+ [ $calc(%scp.Counter + 2) ] ] ***
      inc %scp.Counter
      goto NextIndex
      :DoneIndex
      
      unset %scp.Counter
      
    }
  }  
  else {
    
    ; --Ini File Based Record.
    
    ; -- Fix places in ini file.
    remini %scp.FileName rec $+ %scp.rchand.RecordName 
    writeini %scp.FileName rec $+ %scp.rchand.RecordName Exist True
    %scp.Counter = 1
    :NextField
    if (%scp.Counter > %scp.rchand.NumOfFields) { goto DoneField }
    writeini %scp.FileName rec $+ %scp.rchand.RecordName $gettok($2-,%scp.Counter,32) ***
    inc %scp.Counter
    goto NextField
    :DoneField 
    
    unset %scp.Counter
    
  }
}

; -- /RecordInsert [-v] <Record Name> <Record Field> <Value>
;       Switch -v if record is variable based.

alias RecordInsert {
  
  ; -- Check for syntax errors:
  
  if ($1 = $null) || ($2 = $null) || ($3 = $null) || (($left($1,1) = -) && ($4 = $null)) { *** /RecordInsert: Insufficient Parameters. }
  
  unset %scp.rchand.iUsingParms 
  if ($left($1,1) = -) { %scp.rchand.iUsingParms = True }
  
  ; -- Check for switches.
  if (%scp.rchand.iUsingParms != True) {
    
    ; -- Ini based record.
    
    ; -- Check if record exists.
    if ($readini %scp.FileName rec $+ $1 Exist != True) { echo 2 -s *** /RecordInsert: Record ' $+ $1 $+ ' does not exist. }
    else {
      
      ; -- Check if field exists.
      if ($readini %scp.FileName rec $+ $1 $2 = $null) { echo 2 -s *** /RecordInsert: Field ' $+ $2 $+ ' does not exist in record ' $+ $1 $+ '. }
      
      ; -- Store the value.
      else { writeini %scp.FileName rec $+ $1 $2 $3 }
    }    
  }
  elseif (v isin $1) {
    
    ; -- Variable based record
    
    ; -- Check if record exists.
    if (% $+ scr.rec $+ $2 = $null) { echo 2 -s *** /RecordInsert: Record ' $+ $2 $+ ' does not exist. }
    else {
      
      ; -- Check if field exists.
      if (% $+ scr.rec $+ $2 $+ . $+ $3 = $null) { echo 2 -s *** /RecordInsert: Field ' $+ $2 $+ ' does not exist in record ' $+ $1 $+ '. }
      else { set % $+ scp.rec $+ $2 $+ . $+ $3 $4 }
      
    }   
  }
}

; -- $RecordRead(<Record Name>,<Field Name>[,v])
;      Use extra parameter v to state it is a variable based record.

alias RecordRead {
  
  ; -- Check for syntax errors:
  
  if ($1 = $null) || ($2 = $null) { echo 2 -s *** $ $+ RecordRead: Insufficient Parameters. | return }
  
  ; -- Check for record base:
  
  if ($3 != v) {
    
    ; -- Ini based record.
    
    ; -- Check if record exists.
    if ($readini %scp.FileName rec $+ $1 exist = $null) { echo 2 -s *** $ $+ RecordRead: Record ' $+ $1 $+ ' does not exist. }
    else {
      
      ; -- Check if field exists.
      if ($readini %scp.FileName rec $+ $1 $2 = $null) { echo 2 -s *** $ $+ RecordRead: Field ' $+ $2 $+ ' does not exist in record ' $+ $1 $+ '. }
      else { return $reaini %scp.FileName rec $+ $1 $2 }
    }
  }
  else {
    
    ; -- Variable based record.
    
    ; -- Check if record exists.
    if (% $+ scp.rec $+ $1 $+ .Exist = $null) { echo 2 -s *** $ $+ RecordRead: Record ' $+ $1 $+ ' does not exist. }
    else {
      
      ; -- Check if field exists.
      if (% $+ scp.rec $+ $1 $+ . $+ $2 = $null) { echo 2 -s *** $ $+ RecordRead: Field ' $+ $2 $+ ' does not exist in record ' $+ $1 $+ '. }
      else { set -u2 %scp.Temp % $+ scp.rec $+ $1 $+ . $+ $2 | return [ [ %scp.Temp ] ] }
    }
  }
}

; -- /RecordDelete [-v] <Record Name> [Field Name]
;     Use -v switch if variable based record.

alias RecordDelete {
  
  ; -- Check for syntax errors.
  if ($1 = $null) || (($left($1,1) = -) && ($2 = $null)) { echo 2 -s *** /RecordDelete: Insufficient Parameters. | return }
  
  unset %scp.rchand.dUsingParms
  if ($left($1,1) = -) { %scp.rchand.dUsingParms = True }
  
  if (%scp.rchand.dUsingParms = True) && (v isin $1) { 
    
    ; -- Variable based record.
    
    ; -- Check if Record exists.
    if (% $+ scp.rec $+ $2 $+ .Exist = $null) { echo 2 -s *** /RecordDelete: Record ' $+ $2 $+ ' does not exist. } 
    else {
      ; -- Check if field is a parameter.
      if ($3 = $null) { unset % $+ scp.rec $+ $2 $+ .* }
      else {
        ; -- Check if field exists.
        if (% $+ scp.rec $+ $2 $+ . $+ $3 = $null) { echo 2 -s *** /RecordDelete: Field ' $+ $3 $+ ' does not exist in record ' $+ $2 $+ '. }
        else { unset % $+ scp.rec $+ $2 $+ . $+ $3 }
      }
    }
  }
  else {
    
    ; -- Ini based record.  
    
    ; -- Check if Record exists.
    if ($readini %scp.FileName rec $+ $1 Exist = $null) { echo 2 -s *** /RecordDelete: Record ' $+ $1 $+ ' does not exist. }
    else {
      ; -- Check for field parameter.
      if ($2 = $null) { remini %scp.FileName rec $+ $1 }
      else {
        ; -- Check if field exists.
        if ($readini %scp.FileName rec $+ $1 $2 = $null) { echo 2 -s *** /RecordDelete: Field ' $+ $2 $+ ' does not exist in record ' $+ $1 $+ '. }
        else { remini %scp.FileName rec $+ $1 $2 }
      }
    }
  }
}

; ================== Variable Watch =============

; -- /Watch
;   Watch variables.

alias Watch {
  
  ; -- Check for used coordinates.
  
  if (%scp.varw.WatchWindowX = $null) || (%scp.varw.WatchWindowY = $null) || (%scp.varw.WatchWindowW = $null) || (%scp.varw.WatchWindowH = $null) {
    %scp.varw.WatchWindowX = 425
    %scp.varw.WatchWindowY = 3
    %scp.varw.WatchWindowW = 210 
    %scp.varw.WatchWindowH = 271
  }
  
  ; -- Form window according to previous coordinates.
  window -l @Watch %scp.varw.WatchWindowX %scp.varw.WatchWindowY %scp.varw.WatchWindowW %scp.varw.WatchWindowH Fixedsys 12 @Watch
  
  aline @Watch $Space(5) VARIABLE WATCH 
  aline @Watch $str(_,30)
  aline @Watch Double Click to unset.
  aline @Watch $str(¯,30)
  sline @Watch 1  
  
  ;  .timerSCPRefreshWatch 0 $1 RefreshWatch
}

;    INTERNAL
; -- /RefreshWatch

alias RefreshWatch {
  if ($window(@Watch) = $null) { return }
  clear @Watch
  Watch
  %scp.Counter = 1
  set %scp.varw.Num $readini %scp.FileName vars current
  :NextZ
  if (%scp.Counter > %scp.varw.Num) { goto Done } 
  set %scp.Temp2 $readini %scp.FileName vars %scp.Counter
  AddWatch %scp.Temp2
  inc %scp.Counter
  goto NextZ
  :Done
  
}


;    INTERNAL
; -- /AddWatch <Variable Name without %>

alias AddWatch {
  set %scp.Temp % $+ $1
  aline @Watch $tab($1,10) $tab( [ [ %scp.Temp ] ] ,7)
}  

; -- /WSet [-uN] <Variable Name with no %> <Value>
;   Set variable with watch, -uN for automatic unset after N seconds.

alias WSet {
  
  ; -- Check for syntax errors.
  
  if ($1 = $null) || ($2 = $null) || (($left($1,1) = -) && ($3 = $null)) { echo 2 -s *** /WSet: Insufficient parameters. | return } 
  
  GetCurrent
  
  ; -- Check if switch is used.
  if ($left($1,1) = -) { 
    .timerSCPUnsetVar 1 $remove($1,-u) WUnset $2 
    %scp.varw.VarName = $2 
    %scp.varw.Value = $3-
  }
  else {
    %scp.varw.VarName = $1 
    %scp.varw.Value = $2-
  }
  
  ; -- Check if it is already used.
  %scp.Counter = 1
  :NextVar
  if (%scp.Counter > $readini %scp.FileName vars current) { goto DoneVar }
  if ($readini %scp.FileName vars %scp.Counter = %scp.varw.VarName) { goto WriteValue }
  
  inc %scp.Counter
  goto NextVar
  :DoneVar  
  
  set -u2 %scp.Temp $readini %scp.FileName vars current
  writeini %scp.FileName vars current $calc(%scp.Temp + 1)  
  set %scp.Temp $readini %scp.FileName vars current
  :WriteValue
  writeini %scp.FileName vars %scp.Temp %scp.varw.VarName 
  set -u2 %scp.Temp % $+ %scp.varw.VarName
  set [ [ %scp.Temp ] ] %scp.varw.Value
  
  RefreshWatch
  
}  


;INTERNAL.
; -- /GetCurrent

alias GetCurrent {
  if ($readini %scp.FileName vars 1 = $null) { writeini %scp.FileName vars current 0 }
}

; -- /WUnset <Variable Name with no %>

alias WUnset {
  
  if ($1 = $null) { echo 2 -s *** /WUnset: Insufficient Parameters. | return }
  
  ; -- Unset the variabled, inifiled.
  
  %scp.Counter = 1
  :NextVar
  if (%scp.Counter > $readini %scp.FileName vars current) { echo 2 -s *** /WUnset: No matched variabled ' $+ $1 $+ '. | return }
  if ($readini %scp.FileName vars %scp.Counter = $1) { goto DeleteVar }
  inc %scp.Counter
  goto NextVar
  :DeleteVar
  remini %scp.FileName vars %scp.Counter 
  
  :NextDel
  if (%scp.Counter >= $readini %scp.FileName vars current) { goto DoneDel }
  set %scp.Temp $readini %scp.FileName vars $calc(%scp.Counter + 1)
  writeini %scp.FileName vars %scp.Counter %scp.Temp
  inc %scp.Counter
  goto NextDel
  :DoneDel    
  set -u2 %scp.Temp $readini %scp.FileName vars current
  writeini %scp.FileName vars current $calc(%scp.Temp - 1)  
  
  ; -- Unset the variable, variabled.
  
  //unset % $+ $1
  
  RefreshWatch
  
}

; -- /WInc <Variable Name with no %> [Value]

alias WInc {
  
  ; -- Check for syntax errors.  
  
  if ($1 = $null) { echo 2 -s *** /WInc: Insufficient Parameters. | return }
  
  if ($2 != $null) { %scp.varw.Dif = $2 } 
  else { %scp.varw.Dif = 1 }
  
  WSet $1 $calc($Wread($1) + %scp.varw.Dif)
}

; -- /WDec <Variable Name with no %> [Value]

alias WDec {
  
  ; -- Check for syntax errors.
  
  if ($1 = $null) { echo 2 -s *** /WDec: Insufficient Parameters. | return }
  
  if ($2 != $null) { %scp.varw.Dif = $2 }
  else { %scp.varw.Dif = 1 }
  
  WSet $1 $calc($WRead($1) - %scp.varw.Dif)
}

; -- $Wread(<Variable Name with no %>)
;   Can be also used instead of % $+ the variable name. Returns the variable's value.

alias Wread {
  
  ; -- Check for syntax errors.
  
  if ($1 = $null) { echo 2 -s *** $ $+ Wread: Insufficient paramters. | return }
  
  %scp.Temp = % $+ $1
  return [ [ %scp.Temp ] ]
}

; -- Menu of @Watch, used to delete variables.
;    Double click to delete.

menu @Watch {
  DClick {
    if ($1 > 4) { 
      set -u2 %scp.Temp [ $readini %scp.FileName vars $calc($1 - 4) ]
      WUnset %scp.Temp 
    }
  }
}

; ================== Socket Control ========================

; -- /SockControl 
;    Opens the Socket Control window.

alias /SockControl {
  if (%scp.sock.SocketWindowX = $null) || (%scp.sock.SocketWindowY = $null) || (%scp.sock.SocketWindowW = $null) || (%scp.sock.SocketWindowH = $null) {
    %scp.sock.SocketWindowX = 8
    %scp.sock.SocketWindowY = 351
    %scp.sock.SocketWindowW = 474
    %scp.sock.SocketWindowH = 126
  }
  .enable #scp.SocketControl
  window -l @Sockets %scp.sock.SocketWindowX %scp.sock.SocketWindowY %scp.sock.SocketWindowW %scp.sock.SocketWindowH FixedSys 12 @Sockets
  RefreshSockets
  
}

menu @Sockets {
  DClick { SockInfo $calc($1 - 2) }
}


#scp.SocketControl off

; -- /SockInfo <Socket Number>
;    Shows basic information about a socket.

alias SockInfo {
  
  if ($1 = $null) { echo 2 -s *** /SockInfo: Insufficient Parameters. | return }
  
  %scp.Temp = $1
  %scp.sock.WindowName = @Socket- $+ $Sock(*,%scp.Temp)
  window %scp.sock.WindowName 157 159 290 162 Fixedsys 12
  aline %scp.sock.WindowName Socket Name: $Sock(*,%scp.Temp) $Sock(*,%scp.Temp).mark
  aline %scp.sock.WindowName Status: $Sock(*,%scp.Temp).status
  aline %scp.sock.WindowName Port: $Sock(*,%scp.Temp).port
  aline %scp.sock.WindowName Connected to IP: $Sock(*,%scp.Temp).ip
  aline %scp.sock.WindowName Data passed: Rcvd $Sock(*,%scp.Temp).rcvd Sent $Sock(*,%scp.Temp).sent
}

; -- /RefreshSockets
;    Refreshes Sockets Control.

alias RefreshSockets {
  clear @Sockets
  
  if ($window(@Sockets) = $null) { return }  
  aline @Sockets  $space(20) $+ Sockets Control $+ $space(30)
  aline @Sockets  $tab(Name,15) $tab(Port,8) $tab(To:,14) $tab(Status,10) $+ $space(50)
  
  %scp.Counter = 1
  :NextSock 
  if (%scp.Counter > $Sock(*,0)) { goto DoneSock }
  aline @Sockets $space $+ $tab( [ $Sock(*,%scp.Counter).name ] ,15) $tab( [ $Sock(*,%scp.Counter).port ] ,8) $tab( [ $Sock(*,%scp.Counter).ip ] ,14) $tab( [ $Sock(*,%scp.Counter).status ] ,10)
  inc %scp.Counter
  goto NextSock
  :DoneSock
  
}

; -- /SockClose <SockName> [SockName2,SockName3,..,SockNameN]
;    Closes all sockets until the Nth.

alias /SockClose {
  
  ; -- Close the first one.
  sockclose $1
  window -c @Socket- $+ $1
  
  %scp.CounterB = 2
  :Loop
  if ( [ $ [ $+ [ %scp.CounterB ] ] ] != $null) { 
    SockClose $ [ $+ [ %scp.CounterB ] ] 
    Window -c @Socket-  $+ $ [ $+ [ %scp.CounterB ] ]
    inc %scp.CounterB
    Goto Loop
  }
  
  RefreshSockets
  
}

; -- /SockRename <Socket Name> <New Socket Name>

alias SockRename {
  SockRename $1-
  RefreshSockets
}

; -- /SockListen <Socket Name> [Port]

alias SockListen {
  SockListen $1-
  RefreshSockets
}

on 1:SOCKCLOSE:*:{
  window -c @Socket- $+ $SockName
  RefreshSockets
}
on 1:SOCKOPEN:*:{
  RefreshSockets
}

#scp.SocketControl end

; End of Scripting Accessories, UNIT 1, version 1.0 ;