Running a Server

From Tronwiki
(Difference between revisions)
Jump to: navigation, search
(Random Flying Deathzones)
Line 40: Line 40:
 
  while (1)  {
 
  while (1)  {
 
     $line = rtrim(fgets(STDIN, 1024));
 
     $line = rtrim(fgets(STDIN, 1024));
// watch the game time to update settings based on time
+
    // watch the game time to update settings based on time
if (preg_match("/^GAME_TIME/", $line)){
+
    if (preg_match("/^GAME_TIME/", $line)){
    $keywords = preg_split("/ /", $line);
+
$keywords = preg_split("/ /", $line);
    $game_time=$keywords[1];
+
$game_time=$keywords[1];
    if ( $game_time % 10 == 0 ){
+
if ( $game_time % 10 == 0 ){
          $mincoord=225;
+
    $mincoord=225;
    $maxcoord=275;
+
    $maxcoord=275;
    $minsize=2;
+
    $minsize=2;
    $maxsize=8;
+
    $maxsize=8;
    $minspeed=1;
+
    $minspeed=1;
    $maxspeed=30;
+
    $maxspeed=30;
    $xcoord=rand($mincoord, $maxcoord);
+
    $xcoord=rand($mincoord, $maxcoord);
    $ycoord=rand($mincoord, $maxcoord);
+
    $ycoord=rand($mincoord, $maxcoord);
    $size=rand($minsize, $maxsize);
+
            $size=rand($minsize, $maxsize);
    $xspeed=rand($minspeed, $maxspeed);
+
    $xspeed=rand($minspeed, $maxspeed);
    $yspeed=rand($minspeed, $maxspeed);
+
    $yspeed=rand($minspeed, $maxspeed);
    $ycoord2=($ycoord>250)?(250-($ycoord-250)):(250+(250-$ycoord));
+
    $ycoord2=($ycoord>250)?(250-($ycoord-250)):(250+(250-$ycoord));
    $xcoord2=($xcoord>250)?(250-($xcoord-250)):(250+(250-$xcoord));
+
    $xcoord2=($xcoord>250)?(250-($xcoord-250)):(250+(250-$xcoord));
    if ( $game_time%20==0 ) {
+
    if ( $game_time%20==0 ) {
      print("spawn_zone death $xcoord $ycoord $size 0 $xspeed $yspeed true\n");
+
        print("spawn_zone death $xcoord $ycoord $size 0 $xspeed $yspeed true\n");
    print("spawn_zone death $xcoord2 $ycoord2 $size 0 -$xspeed -$yspeed true\n");
+
print("spawn_zone death $xcoord2 $ycoord2 $size 0 -$xspeed -$yspeed true\n");
    } else {
+
    } else {
          print("spawn_zone death $xcoord $ycoord $size 0 -$xspeed $yspeed true\n");
+
        print("spawn_zone death $xcoord $ycoord $size 0 -$xspeed $yspeed true\n");
        print("spawn_zone death $xcoord2 $ycoord2 $size 0 $xspeed -$yspeed true\n");
+
        print("spawn_zone death $xcoord2 $ycoord2 $size 0 $xspeed -$yspeed true\n");
        }
+
    }
      }
+
}
 
     }
 
     }
 
  }
 
  }
 
  ?>
 
  ?>
 
  </nowiki>
 
  </nowiki>

Revision as of 11:54, 3 October 2007

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 a Scripted Server in one screen session

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:

#!/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"
edlog="${var}edlog.txt"

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

Running a Scripted Server on 2 screen sessions for more flexibility

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

tail -f -n0 -s 0.01 /path/to/edlog.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"
edlog="${var}edlog.txt"
cmds="${var}cmds.txt"
tail -n0 -f -s 0.01 $cmds | $tron --userconfigdir $userconfigdir --vardir $var | tee -a $log

The Scripts

Random Flying Deathzones

 #!/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");
	     }
 	 }
     }
 }
 ?>
 
Personal tools