Bläddra i källkod

Implement a better check for TeleportConsumer IPC

Dragon 3 år sedan
förälder
incheckning
f10d35f6ef
2 ändrade filer med 29 tillägg och 5 borttagningar
  1. 1 1
      HuntBuddy/Interface.cs
  2. 28 4
      HuntBuddy/Ipc/TeleportConsumer.cs

+ 1 - 1
HuntBuddy/Interface.cs

@@ -155,7 +155,7 @@ namespace HuntBuddy
 
 							ImGui.SameLine();
 
-							if (Plugin.TeleportConsumer?.Subscribed == true)
+							if (Plugin.TeleportConsumer?.IsAvailable == true)
 							{
 								if (Interface.IconButton(FontAwesomeIcon.StreetView, $"t##{mobHuntEntry.MobHuntId}"))
 								{

+ 28 - 4
HuntBuddy/Ipc/TeleportConsumer.cs

@@ -6,8 +6,34 @@ namespace HuntBuddy.Ipc
 {
 	public class TeleportConsumer
 	{
-		public bool Subscribed { get; private set; }
+		private bool isAvailable;
+		private long timeSinceLastCheck;
 
+		public bool IsAvailable
+		{
+			get
+			{
+				if (this.timeSinceLastCheck + 5 > DateTimeOffset.UtcNow.ToUnixTimeSeconds())
+				{
+					return this.isAvailable;
+				}
+
+				try
+				{
+					this.consumerMessageSetting.InvokeFunc();
+					this.isAvailable = true;
+					this.timeSinceLastCheck = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
+				}
+				catch
+				{
+					this.isAvailable = false;
+				}
+
+				return this.isAvailable;
+			}
+		}
+
+		private ICallGateSubscriber<bool> consumerMessageSetting = null!;
 		private ICallGateSubscriber<uint, byte, bool> consumerTeleport = null!;
 
 		private void Subscribe()
@@ -15,12 +41,10 @@ namespace HuntBuddy.Ipc
 			try
 			{
 				this.consumerTeleport = Plugin.PluginInterface.GetIpcSubscriber<uint, byte, bool>("Teleport");
-
-				this.Subscribed = true;
+				this.consumerMessageSetting = Plugin.PluginInterface.GetIpcSubscriber<bool>("Teleport.ChatMessage");
 			}
 			catch (Exception ex)
 			{
-				this.Subscribed = false;
 				PluginLog.LogDebug($"Failed to subscribe to Teleporter\nReason: {ex}");
 			}
 		}