Changing settings on the fly using a script.

Post here if you need help setting up your server, etc.
Post Reply
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Changing settings on the fly using a script.

Post by ed »

There was a server some time ago, I forget its name. Instead of a deathzone putting an end to a looong round, you get a warning, then the cycles would speed up to a terrifying pace and the guy who could survive this would win.
Not exactly what I want, but this kind of control would be great. Watch for the start of the round, after a certain time, throw some interesting new settings at people. Seperate the men from the boys. Not just find the furthest corner and try to survive.
I'm assuming the server admin had a script running that would somehow write to the armagetronad-dedicated that was running.
But I can't work out how to do this, where to write it to. Maybe I'm barking up the wrong tree.

I run CT server's within a screen session using the startup script similar to this:
#!/bin/sh

tron="/home/ed/ctf3/bin/armagetronad-dedicated"
log="/home/ed/wild/log/wildlog.txt"
var="/home/ed/wild/var"
config="/home/ed/wild/config"
autoresourcedir="/home/ed/resource"

$tron --configdir $config --vardir $var --autoresourcedir $autoresourcedir | tee -a $log
And I'm able to type commands at this.
cycle_speed 100 etc works. But how can I get a script to do this?

This is probably a screen question more than anything. But any tips would be helpful.
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

Code: Select all

echo '' > $tmpfile
tail -f $tmpfile | $tron $opts | tee -a $log
$scriptThatWritesCommandsToStdout > $tmpfile
Alternatively:

Code: Select all

rm $tmpfile
mkfifo $tmpfile
$tron $opts <$tmpfile | tee -a $log
$scriptThatWritesCommandsToStdout > $tmpfile
There's no place like ::1
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

