Skip to content

Commit

Permalink
Disable vault cache and improve restriction enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimmyMySherbet committed Dec 4, 2022
1 parent b410966 commit 0a492aa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
14 changes: 9 additions & 5 deletions SherbetVaults/Database/Tables/VaultItemsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ public VaultItemsTable(SherbetVaultsPlugin plugin, string tableName) : base(tabl
public async Task<VaultItems> OpenVault(ulong playerID, string vaultID, VaultConfig config)
{
var items = await QueryAsync("SELECT * FROM @TABLE WHERE PlayerID=@0 AND VaultID=@1", playerID, vaultID);
var vi = new VaultItems(playerID, vaultID, Plugin);
vi.loadSize(config.Width, config.Height);

var vaultItems = new VaultItems(playerID, vaultID, Plugin);
vaultItems.loadSize(config.Width, config.Height);

foreach (var item in items)
{
vi.loadItem(item.X, item.Y, item.Rot, item.GetItem());
vaultItems.loadItem(item.X, item.Y, item.Rot, item.GetItem());
}
vi.EnableSync();
return vi;

vaultItems.EnableSync();

return vaultItems;
}

public async Task AddItem(ulong playerID, string vaultID, Item item, byte rot, byte x, byte y) =>
Expand Down
5 changes: 3 additions & 2 deletions SherbetVaults/Models/Config/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public partial class SherbetVaultsPlugin
{ "VaultAliases_Set", "[color=cyan]Vault alias created: {0}➔{1}[/color]" },
{ "VaultAliases_Removed", "[color=cyan]Removed alias {0}[/color]" },
{ "VaultAliases_Remove_NotFound", "[color=cyan]No alias by that name found[/color]" },
{ "VaultAliases_List", "[color=cyan]Aliases: {1}[/color]" },
{ "Restrictions_Blacklisted", "[color=red]You cannot store that item in your vault[/color]" }
{ "VaultAliases_List", "Aliases: {1}" },
{ "Restrictions_Blacklisted", "[color=red]You cannot store that item in your vault[/color]" },
{ "VaultAliases_Disabled", "[color=red]Vault aliases are disabled on this server[/color]" }
};
}
}
8 changes: 7 additions & 1 deletion SherbetVaults/Models/Data/VaultItems.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading;
using System.Threading.Tasks;
using Rocket.Core.Logging;
using RocketExtensions.Models;
using RocketExtensions.Utilities;
using RocketExtensions.Utilities.ShimmyMySherbet.Extensions;
Expand Down Expand Up @@ -68,7 +69,12 @@ private void ItemAdded(byte page, byte index, ItemJar jar)
items.Remove(jar);

Player.Player.inventory.tryAddItem(jar.item, true, false);
return;

Logger.Log($"({Player.DisplayName}) tried to store blacklisted item ({jar.item.id}) in vault {VaultID}.");
Logger.Log("Please disregard the following error message.");

// Throw an error to prevent the item being stored client-side
throw new VaultStoreDeniedException();
}

Database.Enqueue(async (table) =>
Expand Down
2 changes: 0 additions & 2 deletions SherbetVaults/Models/RestrictionTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Rocket.API;
using Rocket.Core.Logging;
using RocketExtensions.Models;
using SDG.Unturned;
using SherbetVaults.Models.Config.Restrictions;
Expand Down Expand Up @@ -38,7 +37,6 @@ public bool IsPermitted(ushort itemID, LDMPlayer player, out RestrictionGroup ma

if (asset == null)
{
Logger.LogWarning($"Player {player.PlayerID} tried to put an unrecognized item in their vault. Item ID: {itemID}");
return false;
}

Expand Down
16 changes: 8 additions & 8 deletions SherbetVaults/Models/VaultManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public VaultManager(SherbetVaultsPlugin vaultsPlugin)

public async Task<VaultItems> GetVault(ulong playerID, string vaultID, bool allowCache = true)
{
if (EnableCache && allowCache)
{
var cached = VaultsCache.GetStorage(playerID, vaultID);
if (cached != null)
{
return cached;
}
}
//if (EnableCache && allowCache)
//{
// var cached = VaultsCache.GetStorage(playerID, vaultID);
// if (cached != null)
// {
// return cached;
// }
//}

var vaultConfig = VaultsPlugin.VaultSelector.GetVaultConfig(vaultID);

Expand Down
11 changes: 11 additions & 0 deletions SherbetVaults/Models/VaultStoreDeniedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace SherbetVaults.Models
{
public class VaultStoreDeniedException : Exception
{
public VaultStoreDeniedException() : base("A player attemped to store an item in their vault that is blacklisted")
{
}
}
}
1 change: 1 addition & 0 deletions SherbetVaults/SherbetVaults.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<Compile Include="Models\Utility\VaultSelector.cs" />
<Compile Include="Models\Data\VaultItems.cs" />
<Compile Include="Models\VaultManager.cs" />
<Compile Include="Models\VaultStoreDeniedException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SherbetVaultsPlugin.cs" />
</ItemGroup>
Expand Down

0 comments on commit 0a492aa

Please sign in to comment.