All pastes #475559 Raw Edit

Something

public text v1 · immutable
·published 2007-05-07 15:01 UTC
rendered paste body
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Port checker version 1.0 ;;
;; - By skauert © 2007      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; SETUP
; -----

alias pcsetup {
  ; Channel
  set %pcchan #deltaanime

  ; Enable continuous checking?
  set %pccont 0

  ; Trigger
  set %pctrigger !status

  ; IP to check
  set %pcip 128.121.25.132

  ; Port to check
  set %pcport 4111

  ; Socket name
  set %pcsocketname mysock

  ; Timeout (seconds)
  set %pctimeout 20

  ; Check how often? (Do NOT let this be smaller than the timeout)
  set %pctimer 30

  ; Message on successful connection
  set %pcconmsgok The connection is OK.

  ; Message on failed connection
  set %pcconmsgfail The connection failed.

  if (%pccont == 1) {
    ; (Re)start the timer
    .timer4421 off
    .timer4421 0 %pctimer checkport %pcip %pcport
  }

  sockclose %pcsocketname
}


; REMOTE
; ------

on *:sockopen:%pcsocketname: {
  if ($sockerr == 0) {
    set %pcsockok 1
    .timer4422 off
    checksockvar
  }

  sockclose %pcsocketname
}

on *:text:%pctrigger:%pcchan: {
  if (%pccont == 0) {
    checkport $iif($2 == $null, %pcip, $2) $iif($3 == $null, %pcport, $3)
  }
}

; ALIASES
; -------

alias stopchecker {
  .timer4421 off
  .timer4422 off
  sockclose %pcsocketname
}

alias startchecker {
  pcsetup
}

alias checkport {
  var %ip = $$1
  var %port = $$2

  sockopen %pcsocketname %ip %port
  .timer4422 1 %pctimeout checksockvar
}

alias checksockvar {
  if (%pcsockok != 1) {
    msg %pcchan %pcconmsgfail
  }
  else {
    msg %pcchan %pcconmsgok
    set %pcsockok 0
  }
}