From c2398f290059671e32744698df70f4ef4038c376 Mon Sep 17 00:00:00 2001 From: kozabrada123 <“kozabrada123@users.noreply.github.com”> Date: Sat, 27 May 2023 09:21:26 +0200 Subject: [PATCH] Add a sensible defaults for Identify and its props --- src/types/events/identify.rs | 107 ++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/src/types/events/identify.rs b/src/types/events/identify.rs index 19902f3..b4c9f5c 100644 --- a/src/types/events/identify.rs +++ b/src/types/events/identify.rs @@ -1,7 +1,7 @@ use crate::types::events::{PresenceUpdate, WebSocketEvent}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Deserialize, Serialize, Default)] +#[derive(Debug, Deserialize, Serialize)] pub struct GatewayIdentifyPayload { pub token: String, pub properties: GatewayIdentifyConnectionProps, @@ -22,6 +22,21 @@ pub struct GatewayIdentifyPayload { pub capabilities: Option, } +impl Default for GatewayIdentifyPayload { + fn default() -> Self { + Self::common() + } +} + +impl GatewayIdentifyPayload { + /// Uses the most common, 25% data along with client capabilities + /// + /// Basically pretends to be an official client on windows 10, with chrome 113.0.0.0 + pub fn common() -> Self { + Self { token: "".to_string(), properties: GatewayIdentifyConnectionProps::default(), compress: Some(false), large_threshold: None, shard: None, presence: None, intents: None, capabilities: Some(8189) } + } +} + impl GatewayIdentifyPayload { /// Creates an identify payload with the same default capabilities as the official client pub fn default_w_client_capabilities() -> Self { @@ -40,9 +55,97 @@ impl GatewayIdentifyPayload { impl WebSocketEvent for GatewayIdentifyPayload {} -#[derive(Debug, Deserialize, Serialize, Default)] +#[derive(Debug, Deserialize, Serialize)] pub struct GatewayIdentifyConnectionProps { + /// Almost always sent + /// + /// ex: "Linux", "Windows" pub os: String, + /// Almost always sent + /// + /// ex: "Firefox", "Chrome" pub browser: String, + /// Sometimes not sent, acceptable to be "" + /// + /// Speculation: + /// Only sent for mobile devices + /// + /// ex: "BlackBerry", "Windows Phone", "Android", "iPhone", "iPad", "" pub device: String, + /// Almost always sent, most commonly en-US + /// + /// ex: "en-US" + pub system_locale: String, + /// Almost always sent + /// + /// ex: any user agent, most common is "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" + pub browser_user_agent: String, + /// Almost always sent + /// + /// ex: "113.0.0.0" + pub browser_version: String, + /// Sometimes not sent, acceptable to be "" + /// + /// ex: "10" (For os = "Windows") + pub os_version: String, + /// Sometimes not sent, acceptable to be "" + pub referrer: String, + /// Sometimes not sent, acceptable to be "" + pub referring_domain: String, + /// Sometimes not sent, acceptable to be "" + pub referrer_current: String, + /// Almost always sent, most commonly "stable" + pub release_channel: String, + /// Almost always sent, identifiable if default is 0, should be around 199933 + pub client_build_number: u64, + //pub client_event_source: Option } + +impl Default for GatewayIdentifyConnectionProps { + /// Uses the most common, 25% data + fn default() -> Self { + Self::common() + } +} + +impl GatewayIdentifyConnectionProps { + + /// Returns a minimal, least data possible default + fn minimal() -> Self { + Self { + os: "".to_string(), + browser: "".to_string(), + device: "".to_string(), + system_locale: "en-US".to_string(), + browser_user_agent: "".to_string(), + browser_version: "".to_string(), + os_version: "".to_string(), + referrer: "".to_string(), + referring_domain: "".to_string(), + referrer_current: "".to_string(), + release_channel: "stable".to_string(), + client_build_number: 199933, + } + } + + /// Returns the most common connection props so we can't be tracked + pub fn common() -> Self { + let mut default = Self::default(); + + // See https://www.useragents.me/#most-common-desktop-useragents + // 25% of the web + default.browser_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36".to_string(); + default.browser = "Chrome".to_string(); + default.browser_version = "113.0.0.0".to_string(); + + default.system_locale = "en-US".to_string(); + + default.os = "Windows".to_string(); + default.os_version = "10".to_string(); + + default.client_build_number = 199933; + default.release_channel = "stable".to_string(); + + return default; + } +} \ No newline at end of file