zIRCk Final Project — File Browser

zIRCkFinalProjectv2.5 / zIRCkFinalProjectv2.5 / System / script3.mrc

script3.mrc — 13.96 KB — Download this file

[SCRIPT]
NAME=Script events
VERSION=2.5

; ## Script Events
; ## [AFX] 2005

; ## Startup

on *:start: {
  loadpb -o
  loadpb -t Welcome to zIRCk, initializing... 
  inc %times
  $iif(!%arise_text,arise_reset)
  hmake pwb 500
  loadpb -t Setting tip...
  set %tip $rand(1,$lines($_doc(Tips)))
  loadpb -a 10
  loadpb -t Checking times ran...
  if (%times = 1) {
    findmod
    def_nicklust
    def_switchbar
    dodialog about
  }
  loadpb -a 30
  loadpb -t Checking mIRC version...
  if ($version < 6.16) { kte.echo Incompatible mIRC version! | .exit }
  loadpb -a 50
  mcustom SetIcon -m $shortfn($scriptdirIcons\zirck.ico)
  loadpb -t Output to status window...
  echo -a zIRCk standing by...
  echo -a $chr(160) $+(,$chr(187),)  Nickname: $me / Started on $date
  loadpb -a 70
  whilefix
  loadpb -t Checking display settings...
  $iif($rconf(Display,Toolbar) = on && $rconf(Display,MiniTb) = off || $rconf(Display,MiniZ) = on,dodialog tb)
  $iif($rconf(Display,BBar) = on,dodialog bbar)
  $iif($rconf(Display,SidePane) = on,sidepane)
  loadpb -a 95
  loadpb -t Finalizing zIRCk...
  $iif($rconf(General,ConfigStart) = on,dodialog config)
  $iif(!$timer(zupdates),.timerzupdates 0 180 zfastupdates)
  loadpb -a 100
  loadpb -x
  if ($rconf(Display,NotifyWin) = on) { $arise(Welcome to zIRCk,You have ran zIRCk %times times since you downloaded it) }
  zfastupdates
}

; ## Exit

on *:exit: {
  var %x = $dll(0) 
  while %x >= 0 {
    .dll -u $dll(%x)
    dec %x
  }
  unset %download* 
  sockclose download*
}

; ## on CONNECT

on *:connect: {
  _toolbar.s
  .timer -m 1 1 load.sb
  $iif(!$timer(lag),.timerlag 0 10 tlag)
  if ($rconf(Display,NotifyWin) = on) { $arise(zIRCk Script Notification,You are now connected to $network $+($chr(40),$server,/,$port,$chr(41))) }
}

; ## on DISCONNECT

on *:disconnect: {
  _toolbar.s
  .timer -m 1 1 load.sb
  .timer -m 1 1 _updatenl
  if ($rconf(Display,NotifyWin) = on) { $arise(zIRCk Script Notification,You have been disconnected from $scid($cid).network $+($chr(40),$server,/,$port,$chr(41))) }
}

; ## on ACTIVE

on *:active:*: {
  wicon $active
  _toolbar.s
  .timer -m 1 1 load.sb
  .timer -m 1 1 _update.dcc 
  if ($window($active).type == channel) { theme_nlist $active }
}

; ## on CLOSE events

on *:close:*: { .timer -m 1 1 load.sb }
on *:close:@: { .timer -m 1 1 load.sb }
on *:close:#: { .timer -m 1 1 load.sb }
on *:close:?: { .timer -m 1 1 load.sb }
on *:close:!: { .timer -m 1 1 load.sb }
on *:close:=: { .timer -m 1 1 load.sb }

; ## on JOIN 

on *:join:*: { 
  if ($nick = $me) {
    .timer -m 1 1 load.sb
    nlust.chan $chan
  }
}

; ## on PART

on *:part:*: { 
  if ($nick = $me) { 
    .timer -m 1 1 load.sb 
  } 
}

; ## on NICK
on *:nick: { 
  if ($nick = $me) { 
    .timer -m 1 1 load.sb 
  } 
} 

; ## on KICK

on *:kick:*: { 
  if ($knick = $me) {
    .timer -m 1 1 load.sb 
    if ($rconf(Display,NotifyWin) = on) { $arise(zIRCk Script Notification,You have been kicked from $chan from $nick on $scid($cid).network) }
  }
}

; ## on FILERCVD

on *:filercvd:*: {  
  if ($rconf(Display,NotifyWin) = on) { $arise(zIRCk Script Notification,You have successfully received $nopath($filename) from $nick $+($chr(40),$send($nick).secs seconds,) on $scid($cid).network) }
}

; ## on FILESENT

