-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added anti-vault-spam to prevent client-side graphical glitches when …
…spammed
- Loading branch information
1 parent
3379938
commit ae7c1a3
Showing
3 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace SherbetVaults.Models | ||
{ | ||
/// <summary> | ||
/// Helps prevent client-side graphical item graphical glitches if a player spams the vault command. | ||
/// </summary> | ||
public class VaultPlayerLock | ||
{ | ||
public ConcurrentDictionary<ulong, bool> m_PlayerBlocks = new ConcurrentDictionary<ulong, bool>(); | ||
|
||
public OpenBlockToken TryObtainLock(ulong player, out bool valid) | ||
{ | ||
if (m_PlayerBlocks.TryGetValue(player, out var blocked)) | ||
{ | ||
if (blocked) | ||
{ | ||
valid = false; | ||
return default; | ||
} | ||
} | ||
m_PlayerBlocks[player] = true; | ||
valid = true; | ||
return new OpenBlockToken(player, this); | ||
} | ||
|
||
private void Release(ulong player) | ||
{ | ||
m_PlayerBlocks[player] = false; | ||
} | ||
|
||
public struct OpenBlockToken : IDisposable | ||
{ | ||
public ulong PlayerID { get; } | ||
private VaultPlayerLock Parent { get; } | ||
|
||
private bool Disposed; | ||
|
||
public OpenBlockToken(ulong playerID, VaultPlayerLock parent) | ||
{ | ||
Disposed = false; | ||
PlayerID = playerID; | ||
Parent = parent; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (!Disposed) | ||
{ | ||
Disposed = true; | ||
Parent?.Release(PlayerID); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters