mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 26
M
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Aug 2004
Posts: 26
Would it be possible to have something that loads script files from a folder on the web? A friend has offered me a position as the "bot script guy" for his channel, and his connection is a lot more stable than mine, so the actual bot is planned to be on his computer. He's offered to make an FTP space on his website that I could load scripts to, but we were wondering if it would be possible to rig something up so that when the bot started up (Or when given a command, for when I updated things while it was running), it would either download or just read all the scripts from that folder on the web, and load the scripts.

My other idea (Since his DCC is busted) was to make a switch command that would create a sort of logging script. Something along the lines of:
Code:
  
on 1:TEXT:*:?: {
if ($1 == !StartScriptLogging) {
set %ScriptName $2
set %LoggingScript on
}
elseif ($1 == !StopLoggingScript) { set %LoggingScript off }
elseif ($1 == !LoadScript) { load $2 }
elseif ($1 == !UnloadScript) { unload $2 }
elseif (%LoggingScript = on) { write scripts/ $+ %ScriptName $+ .mrc $1- }
else { }
}

Apologies if there's errors in that, it was just something I typed up on the fly as an example.

Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
You can't run a script from a website, unless the bot is on the host machine. (Meaning, if the machine hosting the website is the same machine that is hosting the bot, then yes, the bot could just find and load the upload script via an on text command or what have you.)

If the website is on a different machine, then it gets more complicated. You could write a script that does something like: !get http://something.com/somefile.mrc, and have the bot download that file via sockets, and then load the file. But that's a little more complicated than it's worth, imo.

Of course, seeing as this is a pretty commonly requested thing, you could just download a premade one that works wonders. Such as FiberOPtics $download() script, which can be found here

Then, all you would have to do is:

Code:
on *:text:!getscript & &:#:{ .signal getscript $2 $3 }
on *:signal:getscript:{
  if ($download($2, GET, $3, 2)) { load -rs $2 }
}


!getscript somename.mrc http://yadayada.com/somename.mrc

Of course, you would need some sort of "protection" for the "on text" event, as you don't want just anyone to be able to !getscript.

Also, you might need someone to actually accept that the script is to be loaded. heh.

Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
the logging script sounds good you could compliment that with your own /play command. What if he disconnects mid-log though.
The other way using sockets would be better perhaps, since he wouldn't need to be connected to the network after the trigger.

You'd need him to load a script to handle either way of course.

btk


billythekid
Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
nice link to that, think i'll have many uses for the $download script.

btk


billythekid
Joined: Jan 2003
Posts: 1,063
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
do remember to have mIRC reload the script if you edit it and have it downloaded again ;-]
it doesn't reload it on changes by itself


If it ain't broken, don't fix it!
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
I suffered from something called boredom, and decided to take a stab at this. Works fairly well, but could probably use some improvements and such. Here's what I came up with:

Code:
; -----------------------------------------------------------------------------
; Remotely Manage mIRC Files
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Constants
; -----------------------------------------------------------------------------

; rm.site
; The host URL to be retrieving script files from
alias -l rm.host { return www.changeme.com }

; rm.path
; Path on said site to retrieve script files from
alias -l rm.path { return /change/me/ }

; rm.hash
; Hash table name (used to maintain file updates)
alias -l rm.hash { return rmlist }

; rm.hfile
; Hash file store path
alias -l rm.hfile { return system\hash\rmlist.hsh }

; -----------------------------------------------------------------------------
; Menu System
; -----------------------------------------------------------------------------

menu nicklist {
  Remote mIRC
  .$iif($ulist($$1,admin),Remove,Add) User: {
    if ($ulist($$1,admin)) .ruser admin $$1
    else /auser -a admin $$1
  }
}

; -----------------------------------------------------------------------------
; Hash Table System
; -----------------------------------------------------------------------------

alias -l rm.save {
  if ($hget($rm.hash)) {
    var %t = 1, %dir = $nofile($rm.hfile), %tok = $iif($pos(%dir,/),47,92), %n = $numtok(%dir,%tok)
    while (%t < %n) {
      var %path = $gettok(%dir,$iif(%t == 1,%t,$+(1-,%t)),%tok), %t = %t + 1
      if (!$isdir(%path)) /mkdir %path
    }
    /hsave $rm.hash $rm.hfile
  }
}