on *:filesent:*: { 
  if ($rconf(Display,NotifyWin) = on) { $arise(zIRCk Script Notification,You have successfully sent $nopath($filename) to $nick $+($chr(40),$send($nick).secs seconds,) on $scid($cid).network) }
}

; ## on TEXT events

on *:text:*:?: { 
  .timer -m 1 1 load.sb
  if ($rconf(Misc,MsgBlock) = on) {
    var %i = 1
    while (%i <= $lines($_doc(BadWords))) {
      if ($read($_doc(Badwords),%i) iswm $1-) && (!$istok(%msgnicks,$nick,32)) {
        $iif($rconf(Misc,BadWordMethod) = close,scid $cid close -m $nick,$iif($rconf(Misc,BadWordMethod) = block,.scid $cid ignore $nick,qblockig)) 
        if ($rconf(Display,NotifyWin) = on) {
          $arise(zIRCk Script Notification,$iif($rconf(Misc,BadWordMethod) = close,Blocked incomming message from $nick,$iif($rconf(Misc,BadWordMethod) = block,Ignored $nick (words in message matched words in databse),Blocked and ignored $nick)) on $scid($cid).network)  
        }
        else { 
          kte_echo -a Message blocker: $iif($rconf(Misc,BadWordMethod) = close,Blocked incomming message from $nick,$iif($rconf(Misc,BadWordMethod) = block,Ignored $nick (words in message matched words in databse),Blocked and ignored $nick))
        }
        .notice $nick Message was blocked because words mentioned in message are in my block list...
        haltdef
        goto next
      }
      elseif ($istok(%msgnicks,$nick,32)) { goto next }
      inc %i
    }
    :next
    return
  }
  if ($window($active) != $query($nick)) && ($rconf(Display,NotifyWin) = on) {
    $arise(zIRCk Script Notification,$nick said: $+(",$1-,") in a query on $scid($cid).network) 
  }
}

on *:text:*:#: { 
  .timer -m 1 1 load.sb
  if ($me iswm $1-) && ($active != $chan) && ($rconf(Display,NotifyWin) = on) {
    $arise(zIRCk Script Notification,$nick mentioned you in $chan on $scid($cid).network)  
  }
}

on *:text:*:=: { .timer -m 1 1 load.sb }

; ## on PONG

on ^*:PONG: { 
  set %lag $calc(($ticks - %ticks) / 1000) 
  if ($dialog(bbar)) {
    lagbar set %lag
  }
  unset %ticks 
  haltdef 
}

; ## CTCP event

ctcp *:*:*: {
  if ($rconf(Misc,CTCPs) = on) && ($gettok($read($_doc(CTCPs),w,$+(*,$1,*)),1,42) = 2) && ($1 = $gettok($read($_doc(CTCPs),w,$+(*,$1,*)),2,42)) {
    var %r = $gettok($read($_doc(CTCPs),w,$+(*,$1,*)),3,42)   
    .ctcpreply $nick $1 %r | haltdef
  }
  if ($1 = dcc) { 
    .timer -m 1 1 load.sb
    .timer -m 1 1 _update.dcc
  }
}

; ## hOSDock.dll resize event

on *:signal:hOSdock: {
  if ($1 = mIRCResize) {
    if ($dialog(tb)) && ($rconf(Display,BandMeter) = on) {
      did -h tb 4,5
      mdx MoveControl tb 4 $calc($window(-2).w -178) 6 168 38 
      mdx MoveControl tb 5 $calc($window(-2).w - 170) 11 26 16
      mdx MoveControl tb 6 $calc($window(-2).w -146) 11 100 12
      mdx MoveControl tb 7 $calc($window(-2).w -42) 11 30 16
      mdx MoveControl tb 8 $calc($window(-2).w - 170) 28 26 14
      mdx MoveControl tb 9 $calc($window(-2).w -146) 28 100 12
      mdx MoveControl tb 10 $calc($window(-2).w -42) 28 30 14
      did -v tb 4,5
    }
    if ($dialog(bbar)) {
      var %s = -183
      mdx MoveControl bbar 4 1 29 $calc($window(-2).w %s) 27
      mdx MoveControl bbar 7 $calc($window(-2).w -179) 31 170 25
      did -i bbar 4 1 setparts $calc($window(-2).w %s)
      load.sb
    }
  }
}

; ## Checking for updates

on *:sockopen:z:{
  if ($sockerr = 0) {
    sockwrite -n $sockname GET /afx/zIRCk/updates.zrk HTTP/1.1
    sockwrite -n $sockname Host: coderscore.org $+ $str($crlf ,2)
    sockwrite -n $sockname Connection: Close
  }
}

