diff --git a/bot_config.yaml.example b/bot_config.yaml.example index 105d6cd..af7fa4e 100644 --- a/bot_config.yaml.example +++ b/bot_config.yaml.example @@ -1,4 +1,5 @@ botname: 'Bob' +tmpdir: '/tmp/.skyfall/egs-bot' token: '' telnet: host: '' diff --git a/commands.rb b/commands.rb index 42557e7..073a587 100644 --- a/commands.rb +++ b/commands.rb @@ -81,7 +81,7 @@ def process_command_srvstatus(message, command, adm) else print "Receipt FAILED to send (non-zero exit code on scripts/srvstatus.receipt) !!!\nContinuing to fetch details anyway...\n".red.bold end - reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}` + reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']} #{@tmpdir}` else print "Server did not respond!\nSending failure message...\n".red.bold reply = "Server is not responding!" diff --git a/patchnotes.txt b/patchnotes.txt index 6ef4189..372beeb 100644 --- a/patchnotes.txt +++ b/patchnotes.txt @@ -1,25 +1,26 @@ SkyfallTech EGS Telebot Patch Notes: -v0.3.04 +v0.4.00 + Better server logs, round 3. ---- Vastly improved sanity check ---- Timestamps, colours, user IDs ---- Better STDOUT synchronization + * Vastly improved sanity check + * Timestamps, colours, user IDs + * Better STDOUT synchronization + Code efficiency improvements. + Fixed a few typos in responses. + Fixed possible "binary file" bug for /status command. ++ Added configurable tmp directory. v0.3.03 + Fixed 'server is up oops nevermind' condition in /status. + Fixed /whoami output formatting. + Fixed /whereareyou command. ---- (previously relied on a now-broken Contegix service) + * (previously relied on a now-broken Contegix service) v0.3.02 + Better server logs, round 2. + Less ambiguous patchnotes listing ---- (These are for the bot, not for Empyrion) + * (These are for the bot, not for Empyrion) v0.3.01 + Better server logs, round 1. diff --git a/run.rb b/run.rb index a8dfa5c..bd831d5 100755 --- a/run.rb +++ b/run.rb @@ -15,6 +15,7 @@ end #conf = YAML.load(File.read("bot_config.yaml")) @conf = YAML.load_file("bot_config.yaml") @botname = @conf['botname'] +@tmpdir = @conf['tmpdir'] token = @conf['token'] telnet = @conf['telnet'] admin = @conf['admin'] @@ -28,7 +29,7 @@ puts "Checking if environment is sane...\n\n" print "Checking bot token ...................... " if token.nil? print "FAIL!\n\n".red.bold - puts "No bot token defined in bot_config.yaml!\nTHIS IS REQUIRED! Bot initialization failed; exiting..." + puts "No bot token defined in bot_config.yaml!\n" + "THIS IS REQUIRED!".red.bold + " Bot initialization failed; exiting..." exit(1) else print "OK\n".green.bold @@ -42,6 +43,42 @@ if @botname.nil? else print "OK\n".green.bold end +### Temporary directory check +print "Checking configured tmp directory ....... " +def is_tmp_writable? + system("mkdir -p #{@tmpdir} >/dev/null 2>&1") + if system("touch #{@tmpdir}/test.file >/dev/null 2>&1") + system("rm #{@tmpdir}/test.file >/dev/null 2>&1") + return true + else + system("rm #{@tmpdir}/test.file >/dev/null 2>&1") #Attempt to clean up anyway + return false + end +end + +if @tmpdir.nil? + errcount += 1 + print "FAIL!\n\n".red.bold + puts "Error(#{errcount.to_s}): No temporary directory defined. Using '/tmp/.skyfall/egs-bot'.\n" + @tmpdir = "/tmp/.skyfall/egs-bot" + if is_tmp_writable? + puts "Default temporary directory is writable. Continuing...\n\n" + else + errcount += 1 + puts "Error(#{errcount.to_s}): Temporary directory [" + @tmpdir.red.bold + "] is not writable!\n" + "THIS IS REQUIRED!".red.bold + " Bot initialization failed; exiting..." + exit(1) + end +else + if is_tmp_writable? + print "OK\n".green.bold + else + errcount += 1 + print "FAIL!\n\n".red.bold + puts "Error(#{errcount.to_s}): Temporary directory [" + @tmpdir.red.bold + "] is not writable!\n" + "THIS IS REQUIRED!".red.bold + " Bot initialization failed; exiting..." + exit(1) + end +end +### End tmpdir check print "Checking telnet configuration ........... " if telnet.nil? errcount += 1 @@ -85,6 +122,7 @@ puts "Empyrion Telnet Port: #{telnet['port']}" puts "Authorized administrator IDs: #{admin}" puts "Authorized chat IDs: #{@auth_chat}" puts "Bot token: #{token}" +puts "Temporary direcotry: #{@tmpdir}" puts "Start time: " + timestamp + "\n\n\n\n" STDOUT.flush diff --git a/scripts/srvstatus b/scripts/srvstatus index b026c65..3a3f57c 100755 --- a/scripts/srvstatus +++ b/scripts/srvstatus @@ -3,11 +3,11 @@ host=$1 port=$2 pass=$3 -tmpfile=/tmp/.egsbot-stat +tmpfile=$4/.egsbot-stat if nc -zvw3 $host $port 2>/dev/null; then ./scripts/srvstatus.expect $host $port $pass > $tmpfile - grep -a -B1 -A8 Empyrion\ dedicated\ server /tmp/.stat | egrep -v Playfield\|Game\ seed + grep -a -B1 -A8 Empyrion\ dedicated\ server $tmpfile | egrep -v Playfield\|Game\ seed printf "\nOnline players:\n- - - - - - - - - - - - -" sed -n '/Global\ online/,/Global\ players/p' $tmpfile | awk -F\= '{print $3}' | sed 's/....$//' rm $tmpfile