Slots available decreases with player disconnection

Hi,

I set up 35 reserved slots out of the 50 slots in my server and I noticed that the number of reserved slots decreases whenever a user having the "reserved.slot" permission logs in or logs out of the server:

[Reserved] 35 slot(s) now available
Server startup complete
X.X.X.X:63489/XXXXXXXXXXXXX5540/G******** has auth level 1
[Reserved] 34 slot(s) now available
X.X.X.X:54440/XXXXXXXXXXXXX3053/M******** has auth level 2
[Reserved] 33 slot(s) now available
X.X.X.X:63489/XXXXXXXXXXXXX5540/G******** joined [windows/XXXXXXXXXXXXX5540]
G********[XXXXXXXXXXXXX5540] has spawned 
X.X.X.X:54440/XXXXXXXXXXXXX3053/M******** joined [windows/XXXXXXXXXXXXX3053]
M********[XXXXXXXXXXXXX3053] has spawned
X.X.X.X:54440/XXXXXXXXXXXXX3053/M******** disconnecting: disconnect
[Reserved] 32 slot(s) now available
X.X.X.X:59920/XXXXXXXXXXXXX3053/M******** has auth level 2
[Reserved] 31 slot(s) now available
X.X.X.X:59920/XXXXXXXXXXXXX3053/M******** joined [windows/XXXXXXXXXXXXX3053]
M********[XXXXXXXXXXXXX3053] has spawned
X.X.X.X:59920/XXXXXXXXXXXXX3053/M******** disconnecting: disconnect
[Reserved] 30 slot(s) now available
X.X.X.X:61699/XXXXXXXXXXXXX3053/M******** has auth level 2
[Reserved] 29 slot(s) now available
X.X.X.X:61699/XXXXXXXXXXXXX3053/M******** joined [windows/XXXXXXXXXXXXX3053]
M********[XXXXXXXXXXXXX3053] has spawned
X.X.X.X:61699/XXXXXXXXXXXXX3053/M******** disconnecting: disconnect
[Reserved] 28 slot(s) now available


According to the plugin's description the number of reserved slots should only decrease when a user having said permission logs in to the server and it should increase (=slot should be freed) when a user having said permission logs off the server.

This problem seems to be related to the problem described in the "Slots not freed when players disconnect" thread that is marked "Fixed" even though there is no new version of the plugin.

Plugin configuration:

{
  "Always allow admin to connect (true/false)": false,
  "Always use reserved slot if player has permission (true/false)": true,
  "Dynamic slots based on players with permission (true/false)": false,
  "Kick other players for players with permission (true/false)": false,
  "Number of slots to reserve (if dynamic slots not enabled)": 35
}


Thank you very much for the help!

Br,

Maegoss

Try setting:

"Always use reserved slot if player has permission (true/false)"​

to false.

hpHBhgVGDienMyr.jpg Wulf

Try setting:

"Always use reserved slot if player has permission (true/false)"​

to false.

I changed the value of the aforementioned parameter but the problem is still the same:

Reserved was compiled successfully in 5590ms
Unloaded plugin Reserved v2.0.3 by Wulf/lukespragg
[Reserved] 35 slot(s) now available
Loaded plugin Reserved v2.0.3 by Wulf/lukespragg
X.X.X.X:57303/XXXXXXXXXXXXX3053/M******** has auth level 2
[Reserved] 34 slot(s) now available
X.X.X.X:57303/XXXXXXXXXXXXX3053/M******** joined [windows/XXXXXXXXXXXXX3053]
M********[XXXXXXXXXXXXX3053] has spawned
X.X.X.X:57303/XXXXXXXXXXXXX3053/M******** disconnecting: disconnect
[Reserved] 33 slot(s) now available
X.X.X.X:60260/XXXXXXXXXXXXX3053/M******** has auth level 2
[Reserved] 32 slot(s) now available
X.X.X.X:60260/XXXXXXXXXXXXX3053/M******** joined [windows/XXXXXXXXXXXXX3053]
M********[XXXXXXXXXXXXX3053] has spawned
X.X.X.X:60260/XXXXXXXXXXXXX3053/M******** disconnecting: disconnect
[Reserved] 31 slot(s) now available​

