English Automatic player ban in script

  • Auteur de la discussion Auteur de la discussion AltisLifeDev
  • Date de début Date de début
17/4/23
16
2
1
100
Inside life_server\Functions\Systems create a file fn_banplayer.sqf
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;

As well fn_sendCommand.sqf
fn_sendCommand.sqf:
Développer Réduire Copier
/*
    File: fn_sendCommand.sqf
    Author:    Extremo DevTeam
    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 = "command password Here";  // 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;

Inside life_server\config.cpp add inside class TON_System
config.cpp:
Développer Réduire Copier
class banPlayer {};
class sendCommand {};

Now go to your mission file and open CfgRemoteExec.hpp and add
CfgRemoteExec.hpp:
Développer Réduire Copier
F(TON_fnc_banPlayer,SERVER)

Here is the table to add to your DB
Code:
Développer Réduire Copier
CREATE TABLE `ban_log` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `cheater_name` VARCHAR(255) NOT NULL,
    `cheater_uid` VARCHAR(20) NOT NULL,
    `ban_reason` TEXT NOT NULL,
    `ban_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
);

Here is how to use the ban function:
Code:
Développer Réduire Copier
[player,"Speed Hacking"] remoteExecCall ["TON_fnc_banPlayer", 2];

Here is an example:

C++:
Développer Réduire Copier
if((getAnimSpeedCoef player) > 1.1) then {
        [profileName,getPlayerUID player,"speed_hack"] remoteExec ["SPY_fnc_cookieJar",RSERV];
        [profileName,"Speed Hacking"] remoteExec ["SPY_fnc_notifyAdmins",RCLIENT];
        [player,"Speed Hacking"] remoteExecCall ["TON_fnc_banPlayer", 2];
        player setAnimSpeedCoef 1;
        sleep 0.5;
    };
 
Activité
Pour l'instant, il n'y a personne ici