mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
I am trying to write code to prevent the unloading of a remote script where I have core functions of my over all script located can anyone tell me why this dosnt work and help with a fix.

on *:UNLOAD: {
if ($script == $mircdir\Core\Core.mrc) { echo -a 4 SYSTEM ERROR YOU CAN NOT REMOVE CORE }
load -rs $mircdirCore\Core.mrc
}

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Regarding the reason your code isn't working, is due to the discrepenancy between the script name that is being recognized under $script and the script name used in the load command.

Try this version
Code:
on *:unload:{
  if $script == Core\Core.mrc {
    echo 4 -a SYSTEM ERROR YOU CAN NOT REMOVE CORE
  }
  load -rs Core\Core.mrc
}


I left the $mircdir out of the code purposely, so that the unload event will work and reload the correct file as long as it's in the Core sub-directory.. This means that someone could put it in C:\WINDOWS\CORE and it would still work.

P.S.: You had the 4 for the colour in the echo in the wrong location.

Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
I tried the verison you gave below and the results where the same .

I typed this in status /unload -rs Core.mrc and the script was unloaded with no messages.

* Unloaded script 'Core.mrc'

Code:
on *:unload:{
  if $script == Core\Core.mrc {
    echo 4 -a SYSTEM ERROR YOU CAN NOT REMOVE CORE
  }
  load -rs Core\Core.mrc
}



Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031
I made this for someone on here some time ago, just paste it at the beginning of each file you want to protect.

Code:
on *:UNLOAD: {
  if ($input(Are you sure you want to unload this script?,dwyk10,Unloading: $nopath($script))) return
  var %i = 1
  while ($script(%i)) {
    if ($v1 == $script) {
      echo -ace info * Reloading script $+(',$script,') back into the $ord(%i) position...
      .timer 1 0 reload $+(-rs,%i) $qt($script)
      return
    }
    inc %i
  }
}

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
AFAIK $script is always an absolute pathname so it could never equal "Core\Core.mrc" no matter where it was. Of course there's no need to be checking $script anyway since the UNLOAD event will only trigger for the script it's in.

The real question is whether a scripter should unconditionally prevent a script from being unloaded. By reloading a script on unload it's effectively impossible to uninstall or otherwise remove that script short of disabling remotes first or deleting it from mirc.ini prior to starting mIRC. Not exactly user-friendly. At the very most it should provide a $input() to ask if the user really intended to remove the script (although even that seems redundant to me - of course they want to remove it, that's why they're /unload'ing it).

I don't believe it's possible to directly load/reload a script through it's UNLOAD event. It would seem to be an intentional design choice on Khaled's part. If absolutely necessary it can be done with timers or by alias'ing the /unload command itself but it's a messy way to do things and as I said above it's just bad practice in general to stop a script from being unloaded. The OP should really ask himself if he wants to piss off his users like that.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
Actually its not that I wish to prevent the script from being unloaded at all, The reason behind this particular Remote from unloading is due to the affect it has on other Remotes. Since it is the main (Core) file for the entire script. It holds all alias and script basic Functions the rest of the remotes can be removed from the script using a dialog, this is mainly a script designed for those with limited or no IRC experience on the server which I frequent.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I still would agree with starbucks_mafia. Preventing a script from being unloaded isn't a good thing. If you need to do that, then do as he mentioned and use an input to verify that the user wants to remove it. You can put a note right in there stating that removing it will prevent all of your other scripts from working properly.

Keep in mind that those inexperienced users may want to remove your script and your automatic reload will prevent them from doing so and they won't know how to get rid of it.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
One option you could consider would be to have the yes/no dialog as shown above. It would tell the user that unloading will cause problems, etc. If the user chooses 'no' (to unloading) then the script is reloaded for them. If the user chooses 'yes' (to unloading), your script could automatically unload all related scripts that would fail to work without that core script file.

Code:
<Are you sure you want to unload this core script?>
if <no> /reload core
else /unload dependencies


-genius_at_work


Link Copied to Clipboard