WIP: whitelist, queue

This commit is contained in:
2026-03-23 12:24:24 +01:00
parent 7ecd952f08
commit 36370c4b80
7 changed files with 246 additions and 66 deletions

View File

@@ -0,0 +1,20 @@
import subprocess
import os
from config.constants import FIVEMURL
class FiveMLauncher:
def __init__(self, fivem_path: str):
self.fivem_path = os.path.expandvars(fivem_path)
@staticmethod
def launch():
"""
if not os.path.exists(self.fivem_path):
raise FileNotFoundError("❌ FiveM.exe introuvable")
subprocess.Popen(self.fivem_path, shell=True)
"""
#subprocess.Popen(f"explorer {FIVEMURL}")
subprocess.Popen(r'explorer fivem://connect/prod.la-taniere.fun')

View File

@@ -0,0 +1,128 @@
import requests
from PySide6.QtCore import QThread, Signal
from config.constants import Urls, ApiEndPoints
class JoinQueueThread(QThread):
result = Signal(dict)
error = Signal(str)
def __init__(self, user_id: str):
super().__init__()
self.user_id = user_id
self.api_url = Urls.API_URL.value
def run(self):
try:
res = requests.post(
f"{self.api_url}{ApiEndPoints.QUEUE_JOIN.value}",
headers={"Content-Type": "application/json"},
json={"uuid": self.user_id}
)
self.result.emit(res.json())
except Exception as e:
self.error.emit(str(e))
class CheckStatusThread(QThread):
result = Signal(dict)
error = Signal(str)
def __init__(self, user_id: str):
super().__init__()
self.user_id = user_id
self.api_url = Urls.API_URL.value
def run(self):
try:
res = requests.get(f"{self.api_url}{ApiEndPoints.QUEUE_STATUS.value}{self.user_id}")
self.result.emit(res.json())
except Exception as e:
self.error.emit(str(e))
class LeaveQueueThread(QThread):
done = Signal()
error = Signal(str)
def __init__(self, user_id: str):
super().__init__()
self.user_id = user_id
self.api_url = Urls.API_URL.value
def run(self):
try:
requests.post(
f"{self.api_url}{ApiEndPoints.QUEUE_LEAVE.value}",
headers={"Content-Type": "application/json"},
json={"uuid": self.user_id}
)
self.done.emit()
except Exception as e:
self.error.emit(str(e))
class QueueManager(QThread):
"""
Équivalent de startQueue() — gère tout le cycle :
join → poll toutes les 5s → lance FiveM quand c'est le tour
"""
update_ui = Signal(str) # → updateQueueUI()
launch_game = Signal() # → launchFiveM()
error = Signal(str)
def __init__(self, user_id: str, parent=None):
super().__init__(parent)
self.user_id = user_id
self.api_url = Urls.API_URL.value
self._running = True
def stop(self):
self._running = False
def run(self):
# 1. Join queue
try:
res = requests.post(
f"{self.api_url}/queue/join",
headers={"Content-Type": "application/json"},
json={"uuid": self.user_id}
)
join = res.json()
except Exception as e:
self.error.emit(str(e))
return
# 2. Slot dispo directement
if join.get("status") == "ok":
self.update_ui.emit("Slot dispo, lancement du jeu...")
self.launch_game.emit()
return
# 3. En file d'attente → poll toutes les 5s
self.update_ui.emit(
f"⏳ Vous êtes en file d'attente : position {join.get('position')} / {join.get('queueSize')}"
)
while self._running:
self.sleep(5) # Équivalent setInterval 5000ms
if not self._running:
break
try:
res = requests.get(f"{self.api_url}/queue/status/{self.user_id}")
status = res.json()
except Exception as e:
self.error.emit(str(e))
return
if status.get("status") == "queued":
self.update_ui.emit(
f"⏳ Votre position : {status.get('position')} / {status.get('queueSize')}"
)
else:
self.update_ui.emit("🚀 C'est votre tour !")
self.launch_game.emit()
return

View File

@@ -2,6 +2,8 @@ import requests
from urllib3 import disable_warnings
from urllib3.exceptions import InsecureRequestWarning
from config.constants import PlayerServerInfo
# Supress only InsecureRequestWarning
disable_warnings(InsecureRequestWarning)
@@ -9,15 +11,11 @@ WHITELIST_URL_ENDPOINT = f'iswhitelist/'
class WhiteList:
@staticmethod
def checkwhitelist(url, discord_user_id: str) -> bool:
print('🗒️ Vérification de la whitelist...')
def checkwhitelist(url, discord_user_id: str) -> None:
response = requests.get(url + WHITELIST_URL_ENDPOINT + discord_user_id, verify=False)
api_data = response.json()
if api_data['whitelisted']:
print("👍 Vous êtes en whitelist")
return True
else:
print('🙅‍♂️ Désole mais vous n\'êtes pas whitelisté sur le serveur.')
return False
PlayerServerInfo.is_whitelist = api_data.get('whitelisted', False)
#PlayerServerInfo.is_staff = api_data.get('isStaff', False)
PlayerServerInfo.is_staff = True