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