Fixed amb1154 and another kick bug with sm_reserve_type 1
authorMatt Woodrow <pred@alliedmods.net>
Mon Nov 12 21:51:54 2007 +0000 (2007-11-12)
changeset 1676df6b4e53cca0
parent 1674 cd474b45a045
child 1677 9e81dcf43499
Fixed amb1154 and another kick bug with sm_reserve_type 1
plugins/reservedslots.sp
     1.1 --- a/plugins/reservedslots.sp	Sun Nov 11 20:40:08 2007 +0000
     1.2 +++ b/plugins/reservedslots.sp	Mon Nov 12 21:51:54 2007 +0000
     1.3 @@ -90,10 +90,8 @@
     1.4  	}	
     1.5  }
     1.6  
     1.7 -public Action:OnTimedKick(Handle:timer, any:value)
     1.8 -{
     1.9 -	new client = GetClientOfUserId(value);
    1.10 -	
    1.11 +public Action:OnTimedKick(Handle:timer, any:client)
    1.12 +{	
    1.13  	if (!client || !IsClientInGame(client))
    1.14  	{
    1.15  		return Plugin_Handled;
    1.16 @@ -101,6 +99,8 @@
    1.17  	
    1.18  	KickClient(client, "%T", "Slot reserved", client);
    1.19  	
    1.20 +	SetVisibleMaxSlots(GetClientCount(false), g_MaxClients - GetConVarInt(sm_reserved_slots));
    1.21 +	
    1.22  	return Plugin_Handled;
    1.23  }
    1.24  
    1.25 @@ -113,32 +113,45 @@
    1.26  		new clients = GetClientCount(false);
    1.27  		new limit = g_MaxClients - reserved;
    1.28  		new flags = GetUserFlagBits(client);
    1.29 -	
    1.30 -		if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    1.31 +		
    1.32 +		new type = GetConVarInt(sm_reserve_type);
    1.33 +		
    1.34 +		if (type == 0)
    1.35  		{
    1.36 -			if (GetConVarBool(sm_hide_slots))
    1.37 +			if (clients <= limit || IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    1.38  			{
    1.39 -				SetVisibleMaxSlots(clients, limit);
    1.40 +				if (GetConVarBool(sm_hide_slots))
    1.41 +				{
    1.42 +					SetVisibleMaxSlots(clients, limit);
    1.43 +				}
    1.44 +				
    1.45 +				return;
    1.46  			}
    1.47  			
    1.48 -			new type = GetConVarInt(sm_reserve_type);
    1.49 -			
    1.50 -			if (type == 1)
    1.51 -			{
    1.52 -				new target = SelectKickClient();
    1.53 -				
    1.54 -				if (target)
    1.55 +			/* Kick player because there are no public slots left */
    1.56 +			CreateTimer(0.1, OnTimedKick, client);
    1.57 +		}
    1.58 +		else
    1.59 +		{		
    1.60 +			if (clients > limit)
    1.61 +			{	
    1.62 +				if (flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
    1.63  				{
    1.64 -					/* Kick public player to free the reserved slot again */
    1.65 -					CreateTimer(0.1, OnTimedKick, GetClientUserId(target));
    1.66 +					new target = SelectKickClient();
    1.67 +						
    1.68 +					if (target)
    1.69 +					{
    1.70 +						/* Kick public player to free the reserved slot again */
    1.71 +						CreateTimer(0.1, OnTimedKick, target);
    1.72 +					}
    1.73 +				}
    1.74 +				else
    1.75 +				{				
    1.76 +					/* Kick player because there are no public slots left */
    1.77 +					CreateTimer(0.1, OnTimedKick, client);
    1.78  				}
    1.79  			}
    1.80 -			
    1.81 -			return;
    1.82  		}
    1.83 -
    1.84 -		/* Kick player because there are no public slots left */
    1.85 -		CreateTimer(0.1, OnTimedKick, GetClientUserId(client));
    1.86  	}
    1.87  }
    1.88  
    1.89 @@ -161,7 +174,7 @@
    1.90  
    1.91  SetVisibleMaxSlots(clients, limit)
    1.92  {
    1.93 -	new num = clients + 1;
    1.94 +	new num = clients;
    1.95  	
    1.96  	if (clients == g_MaxClients)
    1.97  	{
    1.98 @@ -186,7 +199,7 @@
    1.99  	new Float:latency;
   1.100  	
   1.101  	for (new i=1; i<=g_MaxClients; i++)
   1.102 -	{
   1.103 +	{	
   1.104  		if (!IsClientConnected(i))
   1.105  		{
   1.106  			continue;
   1.107 @@ -198,13 +211,17 @@
   1.108  		{
   1.109  			continue;
   1.110  		}
   1.111 +		
   1.112 +		latency = 0.0;
   1.113  			
   1.114  		if (IsClientInGame(i))
   1.115 -		{
   1.116 -			latency = GetClientAvgLatency(i, NetFlow_Both);
   1.117 +		{		
   1.118 +			latency = GetClientAvgLatency(i, NetFlow_Outgoing);
   1.119 +			
   1.120 +			LogMessage("Latency : %f",latency);
   1.121  			
   1.122  			if (IsClientObserver(i))
   1.123 -			{
   1.124 +			{			
   1.125  				specFound = true;
   1.126  				
   1.127  				if (latency > highestSpecLatency)
   1.128 @@ -214,12 +231,8 @@
   1.129  				}
   1.130  			}
   1.131  		}
   1.132 -		else
   1.133 -		{
   1.134 -			latency = 0.0;
   1.135 -		}
   1.136  		
   1.137 -		if (latency > highestLatency)
   1.138 +		if (latency >= highestLatency)
   1.139  		{
   1.140  			highestLatency = latency;
   1.141  			highestLatencyId = i;