Stickers: added subscription check on outbound mod network calls

This commit is contained in:
NotAKidoS 2024-09-10 20:22:14 -05:00
parent 52315f5d51
commit 958f07ed08
3 changed files with 76 additions and 8 deletions

View file

@ -6,6 +6,25 @@ public static partial class ModNetwork
{
#region Mod Network Internals
// private static bool _isEnabled = true;
//
// public static bool IsEnabled
// {
// get => _isEnabled;
// set
// {
// if (_isEnabled == value)
// return;
//
// _isEnabled = value;
//
// if (_isEnabled) Subscribe();
// else Unsubscribe();
//
// Reset(); // reset buffers and metadata
// }
// }
public static bool IsSendingTexture { get; private set; }
private static bool _isSubscribedToModNetwork;
@ -15,6 +34,16 @@ public static partial class ModNetwork
_isSubscribedToModNetwork = ModNetworkManager.IsSubscribed(ModId);
if (!_isSubscribedToModNetwork) StickerMod.Logger.Error("Failed to subscribe to Mod Network! This should not happen.");
else StickerMod.Logger.Msg("Subscribed to Mod Network.");
}
private static void Unsubscribe()
{
ModNetworkManager.Unsubscribe(ModId);
_isSubscribedToModNetwork = ModNetworkManager.IsSubscribed(ModId);
if (_isSubscribedToModNetwork) StickerMod.Logger.Error("Failed to unsubscribe from Mod Network! This should not happen.");
else StickerMod.Logger.Msg("Unsubscribed from Mod Network.");
}
#endregion Mod Network Internals

View file

@ -38,6 +38,9 @@ public static partial class ModNetwork
public static void SendPlaceSticker(int stickerSlot, Vector3 position, Vector3 forward, Vector3 up)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -55,6 +58,9 @@ public static partial class ModNetwork
public static void SendClearSticker(int stickerSlot)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -68,6 +74,9 @@ public static partial class ModNetwork
public static void SendClearAllStickers()
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -80,6 +89,9 @@ public static partial class ModNetwork
private static void SendStartTexture(int stickerSlot, Guid textureHash, int chunkCount, int width, int height)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -97,6 +109,9 @@ public static partial class ModNetwork
public static void SendTextureChunk(int chunkIdx, byte[] chunkData)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -111,6 +126,9 @@ public static partial class ModNetwork
public static void SendEndTexture()
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -123,6 +141,9 @@ public static partial class ModNetwork
public static void SendRequestTexture(int stickerSlot, Guid textureHash)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork())
return;
@ -137,6 +158,9 @@ public static partial class ModNetwork
public static void SendTexture(int stickerSlot)
{
if (!_isSubscribedToModNetwork)
return;
if (!IsConnectedToGameNetwork() || IsSendingTexture)
return;

View file

@ -4,7 +4,6 @@ using ABI_RC.Core.UI;
using ABI_RC.Systems.GameEventSystem;
using NAK.Stickers.Networking;
using NAK.Stickers.Utilities;
using UnityEngine;
namespace NAK.Stickers;
@ -65,6 +64,29 @@ public partial class StickerSystem
#region Data
// private bool _isEnabled = true;
//
// public bool IsEnabled
// {
// get => _isEnabled;
// set
// {
// if (_isEnabled == value)
// return;
//
// _isEnabled = value;
// if (!_isEnabled) ClearAllStickers();
// ModNetwork.IsEnabled = _isEnabled;
// }
// }
private string SelectedStickerName => ModSettings.Hidden_SelectedStickerNames.Value[_selectedStickerSlot];
private const float StickerKillTime = 30f;
private const float StickerCooldown = 0.2f;
private readonly Dictionary<string, StickerData> _playerStickers = new();
internal const string PlayerLocalId = "_PLAYERLOCAL";
private int _selectedStickerSlot;
public int SelectedStickerSlot
{
@ -98,12 +120,5 @@ public partial class StickerSystem
}
}
private string SelectedStickerName => ModSettings.Hidden_SelectedStickerNames.Value[_selectedStickerSlot];
private const float StickerKillTime = 30f;
private const float StickerCooldown = 0.2f;
private readonly Dictionary<string, StickerData> _playerStickers = new();
internal const string PlayerLocalId = "_PLAYERLOCAL";
#endregion Data
}