#!/bin/bash

source ~/.gamerc

grep -q "^[0-9]\+$" <<< $2 || exec echo "Usage: $0 <TEST/LIVE> <Number of Max Characters>"

if grep -qi "live" <<< $1 ; then

    # LIVE
    echo "setup.ini" | colorize cyan
    sendscript allall <<< "source ~/.gamerc ; sed -i -e 's/MaxCharacterNumber=.*/MaxCharacterNumber=$2/g' ~/servers*/setup.ini ; grep -H MaxCharacterNumber= ~/servers*/setup.ini"

    echo

    echo "config.ini" | colorize cyan
    sendscript allall <<< "source ~/.gamerc ; sed -i -e 's/MaxCreateChar=.*/MaxCreateChar=$2/g' ~/servers*/bin/config.ini ; grep -H MaxCreateChar= ~/servers*/bin/config.ini"

else

    # TEST
    echo "setup.ini" | colorize cyan
    sed -i -e "s/MaxCharacterNumber=.*/MaxCharacterNumber=$2/g" ~/servers*/setup.ini ; grep -H MaxCharacterNumber= ~/servers*/setup.ini

    echo

    echo "config.ini" | colorize cyan
    sed -i -e "s/MaxCreateChar=.*/MaxCreateChar=$2/g" ~/servers*/bin/config.ini ; grep -H MaxCreateChar= ~/servers*/bin/config.ini

fi

