From 3b2d8579913837184592ee18a628335d4e6874c8 Mon Sep 17 00:00:00 2001 From: Marcus Whybrow Date: Fri, 20 Jul 2012 06:27:29 +0100 Subject: [PATCH] Added offline support for blacklist add and remove commands. --- bash_completion/msm | 4 ++-- init/msm | 32 ++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/bash_completion/msm b/bash_completion/msm index 0abf44c..d71d064 100644 --- a/bash_completion/msm +++ b/bash_completion/msm @@ -208,7 +208,7 @@ _msm() { else case "${COMP_WORDS[4]}" in remove) - if [[ $COMP_CWORD == 5 ]]; then + if [[ $COMP_CWORD -ge 5 ]]; then server_property "$sid" BANNED_PLAYERS_PATH if [ -f "${SERVER_BANNED_PLAYERS_PATH[$sid]}" ]; then options="$(cat "${SERVER_BANNED_PLAYERS_PATH[$sid]}")" @@ -224,7 +224,7 @@ _msm() { else case "${COMP_WORDS[4]}" in remove) - if [[ $COMP_CWORD == 5 ]]; then + if [[ $COMP_CWORD -ge 5 ]]; then server_property "$sid" BANNED_PLAYERS_PATH if [ -f "${SERVER_BANNED_IPS_PATH[$sid]}" ]; then options="$(cat "${SERVER_BANNED_IPS_PATH[$sid]}")" diff --git a/init/msm b/init/msm index b1e2b23..1f3dc9f 100755 --- a/init/msm +++ b/init/msm @@ -2190,9 +2190,19 @@ command_server_whitelist_list() { # $1: The server ID # $2->: The player names command_server_blacklist_player_add() { - for player in "${@:2}"; do - server_eval "$1" "ban $player" - done + if server_is_running "$1"; then + for player in "${@:2}"; do + server_eval "$1" "ban $player" + done + else + server_property "$1" BANNED_PLAYERS_PATH + + for player in "${@:2}"; do + if ! grep "$player" "${SERVER_BANNED_PLAYERS_PATH[$1]}" >/dev/null; then + echo "$player" >> "${SERVER_BANNED_PLAYERS_PATH[$1]}" + fi + done + fi if [[ $# -gt 2 ]]; then echo -n "Blacklisted the following players: " @@ -2210,9 +2220,19 @@ command_server_blacklist_player_add() { # $1: The server ID # $2->: The player names command_server_blacklist_player_remove() { - for player in "${@:2}"; do - server_eval "$1" "pardon $player" - done + if server_is_running "$1"; then + for player in "${@:2}"; do + server_eval "$1" "pardon $player" + done + else + server_property "$1" BANNED_PLAYERS_PATH + + for player in "${@:2}"; do + if grep "$player" "${SERVER_BANNED_PLAYERS_PATH[$1]}" >/dev/null; then + sed -i "/$player/d" "${SERVER_BANNED_PLAYERS_PATH[$1]}" + fi + done + fi if [[ $# -gt 2 ]]; then echo -n "Removed the following players from the blacklist: "