ITechSC.com

DOWNLOAD
MAIL LISTS
HOWTO
FAQ



Location: Software / Free / NetScript / HOW TO


Net Script




HOW TO Index...

1.How to install.
2.How to add a site/job.
3.How to setup triggers.
4.How to setup scripts.
5.How to debug scripts.

How to install

Please see the "doc/build.txt" file which comes with the NetScript distribution.

How to add a host/task

You can do this in 2 ways, the first way is you can do it manually, by creating the right directories and files. The second way is you can use the "netscript_mksite" script which comes with the NetScript distribution. All this script does is it creates the directories and files for you.

If you run the script, it basically does what is described below for you. If this is your first time, use the script, then you will see the file formats. If you use UNIX regularly you will probably not use the script again because you can probably create and/or modify the files quicker by hand than running the script again...

If you want to create the host/task by hand though, this is what you do.

You can run NetScript and connect to a network servive without even creating a host/task of course, but if you do this you may as well use telnet! The minimum you have to do to create a host/task is you have to create a directory in your home directory called .netscript, and then inside this, create a directory for the host you are going to connect to, for example, you might create an "mail.itechsc.com" directory. Now create a directory inside the host directory for your task. For example you might create the directory "checksmtp". Now NetScript will recognise a configuration called "mail.itechsc.com/checksmtp".

Having done this, although NetScript will recognise "mail.itechsc.com/checksmtp" (which means you can now start NetScript with the command "netscript -m mail.itechsc.com/checksmtp") it still isn't any different to telnet. If you use the command "netscript -m mail.itechsc.com/checksmtp mail.itechsc.com 25" then you will be connected to the SMTP server, but again, you could have done this with telnet and not bothered with the "-m mail.itechsc.com/checksmtp"!

Now for the useful bits. Create a file inside the "mail.itechsc.com/checksmtp" directory called "config.txt" and make it look like this:

        GameHost: mail.itechsc.com
        GamePort: 25
        Triggers: On
        Scripts: On
        Record: On
Now you have a useful feature at last! If you use the command "netscript -m mail.itechsc.com/checksmtp" then you will be connected to the server without having to enter in the host and port! Woo hoo!

The "Triggers", "Scripts" and "Record" lines above mean that triggers are enabled by default, scripts are enabled by default and recording is on by default, these options can be set to "On" or "Off".

Note that this 2 tier directory structure isn't mandatory, you could simple create a single "abs" directory in your ".netscript" and put all your files in there, which would allow you to connect with the command "netscript -m abs".

I bet your mind is blown so far.. well.. never mind.. check out the next section to see how to create triggers..

How to setup triggers

You can do this in 2 ways, the first way is you can do it manually, by creating the files (or entries in files). The second way is you can use the "netscript_mktrigger" script which comes with the NetScript distribution. All this script does is change the configuration files for you.

If you run the script, it basically does what is described below for you. If this is your first time, use the script, then you will see the file formats. If you use UNIX regularly you will probably not use the script again because you can probably modify the files quicker by hand than running the script again...

If you want to create the triggers by hand though, this is what you do.

Let us assume that you have a site/task which you've called "mail.itechsc.com" and a character called "checksmtp", as if created from the example in the previous section. Inside the "checksmtp" directory, create a file called "triggers.txt". Put in a line which reads like this:

        see "220 toxic.bogusmove.com" send "helo\n"
Basically this is a simple instruction to NetScript that says when it sees a certain thing, it should send back something else! The format is as follows:
        see "X" send "Y"
DO include the double quotes!!

When X is seen from the network server, then Y is sent back. Notice that in the above example "Y" ends with a "\n". The "\n" is taken to mean a "return". If you don't include it then "Y" will be inserted into your buffer, but not sent to the network! You will discover what effect this has if you try it.

Create as many such lines in the file as you like. If output from the network server matches more than one of the triggers then ALL the matching triggers will be triggered, so if you were to put 5 lines like the example above into your "triggers.txt" file, you are liable to respond with 5 "helo" responses!!

There are also some advanced features, introduced in version 1.01. These allow you to add tags to the triggers to change the way they work. There are 3 tags currently supported, they are the "maxtimes" tag, the "matchstop" tag and the "debug" tag. The "debug" tag is only for scripts and is covered later in the "how to debug scripts" section.

The other 2 tags can be applied to stright triggers or scripts. The "maxtimes" tag allows you to specify the maximum number of times a trigger can be activated (since you started netscript). This might be good for logging in to something for example:

        see "Login:" send "NAME\n" maxtimes=1
This will only ever be triggered once.

