2007-06-20 10:48:11 +02:00
|
|
|
/**
|
2007-08-15 08:19:30 +02:00
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Reserved Slots Plugin
|
2007-06-20 10:48:11 +02:00
|
|
|
* Provides basic reserved slots.
|
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
2007-06-20 10:48:11 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
2007-06-20 10:48:11 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
2007-06-20 10:48:11 +02:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma semicolon 1
|
|
|
|
|
|
|
|
#include <sourcemod>
|
|
|
|
|
|
|
|
public Plugin:myinfo =
|
|
|
|
{
|
|
|
|
name = "Reserved Slots",
|
|
|
|
author = "AlliedModders LLC",
|
|
|
|
description = "Provides basic reserved slots",
|
|
|
|
version = SOURCEMOD_VERSION,
|
|
|
|
url = "http://www.sourcemod.net/"
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Maximum number of clients that can connect to server */
|
|
|
|
new g_MaxClients;
|
|
|
|
|
|
|
|
/* Handles to convars used by plugin */
|
|
|
|
new Handle:sm_reserved_slots;
|
|
|
|
new Handle:sm_hide_slots;
|
|
|
|
new Handle:sv_visiblemaxplayers;
|
2007-10-21 06:51:57 +02:00
|
|
|
new Handle:sm_reserve_type;
|
2007-06-20 10:48:11 +02:00
|
|
|
|
|
|
|
public OnPluginStart()
|
|
|
|
{
|
2007-07-27 02:34:58 +02:00
|
|
|
LoadTranslations("reservedslots.phrases");
|
2007-06-20 10:48:11 +02:00
|
|
|
|
|
|
|
sm_reserved_slots = CreateConVar("sm_reserved_slots", "0", "Number of reserved player slots", 0, true, 0.0);
|
|
|
|
sm_hide_slots = CreateConVar("sm_hide_slots", "0", "If set to 1, reserved slots will hidden (subtracted from the max slot count)", 0, true, 0.0, true, 1.0);
|
|
|
|
sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers");
|
2007-10-21 06:51:57 +02:00
|
|
|
sm_reserve_type = CreateConVar("sm_reserve_type", "0", "Method of reserving slots", 0, true, 0.0, true, 1.0);
|
2007-11-10 03:00:04 +01:00
|
|
|
|
|
|
|
HookConVarChange(sm_reserved_slots, SlotsChanged);
|
|
|
|
HookConVarChange(sm_hide_slots, SlotsChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
public OnPluginEnd()
|
|
|
|
{
|
|
|
|
/* If the plugin has been unloaded, reset visiblemaxplayers. In the case of the server shutting down this effect will not be visible */
|
|
|
|
SetConVarInt(sv_visiblemaxplayers, g_MaxClients);
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public OnMapStart()
|
|
|
|
{
|
|
|
|
g_MaxClients = GetMaxClients();
|
2007-11-10 03:00:04 +01:00
|
|
|
|
|
|
|
if (GetConVarBool(sm_hide_slots))
|
|
|
|
{
|
|
|
|
SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
|
|
|
|
}
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public OnConfigsExecuted()
|
|
|
|
{
|
|
|
|
if (GetConVarBool(sm_hide_slots))
|
|
|
|
{
|
2007-06-22 05:43:00 +02:00
|
|
|
SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 22:51:54 +01:00
|
|
|
public Action:OnTimedKick(Handle:timer, any:client)
|
|
|
|
{
|
2007-08-19 00:51:25 +02:00
|
|
|
if (!client || !IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
KickClient(client, "%T", "Slot reserved", client);
|
|
|
|
|
2007-11-18 07:25:33 +01:00
|
|
|
if (GetConVarBool(sm_hide_slots))
|
|
|
|
{
|
|
|
|
SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
|
|
|
|
}
|
2007-11-12 22:51:54 +01:00
|
|
|
|
2007-08-19 00:51:25 +02:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2007-08-08 18:22:51 +02:00
|
|
|
public OnClientPostAdminCheck(client)
|
2007-06-20 10:48:11 +02:00
|
|
|
{
|
|
|
|
new reserved = GetConVarInt(sm_reserved_slots);
|
2007-10-21 06:51:57 +02:00
|
|
|
|
2007-06-20 10:48:11 +02:00
|
|
|
if (reserved > 0)
|
|
|
|
{
|
|
|
|
new clients = GetClientCount(false);
|
|
|
|
new limit = g_MaxClients - reserved;
|
|
|
|
new flags = GetUserFlagBits(client);
|
2007-11-12 22:51:54 +01:00
|
|
|
|
|
|
|
new type = GetConVarInt(sm_reserve_type);
|
|
|
|
|
|
|
|
if (type == 0)
|
2007-06-20 10:48:11 +02:00
|
|
|
{
|
2007-11-12 22:51:54 +01:00
|
|
|
if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
|
2007-06-20 10:48:11 +02:00
|
|
|
{
|
2007-11-12 22:51:54 +01:00
|
|
|
if (GetConVarBool(sm_hide_slots))
|
|
|
|
{
|
|
|
|
SetVisibleMaxSlots(clients, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
|
|
|
|
2007-11-12 22:51:54 +01:00
|
|
|
/* Kick player because there are no public slots left */
|
|
|
|
CreateTimer(0.1, OnTimedKick, client);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (clients > limit)
|
|
|
|
{
|
|
|
|
if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
|
2007-10-21 06:51:57 +02:00
|
|
|
{
|
2007-11-12 22:51:54 +01:00
|
|
|
new target = SelectKickClient();
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
/* Kick public player to free the reserved slot again */
|
|
|
|
CreateTimer(0.1, OnTimedKick, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Kick player because there are no public slots left */
|
|
|
|
CreateTimer(0.1, OnTimedKick, client);
|
2007-10-21 06:51:57 +02:00
|
|
|
}
|
|
|
|
}
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 05:43:00 +02:00
|
|
|
public OnClientDisconnect_Post(client)
|
2007-06-20 10:48:11 +02:00
|
|
|
{
|
|
|
|
if (GetConVarBool(sm_hide_slots))
|
2007-06-22 05:43:00 +02:00
|
|
|
{
|
|
|
|
SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-10 03:00:04 +01:00
|
|
|
public SlotsChanged(Handle:convar, const String:oldValue[], const String:newValue[])
|
|
|
|
{
|
|
|
|
/* Reserved slots or hidden slots have been disabled - reset sv_visiblemaxplayers */
|
|
|
|
if (StringToInt(newValue) == 0)
|
|
|
|
{
|
|
|
|
SetConVarInt(sv_visiblemaxplayers, g_MaxClients);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 05:43:00 +02:00
|
|
|
SetVisibleMaxSlots(clients, limit)
|
|
|
|
{
|
2007-11-12 22:51:54 +01:00
|
|
|
new num = clients;
|
2007-06-22 05:43:00 +02:00
|
|
|
|
2007-06-22 06:35:27 +02:00
|
|
|
if (clients == g_MaxClients)
|
2007-06-20 10:48:11 +02:00
|
|
|
{
|
2007-06-22 05:43:00 +02:00
|
|
|
num = g_MaxClients;
|
|
|
|
} else if (clients < limit) {
|
|
|
|
num = limit;
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
2007-06-22 05:43:00 +02:00
|
|
|
|
|
|
|
SetConVarInt(sv_visiblemaxplayers, num);
|
2007-06-20 10:48:11 +02:00
|
|
|
}
|
2007-10-21 06:51:57 +02:00
|
|
|
|
|
|
|
SelectKickClient()
|
|
|
|
{
|
|
|
|
new Float:highestLatency;
|
|
|
|
new highestLatencyId;
|
|
|
|
|
|
|
|
new Float:highestSpecLatency;
|
|
|
|
new highestSpecLatencyId;
|
|
|
|
|
|
|
|
new bool:specFound;
|
|
|
|
|
|
|
|
new Float:latency;
|
|
|
|
|
|
|
|
for (new i=1; i<=g_MaxClients; i++)
|
2007-11-12 22:51:54 +01:00
|
|
|
{
|
2007-10-21 06:51:57 +02:00
|
|
|
if (!IsClientConnected(i))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
new flags = GetUserFlagBits(i);
|
|
|
|
|
2007-11-10 03:03:27 +01:00
|
|
|
if (IsFakeClient(i) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION || CheckCommandAccess(i, "sm_reskick_immunity", ADMFLAG_RESERVATION, false))
|
2007-10-21 06:51:57 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-12 22:51:54 +01:00
|
|
|
|
|
|
|
latency = 0.0;
|
2007-10-21 06:51:57 +02:00
|
|
|
|
|
|
|
if (IsClientInGame(i))
|
2007-11-12 22:51:54 +01:00
|
|
|
{
|
|
|
|
latency = GetClientAvgLatency(i, NetFlow_Outgoing);
|
|
|
|
|
|
|
|
LogMessage("Latency : %f",latency);
|
2007-10-21 06:51:57 +02:00
|
|
|
|
2007-10-21 08:43:03 +02:00
|
|
|
if (IsClientObserver(i))
|
2007-11-12 22:51:54 +01:00
|
|
|
{
|
2007-10-21 06:51:57 +02:00
|
|
|
specFound = true;
|
|
|
|
|
|
|
|
if (latency > highestSpecLatency)
|
|
|
|
{
|
|
|
|
highestSpecLatency = latency;
|
|
|
|
highestSpecLatencyId = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 22:51:54 +01:00
|
|
|
if (latency >= highestLatency)
|
2007-10-21 06:51:57 +02:00
|
|
|
{
|
|
|
|
highestLatency = latency;
|
|
|
|
highestLatencyId = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (specFound)
|
|
|
|
{
|
|
|
|
return highestSpecLatencyId;
|
|
|
|
}
|
|
|
|
|
|
|
|
return highestLatencyId;
|
|
|
|
}
|