Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
561 stars 93 forks source link

[BUG] Discord is crashing when attempting to authenticate #203

Open ronfrigginjon opened 1 year ago

ronfrigginjon commented 1 year ago

Describe the bug After updating to v1.0.9006 Discord is crashing when my app is authenticating. The window that used to pop up and allow me to click the "Authorize" button is no longer there. Instead, discord crashes and says it was awkward.

To Reproduce Authenticate application

Expected behavior Would expect the authentication window to appear, allowing me to click the authorize button, which in turn will fire the OnAuthenticated event.

Desktop (please complete the following information):

Logs INFO: Attempting a new connection INFO: RPC Connection Started TRCE: ============================ TRCE: Assembly: DiscordRPC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null TRCE: Pipe: DiscordRPC.IO.ManagedNamedPipeClient TRCE: Platform: Microsoft Windows NT 6.2.9200.0 TRCE: applicationID: 800373225032777738 TRCE: targetPipe: -1 TRCE: POLL_RATE: 750 TRCE: _maxRtQueueSize: 4096 TRCE: _maxRxQueueSize: 0 TRCE: ============================ TRCE: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient TRCE: ManagedNamedPipeClient.Connection(-1) TRCE: Connection Attempt 0 () INFO: Attempting to connect to discord-ipc-0 TRCE: Waiting for connection... TRCE: Setting the auth state to WAITING_FOR_USER TRCE: Enqueue Command: DiscordRPC.RPC.Commands.AuthorizeCommand TRCE: Enqueue Command: DiscordRPC.RPC.Commands.PresenceCommand INFO: Connected to discord-ipc-0 TRCE: Done. Result: False TRCE: Begining Read of 16384 bytes TRCE: Connected to the pipe. Attempting to establish handshake... TRCE: Enqueued Message, but queue size is 0.1:29:59 PM TRCE: Attempting to establish a handshake... TRCE: Sending Handshake... TRCE: Setting the connection state to CONNECTING TRCE: Connection Established. Starting reading loop... INFO: Checking command queue TRCE: Ending Read TRCE: Read 344 bytes TRCE: Read a frame: Frame TRCE: Starting another read TRCE: Begining Read of 16384 bytes TRCE: Read Payload: Frame INFO: Handling Response. Cmd: Dispatch, Event: Ready INFO: Connection established with the RPC TRCE: Setting the connection state to CONNECTED TRCE: Enqueued Message, but queue size is 0.1:30:01 PM INFO: Checking command queue TRCE: Attempting to send payload: Authorize TRCE: Sending payload: Authorize TRCE: Sent Successfully. TRCE: Attempting to send payload: SetActivity TRCE: Sending payload: SetActivity TRCE: Sent Successfully. TRCE: Ending Read TRCE: Read 150 bytes TRCE: Read a frame: Frame TRCE: Starting another read TRCE: Begining Read of 16384 bytes TRCE: Read Payload: Frame INFO: Handling Response. Cmd: SetActivity, Event: TRCE: Enqueued Message, but queue size is 0.1:30:01 PM INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue TRCE: Ending Read TRCE: Read 0 bytes WARN: Empty frame was read. Please send report to Lachee. TRCE: Starting another read TRCE: Begining Read of 16384 bytes TRCE: Ending Read TRCE: Left main read loop for some reason. Aborting: False, Shutting Down: False TRCE: Waiting 1095ms before attempting to connect again TRCE: Setting the connection state to DISCONNECTED TRCE: Connecting to the pipe through the DiscordRPC.IO.ManagedNamedPipeClient TRCE: ManagedNamedPipeClient.Connection(-1) TRCE: Connection Attempt 0 () INFO: Attempting to connect to discord-ipc-0 TRCE: Waiting for connection... INFO: Connected to discord-ipc-0 TRCE: Done. Result: False TRCE: Begining Read of 16384 bytes TRCE: Connected to the pipe. Attempting to establish handshake... TRCE: Enqueued Message, but queue size is 0.1:30:06 PM TRCE: Attempting to establish a handshake... TRCE: Sending Handshake... TRCE: Setting the connection state to CONNECTING TRCE: Connection Established. Starting reading loop... INFO: Checking command queue INFO: Checking command queue TRCE: Ending Read TRCE: Read 319 bytes TRCE: Read a frame: Frame TRCE: Starting another read TRCE: Begining Read of 16384 bytes TRCE: Read Payload: Frame INFO: Handling Response. Cmd: Dispatch, Event: Ready INFO: Connection established with the RPC TRCE: Setting the connection state to CONNECTED TRCE: Enqueued Message, but queue size is 0.1:30:07 PM INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue INFO: Checking command queue

ronfrigginjon commented 1 year ago

