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