Skip to content

Commit

Permalink
Remember if a warning was already sent, dont spam it & removed level …
Browse files Browse the repository at this point in the history
…failed check from level restart
  • Loading branch information
TheXorog committed Oct 25, 2021
1 parent feecab4 commit e62df9d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
29 changes: 24 additions & 5 deletions OBSControl/DataPullerWebSocket/DataPuller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Websocket.Client;
using Websocket.Client.Models;
Expand Down Expand Up @@ -50,6 +51,7 @@ internal static void MapDataMessageRecieved(string e)
}
else if (DataPullerObjects.DataPullerInLevel && !_status.InLevel)
{
Thread.Sleep(500);
DataPullerObjects.DataPullerInLevel = false;
DataPullerObjects.DataPullerPaused = false;
_logger.LogDebug("[BS-DP1] Menu entered.");
Expand Down Expand Up @@ -139,13 +141,18 @@ internal static void LiveDataMessageRecieved(string e)
internal static void MapDataReconnected(ReconnectionInfo msg)
{
if (msg.Type != ReconnectionType.Initial)
{
_logger.LogWarn($"[BS-DP1] Reconnected: {msg.Type}");
Objects.LastDP1Warning = Objects.ConnectionTypeWarning.CONNECTED;
}
}

internal static void LiveDataReconnected(ReconnectionInfo msg)
{
if (msg.Type != ReconnectionType.Initial)
{
_logger.LogWarn($"[BS-DP2] Reconnected: {msg.Type}");
}
}

internal static void MapDataDisconnected(DisconnectionInfo msg)
Expand All @@ -156,7 +163,9 @@ internal static void MapDataDisconnected(DisconnectionInfo msg)

if (!processCollection.Any(x => x.ProcessName.ToLower().StartsWith("beat")))
{
_logger.LogWarn($"[BS-DP1] Couldn't find a BeatSaber process, is BeatSaber started? ({msg.Type})");
if (Objects.LastDP1Warning != Objects.ConnectionTypeWarning.NO_PROCESS)
_logger.LogWarn($"[BS-DP1] Couldn't find a BeatSaber process, is BeatSaber started? ({msg.Type})");
Objects.LastDP1Warning = Objects.ConnectionTypeWarning.NO_PROCESS;
}
else
{
Expand All @@ -174,13 +183,23 @@ internal static void MapDataDisconnected(DisconnectionInfo msg)
}
else
{
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running but the BSDataPuller modifaction doesn't seem to be installed. Is your game even modded? (If haven't modded it, please do it: https://bit.ly/2TAvenk. If already modded, install BSDataPuller: https://bit.ly/3mcvC7g) ({msg.Type})");
if (Objects.LastDP1Warning != Objects.ConnectionTypeWarning.NOT_MODDED)
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running but the BSDataPuller modifaction doesn't seem to be installed. Is your game even modded? (If haven't modded it, please do it: https://bit.ly/2TAvenk. If already modded, install BSDataPuller: https://bit.ly/3mcvC7g) ({msg.Type})");
Objects.LastDP1Warning = Objects.ConnectionTypeWarning.NOT_MODDED;
}

if (FoundWebSocketDll)
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running and the BSDataPuller modifaction seems to be installed. Please make sure you put in the right port and you installed all of BSDataPuller' dependiencies! (If not installed, please install it: https://bit.ly/3mcvC7g) ({msg.Type})");
{
if (Objects.LastDP1Warning != Objects.ConnectionTypeWarning.MOD_INSTALLED)
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running and the BSDataPuller modifaction seems to be installed. Please make sure you put in the right port and you installed all of BSDataPuller' dependiencies! (If not installed, please install it: https://bit.ly/3mcvC7g) ({msg.Type})");
Objects.LastDP1Warning = Objects.ConnectionTypeWarning.MOD_INSTALLED;
}
else
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running but the BSDataPuller modifaction doesn't seem to be installed. Please make sure to install BSDataPuller! (If not installed, please install it: https://bit.ly/3mcvC7g) ({msg.Type})");
{
if (Objects.LastDP1Warning != Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED)
_logger.LogCritical($"[BS-DP1] Beat Saber seems to be running but the BSDataPuller modifaction doesn't seem to be installed. Please make sure to install BSDataPuller! (If not installed, please install it: https://bit.ly/3mcvC7g) ({msg.Type})");
Objects.LastDP1Warning = Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED;
}
}
}
catch (Exception ex)
Expand Down Expand Up @@ -274,7 +293,7 @@ internal static void HandleFile(DataPullerObjects.DataPullerMain BeatmapInfo, Da
}
else
{
if (!BeatmapInfo.LevelFailed && !BeatmapInfo.LevelQuit && !BeatmapInfo.LevelFinished)
if (!BeatmapInfo.LevelQuit && !BeatmapInfo.LevelFinished)
{
_logger.LogDebug($"[OBSC] Level restarted");
if (Objects.LoadedSettings.DeleteQuit)
Expand Down
22 changes: 18 additions & 4 deletions OBSControl/HttpStatusWebSocket/HttpStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ internal static void Reconnected(ReconnectionInfo msg)
{
if (msg.Type != ReconnectionType.Initial)
_logger.LogWarn($"[BS-HS] Reconnected: {msg.Type}");

Objects.LastHttpStatusWarning = Objects.ConnectionTypeWarning.CONNECTED;
}

internal static void Disconnected(DisconnectionInfo msg)
Expand All @@ -142,7 +144,9 @@ internal static void Disconnected(DisconnectionInfo msg)

if (!processCollection.Any(x => x.ProcessName.ToLower().StartsWith("beat")))
{
_logger.LogWarn($"[BS-HS] Couldn't find a BeatSaber process, is BeatSaber started? ({msg.Type})");
if (Objects.LastHttpStatusWarning != Objects.ConnectionTypeWarning.NO_PROCESS)
_logger.LogWarn($"[BS-HS] Couldn't find a BeatSaber process, is BeatSaber started? ({msg.Type})");
Objects.LastHttpStatusWarning = Objects.ConnectionTypeWarning.NO_PROCESS;
}
else
{
Expand All @@ -160,13 +164,23 @@ internal static void Disconnected(DisconnectionInfo msg)
}
else
{
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running but the beatsaber-http-status modifaction doesn't seem to be installed. Is your game even modded? (If haven't modded it, please do it: https://bit.ly/2TAvenk. If already modded, install beatsaber-http-status: https://bit.ly/3wYX3Dd) ({msg.Type})");
if (Objects.LastHttpStatusWarning != Objects.ConnectionTypeWarning.NOT_MODDED)
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running but the beatsaber-http-status modifaction doesn't seem to be installed. Is your game even modded? (If haven't modded it, please do it: https://bit.ly/2TAvenk. If already modded, install beatsaber-http-status: https://bit.ly/3wYX3Dd) ({msg.Type})");
Objects.LastHttpStatusWarning = Objects.ConnectionTypeWarning.NOT_MODDED;
}

if (FoundWebSocketDll)
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running and the beatsaber-http-status modifaction seems to be installed. Please make sure you put in the right port and you installed all of beatsaber-http-status' dependiencies! (If not installed, please install it: https://bit.ly/3wYX3Dd) ({msg.Type})");
{
if (Objects.LastHttpStatusWarning != Objects.ConnectionTypeWarning.MOD_INSTALLED)
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running and the beatsaber-http-status modifaction seems to be installed. Please make sure you put in the right port and you installed all of beatsaber-http-status' dependiencies! (If not installed, please install it: https://bit.ly/3wYX3Dd) ({msg.Type})");
Objects.LastHttpStatusWarning = Objects.ConnectionTypeWarning.MOD_INSTALLED;
}
else
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running but the beatsaber-http-status modifaction doesn't seem to be installed. Please make sure to install beatsaber-http-status! (If not installed, please install it: https://bit.ly/3wYX3Dd) ({msg.Type})");
{
if (Objects.LastHttpStatusWarning != Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED)
_logger.LogCritical($"[BS-HS] Beat Saber seems to be running but the beatsaber-http-status modifaction doesn't seem to be installed. Please make sure to install beatsaber-http-status! (If not installed, please install it: https://bit.ly/3wYX3Dd) ({msg.Type})");
Objects.LastHttpStatusWarning = Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED;
}
}
}
catch (Exception ex)
Expand Down
18 changes: 15 additions & 3 deletions OBSControl/OBSWebSocket/OBSWebSocketEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ internal static void Reconnected(ReconnectionInfo msg)
{
_logger.LogInfo($"[OBS] Reconnected: {msg.Type}");

Objects.LastOBSWarning = Objects.ConnectionTypeWarning.CONNECTED;

Program.obsWebSocket.Send($"{{\"request-type\":\"GetAuthRequired\", \"message-id\":\"{RequiredAuthenticationGuid}\"}}");
}
}
Expand All @@ -219,7 +221,9 @@ internal static void Disconnected(DisconnectionInfo msg)

