mirror of
https://github.com/uprightbass360/AzerothCore-RealmMaster.git
synced 2026-01-13 00:58:34 +00:00
add min/max playerbots env settings
This commit is contained in:
@@ -135,6 +135,7 @@ BACKUP_HEALTHCHECK_START_PERIOD=120s
|
||||
# Playerbots runtime flags (used by worldserver env)
|
||||
# =====================
|
||||
PLAYERBOT_ENABLED=0
|
||||
PLAYERBOT_MIN_BOTS=40
|
||||
PLAYERBOT_MAX_BOTS=40
|
||||
|
||||
# =====================
|
||||
|
||||
@@ -221,6 +221,7 @@ update_playerbots_db_info(){
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import re
|
||||
|
||||
def load_env_file(path):
|
||||
data = {}
|
||||
@@ -253,7 +254,29 @@ def resolve_key(env_map, key, default=""):
|
||||
return value
|
||||
return env_map.get(key, default)
|
||||
|
||||
def update_config(path_in, replacement):
|
||||
def parse_bool(value):
|
||||
if value is None:
|
||||
return None
|
||||
value = value.strip().lower()
|
||||
if value == "":
|
||||
return None
|
||||
if value in {"1", "true", "yes", "on"}:
|
||||
return True
|
||||
if value in {"0", "false", "no", "off"}:
|
||||
return False
|
||||
return None
|
||||
|
||||
def parse_int(value):
|
||||
if value is None:
|
||||
return None
|
||||
value = value.strip()
|
||||
if not value:
|
||||
return None
|
||||
if re.fullmatch(r"[+-]?\d+", value):
|
||||
return str(int(value))
|
||||
return None
|
||||
|
||||
def update_config(path_in, settings):
|
||||
if not (os.path.exists(path_in) or os.path.islink(path_in)):
|
||||
return False
|
||||
path = os.path.realpath(path_in)
|
||||
@@ -263,18 +286,33 @@ def update_config(path_in, replacement):
|
||||
except FileNotFoundError:
|
||||
lines = []
|
||||
|
||||
key = "PlayerbotsDatabaseInfo"
|
||||
replacement_line = f'{key} = "{replacement}"'
|
||||
changed = False
|
||||
pending = dict(settings)
|
||||
|
||||
for idx, raw in enumerate(lines):
|
||||
if raw.strip().startswith(key):
|
||||
if raw.strip() != replacement_line:
|
||||
lines[idx] = replacement_line
|
||||
stripped = raw.strip()
|
||||
for key, value in list(pending.items()):
|
||||
if re.match(rf"^\s*{re.escape(key)}\s*=", stripped):
|
||||
desired = f"{key} = {value}"
|
||||
if stripped != desired:
|
||||
leading = raw[: len(raw) - len(raw.lstrip())]
|
||||
trailing = ""
|
||||
if "#" in raw:
|
||||
before, comment = raw.split("#", 1)
|
||||
if before.strip():
|
||||
trailing = f" # {comment.strip()}"
|
||||
lines[idx] = f"{leading}{desired}{trailing}"
|
||||
changed = True
|
||||
pending.pop(key, None)
|
||||
break
|
||||
else:
|
||||
lines.append(replacement_line)
|
||||
|
||||
if pending:
|
||||
if lines and lines[-1] and not lines[-1].endswith("\n"):
|
||||
lines[-1] = lines[-1] + "\n"
|
||||
if lines and lines[-1].strip():
|
||||
lines.append("\n")
|
||||
for key, value in pending.items():
|
||||
lines.append(f"{key} = {value}\n")
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
@@ -296,7 +334,24 @@ password = resolve_key(env_map, "MYSQL_ROOT_PASSWORD", "")
|
||||
database = resolve_key(env_map, "DB_PLAYERBOTS_NAME", "acore_playerbots") or "acore_playerbots"
|
||||
|
||||
value = ";".join([host, port, user, password, database])
|
||||
update_config(target_path, value)
|
||||
settings = {"PlayerbotsDatabaseInfo": f'"{value}"'}
|
||||
|
||||
enabled_setting = parse_bool(resolve_key(env_map, "PLAYERBOT_ENABLED"))
|
||||
if enabled_setting is not None:
|
||||
settings["AiPlayerbot.Enabled"] = "1" if enabled_setting else "0"
|
||||
|
||||
max_bots = parse_int(resolve_key(env_map, "PLAYERBOT_MAX_BOTS"))
|
||||
min_bots = parse_int(resolve_key(env_map, "PLAYERBOT_MIN_BOTS"))
|
||||
|
||||
if max_bots and not min_bots:
|
||||
min_bots = max_bots
|
||||
|
||||
if min_bots:
|
||||
settings["AiPlayerbot.MinRandomBots"] = min_bots
|
||||
if max_bots:
|
||||
settings["AiPlayerbot.MaxRandomBots"] = max_bots
|
||||
|
||||
update_config(target_path, settings)
|
||||
|
||||
print(value)
|
||||
PY
|
||||
|
||||
30
setup.sh
30
setup.sh
@@ -68,6 +68,7 @@ declare -A TEMPLATE_VALUE_MAP=(
|
||||
[DEFAULT_AUTH_PORT]=AUTH_EXTERNAL_PORT
|
||||
[DEFAULT_SOAP_PORT]=SOAP_EXTERNAL_PORT
|
||||
[DEFAULT_MYSQL_PORT]=MYSQL_EXTERNAL_PORT
|
||||
[DEFAULT_PLAYERBOT_MIN]=PLAYERBOT_MIN_BOTS
|
||||
[DEFAULT_PLAYERBOT_MAX]=PLAYERBOT_MAX_BOTS
|
||||
[DEFAULT_LOCAL_STORAGE]=STORAGE_PATH
|
||||
[DEFAULT_BACKUP_PATH]=BACKUP_PATH
|
||||
@@ -573,6 +574,7 @@ main(){
|
||||
local CLI_MODULE_MODE=""
|
||||
local CLI_MODULE_PRESET=""
|
||||
local CLI_PLAYERBOT_ENABLED=""
|
||||
local CLI_PLAYERBOT_MIN=""
|
||||
local CLI_PLAYERBOT_MAX=""
|
||||
local CLI_AUTO_REBUILD=0
|
||||
local CLI_MODULES_SOURCE=""
|
||||
@@ -615,6 +617,7 @@ Options:
|
||||
--module-config NAME Use preset NAME from profiles/<NAME>.conf
|
||||
--enable-modules LIST Comma-separated module list (MODULE_* or shorthand)
|
||||
--playerbot-enabled 0|1 Override PLAYERBOT_ENABLED flag
|
||||
--playerbot-min-bots N Override PLAYERBOT_MIN_BOTS value
|
||||
--playerbot-max-bots N Override PLAYERBOT_MAX_BOTS value
|
||||
--auto-rebuild-on-deploy Enable automatic rebuild during deploys
|
||||
--modules-rebuild-source PATH Source checkout used for module rebuilds
|
||||
@@ -755,6 +758,12 @@ EOF
|
||||
;;
|
||||
--playerbot-max-bots)
|
||||
[[ $# -ge 2 ]] || { say ERROR "--playerbot-max-bots requires a value"; exit 1; }
|
||||
CLI_PLAYERBOT_MIN="$2"; shift 2
|
||||
;;
|
||||
--playerbot-min-bots=*)
|
||||
CLI_PLAYERBOT_MIN="${1#*=}"; shift
|
||||
;;
|
||||
--playerbot-max-bots)
|
||||
CLI_PLAYERBOT_MAX="$2"; shift 2
|
||||
;;
|
||||
--playerbot-max-bots=*)
|
||||
@@ -1112,7 +1121,9 @@ fi
|
||||
[MODULE_LEVEL_GRANT]="QuestCountLevel module relies on removed ConfigMgr APIs and fails to build"
|
||||
)
|
||||
|
||||
local PLAYERBOT_ENABLED=0 PLAYERBOT_MAX_BOTS=40
|
||||
local PLAYERBOT_ENABLED=0
|
||||
local PLAYERBOT_MIN_BOTS="${DEFAULT_PLAYERBOT_MIN:-40}"
|
||||
local PLAYERBOT_MAX_BOTS="${DEFAULT_PLAYERBOT_MAX:-40}"
|
||||
|
||||
local AUTO_REBUILD_ON_DEPLOY=$CLI_AUTO_REBUILD
|
||||
local MODULES_REBUILD_SOURCE_PATH_VALUE="${CLI_MODULES_SOURCE}"
|
||||
@@ -1192,6 +1203,13 @@ fi
|
||||
fi
|
||||
PLAYERBOT_ENABLED="$CLI_PLAYERBOT_ENABLED"
|
||||
fi
|
||||
if [ -n "$CLI_PLAYERBOT_MIN" ]; then
|
||||
if ! [[ "$CLI_PLAYERBOT_MIN" =~ ^[0-9]+$ ]]; then
|
||||
say ERROR "--playerbot-min-bots must be numeric"
|
||||
exit 1
|
||||
fi
|
||||
PLAYERBOT_MIN_BOTS="$CLI_PLAYERBOT_MIN"
|
||||
fi
|
||||
if [ -n "$CLI_PLAYERBOT_MAX" ]; then
|
||||
if ! [[ "$CLI_PLAYERBOT_MAX" =~ ^[0-9]+$ ]]; then
|
||||
say ERROR "--playerbot-max-bots must be numeric"
|
||||
@@ -1204,9 +1222,17 @@ fi
|
||||
if [ -z "$CLI_PLAYERBOT_ENABLED" ]; then
|
||||
PLAYERBOT_ENABLED=1
|
||||
fi
|
||||
PLAYERBOT_MIN_BOTS=$(ask "Minimum concurrent playerbots" "${CLI_PLAYERBOT_MIN:-$DEFAULT_PLAYERBOT_MIN}" validate_number)
|
||||
PLAYERBOT_MAX_BOTS=$(ask "Maximum concurrent playerbots" "${CLI_PLAYERBOT_MAX:-$DEFAULT_PLAYERBOT_MAX}" validate_number)
|
||||
fi
|
||||
|
||||
if [ -n "$PLAYERBOT_MIN_BOTS" ] && [ -n "$PLAYERBOT_MAX_BOTS" ]; then
|
||||
if [ "$PLAYERBOT_MAX_BOTS" -lt "$PLAYERBOT_MIN_BOTS" ]; then
|
||||
say WARNING "Playerbot max bots ($PLAYERBOT_MAX_BOTS) lower than min ($PLAYERBOT_MIN_BOTS); adjusting max to match min."
|
||||
PLAYERBOT_MAX_BOTS="$PLAYERBOT_MIN_BOTS"
|
||||
fi
|
||||
fi
|
||||
|
||||
for mod_var in "${MODULE_KEYS[@]}"; do
|
||||
if [ "${MODULE_NEEDS_BUILD_MAP[$mod_var]}" = "1" ]; then
|
||||
eval "value=\${$mod_var:-0}"
|
||||
@@ -1235,6 +1261,7 @@ fi
|
||||
printf " %-18s %s\n" "Modules images:" "$AC_AUTHSERVER_IMAGE_MODULES_VALUE | $AC_WORLDSERVER_IMAGE_MODULES_VALUE"
|
||||
|
||||
printf " %-18s %s\n" "Modules preset:" "$SUMMARY_MODE_TEXT"
|
||||
printf " %-18s %s\n" "Playerbot Min Bots:" "$PLAYERBOT_MIN_BOTS"
|
||||
printf " %-18s %s\n" "Playerbot Max Bots:" "$PLAYERBOT_MAX_BOTS"
|
||||
printf " %-18s" "Enabled Modules:"
|
||||
local enabled_modules=()
|
||||
@@ -1474,6 +1501,7 @@ CLIENT_DATA_VERSION=${CLIENT_DATA_VERSION:-$DEFAULT_CLIENT_DATA_VERSION}
|
||||
|
||||
# Playerbot runtime
|
||||
PLAYERBOT_ENABLED=$PLAYERBOT_ENABLED
|
||||
PLAYERBOT_MIN_BOTS=$PLAYERBOT_MIN_BOTS
|
||||
PLAYERBOT_MAX_BOTS=$PLAYERBOT_MAX_BOTS
|
||||
|
||||
# Rebuild automation
|
||||
|
||||
Reference in New Issue
Block a user