From 9b8a1dd21d1cb3cce5ce689556fd7a07949bc743 Mon Sep 17 00:00:00 2001 From: Marcus Whybrow Date: Mon, 25 Jun 2012 15:18:08 +0100 Subject: [PATCH] Fixes #20. By implementing checks before reading server files. --- init/msm | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/init/msm b/init/msm index d080a39..099c8b3 100755 --- a/init/msm +++ b/init/msm @@ -1564,13 +1564,16 @@ command_server_whitelist_remove() { # Displays a list of whitelisted players for an individual server # $1: The server ID command_server_whitelist_list() { - # TODO: Protect against no whitelist file - local players="$(cat "${server_whitelist[$1]}")" + if [ -f "${server_whitelist[$1]}" ]; then + local players="$(cat "${server_whitelist[$1]}")" - if [ -z "$players" ]; then - echo "No players are whitelisted." + if [ -z "$players" ]; then + echo "No players are whitelisted." + else + echo "$players" + fi else - echo "$players" + echo "No players are whitelisted." fi } @@ -1657,10 +1660,16 @@ command_server_blacklist_ip_remove() { # Displays a server's banned player names and ip addresses # $1: The server ID command_server_blacklist_list() { - # TODO: Protect against non-existent files - - local players="$(cat "${server_banned_players[$1]}")" - local ips="$(cat "${server_banned_ips[$1]}")" + local players + local ips + + if [ -f "${server_banned_players[$1]}" ]; then + players="$(cat "${server_banned_players[$1]}")" + fi + + if [ -f "${server_banned_ips[$1]}" ]; then + ips="$(cat "${server_banned_ips[$1]}")" + fi if [[ -z "$players" && -z "$ips" ]]; then echo "The blacklist is empty."