LabAPI icon indicating copy to clipboard operation
LabAPI copied to clipboard

[BUG]: Setting Player.DisarmedBy = null skips client network synchronization (SendToAuthenticated)

Open efrosim opened this issue 3 weeks ago • 1 comments

Before You Report

  • [x] I have searched for existing reports of this bug, and this bug report is unique.

Version

1.1.7

Description

Setting player.DisarmedBy = null uncuffs the player on the server via Inventory.SetDisarmedStatus(null), but fails to notify clients because an early return bypasses new DisarmedPlayersListMessage(DisarmedPlayers.Entries).SendToAuthenticated().

As a result:

  • The server considers the player uncuffed.
  • Clients never receive the updated DisarmedPlayersListMessage, keeping the player visually and functionally cuffed from the perspective of clients (client/server desync).

To Reproduce

  1. Disarm a player by setting player.DisarmedBy = disarmerPlayer; (or via standard in-game disarmer).
  2. Uncuff the player via player.DisarmedBy = null;.
  3. Observe that while player.IsDisarmed is false on the server, connected clients still render the player with hands bound behind their back and client-side interactions remain restricted.

Expected Behavior

Setting player.DisarmedBy = null should update the status on the server and broadcast DisarmedPlayersListMessage to all authenticated clients so they recognize the player as uncuffed.

Additional Information

In LabApi/Features/Wrappers/Players/Player.cs lines 1159-1170:

public Player? DisarmedBy
{
    get
    {
        if (!IsDisarmed)
        {
            return null;
        }

        DisarmedPlayers.DisarmedEntry entry = DisarmedPlayers.Entries.Find(x => x.DisarmedPlayer == NetworkId);

        return Get(entry.Disarmer);
    }

    set
    {
        Inventory.SetDisarmedStatus(null);

        if (value == null)
        {
            return; // <--- The early return bypasses network synchronization!
        }

        DisarmedPlayers.Entries.Add(new DisarmedPlayers.DisarmedEntry(NetworkId, value.NetworkId));
        new DisarmedPlayersListMessage(DisarmedPlayers.Entries).SendToAuthenticated();
    }
}

Because Inventory.SetDisarmedStatus(Inventory disarmer) in InventorySystem.Disarming.DisarmedPlayers already handles removing existing entries and adding a new one if disarmer != null, the setter can be simplified and made fully consistent:

Proposed fix:

set
{
    Inventory.SetDisarmedStatus(value?.Inventory);
    new DisarmedPlayersListMessage(DisarmedPlayers.Entries).SendToAuthenticated();
}

This guarantees that:

  1. When value == null, SetDisarmedStatus(null) removes the entry from Entries, and clients receive the updated list.
  2. When value != null, SetDisarmedStatus(value.Inventory) removes any stale entry and registers the new disarmer without needing manual Entries.Add(...).
  3. Network synchronization always executes.

efrosim avatar Nov 11 '26 18:11 efrosim

value?.Inventory doesn't do a proper Unity lifetime check, but other than that it should be sufficient

Axwabo avatar Nov 11 '26 18:11 Axwabo