Compare commits
4 Commits
6d1ff496dd
...
6ca35c12e2
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ca35c12e2 | |||
| 06514cc4c2 | |||
| caba8d42bd | |||
| 84b84f45b6 |
@@ -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,
|
||||
|
||||
30
webui.py
30
webui.py
@@ -1,6 +1,9 @@
|
||||
from nicegui import ui
|
||||
from bot_instance import bot
|
||||
from dom5game import Dom5game
|
||||
import servermanager
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
def create_ui():
|
||||
@@ -11,6 +14,7 @@ def create_ui():
|
||||
rows.append({"Name": game.name, "Turn": game.turn})
|
||||
|
||||
pages.add("/", lambda: main_page(rows))
|
||||
pages.add("/create", lambda: creator_page())
|
||||
|
||||
ui.run(reload=False)
|
||||
|
||||
@@ -29,3 +33,29 @@ def game_page(game_name: str):
|
||||
if game.players[player] not in {"AI", "Eliminated"}:
|
||||
rows.append({"Player": player, "Status": game.players[player]})
|
||||
ui.table(rows=rows, title=game_name)
|
||||
|
||||
|
||||
# hell
|
||||
def creator_page():
|
||||
# Game Name
|
||||
name = ui.input(
|
||||
label="Game Name",
|
||||
validation={
|
||||
"Game with that name already exists": lambda value: not (
|
||||
os.path.isdir("games/" + value)
|
||||
)
|
||||
},
|
||||
).value
|
||||
# Port
|
||||
load_dotenv()
|
||||
port_min = os.getenv("PORT_MIN")
|
||||
port_max = os.getenv("PORT_MAX")
|
||||
port = ui.input(
|
||||
label="Port",
|
||||
validation={
|
||||
f"Port must be between {str(port_min)} and {str(port_max)}": lambda value: port_min
|
||||
<= value
|
||||
<= port_max
|
||||
},
|
||||
)
|
||||
# Era
|
||||
|
||||
Reference in New Issue
Block a user