English Banning players with serverCommand issue

  • Auteur de la discussion Auteur de la discussion AltisLifeDev
  • Date de début Date de début
17/4/23
16
2
1
100
Here is my script
C++:
Développer Réduire Copier
#include "\life_server\script_macros.hpp"
/*
    File: fn_banAndLog.sqf
    Description:
    Bans a player and logs the event to the database.

    Parameters:
        0: OBJECT (Player to be banned)
        1: STRING (Reason for the ban)

        if ((_cheater getVariable ["life_adminlevel", 0]) > 0) exitWith {
    diag_log format ["Server Tried To Ban Admin: %1", _cheater];
};
*/
params ["_cheater", "_banReason"];
if (isNull _cheater) exitWith {diag_log format ["isNull: %1", _cheater];};
if (!isPlayer _cheater) exitWith {};
if (isNil "_banReason") then { _banReason = "No reason provided"; };

_cheaterID = getPlayerUID _cheater;
_cheaterName = name _cheater;

// Create the ban command
_banCommand = format ['#exec ban %1', _cheaterID];

diag_log format ["Executing ban command: %1", _banCommand];

// Execute the ban command on the server
if (isServer) then {
    private _result = serverCommand _banCommand;
    diag_log format ["Ban command result: %1", _result];
    if (!_result) then {
        hint "Ban command failed.";
    } else {
        hint "Player banned successfully.";
        diag_log format ["Player: %1 (UID: %2) has been banned for: %3", _cheaterName, _cheaterID, _banReason];
        private _query = format [ // Prepare SQL query
            "INSERT INTO ban_log (cheater_name, cheater_uid, ban_reason) VALUES ('%1', '%2', '%3')",
            _cheaterName, _cheaterID, _banReason
        ];
        [_query, 1, false] call DB_fnc_asyncCall;

        // Optional: Notify admins or log to an additional logging service
        [profileName,format ["Player Banned: %1",_banReason]] remoteExec ["SPY_fnc_notifyAdmins",RCLIENT];
    };
};
The issue I have
C++:
Développer Réduire Copier
2024/07/12,  8:30:52 "Executing ban command: #exec ban 76561198166293192"
2024/07/12,  8:30:52 "Ban command result: false"
2024/07/12,  8:30:52 "SPYGLASS-FLAG: MRWick : 76561198166293192 : speed_hack"
 
Solution
Got it working with this update :
fn_banplayer.sqf:
Développer Réduire Copier
/*
    File: fn_banplayer.sqf
    Description:
    Bans a player and logs the event to the database.

    Parameters:
        0: OBJECT (Player to be banned)
        1: STRING (Reason for the ban)
*/

// Validate parameters
params ["_cheater", "_banReason"];
if (!isPlayer _cheater) exitWith {};
if (isNil "_banReason") then { _banReason = "No reason provided"; };

_cheatID = getPlayerUID _cheater;
_cheaterName = name _cheater;

format['#exec ban "%1"', _cheatID] call TON_fnc_sendCommand;

diag_log format ["Player: %1 (UID: %2) has been banned for: %3", _cheaterName, _cheatID, _banReason];
private _query = format [ // Prepare SQL query
    "INSERT INTO ban_log (cheater_name, cheater_uid, ban_reason)...
--- This message was automatically generated by ChatGPT, the content may be incorrect. Please read the message with precautions! ---

It seems like the ban command is returning false, indicating a failure. This could be due to incorrect permissions or issues with the ban execution. Check if the server has the necessary permissions to execute ban commands. Also, ensure the player's unique ID is correct and that there are no syntax errors in the ban command. Review the ban script logic and verify that all conditions are met before executing the ban. Double-check the formatting and syntax of the ban command to ensure it's valid. Feel free to reach out if you need further assistance with debugging the ban process.

--- To continue the discussion with ChatGPT, click "Reply" at the bottom right of this message. Otherwise, wait for someone to reply. ---
 
If player is cough then this is ran
C++:
Développer Réduire Copier
[player, "Unknown Addon Patches"] remoteExecCall ["TON_fnc_banPlayer", 2];

Inside my CfgRemoteExec.hpp I have added:
Code:
Développer Réduire Copier
F(TON_fnc_banPlayer,SERVER)
 
Okay I changed my script around and the command works but dose not ban the player but kicking dose work.
C++:
Développer Réduire Copier
2024/07/12, 10:43:25 "Player: IceEagle132 (UID: 76561198166293192) has been banned for: Player Speed Hack"
2024/07/12, 10:43:25 "SPYGLASS-FLAG: IceEagle132 : 76561198166293192 : speed_hack"
2024/07/12, 10:43:25 Successfull attempt to execute serverCommand '#exec ban 76561198166293192' by server.

fn_banplayer.sqf:
Développer Réduire Copier
/*
    File: fn_banplayer.sqf
    Description:
    Bans a player and logs the event to the database.

    Parameters:
        0: OBJECT (Player to be banned)
        1: STRING (Reason for the ban)
*/

// Validate parameters
params ["_cheater", "_banReason"];
if (!isPlayer _cheater) exitWith {};
if (isNil "_banReason") then { _banReason = "No reason provided"; };

_cheatID = getPlayerUID _cheater;
_cheaterName = name _cheater;

format['#exec ban %1',_cheatID] call TON_fnc_sendCommand;

diag_log format ["Player: %1 (UID: %2) has been banned for: %3", _cheaterName, _cheatID, _banReason];
private _query = format [ // Prepare SQL query
    "INSERT INTO ban_log (cheater_name, cheater_uid, ban_reason) VALUES ('%1', '%2', '%3')",
    _cheaterName, _cheatID, _banReason
];
[_query, 1, false] call DB_fnc_asyncCall;


fn_sendCommand.sqf:
Développer Réduire Copier
#include "\life_server\script_macros.hpp"
/*
    File: fn_sendCommand.sqf
    Description: Sends a server command with a password.
*/
 
private["_command","_password","_return"];  // Declare private variables
_command = _this;  // Assign the input parameter (the command) to _command
_password = "ComplexServerCmdPass456!";  // Set the server command password

// If the password is empty (this condition will never be true with the hard-coded password)
if (_password isEqualTo "") then {
    _password = "empty";  // Set the password to "empty" if it was empty
};

// Execute the server command with the password and store the result in _return
_return = _password serverCommand _command;

_return;
 
Got it working with this update :
fn_banplayer.sqf:
Développer Réduire Copier
/*
    File: fn_banplayer.sqf
    Description:
    Bans a player and logs the event to the database.

    Parameters:
        0: OBJECT (Player to be banned)
        1: STRING (Reason for the ban)
*/

// Validate parameters
params ["_cheater", "_banReason"];
if (!isPlayer _cheater) exitWith {};
if (isNil "_banReason") then { _banReason = "No reason provided"; };

_cheatID = getPlayerUID _cheater;
_cheaterName = name _cheater;

format['#exec ban "%1"', _cheatID] call TON_fnc_sendCommand;

diag_log format ["Player: %1 (UID: %2) has been banned for: %3", _cheaterName, _cheatID, _banReason];
private _query = format [ // Prepare SQL query
    "INSERT INTO ban_log (cheater_name, cheater_uid, ban_reason) VALUES ('%1', '%2', '%3')",
    _cheaterName, _cheatID, _banReason
];
[_query, 1, false] call DB_fnc_asyncCall;
 
Solution
Activité
Pour l'instant, il n'y a personne ici