Skip to content

Commit

Permalink
Discord: Log ~2 less lines when disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 20, 2022
1 parent a7da4b8 commit 00ff666
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs
Expand Up @@ -67,6 +67,7 @@ public sealed class DiscordWebsocket : ClientWebSocket
SchedulerTask heartbeat;
TcpClient client;
SslStream stream;
bool readable = true;

public const int DEFAULT_INTENTS = INTENT_GUILD_MESSAGES | INTENT_DIRECT_MESSAGES | INTENT_MESSAGE_CONTENT;
const int INTENT_GUILD_MESSAGES = 1 << 9;
Expand Down Expand Up @@ -109,6 +110,7 @@ public sealed class DiscordWebsocket : ClientWebSocket
}

public override void Close() {
readable = false;
Server.Heartbeats.Cancel(heartbeat);
try {
client.Close();
Expand All @@ -122,7 +124,7 @@ public sealed class DiscordWebsocket : ClientWebSocket

protected override void OnDisconnected(int reason) {
SentIdentify = false;
Logger.Log(LogType.SystemActivity, "Discord relay bot closing: " + reason);
if (readable) Logger.Log(LogType.SystemActivity, "Discord relay bot closing: " + reason);
Close();

if (reason == REASON_INVALID_TOKEN) {
Expand All @@ -140,7 +142,10 @@ public sealed class DiscordWebsocket : ClientWebSocket

public void ReadLoop() {
byte[] data = new byte[4096];
for (;;) {
readable = true;

while (readable)
{
int len = stream.Read(data, 0, 4096);
if (len == 0) throw new IOException("stream.Read returned 0");

Expand Down

0 comments on commit 00ff666

Please sign in to comment.