Time Synch — File Browser

TimeSynchv1.02 / TimeSynchv1.02 / tsynch.mrc

tsynch.mrc — 8.43 KB — Download this file

; ##                                                                               ##
;      Author, SpikerX
;      E-mail, spike46042@hotmail.com
;     Version, 1.02
; Description, Addon that simplifies the task of correcting your computer's clock.
; ##                                                                               ##

;## Aliases ##

alias -l dlg dialog $iif($dialog($1),-v,-m $+ $2 $1) $1
alias -l dlgx var %i = $0 | while (%i) { var %d = $ [ $+ [ %i ] ] | if ($dialog(%d)) dialog -x %d | dec %i }
alias -l _d { if ($dialog(tsynch)) did -ra $ifmatch 5 $1- }
alias -l _e echo $colour(info) $1-
alias -l _hget return $hget(tsynch,$1)
alias -l _hadd hadd -m tsynch $1-
alias -l convert { if (!$1) return | var %., %z = $calc($timezone / 3600), %_, %- | if ($daylight) %z = $calc(%z - 1) | if (. isin %z) %- = $calc($+(.,$gettok(%z,2,46)) *60) | %z = $gettok(%z,1,46) | tokenize 58 $1 | if ($1 < %z) tokenize 32 $calc(24 + $ifmatch + $daylight) $2-3 | %. = $abs($calc($1 - %z)) | %_ = $convert2($+(%.,:,$2,:,$3)) | %_ = $calc(%_ + (%- *60)) | return $frmt(%_) }
alias -l convert2 { if ($numtok($1,58) != 3) return | var %s = $calc($gettok($1,1,58) * (60^2)) | %s = $calc(%s + ($gettok($1,2,58) *60)) | %s = $calc(%s + $gettok($1,3,58)) | return %s }
alias -l cmpr { var %. = tsynch, %d1 = $iif(%tsynch.d1,$ifmatch,$did(%.,2)), %d2 = $iif(%tsynch.d2,$ifmatch,$did(%.,3)) | .timertsynch 1 5 unset %tsynch.* | if (%d1 == %d2) return 0 | if (!%d1) || (!%d2) return 1 | if ($gettok(%d1,1-2,58) != $gettok(%d2,1-2,58)) return 1 | if ($round($abs($calc($gettok(%d1,3,58) - $gettok(%d2,3,58))),0) !isnum 1-5 ) return 1 | return 0 }
alias -l frmt { if (!$1) return | var %t = $gettok($calc($1 /3600),1,46) | if (%t > 24) %t = $calc(%t - $iif($daylight,23,24)) | if ($len(%t) == 1) %t = 0 $+ %t | if (%t == 24) %t = 00 | %t = $addtok(%t,$gettok($duration($1,3),2-3,58),58) | return %t }
alias -l getday return $gettok($asctime,3,32)
alias -l ltime { tokenize 58 $time | return $+($iif($len($1) == 1,$+(0,$1),$1),:,$2,:,$3) }
alias -l tsynch.start { if ($sock(nist)) sockclose nist | _d Accessing NIST server. | sockopen nist $iif($_hget(proxy),$_hget(proxy.host) $_hget(proxy.port),132.163.4.101 14) }
alias -l tsynch.update { var %s = $round($calc(($ticks - %tsynch-ticks) / 1000),0) | %s = $calc(%s + $convert2($1)) | unset %tsynch-ticks | if (!$gettok($dll($scriptdirsettime.dll,set,$frmt(%s)),1,32)) { _d Unable to adjust system time. | halt } }
alias -l tsynch.help return $+(",$scriptdirtsynch-help.cfg,")
alias -l tsynch.dupdate { if ($getday != $_hget(day)) { hinc tsynch dcount | _hadd day $getday } }
alias tsynch.tupdate { tsynch.dupdate | if ($_hget(dcount) >= $_hget(asynch.days)) { if (!$_hget(asynch.s)) { %tsynch.dtmp = 1 | tsynch } | else { %tsynch.atmp = 1 | tsynch.start } | _hadd dcount 0 } | .timertsynch.tupdate -o 1 21600 tsynch.tupdate }
alias tsynch dlg tsynch

;## Dialogs ##

dialog tsynch {
  title "Time Synch"
  size -1 -1 131 54
  option dbu

  text "System Time:", 1, 4 2 32 8
  edit "", 2, 4 10 56 11, read autohs
  text "Current Time:", 4, 71 2 33 8
  edit "", 3, 71 10 56 11, read autohs

  edit "", 5, 4 24 123 11, read autohs center

  button "Correct &Time", 8, 4 39 37 12, disable

  button "&Close", 7, 91 39 37 12, cancel
}

on *:dialog:tsynch:*:* {
  if ($devent == init) tsynch.start
  if ($devent == sclick) && ($did == 8) { tsynch.update $did(3) | did -b $dname 8 | _d Time successfully adjusted. | did -ra $dname 2,3 $ltime }
  if ($devent == close) unset %tsynch*
}

dialog tsynch.config {
  title "Time Synch - Configure"
  size -1 -1 143 129
  option dbu

  button "&OK", 8, 57 114 37 12, ok
  button "&Cancel", 1, 104 114 37 12, cancel

  text "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯", 14, 2 7 143 3, disable
  text "Setup", 2, 7 4 14 8
  check "&Auto-synch time at regular intervals.", 4, 7 15 100 10
  text "&Days between auto-synchs:", 5, 16 28 68 8
  edit "", 6, 85 27 17 10, autohs center
  check "&Run silently.", 7, 16 38 50 10

  text "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯", 3, 2 55 143 3, disable
  text "Proxy", 15, 7 52 14 8
  check "Use a &proxy server.", 9, 7 63 59 10
  text "Host:", 10, 17 78 13 8
  edit "", 11, 31 76 73 11, autohs
  text "Port:", 12, 17 93 12 8
  edit "", 13, 31 91 24 10, autohs center

  text "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯", 16, 2 109 143 3, disable
}

