plugins/reservedslots.sp
author David Anderson <dvander@alliedmods.net>
Sun Jul 08 05:20:54 2007 +0000 (2007-07-08)
changeset 1063 2078b3a13b81
parent 1027 4bb60993758e
child 1187 85c0934305bd
permissions -rw-r--r--
small hack so knagg0's stuff can compile
     1 /**
     2  * reservedslots.sp
     3  * Provides basic reserved slots.
     4  * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     5  *
     6  * This program is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This program is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  * 
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    19  *
    20  * Version: $Id$
    21  */
    22 
    23 #pragma semicolon 1
    24 
    25 #include <sourcemod>
    26 
    27 public Plugin:myinfo = 
    28 {
    29 	name = "Reserved Slots",
    30 	author = "AlliedModders LLC",
    31 	description = "Provides basic reserved slots",
    32 	version = SOURCEMOD_VERSION,
    33 	url = "http://www.sourcemod.net/"
    34 };
    35 
    36 /* Maximum number of clients that can connect to server */
    37 new g_MaxClients;
    38 
    39 /* Handles to convars used by plugin */
    40 new Handle:sm_reserved_slots;
    41 new Handle:sm_hide_slots;
    42 new Handle:sv_visiblemaxplayers;
    43 
    44 public OnPluginStart()
    45 {
    46 	LoadTranslations("plugin.reservedslots");
    47 	
    48 	sm_reserved_slots = CreateConVar("sm_reserved_slots", "0", "Number of reserved player slots", 0, true, 0.0);
    49 	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);
    50 	sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers");
    51 }
    52 
    53 public OnMapStart()
    54 {
    55 	g_MaxClients = GetMaxClients();
    56 }
    57 
    58 public OnConfigsExecuted()
    59 {
    60 	if (GetConVarBool(sm_hide_slots))
    61 	{
    62 		SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
    63 	}	
    64 }
    65 
    66 public OnClientAuthorized(client, const String:auth[])
    67 {
    68 	new reserved = GetConVarInt(sm_reserved_slots);
    69 	
    70 	if (reserved > 0)
    71 	{
    72 		new clients = GetClientCount(false);
    73 		new limit = g_MaxClients - reserved;
    74 		new flags = GetUserFlagBits(client);
    75 		
    76 		if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    77 		{
    78 			if (GetConVarBool(sm_hide_slots))
    79 			{
    80 				SetVisibleMaxSlots(clients, limit);
    81 			}
    82 			
    83 			return;
    84 		}
    85 
    86 		/* Kick player because there are no public slots left */
    87 		KickClient(client, "%T", "Slot reserved", client);
    88 	}
    89 }
    90 
    91 public OnClientDisconnect_Post(client)
    92 {
    93 	if (GetConVarBool(sm_hide_slots))
    94 	{		
    95 		SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
    96 	}
    97 }
    98 
    99 SetVisibleMaxSlots(clients, limit)
   100 {
   101 	new num = clients + 1;
   102 	
   103 	if (clients == g_MaxClients)
   104 	{
   105 		num = g_MaxClients;
   106 	} else if (clients < limit) {
   107 		num = limit;
   108 	}
   109 	
   110 	SetConVarInt(sv_visiblemaxplayers, num);
   111 }