Welcome to lark3ri.com

Protection code for random kick votes

I wrote this addition to the Xonotic source code. This is added to both of my Xonotic servers. This addition prevents random players from kick voting me out of the server when i'm afk in my server. More player crypto_id values can be added to the sv_protected_players to prevent players to ever kick vote those players out of the server. First it was just a chatbot but it has many flaws. The chatbot was written in bash, it read the Xonotic server log file and worked based on that. I had a hard time to create a working regex code that would work on it so that it can not be manipulated through the player name text. Now this is straight addition to the Xonotic source code and simple and straightforward also in the code side.

The problem is that everybody can run multiple instances of the Xonotic game and join in the server with all of those instances at the same time. With all of those instances connected it is bossible to get votes through. Now with this addition, when someone tries to kick a player out which is in the variable sv_protected_players list, the code will reverse the kick and it start a vote to kick the voter itself out instead.

If you wanna add this code to your Xonotic server, follow these steps. Firstly you need to add the vote.qh code addition to the end of the file vote.qh and add players crypto_id values to the variable sv_protected_players to your server config file.

Separated by spaces like this sv_protected_players "crypto_id crypto_id crypto_id". You can find connected players crypto_id values by using who command.

Secondly you need to add the vote.qc code addition to the file vote.qc exactly under the line 714. The exact line number may change over time when the file got updates. The exact position should be inside and at the end of the if statement if (accepted > 0). Now you can recompile the server code by using this command ./all compile -r dedicated.

vote.qh
string autocvar_sv_protected_players;
string autocvar_sv_protected_players;
string autocvar_sv_protected_players;

vote.qc
if (etof(caller) == 0
|| !autocvar_sv_protected_players
|| autocvar_sv_protected_players == "")
{
break;
}
string identity_key = victim.playerstats_id;
if (identity_key == "")
{
identity_key = victim.crypto_idfp;
}
if (identity_key == "")
{
break;
}
float n = tokenizebyseparator(autocvar_sv_protected_players, " ");
float i;
for (i = 0; i < n; i++)
{
string protected_player_id = argv(i);
if (identity_key == protected_player_id)
{
string voter_caller_name = strzone(GetCallerName(caller));
int voter_caller_id = etof(caller);
GameLogEcho(sprintf("^2* ^1REVERSE KICK VOTE ^3%s ^2tried to call a vote for ^1kick ^1#%d ^3%s",
voter_caller_name,
etof(victim),
victim.netname));
vote_parsed_command = strcat(first_command, " # ", ftos(voter_caller_id), " ", command_arguments);
vote_parsed_display = sprintf("^1%s #%d ^7%s^1 %s", first_command, voter_caller_id, voter_caller_name, reason);
break;
}
}
if (etof(caller) == 0 || !autocvar_sv_protected_players || autocvar_sv_protected_players == "") { break; } string identity_key = victim.playerstats_id; if (identity_key == "") { identity_key = victim.crypto_idfp; } if (identity_key == "") { break; } float n = tokenizebyseparator(autocvar_sv_protected_players, " "); float i; for (i = 0; i < n; i++) { string protected_player_id = argv(i); if (identity_key == protected_player_id) { string voter_caller_name = strzone(GetCallerName(caller)); int voter_caller_id = etof(caller); GameLogEcho(sprintf("^2* ^1REVERSE KICK VOTE ^3%s ^2tried to call a vote for ^1kick ^1#%d ^3%s", voter_caller_name, etof(victim), victim.netname)); vote_parsed_command = strcat(first_command, " # ", ftos(voter_caller_id), " ", command_arguments); vote_parsed_display = sprintf("^1%s #%d ^7%s^1 %s", first_command, voter_caller_id, voter_caller_name, reason); break; } }
if (etof(caller) == 0
        || !autocvar_sv_protected_players
        || autocvar_sv_protected_players == "")
    {
        break;
    }
    
    string identity_key = victim.playerstats_id;
    if (identity_key == "")
    {
        identity_key = victim.crypto_idfp;
    }
    if (identity_key == "")
    {
        break;
    }
    
    float n = tokenizebyseparator(autocvar_sv_protected_players, " ");
    float i;
    for (i = 0; i < n; i++)
    {
        string protected_player_id = argv(i);
        if (identity_key == protected_player_id)
        {
            string voter_caller_name = strzone(GetCallerName(caller));
            int voter_caller_id = etof(caller);
    
            GameLogEcho(sprintf("^2* ^1REVERSE KICK VOTE ^3%s ^2tried to call a vote for ^1kick ^1#%d ^3%s",
                voter_caller_name,
                etof(victim),
                victim.netname));
    
            vote_parsed_command = strcat(first_command, " # ", ftos(voter_caller_id), " ", command_arguments);
            vote_parsed_display = sprintf("^1%s #%d ^7%s^1 %s", first_command, voter_caller_id, voter_caller_name, reason);
    
            break;
        }
    }
    
« Back | ↑ Top