Using better discord I was able to get the following log as it crashed. Hope this helps: [2022-08-19 19:13:12.933][CONSOLE:INFO] [RPCServer:IPC] Socket Emit: 58 {"cmd":"DISPATCH","data":{"v":1,"config":{"cdn_host":"cdn.discordapp.com","api_endpoint":"//discord.com/api","environment":"production"},"user":{"id":"MYUSERID","username":"MYUSERNAME","discriminator":"2045","avatar":"010bb8e8808c3db62a43b18d55608044","avatar_decoration":null,"bot":false,"flags":0}},"evt":"READY","nonce":null} [2022-08-19 19:13:13.681][CONSOLE:INFO] [RPCServer:IPC] Socket Message: 58 {"args":{"client_id":"CLIENTID","scopes":["rpc","messages.read"]},"cmd":"AUTHORIZE","nonce":"1"} [2022-08-19 19:13:13.687][CONSOLE:INFO] [RPCServer:IPC] Socket Message: 58 {"args":{"pid":2968,"activity":{"assets":{"large_image":"image_large","small_image":"image_small"},"instance":false}},"cmd":"SET_ACTIVITY","nonce":"2"} [2022-08-19 19:13:13.831][CONSOLE:INFO] [RPCServer:IPC] Socket Emit: 58 {"cmd":"SET_ACTIVITY","data":{"assets":{},"name":"APPLICATIONNAME","application_id":"APPLICATIONID","type":0},"evt":null,"nonce":"2"} [2022-08-19 19:13:13.948][CONSOLE:ERROR] Failed to construct 'URL': Invalid URL TypeError: Failed to construct 'URL': Invalid URL at g (https://discord.com/assets/35040bb1dd839dc700d5.js:2507:834) at so (https://discord.com/assets/35040bb1dd839dc700d5.js:6076:468) at $s (https://discord.com/assets/35040bb1dd839dc700d5.js:6128:48) at Gu (https://discord.com/assets/35040bb1dd839dc700d5.js:6119:748) at wu (https://discord.com/assets/35040bb1dd839dc700d5.js:6119:676) at Uu (https://discord.com/assets/35040bb1dd839dc700d5.js:6119:539) at Au (https://discord.com/assets/35040bb1dd839dc700d5.js:6116:164) at https://discord.com/assets/35040bb1dd839dc700d5.js:6061:340 at t.unstable_runWithPriority (https://discord.com/assets/35040bb1dd839dc700d5.js:6250:828) at Ki (https://discord.com/assets/35040bb1dd839dc700d5.js:6061:117) at qi (https://discord.com/assets/35040bb1dd839dc700d5.js:6061:285) at Xi (https://discord.com/assets/35040bb1dd839dc700d5.js:6061:220) at Tu (https://discord.com/assets/35040bb1dd839dc700d5.js:6113:510) at Mo (https://discord.com/assets/35040bb1dd839dc700d5.js:6081:915) at e (https://discord.com/assets/35040bb1dd839dc700d5.js:4927:630) at https://discord.com/assets/35040bb1dd839dc700d5.js:4925:612 at Set.forEach () at Function.r [as setState] (https://discord.com/assets/35040bb1dd839dc700d5.js:4925:584) at A (https://discord.com/assets/35040bb1dd839dc700d5.js:3724:234) at https://discord.com/assets/d5ca6fe0f4596e60db34.js:2179:540 at new Promise () at https://discord.com/assets/d5ca6fe0f4596e60db34.js:2179:476 at https://discord.com/assets/d5ca6fe0f4596e60db34.js:2112:877 at c (https://discord.com/assets/35040bb1dd839dc700d5.js:107:318) at Generator._invoke (https://discord.com/assets/35040bb1dd839dc700d5.js:107:88) at Generator.next (https://discord.com/assets/35040bb1dd839dc700d5.js:107:835) at h (https://discord.com/assets/d5ca6fe0f4596e60db34.js:2110:742) at i (https://discord.com/assets/d5ca6fe0f4596e60db34.js:2110:940) [2022-08-19 19:13:19.922][CONSOLE:WARN] Window state not initialized window-1

Lachee commented 1 year ago
ronfrigginjon commented 1 year ago

It is a discord update. This worked in 1.0.9004 and below, I never tried on 1.0.9005 and now it crashes on 1.09006. I am using the channel listener so have always had to authenticate my app to discord.

ronfrigginjon commented 1 year ago

This issue can close. The crashing was an issue on my end. However there is an issue with the WebClient in ExchangeCode function. Discord recently updated to use TLS 1.2 security protocol, so you just need to update the SecurityProtocolType to Tls12. In order to do this I also had to port the project over to the .net 4.5 framework.

Lachee commented 1 year ago

This issue can close. The crashing was an issue on my end. However there is an issue with the WebClient in ExchangeCode function. Discord recently updated to use TLS 1.2 security protocol, so you just need to update the SecurityProtocolType to Tls12. In order to do this I also had to port the project over to the .net 4.5 framework.

Yeah I have dropped support already on master for .NET Framework (master is .NET Standard 2.0*).

What line / file you have to port specifically so I can look into those (feel free for a PR too :3)

*I know .NET Standard 2.0 is depreciated but I still need to look into Unity 2018 support for .NET Standard 2.1 and Godots support

ronfrigginjon commented 1 year ago

In RpcConnection.cs around line 970, inside the ExchangeCode function and just under the validation check I added the following: System.Net.ServicePointManager.Expect100Continue = true; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

However SecurityProtocolType of Tls12 is not available in net 3.5 and the rest of my project doesn't work with net 2.0 so I just switched the whole project over to .net 4.5