version 1.3, 2010/01/11 05:02:27
|
version 1.5, 2010/12/13 05:54:50
|
Line 34 use threads::shared;
|
Line 34 use threads::shared;
|
## |
## |
my %opts = &fetchOptions( ); |
my %opts = &fetchOptions( ); |
my $pidFile = "/var/run/telnetbbs.pid"; |
my $pidFile = "/var/run/telnetbbs.pid"; |
my @nodes = ( ); |
|
my $EOL = "\015\012"; |
my $EOL = "\015\012"; |
|
|
## |
## |
## These will be moved in to a config file |
## These will be moved in to a config file |
## |
## |
my $DISPLAY = ":1018.0"; |
my $DISPLAY = ":0.0"; |
my $BBS_NAME = "Hell's Dominion BBS"; |
my $BBS_NAME = "Hell's Dominion BBS"; |
my $BBS_NODE = 0; |
my $BBS_NODE = 0; |
my $DBCONF = "/tmp/dosbox-__NODE__.conf"; |
my $DBCONF = "/tmp/dosbox-__NODE__.conf"; |
my $BBS_CMD = "DISPLAY=$DISPLAY /usr/bin/dosbox -conf "; |
my $BBS_CMD = "DISPLAY=$DISPLAY /usr/bin/dosbox -conf "; |
my $LOG = "/var/log/bbs.log"; |
my $LOG = "/var/log/bbs.log"; |
my $MAX_NODE = 6; |
my $MAX_NODE = 1; |
my $DOSBOXT = "dosbox.conf.template"; |
my $DOSBOXT = "dosbox.conf.template"; |
my $BASE_PORT = 5000; |
my $BASE_PORT = 7000; |
|
my $LOCK_PATH = "/tmp"; |
|
|
## |
## |
## Check that we are 'root' |
## Check that we are 'root' |
Line 81 local $SIG{HUP} = $SIG{INT} = $SIG{TERM
|
Line 81 local $SIG{HUP} = $SIG{INT} = $SIG{TERM
|
## |
## |
## Start the network server |
## Start the network server |
## |
## |
my $netThread = threads->create( \&startNetServer ); |
my $netThread = threads->create( \&startNetServer( ) ); |
|
|
|
|
while( 1 ) { sleep 1; } |
while( 1 ) { sleep 1; } |
|
|
Line 98 while( 1 ) { sleep 1; }
|
Line 99 while( 1 ) { sleep 1; }
|
############################################################################### |
############################################################################### |
############################################################################### |
############################################################################### |
|
|
sub logmsg { print "$0 $$ ", scalar localtime, ":@_\n" } |
sub logmsg { print STDOUT "$0 $$ ", scalar localtime, ":@_\n" } |
|
|
############################################################################### |
############################################################################### |
## startNetServer( ); |
## startNetServer( ); |
Line 111 sub startNetServer
|
Line 112 sub startNetServer
|
{ |
{ |
my $hostConnection; |
my $hostConnection; |
my $childPID; |
my $childPID; |
my $port = $opts{'port'} || 23; |
my $port = $opts{'port'} || 23; |
|
my @nodes = ( ); |
|
|
my $server = IO::Socket::INET->new( |
my $server = IO::Socket::INET->new( |
LocalPort => $port, |
LocalPort => $port, |
Line 133 sub startNetServer
|
Line 135 sub startNetServer
|
## Find the next available node |
## Find the next available node |
## |
## |
my $node = 0; |
my $node = 0; |
|
my $lock_file = ""; |
foreach (1 .. $MAX_NODE) |
foreach (1 .. $MAX_NODE) |
{ |
{ |
next if ( $node ); |
print "Searching for lock: " . $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock\n"; |
if ( ! $nodes[$_] ) |
next if ( -f $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock" ); |
{ |
|
$node = $BBS_NODE = $_; |
## |
$nodes[$_]++; |
## Create node lock file |
} |
## |
|
$lock_file = $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock"; |
|
open LOCK, ">$lock_file"; |
|
close( LOCK ); |
|
$node = $BBS_NODE = $_; |
} |
} |
|
print "Using lock: " . $LOCK_PATH."/".$BBS_NAME."_node".$node.".lock\n"; |
|
|
## |
## |
## Create our dosbox config |
## Create our dosbox config |
Line 172 sub startNetServer
|
Line 180 sub startNetServer
|
} |
} |
defined( $childPID ) || die( "Cannot fork: $!\n" ); |
defined( $childPID ) || die( "Cannot fork: $!\n" ); |
|
|
|
select $hostConnection; |
|
|
## |
## |
## Default file descriptor to the client and turn on autoflush |
## Default file descriptor to the client and turn on autoflush |
## |
## |
$hostConnection->autoflush( 1 ); |
$hostConnection->autoflush( 1 ); |
|
|
print $hostConnection "Welcome to $BBS_NAME!" . $EOL; |
print "Welcome to $BBS_NAME!" . $EOL; |
|
|
## |
## |
if ( ! $BBS_NODE ) |
if ( ! $lock_file ) |
{ |
{ |
print $hostConnection "No available nodes. Try again later.".$EOL; |
print "No available nodes. Try again later.".$EOL; |
exit; |
exit; |
} |
} |
|
|
print $hostConnection "Starting BBS on node $BBS_NODE...$EOL"; |
print "Starting BBS on node $BBS_NODE...$EOL"; |
|
|
## |
## |
## Launch BBS via dosbox |
## Launch BBS via dosbox |
Line 194 sub startNetServer
|
Line 204 sub startNetServer
|
my $bbsPID = fork( ); |
my $bbsPID = fork( ); |
if ( $bbsPID ) |
if ( $bbsPID ) |
{ |
{ |
|
select STDOUT; |
my $cmd = $BBS_CMD . $DBCONF; |
my $cmd = $BBS_CMD . $DBCONF; |
exec( $cmd ); |
system( $cmd ); |
|
print "Shutting down node $BBS_NODE\n"; |
|
## |
|
## Remove Lock |
|
## |
|
unlink( $lock_file ); |
|
unlink( $DBCONF ); |
exit; |
exit; |
} |
} |
|
|
Line 225 sub startNetServer
|
Line 242 sub startNetServer
|
{ |
{ |
print $hostConnection $byte; |
print $hostConnection $byte; |
} |
} |
kill( "TERM" => $childPID ); |
$nodes[$BBS_NODE] = 0; |
|
kill( "TERM" => $kidpid ); |
} |
} |
else |
else |
{ |
{ |
Line 257 sub shutdown
|
Line 275 sub shutdown
|
{ |
{ |
my $signame = shift || 0; |
my $signame = shift || 0; |
|
|
|
select STDOUT; |
|
|
&logmsg( "$0: Shutdown (SIG$signame) received.\n" ) |
&logmsg( "$0: Shutdown (SIG$signame) received.\n" ) |
if( $signame ); |
if( $signame ); |
|
|