From 96087b1bf9d0333592917288f7e16a55ef8161a5 Mon Sep 17 00:00:00 2001 From: Marcus Whybrow Date: Fri, 20 Jul 2012 06:13:12 +0100 Subject: [PATCH] Added multi-user support to whitelist add and remove commands. --- bash_completion/msm | 2 +- init/msm | 81 +++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/bash_completion/msm b/bash_completion/msm index 2bf28bb..0abf44c 100644 --- a/bash_completion/msm +++ b/bash_completion/msm @@ -187,7 +187,7 @@ _msm() { else case "${COMP_WORDS[3]}" in remove) - if [[ $COMP_CWORD == 4 ]]; then + if [[ $COMP_CWORD -ge 4 ]]; then server_property "$sid" WHITELIST_PATH if [ -f "${SERVER_WHITELIST_PATH[$sid]}" ]; then options="$(cat "${SERVER_WHITELIST_PATH[$sid]}")" diff --git a/init/msm b/init/msm index 60383f9..9e87f97 100755 --- a/init/msm +++ b/init/msm @@ -2105,21 +2105,34 @@ command_server_whitelist_off() { # Adds a player name to a server's whitelist # $1: The server ID -# $2: The player name +# $2->: The player name command_server_whitelist_add() { # TODO: Support whitelisting multiple players (see blacklist player add) if server_is_running "$1"; then - server_eval "$1" "whitelist add $2" - echo "Added \"$2\" to the whitelist." + # Whitelist players + for player in "${@:2}"; do + server_eval "$1" "whitelist add $player" + done else server_property "$1" WHITELIST_PATH - if grep "$2" "${SERVER_WHITELIST_PATH[$1]}" >/dev/null; then - echo "Player \"$2\" is already whitelisted for server \"${SERVER_NAME[$1]}\"." - else - echo "$2" >> "${SERVER_WHITELIST_PATH[$1]}" - echo "Player \"$2\" has been added to the whitelisted for server \"${SERVER_NAME[$1]}\"." - fi + for player in "${@:2}"; do + if ! grep "$player" "${SERVER_WHITELIST_PATH[$1]}" >/dev/null; then + echo "$player" >> "${SERVER_WHITELIST_PATH[$1]}" + fi + done + fi + + # Confirmation display + if [[ $# -gt 2 ]]; then + echo -n "Added the following players to the whitelist: " + echo -n "$2" + for player in "${@:3}"; do + echo -n ", $player" + done + echo "." + else + echo "Added \"$2\" to the whitelist." fi } @@ -2129,17 +2142,29 @@ command_server_whitelist_add() { command_server_whitelist_remove() { # TODO: Support multiple player names if server_is_running "$1"; then - server_eval "$1" "whitelist remove $2" - echo "Removed \"$2\" from the whitelist." + for player in "${@:2}"; do + server_eval "$1" "whitelist remove $player" + done else server_property "$1" WHITELIST_PATH - if grep "$2" "${SERVER_WHITELIST_PATH[$1]}" >/dev/null; then - sed -i "/$2/d" "${SERVER_WHITELIST_PATH[$1]}" - echo "Player \"$2\" has been removed from the whitelisted for server \"${SERVER_NAME[$1]}\"." - else - echo "Player \"$2\" is not whitelisted for server \"${SERVER_NAME[$1]}\"." - fi + for player in "${@:2}"; do + if grep "$player" "${SERVER_WHITELIST_PATH[$1]}" >/dev/null; then + sed -i "/$player/d" "${SERVER_WHITELIST_PATH[$1]}" + fi + done + fi + + # Confirmation display + if [[ $# -gt 2 ]]; then + echo -n "Removed the following players from the whitelist: " + echo -n "$2" + for player in "${@:3}"; do + echo -n ", $player" + done + echo "." + else + echo "Removed \"$2\" from the whitelist." fi } @@ -2147,7 +2172,7 @@ command_server_whitelist_remove() { # $1: The server ID command_server_whitelist_list() { server_property "$1" WHITELIST_PATH - + if [ -f "${SERVER_WHITELIST_PATH[$1]}" ]; then local players="$(cat "${SERVER_WHITELIST_PATH[$1]}")" @@ -3056,19 +3081,19 @@ register_commands() { register_command " jar " "command_server_jar" register_command " whitelist|wl on" "command_server_whitelist_on" register_command " whitelist|wl off" "command_server_whitelist_off" - register_command " whitelist|wl add " "command_server_whitelist_add" - register_command " whitelist|wl remove " "command_server_whitelist_remove" + register_command " whitelist|wl add " "command_server_whitelist_add" + register_command " whitelist|wl remove " "command_server_whitelist_remove" register_command " whitelist|wl list" "command_server_whitelist_list" - register_command " blacklist|bl player add " "command_server_blacklist_player_add" - register_command " blacklist|bl player remove " "command_server_blacklist_player_remove" - register_command " blacklist|bl ip add " "command_server_blacklist_ip_add" - register_command " blacklist|bl ip remove " "command_server_blacklist_ip_remove" + register_command " blacklist|bl player add " "command_server_blacklist_player_add" + register_command " blacklist|bl player remove " "command_server_blacklist_player_remove" + register_command " blacklist|bl ip add " "command_server_blacklist_ip_add" + register_command " blacklist|bl ip remove " "command_server_blacklist_ip_remove" register_command " blacklist|bl list" "command_server_blacklist_list" - register_command " operator|op add " "command_server_operator_add" - register_command " operator|op remove " "command_server_operator_remove" + register_command " operator|op add " "command_server_operator_add" + register_command " operator|op remove " "command_server_operator_remove" register_command " operator|op list" "command_server_operator_list" - register_command " gamemode|gm " "command_server_gamemode" - register_command " kick " "command_server_kick" + register_command " gamemode|gm " "command_server_gamemode" + register_command " kick " "command_server_kick" register_command " say " "command_server_say" register_command " time set " "command_server_time_set" register_command " time add " "command_server_time_add"