gema
Would you like to react to this message? Create an account in a few clicks or log in to continue.


A website for every gema-assaultcube fan
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log in  

 

 [Lua] Working Anti-Cheat script

Go down 
5 posters
AuthorMessage
UKnowMe?




Messages : 51
Joined/Date d'inscription : 2012-10-08
Location/Localisation : Germany

Gema stats
farthest jump:

[Lua] Working Anti-Cheat script Empty
PostSubject: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script EmptySun Jan 03, 2016 2:04 pm

So today I wrote a little script which detects some basic cheats (nadehack and ammohack, to be specific)
Just put it into the lua/scripts directory and reload the server.

Code:
PLUGIN_NAME = "Basic Anti-Cheat for AssaultCube"
PLUGIN_AUTHOR = "UKnowMe?"
PLUGIN_VERSION = "1.0.1"

local configuration = {
    ban_time = 1200000
}
-- values taken from server.h.cpp, will probably break in next release
-- format: refill_size, max_reserve, magsize
local guninfo = {
    [GUN_KNIFE]   = {  1,  1,  1},
    [GUN_PISTOL]  = { 20,100, 10},
    [GUN_CARBINE] = { 15, 30, 10},
    [GUN_SHOTGUN] = { 14, 21,  7},
    [GUN_SUBGUN]  = { 60, 90, 30},
    [GUN_SNIPER]  = { 10, 15,  5},
    [GUN_ASSAULT] = { 40, 60, 20},
    [GUN_CPISTOL] = { 30, 75, 15},
    [GUN_GRENADE] = {  1,  3,  1},
    [GUN_AKIMBO]  = {100,100, 20}
}
local player_information = {}

-- helper functions

function banclient(cn, reason)
    clientprint(-1, "\f3Player " .. getname(cn) .. " has " .. reason .. ", auto-banning " .. getip(cn))
    logline(ACLOG_INFO, reason .. " detected on player " .. getname(cn) .. " auto-banning...")
    ban(cn, configuration['ban_time'], BAN_AUTO)
end

-- handlers

function onInit()
    for cn in players(true) do
        onPlayerSpawn(cn)
        onPlayerWeaponChange(cn, getweapon(cn))
        player_information[cn]['nades'] = getammo(GUN_GRENADE)
    end
end

function onPlayerSpawn(cn)
    player_information[cn] = {
        nades = 0,
        akimbo = false,
        ammo = {}
    }
end

function onPlayerWeaponChange(cn, weapon)
    if weapon ~= GUN_KNIFE and weapon ~= GUN_GRENADE then
        if player_information[cn]['ammo'][weapon] == nil or next(player_information[cn]['ammo'][weapon]) == nil then
            player_information[cn]['ammo'][weapon] = {}
            player_information[cn]['ammo'][weapon]['reserve'], player_information[cn]['ammo'][weapon]['mag'] = getammo(cn, weapon)
        end
    end
end

function onPlayerShoot(cn, gun, to)
    if gun == GUN_GRENADE then
        if player_information[cn]['nades'] == 0 then
            banclient(cn, 'nadehack')
        else
            player_information[cn]['nades'] = player_information[cn]['nades'] - 1
        end
    end
end

function onPlayerShootAfter(cn, gun, to)
    if gun ~= GUN_KNIFE and gun ~= GUN_GRENADE then
        local reserve, mag = getammo(cn, gun)
        if player_information[cn]['ammo'][gun]['mag'] == 0 then
            banclient(cn, 'ammohack')
        else
            player_information[cn]['ammo'][gun]['mag'] = player_information[cn]['ammo'][gun]['mag'] - 1
        end
    end
end

function onPlayerItemPickup(cn, item_type, item_id)
    if item_type == I_GRENADE then
        player_information[cn]['nades'] = math.min(player_information[cn]['nades'] + (getgamemode() == GM_LSS and 2 or 1), guninfo[GUN_GRENADE][2])
    elseif item_type == I_AMMO then
        local gun = getprimary(cn)
        local info = guninfo[gun]
        player_information[cn]['ammo'][gun]['reserve'] = math.min(player_information[cn]['ammo'][gun]['reserve'] + info[1], info[2])
    elseif item_type == I_CLIPS then
        local gun = player_information[cn]['akimbo'] and GUN_AKIMBO or GUN_PISTOL
        local info = guninfo[gun]
        player_information[cn]['ammo'][gun]['reserve'] = math.min(player_information[cn]['ammo'][gun]['reserve'] + info[1], info[2])
    end
end

function onPlayerWeaponReload(cn, gun)
    if player_information[cn]['ammo'][gun]['reserve'] == 0 then
        banclient(cn, 'ammohack')
    end

    local current = player_information[cn]['ammo'][gun]['mag']
    local info = guninfo[gun]
    local fill = math.min(info[3] - current, player_information[cn]['ammo'][gun]['reserve'])
    player_information[cn]['ammo'][gun]['mag'] = player_information[cn]['ammo'][gun]['mag'] + fill
    player_information[cn]['ammo'][gun]['reserve'] = player_information[cn]['ammo'][gun]['reserve'] - fill
end

function clearAkimbo(timerid)
    player_information[timerid]['akimbo'] = false
end

function onPlayerGetAkimbo(cn)
    player_information[cn]['akimbo'] = true
    tmr.after(cn, 30000, clearAkimbo)
end

function onPlayerDisconnect(cn, reason)
    player_information[cn] = nil
    tmr.remove(cn)
end


Last edited by UKnowMe? on Sat Jan 09, 2016 7:27 am; edited 1 time in total (Reason for editing : Fixed nadehack detection after reload)
Back to top Go down
|HP|
Admin
|HP|


Messages : 226
Joined/Date d'inscription : 2010-06-01

Gema stats
farthest jump: MAX

[Lua] Working Anti-Cheat script Empty
PostSubject: Re: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script EmptyMon Jan 04, 2016 2:24 pm

nice thx
Back to top Go down
Sponsored content

Sponsored content


Messages : 56
Joined/Date d'inscription : 2014-12-06

[Lua] Working Anti-Cheat script Empty
PostSubject: Re: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script EmptyFri Jan 15, 2016 8:51 pm

halts maul.
Back to top Go down
JagArNoob!!!

JagArNoob!!!


Messages : 48
Joined/Date d'inscription : 2015-06-28
Age : 28
Location/Localisation : Rio de Janeiro - Brazil

Gema stats
farthest jump: almost 6 cubes

[Lua] Working Anti-Cheat script Empty
PostSubject: Re: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script EmptySun Jan 31, 2016 4:57 pm

nice
Back to top Go down
vahe

vahe


Messages : 4
Joined/Date d'inscription : 2016-08-24
Age : 36
Location/Localisation : Armenia

[Lua] Working Anti-Cheat script Empty
PostSubject: Re: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script EmptySun Aug 28, 2016 9:53 pm

thanks!
Back to top Go down
https://վահե.հայ/
Sponsored content





[Lua] Working Anti-Cheat script Empty
PostSubject: Re: [Lua] Working Anti-Cheat script   [Lua] Working Anti-Cheat script Empty

Back to top Go down
 
[Lua] Working Anti-Cheat script
Back to top 
Page 1 of 1
 Similar topics
-
» Force Script
» LUA mod for 1.2 - Tested And Working
» AFK Script
» Ask us for a script
» Admin Script

Permissions in this forum:You cannot reply to topics in this forum
gema :: International :: Scripts-
Jump to: