Zbot Detection and Kicking

I hate auto-aim, don't you?

I personally hate all bot users of any kind, so I picked pieces and put them together for this code from the Quake2 Coding mailing list from PlanetQuake.

This code checks for the use of "impulse" commands which are necessary in the menu system of the Zbot.  Upon finding someone using the impulse command, it tells the server administrator who the bot user was, and kicks them off the server.  Add in the blue code and take out the pink code.

Note: You will need to add the StuffCMD function to your mod for this tutorial to work.

First, add this external cvar to g_local.h:

extern    cvar_t    *sv_cheats;
extern    cvar_t    *maxclients;
extern    cvar_t    *zk_logonly;

Then open up g_save.c and modify the areas around around initgame so it looks like this:

cvar_t *zk_logonly;

/*
============
InitGame

This will be called when the dll is first loaded, which
only happens when a new game is started or a save game
is loaded.
============
*/
void InitGame (void)
{
    gi.dprintf ("==== InitGame ====\n");

    
zk_logonly = gi.cvar("zk_logonly", "0", CVAR_ARCHIVE);

Next add this to the clientthink function in p_client.c

void ClientThink (edict_t *ent, usercmd_t *ucmd)
{
    gclient_t *client;
    edict_t *other;
    int i, j;
    pmove_t pm;

    
if (ucmd->impulse)
    {
         if (zk_logonly->value)
            gi.dprintf ("[ZKick]: client#%d @ %s is a bot (impulse=%d)\n", (ent-g_edicts)-1, Info_ValueForKey (ent->client->pers.userinfo,"ip"), ucmd->impulse);
        else
        {
             gi.dprintf ("[ZKick]: client#%d @ %s was kicked (impulse=%d)\n", (ent-g_edicts)-1, Info_ValueForKey (ent->client->pers.userinfo,"ip"), ucmd->impulse);
            stuffcmd (ent, "quit\n");
        }
}

This last section is the key to the whole thing.  It checks clients to see if they ever use the impulse commands.  If they do, they are kicked!
Now your mod has a simple form of Zbot detecting and kicking.  You may test this to see if it works by pulling down the console and typing "impulse 1" or something like that.  It should make you quit Quake 2 automatically.

Tutorial by Willi
Quake Style - Tutorials