mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-14 08:01:38 +01:00
allow to run multiple games at once
This commit is contained in:
parent
a3305e2ca9
commit
aa1161cbaf
1 changed files with 33 additions and 23 deletions
|
@ -6,11 +6,12 @@ use strict;
|
||||||
|
|
||||||
my $xwdir = "../linux/linux";
|
my $xwdir = "../linux/linux";
|
||||||
|
|
||||||
my $cookie = "COOKIE";
|
my @cookies = ( "COOKIE" );
|
||||||
my $nPlayers = 2;
|
my $nPlayers = 2;
|
||||||
my $port = 10999;
|
my $port = 10999;
|
||||||
my $dict = "~/personal/dicts/SOWPODS2to15.xwd";
|
my $dict = "~/personal/dicts/SOWPODS2to15.xwd";
|
||||||
my $quit = "";
|
my $quit = "";
|
||||||
|
my $gettingCookies = 0;
|
||||||
|
|
||||||
my @names = (
|
my @names = (
|
||||||
"Fred",
|
"Fred",
|
||||||
|
@ -23,7 +24,8 @@ while ( my $param = shift( @ARGV ) ) {
|
||||||
print STDERR "param $param\n";
|
print STDERR "param $param\n";
|
||||||
|
|
||||||
if ( $param =~ m|-C| ) {
|
if ( $param =~ m|-C| ) {
|
||||||
$cookie = shift( @ARGV );
|
$cookies[0] = shift( @ARGV );
|
||||||
|
$gettingCookies = 1;
|
||||||
next;
|
next;
|
||||||
} elsif ( $param =~ m|-nplayers| ) {
|
} elsif ( $param =~ m|-nplayers| ) {
|
||||||
$nPlayers = shift( @ARGV );
|
$nPlayers = shift( @ARGV );
|
||||||
|
@ -33,36 +35,44 @@ while ( my $param = shift( @ARGV ) ) {
|
||||||
$port = shift( @ARGV );
|
$port = shift( @ARGV );
|
||||||
} elsif ( $param =~ m|-quit| ) {
|
} elsif ( $param =~ m|-quit| ) {
|
||||||
$quit = " -q ";
|
$quit = " -q ";
|
||||||
|
} elsif ( $gettingCookies ) {
|
||||||
|
push @cookies, $param;
|
||||||
|
next;
|
||||||
} else {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
$gettingCookies = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $cmdBase = "cd $xwdir && ./xwords -d $dict -C $cookie $quit -p $port";
|
foreach my $cookie (@cookies) {
|
||||||
|
|
||||||
for ( my $p = 0; $p < $nPlayers; ++$p ) {
|
my $cmdBase = "cd $xwdir && ./xwords -d $dict -C $cookie $quit -p $port";
|
||||||
print STDERR "p = $p\n";
|
print "$cmdBase\n";
|
||||||
my $cmd = $cmdBase;
|
|
||||||
if ( $p == 0 ) { # server case
|
for ( my $p = 0; $p < $nPlayers; ++$p ) {
|
||||||
$cmd .= " -s ";
|
print STDERR "p = $p\n";
|
||||||
|
my $cmd = $cmdBase;
|
||||||
for ( my $i = 1; $i < $nPlayers; ++$i ) {
|
if ( $p == 0 ) { # server case
|
||||||
$cmd .= " -N ";
|
$cmd .= " -s ";
|
||||||
|
|
||||||
|
for ( my $i = 1; $i < $nPlayers; ++$i ) {
|
||||||
|
$cmd .= " -N ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
$cmd .= " -r $names[$p]";
|
||||||
$cmd .= " -r $names[$p]";
|
|
||||||
|
|
||||||
my $pid = fork;
|
my $pid = fork;
|
||||||
print STDERR "fork => $pid.\n";
|
print STDERR "fork => $pid.\n";
|
||||||
if ( $pid ) {
|
if ( $pid ) {
|
||||||
# parent; give child chance to get ahead
|
# parent; give child chance to get ahead
|
||||||
sleep 1;
|
# sleep 1;
|
||||||
} else {
|
} else {
|
||||||
exec "$cmd";
|
exec "$cmd 2>/dev/null &";
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub usage()
|
sub usage()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue