Added function to check if folder exists.
This commit is contained in:
@@ -8,17 +8,15 @@ load_dotenv()
|
||||
SERVER_PATH = os.getenv("SERVERPATH")
|
||||
|
||||
|
||||
def create_server(name, port, channel):
|
||||
def create_server(name: str, port: int, channel: int, command: str):
|
||||
if is_port_in_use(port):
|
||||
return "ERROR_PORT_IN_USE"
|
||||
os.mkdir("games/" + name)
|
||||
# print(SERVER_PATH)
|
||||
# print(server_command_builder(name, port, channel))
|
||||
game = Dom5game(name, channel, [], 0, {})
|
||||
game.to_json()
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
server_command_builder(name, port),
|
||||
command,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
@@ -55,9 +53,11 @@ def get_nations():
|
||||
def server_command_builder(
|
||||
name: str,
|
||||
port: int,
|
||||
era: int,
|
||||
closed_slots: list[int] = [],
|
||||
ai_slots: list[tuple[int, int]] = [],
|
||||
era: int, # 1 EA, 2 MA, 3 LA
|
||||
closed_slots: list[int] = [], # list of nations that will be closed
|
||||
ai_slots: list[
|
||||
tuple[int, int]
|
||||
] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6)
|
||||
client_start: bool = True,
|
||||
teams: list[tuple[int, int, int]] = [],
|
||||
clustered_start: bool = False,
|
||||
@@ -253,3 +253,7 @@ def is_port_in_use(port: int) -> bool:
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
return s.connect_ex(("localhost", port)) == 0
|
||||
|
||||
|
||||
def does_game_folder_exist(folder: str) -> bool:
|
||||
return not (os.path.isdir(SERVER_PATH + "/" + folder))
|
||||
|
||||
Reference in New Issue
Block a user