From d0a1d7baa2233a51c32e26df8df02fe1e8af8a7b Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 8 Jan 2021 06:34:56 -0600 Subject: [PATCH] Use command handlers instead of event --- scripts/server/command.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/server/command.js b/scripts/server/command.js index 1b3596d6..ff61bf9a 100644 --- a/scripts/server/command.js +++ b/scripts/server/command.js @@ -28,6 +28,7 @@ let builtInCommands = [ function initCommandScript() { logToConsole(LOG_DEBUG, "[Asshat.Command]: Initializing commands script ..."); serverCommands = loadCommands(); + addAllCommandHandlers(); logToConsole(LOG_DEBUG, "[Asshat.Command]: Initialized commands script!"); } @@ -148,8 +149,11 @@ function loadCommands() { commandData("ccode", executeClientCodeCommand, "", getStaffFlagValue("developer"), true, true), commandData("gmx", restartGameModeCommand, "", getStaffFlagValue("developer"), true, true), commandData("saveall", saveAllServerDataCommand, "", getStaffFlagValue("developer"), true, true), - commandData("docmd", simulateCommandForPlayer, " [params]", getStaffFlagValue("developer"), true, true), - commandData("docmdall", simulateCommandForAllPlayers, " [params]", getStaffFlagValue("developer"), true, true), + commandData("docmd", simulateCommandForPlayerCommand, " [params]", getStaffFlagValue("developer"), true, true), + commandData("docmdall", simulateCommandForAllPlayersCommand, " [params]", getStaffFlagValue("developer"), true, true), + commandData("docmdall", simulateCommandForAllPlayersCommand, " [params]", getStaffFlagValue("developer"), true, true), + commandData("addloglvl", addServerLogLevelCommand, "", getStaffFlagValue("developer"), true, true), + commandData("delloglvl", removeServerLogLevelCommand, "", getStaffFlagValue("developer"), true, true), ], discord: [], help: [ @@ -305,11 +309,18 @@ function loadCommands() { commandData("vehcolour", setVehicleColourCommand, " ", getStaffFlagValue("none"), true, true), commandData("vehrepair", vehicleRepairCommand, "", getStaffFlagValue("none"), true, true), commandData("passenger", enterVehicleAsPassengerCommand, "", getStaffFlagValue("none"), true, true), - ], }; } +function addAllCommandHandlers() { + for(let i in serverCommands) { + for(let j in serverCommands[i]) { + addCommandHandler(serverCommands[i][j].command, processPlayerCommand); + } + } +} + // --------------------------------------------------------------------------- function getCommand(command) { @@ -457,7 +468,7 @@ function enableAllCommandsByType(command, params, client) { // --------------------------------------------------------------------------- function onPlayerCommand(event, client, command, params) { - processPlayerCommand(command, params, client) + //processPlayerCommand(command, params, client) } addEventHandler("OnPlayerCommand", onPlayerCommand); @@ -503,10 +514,12 @@ function processPlayerCommand(command, params, client) { // } //} - if(!doesPlayerHaveStaffPermission(client, getCommandRequiredPermissions(toLowerCase(command)))) { - console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (no permission): /${command} ${paramsDisplay}`); - messagePlayerError(client, `You do not have permission to use the [#AAAAAA]/${toLowerCase(command)} [#FFFFFF]command!`); - return false; + if(!client.console) { + if(!doesPlayerHaveStaffPermission(client, getCommandRequiredPermissions(toLowerCase(command)))) { + console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (no permission): /${command} ${paramsDisplay}`); + messagePlayerError(client, `You do not have permission to use the [#AAAAAA]/${toLowerCase(command)} [#FFFFFF]command!`); + return false; + } } logToConsole(LOG_DEBUG, `[Asshat.Command] ${getPlayerDisplayForConsole(client)} used command: /${command} ${paramsDisplay}`);