Thread: Plugin request
View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-24-2022 , 19:50   Re: Plugin request
Reply With Quote #9

...but it works fine on my test server (SRCDS windows). Server use kickid and banid commands after vote.

Don't know.

Check you not have this cvar disabled
sv_banid_enabled
It will stop all ban actions
Code:
banid: disabled on server (sv_banid_enabled = 0)



But here is another version of plugin.
- I have only tested with bots...
- I made big change, use game log system: "log on"


It use game cvars:
sv_vote_kick_ban_duration
sv_vote_command_delay

- These are hidden cvars, you can check cvar using cmd help.
But you can only change cvar value with cmd sm_cvar

Code:
] help sv_vote_kick_ban_duration; help sv_vote_command_delay
"sv_vote_kick_ban_duration" = "5"
 game
 - How long should a kick vote ban someone from the server? (in minutes)
"sv_vote_command_delay" = "2" max. 4.500000
 game
 - How long after a vote passes until the action happens
...and plugin own kick will take action, 1 second later of server normal vote kick, if player is still in server.
PHP Code:

// Plugin works with game log: "log on"


ConVar sv_vote_kick_ban_duration;
ConVar sv_vote_command_delay;

ArrayList VoteKickData;

#include <regex>

Regex regex;


public 
void OnPluginStart()
{
    
//regex = new Regex("^\"\\w+<(\\d+)>.*>\" called vote \"kick (\\d+)\"$");
    
regex = new Regex("^\".*<(\\d+)><STEAM_\\d:\\d:\\d+>(?:<Survivor>|<Infected>).*>\" called vote \"kick (\\d+)\"$");



    
VoteKickData = new ArrayList(ByteCountToCells(60));

    
sv_vote_kick_ban_duration FindConVar("sv_vote_kick_ban_duration");
    
sv_vote_command_delay FindConVar("sv_vote_command_delay");

    
HookEvent("vote_failed"vote_started);
    
HookEvent("vote_passed"vote_started); // details #L4D_vote_passed_kick_player

    
HookEvent("player_disconnect"vote_started);

    
AddGameLogHook(gameloghook);
}


public 
Action gameloghook(const char[] message)
{
    if(
regex.Match(message) == 3)
    {
        
VoteKickData.Clear();

        
char buffer[20];
        
regex.GetSubString(1buffersizeof(buffer));
        
VoteKickData.Push(StringToInt(buffer));

        
regex.GetSubString(2buffersizeof(buffer));
        
VoteKickData.Push(StringToInt(buffer));

        
int target GetClientOfUserId(VoteKickData.Get(1));
        
        if(
target)
        {
            
char identity[60];
            if(
GetClientAuthId(targetAuthId_Engineidentitysizeof(identity)))
            {
                
VoteKickData.PushString(identity);
                
                
PrintToChatAll("[SM] Vote Kick will be successful, if player %N choose to disconnect from server before vote ends."target);
            }
        }
    }

    return 
Plugin_Continue;
}


public 
void vote_started(Event event, const char[] namebool dontBroadcast)
{
    if(
StrEqual(name"player_disconnect"false))
    {
        if(
VoteKickData.Length == 3)
        {
            
// If player disconnect during vote
            
int userid event.GetInt("userid");

            if(
userid == VoteKickData.Get(1))
            {
                
ActivateBan(VoteKickDatatrue);
            }
        }

        
// every player_disconnect events stop here
        
return;
    }
    else if(
StrEqual(name"vote_failed"false))
    {
        
// not needed...
    
}
    else if(
StrEqual(name"vote_passed"false))
    {
        
char buffer[30];
        
event.GetString("details"buffersizeof(buffer), " ");

        if(
StrEqual(buffer"#L4D_vote_passed_kick_player"false)
          && 
VoteKickData.Length == 3)
        {
            
// Final step - vote passed: ban and kick player
            
float delay 3.0;

            if(
sv_vote_command_delay != null)
            {
                
delay sv_vote_command_delay.FloatValue 1.0;
            }
            
            
CreateTimer(delaycommand_delayVoteKickData.Get(1));

            
ActivateBan(VoteKickDatafalse);
        }
    }

    
VoteKickData.Clear();
}

public 
Action command_delay(Handle timerany userid)
{
    
int target GetClientOfUserId(userid);

    
// Works only if client is still in server
    
if(target && IsClientConnected(target) && !IsClientInKickQueue(target))
    {
        
KickClient(target"You have been voted off");
    }

    return 
Plugin_Continue;
}


void ActivateBan(ArrayList &list, bool playerdisconnect)
{
    if(list == 
null || list.Length != 3)
        return;

    
int ban_duration 5;

    
int target = list.Get(1);
    
int source = list.Get(0);

    if(
sv_vote_kick_ban_duration != null)
    {
        
ban_duration sv_vote_kick_ban_duration.IntValue;
        
        if(
ban_duration <= 0)
            
ban_duration 1;
        
        if(
ban_duration 300)
            
ban_duration 300;
    }

    
char identity[60];
    list.
GetString(2identitysizeof(identity));

    
BanIdentity(identityban_durationBANFLAG_AUTHID"You have been voted off""callvote kick"source);

    
// Show players ids as userid, don't know are they in server currently. Use game log files to track they actions on server.
    
LogAction(-1, -1"L4D Vote Kick Passed: Player #%i vote kick #%i.    Ban %s for %i minutes"sourcetargetidentityban_duration);

    if(
playerdisconnect)
    {
        
LogAction(-1, -1"L4D Vote Kick Passed: Player #%i disconnected during vote kick"target);
    }

__________________
Do not Private Message @me

Last edited by Bacardi; 04-25-2022 at 15:32. Reason: update
Bacardi is offline