--- telnetbbs/telnetbbs.pl 2010/12/14 20:32:49 1.6 +++ telnetbbs/telnetbbs.pl 2010/12/16 21:53:41 1.9 @@ -6,14 +6,14 @@ ## ## Nicholas DeClario ## October 2009 -## $Id: telnetbbs.pl,v 1.6 2010/12/14 20:32:49 nick Exp $ +## $Id: telnetbbs.pl,v 1.9 2010/12/16 21:53:41 nick Exp $ ## ################################################################################ BEGIN { delete @ENV{qw(IFS CDPATH ENV BASH_ENV PATH)}; $ENV{PATH} = "/bin:/usr/bin"; $|++; - $SIG{__DIE__} = sub { require Carp; Carp::confess(@_); } +# $SIG{__DIE__} = sub { require Carp; Carp::confess(@_); } } use strict; @@ -36,7 +36,7 @@ my %cfg = &fetchConfig( ); my $EOL = "\015\012"; ## -## These will be moved in to a config file +## These are read in from the config file ## my $BBS_NODE = 0; my $pidFile = $cfg{'pidfile'} || "/tmp/telnetbbs.pid"; @@ -105,8 +105,16 @@ while( 1 ) { sleep 1; } ## Sub-routines begin here ## ############################################################################### -############################################################################### + +############################################################################### +## +## &logmsg( "string" ); +## +## This takes a string and prepends the process name, ID and timestamp +## to the message. It then displays it to STDOUT and logs it if enabled. +## +############################################################################### sub logmsg { my $message = "$0 $$ " . scalar( localtime( ) ) . ":@_\n"; @@ -116,6 +124,15 @@ sub logmsg ############################################################################### +## +## &display_config_and_options( %hash ); +## +## This will display via Data::Dumper a hash that is passed to it. +## If verbose is enabled it will got to STDOUT and if logging is enabled +## it will be logged. +## +## This is called only once during startup. +## ############################################################################### sub display_config_and_options { @@ -165,18 +182,17 @@ sub startNetServer my $lock_file = ""; foreach (1 .. $MAX_NODE) { -print "Searching for lock: " . $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock\n"; - next if ( -f $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock" ); + $lock_file = $LOCK_PATH . "/" . $BBS_NAME . + "_node" . $_ . ".lock"; + next if ( -f $lock_file ); ## ## 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 @@ -318,6 +334,15 @@ sub shutdown unlink( $pidFile ); ## + ## Remove node lock files + ## + foreach (1 .. $MAX_NODE) + { + my $node_lock = $LOCK_PATH."/".$BBS_NAME."_node".$_.".lock"; + unlink( $node_lock ) if ( -f $node_lock ); + } + + ## ## Wait for the thread to shutdown ## # $netThread->detach( ); @@ -427,6 +452,13 @@ sub processExists } ############################################################################### +## +## %config_hash = &fetchConfig( ); +## +## This reads in a file in the format of "key = value" and stores them +## in to a hash of $hash{$key} = $value. Lines starting with '#' are +## considered comments and ignored. +## ############################################################################### sub fetchConfig { @@ -454,12 +486,21 @@ sub fetchConfig } ############################################################################### +## +## my $file = &fetchConfig( ); +## +## This function will look for 'telnetbbs.conf' or whatever was specified +## on the command line. It will search the @paths below for the default +## filename if none is specifed. +## ############################################################################### sub findConfig { my $cf = 0; my @paths = qw| ./ ./.telnetbbs /etc /usr/local/etc |; + return $opts{'config'} if defined $opts{'config'}; + foreach ( @paths ) { my $fn = $_ . "/telnetbbs.conf"; @@ -480,6 +521,7 @@ sub fetchOptions { my %opts; &GetOptions( + "config:s" => \$opts{'config'}, "help|?" => \$opts{'help'}, "man" => \$opts{'man'}, "port:i" => \$opts{'port'}, @@ -502,9 +544,11 @@ telnetbbs.pl - A telnet server designed telnetbbs.pl [options] Options: + --config,c Specify the configuration file to use --help,? Display the basic help menu --man,m Display the detailed man page --port,p Port to listen on, default 23. + --verbose,v Enable verbose output =head1 DESCRIPTION