on *:START: {
  var %dir_list = system\hash system\backup system\scripts, %d = 1
  while ($gettok(%dir_list,%d,32)) {
    var %t = 1, %dir = $v1, %n = $numtok(%dir,92), %d = %d + 1
    while (%t < %n) {
      var %path = $gettok(%dir,$iif(%t == 1,%t,$+(1-,%t)),92), %t = %t + 1
      if (!$isdir(%path)) /mkdir %path
    }
  }

  if (!$hget($rm.hash)) /hmake $rm.hash 10
  if ($isFile($rm.hfile)) /hload $rm.hash $rm.hfile
}

on *:EXIT: {
  /rm.save
}

; -----------------------------------------------------------------------------
; Sockets
; -----------------------------------------------------------------------------

alias -l rm.cmd {
  if ($1 == echo) return /echo -s *
  return /msg $1
}

alias -l rm.chk_update {
  var %cmd = $rm.cmd($1), %file = $replace($2-,$chr(32),$+(%,20)), %lupdate = $hget($rm.hash,%file)

  if (%lupdate) {
    /sockopen rm.update $rm.host 80
    /sockmark rm.update CHKUPDATE $1 %file
    [ %cmd ] Checking for update of %file $+ ...
  }
  else [ %cmd ] Could not update file: Previous record not found.
}

alias -l rm.update {
  var %cmd = $rm.cmd($1), %file = $replace($2-,$chr(32),$+(%,20)), %lupdate = $hget($rm.hash,%file)

  /sockopen rm.update $rm.host 80
  /sockmark rm.update UPDATE $1 %file
  [ %cmd ] Downloading update of %file $+ ...
}

on *:SOCKOPEN:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)

  /set %rm.update.header 1

  if ($right($rm.path,1) == /) var %gfile = $rm.path $+ %file
  else var %gfile = $rm.path $+ / $+ %file

  if ($sockerr) [ %cmd ] Could not check for update: $sock(%sock).wsmsg
  else if (%what == CHKUPDATE) {
    /sockwrite -n %sock HEAD %gfile HTTP/1.0
    /sockwrite -n %sock Host: $rm.host
    /sockwrite -n %sock User-Agent: Mozilla/4.0 (mIRC Remote)
    /sockwrite -n %sock Accept: */*
    /sockwrite -n %sock If-Modified-Since: $hget($rm.hash,%file)
    /sockwrite -n %sock $crlf
  }
  else if (%what == UPDATE) {
    /sockwrite -n %sock GET %gfile HTTP/1.0
    /sockwrite -n %sock Host: $rm.host
    /sockwrite -n %sock User-Agent: Mozilla/4.0 (mIRC Remote)
    /sockwrite -n %sock Accept: */*
    /sockwrite -n %sock $crlf
  }
  else {
    [ %cmd ] Unknown action %what
    /sockclose %sock
  }
}

