Using perl for scripting

Post here if you need help setting up your server, etc.
Post Reply
h4zard
On Lightcycle Grid
Posts: 22
Joined: Thu Mar 22, 2012 7:01 am

Using perl for scripting

Post by h4zard »

I know perl enough to do some cool things with it, but I don't understand how to interface with arma or rather I can interface with arma but I can't regex based on output from the server. I assumed that using SPAWN_SCRIPT and INTERCEPT_UNKNOWN_COMMANDS 1, I could just use something like

Code: Select all

#!/usr/bin/perl

while(1){
my $input = <STDIN>;
# output to regex [1 IP=0.0.0.0:0000] [cmd] user: /Something
if($input =~ m/\[\d\s*\/Something/){
print "console_message 0xff0000Some Console Text.\n";
}
}
much to my dismay I don't seem to be able to regex output from the server output. any ideas what i'm doing wrong ?
User avatar
compguygene
Adjust Outside Corner Grinder
Posts: 2346
Joined: Thu Aug 21, 2008 12:09 pm
Location: Cleveland, Ohio
Contact:

Re: Using perl for scripting

Post by compguygene »

Only kyle or Voodoo can probably confirm this, but it is my understanding that only PHP and Python are supported in the current .2.8 branches. Only python is supporting in the trunk scripting branch Voodoo has started.
Armagetron: It's a video game that people should just play and enjoy :)
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm
User avatar
dlh
Formerly That OS X Guy
Posts: 2035
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Re: Using perl for scripting

Post by dlh »

Scripts launched with SPAWN_SCRIPT are fed ladderlog as input, not the output from the server console. Take a look at var/ladderlog.txt, or run LADDERLOG_WRITE in the server console to see a little documentation about the format of events.

compguygene: any language will work. Scripts only need to read stdin and write commands to stdout.
h4zard
On Lightcycle Grid
Posts: 22
Joined: Thu Mar 22, 2012 7:01 am

Re: Using perl for scripting

Post by h4zard »

ahh thanks dlh that makes sense as to why its not working I don't have anything writing to ladderlog ;p

EDIT: hmm well it still doesn't seem to be working I've set --vardir /h4z/.tronlogs/ so that it would output ladderlog.txt there but can't seem to get anything. ;(
h4zard
On Lightcycle Grid
Posts: 22
Joined: Thu Mar 22, 2012 7:01 am

Re: Using perl for scripting

Post by h4zard »

I've enabled LADDERLOG_WRITE_ALL 1, with SPAWN_SCRIPT my-script.pl but arma doesn't seem to be passing ladderlog.txt to it, I've verified that my script works by running tail -f ~/.tron-logs/ladderlog.txt | /usr/share/armagetronad/scripts/my-script.pl, so it works it just appears that arma isn't passing ladderlog to it. maybe I compiled arma wrong ? I compiled with --enable-respawn --enable-armathentication --prefix=/usr/local did I miss a flag ? I'm running arma with --configdir /usr/local/etc/games/armagetronad --vardir ~/.tron-logs/ --datadir /usr/share/armagetronad/.
User avatar
compguygene
Adjust Outside Corner Grinder
Posts: 2346
Joined: Thu Aug 21, 2008 12:09 pm
Location: Cleveland, Ohio
Contact:

Re: Using perl for scripting

Post by compguygene »

dlh wrote:Scripts launched with SPAWN_SCRIPT are fed ladderlog as input, not the output from the server console. Take a look at var/ladderlog.txt, or run LADDERLOG_WRITE in the server console to see a little documentation about the format of events.

compguygene: any language will work. Scripts only need to read stdin and write commands to stdout.
I must have been rather tired when I made my post. I think I was confusing the new trunk scripting branch that Voodoo has been working on with normal scripting.
Armagetron: It's a video game that people should just play and enjoy :)
https://bit.ly/2KBGYjvCheck out the simple site about TheServerPharm
h4zard
On Lightcycle Grid
Posts: 22
Joined: Thu Mar 22, 2012 7:01 am

Re: Using perl for scripting

Post by h4zard »

anyone ^^ know what my problem is ? I've done everything that I believe is necessary to make it work, the script works fine if I cat ladderlog to it or manually so that part works, arma just isn't feeding my script ladderlog, so unless I missed a compile script or a flag I'm clueless.
h4zard
On Lightcycle Grid
Posts: 22
Joined: Thu Mar 22, 2012 7:01 am

Re: Using perl for scripting

Post by h4zard »

Figured this shit out now:

a working script.

Code: Select all

#!/usr/bin/perl
my $sihtty_var="CONSOLE_MESSAGE 0x00ffffSOME FRIGGIN TEXT\n";
system("echo CONSOLE_MESSAGE 0xff0000THIS SIHT WORKS!!!\n");
system("echo $sihtty_var");
A better working script with regex:

Code: Select all

#!/usr/bin/perl
while(1){
my $input =<STDIN>;
if($input =~ /\s*/Ihatepipes\s*/){
system("echo CONSOLE_MESSAGE 0xffff00I Hate PIPES TOO\n");
}
}
User avatar
dlh
Formerly That OS X Guy
Posts: 2035
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Re: Using perl for scripting

Post by dlh »

Using system() is a bad idea. You probably only need to flush STDOUT.

In python, for example (sorry, I don't perl):

Code: Select all

print "SAY hello"
sys.stdout.flush()
Post Reply