Add changing cars
This commit is contained in:
@@ -166,15 +166,17 @@ class Handler(BaseHTTPRequestHandler):
|
||||
import json
|
||||
try:
|
||||
data = json.loads(body)
|
||||
print("Received cars:", data)
|
||||
success, message = update_cars(data.get("cars", []))
|
||||
return True
|
||||
except json.JSONDecodeError:
|
||||
self.send_response(400)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(b'{"error":"invalid json"}')
|
||||
return
|
||||
print("Invalid JSON received")
|
||||
return False
|
||||
|
||||
print("Received cars:", data)
|
||||
|
||||
def send_image(self, img_path: str):
|
||||
if os.path.exists(img_path):
|
||||
|
||||
13
ac_cars.py
13
ac_cars.py
@@ -2,10 +2,10 @@ import os
|
||||
|
||||
CONFIG_FILE = "server_cfg.ini"
|
||||
ENTRY_LIST_FILE = "entry_list.ini"
|
||||
CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
|
||||
CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
|
||||
# CONTENT_FOLDER = "./content"
|
||||
# CONFIG_PATH = "./cfg"
|
||||
# CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
|
||||
# CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
|
||||
CONTENT_FOLDER = "./content"
|
||||
CONFIG_PATH = "./cfg"
|
||||
|
||||
CARS_FOLDER = os.path.join(CONTENT_FOLDER, "cars")
|
||||
|
||||
@@ -26,6 +26,7 @@ def get_all_cars():
|
||||
skins = get_car_skins(cars_folders[i])
|
||||
if len(skins) == 0:
|
||||
continue # skip cars without skins
|
||||
|
||||
skins_data = []
|
||||
for j in range(len(skins)):
|
||||
skin_data = {
|
||||
@@ -68,9 +69,9 @@ def update_cars(cars: list[dict]) -> tuple[bool, str]:
|
||||
if (car_entry == ""):
|
||||
continue
|
||||
if (car_entry not in cars_line):
|
||||
cars_line += f"{car};"
|
||||
car_numer += 1
|
||||
cars_line += f"{car_entry};"
|
||||
final_cars.append(Car(car_entry, car.get("skin"), car_number))
|
||||
car_number += 1
|
||||
cars_line = cars_line.rstrip(";")
|
||||
|
||||
write_car_entries_line(cars_line)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import os
|
||||
|
||||
CONFIG_FILE = "server_cfg.ini"
|
||||
CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
|
||||
CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
|
||||
# CONTENT_FOLDER = "./content"
|
||||
# CONFIG_PATH = "./cfg"
|
||||
# CONTENT_FOLDER = "/home/sem/assetto-corsa/content"
|
||||
# CONFIG_PATH = "/home/sem/assetto-corsa/cfg"
|
||||
CONTENT_FOLDER = "./content"
|
||||
CONFIG_PATH = "./cfg"
|
||||
|
||||
TRACKS_FOLDER = os.path.join(CONTENT_FOLDER, "tracks")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user