plugins/reservedslots.sp
author David Anderson <dvander@alliedmods.net>
Fri Sep 14 02:11:10 2007 +0000 (2007-09-14)
changeset 1423 e73b3563f254
parent 1351 47bf177d07e2
child 1617 e0bcb6bb82fd
permissions -rw-r--r--
- added 3 new natives for banning/unbanning and interception
- moved banning commands into new plugin, basebans
- improved quality and input methods of ban commands
- corrected svn props on a few files
- added an IsLANServer() to IGameHelpers API
- completely deprecated and removed old banning forwards
ds@988
     1
/**
ds@1330
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
ds@1330
     4
 * SourceMod Reserved Slots Plugin
ds@988
     5
 * Provides basic reserved slots.
ds@1330
     6
 *
ds@1330
     7
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     8
 * =============================================================================
ds@988
     9
 *
ds@1330
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    12
 * Free Software Foundation.
ds@1330
    13
 * 
ds@1330
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    17
 * details.
ds@988
    18
 *
ds@1330
    19
 * You should have received a copy of the GNU General Public License along with
ds@1330
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    21
 *
ds@1330
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    29
 * or <http://www.sourcemod.net/license.php>.
ds@988
    30
 *
ds@988
    31
 * Version: $Id$
ds@988
    32
 */
ds@988
    33
ds@988
    34
#pragma semicolon 1
ds@988
    35
ds@988
    36
#include <sourcemod>
ds@988
    37
ds@988
    38
public Plugin:myinfo = 
ds@988
    39
{
ds@988
    40
	name = "Reserved Slots",
ds@988
    41
	author = "AlliedModders LLC",
ds@988
    42
	description = "Provides basic reserved slots",
ds@988
    43
	version = SOURCEMOD_VERSION,
ds@988
    44
	url = "http://www.sourcemod.net/"
ds@988
    45
};
ds@988
    46
ds@988
    47
/* Maximum number of clients that can connect to server */
ds@988
    48
new g_MaxClients;
ds@988
    49
ds@988
    50
/* Handles to convars used by plugin */
ds@988
    51
new Handle:sm_reserved_slots;
ds@988
    52
new Handle:sm_hide_slots;
ds@988
    53
new Handle:sv_visiblemaxplayers;
ds@988
    54
ds@988
    55
public OnPluginStart()
ds@988
    56
{
ferret99gt@1187
    57
	LoadTranslations("reservedslots.phrases");
ds@988
    58
	
ds@988
    59
	sm_reserved_slots = CreateConVar("sm_reserved_slots", "0", "Number of reserved player slots", 0, true, 0.0);
ds@988
    60
	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
    61
	sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers");
ds@988
    62
}
ds@988
    63
ds@988
    64
public OnMapStart()
ds@988
    65
{
ds@988
    66
	g_MaxClients = GetMaxClients();
ds@988
    67
}
ds@988
    68
ds@988
    69
public OnConfigsExecuted()
ds@988
    70
{
ds@988
    71
	if (GetConVarBool(sm_hide_slots))
ds@988
    72
	{
ds@998
    73
		SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
ds@988
    74
	}	
ds@988
    75
}
ds@988
    76
dvander@1351
    77
public Action:OnTimedKick(Handle:timer, any:value)
dvander@1351
    78
{
dvander@1351
    79
	new client = GetClientOfUserId(value);
dvander@1351
    80
	
dvander@1351
    81
	if (!client || !IsClientInGame(client))
dvander@1351
    82
	{
dvander@1351
    83
		return Plugin_Handled;
dvander@1351
    84
	}
dvander@1351
    85
	
dvander@1351
    86
	KickClient(client, "%T", "Slot reserved", client);
dvander@1351
    87
	
dvander@1351
    88
	return Plugin_Handled;
dvander@1351
    89
}
dvander@1351
    90
dvander@1273
    91
public OnClientPostAdminCheck(client)
ds@988
    92
{
ds@988
    93
	new reserved = GetConVarInt(sm_reserved_slots);
ds@988
    94
	
ds@988
    95
	if (reserved > 0)
ds@988
    96
	{
ds@988
    97
		new clients = GetClientCount(false);
ds@988
    98
		new limit = g_MaxClients - reserved;
ds@988
    99
		new flags = GetUserFlagBits(client);
ds@988
   100
		
ds@998
   101
		if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
ds@988
   102
		{
ds@988
   103
			if (GetConVarBool(sm_hide_slots))
ds@988
   104
			{
ds@998
   105
				SetVisibleMaxSlots(clients, limit);
ds@988
   106
			}
ds@988
   107
			
ds@988
   108
			return;
ds@988
   109
		}
ds@998
   110
ds@988
   111
		/* Kick player because there are no public slots left */
dvander@1351
   112
		CreateTimer(0.1, OnTimedKick, GetClientUserId(client));
ds@988
   113
	}
ds@988
   114
}
ds@988
   115
ds@998
   116
public OnClientDisconnect_Post(client)
ds@988
   117
{
ds@988
   118
	if (GetConVarBool(sm_hide_slots))
ds@998
   119
	{		
ds@998
   120
		SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
ds@988
   121
	}
ds@988
   122
}
ds@998
   123
ds@998
   124
SetVisibleMaxSlots(clients, limit)
ds@998
   125
{
ds@998
   126
	new num = clients + 1;
ds@998
   127
	
ds@999
   128
	if (clients == g_MaxClients)
ds@998
   129
	{
ds@998
   130
		num = g_MaxClients;
ds@998
   131
	} else if (clients < limit) {
ds@998
   132
		num = limit;
ds@998
   133
	}
ds@998
   134
	
ds@998
   135
	SetConVarInt(sv_visiblemaxplayers, num);
ds@998
   136
}