on *:SOCKREAD:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark, %read
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)

  if (%rm.update.header) {
    /sockread %read
    if ($len(%read) == 0) {
      /unset %rm.update.header
      return
    }
  }
  else {
    /sockread &data
  }

  ; HEADERS
  if (%rm.update.header) {
    var %reg_http = /HTTP[\/0-9\.]+ ([0-9]+) .*/i
    var %reg_lmod = /Last-Modified: (.*)/i
    if (%what == CHKUPDATE) {
      if ($regex(%read,%reg_http)) {
        var %code = $regml(1)
        if (%code == 304) [ %cmd ] %file has not been updated
        else if (%code == 200) /set %rm.update.modified 1
        else if (%code == 404) [ %cmd ] File could not be found. Check the file name, and try again.
      }
      else if (($regex(%read,%reg_lmod)) && (%rm.update.modified)) {
        var %date = $gettok(%read,2-,32)
        [ %cmd ] %file was last modified %date $+ .
        /unset %rm.update.modified
      }
    }
    else if (%what == UPDATE) {
      if ($regex(%read,%reg_http)) {
        var %code = $regml(1)
        if (%code == 200) {
          /set %rm.update.download 1
          [ %cmd ] Found %file $+ , downloading...
        }
        else if (%code == 404) [ %cmd ] File could not be found. Check the file name, and try again.
      }
      else if ($regex(%read,%reg_lmod)) {
        var %date = $regml(1)
        if (!$hget($rm.hash,%file)) /set %rm.upload.newfile 1
        /hadd $rm.hash %file %date
        /rm.save
      }
    }
    else if ($regex(%read,%reg_http)) {
      var %code = $regml(1)
      if (%code == 400) [ %cmd ] Could not retrieve file: bad request
      else [ %cmd ] Unknown error: %read
    }
  }
  else if (%rm.update.modified || %rm.update.download) {
    var %savefile = $replace(%file,$+(%,20),$chr(32))
    /echo -s /bwrite $+(",%savefile,") -1 -1 &data
    /bwrite $+(",%savefile,") -1 -1 &data
    /set %rm.update.file %savefile
  }
}

on *:SOCKCLOSE:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)

  /echo -s %mark
  /echo -s % $+ rm.* vars: $var(%rm.*,0)

  if ((%what == UPDATE) && (%rm.update.file)) {
    [ %cmd ] Download complete. Loading script...

    var %savefile = %rm.update.file
    if ($isFile($+("system\scripts\,%savefile,"))) .copy -o $+("system\scripts\,%savefile,") $+("system\backup\,%savefile,")

    .copy -o $+(",%savefile,") $+("system\scripts\,%savefile,")
    .remove $+(",%savefile,")

    if ($script($+("system\scripts\,%savefile,"))) /reload -rs $+("system\scripts\,%savefile,")
    else /load -rs $+("system\scripts\,%savefile,")

    if (*Loaded* !isin $line(Status Window,$calc($line(Status Window,0) - 1))) {
      [ %cmd ] Error loading %file $+ : $line(Status Window,$calc($line(Status Window,0) - 1))
    }
    else [ %cmd ] %file loaded successfully.

    /unset %rm.update.*
  }
}

; -----------------------------------------------------------------------------
; BOT Commands
; -----------------------------------------------------------------------------

on admin:TEXT:!*:#,?: {
  var %target = $iif($target == $me,$nick,$chan)

  ;
  ; !download <file>
  ;
  ; Downloads the specified file from a web server (provided), then loads the
  ; file.
  ;
  if ($1 == !download) {
    if ($2) {
      var %file = $2-
      /msg %target Downloading $+(,%file,...)
      /rm.update %target %file
    }
    else /msg %target Insufficient parameters: !download <file>
  }

  ;
  ; !update <file>
  ;
  ; Checks for an update of the file on the specified web server.
  ;
  else if ($1 == !update) {
    if ($2) {
      var %file = $2-
      /msg %target Checking $+(,%file,) for update...
      /rm.chk_update %target %file
    }
    else /msg %target Insufficient parameters: !update <file>
  }

  ;
  ; !unload <file>
  ;
  ; Unloads the script file
  ;
  else if ($1 == !unload) {
    if ($2) {
      var %file = $2-
      if ($script(%file)) {
        /unload -rs %file
        /msg %target %file has been unloaded.
      }
      else /msg %target %file is not loaded.
    }
    else /msg %target Insufficient parameters: !unload <file>
  }
}


Basically, use !download <file> to download and load your new file, !update <file> to check for a file update, and !unload <file> to unload your file. Again, primitive. I wrote this on 6.2, so not sure what I used that may be unavailable as of earlier versions. The only thing I can think of off-hand would be $v1, which is a few versions old.

I've tested this off my server, worked great. Just realize it's simple, and gets the job done. It's meant for you to upload your file to a web server, then point to it and refer to the files using the commands. I used my site with a sub folder (example: kingtomato.org/scripts/myscript.mrc--means rm.host is www.kingtomato.org, rm.path is /scripts/, and I would use !download myscript.mrc)


-KingTomato

Link Copied to Clipboard