...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(1, buffer, sizeof(buffer));
VoteKickData.Push(StringToInt(buffer));
regex.GetSubString(2, buffer, sizeof(buffer));
VoteKickData.Push(StringToInt(buffer));
int target = GetClientOfUserId(VoteKickData.Get(1));
if(target)
{
char identity[60];
if(GetClientAuthId(target, AuthId_Engine, identity, sizeof(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[] name, bool 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(VoteKickData, true);
}
}
// 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", buffer, sizeof(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(delay, command_delay, VoteKickData.Get(1));
ActivateBan(VoteKickData, false);
}
}
VoteKickData.Clear();
}
public Action command_delay(Handle timer, any 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(2, identity, sizeof(identity));
BanIdentity(identity, ban_duration, BANFLAG_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", source, target, identity, ban_duration);
if(playerdisconnect)
{
LogAction(-1, -1, "L4D Vote Kick Passed: Player #%i disconnected during vote kick", target);
}
}
__________________