Stop spamming subscriptions when already online

This commit is contained in:
barelyprofessional
2025-03-22 14:17:54 +08:00
parent 8c6591cb2c
commit 7122a1898c

View File

@@ -25,6 +25,7 @@ public class Clashgg : IDisposable
private Task? _heartbeatTask; private Task? _heartbeatTask;
// There's no smarts, it just does 30-second pings // There's no smarts, it just does 30-second pings
private TimeSpan _heartbeatInterval = TimeSpan.FromSeconds(30); private TimeSpan _heartbeatInterval = TimeSpan.FromSeconds(30);
private bool _isOnline = false;
public Clashgg(string? proxy = null, CancellationToken? cancellationToken = null) public Clashgg(string? proxy = null, CancellationToken? cancellationToken = null)
{ {
@@ -119,12 +120,13 @@ public class Clashgg : IDisposable
{ {
var packet = JsonSerializer.Deserialize<List<JsonElement>>(message.Text); var packet = JsonSerializer.Deserialize<List<JsonElement>>(message.Text);
if (packet == null) throw new InvalidOperationException("Caught a null when deserializing Clash.gg packet"); if (packet == null) throw new InvalidOperationException("Caught a null when deserializing Clash.gg packet");
if (packet[0].GetString() == "online") if (packet[0].GetString() == "online" && !_isOnline)
{ {
_logger.Info("Received online packet from Clash.gg. Subscribing to Plinko, Mines and Keno"); _logger.Info("Received online packet from Clash.gg. Subscribing to Plinko, Mines and Keno");
_wsClient.Send("[\"subscribe\",\"plinko\"]"); _wsClient.Send("[\"subscribe\",\"plinko\"]");
_wsClient.Send("[\"subscribe\",\"mines\"]"); _wsClient.Send("[\"subscribe\",\"mines\"]");
_wsClient.Send("[\"subscribe\",\"keno\"]"); _wsClient.Send("[\"subscribe\",\"keno\"]");
_isOnline = true;
return; return;
} }