start revamp

This commit is contained in:
shoopea
2024-10-29 20:15:00 +01:00
parent 7b44b540e1
commit c96cf2e93e
13 changed files with 368 additions and 149 deletions

View File

@@ -14,28 +14,32 @@ router.post('/api/setup-game', is_authenticated, async (req, res) => {
const team1 = req.body.team1;
const team2 = req.body.team2;
const selected_map = req.body.selectedMap;
const game_mode = req.body.game_mode.toString();
// rcon.rcons[server_id].execute(`mp_teamname_1 "${team1}"`);
// rcon.rcons[server_id].execute(`mp_teamname_2 "${team2}"`);
// rcon.rcons[server_id].execute(`game_mode ${game_mode}`);
const game_sel = req.body.game_mode.toString();
if (team1.trim() != "") {
await rcon.execute_command(server_id, `mp_teamname_1 "${team1}"`);
}
if (team2.trim() != "") {
await rcon.execute_command(server_id, `mp_teamname_2 "${team2}"`);
}
if (game_mode == "1") {
if (game_sel == "1") {
await rcon.execute_command(server_id, `game_mode 1`);
execute_cfg_on_server(server_id, './cfg/live16.cfg');
} else if (game_mode == "2") {
execute_cfg_on_server(server_id, './cfg/live_competitive_16.cfg');
} else if (game_sel == "2") {
await rcon.execute_command(server_id, `game_mode 1`);
execute_cfg_on_server(server_id, './cfg/live24.cfg');
} else if (game_mode == "3") {
execute_cfg_on_server(server_id, './cfg/live_competitive_24.cfg');
} else if (game_sel == "3") {
await rcon.execute_command(server_id, `game_mode 1`);
execute_cfg_on_server(server_id, './cfg/live_casual_16.cfg');
} else if (game_sel == "4") {
await rcon.execute_command(server_id, `game_mode 1`);
execute_cfg_on_server(server_id, './cfg/live_casual_24.cfg');
} else if (game_sel == "5") {
await rcon.execute_command(server_id, `game_mode 2`);
execute_cfg_on_server(server_id, './cfg/live_wingman.cfg');
}
// rcon.rcons[server_id].execute(`mp_warmup_pausetimer 1`);
// rcon.rcons[server_id].execute(`changelevel ${selected_map}`);
await rcon.execute_command(server_id, `mp_warmup_pausetimer 1`);
await rcon.execute_command(server_id, `changelevel ${selected_map}`);
@@ -44,7 +48,7 @@ router.post('/api/setup-game', is_authenticated, async (req, res) => {
execute_cfg_on_server(server_id, './cfg/warmup.cfg');
}, 1000)
//return res.status(200).json({ message: 'Game Created!' });
return res.status(200).json({ message: 'Game Created!' });
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Internal server error' });
@@ -54,9 +58,8 @@ router.post('/api/setup-game', is_authenticated, async (req, res) => {
router.post('/api/restart', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('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) {
console.log(error);
res.status(500).json({ error: 'Internal server error' });
@@ -66,27 +69,10 @@ router.post('/api/restart', is_authenticated, async (req, res) => {
router.post('/api/start-warmup', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('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_restart.cfg');
//return res.status(200).json({ message: 'Warmup started!' });
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Internal server error' });
}
});
router.post('/api/start-knife', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_warmup_end');
// rcon.rcons[server_id].execute('mp_restartgame 1');
await rcon.execute_command(server_id, `mp_warmup_end`);
await rcon.execute_command(server_id, `mp_restartgame 1`);
execute_cfg_on_server(server_id, './cfg/knife.cfg');
//return res.status(200).json({ message: 'Knife started!' });
return res.status(200).json({ message: 'Warmup started!' });
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Internal server error' });
@@ -96,9 +82,8 @@ router.post('/api/start-knife', is_authenticated, async (req, res) => {
router.post('/api/swap-team', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('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) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -107,25 +92,36 @@ router.post('/api/swap-team', is_authenticated, async (req, res) => {
router.post('/api/go-live', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('mp_warmup_end');
await rcon.execute_command(server_id, `mp_warmup_end`);
// const response = await rcon.rcons[server_id].execute('game_mode');
const response = await rcon.execute_command(server_id, `game_mode`);
const game_mode = response.split("=")[1].trim().toString();
if (game_mode == "1") {
console.log("Executing live16.cfg")
execute_cfg_on_server(server_id, './cfg/live16.cfg');
response = await rcon.execute_command(server_id, `game_type`);
const game_type = response.split("=")[1].trim().toString();
response = await rcon.execute_command(server_id, `mp_maxrounds`);
const maxrounds = response.split("=")[1].trim().toString();
if (game_mode == "1" && maxrounds == "16") {
console.log("Executing live_competitive_16.cfg")
execute_cfg_on_server(server_id, './cfg/live_competitive_16.cfg');
} else if (game_mode == "1" && maxrounds == "24") {
console.log("Executing live_competitive_24.cfg")
execute_cfg_on_server(server_id, './cfg/live_competitive_24.cfg');
} else if (game_mode == "0" && maxrounds == "16") {
console.log("Executing live_casual_16.cfg")
execute_cfg_on_server(server_id, './cfg/live_casual_16.cfg');
} else if (game_mode == "0" && maxrounds == "24") {
console.log("Executing live_casual_24.cfg")
execute_cfg_on_server(server_id, './cfg/live_casual_24.cfg');
} else if (game_mode == "2") {
console.log("Executing live24.cfg")
execute_cfg_on_server(server_id, './cfg/live24.cfg');
} else if (game_mode == "3") {
console.log("Executing live_wingman.cfg")
execute_cfg_on_server(server_id, './cfg/live_wingman.cfg');
}
// rcon.rcons[server_id].execute('mp_restartgame 1');
await rcon.execute_command(server_id, `mp_restartgame 1`);
//return res.status(200).json({ message: 'Match is live!!' });
execute_cfg_on_server(server_id, './cfg/live_restart.cfg');
return res.status(200).json({ message: 'Match is live!!' });
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Internal server error' });
@@ -136,10 +132,9 @@ router.post('/api/go-live', is_authenticated, async (req, res) => {
router.post('/api/list-backups', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// 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");
console.log('Server response:', response);
//return res.status(200).json({ message: response });
return res.status(200).json({ message: response });
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Internal server error' });
@@ -155,11 +150,9 @@ router.post('/api/restore-round', is_authenticated, async (req, res) => {
round_number = "0" + round_number;
}
console.log(`SENDING mp_backup_restore_load_file backup_round${round_number}.txt`)
// rcon.rcons[server_id].execute(`mp_backup_restore_load_file backup_round${round_number}.txt`);
// 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_pause_match`);
//return res.status(200).json({ message: 'Round Restored!' });
return res.status(200).json({ message: 'Round Restored!' });
} catch (error) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -168,17 +161,14 @@ router.post('/api/restore-round', is_authenticated, async (req, res) => {
router.post('/api/restore-latest-backup', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// const response = await rcon.rcons[server_id].execute('mp_backup_round_file_last');
const response = await rcon.execute_command(server_id, `mp_backup_round_file_last`);
const last_round_file = response.split("=")[1].trim().toString();
if (last_round_file.includes('.txt')) {
// rcon.rcons[server_id].execute(`mp_backup_restore_load_file ${last_round_file}`);
// 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_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 {
//return res.status(200).json({ message: 'No latest backup found!' });
return res.status(200).json({ message: 'No latest backup found!' });
}
} catch (error) {
@@ -191,9 +181,8 @@ router.post('/api/restore-latest-backup', is_authenticated, async (req, res) =>
router.post('/api/pause', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('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) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -203,9 +192,8 @@ router.post('/api/pause', is_authenticated, async (req, res) => {
router.post('/api/unpause', is_authenticated, async (req, res) => {
try {
const server_id = req.body.server_id;
// rcon.rcons[server_id].execute('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) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -219,10 +207,10 @@ router.post('/api/rcon', is_authenticated, async (req, res) => {
const response = await rcon.execute_command(server_id, command);
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) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -234,7 +222,7 @@ router.post('/api/say-admin', is_authenticated, async (req, res) => {
const message = req.body.message;
const message_to_send = "say " + message;
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) {
res.status(500).json({ error: 'Internal server error' });
}
@@ -310,7 +298,6 @@ async function execute_cfg_on_server(server_id, cfg_path) {
try {
if (item < exported_lines.length) {
console.log("Executing on server:", exported_lines[item]);
// rcon.rcons[server_id].execute(exported_lines[item]);
await rcon.execute_command(server_id, exported_lines[item]);
// Wait for 100ms before moving to the next iteration