Br,
Maegoss

Hi,

I managed to find and fix the problem, it was in function OnUserDisconnected():

        private void OnUserDisconnected(IPlayer player, string reason)
        {
            if (config.AlwaysUseSlot && permission.UserHasPermission(player.Id, permSlot))
            {
                //slotsAvailable--;
                slotsAvailable++;
                Log(Lang("SlotsNowAvailable", null, slotsAvailable.ToString()));
            }
        }​


I tried and now the slot is freed when a user having the permission disconnects.

Br,
Maegoss

Good find! I'll apply that for the next.

Slots available decreases when player with permission get kick on connection stage or if Player will press Cancel Button.
Connecting & pressing cancel button can decrease available slots to 0.
For example, a player's game freezes or the Internet fell off at the moment when he connecting to the server. ( asssests , prefabs loading screen )
or will press cancel on loading stage.
I fixed the problem by moving a piece of code into the conditions (trigger) that the player had already logged into the server.
Now Plugin decreases slot only when player connected and increases when player disconnected. Counting is right now but not sure if there will be other problems now.
My Code:

            int currentPlayers = players.Connected.Count();
            int maxPlayers = server.MaxPlayers;

            if (slotsAvailable > 0)
            {
                if (maxPlayers - currentPlayers <= slotsAvailable)
                {
                    if (!permission.UserHasPermission(id, permSlot))
                    {
                        return Lang("ReservedSlotsOnly", id);
                    }

                    if (config.KickForReserved && currentPlayers == maxPlayers)
                    {
                        IPlayer[] targets = players.Connected.ToArray();
                        IPlayer target = targets.FirstOrDefault(p => !p.HasPermission(permSlot) && p.Id != id);

                        if (target != null)
                        {
                            target.Kick(Lang("KickedForReserved", target.Id));
                        }
                    }
                }
                
                
            }

            return null;
        }
private void OnUserConnected(IPlayer player)
{
	if (config.AlwaysUseSlot && permission.UserHasPermission(player.Id, permSlot)) 
                {
                    slotsAvailable--;
                    Log(Lang("SlotsNowAvailable", null, slotsAvailable.ToString()));
                }
}
private void OnUserDisconnected(IPlayer player, string reason)
{
    if (config.AlwaysUseSlot && permission.UserHasPermission(player.Id, permSlot))
    {
        slotsAvailable++;
        Log(Lang("SlotsNowAvailable", null, slotsAvailable.ToString()));
    }
}

Original Code:

            int currentPlayers = players.Connected.Count();
            int maxPlayers = server.MaxPlayers;

            if (slotsAvailable > 0)
            {
                if (maxPlayers - currentPlayers <= slotsAvailable)
                {
                    if (!permission.UserHasPermission(id, permSlot))
                    {
                        return Lang("ReservedSlotsOnly", id);
                    }

                    if (config.KickForReserved && currentPlayers == maxPlayers)
                    {
                        IPlayer[] targets = players.Connected.ToArray();
                        IPlayer target = targets.FirstOrDefault(p => !p.HasPermission(permSlot) && p.Id != id);

                        if (target != null)
                        {
                            target.Kick(Lang("KickedForReserved", target.Id));
                        }
                    }
                }

                if (config.AlwaysUseSlot)
                {
                    slotsAvailable--;
                    Log(Lang("SlotsNowAvailable", null, slotsAvailable.ToString()));
                }
            }

            return null;
        }

        private void OnUserDisconnected(IPlayer player, string reason)
        {
            if (config.AlwaysUseSlot && permission.UserHasPermission(player.Id, permSlot))
            {
                slotsAvailable--;
                Log(Lang("SlotsNowAvailable", null, slotsAvailable.ToString()));
            }
        }