mIRC Home    About    Download    Register    News    Help

Print Thread
Reloading script using $md5 #232713 17/06/11 12:00 AM
Joined: Jan 2007
Posts: 280
DuXxXieJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Ok, Riamsus2 gave me the brilliant solution for my 'automaticly reload when file has been edited' problem. Using $md5.

Step one (check if $md5 changes when editing file) works.
Now I need to go to step 2 which I can't figure out.

Now, a timer needs to check by EACH loaded script (I've got a 'which scripts are loaded' script loaded if this is maybe usefull to use by this?) if it's md5 has been changed. If so; reload the script.

I tried saving all md5's in a .ini file,
Quote:
[md5]
scriptname=md5 here
scriptname2=md5 thing here


etc.etc.

The timer should check if the $md5(file,2) is now different from the file's md5 in the .ini file.

Butttt, I can't figure it out, only per script, not for ALL of them.

Any help?


Squee whenever a squee squee's. Squee whenever a squee does not squee.
Re: Reloading script using $md5 [Re: DuXxXieJ] #232715 17/06/11 12:55 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Code:
; offline timer to check all remote scripts every minute
on *:start: .timerreloadmodscripts -o 0 60 reloadmodscripts

alias reloadmodscripts {
  ; loop all scripts
  var %n = 1
  while ($script(%n)) {
    ; store filehashes in a hash table (using the filenamehash as item to account for names with spaces)
    var %nh = $md5($v1), %fh = $md5($v1,2) 
    ; stored filehash is either different or nonexistent - file had been modified or new file
    if ($hget(scripthashes,%nh) != %fh) {
      ; any hash stored - file had been modified: reload at same position
     ; (without the timer you won't be able to reload this very file too)
      if ($v1 != $null) { .timer 1 0 reload -rs $+ %n $safe2($qt($script(%n))) }
      ; add/update filehash in hash table
      hadd -m scripthashes %nh %fh
    }
    inc %n
  }
}

alias -l safe2 { bset -t &a 1 $1 | return $!regsubex(safe, $bvar(&a,1-) ,/(\d+)(?: |$)/g,$chr(\1)) }


Last edited by Horstl; 17/06/11 01:01 AM.
Re: Reloading script using $md5 [Re: Horstl] #232716 17/06/11 02:31 AM
Joined: Jan 2007
Posts: 280
DuXxXieJ Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Looks very nice, although it doesnt work shocked.

When starting, I don't see any timers start (don't know if it has to?) and when a file is edited it hasn't been reloaded frown


- EDIT -

Never mind! Works perfectly, thank you very much smile.

Just a question: Possible to change timer to 30 seconds? (I know how, but I don't know if that's safe for mIRC. Lag etc.)


Last edited by DuXxXieJ; 17/06/11 02:33 AM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Re: Reloading script using $md5 [Re: DuXxXieJ] #232721 17/06/11 11:32 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
That depends on the hosting system, it's general load, and the number of scripts loaded. I don't think a shorter interval (even ~10s) could cause a noticeable lag on an average system, but it's up to you to balance resources with patience. smile

Re: Reloading script using $md5 [Re: Horstl] #232722 17/06/11 01:09 PM
Joined: Jul 2006
Posts: 3,588
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,588
I noticed you are not using the last version of that $safe alias frown
It does not handle several call of $safe in the same scope, you need to use bset -ct to clear the binvar each time wink


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Reloading script using $md5 [Re: Wims] #232723 17/06/11 02:05 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You're right... was a hasty paste smile

Re: Reloading script using $md5 [Re: DuXxXieJ] #232732 18/06/11 06:54 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
i would recommend comparing $file().mtime to detect file edits rather than MD5 hashes (or mtime and then a hash to cover cases where the file was saved/modified at least once but there was no change in its contents, if applicable), even though as a user you're unlikely to notice a difference between the two unless the total filesize of your scripts is tremendous.

for small strings of text (such as the filenames up there), i'd suggest one of the 32-bit $hash( , 32) or $crc( , 0) or even a sensible character replacement if collisions would be disastrous for you.

even though MD5 hash generation is computationally expensive, it won't impact the performance of a script in most practical cases, but there's something about using it for these types of checks that seems a bit overkill :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde