Running a Server

From Tronwiki
(Difference between revisions)
Jump to: navigation, search
(All on one screen session)
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
How to use all these new features on a server. Scripts.
 
How to use all these new features on a server. Scripts.
 
Php is the language used by most, but bash, perl, python, anything that can read text from standard input and write to a text file should work.
 
Php is the language used by most, but bash, perl, python, anything that can read text from standard input and write to a text file should work.
 
+
= Running the scripted server =
To start the server, which will read the file edlog.txt, feed that into the parser script, then write the output of that into arma server, which will use tee to display the console log, use something like this shell script:  
+
== All on one screen session ==
 +
To start the server, which will read the all important file [[ladderlog|ladderlog.txt]], feed that into the parser script, then write the output of that into arma server, which will use tee to display the console log, use something like this shell script:  
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 10: Line 11:
 
  userconfigdir="/path/to/config/"
 
  userconfigdir="/path/to/config/"
 
  parser="/path/to/parser.php"
 
  parser="/path/to/parser.php"
  edlog="${var}edlog.txt"
+
  ladderlog="${var}ladderlog.txt"
+
 
  tail -n0 -f -s 0.01 $edlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log
+
  tail -n0 -f -s 0.01 $ladderlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log
  
Alternativey, for debugging, you might want to write the cmds to a seperate text file for reading. This allows you to modify the parser as the server is running and restart it.
+
== On two screen sessions for more flexibility ==
 +
Alternatively, for debugging, you might want to write the cmds to a separate text file for reading. This allows you to modify and restart the parser as the server is running.
  
  tail -f -n0 -s0.1 /path/to/edlog.txt | /path/to/parser.php | tee -a /path/to/cmds.txt
+
  tail -f -n0 -s 0.01 /path/to/ladderlog.txt | /path/to/parser.php | tee -a /path/to/cmds.txt
  
Then run the server with:
+
Then run the server on a separate screen session with:
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 26: Line 28:
 
  userconfigdir="/path/to/config/"
 
  userconfigdir="/path/to/config/"
 
  parser="/path/to/parser.php"
 
  parser="/path/to/parser.php"
  edlog="${var}edlog.txt"
+
  ladderlog="${var}ladderlog.txt"
 
  cmds="${var}cmds.txt"
 
  cmds="${var}cmds.txt"
 
+
 
  tail -n0 -f -s 0.01 $cmds | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log
 
  tail -n0 -f -s 0.01 $cmds | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log
 +
 +
=Sample Scripts=
 +
==Random Flying Deathzones==
 +
A server that sends 2 deathzones of random size and speed in opposite directions at alternating corners every 10 seconds.
 +
<nowiki>
 +
#!/usr/bin/php
 +
<?php
 +
while (1)  {
 +
    $line = rtrim(fgets(STDIN, 1024));
 +
    // watch the game time to update settings based on time
 +
    if ( preg_match( "/^GAME_TIME/", $line ) ){
 +
        $keywords = preg_split("/ /", $line);
 +
$game_time=$keywords[1];
 +
if ( $game_time % 10 == 0 ){
 +
            $mincoord=225;
 +
            $maxcoord=275;
 +
            $minsize=2;
 +
            $maxsize=8;
 +
            $minspeed=1;
 +
            $maxspeed=30;
 +
            $xcoord=rand($mincoord, $maxcoord);
 +
            $ycoord=rand($mincoord, $maxcoord);
 +
            $size=rand($minsize, $maxsize);
 +
            $xspeed=rand($minspeed, $maxspeed);
 +
            $yspeed=rand($minspeed, $maxspeed);
 +
            $ycoord2=($ycoord>250)?(250-($ycoord-250)):(250+(250-$ycoord));
 +
            $xcoord2=($xcoord>250)?(250-($xcoord-250)):(250+(250-$xcoord));
 +
            if ( $game_time%20==0 ) {
 +
                print("spawn_zone death $xcoord $ycoord $size 0 $xspeed $yspeed true\n");
 +
        print("spawn_zone death $xcoord2 $ycoord2 $size 0 -$xspeed -$yspeed true\n");
 +
            } else {
 +
                print("spawn_zone death $xcoord $ycoord $size 0 -$xspeed $yspeed true\n");
 +
                print("spawn_zone death $xcoord2 $ycoord2 $size 0 $xspeed -$yspeed true\n");
 +
            }
 +
}
 +
    }
 +
}
 +
?></nowiki>
 +
 +
==Alternating Death Pulses==
 +
Create a grid of deathzone markers, then have them alternatively pules with death, gradually getting larger every 7 seconds.
 +
<nowiki>#!/usr/bin/php
 +
<?php
 +
while (1)  {
 +
    $line = rtrim(fgets(STDIN, 1024));
 +
    // watch the game time to update settings based on time
 +
    if (preg_match("/^GAME_TIME/", $line)){
 +
        $keywords = preg_split("/ /", $line);
 +
        $game_time=$keywords[1];
 +
        if ( $game_time == 0 ){
 +
            for ( $i=0; $i<=500; $i+=50 )
 +
                for ( $j=0; $j<=500; $j+=50 )
 +
                    print("spawn_zone death $i $j 1 0\n");
 +
        } else if ( $game_time % 14 == 0 ){
 +
            for ( $i=0; $i<=500; $i+=100 ){
 +
                for ( $j=0; $j<=500; $j+=100 ){
 +
                    print("spawn_zone death $i $j " . $game_time/2 . " -" . $game_time/5 . "\n");
 +
                    usleep(20000);
 +
                }
 +
            }
 +
        } else if ( $game_time % 7 == 0 ) {
 +
            for ( $i=50; $i<=450; $i+=100 ){
 +
                for ( $j=50; $j<=450; $j+=100 ){
 +
                    print("spawn_zone death $i $j " . $game_time/2 . " -" . $game_time/5 . "\n");
 +
                    usleep(20000);
 +
                }
 +
            }
 +
        }
 +
    }
 +
}
 +
?>
 +
</nowiki>
 +
==Zombies Attack==
 +
Create a grid of Zombies following every player.
 +
<nowiki>#!/usr/bin/php
 +
<?php
 +
while (1)  {
 +
    $line = rtrim(fgets(STDIN, 1024));
 +
    // watch the game time to update settings based on time
 +
    if (preg_match("/^GAME_TIME/", $line)){
 +
      $keywords = preg_split("/ /", $line);
 +
      $game_time=floor($keywords[1]);
 +
      if ( $game_time == -1 ) {
 +
          if ($current_map=="loopy_passages") {
 +
      print($zombie_spawn);
 +
      }
 +
      $zombie_spawn=""; 
 +
      }
 +
  }
 +
 +
if (preg_match("/^ONLINE_PLAYER/", $line)){
 +
        $keywords = preg_split("/ /", $line);
 +
            //make sure the player is playing
 +
      if(sizeof($keywords)==7){
 +
          //SPAWN_ZONE zombie <player> <x> <y> <size> <growth> <xdir> <ydir> <interactive> <r> <g> <b> <target_size>
 +
        $zombie_spawn.="SPAWN_ZONE zombie ".$keywords[1]." 1<x> <y> <size> <growth> <xdir> <ydir> 1 15 00 00 <target_size>\n";
 +
      }
 +
    }
 +
}
 +
?>
 +
</nowiki>

Latest revision as of 18:13, 15 April 2009

How to use all these new features on a server. Scripts. Php is the language used by most, but bash, perl, python, anything that can read text from standard input and write to a text file should work.

Contents

Running the scripted server

All on one screen session

To start the server, which will read the all important file ladderlog.txt, feed that into the parser script, then write the output of that into arma server, which will use tee to display the console log, use something like this shell script:

#!/bin/sh
tron="/path/to/bin/armagetronad-dedicated"
var="/path/to/var/"
log="${var}console_log.txt"
userconfigdir="/path/to/config/"
parser="/path/to/parser.php"
ladderlog="${var}ladderlog.txt"
 
tail -n0 -f -s 0.01 $ladderlog | $parser | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log

On two screen sessions for more flexibility

Alternatively, for debugging, you might want to write the cmds to a separate text file for reading. This allows you to modify and restart the parser as the server is running.

tail -f -n0 -s 0.01 /path/to/ladderlog.txt | /path/to/parser.php | tee -a /path/to/cmds.txt

Then run the server on a separate screen session with:

#!/bin/sh
tron="/path/to/bin/armagetronad-dedicated"
var="/path/to/var/"
log="${var}console_log.txt"
userconfigdir="/path/to/config/"
parser="/path/to/parser.php"
ladderlog="${var}ladderlog.txt"
cmds="${var}cmds.txt"

tail -n0 -f -s 0.01 $cmds | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log

Sample Scripts

Random Flying Deathzones

A server that sends 2 deathzones of random size and speed in opposite directions at alternating corners every 10 seconds.

#!/usr/bin/php
<?php
while (1)  {
    $line = rtrim(fgets(STDIN, 1024));
    // watch the game time to update settings based on time
    if ( preg_match( "/^GAME_TIME/", $line ) ){
        $keywords = preg_split("/ /", $line);
	$game_time=$keywords[1];
	if ( $game_time % 10 == 0 ){
            $mincoord=225;
            $maxcoord=275;
            $minsize=2;
            $maxsize=8;
            $minspeed=1;
            $maxspeed=30;
            $xcoord=rand($mincoord, $maxcoord);
            $ycoord=rand($mincoord, $maxcoord);
            $size=rand($minsize, $maxsize);
            $xspeed=rand($minspeed, $maxspeed);
            $yspeed=rand($minspeed, $maxspeed);
            $ycoord2=($ycoord>250)?(250-($ycoord-250)):(250+(250-$ycoord));
            $xcoord2=($xcoord>250)?(250-($xcoord-250)):(250+(250-$xcoord));
            if ( $game_time%20==0 ) {
                print("spawn_zone death $xcoord $ycoord $size 0 $xspeed $yspeed true\n");
 	        print("spawn_zone death $xcoord2 $ycoord2 $size 0 -$xspeed -$yspeed true\n");
            } else {
                print("spawn_zone death $xcoord $ycoord $size 0 -$xspeed $yspeed true\n");
                print("spawn_zone death $xcoord2 $ycoord2 $size 0 $xspeed -$yspeed true\n");
            }
	}
    }
}
?>

Alternating Death Pulses

Create a grid of deathzone markers, then have them alternatively pules with death, gradually getting larger every 7 seconds.

#!/usr/bin/php
<?php
while (1)  {
    $line = rtrim(fgets(STDIN, 1024));
    // watch the game time to update settings based on time
    if (preg_match("/^GAME_TIME/", $line)){
        $keywords = preg_split("/ /", $line);
        $game_time=$keywords[1];
        if ( $game_time == 0 ){
            for ( $i=0; $i<=500; $i+=50 )
                for ( $j=0; $j<=500; $j+=50 )
                    print("spawn_zone death $i $j 1 0\n");
        } else if ( $game_time % 14 == 0 ){
            for ( $i=0; $i<=500; $i+=100 ){
                for ( $j=0; $j<=500; $j+=100 ){
                    print("spawn_zone death $i $j " . $game_time/2 . " -" . $game_time/5 . "\n");
                    usleep(20000);
                }
            }
        } else if ( $game_time % 7 == 0 ) {
            for ( $i=50; $i<=450; $i+=100 ){
                for ( $j=50; $j<=450; $j+=100 ){
                    print("spawn_zone death $i $j " . $game_time/2 . " -" . $game_time/5 . "\n");
                    usleep(20000);
                }
            }
        }
    }
}
?>

Zombies Attack

Create a grid of Zombies following every player.

#!/usr/bin/php
<?php
while (1)  {
    $line = rtrim(fgets(STDIN, 1024));
    // watch the game time to update settings based on time
    if (preg_match("/^GAME_TIME/", $line)){
      $keywords = preg_split("/ /", $line);
      $game_time=floor($keywords[1]);
      if ( $game_time == -1 ) {
          if ($current_map=="loopy_passages") {
      print($zombie_spawn);
      }
      $zombie_spawn="";   
      }
   }

if (preg_match("/^ONLINE_PLAYER/", $line)){
        $keywords = preg_split("/ /", $line);
            //make sure the player is playing
       if(sizeof($keywords)==7){
          //SPAWN_ZONE zombie <player> <x> <y> <size> <growth> <xdir> <ydir> <interactive> <r> <g> <b> <target_size>
        $zombie_spawn.="SPAWN_ZONE zombie ".$keywords[1]." 1<x> <y> <size> <growth> <xdir> <ydir> 1 15 00 00 <target_size>\n";
      }
    }
}
?>

Personal tools