if (!processCollection.Any(x => x.ProcessName.ToLower().StartsWith("obs64") || x.ProcessName.ToLower().StartsWith("obs32")))
{
_logger.LogWarn($"[OBS] Couldn't find an OBS process, is your OBS running? ({msg.Type})");
if (Objects.LastOBSWarning != Objects.ConnectionTypeWarning.NO_PROCESS)
_logger.LogWarn($"[OBS] Couldn't find an OBS process, is your OBS running? ({msg.Type})");
Objects.LastOBSWarning = Objects.ConnectionTypeWarning.NO_PROCESS;
}
else
{
Expand All @@ -241,9 +245,17 @@ internal static void Disconnected(DisconnectionInfo msg)
}

if (FoundWebSocketDll)
_logger.LogCritical($"[OBS] OBS seems to be running but the obs-websocket server isn't running. Please make sure you have the obs-websocket server activated! (Tools -> WebSocket Server Settings) ({msg.Type})");
{
if (Objects.LastOBSWarning != Objects.ConnectionTypeWarning.MOD_INSTALLED)
_logger.LogCritical($"[OBS] OBS seems to be running but the obs-websocket server isn't running. Please make sure you have the obs-websocket server activated! (Tools -> WebSocket Server Settings) ({msg.Type})");
Objects.LastOBSWarning = Objects.ConnectionTypeWarning.MOD_INSTALLED;
}
else
_logger.LogCritical($"[OBS] OBS seems to be running but the obs-websocket server isn't installed. Please make sure you have the obs-websocket server installed! (To install, follow this link: https://bit.ly/3BCXfeS) ({msg.Type})");
{
if (Objects.LastOBSWarning != Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED)
_logger.LogCritical($"[OBS] OBS seems to be running but the obs-websocket server isn't installed. Please make sure you have the obs-websocket server installed! (To install, follow this link: https://bit.ly/3BCXfeS) ({msg.Type})");
Objects.LastOBSWarning = Objects.ConnectionTypeWarning.MOD_NOT_INSTALLED;
}
}
}
catch (Exception ex)
Expand Down
13 changes: 12 additions & 1 deletion OBSControl/Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ namespace OBSControl
{
class Objects
{
// Settings
public static ConnectionTypeWarning LastDP1Warning { get; set; }
public static ConnectionTypeWarning LastHttpStatusWarning { get; set; }
public static ConnectionTypeWarning LastOBSWarning { get; set; }

public enum ConnectionTypeWarning
{
CONNECTED,
MOD_INSTALLED,
MOD_NOT_INSTALLED,
NOT_MODDED,
NO_PROCESS
}

public static Settings LoadedSettings = new Settings();

Expand Down
8 changes: 4 additions & 4 deletions OBSControl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ await Task.Run(async () =>

beatSaberWebSocket = new WebsocketClient(new Uri($"ws://{Objects.LoadedSettings.BeatSaberUrl}:{Objects.LoadedSettings.BeatSaberPort}/BSDataPuller/MapData"), factory);
beatSaberWebSocket.ReconnectTimeout = null;
beatSaberWebSocket.ErrorReconnectTimeout = TimeSpan.FromSeconds(10);
beatSaberWebSocket.ErrorReconnectTimeout = TimeSpan.FromSeconds(3);

beatSaberWebSocket.MessageReceived.Subscribe(msg => { DataPuller.MapDataMessageRecieved(msg.Text); });
beatSaberWebSocket.ReconnectionHappened.Subscribe(type => { DataPuller.MapDataReconnected(type); });
Expand All @@ -139,7 +139,7 @@ await Task.Run(async () =>

beatSaberWebSocketLiveData = new WebsocketClient(new Uri($"ws://{Objects.LoadedSettings.BeatSaberUrl}:{Objects.LoadedSettings.BeatSaberPort}/BSDataPuller/LiveData"), factory);
beatSaberWebSocketLiveData.ReconnectTimeout = null;
beatSaberWebSocketLiveData.ErrorReconnectTimeout = TimeSpan.FromSeconds(10);
beatSaberWebSocketLiveData.ErrorReconnectTimeout = TimeSpan.FromSeconds(3);

beatSaberWebSocketLiveData.MessageReceived.Subscribe(msg => { DataPuller.LiveDataMessageRecieved(msg.Text); });
beatSaberWebSocketLiveData.ReconnectionHappened.Subscribe(type => { DataPuller.LiveDataReconnected(type); });
Expand All @@ -166,7 +166,7 @@ await Task.Run(async () =>
});

beatSaberWebSocketLiveData = new WebsocketClient(new Uri($"ws://{Objects.LoadedSettings.BeatSaberUrl}:{Objects.LoadedSettings.BeatSaberPort}/socket"), factory); beatSaberWebSocketLiveData.ReconnectTimeout = null;
beatSaberWebSocketLiveData.ErrorReconnectTimeout = TimeSpan.FromSeconds(10);
beatSaberWebSocketLiveData.ErrorReconnectTimeout = TimeSpan.FromSeconds(3);

beatSaberWebSocketLiveData.MessageReceived.Subscribe(msg => { HttpStatus.MessageReceived(msg.Text); });
beatSaberWebSocketLiveData.ReconnectionHappened.Subscribe(type => { HttpStatus.Reconnected(type); });
Expand All @@ -191,7 +191,7 @@ await Task.Run(async () =>

obsWebSocket = new WebsocketClient(new Uri($"ws://{Objects.LoadedSettings.OBSUrl}:{Objects.LoadedSettings.OBSPort}"), factory);
obsWebSocket.ReconnectTimeout = null;
obsWebSocket.ErrorReconnectTimeout = TimeSpan.FromSeconds(10);
obsWebSocket.ErrorReconnectTimeout = TimeSpan.FromSeconds(3);

obsWebSocket.MessageReceived.Subscribe(msg => { _ = OBSWebSocketEvents.MessageReceived(msg); });
obsWebSocket.ReconnectionHappened.Subscribe(type => { OBSWebSocketEvents.Reconnected(type); });
Expand Down

0 comments on commit e62df9d

Please sign in to comment.