Compare commits

..

2 Commits

Author SHA1 Message Date
e8bba85cd2 Continued work on the command builder. 2026-04-28 18:01:33 +02:00
fbb434563d Added input validation for team nations. 2026-04-28 17:36:27 +02:00

View File

@@ -90,6 +90,9 @@ def server_command_builder(
required_apoints: int = 0, required_apoints: int = 0,
cataclysm: int = 0, cataclysm: int = 0,
): ):
available_nations = get_nations()
# TODO change < ranges to =<
if (not ((random_map == 0) ^ (mapfile == ""))) or random_map not in {0, 10, 15, 20}: if (not ((random_map == 0) ^ (mapfile == ""))) or random_map not in {0, 10, 15, 20}:
return "ERROR_MAP" return "ERROR_MAP"
@@ -106,6 +109,32 @@ def server_command_builder(
if required_apoints == 0: if required_apoints == 0:
required_apoints = thrones[0] + (2 * thrones[1]) + (3 * thrones[2]) - 1 required_apoints = thrones[0] + (2 * thrones[1]) + (3 * thrones[2]) - 1
if not (0 <= research_difficulty < 5):
return "ERROR_RESEARCH"
if not (4 < hof_size < 16):
return "ERROR_HOF"
if not (2 < global_slots < 10):
return "ERROR_GLOBALS"
if not (0 <= inde_strength <= 9):
return "ERROR_INDEP"
if not (0 <= magic_sites <= 75):
return "ERROR_MAGICSITES"
if not (1 <= event_rarity <= 2):
return "ERROR_EVENTS"
if not (50 <= richness <= 300):
return "ERROR_RICHNESS"
if not (50 <= recruitment <= 300):
return "ERROR_RECRUITMENT"
if not (50 <= resources <= 300):
return "ERROR_RESOURCES"
if not (50 <= supplies <= 300):
return "ERROR_SUPPLIES"
if not (1 <= start_prov <= 9):
return "ERROR_STARTPROV"
if not (0 <= story_events <= 2):
return "ERROR_STORYEVENTS"
if not (1 <= new_ai_lvl <= 6):
return "ERROR_NEWAIS"
command = [ command = [
SERVER_PATH, SERVER_PATH,
"-TS ", "-TS ",
@@ -119,7 +148,10 @@ def server_command_builder(
] ]
if team_game: if team_game:
for team in teams: for team in teams:
# TODO Check valid inputs # TODO Can team have more than one disciple and pretender?
if team[0] not in available_nations[era]:
return "ERROR_INVALID_NATION"
command.append( command.append(
" --team " + str(team[0]) + " " + str(team[1]) + " " + str(team[2]) " --team " + str(team[0]) + " " + str(team[1]) + " " + str(team[2])
) )
@@ -132,7 +164,14 @@ def server_command_builder(
command.append(" --cataclysm " + str(cataclysm)) command.append(" --cataclysm " + str(cataclysm))
if conq_all: if conq_all:
command.append(" --conqall") command.append(" --conqall")
if not research_difficulty == 2:
command.append(" --research " + str(research_difficulty))
if not random_start_research:
command.append(" --norandres ")
if not hof_size == 10:
command.append(" --hof_size " + str(hof_size))
if not global_slots == 5:
command.append(" --globals " + str(global_slots))
return command return command