version 1.1.1.1, 2010/01/06 05:19:47
|
version 1.4, 2010/12/10 23:28:09
|
Line 36 my %opts = &fetchOptions( );
|
Line 36 my %opts = &fetchOptions( );
|
my $pidFile = "/var/run/telnetbbs.pid"; |
my $pidFile = "/var/run/telnetbbs.pid"; |
my $EOL = "\015\012"; |
my $EOL = "\015\012"; |
|
|
|
## |
|
## These will be moved in to a config file |
|
## |
|
my $DISPLAY = ":0.0"; |
|
my $BBS_NAME = "Hell's Dominion BBS"; |
|
my $BBS_NODE = 0; |
|
my $DBCONF = "/tmp/dosbox-__NODE__.conf"; |
|
my $BBS_CMD = "DISPLAY=$DISPLAY /usr/bin/dosbox -conf "; |
|
my $LOG = "/var/log/bbs.log"; |
|
my $MAX_NODE = 1; |
|
my $DOSBOXT = "dosbox.conf.template"; |
|
my $BASE_PORT = 5000; |
|
|
## |
## |
## Check that we are 'root' |
## Check that we are 'root' |
## |
## |
Line 59 $SIG{CHLD} = 'IGNORE';
|
Line 72 $SIG{CHLD} = 'IGNORE';
|
local $SIG{HUP} = $SIG{INT} = $SIG{TERM} = \&shutdown; |
local $SIG{HUP} = $SIG{INT} = $SIG{TERM} = \&shutdown; |
|
|
## |
## |
|
## Open the Log |
|
## |
|
#open LOG, ">>$LOG"; |
|
&logmsg( "Starting telnetbbs server" ); |
|
|
|
## |
## 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 78 while( 1 ) { sleep 1; }
|
Line 98 while( 1 ) { sleep 1; }
|
############################################################################### |
############################################################################### |
############################################################################### |
############################################################################### |
|
|
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" } |
sub logmsg { print "$0 $$ ", scalar localtime, ":@_\n" } |
|
|
############################################################################### |
############################################################################### |
## startNetServer( ); |
## startNetServer( ); |
Line 91 sub startNetServer
|
Line 111 sub startNetServer
|
{ |
{ |
my $hostConnection; |
my $hostConnection; |
my $childPID; |
my $childPID; |
my $port = $opts{'port'}; |
my $port = $opts{'port'} || 23; |
my $node = 1; |
my @nodes = ( ); |
|
|
my $server = IO::Socket::INET->new( |
my $server = IO::Socket::INET->new( |
LocalPort => $port, |
LocalPort => $port, |
Line 110 sub startNetServer
|
Line 130 sub startNetServer
|
## |
## |
REQUEST: while( $hostConnection = $server->accept( ) ) |
REQUEST: while( $hostConnection = $server->accept( ) ) |
{ |
{ |
|
## |
|
## Find the next available node |
|
## |
|
my $node = 0; |
|
foreach (1 .. $MAX_NODE) |
|
{ |
|
next if ( $node ); |
|
if ( ! $nodes[$_] ) |
|
{ |
|
$node = $BBS_NODE = $_; |
|
$nodes[$node]++; |
|
} |
|
} |
|
|
|
print STDOUT "Node Status: \n" . Dumper( @nodes ); |
|
|
|
## |
|
## Create our dosbox config |
|
## |
|
open( DBT, "<$DOSBOXT" ); |
|
my @dbt = <DBT>; |
|
close( DBT ); |
|
|
|
my $bpn = $BASE_PORT + $BBS_NODE; |
|
$DBCONF =~ s/__NODE__/$BBS_NODE/g; |
|
open( DBC, ">$DBCONF" ); |
|
foreach( @dbt ) |
|
{ |
|
$_ =~ s/__NODE__/$BBS_NODE/g; |
|
$_ =~ s/__LISTEN_PORT__/$bpn/g; |
|
print DBC $_; |
|
} |
|
close( DBC ); |
|
|
|
&logmsg( "Connecting on node $BBS_NODE\n" ); |
|
|
my $kidpid; |
my $kidpid; |
my $line; |
my $line; |
|
|
Line 124 sub startNetServer
|
Line 180 sub startNetServer
|
## |
## |
$hostConnection->autoflush( 1 ); |
$hostConnection->autoflush( 1 ); |
|
|
print $hostConnection "Welcome to Hell's Dominion BBS!" . $EOL; |
print $hostConnection "Welcome to $BBS_NAME!" . $EOL; |
print $hostConnection "Starting BBS on node $node...$EOL"; |
|
|
## |
|
if ( ! $BBS_NODE ) |
|
{ |
|
print $hostConnection "No available nodes. Try again later.".$EOL; |
|
exit; |
|
} |
|
|
|
print $hostConnection "Starting BBS on node $BBS_NODE...$EOL"; |
|
|
## |
## |
## Launch BBS via dosbox |
## Launch BBS via dosbox |
Line 133 sub startNetServer
|
Line 197 sub startNetServer
|
my $bbsPID = fork( ); |
my $bbsPID = fork( ); |
if ( $bbsPID ) |
if ( $bbsPID ) |
{ |
{ |
exec( "dosbox" ); |
my $cmd = $BBS_CMD . $DBCONF; |
|
exec( $cmd ); |
exit; |
exit; |
} |
} |
sleep 10; |
|
|
## |
|
## We wait for dosbox to start and the BBS to start |
|
## There really should be a better way to determine this |
|
## |
|
sleep 5; |
|
|
## |
## |
## Create connection to BBS |
## Create connection to BBS |
## |
## |
my $bbs = IO::Socket::INET->new ( |
my $bbs = IO::Socket::INET->new ( |
PeerAddr => 'localhost', |
PeerAddr => 'localhost', |
Type => SOCK_STREAM, |
Type => SOCK_STREAM, |
PeerPort => 5000, |
PeerPort => $bpn, |
Proto => 'tcp', |
Proto => 'tcp', |
) || die "Could not open BBS socket: $!\n"; |
) || die "Could not open BBS socket: $!\n"; |
$bbs->autoflush( 1 ); |
$bbs->autoflush( 1 ); |
Line 158 sub startNetServer
|
Line 228 sub startNetServer
|
{ |
{ |
print $hostConnection $byte; |
print $hostConnection $byte; |
} |
} |
kill( "TERM" => $childPID ); |
$nodes[$BBS_NODE] = 0; |
|
print "Post-Disconnect Node Status: \n" . Dumper( @nodes ); |
|
kill( "TERM" => $kidpid ); |
} |
} |
else |
else |
{ |
{ |
Line 168 sub startNetServer
|
Line 240 sub startNetServer
|
print $bbs $byte; |
print $bbs $byte; |
} |
} |
} |
} |
|
|
|
unlink( $DBCONF ); |
} |
} |
close( $hostConnection ); |
close( $hostConnection ); |
exit; |
exit; |
|
|
close( $server ); |
# close( $server ); |
} |
} |
|
|
############################################################################### |
############################################################################### |
Line 188 sub shutdown
|
Line 262 sub shutdown
|
{ |
{ |
my $signame = shift || 0; |
my $signame = shift || 0; |
|
|
print "$0: Shutdown (SIG$signame) received.\n" |
&logmsg( "$0: Shutdown (SIG$signame) received.\n" ) |
if( $signame ); |
if( $signame ); |
|
|
|
## |
|
## Close Log |
|
## |
|
close( LOG ); |
|
|
## |
## |
## Remove the PID |
## Remove the PID |
## |
## |
Line 319 sub fetchOptions {
|
Line 398 sub fetchOptions {
|
&GetOptions( |
&GetOptions( |
"help|?" => \$opts{'help'}, |
"help|?" => \$opts{'help'}, |
"man" => \$opts{'man'}, |
"man" => \$opts{'man'}, |
"port:i" => \$opts{'port'}, |
"port:i" => \$opts{'port'}, |
) || &pod2usage( ); |
) || &pod2usage( ); |
&pod2usage( ) if defined $opts{'help'}; |
&pod2usage( ) if defined $opts{'help'}; |
&pod2usage( { -verbose => 2, -input => \*DATA } ) if defined $opts{'man'}; |
&pod2usage( { -verbose => 2, -input => \*DATA } ) if defined $opts{'man'}; |
Line 331 __END__
|
Line 410 __END__
|
|
|
=head1 NAME |
=head1 NAME |
|
|
masterbuild.pl - blurb |
telnetbbs.pl - A telnet server designed to launch a multi-node BBS. |
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
masterbuild.pl [options] |
telnetbbs.pl [options] |
|
|
Options: |
Options: |
--help,? Display the basic help menu |
--help,? Display the basic help menu |
--man,m Display the detailed man page |
--man,m Display the detailed man page |
|
--port,p Port to listen on, default 23. |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|