Reserve slots plugin now offers the option to kick public players (see sourcemod.cfg for details)
authorMatt Woodrow <pred@alliedmods.net>
Sun Oct 21 04:51:57 2007 +0000 (2007-10-21)
changeset 1617e0bcb6bb82fd
parent 1616 173e015bac82
child 1618 4017b4d362d4
Reserve slots plugin now offers the option to kick public players (see sourcemod.cfg for details)
configs/cfg/sourcemod.cfg
plugins/reservedslots.sp
     1.1 --- a/configs/cfg/sourcemod.cfg	Sun Oct 21 00:16:46 2007 +0000
     1.2 +++ b/configs/cfg/sourcemod.cfg	Sun Oct 21 04:51:57 2007 +0000
     1.3 @@ -59,6 +59,17 @@
     1.4  // Default: 0.75
     1.5  sm_flood_time 0.75
     1.6  
     1.7 +// Specifies how the reserved slots plugin operates. Valid values are:
     1.8 +// 0 : Public slots are used in preference to reserved slots. Reserved slots are freed before public slots.
     1.9 +// 1 : If someone with reserve access joins into a reserved slot, the player with the highest latency and 
    1.10 +// no reserved slot access (spectator players are selected first) is kicked to make room. Thus, the reserved
    1.11 +// slots always remains free. The only situation where the reserved slot(s) can become properly occupied is 
    1.12 +// if the server is full with reserve slot access clients.
    1.13 +// --
    1.14 +// Requires: reservedslots.smx
    1.15 +// Default: 0
    1.16 +sm_reserve_type 0
    1.17 +
    1.18  // Specifies the number of reserved player slots.  Users with the reservation
    1.19  // admin flag set will be able to join the server when there are no public slots
    1.20  // remaining. If someone does not have this flag, they will be kicked.
     2.1 --- a/plugins/reservedslots.sp	Sun Oct 21 00:16:46 2007 +0000
     2.2 +++ b/plugins/reservedslots.sp	Sun Oct 21 04:51:57 2007 +0000
     2.3 @@ -51,6 +51,7 @@
     2.4  new Handle:sm_reserved_slots;
     2.5  new Handle:sm_hide_slots;
     2.6  new Handle:sv_visiblemaxplayers;
     2.7 +new Handle:sm_reserve_type;
     2.8  
     2.9  public OnPluginStart()
    2.10  {
    2.11 @@ -59,6 +60,7 @@
    2.12  	sm_reserved_slots = CreateConVar("sm_reserved_slots", "0", "Number of reserved player slots", 0, true, 0.0);
    2.13  	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);
    2.14  	sv_visiblemaxplayers = FindConVar("sv_visiblemaxplayers");
    2.15 +	sm_reserve_type = CreateConVar("sm_reserve_type", "0", "Method of reserving slots", 0, true, 0.0, true, 1.0);
    2.16  }
    2.17  
    2.18  public OnMapStart()
    2.19 @@ -91,13 +93,13 @@
    2.20  public OnClientPostAdminCheck(client)
    2.21  {
    2.22  	new reserved = GetConVarInt(sm_reserved_slots);
    2.23 -	
    2.24 +
    2.25  	if (reserved > 0)
    2.26  	{
    2.27  		new clients = GetClientCount(false);
    2.28  		new limit = g_MaxClients - reserved;
    2.29  		new flags = GetUserFlagBits(client);
    2.30 -		
    2.31 +	
    2.32  		if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    2.33  		{
    2.34  			if (GetConVarBool(sm_hide_slots))
    2.35 @@ -105,6 +107,18 @@
    2.36  				SetVisibleMaxSlots(clients, limit);
    2.37  			}
    2.38  			
    2.39 +			new type = GetConVarInt(sm_reserve_type);
    2.40 +			
    2.41 +			if (type == 1)
    2.42 +			{
    2.43 +				new target = SelectKickClient();
    2.44 +				
    2.45 +				if (target)
    2.46 +				{
    2.47 +					CreateTimer(0.1, OnTimedKick, GetClientUserId(target));
    2.48 +				}
    2.49 +			}
    2.50 +			
    2.51  			return;
    2.52  		}
    2.53  
    2.54 @@ -134,3 +148,64 @@
    2.55  	
    2.56  	SetConVarInt(sv_visiblemaxplayers, num);
    2.57  }
    2.58 +
    2.59 +SelectKickClient()
    2.60 +{
    2.61 +	new Float:highestLatency;
    2.62 +	new highestLatencyId;
    2.63 +	
    2.64 +	new Float:highestSpecLatency;
    2.65 +	new highestSpecLatencyId;
    2.66 +	
    2.67 +	new bool:specFound;
    2.68 +	
    2.69 +	new Float:latency;
    2.70 +	
    2.71 +	for (new i=1; i<=g_MaxClients; i++)
    2.72 +	{
    2.73 +		if (!IsClientConnected(i))
    2.74 +		{
    2.75 +			continue;
    2.76 +		}
    2.77 +	
    2.78 +		new flags = GetUserFlagBits(i);
    2.79 +		
    2.80 +		if (IsFakeClient(i) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    2.81 +		{
    2.82 +			continue;
    2.83 +		}
    2.84 +			
    2.85 +		if (IsClientInGame(i))
    2.86 +		{
    2.87 +			latency = GetClientAvgLatency(i, NetFlow_Both);
    2.88 +			
    2.89 +			if (GetClientTeam(i) == 1)
    2.90 +			{
    2.91 +				specFound = true;
    2.92 +				
    2.93 +				if (latency > highestSpecLatency)
    2.94 +				{
    2.95 +					highestSpecLatency = latency;
    2.96 +					highestSpecLatencyId = i;
    2.97 +				}
    2.98 +			}
    2.99 +		}
   2.100 +		else
   2.101 +		{
   2.102 +			latency = 0.0;
   2.103 +		}
   2.104 +		
   2.105 +		if (latency > highestLatency)
   2.106 +		{
   2.107 +			highestLatency = latency;
   2.108 +			highestLatencyId = i;
   2.109 +		}
   2.110 +	}
   2.111 +	
   2.112 +	if (specFound)
   2.113 +	{
   2.114 +		return highestSpecLatencyId;
   2.115 +	}
   2.116 +	
   2.117 +	return highestLatencyId;
   2.118 +}