on *:sockread:z: {
  sockread %z
  if (!$exists($scriptdir $+ $gettok(%z,2,42)) || $gettok(%z,4,42) > $readini($shortfn($scriptdir $+ $gettok(%z,2,42)),SCRIPT,VERSION)) && ($dialog(config)) { 
    did -a config 97 $gettok(%z,1,42) $chr(9) $gettok(%z,2,42) $chr(9) $gettok(%z,3,42)
  }
}

on *:sockclose:z: { 
  unset %z 
  if ($dialog(config)) {
    did -i config 97 1 headerdims 100 75 $iif($did(config,97).lines > 1,auto:all,160)
    did -e config 97,98
  }
}

; ## Checking for other updates

on *:sockopen:zo:{
  if ($sockerr = 0) {
    sockwrite -n $sockname GET /afx/zIRCk/others.zrk HTTP/1.1
    sockwrite -n $sockname Host: coderscore.org $+ $str($crlf ,2)
    sockwrite -n $sockname Connection: Close
  }
}

on *:sockread:zo: {
  sockread %z
  var %c = $gettok(%z,1,42),%v = $gettok(%z,4,42), %d = $gettok(%z,3,42),%f = $gettok(%z,2,42)
  if (KTE* iswm %c) && (%v > $readini($shortfn($scriptdirKte\Kte_Version.mrc),KTE,VERSION)) { 
    did -a config 105 %c $chr(9) %f $chr(9) %d
  }
  if (ICL:* iswm %c) && (!$isfile($+(",$scriptdirIcons\Engine\,%f,"))) {
    did -a config 105 %c $chr(9) %f $chr(9) %d
  }
}

on *:sockclose:zo: { 
  unset %z 
  if ($dialog(config)) {
    did -i config 105 1 headerdims 100 75 $iif($did(config,105).lines > 1,auto:all,160)
    did -e config 98,105
  }
}

; ## Checking for updates (2nd method - not through config)

on *:sockopen:z2: {
  if ($sockerr = 0) {
    sockwrite -n $sockname GET /afx/zIRCk/updates.zrk HTTP/1.1
    sockwrite -n $sockname Host: coderscore.org $+ $str($crlf ,2)
    sockwrite -n $sockname Connection: Close
  }
}

on *:sockread:z2: {
  sockread %z2
  if (!$exists($scriptdir $+ $gettok(%z2,2,42)) || $gettok(%z2,4,42) > $readini($shortfn($scriptdir $+ $gettok(%z2,2,42)),SCRIPT,VERSION)) { 
    inc %eupdates
  }
}

on *:sockclose:z2: { 
  unset %z2
  zfastupdates_o
}

; ## Checking for other updates (ties with zfastupdates)

on *:sockopen:zof:{
  if ($sockerr = 0) {
    sockwrite -n $sockname GET /afx/zIRCk/others.zrk HTTP/1.1
    sockwrite -n $sockname Host: coderscore.org $+ $str($crlf ,2)
    sockwrite -n $sockname Connection: Close
  }
}

on *:sockread:zof: {
  sockread %z
  var %c = $gettok(%z,1,42),%v = $gettok(%z,4,42), %d = $gettok(%z,3,42),%f = $gettok(%z,2,42)
  if (KTE* iswm %c) && (%v > $readini($shortfn($scriptdirKte\Kte_Version.mrc),KTE,VERSION)) { 
    inc %oupdates
  }
  elseif (ICL:* iswm %c) && (!$isfile($+(",$scriptdirIcons\Engine\,%f,"))) {
    inc %oupdates
  }
}


on *:sockclose:zof: {
  unset %z
  if (%eupdates > 0) || (%oupdates > 0) { .timer -m 1 1 zupdateinpt }
}

; ## Checking for new/updated modules

on *:sockopen:m: {
  if ($sockerr = 0) {
    sockwrite -n $sockname GET /afx/zIRCk/mods.zrk HTTP/1.1
    sockwrite -n $sockname Host: coderscore.org $+ $str($crlf ,2)
    sockwrite -n $sockname Connection: Close
  }
}

on *:sockread:m: {
  sockread %m
  if (!$exists($scriptdir $+ $gettok(%m,5,42)) || $gettok(%m,4,42) > $readini($shortfn($scriptdir $+ $gettok(%m,5,42)),MODULE,VERSION)) { 
    did -a mods 18 $gettok(%m,1,42) $chr(9) $gettok(%m,2,42) $chr(9) $gettok(%m,3,42)
  }
}

on *:sockclose:m: { 
  unset %m
  if ($dialog(mods)) {
    did -i mods 18 1 headerdims 110 100 $iif($did(mods,18).lines > 1,auto:all,160)
    did -e mods 18,19
  }
}

; ## /download events 