on *:dialog:tsynch.config:*:* {
  if ($devent == init) { if ($_hget(asynch)) did -c $dname 4 | else did -b $dname 5,6,7 | did -a $dname 6 $_hget(asynch.days) | if ($_hget(asynch.s)) did -c $dname 7 | if ($_hget(proxy)) did -c $dname 9 | else did -b $dname 10,11,12,13 | did -a $dname 11 $_hget(proxy.host) | did -a $dname 13 $_hget(proxy.port) }
  if ($devent == sclick) {
    if ($did == 8) { if (!$did(6)) { var %_ = $input(You must specify a value greater than zero (0) in the corresponding 'Days between auto-sycnh:' field.,oh,Time Synch - Warning) | halt } | _hadd asynch $did(4).state | _hadd asynch.days $did(6) | _hadd asynch.s $did(7).state | _hadd proxy $did(9).state | _hadd proxy.host $did(11) | _hadd proxy.port $did(13) }
    if ($did == 4) did $iif($did(4).state,-e,-b) $dname 5,6,7
    if ($did == 9) did $iif($did(9).state,-e,-b) $dname 10,11,12,13
  }
  if ($devent == edit) && ($did == 6) || ($did == 13) { var %. = $did($did) | if (%. !isnum) { :c | %. = $iif($len(%.) > 1,$left(%.,-1)) | if (%. !isnum) && (%.) goto c | did -ra $dname $did %. } }
}

dialog tsynch-help {
  title Time Synch - Help
  size -1 -1 200 136
  option dbu
  text "Topics:", 2, 5 4 17 7
  list 5, 5 13 70 102, size
  text "Details:", 4, 80 4 18 7
  edit "", 7, 80 13 115 102, read multi vsbar
  button "&Close", 6, 80 120 40 12, ok
}
on *:dialog:tsynch-help:*:*: {
  if ($devent == init) { if (!$isfile($tsynch.help)) goto empty | loadbuf -ottopics $dname 5 $tsynch.help | if (!$did(5).lines) { :empty | did -ab $dname 5 Empty! | did -a $dname 7 No help topics could be found. | return } | did -a $dname 7 Select a topic you wish to find help on. }
  if ($devent == sclick) && ($did == 5) { did -r $dname 7 | if (!$readini($tsynch.help,$did(5).seltext,n0)) did -a $dname 7 No help is available for $+(",$did(5).seltext,".) | elseif (!$readini($tsynch.help,$did(5).seltext,n1)) did -a $dname 7 $readini($tsynch.help,$did(5).seltext,n0) | else { var %n = 0 | while ($readini($tsynch.help,$did(5).seltext,$+(n,%n))) { did -a $dname 7 $ifmatch $+ $iif($readini($tsynch.help,$did(5).seltext,$+(n,$calc(%n + 1))),$+($crlf,$crlf)) | inc %n } | did -c $dname 7 1 } }
}

;## Popups ##

menu status,channel,query {
  Time Synch
  .Check Time: tsynch
  .-
  .Configure: dlg tsynch.config
  .Help: dlg tsynch-help  
  .-
  .Unload: if ($input(Are you sure you want to unload $crlf $+ Time Synch?,qy,Unload Confirmation)) .unload -rs $+(",$script,")
}

;## Remotes ##

on *:sockopen:nist: { if ($sockerr) { _d Unable to connect to NIST server. | return } | if ($_hget(proxy)) { var %_ = .sockwrite -n $sockname | %_ GET / HTTP/1.0 | %_ Host: $ip | %_ User-Agent: Time Synch | %_ Accept: */* | %_ $crlf } | _d Connected. Retrieving local time. }
on *:sockread:nist: { var %i, %. = $dialog(tsynch) | sockread %i | if ($sockerr > 0) { _d Unable to retrieve local time. | halt } | if (!%i) return | if (%.) { did -ra %. 2 $ltime | did -ra %. 3 $convert($gettok(%i,3,32)) } | else { %tsynch.d1 = $ltime | %tsynch.d2 = $convert($gettok(%i,3,32)) } | if ($cmpr) { _d Time difference detected. | %tsynch-ticks = $ticks | if (%tsynch.dtmp) { tsynch.update $did(tsynch,3) | _d Time successfully adjusted. Closing. | .timertsynch.xclose 1 5 dialog -c tsynch } | elseif (%tsynch.atmp) tsynch.update %tsynch.d2 | if (%.) did -e %. 8 | return } | _d System time within an acceptable margin. | if (%.) did -b %. 8 }
on *:exit: { if ($hget(tsynch)) hsave -o tsynch tsynch.dat }
on *:start: { if (!$hget(tsynch)) hmake tsynch 5 | if ($isfile(tsynch.dat)) hload tsynch tsynch.dat | tsynch.tupdate }
on *:load: { if ($version < 6.01) { _e -a Time Synch cannot run in a version of mIRC less than 6.01. Upgrading to version 6.12 is highly recommended. | .unload $+(",$script,") } | hmake tsynch 5 | _hadd asynch 1 | _hadd asynch.days 5 | _hadd asynch.s 1 | _e -ea * Time Synch successfully loaded. Time Synch can be accessed through the menus. }
on *:unload: { unset %tsynch* | dlgx tsynch tsynch.config tsynch-help | sockclose nist | hfree tsynch | if ($isfile(tsynch.dat)) .remove tsynch.dat | .timertsynch.tupdate off | _e -ea * Time Synch unloaded successfully. }