From 32824886dbfb86c34aa161f29ab56a1158c6bcc7 Mon Sep 17 00:00:00 2001 From: LoV432 Date: Mon, 12 Feb 2024 15:51:14 +0500 Subject: [PATCH] add option for pre defined maps --- app/components/ConfirmationModals.tsx | 72 +++++++++++++++++++++++---- app/lib/configParse.ts | 1 + app/lib/get-public-configs.tsx | 13 +++++ config.toml.example | 1 + 4 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 app/lib/get-public-configs.tsx diff --git a/app/components/ConfirmationModals.tsx b/app/components/ConfirmationModals.tsx index 422df4f..aebe7eb 100644 --- a/app/components/ConfirmationModals.tsx +++ b/app/components/ConfirmationModals.tsx @@ -1,9 +1,10 @@ -import { useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { execRcon } from '../lib/exec-rcon'; import { searchSteamIDFromAdminPlugin } from '../lib/get-steamid'; import { useRecoilState } from 'recoil'; import { activeServerStore } from '../store/active-server-store'; import { reloadAllServerAdmin } from '../lib/reload-admin-vip'; +import { getMapsList } from '../lib/get-public-configs'; export function ConfirmationModal({ modalName, modalRef, @@ -462,16 +463,28 @@ export function ConfirmationModalChangeMap({ modalRef: React.MutableRefObject; }) { const [activeServer] = useRecoilState(activeServerStore); + const [mapsList, setMapsList] = useState>([]); const mapNameRef = useRef() as React.MutableRefObject; + const mapNameSelectRef = + useRef() as React.MutableRefObject; function changeMap(mapName: string) { - if (mapName == '') return; + if (mapName == '' || mapName == 'Select Map') return; execRcon(`css_map ${mapName}`, activeServer); closePopUp(); } function closePopUp() { modalRef.current.close(); mapNameRef.current.value = ''; + mapNameSelectRef.current.value = 'Select Map'; } + useEffect(() => { + (async () => { + const fetchedMapsList = await getMapsList(); + if (fetchedMapsList && fetchedMapsList.maps) { + setMapsList(fetchedMapsList.maps); + } + })(); + }, [activeServer]); return (

Change Map

@@ -489,16 +502,55 @@ export function ConfirmationModalChangeMap({
{ e.preventDefault(); - changeMap(String(mapNameRef.current.value)); - mapNameRef.current.value = ''; + changeMap( + String(mapNameRef.current.value || mapNameSelectRef.current.value) + ); }} > - + {mapsList.length > 0 ? ( + <> + +

OR

+ + + ) : ( + <> + + + + )} diff --git a/app/lib/configParse.ts b/app/lib/configParse.ts index 5e1767b..456b12d 100644 --- a/app/lib/configParse.ts +++ b/app/lib/configParse.ts @@ -10,6 +10,7 @@ export type configType = { mysqlUser: string; mysqlDatabase: string; mysqlPassword: string; + preDefinedMaps?: Array<[string, string]>; }; servers: { serverName: string; diff --git a/app/lib/get-public-configs.tsx b/app/lib/get-public-configs.tsx new file mode 100644 index 0000000..5ca4523 --- /dev/null +++ b/app/lib/get-public-configs.tsx @@ -0,0 +1,13 @@ +'use server'; +import { getServersConfig } from './configParse'; + +export async function getMapsList() { + const config = getServersConfig(); + if ('err' in config) { + return undefined; + } + + return { + maps: config.global.preDefinedMaps + }; +} diff --git a/config.toml.example b/config.toml.example index 326d23f..7e18381 100644 --- a/config.toml.example +++ b/config.toml.example @@ -9,6 +9,7 @@ mysqlPort = 3306 mysqlUser = 'root' mysqlDatabase = 'dbname' mysqlPassword = 'password' +preDefinedMaps = [['ws:fy_pool_day','Pool Day'], ['de_mirage', 'Mirage'], ['de_dust2', 'Dust 2']] # This is Not Required [[servers]] serverName = "Good Name"