on *:sockopen:download*:{
  if ($sockerr) { dl.fail $sockname Unable to Connect | return }
  var %1 = $dl.var($sockname,url),%2 = $dl.var($sockname,file)
  set % [ $+ [ $sockname $+ .status ] ] Requesting File
  sockwrite -tn $sockname GET %1 HTTP/1.1
  sockwrite -tn $sockname Host: $gettok($remove(%1,http://),1,47)
  sockwrite -tn $sockname Accept: *.*, */*
  sockwrite -tn $sockname Range: $+(bytes=,$iif($exists(%2),$file(%2).size,0),-)
  sockwrite -tn $sockname Connection: close
  sockwrite -tn $sockname $crlf
}

on *:sockclose:download*:{ if ($dl.var($sockname,status) != done) { dl.fail $sockname Disconnected } }

on *:sockread:download*:{
  if ($sockerr) { dl.fail $sockname Disconnected | return }
  if ($dl.var($sockname,status) != downloading) {
    var %1 | sockread %1 | tokenize 32 %1
    if ($1 == HTTP/1.1) { if ($2 != 200 && $2 != 206) { dl.fail $sockname $iif($dl.httpcode($2),$ifmatch,$3-) } }
    elseif ($1 == Content-Range:) { set % [ $+ [ $sockname $+ .size ] ] $gettok($3,-1,47) }
    elseif ($1 == Content-Type:) { set % [ $+ [ $sockname $+ .type ] ] $2- }
    elseif (!$1) {
      set % [ $+ [ $sockname $+ .ctime ] ] $dl.var($sockname,ctime,1) $ctime
      set % [ $+ [ $sockname $+ .status ] ] Downloading
      return
    }
  }
  else {
    var %1 = $dl.var($sockname,file)
    :sockread
    sockread &1
    if (!$sockbr) { return }
    bwrite $+(",%1,") -1 &1
    unset % [ $+ [ $sockname $+ .resume ] ]
    if ($file(%1).size < $dl.var($sockname,size)) { goto sockread }
    else {
      var %1 = $right($sockname,-8),%2 = $dl.var($sockname,file)
      set % [ $+ [ $sockname $+ .status ] ] Done
      .signal -n download_complete %1
      close -d %1
    }
  }
}

; ## Download fail/complete events

on *:signal:download_complete: {
  var %x = 1,%t
  while (%x <= $download(0)) {
    if ($download(%x) = z) {
      %t = $right(%updatefile,4)
      if (%t = .mrc) {
        echo -a $readini($+(",$scriptdir,%updatefile,"),SCRIPT,NAME)
        .timer -m 1 1 $iif($script(%updatefile),.reload,.load) -rs $+(",$scriptdir,%updatefile,")
        if ($readini($+(",$scriptdir,%updatefile,"),SCRIPT,NAME) = Bottom bar) && ($dialog(bbar)) { bbar_close ! | dodialog bbar }
        if ($readini($+(",$scriptdir,%updatefile,"),SCRIPT,NAME) = Toolbar) && ($dialog(tb)) { tb_close ! | dodialog tb }
        if ($readini($+(",$scriptdir,%updatefile,"),SCRIPT,NAME) = Sidepanel) && ($dialog(sidepane)) { sidepane_close | dodialog sidepane }
        kte_echo %updatefile was successfully updated and reloaded
        unset %updatefile
      }
    }
    if ($download(%x) = m) {
      munzip Unzip -odS update $shortfn($scriptdir $+ $gettok(%modfile,1,42)) $shortfn($scriptdir)
      .timer -m 1 1 $iif($script($gettok(%modfile,2,42) $+ .mod),.reload,.load) -rs $+(",$scriptdir,$gettok(%modfile,2,42),.mod,")
      kte_echo $gettok(%modfile,1,42) was successfully downloaded/updated. You can unload this by opening the Module Manager
      $iif($dialog(mods),did -ra mods 22 The module download directory is $modsize full.)
      .remove $shortfn($scriptdir $+ $gettok(%modfile,1,42))
      unset %modfile
    }
    inc %x
  }  
  $iif($dialog(mods),mupdates)
  $iif($dialog(config),zupdates)
  if ($dialog(mods)) {
    did -e mods 18,19
  }
  if ($dialog(config)) {
    did -e config 97,98
  }
}

on *:signal:download_fail: {
  var %x = 1 
  while (%x <= $download(0)) {
    if ($download(%x) = z) {
      kte_echo %updatefile could not be updated, please retry
      unset %updatefile
    }
    if ($download(%x) = m) {
      kte_echo %modfile could not be downloaded/updates, please retry
      unset %modfile
    }
    inc %x
  }
  if ($dialog(mods)) {
    did -e mods 18,19
  }
  if ($dialog(config)) {
    did -e config 97,98
  }
}