Raised This Month: $51 Target: $400
 12% 

Solved Reserve slot for disconnected player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
4ever16
Veteran Member
Join Date: Apr 2015
Old 01-29-2020 , 02:05   Reserve slot for disconnected player
Reply With Quote #1

If player disconnects he gets a reserved slot for 5 minutes.

This is so no one else can join for 5 minutes so that the disconencted player have chance to come back.

Hope someone can make it.

Last edited by 4ever16; 02-20-2020 at 00:54.
4ever16 is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 02-10-2020 , 17:40   Re: Reserve slot for disconnected player
Reply With Quote #2

Bump!
4ever16 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-10-2020 , 23:15   Re: Reserve slot for disconnected player
Reply With Quote #3

Try this. I didn't test it but I think it should work.

-- plugin removed -- didn't quite work and Bugsy wrote his own version that looks like it should work.
__________________

Last edited by fysiks; 02-12-2020 at 21:22.
fysiks is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 02-12-2020 , 11:50   Re: Reserve slot for disconnected player
Reply With Quote #4

When i leave other players gets kicked.

Quote:
Kicked by Console: "Player idle"
Kicked :"Player idle"
4ever16 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-12-2020 , 20:05   Re: Reserve slot for disconnected player
Reply With Quote #5

Not tested, and reserved slots are lost at map change. Set SLOT_COUNT as needed.
PHP Code:

#include <amxmodx>

#define MAX_PLAYERS 32

const SLOT_COUNT 5;

enum SlotInfo
{
    
AuthID34 ],
    
DisconnectTime
}

new 
g_siSlotsSLOT_COUNT ][ SlotInfo ];
new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
bool:g_bKickedMAX_PLAYERS ];
new 
g_iUsedSlots;
new 
g_iMaxPlayers;
new 
g_pReserveTime;

new const 
g_szKickReason[] = "There are no unreserved slots, please try again later";

public 
plugin_init()
{
    
register_plugin"Disconnect Reserve Slot" "0.1" "bugsy" );
    
    
g_pReserveTime register_cvar"drs_reserveminutes" "5" );
    
g_iMaxPlayers get_maxplayers();
}

public 
client_disconnectid )
{
    
RefreshSlots();
    
    if ( !
g_bKickedid ] )
    {
        
AddSlotid );
    }
}

public 
client_authorizedid )
{
    new 
iSlotID;
    
    
RefreshSlots();
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
g_bKickedid ] = false;
    
    
iSlotID GetPlayerSlotIDid );
    
    if ( ( 
get_playersnum() + g_iUsedSlots ) > g_iMaxPlayers )
    {
        if ( 
iSlotID == -)
        {
            
g_bKickedid ] = true;
            
server_cmd"kick #%d ^"%s^"" get_user_useridid ) , g_szKickReason );
        }
        else
        {
            
g_siSlotsiSlotID ][ AuthID ][ ] = EOS;
            
g_siSlotsiSlotID ][ DisconnectTime ] = 0;
            
g_iUsedSlots--;
        }
    }
    else if ( 
iSlotID != -)
    {
        
g_siSlotsiSlotID ][ AuthID ][ ] = EOS;
        
g_siSlotsiSlotID ][ DisconnectTime ] = 0;
        
g_iUsedSlots--;
    }
}

AddSlotid )
{
    if ( 
g_iUsedSlots SLOT_COUNT )
    {
        for ( new 
sizeofg_siSlots ) ; i++ )    
        {
            if ( 
g_siSlots][ AuthID ][ ] == EOS )
            {
                
copyg_siSlots][ AuthID ] , charsmaxg_siSlots[][ AuthID ] ) , g_szAuthIDid ] );
                
g_siSlots][ DisconnectTime ] = get_systime();
                
g_iUsedSlots++;
                break;
            }
        }
    }
}

GetPlayerSlotIDid )
{
    new 
iSlotID = -1;
    
    for ( new 
sizeofg_siSlots ) ; i++ )    
    {
        if ( 
equalg_siSlots][ AuthID ] , g_szAuthIDid ] ) )
        {
            
iSlotID i;
            break;
        }
    }
    
    return 
iSlotID;
}

RefreshSlots()
{
    new 
iSlotTime = ( get_pcvar_numg_pReserveTime ) * 60 );
    new 
