Added basic reserved slots plugin, finally...
Added basic reserved slots plugin, finally...
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/reservedslots.sp Wed Jun 20 08:48:11 2007 +0000
1.3 @@ -0,0 +1,100 @@
1.4 +/**
1.5 + * reservedslots.sp
1.6 + * Provides basic reserved slots.
1.7 + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.22 + *
1.23 + * Version: $Id$
1.24 + */
1.25 +
1.26 +#pragma semicolon 1
1.27 +
1.28 +#include <sourcemod>
1.29 +
1.30 +public Plugin:myinfo =
1.31 +{
1.32 + name = "Reserved Slots",
1.33 + author = "AlliedModders LLC",
1.34 + description = "Provides basic reserved slots",
1.35 + version = SOURCEMOD_VERSION,
1.36 + url = "http://www.sourcemod.net/"
1.37 +};
1.38 +
1.39 +/* Maximum number of clients that can connect to server */
1.40 +new g_MaxClients;
1.41 +
1.42 +/* Handles to convars used by plugin */
1.43 +new Handle:sm_reserved_slots;
1.44 +new Handle:sm_hide_slots;
1.45 +new Handle:sv_visiblemaxplayers;
1.46 +
1.47 +public OnPluginStart()
1.48 +{
1.49 + LoadTranslations("plugin.reservedslots.cfg");
1.50 +
1.51 + sm_reserved_slots = CreateConVar("sm_reserved_slots", "0", "Number of reserved player slots", 0, true, 0.0);
1.52 + 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);
1.53 + sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers");
1.54 +}
1.55 +
1.56 +public OnMapStart()
1.57 +{
1.58 + g_MaxClients = GetMaxClients();
1.59 +}
1.60 +
1.61 +public OnConfigsExecuted()
1.62 +{
1.63 + if (GetConVarBool(sm_hide_slots))
1.64 + {
1.65 + SetConVarInt(sv_visiblemaxplayers, g_MaxClients - GetConVarInt(sm_reserved_slots));
1.66 + }
1.67 +}
1.68 +
1.69 +public OnClientAuthorized(client, const String:auth[])
1.70 +{
1.71 + new reserved = GetConVarInt(sm_reserved_slots);
1.72 +
1.73 + if (reserved > 0)
1.74 + {
1.75 + new clients = GetClientCount(false);
1.76 + new limit = g_MaxClients - reserved;
1.77 + new flags = GetUserFlagBits(client);
1.78 +
1.79 + if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION || clients <= limit)
1.80 + {
1.81 + if (GetConVarBool(sm_hide_slots))
1.82 + {
1.83 + SetConVarInt(sv_visiblemaxplayers, (clients == g_MaxClients) ? g_MaxClients : ++limit);
1.84 + }
1.85 +
1.86 + return;
1.87 + }
1.88 +
1.89 + /* Kick player because there are no public slots left */
1.90 + ServerCommand("kickid %s %T", auth, "Slot reserved", client);
1.91 + }
1.92 +}
1.93 +
1.94 +public OnClientDisconnect(client)
1.95 +{
1.96 + if (GetConVarBool(sm_hide_slots))
1.97 + {
1.98 + new clients = GetClientCount(false);
1.99 + new limit = g_MaxClients - GetConVarInt(sm_reserved_slots);
1.100 +
1.101 + SetConVarInt(sv_visiblemaxplayers, (clients == g_MaxClients) ? g_MaxClients : limit);
1.102 + }
1.103 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/translations/plugin.reservedslots.cfg Wed Jun 20 08:48:11 2007 +0000
2.3 @@ -0,0 +1,7 @@
2.4 +"Phrases"
2.5 +{
2.6 + "Slot reserved"
2.7 + {
2.8 + "en" "Dropped to due to slot reservation"
2.9 + }
2.10 +}