From f94d08018349e4dc7718fb1247255fb7cf7ccdc5 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Wed, 20 Jun 2007 08:48:11 +0000 Subject: [PATCH] Added basic reserved slots plugin, finally... --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40994 --- plugins/reservedslots.sp | 100 ++++++++++++++++++++++++++ translations/plugin.reservedslots.cfg | 7 ++ 2 files changed, 107 insertions(+) create mode 100644 plugins/reservedslots.sp create mode 100644 translations/plugin.reservedslots.cfg diff --git a/plugins/reservedslots.sp b/plugins/reservedslots.sp new file mode 100644 index 00000000..ab2183e1 --- /dev/null +++ b/plugins/reservedslots.sp @@ -0,0 +1,100 @@ +/** + * reservedslots.sp + * Provides basic reserved slots. + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Version: $Id$ + */ + +#pragma semicolon 1 + +#include + +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; + +public OnPluginStart() +{ + LoadTranslations("plugin.reservedslots.cfg"); + + 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"); +} + +public OnMapStart() +{ + g_MaxClients = GetMaxClients(); +} + +public OnConfigsExecuted() +{ + if (GetConVarBool(sm_hide_slots)) + { + SetConVarInt(sv_visiblemaxplayers, g_MaxClients - GetConVarInt(sm_reserved_slots)); + } +} + +public OnClientAuthorized(client, const String:auth[]) +{ + new reserved = GetConVarInt(sm_reserved_slots); + + if (reserved > 0) + { + new clients = GetClientCount(false); + new limit = g_MaxClients - reserved; + new flags = GetUserFlagBits(client); + + if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION || clients <= limit) + { + if (GetConVarBool(sm_hide_slots)) + { + SetConVarInt(sv_visiblemaxplayers, (clients == g_MaxClients) ? g_MaxClients : ++limit); + } + + return; + } + + /* Kick player because there are no public slots left */ + ServerCommand("kickid %s %T", auth, "Slot reserved", client); + } +} + +public OnClientDisconnect(client) +{ + if (GetConVarBool(sm_hide_slots)) + { + new clients = GetClientCount(false); + new limit = g_MaxClients - GetConVarInt(sm_reserved_slots); + + SetConVarInt(sv_visiblemaxplayers, (clients == g_MaxClients) ? g_MaxClients : limit); + } +} diff --git a/translations/plugin.reservedslots.cfg b/translations/plugin.reservedslots.cfg new file mode 100644 index 00000000..cb261721 --- /dev/null +++ b/translations/plugin.reservedslots.cfg @@ -0,0 +1,7 @@ +"Phrases" +{ + "Slot reserved" + { + "en" "Dropped to due to slot reservation" + } +}