Skip to content

Commit

Permalink
add option for pre defined maps
Browse files Browse the repository at this point in the history
  • Loading branch information
LoV432 committed Feb 12, 2024
1 parent 250fb30 commit 3282488
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
72 changes: 62 additions & 10 deletions app/components/ConfirmationModals.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -462,16 +463,28 @@ export function ConfirmationModalChangeMap({
modalRef: React.MutableRefObject<HTMLDialogElement>;
}) {
const [activeServer] = useRecoilState(activeServerStore);
const [mapsList, setMapsList] = useState<Array<[string, string]>>([]);
const mapNameRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const mapNameSelectRef =
useRef() as React.MutableRefObject<HTMLSelectElement>;
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 (
<ConfirmationModalWrapper modalRef={modalRef} closePopUp={closePopUp}>
<h3 className="pb-5 text-lg font-bold capitalize">Change Map</h3>
Expand All @@ -489,16 +502,55 @@ export function ConfirmationModalChangeMap({
<form
onSubmit={(e) => {
e.preventDefault();
changeMap(String(mapNameRef.current.value));
mapNameRef.current.value = '';
changeMap(
String(mapNameRef.current.value || mapNameSelectRef.current.value)
);
}}
>
<input
required
ref={mapNameRef}
className="input mt-5 w-full"
placeholder="Map name*"
></input>
{mapsList.length > 0 ? (
<>
<select
defaultValue={'Select Map'}
ref={mapNameSelectRef}
className="select select-bordered mt-5 w-full min-w-full max-w-xs"
>
<option className="text-lg" value={'Select Map'} disabled>
Select Map
</option>
{mapsList.map((map) => {
return (
<option className="text-lg" key={map[1]} value={map[0]}>
{map[1]}
</option>
);
})}
</select>
<h1 className="divider">OR</h1>
<input
ref={mapNameRef}
className="input w-full"
placeholder="Custom Map"
></input>
</>
) : (
<>
<select
defaultValue={'Select Map'}
ref={mapNameSelectRef}
className="hidden"
>
<option className="text-lg" value={'Select Map'} disabled>
Select Map
</option>
</select>
<input
required
ref={mapNameRef}
className="input mt-5 w-full"
placeholder="Map name*"
></input>
</>
)}
<button type="submit" className="btn btn-success mt-5 w-full">
CHANGE MAP
</button>
Expand Down
1 change: 1 addition & 0 deletions app/lib/configParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type configType = {
mysqlUser: string;
mysqlDatabase: string;
mysqlPassword: string;
preDefinedMaps?: Array<[string, string]>;
};
servers: {
serverName: string;
Expand Down
13 changes: 13 additions & 0 deletions app/lib/get-public-configs.tsx
Original file line number Diff line number Diff line change
@@ -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
};
}
1 change: 1 addition & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3282488

Please sign in to comment.