iSysTime get_systime();
    
    for ( new 
sizeofg_siSlots ) ; i++ )
    {
        if ( 
g_siSlots][ DisconnectTime ] && ( ( g_siSlots][ DisconnectTime ] + iSlotTime ) < iSysTime ) )
        {
            
g_siSlots][ AuthID ][ ] = EOS;
            
g_siSlots][ DisconnectTime ] = 0;
            
g_iUsedSlots--;
        }
    }        

__________________

Last edited by Bugsy; 02-13-2020 at 06:45.
Bugsy is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2020 , 21:19   Re: Reserve slot for disconnected player
Reply With Quote #6

Quote:
Originally Posted by 4ever16 View Post
When i leave other players gets kicked.
I'm not sure how my plugin would be related to that.

Also, I realized that in my version, I forgot to account for cases when a player doesn't come back. However, it looks like Bugsy wrote a version that takes into account some things that I didn't consider so it will be more likely to work.

Quote:
Originally Posted by Bugsy View Post
Not tested, and reserved slots are lost at map change. Set SLOT_COUNT as needed.
Bugsy,

I think there is an oddity that will occur with your code. When a player with a reserved slot reconnects within the alotted time, it won't clear his reserved slot. So, there will still be a reserved slot until it expires and is removed with RefreshSlots().

This will occur when someone leaves/reconnects in a less than full server situation. For example, if there are 8 players and one disconnects and then reconnects within the 5 minutes, the slot check doesn't occur because iNum + g_iUsedSlots is only 9.

You'd need to check if there is a reserved slot for all connecting players if there are any reserved slots.
__________________

Last edited by fysiks; 02-12-2020 at 21:45.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-12-2020 , 22:09   Re: Reserve slot for disconnected player
Reply With Quote #7

It will clear his slot since his slot id will return a non -1 value on connect and subsequently clear it. Also, all slots are pruned on every player connect and disconnect so it should not ever allow stale slots.
__________________

Last edited by Bugsy; 02-12-2020 at 22:09.
Bugsy is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2020 , 22:39   Re: Reserve slot for disconnected player
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
It will clear his slot since his slot id will return a non -1 value on connect and subsequently clear it. Also, all slots are pruned on every player connect and disconnect so it should not ever allow stale slots.
Consider the following scenario:
  • Maxplayers = 10
  • Player count = 9
  • 1 player leaves
  • Slot get reserved for that player
  • Player count = 8
  • Same player reconnects 1 minute later
  • Player count = 9
  • iNum + g_iUsedSlots = 9 + 1
  • ( iNum + g_iUsedSlots ) > g_iMaxPlayers => false
  • GetPlayerSlotID( id ) is never called, slot is still reserved for 4 more minutes
  • A 10th player joins
  • Player count = 10
  • iNum + g_iUsedSlots = 10 + 1
  • ( iNum + g_iUsedSlots ) > g_iMaxPlayers => true
  • GetPlayerSlotID( id ) returns -1
  • 10th player gets kicked because that 9th player's slot is still reserved
  • 10th player will get kicked for the next 4 minutes

I think you simply need to change the condition to g_iUsedSlots > 0. Also, since you're not using iPlayers, you can use get_playersnum() isntead. The other thing I noticed is that you're using definitions only defined for AMX Mod X 1.9+ (and, unfortunately, it's not release yet).

Let me know if I have a flaw in my logic there, I'm quite tired right now (should probably go to bed).
__________________

Last edited by fysiks; 02-12-2020 at 22:43.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-12-2020 , 22:52   Re: Reserve slot for disconnected player
Reply With Quote #9

All of those bullets are making my head hurt. I give you props for putting that much thought into it.

But the fact that the slots will be freed every time a player connects and disconnects, you think there is still an issue?
__________________
Bugsy is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-12-2020 , 23:00   Re: Reserve slot for disconnected player
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
But the fact that the slots will be freed every time a player connects and disconnects, you think there is still an issue?
But that's not entirely true. Only expired reserved slots will be freed on every connect and disconnect. Clearing a slot that is not yet expired requires ( iNum + g_iUsedSlots ) > g_iMaxPlayers to return true which doesn't always happen (as shown in my above scenario).
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode