FluxpointDev / RevoltSharp

A C# lib for using the revolt chat API and connecting to the gateway to get events.
https://rvlt.gg/N33Rf6DE
MIT License
17 stars 3 forks source link

Add partial Cloudflare UAM support #18

Closed nulldg closed 1 year ago

nulldg commented 1 year ago

this adds a single field to ClientConfig called CfClearance, allowing you to provide a Cloudflare clearance cookie while Revolt is on UAM mode (ie to mitigate DDoS attacks). may be used in conjunction with automatic CF clearance acquisition. this is needed because UAM kills bots, potentially stalls bot development, and can be left enabled for hours or even days depending on the severity of the attack.

this method of restoring the bot during UAM is a bit trashy and it's not needed most of the time, so it's been hidden into the client config as a single field, but this was critical for getting my bot back online yesterday while revolt was suffering a DDoS attack.

steps to use this:

  1. use a browser to connect to revolt.chat using a spoofed user agent, mimicking the bot's full user agent (eg Revolt Bot (RevoltSharp) v6.0.5).
  2. complete the cloudflare challenge to receive a clearance cookie. cloudflare may be more suspicious of you because you will be using an unorthodox user agent.
  3. grab the cf_clearance cookie from your cookies. in firefox, you can find them under the storage tab in the developer tools.
  4. set the ClientConfig.CfClearance field to your clearance cookie before instantiating your RevoltClient instance with it.

example code:

ClientConfig config = new ClientConfig()
{
    CfClearance = "akbnewrhiujvcxz81asdifufsknj43-112392524-0-123" // Don't actually hard code this
};
Client = new RevoltClient(TOKEN, ClientMode.WebSocket, config);

the IP and UA must be identical between the recipient of the clearance (the browser) and the bot. if your bot is hosted non-locally, you will need to set up a proxy on your server and complete the cloudflare challenge through that.