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);
}
}