Thanks wrtl, you the man.
That 1st one worked a treat (didn't try the 2nd). To think, the hours i spent trying to direct text into a detached screen :x
Expect another crazy tron server soon.
User avatar
Sylv
On Lightcycle Grid
Posts: 39
Joined: Sun Sep 05, 2004 4:16 pm

Post by Sylv »

you can download the original "sudden-death" skript here : http://armagetron.cybertrench.com/

(http://armagetron.cybertrench.com/scripts/2.0/)
Image
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

I can't do it.
Programming makes my brain turn to slime.

I've made a brand new server. Currently called "ed's highly experimental mayhem" or something.
It's a non team, 8 player max place with rotating maps.
I've completely rewritten the map rotation script, all settings, including axes, are read from mysql and written to everytime.cfg.
That part of it works just dandy.
Oh, and as you enter, the server barks a random insult at you from a file containg insults. Needed to test the running config was working. It is.

Can't figure out how to set a timer going.
Wait for n seconds of inactivety, then throw map stage2 settings at the server.

Here's my script so far. No "bad programming" jokes.

Code: Select all

#!/usr/bin/perl -w
use File::Tail;
use DBI;

$dsn = 'dbi:mysql:ct_forum:localhost:3306';
$user = 'mysql_user';
$pass = 'mysql_pass';

$logfile="/home/ed/mayhem/log/mayhemlog.txt";
#$scorefile="/home/ed/mayhem/var/scorelog.txt";
$everytime="/home/ed/mayhem/config/everytime.cfg";
$running_config="/home/ed/mayhem/config/running_config";
$num_rounds="8";
$map_table="phpbb_maps";
$map_settings_table="phpbb_maps_settings";
$server="mayhem";

#open logfile for reading
$file=File::Tail->new(name=>"$logfile", maxinterval=>1);
while (defined($line=$file->read)) 
{
   	chomp $line;
	print "$line\n";
	if (substr($line,0,13) eq "[0] Go (round")
	{	
		# output log file to screen
	        print "$line";
		print "It's Start of a new Round\n";
		
		# remove trailing spaces from the round number.
		($curr_round = substr($line,14,2)) =~ s/\s+$//;
		if ($curr_round == $num_rounds)
		{
			$next_round=1;
		}
		else
		{
			$next_round=$curr_round+1;
		}

		print "This is Round $curr_round Next Round is $next_round\n";
		print "Possible Maps:\n";
				
		$dbh = DBI->connect($dsn, $user, $pass) or die "Can't connect to the DB: $DBI::errstr\n";
		$sth = $dbh->prepare("select mapfile,map_version,map_loc,mapname from $map_table where round =$next_round and server=\"$server\"");
		$sth->execute;
	
		#find the number of maps available for the round and choose one at random
		$num_records=$sth->rows;
		$rand = int(rand($num_records));
		
		$i=0;
		while(@row = $sth->fetchrow_array())
		{
			$map[$i]=$row[0];
			$map_version[$i] = "$row[1]";
			$map_loc[$i] = "$row[2]";
			$map_name[$i] = "$row[3]";
			$i++;
		}
		$sth->finish;			
		
		# open everytime.cfg and write center message and map to it.
	        open (EVERY, ">$everytime");
                print EVERY "MAP_FILE ${map_loc[$rand]}$map[$rand]-${map_version[$rand]}\n";
		if ( $next_round == $num_rounds )
		{
			print EVERY "ROUND_CENTER_MESSAGE Final Round - $map_name[$rand]\n";
		}
		else
		{
			print EVERY "ROUND_CENTER_MESSAGE Round $next_round - $map_name[$rand]\n";
		}

		# write all default settings to everytime.cfg
		$sth = $dbh->prepare("select setting_name, setting_value from $map_settings_table where map_name=\"${server}_default\"");
		$sth->execute;
		while (@data = $sth->fetchrow_array()) 
		{
			#print "$data[0] $data[1]\n";
			print EVERY "$data[0] $data[1]\n";
		}
		$sth->finish;			
		
		# write map specific settings to everytime.cfg
		$sth = $dbh->prepare("select setting_name, setting_value from $map_settings_table where map_name=\"$map[$rand]\" and stage=1");
		$sth->execute;
		while (@data = $sth->fetchrow_array()) 
		{
			#print "$data[0] $data[1]\n";
			print EVERY "$data[0] $data[1]\n";
		}
		$sth->finish;
	
		close (EVERY);
		$dbh->disconnect;
		
		#$score=File::Tail->new(name=>"$scorefile", maxinterval=>1);
		#while (defined($score_line=$score->read))
		#{
		#	chomp $score_line;
		#        print "scorelog: $score_line\n";
		#        if (substr($score_line,0,6) eq "Winner")
		#        {
		#	        last;
		#	}
		#}
	}
	if ($line =~ /entered/ and $line !~ ":")
	{
		
		open ( INSULT, "/home/ed/mayhem/var/insults");
		#srand;
		#rand($.) < 1 && ($insult = $_) while <INSULT>;
		$insult_num=0;
		foreach $insult(<INSULT>)
		{
			chomp($insult);
			$insult[$insult_num]=$insult;
			$insult_num++;
		}
		$rand_insult_num = int(rand($insult_num));
		
		($name = substr($line, 4, 40)) =~ s/ entered.*//;
		#$name = s/ entered.*//'
		#print "hello $name\n";
		open (RUNNING, ">>$running_config");
		print RUNNING "CONSOLE_MESSAGE 0xe9fd06Welcome $name, $insult[$rand_insult_num]\n";
		close (RUNNING);
		
	}
	
}
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

This is driving me nuts.
All I want are 2 things in the log...

1. A message to tell me Round Start. So I can start my timer.
True round start, not Round 1 of 8, as someone could chat for a few seconds, so this is not accurate.
Nor is "New Round" in scorelog.txt.
Not 3, 2, 1, as this won't get written to the log file unless it is pushed through by another log message (watch the logs).

2. A message to tell me Round End. So I can stop my timer.
Not "Winner:" as there is not always a winner.
Not a scan of the players.txt looking for no "Yes" within. As the players.txt ain't accurate. If a player joins the server mid/end round, players.txt won't get written to for a while.

My set up currently is watch the logfile for "[0] Round ", if I see that throw bollocks at the tron server (echo "bollocks" >> $tron) until I see "[0] 1" then I know the round has started. Even then it's not precise.

And I have no way of knowing for sure the round is over.

I'm running it on 0.3
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

Should be easy to do, if noone minds I'll commit it to the trunk and provide a patch for 0.3.0 (as the trunk contains ph's incomplete zone model which has different and incomplete ways to specify zones).
There's no place like ::1
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

That would be good.
You could time all sorts of strange things to happen at specified times.
ie. on sumo, after 30 seconds, when the zones are a lot smaller, nano style settings can be thrown at it - hello nano sumo. if players are still alive after 1 minute when the zones have vanished, bring on the deathzone and speed boost.
It would need to be fairly accurate to work.
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

I checked the start message (playing on a server and watching its console at the same time), and the “[0] 0” gets printed immediately as the round starts, even if noone's chatting.

I added the round message to the 0.3.0 branch, you need to do something like

Code: Select all

svn co https://svn.sourceforge.net/svnroot/armagetronad/armagetronad/branches/0.3.0/armagetronad
cd armagetronad
./bootstrap.sh
#now run ./configure and whatever you'd do normally
to get it.
There's no place like ::1
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

wrtlprnft wrote:I checked the start message (playing on a server and watching its console at the same time), and the “[0] 0” gets printed immediately as the round starts, even if noone's chatting.
Doesn't on mine. Try it with startup script similar to:

Code: Select all

#!/bin/sh

tron="/home/ed/ctf4/bin/armagetronad-dedicated"
log="/home/ed/wild/log/wildlog.txt"
var="/home/ed/wild/var"
config="/home/ed/wild/config"
autoresourcedir="/home/ed/resource"

$tron --configdir $config --vardir $var --autoresourcedir $autoresourcedir | tee -a $log
It will only only print [0] 3 - [0] 0 when pushed through.
I will try it without tee, maybe that's causing it.
Thanks for the mods, I will try it when I have time.
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

Just tried it with “make run | tee -a /dev/null”, and indeed it has a delay until it prints the “[0] 0”. Probably tee has some kind of buffer that needs to be filled…
There's no place like ::1
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

Thanks wrtl, your mods fixed the no winner scenario.

I'm still having a problem with the
[0] 3
[0] 2
[0] 1
[0] 0
not working. The log is just totally out of sync with the actual game.
It is not a problem with tee either. I've tried running

Code: Select all

$tron --configdir $config --vardir $var --autoresourcedir $autoresourcedir >> $log
and doing a simple tail -n1 -f $log.
but the whole:
[0] 3
[0] 2
[0] 1
[0] 0
won't be sent to the log till another line is sent to the log, then in filters through. Often when the round end, if there's 2 people playing and no one talks.

Only if I run the server with:

Code: Select all

$tron --configdir $config --vardir $var --autoresourcedir $autoresourcedir
Where there is no log written will it output to the screen
[0] 3
[0] 2
[0] 1
[0] 0
In sync with the game that is being played. But this is no good to me, as I use the log for my map rotation/insulting/on the fly setting changing.
Maybe there's a different way I can run it?
Or maybe point me to which src file the 3,2,1,0 part is and I can have a go a modifying this.
User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

I don't know, it seems to be a bash problem.
Anyways, the outputting of “[0] 0” is done in gGame.cpp:

Code: Select all

        if (cd>=0 && cd<PREPARE_TIME && cd!=lastcountdown && se_mainGameTimer && se_mainGameTimer->IsSynced() ){
            lastcountdown=cd;
            tString s;
            s << cd;

            switch(cd) {
            case 3:
                m_Mixer->PushButton(ANNOUNCER_3);
                break;
            case 2:
                m_Mixer->PushButton(ANNOUNCER_2);
                break;
            case 1:
                m_Mixer->PushButton(ANNOUNCER_1);
                break;
            case 0:
                m_Mixer->PushButton(ANNOUNCER_GO);
                break;
            }
            con.CenterDisplay(s,0);
        }
The second-last line is the one that actually outputs it. You can add a big

Code: Select all

                con << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                       "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                       "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                       "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n";
to the “0” case if you wanna be sure the cache is flushed.
There's no place like ::1
User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

thanks again.
I added line:

Code: Select all

con << "The Round Has Begun. Let's Rock!\n";
The log now reads:

Code: Select all

[0] Go (round 2 of 8 )!
[0] 3
[0] The Round Has Begun. Let's Rock!
[0] 2
[0] The Round Has Begun. Let's Rock!
[0] 1
[0] The Round Has Begun. Let's Rock!
[0] 0
[0] The Round Has Begun. Let's Rock!
In sync with the start of the round.
Strange things will be happening on my server soon.
Post Reply