From 45d4a85fe4b9e6804a454daab19bd41638aec874 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Fri, 12 Apr 2024 01:13:10 +0200 Subject: Add battle_config.max_rate limit (500). GMs cannot go above this Blame Ledmitz (: --- src/map/atcommand.cpp | 63 ++++++++++++++++++++++++++++----------------------- tools/config.py | 1 + 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 20743dd..311ca76 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -1667,20 +1667,38 @@ ATCE atcommand_pvpoff(Session *s, dumb_ptr sd, return ATCE::OKAY; } + + +static int extract_rate(Session *s, ZString message) +{ + int rate; + AString output; + + if (!extract(message, &rate)) + { + clif_displaymessage(s, "Please enter the new rate"_s); + return -1; + } + if (rate <= 0 || rate > battle_config.max_rate) + { + output = STRPRINTF("Rate adjustment must be between 1 and %d%%"_fmt, + battle_config.max_rate); + clif_displaymessage(s, output); + return -1; + } + return rate; +} + // Command not removed during bexprate/jexprate split // because serverdata calls it. static ATCE atcommand_exprate(Session *s, dumb_ptr, ZString message) { - int rate; - - if (!extract(message, &rate) || !rate) - { - clif_displaymessage(s, - "Please, enter a rate adjustement (usage: @exprate )."_s); + int rate = extract_rate(s, message); + if (rate < 0) return ATCE::USAGE; - } + battle_config.base_exp_rate = rate; battle_config.job_exp_rate = rate; AString output = STRPRINTF("Base & job XP rates now at %d percent"_fmt, rate); @@ -1692,14 +1710,10 @@ static ATCE atcommand_bexprate(Session *s, dumb_ptr, ZString message) { - int rate; - - if (!extract(message, &rate) || !rate) - { - clif_displaymessage(s, - "Please, enter a rate adjustement (usage: @bexprate )."_s); + int rate = extract_rate(s, message); + if (rate < 0) return ATCE::USAGE; - } + battle_config.base_exp_rate = rate; AString output = STRPRINTF("Base XP rate now at %d percent"_fmt, rate); clif_displaymessage(s, output); @@ -1710,14 +1724,10 @@ static ATCE atcommand_jexprate(Session *s, dumb_ptr, ZString message) { - int rate; - - if (!extract(message, &rate) || !rate) - { - clif_displaymessage(s, - "Please, enter a rate adjustement (usage: @jexprate )."_s); + int rate = extract_rate(s, message); + if (rate < 0) return ATCE::USAGE; - } + battle_config.job_exp_rate = rate; AString output = STRPRINTF("Job XP rate now at %d percent"_fmt, rate); clif_displaymessage(s, output); @@ -1728,14 +1738,10 @@ static ATCE atcommand_droprate(Session *s, dumb_ptr, ZString message) { - int rate; - - if (!extract(message, &rate) || !rate) - { - clif_displaymessage(s, - "Please, enter a rate adjustement (usage: @droprate )."_s); + int rate = extract_rate(s, message); + if (rate < 0) return ATCE::USAGE; - } + battle_config.drop_rate = rate; AString output = STRPRINTF("Drops rate now at %d percent"_fmt, rate); clif_displaymessage(s, output); @@ -1754,6 +1760,7 @@ ATCE atcommand_rates(Session *s, dumb_ptr, return ATCE::OKAY; } + static ATCE atcommand_pvpon(Session *s, dumb_ptr sd, ZString) diff --git a/tools/config.py b/tools/config.py index 49339bd..2f0781d 100755 --- a/tools/config.py +++ b/tools/config.py @@ -602,6 +602,7 @@ def build_config(): battle_conf.opt('base_exp_rate', percent, '100') battle_conf.opt('job_exp_rate', percent, '100') battle_conf.opt('drop_rate', percent, '100') + battle_conf.opt('max_rate', percent, '500') battle_conf.opt('death_penalty_type', i32, '0', min='0', max='2') battle_conf.opt('death_penalty_base', per10kd, '0') battle_conf.opt('death_penalty_job', per10kd, '0') -- cgit v1.2.3-60-g2f50