This commit is contained in:
shoopea 2024-10-17 22:48:18 +02:00
parent 4fc35d3550
commit 4275f36a9c

View File

@ -44,7 +44,7 @@ router.post('/api/setup-game', is_authenticated, async (req, res) => {
execute_cfg_on_server(server_id, './cfg/warmup.cfg'); execute_cfg_on_server(server_id, './cfg/warmup.cfg');
}, 1000) }, 1000)
//return res.status(200).json({ message: 'Game Created!' }); return res.status(200).json({ message: 'Game Created!' });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -56,7 +56,7 @@ router.post('/api/restart', is_authenticated, async (req, res) => {
const server_id = req.body.server_id; const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_restartgame 1'); // rcon.rcons[server_id].execute('mp_restartgame 1');
await rcon.execute_command(server_id, `mp_restartgame 1`); await rcon.execute_command(server_id, `mp_restartgame 1`);
//return res.status(200).json({ message: 'Game restarted' }); return res.status(200).json({ message: 'Game restarted' });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -70,7 +70,7 @@ router.post('/api/start-warmup', is_authenticated, async (req, res) => {
await rcon.execute_command(server_id, `mp_restartgame 1`); await rcon.execute_command(server_id, `mp_restartgame 1`);
execute_cfg_on_server(server_id, './cfg/warmup.cfg'); execute_cfg_on_server(server_id, './cfg/warmup.cfg');
//return res.status(200).json({ message: 'Warmup started!' }); return res.status(200).json({ message: 'Warmup started!' });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -86,7 +86,7 @@ router.post('/api/start-knife', is_authenticated, async (req, res) => {
await rcon.execute_command(server_id, `mp_restartgame 1`); await rcon.execute_command(server_id, `mp_restartgame 1`);
execute_cfg_on_server(server_id, './cfg/knife.cfg'); execute_cfg_on_server(server_id, './cfg/knife.cfg');
//return res.status(200).json({ message: 'Knife started!' }); return res.status(200).json({ message: 'Knife started!' });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -98,7 +98,7 @@ router.post('/api/swap-team', is_authenticated, async (req, res) => {
const server_id = req.body.server_id; const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_swapteams'); // rcon.rcons[server_id].execute('mp_swapteams');
await rcon.execute_command(server_id, `mp_swapteams`); await rcon.execute_command(server_id, `mp_swapteams`);
//return res.status(200).json({ message: 'Teams Swapped!' }); return res.status(200).json({ message: 'Teams Swapped!' });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
@ -125,7 +125,7 @@ router.post('/api/go-live', is_authenticated, async (req, res) => {
// rcon.rcons[server_id].execute('mp_restartgame 1'); // rcon.rcons[server_id].execute('mp_restartgame 1');
await rcon.execute_command(server_id, `mp_restartgame 1`); await rcon.execute_command(server_id, `mp_restartgame 1`);
//return res.status(200).json({ message: 'Match is live!!' }); return res.status(200).json({ message: 'Match is live!!' });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -139,7 +139,7 @@ router.post('/api/list-backups', is_authenticated, async (req, res) => {
// const response = await rcon.rcons[server_id].execute('mp_backup_restore_list_files'); // const response = await rcon.rcons[server_id].execute('mp_backup_restore_list_files');
const response = await rcon.execute_command(server_id, "mp_backup_restore_list_files"); const response = await rcon.execute_command(server_id, "mp_backup_restore_list_files");
console.log('Server response:', response); console.log('Server response:', response);
//return res.status(200).json({ message: response }); return res.status(200).json({ message: response });
} catch (error) { } catch (error) {
console.log(error) console.log(error)
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
@ -159,7 +159,7 @@ router.post('/api/restore-round', is_authenticated, async (req, res) => {
// rcon.rcons[server_id].execute('mp_pause_match'); // rcon.rcons[server_id].execute('mp_pause_match');
await rcon.execute_command(server_id, `mp_backup_restore_load_file backup_round${round_number}.txt`); await rcon.execute_command(server_id, `mp_backup_restore_load_file backup_round${round_number}.txt`);
await rcon.execute_command(server_id, `mp_pause_match`); await rcon.execute_command(server_id, `mp_pause_match`);
//return res.status(200).json({ message: 'Round Restored!' }); return res.status(200).json({ message: 'Round Restored!' });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
@ -176,9 +176,9 @@ router.post('/api/restore-latest-backup', is_authenticated, async (req, res) =>
// rcon.rcons[server_id].execute('mp_pause_match'); // rcon.rcons[server_id].execute('mp_pause_match');
await rcon.execute_command(server_id, `mp_backup_restore_load_file ${last_round_file}`); await rcon.execute_command(server_id, `mp_backup_restore_load_file ${last_round_file}`);
await rcon.execute_command(server_id, `mp_pause_match`); await rcon.execute_command(server_id, `mp_pause_match`);
//return res.status(200).json({ message: `Latest Round Restored! (${last_round_file})` }); return res.status(200).json({ message: `Latest Round Restored! (${last_round_file})` });
} else { } else {
//return res.status(200).json({ message: 'No latest backup found!' }); return res.status(200).json({ message: 'No latest backup found!' });
} }
} catch (error) { } catch (error) {
@ -193,7 +193,7 @@ router.post('/api/pause', is_authenticated, async (req, res) => {
const server_id = req.body.server_id; const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_pause_match'); // rcon.rcons[server_id].execute('mp_pause_match');
const response = await rcon.execute_command(server_id, 'mp_pause_match'); const response = await rcon.execute_command(server_id, 'mp_pause_match');
//return res.status(200).json({ message: 'Game paused' }); return res.status(200).json({ message: 'Game paused' });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
@ -205,7 +205,7 @@ router.post('/api/unpause', is_authenticated, async (req, res) => {
const server_id = req.body.server_id; const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_unpause_match'); // rcon.rcons[server_id].execute('mp_unpause_match');
const response = await rcon.execute_command(server_id, 'mp_unpause_match'); const response = await rcon.execute_command(server_id, 'mp_unpause_match');
//return res.status(200).json({ message: 'Game unpaused' }); return res.status(200).json({ message: 'Game unpaused' });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
@ -219,10 +219,10 @@ router.post('/api/rcon', is_authenticated, async (req, res) => {
const response = await rcon.execute_command(server_id, command); const response = await rcon.execute_command(server_id, command);
if (response == 200) { if (response == 200) {
//return res.status(200).json({ message: 'Command sent!' }); return res.status(200).json({ message: 'Command sent!' });
} }
//return res.status(200).json({ message: 'Command sent! Response received:\n' + response.toString() }); return res.status(200).json({ message: 'Command sent! Response received:\n' + response.toString() });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }
@ -234,7 +234,7 @@ router.post('/api/say-admin', is_authenticated, async (req, res) => {
const message = req.body.message; const message = req.body.message;
const message_to_send = "say " + message; const message_to_send = "say " + message;
await rcon.execute_command(server_id, message_to_send); await rcon.execute_command(server_id, message_to_send);
//return res.status(200).json({ message: 'Message sent!' }); return res.status(200).json({ message: 'Message sent!' });
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Internal server error' }); res.status(500).json({ error: 'Internal server error' });
} }