Started work on implementing most server args.
This commit is contained in:
@@ -10,32 +10,98 @@ SERVER_PATH = os.getenv("SERVERPATH")
|
|||||||
def create_server(name, port, channel):
|
def create_server(name, port, channel):
|
||||||
if is_port_in_use(port):
|
if is_port_in_use(port):
|
||||||
return "ERROR_PORT_IN_USE"
|
return "ERROR_PORT_IN_USE"
|
||||||
# os.mkdir("games/" + name)
|
os.mkdir("games/" + name)
|
||||||
# print(SERVER_PATH)
|
# print(SERVER_PATH)
|
||||||
# print(server_command_builder(name, port, channel))
|
# print(server_command_builder(name, port, channel))
|
||||||
|
game = Dom5game(name, channel, [], 0, {})
|
||||||
|
game.to_json()
|
||||||
try:
|
try:
|
||||||
subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
server_command_builder(name, port, channel),
|
server_command_builder(name, port),
|
||||||
stdin=None,
|
stdout=subprocess.DEVNULL,
|
||||||
stdout=None,
|
stderr=subprocess.STDOUT,
|
||||||
stderr=None,
|
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return "EXCEPTION OCCURED: " + str(e)
|
return "EXCEPTION OCCURED: " + str(e)
|
||||||
|
return "SUCCESS"
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
def server_command_builder(name, port, channel):
|
# This is terrible.
|
||||||
|
def server_command_builder(
|
||||||
|
name: str,
|
||||||
|
port: int,
|
||||||
|
era: int,
|
||||||
|
closed_slots: list[int] = [],
|
||||||
|
ai_slots: list[tuple[int, int]] = [],
|
||||||
|
client_start: bool = True,
|
||||||
|
teams: list[tuple[int, int, int]] = [],
|
||||||
|
clustered_start: bool = False,
|
||||||
|
team_game: bool = False,
|
||||||
|
mapfile: str = "",
|
||||||
|
random_map: int = 0,
|
||||||
|
research_difficulty: int = 2,
|
||||||
|
random_start_research: bool = True,
|
||||||
|
hof_size: int = 10,
|
||||||
|
global_slots: int = 5,
|
||||||
|
inde_strength: int = 5,
|
||||||
|
magic_sites: int = 40,
|
||||||
|
event_rarity: int = 1,
|
||||||
|
richness: int = 100,
|
||||||
|
resources: int = 100,
|
||||||
|
recruitment: int = 100,
|
||||||
|
supplies: int = 100,
|
||||||
|
masterpass: str = "",
|
||||||
|
start_prov: int = 1,
|
||||||
|
renaming: bool = True,
|
||||||
|
score_graphs: bool = False,
|
||||||
|
no_nation_info: bool = False,
|
||||||
|
no_cheat_det: bool = False,
|
||||||
|
no_artifact_rest: bool = False,
|
||||||
|
story_events: int = 1,
|
||||||
|
new_ai_lvl: int = 2,
|
||||||
|
no_new_ai: bool = False,
|
||||||
|
conq_all: bool = False,
|
||||||
|
thrones: tuple[int, int, int] = (1, 1, 1),
|
||||||
|
required_apoints: int = 0,
|
||||||
|
cataclysm: int = 0,
|
||||||
|
):
|
||||||
|
if not ((random_map == 0) ^ (mapfile == "")):
|
||||||
|
return "ERROR_MAP"
|
||||||
|
|
||||||
|
if not (0 < era < 4):
|
||||||
|
return "ERROR_ERA"
|
||||||
|
|
||||||
|
ai_indexes = [t[1] for t in ai_slots]
|
||||||
|
if not (len(ai_indexes) == len(set(ai_indexes))):
|
||||||
|
return "ERROR_AIS"
|
||||||
|
|
||||||
|
if bool(set(closed_slots) & set(ai_indexes)):
|
||||||
|
return "ERROR_CLOSED_AIS"
|
||||||
|
|
||||||
|
if required_apoints == 0:
|
||||||
|
required_apoints = thrones[0] + (2 * thrones[1]) + (3 * thrones[2]) - 1
|
||||||
|
|
||||||
command = [
|
command = [
|
||||||
SERVER_PATH,
|
SERVER_PATH,
|
||||||
"-TS",
|
" -TS ",
|
||||||
name,
|
name,
|
||||||
"--port",
|
" --port ",
|
||||||
str(port),
|
str(port),
|
||||||
"--statuspage",
|
" --statuspage ",
|
||||||
os.getcwd() + "/games/" + name + "/turnstats.html",
|
os.getcwd() + "/games/" + name + "/turnstats.html",
|
||||||
|
" --era ",
|
||||||
|
era,
|
||||||
]
|
]
|
||||||
game = Dom5game(name, channel, [], 0, {})
|
if team_game:
|
||||||
game.to_json()
|
|
||||||
|
if not client_start:
|
||||||
|
command.append(" --noclientstart ")
|
||||||
|
if cataclysm > 0:
|
||||||
|
command.append(" --cataclysm " + str(cataclysm))
|
||||||
|
if conq_all:
|
||||||
|
command.append(" --conqall")
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user