SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 01/07/2015, 04:42 PM   #31
iTakelot
Gangsta
 
iTakelot's Avatar
 
Join Date: Jun 2015
Posts: 676
Reputation: 30
Default Re: Nex-AC - Anticheat system

Belo trabalho. +PEP
iTakelot is offline   Reply With Quote
Old 01/07/2015, 04:44 PM   #32
Carper
Little Clucker
 
Carper's Avatar
 
Join Date: Oct 2013
Posts: 32
Reputation: 5
Default AW: Nex-AC - Anticheat system

Everything works fine (no more warnings.. Problem was: I have used another outdated includes). Thanks for the release.
Carper is offline   Reply With Quote
Old 01/07/2015, 05:19 PM   #33
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 882
Reputation: 317
Default Re: Nex-AC - Anticheat system

SERIOUS ISSUE: This include won't work with streamer because streamer won't call your functions such as CreatePickup,etc

You need to check if streamer is included and hook CreateDynamic... Functions.

Another thing I noticed is that your OnPlayerUpdate has lot of code.In the worst case with 1000 players playing, the OPU might get called nearly 10000 times and you code is huge and is not well optimized.This might potentially slow down the server drastically.

Suggestions:

To improve readability

1. Compact Big Arrays
It is really annoying to see huge arrays.

Code:
static bool:ACAllow[] =
{
        true,   //0 Anti-AirBreak (onfoot)
        true,   //1 Anti-AirBreak (in vehicle)
        true,   //2 Anti-teleport hack (onfoot)
This is a better way to do the same more programmer friendly

Code:
enum { ANTI_AIRBREAK_OF,ANTI_AIRBREAK_V,ANTI_TELEPORT,... };
static bool:ACAllow [] = { true,true,true,...};
Now you'll never need to remember the array indexes.

2. Use Binary instead of hexadecimal

Instead of this
Code:
0x033C2700
you could have

Code:
0b11001111000010011100000000
so that anyone who is going through your code can see every bit (since you are using bits to store information).

Optimize Code
1. const Arrays
The compiler can make necessary optimizations if it knows that a variable (array) is never changed through out the programs lifetime.

Code:
static const MaxPassengers
2. Unnecessary Arrays
I have no idea how many people I have told about this.

Code:
Float:pSetPos[3]
Why do you need an array here?

More Tips & Tricks Check Tip #2

3. Mass Filling Arrays
Use memset to fill arrays with constant value instead of having a loop.

Code:
AntiCheatInfo[playerid][pWeapon][i] = 0;
AntiCheatInfo[playerid][pAmmo][i] = 0;
Code:
for(i = 27; i != -1; --i) AntiCheatInfo[playerid][pFloodCount][i] = 0;
4. CallLocalFunction is faster than CallRemoteFunction
CallLocalFunction can be sometimes 4x-6x faster than CallRemoteFunction (it completely depends on your code and number of FS loaded).

CallRemoteFunction is used to call a function which is in some other script!!
CallLocalFunction is used to call a function which is in your script!!

5. CallLocalFunction is slower than calling a function directly
Just directly call the function instead of using CallLocalFunction/CallRemoteFunction when you know the function name.

Code:
AntiCheatInfo[playerid][pKicked] = 0;
AntiCheatInfo[playerid][pMoney] = 0;
is slower than

Code:
AntiCheatInfo[playerid][pKicked] = AntiCheatInfo[playerid][pMoney] = 0;
More Tips & Tricks Check Tip #7

6. Do not use loops when no required
This is hilarious
Code:
for(i = 2; i != -1; --i) AntiCheatInfo[playerid][pDropJP][i] = 20001.0;
Why not just
Code:
AntiCheatInfo[playerid][pDropJP][0] = 
AntiCheatInfo[playerid][pDropJP][1] = 
AntiCheatInfo[playerid][pDropJP][2] = 20001.0;
This could be even 10x faster.I am guessing.

Few more
Code:
while(AntiCheatInfo[playerid][pHealth] > health + 255) health += 256;
while(zangle < 0.0) zangle += 360.0;
while(zangle > 360.0) zangle -= 360.0;
for(i = 2; i != -1; --i) AntiCheatInfo[playerid][pPos][i] = ppos[i];
There are still more.These loops were found in OnPlayerUpdate.Since OnPlayerUpdate is called many times you must always try to keep OPU code optimized.

There is an operator called modulus (%) which gives the remainder.

7. Copying Arrays(strings)
Code:
for(i = sizeof(ACAllow) - 1; i != -1; --i) AntiCheatInfo[playerid][pACAllow][i] = ACAllow[i];
For this reason we have memcpy.

Also read More Tips & Tricks >> Tip #4

Actually you can even do this when the sizes are same
Code:
new array1[100];
new array2[100];

array1 = array2;
8. Storing & fetching variables takes time

This is very funny!
Code:
i = 1;
#if defined ac_OnDialogResponse
    i = ac_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#endif
AntiCheatInfo[playerid][pCall][27] = AntiCheatInfo[playerid][pCall][0] = GetTickCount();
return i;
You could have instead done the following

Code:
#if defined ac_OnDialogResponse
    return ac_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#else
return 1;
#endif
8. Static does avoid creating a local but it could be slower sometimes
Code:
static gpp, bool:ur;
        ur = false;
        if(!IsPlayerNPC(playerid))
        {
                gpp = GetPlayerPing(playerid);
is slower than

Code:
new ur = false;
        if(!IsPlayerNPC(playerid))
        {
               new gpp = GetPlayerPing(playerid);
9. You can assign values to a variable while using it in a condition
Code:
stateanim = GetPlayerState(playerid);
                if(stateanim != 9)
is slower than

Code:
 if((stateanim = stateanim = GetPlayerState(playerid)) != 9)
10. NPCs cannot do everything a player can
You don't need

Code:
IsPlayerNPC(playerid)
in some of the callbacks.


11. Do not call the same function repeatedly

Code:
new i = GetTickCount();
.
.
.
AntiCheatInfo[playerid][pCall][27] = AntiCheatInfo[playerid][pCall][17] = GetTickCount();
Calling a function takes some extra time.

12. One Timer is better than 1000 timers
Code:
acTimer(playerid)
Instead, you can make one timer where you iterate through all the players.

13. Bool can take only true/false
Code:
stock EnableAntiCheat(acid, enable)
{
        if(!(-1 < acid < sizeof ACAllow)) return 0;
        ACAllow[acid] = !!enable;
Why !!enable? when you can bool:enable?

Code:
stock EnableAntiCheat(acid, bool:enable)

14. Function calls have some overhead
Code:
static GetSpeed(Float:vX, Float:vY, Float:vZ) return floatround(VectorSize(vX, vY, vZ) * 179.28625);
you could have just

Code:
#define GetSpeed(%0,%1,%2) floatround(VectorSize(%0,%1,%2) * 179.28625);
15. Use arrays instead of lot of cases/ifs
Code:
static IsAirVehicle(modelid);
static IsBikeVehicle(modelid);
static IsBoatVehicle(modelid);
In these functions you can do this

Code:
static const vehicle_type[] = { BOAT,BOAT,CAR,CAR,BIKE,AIR...};
#define IsAirVehicle(%0) (vehicle_type[modelid-400] == AIR)


Portability & Compatibility
1. OnPlayerCommandText
ZCMD and many other command processors do not call this callback after hooking.This callback will never be called if someone includes NEX-AC after zcmd/izcmd/etc.



Other Questions & Suggestions:
1. MAX_PING ? MAX_PING : pping
Code:
SetTimerEx("ac_KickTimer", (pping > MAX_PING ? MAX_PING : pping), false, "i", playerid);
Why do you have such an interval?

2. Make this project at GitHub so that people can contribute
GitHub
Yashas is offline   Reply With Quote
Old 01/07/2015, 06:02 PM   #34
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 607
Reputation: 15
Default Re: Nex-AC - Anticheat system

It was tested or? Nice!
vannesenn is offline   Reply With Quote
Old 01/07/2015, 06:09 PM   #35
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 955
Reputation: 333
Default Re: Nex-AC - Anticheat system

Quote:
Originally Posted by Yashas View Post
Suggestions
I agree with many things, but there are some remarks...
These items brought me the most:

Quote:
Originally Posted by Yashas View Post
4. CallLocalFunction is faster than CallRemoteFunction
CallLocalFunction can be sometimes 4x-6x faster than CallRemoteFunction (it completely depends on your code and number of FS loaded).

CallRemoteFunction is used to call a function which is in some other script!!
CallLocalFunction is used to call a function which is in your script!!
Sure, but you should notice that the anti-cheat should also control each filterscript, so it necessary measures.

Quote:
Originally Posted by Yashas View Post
This is very funny!
Code:
i = 1;
#if defined ac_OnDialogResponse
    i = ac_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#endif
AntiCheatInfo[playerid][pCall][27] = AntiCheatInfo[playerid][pCall][0] = GetTickCount();
return i;
You could have instead done the following

Code:
#if defined ac_OnDialogResponse
    return ac_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
#else
return 1;
#endif
Again, I can not be sure that the called public does not slow down, thereby measuring GetTickCount() will not be accurate at the real time of the completion of a public

Quote:
Originally Posted by Yashas View Post
10. NPCs cannot do everything a player can
You don't need

Code:
IsPlayerNPC(playerid)
in some of the callbacks.
I was very excited when I found out that there be false positives on the NPC, so I analyzed and add these checks in the most correct places... in my opinion (although I'm sure you know better where they are needed, and where there is no)
I hope someone tell me where they should be removed

Quote:
Originally Posted by Yashas View Post
Portability & Compatibility
1. OnPlayerCommandText
ZCMD and many other command processors do not call this callback after hooking.This callback will never be called if someone includes NEX-AC after zcmd/izcmd/etc.
But if connect my anticheat first - the problems will not be: D
And yes, that's what I wrote in the installation instructions

Quote:
Originally Posted by Yashas View Post
Other Questions & Suggestions:
1. MAX_PING ? MAX_PING : pping
Code:
SetTimerEx("ac_KickTimer", (pping > MAX_PING ? MAX_PING : pping), false, "i", playerid);
Why do you have such an interval?
This is the minimum interval that is equal to the player ping (given time only on a send message notifying about kick), thereby unwanted players will not linger on the server longer than they should)

About GitHub:
I agree with this idea, but never with him not worked, and it is unlikely in the near future there a project will be is there (I need time though would be to get used to there)
__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker
OstGot is offline   Reply With Quote
Old 01/07/2015, 06:24 PM   #36
Carper
Little Clucker
 
Carper's Avatar
 
Join Date: Oct 2013
Posts: 32
Reputation: 5
Default AW: Nex-AC - Anticheat system

Github is easy with the client (https://windows.github.com/).
Carper is offline   Reply With Quote
Old 01/07/2015, 07:15 PM   #37
Florentin77
Little Clucker
 
Join Date: Jun 2015
Location: Paris
Posts: 15
Reputation: 8
Default Re: Nex-AC - Anticheat system

Hello,

When I spawn, i'm auto kicked from server for reason Teleport on foot
How can I solve this problem?

Thank you

Flo'
Florentin77 is offline   Reply With Quote
Old 01/07/2015, 07:35 PM   #38
OstGot
Gangsta
 
OstGot's Avatar
 
Join Date: Mar 2013
Location: Gomel, Belarus
Posts: 955
Reputation: 333
Default Re: Nex-AC - Anticheat system

Quote:
Originally Posted by Florentin77 View Post
When I spawn, i'm auto kicked from server for reason Teleport on foot
How can I solve this problem?
I assume you are using GrandLarceny gamemode.
This problem is observed only in this gamemode, but I promise to fix this in next versions.
__________________
aka Nexius
Don't want to always check for updates of my scripts?
Include it the last, after all others
Nexius's Update Checker
OstGot is offline   Reply With Quote
Old 01/07/2015, 07:38 PM   #39
Florentin77
Little Clucker
 
Join Date: Jun 2015
Location: Paris
Posts: 15
Reputation: 8
Default Re: Nex-AC - Anticheat system

I'm not using GrandLarceny GM, it is my own GM, here are the callback OnPlayerSpawn and RequestClassId

OnPlayerRequestClass
PHP Code:
    SpawnPlayer(playerid);
    
PlayerAccount(playerid);
    
TogglePlayerSpectating(playeridtrue);
     
InterpolateCameraPos(playerid2107.6384271616.915649138.3092652039134011430000CAMERA_MOVE);
     
InterpolateCameraLookAt(playerid1996.4848631543.79785129.882118229012834030000CAMERA_MOVE); 
OnPlayerSpawn
PHP Code:
            new rand random(sizeof(RandomSpawn));
            
SetPlayerPos(playeridRandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2]);
            
SetPlayerFacingAngle(playeridRandomSpawn[rand][3]);
            
SetCameraBehindPlayer(playerid);
            
SetTimerEx("AntiSpawnKill"10000false"i"playerid);
               
GivePlayerWeapon(playerid41);
            
GivePlayerWeapon(playerid24200);
            
GivePlayerWeapon(playerid29500);
            
GivePlayerWeapon(playerid30500);
            
SetPlayerHealth(playerid9999);
            
SCM(playeridCOLOR_INFO"[AntiSpawnKill] Vous êtes protégé du spawn kill pour 10 secondes");
            
pInfo[playerid][pConnect] = 1;
            new 
string[64];
            
format(stringsizeof(string), "[Info] %s s'est connecté sur le serveur"pInfo[playerid][pName]);
            
SendClientMessageToAll(COLOR_INFOGRISstring);
            
pInfo[playerid][pCanSpawnCar] = true
Florentin77 is offline   Reply With Quote
Old 01/07/2015, 08:09 PM   #40
J4Rr3x
Big Clucker
 
J4Rr3x's Avatar
 
Join Date: Jan 2014
Location: Palermo, Italy
Posts: 164
Reputation: 18
Default Re: Nex-AC - Anticheat system

Italian language: Pastebin Solidfiles

Very nice anticheat!
J4Rr3x is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working AntiCheat system mrxqware Scripting Help 4 02/05/2014 11:04 AM
[Include] System AntiCheat V1.1 Glad2BeHere Includes 13 04/03/2013 07:33 PM
-AntiCheat System geohareas Scripting Help 5 08/01/2013 06:38 PM
[FilterScript] [FS] ZAdmin v1.0 | ADMIN SYSTEM + REGISTER + ANTICHEAT + ANTIFLOOD + ANTISWEAR. [ZFM]Zuc Filterscripts 24 25/05/2011 09:19 AM


All times are GMT. The time now is 12:19 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.