diff --git a/Cargo.lock b/Cargo.lock index ddb54bb..13dcbe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,9 +69,9 @@ checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytes" @@ -155,9 +155,9 @@ checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "flate2" @@ -340,9 +340,9 @@ checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "http" @@ -514,15 +514,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libmimalloc-sys" -version = "0.1.34" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25d058a81af0d1c22d7a1c948576bee6d673f7af3c0f35564abd6c81122f513d" +checksum = "3979b5c37ece694f1f5e51e7ecc871fdb0f517ed04ee45f88d15d6d553cb9664" dependencies = [ "cc", "libc", @@ -642,9 +642,9 @@ dependencies = [ [[package]] name = "mimalloc" -version = "0.1.38" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "972e5f23f6716f62665760b0f4cbf592576a80c7b879ba9beaafc0e558894127" +checksum = "fa01922b5ea280a911e323e4d2fd24b7fe5cc4042e0d2cda3c40775cdc4bdc9c" dependencies = [ "libmimalloc-sys", ] @@ -763,9 +763,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -872,7 +872,7 @@ checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki 0.101.5", + "rustls-webpki 0.101.6", "sct", ] @@ -888,9 +888,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.101.5" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a27e3b59326c16e23d30aeb7a36a24cc0d29e71d68ff611cdfb4a01d013bed" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ "ring", "untrusted", @@ -950,9 +950,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.106" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -1023,9 +1023,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "socket2" @@ -1061,9 +1061,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" -version = "2.0.32" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", "quote", @@ -1072,18 +1072,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.48" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -1102,9 +1102,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" dependencies = [ "deranged", "serde", @@ -1114,15 +1114,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" dependencies = [ "time-core", ] @@ -1167,9 +1167,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -1193,7 +1193,7 @@ dependencies = [ "http", "httparse", "ring", - "rustls-webpki 0.101.5", + "rustls-webpki 0.101.6", "sha1_smol", "simdutf8", "tokio", @@ -1261,7 +1261,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "twilight-cache-inmemory" version = "0.15.4" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "bitflags 2.4.0", "dashmap", @@ -1272,7 +1272,7 @@ dependencies = [ [[package]] name = "twilight-gateway" version = "0.15.4" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "bitflags 2.4.0", "fastrand", @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "twilight-gateway-queue" version = "0.15.4" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "tokio", "tracing", @@ -1300,7 +1300,7 @@ dependencies = [ [[package]] name = "twilight-http" version = "0.15.4" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "fastrand", "hyper", @@ -1319,7 +1319,7 @@ dependencies = [ [[package]] name = "twilight-http-ratelimiting" version = "0.15.3" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "futures-util", "tokio", @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "twilight-model" version = "0.15.4" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "bitflags 2.4.0", "serde", @@ -1341,16 +1341,16 @@ dependencies = [ [[package]] name = "twilight-validate" version = "0.15.3" -source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#cf616672cd2afbc47da21da13cc302fb32ac97c7" +source = "git+https://github.com/Gelbpunkt/twilight.git?branch=15-custom#db4dbb62aa99fdbc4676c9d6a80ae3f9a468713d" dependencies = [ "twilight-model", ] [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "untrusted" diff --git a/README.md b/README.md index 73202b4..46289c5 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Create a file `config.json` and fill in these fields as you wish: }, "status": "idle", "backpressure": 100, + "validate_token": true, "externally_accessible_url": "ws://localhost:7878", "cache": { "channels": false, @@ -50,7 +51,7 @@ Create a file `config.json` and fill in these fields as you wish: } ``` -You can omit the `token` key entirely and set the `TOKEN` environment variable when running to avoid putting credentials in the configuration file. +You can omit the `token` key entirely and set the `TOKEN` environment variable when running to avoid putting credentials in the configuration file. Client tokens will be validated to match the one configured unless `validate_token` is set to `false`. By default, the total shard count will be calculated using the `/api/gateway/bot` endpoint. If you want to change this, set `shards` to the amount of shards. It will also launch all shards by default, you can customize this to launch only a range of shards using `shard_start` and `shard_end` (start inclusive, end exclusive). diff --git a/src/config.rs b/src/config.rs index b528114..1f21365 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,6 +36,8 @@ pub struct Config { pub status: Status, #[serde(default = "default_backpressure")] pub backpressure: usize, + #[serde(default = "default_validate_token")] + pub validate_token: bool, #[serde(default)] pub twilight_http_proxy: Option, pub externally_accessible_url: String, @@ -199,6 +201,10 @@ const fn default_backpressure() -> usize { 100 } +const fn default_validate_token() -> bool { + true +} + pub enum Error { InvalidConfig(JsonError), NotFound(String), diff --git a/src/server.rs b/src/server.rs index 71cdd03..b86ca49 100644 --- a/src/server.rs +++ b/src/server.rs @@ -258,7 +258,9 @@ pub async fn handle_client( } // Discord tokens may be prefixed by 'Bot ' in IDENTIFY - if identify.d.token.split_whitespace().last() != Some(&CONFIG.token) { + if CONFIG.validate_token + && identify.d.token.split_whitespace().last() != Some(&CONFIG.token) + { warn!("[{addr}] Token from client mismatched, disconnecting"); break; } @@ -305,7 +307,9 @@ pub async fn handle_client( }; // Discord tokens may be prefixed by 'Bot ' in RESUME - if resume.d.token.split_whitespace().last() != Some(&CONFIG.token) { + if CONFIG.validate_token + && resume.d.token.split_whitespace().last() != Some(&CONFIG.token) + { warn!("[{addr}] Token from client mismatched, disconnecting"); break; }