I made new version, but I don't want make new topic of this.
This plugin works in any game.
I included
@Spirit_12 admin check. It's not good but it's something.
Player steamid type depends by game... example TF2 use
[U:1:28327177] if I remember right.
Change
AuthId_Engine to
AuthId_Steam2 if you get trouble and want use normal steamid type
STEAM_0:1:123.
65 seconds is default duration while player can connecting into server. Change that bigger if you like.
Cvar
kickloadstuckers_duration min. value is 60 seconds.
- I wanted avoid problems when plugin users use too small value. New players could download server files which take also time.
Code:
Admin command:
"sm_kickloading" - Kick all players who are connecting into server but are not yet in game.
Plugin ConVar:
"kickloadstuckers_duration" = "65.0" min. 60.000000 - Kick player after this many second if they still connecting to server
PHP Code:
public Plugin myinfo =
{
name = "Kick Loading",
author = "Bacardi",
description = "Kick connecting players if takes too long",
version = "18.8.2022",
url = "http://www.sourcemod.net/"
};
ConVar kickloadstuckers_duration;
Handle playertimers[MAXPLAYERS+1];
public void OnPluginStart()
{
LoadTranslations("common.phrases");
RegAdminCmd("sm_kickloading", kickloading, ADMFLAG_KICK, "Kick all players who are connecting into server but are not yet in game.");
kickloadstuckers_duration = CreateConVar("kickloadstuckers_duration", "65.0", "Kick player after this many second if they still connecting to server", _, true, 60.0);
}
public Action kickloading(int client, int args)
{
bool kicked = false;
for(int i = 1; i <= MaxClients; i++)
{
// Let's skip those who have not timer running
if(playertimers[i] == null)
continue;
// To be safe side, skip these
if(i == client || !IsClientConnected(i) || IsFakeClient(i))
continue;
if(!IsClientInGame(i) && !IsClientInKickQueue(i))
{
kicked = true;
ShowActivity2(client, "[SM]", "Kicked connecting player %N", i);
LogAction(client, i, "Admin \"%L\" kicked connecting player \"%L\"", client, i);
KickClient(i, "Admin kicked connecting players", i);
// Timer should end when player disconnect
}
}
if(!kicked)
ReplyToTargetError(client, COMMAND_TARGET_NONE);
return Plugin_Handled;
}
public void OnClientDisconnect(int client)
{
if(playertimers[client] != null)
delete playertimers[client];
}
public void OnClientPutInServer(int client)
{
if(playertimers[client] != null)
delete playertimers[client];
}
public void OnClientConnected(int client)
{
if(playertimers[client] != null)
delete playertimers[client];
if(IsFakeClient(client))
return;
char steamid[30];
if(GetClientAuthId(client, AuthId_Engine, steamid, sizeof(steamid)))
{
// Find player steamid from admin cache (this is not good method for admin immunity check, but we handle client upon connection...)
if(FindAdminByIdentity(AUTHMETHOD_STEAM, steamid) != INVALID_ADMIN_ID)
return;
}
DataPack pack;
playertimers[client] = CreateDataTimer(kickloadstuckers_duration.FloatValue, TimerKick, pack);
pack.WriteCell(client);
pack.WriteCell(GetClientUserId(client));
pack.Reset();
//PrintToServer(" - TimerKick created %N", client);
}
public Action TimerKick(Handle timer, DataPack pack)
{
int index = pack.ReadCell();
// clear handle first
playertimers[index] = null;
int client = GetClientOfUserId(pack.ReadCell());
// when we not find client index anymore with given userid
if(client == 0)
return Plugin_Continue;
// Player still not in game, player is not in kick queue
if(!IsClientInGame(client) && !IsClientInKickQueue(client))
{
LogAction(0, client, "Kicked. Player \"%L\" connecting time takes longer than %0.0f seconds", client, kickloadstuckers_duration.FloatValue);
ShowActivity(0, "Kicked player %N. Connecting time takes longer than %0.0f seconds", client, kickloadstuckers_duration.FloatValue);
KickClient(client, "Kicked.\nYour connecting time into server takes longer than %0.0f seconds", kickloadstuckers_duration.FloatValue);
}
return Plugin_Continue;
}