The "matchstop" tag causes a trigger, if it matches, to stop any further trigger matching. This means that all the triggers AFTER this trigger won't be checked against. For example, if you connected to a chat server this might work:

        see "says 'hello'" send "say hello\n" maxtimes=2 matchstop
        see "says 'hello'" send "say hello yet again\n" maxtimes=1 matchstop
        see "says 'hello'" send "say stop bothering me\n" maxtimes=1
        see "says 'hello'" send "say im not talking to you\n"
The first one will match only twice, and prevent any of the others from matching. The second will match once, and again stop the others from matching. The third will match once but not stop the 4th from matching simultaneously! The fourth will always match since it has no limit specified. This should result in the following conversation:
        You say 'hello'
        Arkal says 'hello'
        You say 'hello'
        Arkal says 'hello'
        You say 'hello'
        Arkal says 'hello yet again'
        You say 'hello'
        Arkal says 'stop bothering me'
        Arkal says 'im not talking to you'
        You say 'hello'
        Arkal says 'im not talking to you'
        You say 'hello'
        Arkal says 'im not talking to you'
You can achieve all sorts of odd effects this way, but don't get bogged down going too mad writing endless intricate triggers when it might be simpler to write a script!

How to setup scripts

Let us assume that you are going to connect to a MUD (an online game), the site for which you've called "mr" and with job/task called "murk". So, in your home directory you have ".netscript", and in that you have "mr" and in that you have "murk" and in that, a "triggers.txt" file!

You should also create a directory called "scripts" in the "murk" directory.

The format for scripts is similar to the triggers, and they go into your "triggers.txt" still. Script entries look like:

        see "X" exec "Y"
"Y" is the name of a file inside your "scripts" directory. The file should be executable.

If the mud "sees" "X", then "Y" is run... from now on, all output from the MUD is sent to the running script, and any output from the script is sent back to the mud! This means that "Y" can be an executable of any sort, it can be a C program, a shell script, a perl script.. almost anything..

Try the following script called "hello.pl" (note that you need perl for this):

        #!/usr/bin/perl
        
        if ($ARGV[0] eq "") {
          exit 0;
        }
        
        use IO::Handle;
        STDOUT->autoflush(1);
        
        while (<STDIN>) {
          if ($_ =~ /^.*?([A-Za-z0-9]+) says \'hello\'.*$/) {
              printf "smile\n"; 
              printf "say hello $1\n";
          }
        }
        
        exit 0;
Add an entry into your "triggers.txt" file similar to this:
        see "start scripting" exec "hello.pl"
Now, logon and make sure your mud client gets to see the phrase "start scripting", by saying it, or something... the script should now be active.

The script should respond to people saying hello now by smiling and and saying hello back.

Note that some services send lots of lovely VT102 codes, which will also get sent to your script! Yuck.. now.. this can be quite helpful sometimes because you can use them to see what is going on and control things better than ever you could if you didn't get this information.. but.. the down side is you have to be aware of them and parse them! The above script works fine on Mortal Realms if you disable colour and VT102. It does not if you have them on.

Future releases of NetScript will include options to automatically strip out VT102 (and telnet) codes so that it is easier to write simple scripts when you have VT102 and colour turned on.

How to debug scripts

Note that these features were introduced in version 1.01!

The problem with scripts is knowing what input is coming from where, to where, why and generally what is going on. Output from your scripts goes to the MUD of course so it isn't always easy to debug in the normal way.

In order to help you, NetScript reads "stderr" from the scripts too. Unless you specify debugging then this output is simply discarded. If you use a "debug" tag on your script (in "triggers.txt") though, it can be sent to the specified log file. Try this:

        see "start scripting" exec "hello.pl" debug=hello.log
Errors from hello.pl will now be appended to the "hello.log" file (in whatever directory you are running netscript. Try the following "hello.pl" changes:
        #!/usr/bin/perl
        
        if ($ARGV[0] eq "") {
          exit 0;
        }
        
        use IO::Handle;
        STDOUT->autoflush(1);
        STDERR->autoflush(1);
        
        while (<STDIN>) {
          if ($_ =~ /^.*?([A-Za-z0-9]+) says \'hello\'.*$/) {
              printf STDERR "I am resonding to $1.\n";
              printf "smile\n"; 
              printf "say hello $1\n";
          }
        }
        
        exit 0;
In addition to responding.. you should now find that NetScript is logging "I am responding to X" messages to your "hello.log" file! You can see live updates to this file by issuing the UNIX command "tail -f hello.log".

If you specify "debug=onscreen" in your "triggers.txt" configuration file then output will be to the screen where everything else is, note that the contents of 2 files "outputprepend,txt" and "outputappend.txt" (read at netscript start time) will be pre and post fixed to the output. These files can contain anything, including VT102 codes to make your errors or debug output show up in bold, or colour, etc.

How to get more help!

Please try using the netscript mailing lists. Subscribe to the netscript-users list, post your quesion, maybe someone will be able to help you.