Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into dev-4.0
  • Loading branch information
Lacyway committed Jan 15, 2025
2 parents 12dcba1 + 24b9c12 commit 0e2db0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Fika.Headless/Classes/HeadlessRaidWebSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using BepInEx.Logging;
using EFT.UI;
using Fika.Core.Networking.Http;
using Fika.Headless;
using Newtonsoft.Json.Linq;
using SPT.Common.Http;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking.Match;
using WebSocketSharp;

namespace Fika.Core.Networking
{
public class HeadlessRaidWebSocketClient
public class HeadlessRaidWebSocketClient : MonoBehaviour
{
private static ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("Fika.HeadlessWebSocket");

Expand All @@ -25,6 +29,8 @@ public bool Connected
}

private WebSocket _webSocket;
// Add a queue for incoming messages, so they can be brought to the main thread in a nice way.
private ConcurrentQueue<StartHeadlessRequest> messagesQueue = new();

public HeadlessRaidWebSocketClient()
{
Expand Down Expand Up @@ -53,6 +59,14 @@ public void Connect()
_webSocket.Connect();
}

public void Update()
{
while (messagesQueue.TryDequeue(out StartHeadlessRequest request))
{
FikaHeadlessPlugin.Instance.OnFikaStartRaid(request);
}
}

public void Close()
{
_webSocket.Close();
Expand Down Expand Up @@ -88,7 +102,7 @@ private void WebSocket_OnMessage(object sender, MessageEventArgs e)
{
case "fikaHeadlessStartRaid":
StartHeadlessRequest request = jsonObject.ToObject<StartHeadlessRequest>();
FikaHeadlessPlugin.Instance.OnFikaStartRaid(request);
messagesQueue.Enqueue(request);
break;
case "fikaHeadlessKeepAlive":
_webSocket.Send("keepalive");
Expand Down
2 changes: 1 addition & 1 deletion Fika.Headless/FikaHeadlessPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected void Awake()

FikaBackendUtils.IsHeadless = true;

fikaHeadlessWebSocket = new HeadlessRaidWebSocketClient();
fikaHeadlessWebSocket = gameObject.AddComponent<HeadlessRaidWebSocketClient>();

StartCoroutine(RunPluginValidation());
}
Expand Down

0 comments on commit 0e2db0f

Please sign in to comment.