This commit is contained in:
FantasyPvP
2024-12-10 11:57:08 +00:00
parent 1707309d95
commit fb1c13bfa0
81 changed files with 2900 additions and 582 deletions
+1
View File
@@ -1 +1,2 @@
/target
*.env
Binary file not shown.
Binary file not shown.
-1
View File
@@ -1 +0,0 @@
MANIFEST-000040
Binary file not shown.
+467 -10
View File
@@ -191,6 +191,9 @@ name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
dependencies = [
"serde",
]
[[package]]
name = "ascii-canvas"
@@ -445,6 +448,12 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
@@ -555,6 +564,12 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "bytecount"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
[[package]]
name = "bytemuck"
version = "1.20.0"
@@ -576,6 +591,37 @@ dependencies = [
"serde",
]
[[package]]
name = "camino"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3"
dependencies = [
"serde",
]
[[package]]
name = "cargo-platform"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"
dependencies = [
"serde",
]
[[package]]
name = "cargo_metadata"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa"
dependencies = [
"camino",
"cargo-platform",
"semver",
"serde",
"serde_json",
]
[[package]]
name = "castaway"
version = "0.2.3"
@@ -668,15 +714,20 @@ name = "chatapp-backend"
version = "0.1.0"
dependencies = [
"chrono",
"dotenv",
"futures",
"rand",
"rocket",
"rocket_cors",
"rocket_ws",
"serde",
"serde_json",
"serenity",
"sha2",
"surrealdb",
"tokio",
"toml",
"tracing-subscriber",
]
[[package]]
@@ -731,6 +782,17 @@ dependencies = [
"inout",
]
[[package]]
name = "command_attr"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fcc89439e1bb4e19050a9586a767781a3060000d2f3296fd2a40597ad9421c5"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@@ -763,6 +825,16 @@ dependencies = [
"version_check",
]
[[package]]
name = "core-foundation"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@@ -778,6 +850,24 @@ dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
@@ -875,6 +965,7 @@ dependencies = [
"lock_api",
"once_cell",
"parking_lot_core",
"serde",
]
[[package]]
@@ -925,7 +1016,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b035a542cf7abf01f2e3c4d5a7acbaebfefe120ae4efc7bde3df98186e4b8af7"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
@@ -990,6 +1081,12 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "earcutr"
version = "0.4.3"
@@ -1046,6 +1143,15 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "error-chain"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc"
dependencies = [
"version_check",
]
[[package]]
name = "event-listener"
version = "5.3.1"
@@ -1093,6 +1199,16 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flate2"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "float_next_after"
version = "1.0.0"
@@ -1253,6 +1369,15 @@ dependencies = [
"thread_local",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generator"
version = "0.7.5"
@@ -1603,6 +1728,20 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590"
dependencies = [
"futures-util",
"http 0.2.12",
"hyper 0.14.31",
"rustls 0.21.12",
"tokio",
"tokio-rustls 0.24.1",
]
[[package]]
name = "hyper-rustls"
version = "0.27.3"
@@ -1618,7 +1757,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.0",
"tower-service",
"webpki-roots",
"webpki-roots 0.26.7",
]
[[package]]
@@ -1957,6 +2096,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "levenshtein"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]]
name = "lexicmp"
version = "0.1.0"
@@ -1984,7 +2129,7 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"libc",
]
@@ -2143,6 +2288,21 @@ dependencies = [
"unicase",
]
[[package]]
name = "mini-moka"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c325dfab65f261f386debee8b0969da215b3fa0037e74c8a1234db7ba986d803"
dependencies = [
"crossbeam-channel",
"crossbeam-utils",
"dashmap",
"skeptic",
"smallvec",
"tagptr",
"triomphe",
]
[[package]]
name = "miniz_oxide"
version = "0.8.0"
@@ -2680,6 +2840,17 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "pulldown-cmark"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
dependencies = [
"bitflags 2.6.0",
"memchr",
"unicase",
]
[[package]]
name = "quick_cache"
version = "0.5.2"
@@ -2838,7 +3009,7 @@ version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
"bitflags 2.6.0",
]
[[package]]
@@ -2925,6 +3096,50 @@ dependencies = [
"bytecheck",
]
[[package]]
name = "reqwest"
version = "0.11.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
dependencies = [
"base64 0.21.7",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"http 0.2.12",
"http-body 0.4.6",
"hyper 0.14.31",
"hyper-rustls 0.24.2",
"ipnet",
"js-sys",
"log",
"mime",
"mime_guess",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls 0.21.12",
"rustls-pemfile 1.0.4",
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper 0.1.2",
"system-configuration",
"tokio",
"tokio-rustls 0.24.1",
"tokio-util",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.25.4",
"winreg",
]
[[package]]
name = "reqwest"
version = "0.12.9"
@@ -2939,7 +3154,7 @@ dependencies = [
"http-body 1.0.1",
"http-body-util",
"hyper 1.5.1",
"hyper-rustls",
"hyper-rustls 0.27.3",
"hyper-util",
"ipnet",
"js-sys",
@@ -2956,7 +3171,7 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
"sync_wrapper",
"sync_wrapper 1.0.2",
"tokio",
"tokio-rustls 0.26.0",
"tokio-util",
@@ -2966,7 +3181,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots",
"webpki-roots 0.26.7",
"windows-registry",
]
@@ -3133,6 +3348,23 @@ dependencies = [
"version_check",
]
[[package]]
name = "rocket_cors"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfac3a1df83f8d4fc96aa41dba3b86c786417b7fc0f52ec76295df2ba781aa69"
dependencies = [
"http 0.2.12",
"log",
"regex",
"rocket",
"serde",
"serde_derive",
"unicase",
"unicase_serde",
"url",
]
[[package]]
name = "rocket_http"
version = "0.5.1"
@@ -3246,7 +3478,7 @@ version = "0.38.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6"
dependencies = [
"bitflags",
"bitflags 2.6.0",
"errno",
"libc",
"linux-raw-sys",
@@ -3265,6 +3497,20 @@ dependencies = [
"sct",
]
[[package]]
name = "rustls"
version = "0.22.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432"
dependencies = [
"log",
"ring",
"rustls-pki-types",
"rustls-webpki 0.102.8",
"subtle",
"zeroize",
]
[[package]]
name = "rustls"
version = "0.23.19"
@@ -3398,6 +3644,16 @@ version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "secrecy"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e"
dependencies = [
"serde",
"zeroize",
]
[[package]]
name = "semver"
version = "1.0.23"
@@ -3431,6 +3687,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_cow"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7bbbec7196bfde255ab54b65e34087c0849629280028238e67ee25d6a4b7da"
dependencies = [
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.215"
@@ -3506,6 +3771,43 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "serenity"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d72ec4323681bf9a3cabe40fd080abc2435859b502a1b5aa9bf693f125bfa76"
dependencies = [
"arrayvec",
"async-trait",
"base64 0.22.1",
"bitflags 2.6.0",
"bytes",
"chrono",
"command_attr",
"dashmap",
"flate2",
"futures",
"fxhash",
"levenshtein",
"mime_guess",
"parking_lot",
"percent-encoding",
"reqwest 0.11.27",
"secrecy",
"serde",
"serde_cow",
"serde_json",
"static_assertions",
"time",
"tokio",
"tokio-tungstenite 0.21.0",
"tracing",
"typemap_rev",
"typesize",
"url",
"uwl",
]
[[package]]
name = "sha1"
version = "0.10.6"
@@ -3576,6 +3878,21 @@ version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "skeptic"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16d23b015676c90a0f01c197bfdc786c20342c73a0afdda9025adb0bc42940a8"
dependencies = [
"bytecount",
"cargo_metadata",
"error-chain",
"glob",
"pulldown-cmark",
"tempfile",
"walkdir",
]
[[package]]
name = "slab"
version = "0.4.9"
@@ -3693,6 +4010,12 @@ dependencies = [
"loom",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_assertions_next"
version = "1.1.2"
@@ -3788,7 +4111,7 @@ dependencies = [
"path-clean",
"pharos",
"reblessive",
"reqwest",
"reqwest 0.12.9",
"revision",
"ring",
"rust_decimal",
@@ -3929,6 +4252,12 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "sync_wrapper"
version = "1.0.2"
@@ -3949,6 +4278,33 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "tagptr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]]
name = "tap"
version = "1.0.1"
@@ -4144,6 +4500,17 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f"
dependencies = [
"rustls 0.22.4",
"rustls-pki-types",
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.26.0"
@@ -4174,8 +4541,12 @@ checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38"
dependencies = [
"futures-util",
"log",
"rustls 0.22.4",
"rustls-pki-types",
"tokio",
"tokio-rustls 0.25.0",
"tungstenite 0.21.0",
"webpki-roots 0.26.7",
]
[[package]]
@@ -4191,7 +4562,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.0",
"tungstenite 0.23.0",
"webpki-roots",
"webpki-roots 0.26.7",
]
[[package]]
@@ -4254,6 +4625,7 @@ version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@@ -4320,6 +4692,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "triomphe"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85"
[[package]]
name = "try-lock"
version = "0.2.5"
@@ -4339,6 +4717,8 @@ dependencies = [
"httparse",
"log",
"rand",
"rustls 0.22.4",
"rustls-pki-types",
"sha1",
"thiserror 1.0.69",
"url",
@@ -4366,12 +4746,47 @@ dependencies = [
"utf-8",
]
[[package]]
name = "typemap_rev"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "typesize"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "549e54551d85ba6718a95333d9bc4367f69793d7aba638de30f8d25a1f554a1d"
dependencies = [
"chrono",
"dashmap",
"hashbrown 0.14.5",
"mini-moka",
"parking_lot",
"secrecy",
"serde_json",
"time",
"typesize-derive",
"url",
]
[[package]]
name = "typesize-derive"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd9fc0ad9e03a2b0c2e2a0eafaecccef2121829e1ab6ce9c9d790e6c6766bd1c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
name = "ubyte"
version = "0.10.4"
@@ -4415,6 +4830,16 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df"
[[package]]
name = "unicase_serde"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef53697679d874d69f3160af80bc28de12730a985d57bdf2b47456ccb8b11f1"
dependencies = [
"serde",
"unicase",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
@@ -4483,6 +4908,7 @@ dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]]
@@ -4520,6 +4946,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "uwl"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4bf03e0ca70d626ecc4ba6b0763b934b6f2976e8c744088bb3c1d646fbb1ad0"
[[package]]
name = "valuable"
version = "0.1.0"
@@ -4677,6 +5109,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webpki-roots"
version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webpki-roots"
version = "0.26.7"
@@ -4765,6 +5203,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@@ -4913,6 +5360,16 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.50.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]]
name = "write16"
version = "1.0.0"
+5
View File
@@ -14,3 +14,8 @@ surrealdb = "2.1.2"
chrono = "0.4.38"
rand = "0.8.5"
sha2 = "0.10.8"
rocket_cors = "0.6.0-alpha2"
serenity = "0.12.4"
dotenv = "0.15.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
toml = "0.8.19"
+11
View File
@@ -0,0 +1,11 @@
[chatsync]
socket_path = "/tmp/minecraft_chat/chat.sock"
[discord]
channel_id = 1315044374127841374
[server.dev]
url = "http://localhost:8080"
[server.prod]
url = "https://zxq5.dev"
+8
View File
@@ -0,0 +1,8 @@
[default]
address = "0.0.0.0"
port = 8000
[release]
address = "0.0.0.0"
port = 8000
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
MANIFEST-000155
@@ -0,0 +1 @@
2024/12/07-22:42:26.540786 140431350968320 [WARN] [db/db_impl/db_impl_open.cc:2254] DB::Open() failed: IO error: While lock file: database.db/LOCK: Resource temporarily unavailable
Binary file not shown.
+87
View File
@@ -1,3 +1,17 @@
DEFINE FUNCTION auth::credentials::validate($username: string, $password: string) {
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
IF $user
{
RETURN {
authenticated: crypto::argon2::compare($user.passhash, $password),
id: $user.id
};
}
ELSE
{ NONE }
;
}
DEFINE FUNCTION auth::sessiontoken::new($user: uuid) {
LET $token = rand::string(64);
@@ -10,3 +24,76 @@ DEFINE FUNCTION auth::sessiontoken::new($user: uuid) {
};
}
DEFINE FUNCTION auth::sessiontoken::validate($token: string) {
LET $exists = (SELECT * FROM SessionToken WHERE token = $token)[0];
IF $exists = NONE {
RETURN NONE;
}
IF time::now() > $exists.expires {
DELETE SessionToken:exists.id;
RETURN NONE;
};
RETURN $exists.user;
}
DEFINE FUNCTION auth::accesstoken::new($user: uuid, $max_uses: option<int>) {
IF $max_uses = NONE {
LET $max_uses = 1;
};
LET $token = rand::string(64);
CREATE AccessToken CONTENT {
id: rand::uuid::v4(),
max_uses: 1,
token: $token,
created: time::now(),
expires: time::now() + 7d,
creator: Entity:user
uses: 0,
};
RETURN $token;
}
DEFINE FUNCTION auth::user::signup(
$email: string,
$username: string,
$password: string,
$displayname: option<string>,
$accesstoken: option<string>,
){
LET $entity_id = rand::uuid::v4();
IF $displayname = NONE {
LET $displayname = $username;
};
CREATE Entity CONTENT {
id: $entity_id,
deleted: false,
displayname: $displayname,
joined: time::now(),
username: $username,
};
LET $human_id = rand::uuid::v4();
CREATE Human CONTENT {
id: $human_id,
email: $email,
passhash: crypto::argon2::generate($password),
entity: Entity:entity_id
};
IF !$accesstoken = NONE {
RELATE Human:human_id -> UserJoinedBy -> AccessToken:(SELECT id FROM AccessToken WHERE token = $accesstoken)[0]
}
RETURN $human_id
}
+32
View File
@@ -0,0 +1,32 @@
DEFINE FUNCTION message::send($from: uuid, $channel: uuid, $content: string, $reply_to: option<uuid>) {
LET $content_id = rand::uuid::v4();
CREATE MessageStringContent CONTENT {
id: $content_id,
content: $content
};
LET $message_id = rand::uuid::v4();
CREATE Message CONTENT {
id: $message_id,
channel: Channel:channel,
edited: false,
sent: time::now(),
reply_to: $reply_to,
};
RELATE Message:message_id -> HasContent -> MessageStringContent:content_id;
RELATE Entity:from -> SentMessage -> Message:message_id;
}
DEFINE FUNCTION message::edit($user: uuid, $message: uuid, $content: string) {
LET $id = (SELECT id
FROM Entity:user
->SentMessage
->(Message WHERE id = $message)
->HasContent
->MessageStringContent)[0];
UPDATE MessageStringContent SET content = $content WHERE id = $id.id;
UPDATE Message:message SET edited = true;
}
+51
View File
@@ -0,0 +1,51 @@
DEFINE FUNCTION user::human::new(
$email: string,
$username: string,
$password: string,
$displayname: option<string>,
$accesstoken: option<string>,
){
LET $entity_id = rand::uuid::v4();
IF $displayname = NONE {
LET $displayname = $username;
};
CREATE Entity CONTENT {
id: $entity_id,
deleted: false,
displayname: $displayname,
joined: time::now(),
username: $username,
};
LET $human_id = rand::uuid::v4();
CREATE Human CONTENT {
id: $human_id,
email: $email,
passhash: crypto::argon2::generate($password),
entity: Entity:entity_id
};
IF !$accesstoken = NONE {
RELATE Human:human_id -> UserJoinedBy -> AccessToken:(SELECT id FROM AccessToken WHERE token = $accesstoken)[0]
}
RETURN $human_id
}
DEFINE FUNCTION objects::human::get($id: uuid) {
LET $human = (SELECT * FROM Human WHERE id = $id)[0];
LET $entity = (SELECT * FROM Entity WHERE id = $human.entity)[0];
RETURN {
id: $human.id,
email: $human.email,
passhash: $human.passhash,
username: $entity.username,
displayname: $entity.displayname,
joined: $entity.joined
}
}
@@ -0,0 +1,482 @@
-- ------------------------------
-- OPTION
-- ------------------------------
OPTION IMPORT;
-- ------------------------------
-- FUNCTIONS
-- ------------------------------
DEFINE FUNCTION fn::auth::credentials::validate($username: string, $password: string) -> option<object> {
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
IF $user {
RETURN {
authenticated: crypto::argon2::compare($user.passhash, $password),
id: $user.id
};
} ELSE {
RETURN NONE
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::auth::sessiontoken::new($user: uuid) {
LET $token = rand::string(64);
CREATE SessionToken CONTENT {
created: time::now(),
expires: time::now() + 1w,
id: rand::uuid::v4(),
token: $token,
user: Entity:user
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::auth::sessiontoken::validate($token: string) {
LET $exists = (SELECT * FROM SessionToken WHERE token = $token)[0];
IF $exists = NONE { RETURN NONE; };
IF time::now() > $exists.expires {
DELETE SessionToken:exists.id;
RETURN NONE;
};
RETURN $exists.user;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::channel::new() {} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::accept($from: uuid, $to: uuid) {
IF (SELECT * FROM HasFriendRequest WHERE in = Entity:from AND out = Entity:to)[0] = NONE { RETURN NONE; } ELSE { DELETE HasFriendRequest WHERE in = Entity:from AND out = Entity:to; };
LET $fsid: uuid = rand::uuid::v4();
CREATE Friendship SET id = $fsid, channel_id = fn::channel::new(), since = time::now();
RELATE Entity:from -> HasFriendship -> Friendship:fsid CONTENT {
nickname = Entity:from.displayname
};
RELATE Entity:to -> HasFriendship -> Friendship:fsid CONTENT {
nickname = Entity:to.displayname
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::reject($from: uuid, $to: uuid) {
DELETE Entity:from->FriendRequest WHERE out = Entity:to;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::remove($from: uuid, $to: uuid) {
DELETE Entity:from->HasFriendship->Friendship WHERE <-HasFriendship.out = Entity:to;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::friend::request($from: uuid, $to: uuid) {
RELATE Entity:from -> HasFriendRequest -> Entity:to CONTENT {
created = time::now()
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::icon::default() -> string {
RETURN '/static/public/server_default.png';
} PERMISSIONS FULL;
DEFINE FUNCTION fn::message::edit($user: uuid, $message: uuid, $content: string) {
LET $id = (SELECT id FROM Entity:user->SentMessage->(Message WHERE id = $message)->HasContent->MessageStringContent)[0];
UPDATE MessageStringContent SET content = $content WHERE id = $id.id;
UPDATE Message:message SET edited = true;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::join($entity: uuid, $server: uuid) {
LET $user = (SELECT displayname FROM Entity WHERE id = $entity);
RELATE Entity:entity -> HasServer -> Server:server CONTENT {
joined: time::now(), nickname: $user.displayname
};
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::leave($server: uuid, $entity: uuid) {
DELETE HasServer WHERE out = Server:server AND in = Entity:entity;
DELETE HasRole WHERE in = Entity:entity AND ->Role.server = Server:server;
} PERMISSIONS FULL;
DEFINE FUNCTION fn::server::new($name: string, $creator: uuid) {
LET $id = rand::uuid::v4();
CREATE Server CONTENT {
created: time::now(),
icon_uri: fn::icon::default(),
id: $id,
name: $name,
owner: $creator
};
fn::server::join($id, $creator);
} PERMISSIONS FULL;
DEFINE FUNCTION fn::sessiontoken::new() -> string {
LET $token = rand::string(64);
CREATE SessionToken CONTENT {
created: time::now(),
expires: time::now() + 1w,
id: rand::uuid::v4(),
token: $token,
user: Entity:user
};
} PERMISSIONS FULL;
-- ------------------------------
-- TABLE: AccessToken
-- ------------------------------
DEFINE TABLE AccessToken TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON AccessToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD creator ON AccessToken TYPE record<Human> PERMISSIONS FULL;
DEFINE FIELD expires ON AccessToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON AccessToken TYPE uuid PERMISSIONS FULL;
DEFINE FIELD max_uses ON AccessToken TYPE option<int> PERMISSIONS FULL;
DEFINE FIELD token ON AccessToken TYPE string PERMISSIONS FULL;
DEFINE FIELD uses ON AccessToken TYPE int PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Channel
-- ------------------------------
DEFINE TABLE Channel TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Channel TYPE uuid PERMISSIONS FULL;
-- ------------------------------
-- TABLE: DataPool
-- ------------------------------
DEFINE TABLE DataPool TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD `value` ON DataPool TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON DataPool TYPE uuid PERMISSIONS FULL;
DEFINE FIELD key ON DataPool TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON DataPool TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Entity
-- ------------------------------
DEFINE TABLE Entity TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD deleted ON Entity TYPE bool VALUE false PERMISSIONS FULL;
DEFINE FIELD displayname ON Entity TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON Entity TYPE uuid PERMISSIONS FULL;
DEFINE FIELD joined ON Entity TYPE datetime PERMISSIONS FULL;
DEFINE FIELD username ON Entity TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Faction
-- ------------------------------
DEFINE TABLE Faction TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Faction TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Faction TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON Faction TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Friendship
-- ------------------------------
DEFINE TABLE Friendship TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD dm_channel ON Friendship TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD id ON Friendship TYPE uuid PERMISSIONS FULL;
DEFINE FIELD since ON Friendship TYPE datetime PERMISSIONS FULL;
-- ------------------------------
-- TABLE: GroupChat
-- ------------------------------
DEFINE TABLE GroupChat TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD channel ON GroupChat TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD icon_uri ON GroupChat TYPE string PERMISSIONS FULL;
DEFINE FIELD name ON GroupChat TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON GroupChat TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasChannel
-- ------------------------------
DEFINE TABLE HasChannel TYPE RELATION IN Server OUT Channel SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasChannel TYPE record<Server> PERMISSIONS FULL;
DEFINE FIELD out ON HasChannel TYPE record<Channel> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasContent
-- ------------------------------
DEFINE TABLE HasContent TYPE RELATION IN Message OUT MessageStringContent SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasContent TYPE record<Message> PERMISSIONS FULL;
DEFINE FIELD out ON HasContent TYPE record<MessageStringContent> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasDomain
-- ------------------------------
DEFINE TABLE HasDomain TYPE RELATION IN DataPool OUT Server | GroupChat | Friendship SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasDomain TYPE record<DataPool> PERMISSIONS FULL;
DEFINE FIELD out ON HasDomain TYPE record<Server | GroupChat | Friendship> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasFriendRequest
-- ------------------------------
DEFINE TABLE HasFriendRequest TYPE RELATION IN Entity OUT Entity SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON HasFriendRequest TYPE datetime PERMISSIONS FULL;
DEFINE FIELD in ON HasFriendRequest TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasFriendRequest TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasFriendship
-- ------------------------------
DEFINE TABLE HasFriendship TYPE RELATION IN Entity OUT Friendship SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasFriendship TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD nickname ON HasFriendship TYPE string PERMISSIONS FULL;
DEFINE FIELD out ON HasFriendship TYPE record<Friendship> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasGroupChat
-- ------------------------------
DEFINE TABLE HasGroupChat TYPE RELATION IN Entity OUT GroupChat SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasGroupChat TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasGroupChat TYPE record<GroupChat> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasPermission
-- ------------------------------
DEFINE TABLE HasPermission TYPE RELATION IN HasServer | ServerRole OUT Permission SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasPermission TYPE record<HasServer | ServerRole> PERMISSIONS FULL;
DEFINE FIELD out ON HasPermission TYPE record<Permission> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasRole
-- ------------------------------
DEFINE TABLE HasRole TYPE RELATION IN Entity OUT ServerRole SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasRole TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasRole TYPE record<ServerRole> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasServer
-- ------------------------------
DEFINE TABLE HasServer TYPE RELATION IN Entity OUT Server SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasServer TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD joined ON HasServer TYPE datetime PERMISSIONS FULL;
DEFINE FIELD nickname ON HasServer TYPE string PERMISSIONS FULL;
DEFINE FIELD out ON HasServer TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: HasTitle
-- ------------------------------
DEFINE TABLE HasTitle TYPE RELATION IN Entity OUT Title SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON HasTitle TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON HasTitle TYPE record<Title> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Human
-- ------------------------------
DEFINE TABLE Human TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD email ON Human TYPE string PERMISSIONS FULL;
DEFINE FIELD entity ON Human TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD id ON Human TYPE uuid PERMISSIONS FULL;
DEFINE FIELD passhash ON Human TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Message
-- ------------------------------
DEFINE TABLE Message TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD channel ON Message TYPE record<Channel> PERMISSIONS FULL;
DEFINE FIELD edited ON Message TYPE bool PERMISSIONS FULL;
DEFINE FIELD id ON Message TYPE uuid PERMISSIONS FULL;
DEFINE FIELD reply_to ON Message TYPE option<record<Message>> PERMISSIONS FULL;
DEFINE FIELD sent ON Message TYPE datetime PERMISSIONS FULL;
-- ------------------------------
-- TABLE: MessageStringContent
-- ------------------------------
DEFINE TABLE MessageStringContent TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD content ON MessageStringContent TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON MessageStringContent TYPE uuid PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Permission
-- ------------------------------
DEFINE TABLE Permission TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD id ON Permission TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Permission TYPE string PERMISSIONS FULL;
DEFINE FIELD server ON Permission TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Plugin
-- ------------------------------
DEFINE TABLE Plugin TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON Plugin TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON Plugin TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Plugin TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: PluginEntity
-- ------------------------------
DEFINE TABLE PluginEntity TYPE RELATION IN Plugin OUT Entity SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON PluginEntity TYPE record<Plugin> PERMISSIONS FULL;
DEFINE FIELD out ON PluginEntity TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: SentMessage
-- ------------------------------
DEFINE TABLE SentMessage TYPE RELATION IN Entity OUT Message SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON SentMessage TYPE record<Entity> PERMISSIONS FULL;
DEFINE FIELD out ON SentMessage TYPE record<Message> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Server
-- ------------------------------
DEFINE TABLE Server TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON Server TYPE datetime PERMISSIONS FULL;
DEFINE FIELD icon_uri ON Server TYPE string PERMISSIONS FULL;
DEFINE FIELD id ON Server TYPE uuid PERMISSIONS FULL;
DEFINE FIELD name ON Server TYPE string PERMISSIONS FULL;
DEFINE FIELD owner ON Server TYPE record<Entity> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: ServerRole
-- ------------------------------
DEFINE TABLE ServerRole TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD colour ON ServerRole TYPE string PERMISSIONS FULL;
DEFINE FIELD name ON ServerRole TYPE string PERMISSIONS FULL;
DEFINE FIELD server ON ServerRole TYPE record<Server> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: SessionToken
-- ------------------------------
DEFINE TABLE SessionToken TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD created ON SessionToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD expires ON SessionToken TYPE datetime PERMISSIONS FULL;
DEFINE FIELD id ON SessionToken TYPE uuid PERMISSIONS FULL;
DEFINE FIELD token ON SessionToken TYPE string PERMISSIONS FULL;
DEFINE FIELD user ON SessionToken TYPE record<Human> PERMISSIONS FULL;
-- ------------------------------
-- TABLE: Title
-- ------------------------------
DEFINE TABLE Title TYPE NORMAL SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD colour ON Title TYPE string PERMISSIONS FULL;
DEFINE FIELD faction ON Title TYPE record<Faction> PERMISSIONS FULL;
DEFINE FIELD name ON Title TYPE string PERMISSIONS FULL;
-- ------------------------------
-- TABLE: UserJoinedBy
-- ------------------------------
DEFINE TABLE UserJoinedBy TYPE RELATION IN Human OUT AccessToken SCHEMAFULL PERMISSIONS NONE;
DEFINE FIELD in ON UserJoinedBy TYPE record<Human> PERMISSIONS FULL;
DEFINE FIELD out ON UserJoinedBy TYPE record<AccessToken> PERMISSIONS FULL;
+90 -32
View File
@@ -1,14 +1,12 @@
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use rand::{thread_rng, Rng};
use rocket::{http::{CookieJar, Status}, options, post, request::{FromRequest, Outcome}, serde::json::Json, Request};
use rocket::{http::{Cookie, CookieJar, Status}, options, post, request::{FromRequest, Outcome}, serde::json::Json, Request};
use serde::Deserialize;
use sha2::{Digest, Sha256};
use surrealdb::RecordId;
use crate::{database::DB, user::{
User, AuthResponse
}};
use crate::{database::DB, user::User};
#[derive(Deserialize)]
pub struct UserLoginForm {
@@ -22,45 +20,105 @@ pub fn login_options() -> Status {
}
#[post("/login", data = "<user>")]
pub async fn login(user: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
println!("Logging in: {}", user.username);
if let Ok(response) = User::authenticate(user.username.clone(), user.password.clone()).await {
if response.matches {
let token = SessionToken::new(response.user_id).await;
jar.add_private(("auth", token.token));
println!("success!");
return Status::Ok
} else {
println!("does not match");
#[post("/login", data = "<form>")]
pub async fn login(form: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
match User::login(form.username.clone(), form.password.clone()).await {
Ok(token) => {
println!("logged in");
jar.add_private(Cookie::new("auth-token", token));
Status::Ok
}
Err(e) => {
println!("login failed: {}", e);
Status::Unauthorized
}
} else {
println!("response err");
}
println!("failed!");
return Status::Unauthorized
}
#[derive(Deserialize)]
pub struct UserSignupForm {
username: String,
password: String,
token: String,
}
#[options("/signup")]
pub fn signup_options() -> Status {
Status::Ok
}
#[post("/signup", data = "<user>")]
pub async fn signup(user: Json<UserLoginForm>, jar: &CookieJar<'_>) -> Status {
println!("signing up: {}", user.username);
User::create(user.username.clone(), user.password.clone()).await;
login(user, jar).await
pub async fn signup(user: Json<UserSignupForm>, jar: &CookieJar<'_>) -> Status {
match User::signup(
user.username.clone(),
user.username.clone(),
user.password.clone(),
user.username.clone()
).await {
Ok(token) => {
println!("signed up");
jar.add_private(Cookie::new("auth-token", token));
Status::Ok
}
Err(e) => {
println!("signup failed: {}", e);
Status::Conflict
}
}
}
pub type SessionTokenGuard = User;
#[derive(Debug, Clone)]
@@ -76,7 +134,7 @@ impl<'r> FromRequest<'r> for SessionTokenGuard {
type Error = ();
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error> {
if let Some(cookie) = req.cookies().get_private("auth") {
if let Some(cookie) = req.cookies().get_private("auth-token") {
let token = cookie.value().to_string();
return match DB
.query("
+133
View File
@@ -0,0 +1,133 @@
use std::{fs, os::unix::fs::PermissionsExt, path::Path};
use rocket::{get, serde::json::Json};
use rocket::tokio::{
self,
net::{UnixListener, UnixStream},
io::{AsyncReadExt, AsyncWriteExt},
sync::Mutex,
};
use std::sync::Arc;
use serde::{Deserialize, Serialize};
use crate::messenger::MessengerServer;
const SOCKET_PATH: &str = "/tmp/minecraft_chat/chat.sock";
const SOCKET_DIR: &str = "/tmp/minecraft_chat";
#[derive(Deserialize)]
struct MinecraftMessage {
player: String,
content: String,
}
#[derive(Serialize)]
struct Response {
status: String,
}
#[derive(Serialize)]
pub struct Status {
status: String,
timestamp: i64,
}
// This function ensures the socket directory exists with correct permissions
pub fn init_socket() {
// Create socket directory if it doesn't exist
let socket_dir = "/tmp/minecraft_chat";
if !std::path::Path::new(socket_dir).exists() {
fs::create_dir(socket_dir).expect("Failed to create socket directory");
// Set directory permissions to 755 (rwxr-xr-x)
fs::set_permissions(socket_dir, fs::Permissions::from_mode(0o755))
.expect("Failed to set directory permissions");
}
}
pub fn get_socket_path() -> String {
"/tmp/minecraft_chat/chat.sock".to_string()
}
pub async fn start_unix_socket(messenger: Arc<Mutex<MessengerServer>>) {
// Ensure the socket directory exists with correct permissions
if !Path::new(SOCKET_DIR).exists() {
fs::create_dir(SOCKET_DIR).expect("Failed to create socket directory");
fs::set_permissions(SOCKET_DIR, fs::Permissions::from_mode(0o755))
.expect("Failed to set directory permissions");
}
// Remove existing socket file if it exists
if Path::new(SOCKET_PATH).exists() {
fs::remove_file(SOCKET_PATH).expect("Failed to remove existing socket");
}
// Create and bind to the Unix socket
let listener = UnixListener::bind(SOCKET_PATH).expect("Failed to bind to Unix socket");
// Set socket file permissions to 777 for testing (adjust as needed)
fs::set_permissions(SOCKET_PATH, fs::Permissions::from_mode(0o777))
.expect("Failed to set socket permissions");
println!("Unix socket listening at {}", SOCKET_PATH);
while let Ok((stream, _)) = listener.accept().await {
let messenger = messenger.clone();
tokio::spawn(async move {
handle_connection(stream, messenger).await;
});
}
}
async fn handle_connection(mut stream: UnixStream, messenger: Arc<Mutex<MessengerServer>>) {
let mut buffer = [0; 1024];
match stream.read(&mut buffer).await {
Ok(n) => {
if let Ok(message_str) = String::from_utf8(buffer[..n].to_vec()) {
if let Ok(message) = serde_json::from_str::<MinecraftMessage>(&message_str) {
// Forward the message to the chat system
let response = handle_minecraft_message(message, messenger).await;
// Send response
if let Ok(response_json) = serde_json::to_string(&response) {
let _ = stream.write_all(response_json.as_bytes()).await;
}
}
}
}
Err(e) => eprintln!("Error reading from Unix socket: {}", e),
}
}
async fn handle_minecraft_message(msg: MinecraftMessage, messenger: Arc<Mutex<MessengerServer>>) -> Response {
// Create a real-time message
use crate::messenger::RealTimeMessage;
use std::time::{SystemTime, UNIX_EPOCH};
let message = RealTimeMessage {
message_id: 0,
user_id: "minecraft".to_string(),
display_name: msg.player,
created_at: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as i64,
content: msg.content,
};
// Send the message to channel 1 (or adjust as needed)
messenger.lock().await.send(1, message).await;
Response {
status: "ok".to_string(),
}
}
#[get("/minecraft/chat")]
pub fn chat() -> Json<Status> {
Json(Status {
status: "ok".to_string(),
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs() as i64,
})
}
+31
View File
@@ -0,0 +1,31 @@
pub mod listener;
use listener::init_socket;
use rocket::fairing::Fairing;
use std::sync::Arc;
use rocket::tokio::sync::Mutex;
use crate::messenger::MessengerServer;
pub struct ChatSyncFairing {
pub messenger: Arc<Mutex<MessengerServer>>,
}
#[rocket::async_trait]
impl Fairing for ChatSyncFairing {
fn info(&self) -> rocket::fairing::Info {
rocket::fairing::Info {
name: "Chat Sync",
kind: rocket::fairing::Kind::Liftoff,
}
}
async fn on_liftoff(&self, _rocket: &rocket::Rocket<rocket::Orbit>) {
let messenger = self.messenger.clone();
init_socket();
tokio::spawn(async move {
listener::start_unix_socket(messenger).await;
});
}
}
+77
View File
@@ -0,0 +1,77 @@
use std::sync::LazyLock;
use serde::{Deserialize, Serialize};
use toml::Table;
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
socket_path: String,
channel_id: u64,
pub dev_url: String,
pub prod_url: String
}
impl Config {
pub fn load() -> Config {
let content = match std::fs::read_to_string("Deploy.toml") {
Ok(content) => content,
Err(e) => {
eprintln!("Failed to read Deploy.toml: {}", e);
return Config::default();
},
};
let table: Table = match content.parse::<Table>() {
Ok(table) => table,
Err(e) => {
eprintln!("Failed to parse Deploy.toml: {}", e);
return Config::default();
},
};
let mut config = Config::default();
if let Some(socket_path) = table.get("chatsync") {
if let Some(socket_path) = socket_path.as_table() {
if let Some(path) = socket_path.get("socket_path") {
config.socket_path = path.to_string();
}
}
}
// get urls
if let Some(server) = table.get("server") {
if let Some(server) = server.as_table() {
if let Some(url) = server.get("dev") {
if let Some(url) = url.as_table() {
if let Some(url) = url.get("url") {
config.dev_url = url.to_string();
println!("OK!")
}
}
}
if let Some(url) = server.get("prod") {
if let Some(url) = url.as_table() {
if let Some(url) = url.get("url") {
config.prod_url = url.to_string();
}
}
}
}
}
config
}
}
impl Default for Config {
fn default() -> Self {
Config {
socket_path: "/tmp/minecraft_chat/chat.sock".to_string(),
channel_id: 1315044374127841374,
dev_url: "http://localhost:8080".to_string(),
prod_url: "https://zxq5.dev".to_string()
}
}
}
+20
View File
@@ -0,0 +1,20 @@
#[derive(Debug)]
pub enum BackendError {
DbError(String),
}
impl std::fmt::Display for BackendError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
BackendError::DbError(message) => write!(f, "{}", message),
}
}
}
impl std::error::Error for BackendError {}
impl From<surrealdb::Error> for BackendError {
fn from(err: surrealdb::Error) -> Self {
BackendError::DbError(err.to_string())
}
}
+5
View File
@@ -0,0 +1,5 @@
#[get("/license/<username>")]
pub async fn get_meme_license(username: String) -> String {
format!("Meme license for {}", username)
}
View File
+52 -27
View File
@@ -1,43 +1,68 @@
use auth::{login, login_options, signup, signup_options};
use rocket::{fs::FileServer, launch, routes};
use std::sync::Arc;
use config::Config;
use rocket::http::Method;
use rocket::tokio::sync::Mutex;
use rocket::{fs::FileServer, launch, routes};
use rocket_cors::{AllowedHeaders, AllowedOrigins, CorsOptions};
use std::sync::Arc;
mod messenger;
mod auth;
mod user;
mod database;
mod error;
mod features;
mod messenger;
mod servers;
mod user;
mod chatsync;
mod config;
use messenger::{MessengerServer, connect};
pub(crate) use error::BackendError;
use messenger::{connect, MessengerServer};
use chatsync::ChatSyncFairing;
#[launch]
async fn rocket() -> _ {
let messenger = Arc::new(Mutex::new(MessengerServer::new()));
let chat_sync = ChatSyncFairing {
messenger: messenger.clone(),
};
let config = Config::load();
let cors = CorsOptions::default()
.allowed_origins(AllowedOrigins::some_exact(&[
&config.dev_url,
&config.prod_url,
]))
.allowed_methods(
vec![Method::Get, Method::Post, Method::Options]
.into_iter()
.map(From::from)
.collect(),
)
.allowed_headers(AllowedHeaders::some(&[
"Authorization",
"Accept",
"Content-Type",
]))
.allow_credentials(true);
database::init().await.unwrap();
rocket::build()
.manage(messenger)
.mount("/", routes![
connect,
login,
signup,
login_options,
signup_options,
])
.mount("/static", FileServer::from("static"))
.attach(rocket::fairing::AdHoc::on_response("CORS", |_, res| Box::pin(async move {
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Origin",
"*"
));
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS"
));
res.set_header(rocket::http::Header::new(
"Access-Control-Allow-Headers",
"*"
));
})))
.mount(
"/api",
routes![
connect,
login,
login_options,
signup,
signup_options,
],
)
.manage(messenger)
.manage(config)
.attach(cors.to_cors().unwrap())
.attach(chat_sync)
}
+40 -36
View File
@@ -1,5 +1,6 @@
use std::{collections::HashMap, sync::Arc, time::{SystemTime, UNIX_EPOCH}};
use chrono::Utc;
use rocket::{
futures::{
channel::mpsc,
@@ -16,46 +17,49 @@ use rocket::{
use serde::Serialize;
use rocket_ws::{Channel, WebSocket, stream::DuplexStream};
use surrealdb::{RecordId, Uuid};
use surrealdb::{RecordId, Uuid, Datetime};
use crate::{auth::SessionTokenGuard, user::User};
#[get("/messenger/connect/<channel_id>/<user_id>")]
pub async fn connect<'r> (
// user: SessionTokenGuard,
user_id: String,
ws: WebSocket,
messenger: &'r rocket::State<Arc<Mutex<MessengerServer>>>,
channel_id: i32,
mut shutdown: Shutdown,
) -> Result<Channel<'r>, Status> {
let messenger = Arc::clone(messenger.inner());
Ok(ws.channel(move | channel| {
Box::pin(async move {
#[get("/messenger/connect/<channel_id>")]
pub async fn connect<'r> (
user: SessionTokenGuard,
ws: WebSocket,
messenger: &'r rocket::State<Arc<Mutex<MessengerServer>>>,
channel_id: i32,
mut shutdown: Shutdown,
) -> Result<Channel<'r>, Status> {
let messenger = Arc::clone(messenger.inner());
Ok(ws.channel(move | channel| {
Box::pin(async move {
let (sender, receiver) = mpsc::channel::<RealTimeMessage>(100);
let (ws_sender, ws_receiver) = channel.split();
println!("REGISTERING: {}", user.id);
messenger.lock().await.register(user.id.clone(), channel_id, sender);
tokio::select! {
_ = inbound_message(ws_receiver, messenger.clone(), channel_id, &user) => {},
_ = outbound_message(ws_sender, receiver) => {},
_ = &mut shutdown => {},
}
// Once the client disconnects, or the server is shutdown they are deregistered from the channel.
println!("DEREGISTERING: {}", user.id);
messenger.lock().await.deregister(user.id);
Ok(())
})
}))
}
let user = User {
id: RecordId::from_table_key("User", Uuid::new_v4().to_string()),
email: "".to_string(),
username: user_id,
passhash: "test".to_string(),
displayname: "test".to_string(),
joined: Datetime::from(Utc::now()),
};
let (sender, receiver) = mpsc::channel::<RealTimeMessage>(100);
let (ws_sender, ws_receiver) = channel.split();
messenger.lock().await.register(user.id.clone(), channel_id, sender);
tokio::select! {
_ = inbound_message(ws_receiver, messenger.clone(), channel_id, &user) => {},
_ = outbound_message(ws_sender, receiver) => {},
_ = &mut shutdown => {},
}
messenger.lock().await.deregister(user.id);
Ok(())
})
}))
}
@@ -72,7 +76,7 @@ pub async fn inbound_message(
let message = RealTimeMessage {
message_id: 0,
user_id: user.id.key().to_string(),
user_id: user.id.key().to_string().trim_start_matches('⟨').trim_end_matches('⟩').to_string(),
display_name: user.username.clone(),
created_at: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64,
content: text,
+21
View File
@@ -0,0 +1,21 @@
use rocket::{get, serde::json::Json};
use serde::Serialize;
#[get("/servers")]
pub fn servers() -> Json<Vec<Server>> {
Json(vec![
Server { id: "0".to_string(), name: "Test Server".to_string() },
Server { id: "1".to_string(), name: "Test Server2".to_string() },
Server { id: "2".to_string(), name: "Test Server3".to_string() },
Server { id: "3".to_string(), name: "Test Server4".to_string() },
Server { id: "4".to_string(), name: "Test Server5".to_string() },
Server { id: "5".to_string(), name: "Test Server6".to_string() },
Server { id: "6".to_string(), name: "Test Server7".to_string() },
])
}
#[derive(Serialize)]
struct Server {
id: String,
name: String,
}
+105 -52
View File
@@ -1,78 +1,131 @@
use serde::{Deserialize, Serialize};
use surrealdb::RecordId;
use crate::database::DB;
use surrealdb::{Datetime, RecordId};
use chrono::Utc;
use crate::{database::DB, BackendError};
#[derive(Debug, Deserialize, Serialize)]
pub struct User {
pub id: RecordId,
pub username: String,
pub email: String,
pub passhash: String,
pub displayname: String,
pub joined: i64,
pub joined: Datetime,
}
#[derive(Debug, Deserialize)]
pub struct AuthResponse {
pub matches: bool,
pub user_id: RecordId,
#[derive(Debug, Deserialize, Serialize)]
struct Entity {
id: RecordId,
deleted: bool,
displayname: String,
joined: Datetime,
username: String
}
#[derive(Debug, Deserialize, Serialize)]
struct Human {
id: RecordId,
email: String,
passhash: String
}
impl User {
pub async fn authenticate(username: String, password: String) -> Result<AuthResponse, ()> {
pub async fn signup(
username: String,
email: String,
password: String,
displayname: String
) -> Result<String, BackendError> {
match DB
.query("
LET $user = (SELECT id, passhash FROM User WHERE username = $username)[0];
RETURN {
matches: crypto::argon2::compare($user.passhash, $password),
user_id: $user.id
}"
)
.bind(("username", username))
.bind(("password", password))
.await
.map_err(|_| ())?
.take::<Option<AuthResponse>>(0)
{
Ok(Some(response)) => Ok(response),
Ok(None) => {
println!("User not found");
Err(())
}
Err(e) => {
println!("Error authenticating user: {}", e);
Err(())
}
_ => Err(()),
}
// let entity = DB
// .create("Entity")
// .content(Entity {
// id: RecordId::from(("Entity", Id::rand())),
// deleted: false,
// displayname: displayname,
// joined: Datetime::now(),
// username: username,
// })
// .await;
return Ok(String::new());
// match DB
// .query("
// LET $entity_id = CREATE Entity CONTENT {
// deleted: false,
// displayname: $displayname,
// joined: time::now(),
// username: $username,
// } RETURN AFTER.id;
// LET $human_id = CREATE Human CONTENT {
// email: $email,
// passhash: crypto::argon2::generate($password),
// } RETURN AFTER.id;
// LET $node1 = type::thing('Entity', $entity_id);
// LET $node2 = type::thing('Human', $human_id);
// RELATE $node2 -> HasEntity -> $node1;
// LET $session_token = CREATE SessionToken CONTENT {
// id: rand::uuid::v4(),
// created: time::now(),
// expires: time::now() + 7d,
// token: rand::string(64),
// user: type::thing('Human', $human_id),
// } RETURN AFTER.token;
// RETURN $session_token;
// ")
// .bind(("username", username))
// .bind(("email", email))
// .bind(("password", password))
// .bind(("displayname", displayname))
// .await
// .unwrap()
// .take::<Option<String>>(0)
// .map_err(|e| BackendError::from(e))
// {
// Ok(Some(user)) => Ok(user),
// Ok(None) => panic!("NO TOKEN RETURNED"),
// _ => Err(BackendError::DbError("Failed to create user".to_string())),
// }
}
pub async fn create(username: String, password: String) -> Result<String, ()> {
pub async fn login(username: String, password: String) -> Result<String, BackendError> {
match DB
.query("
CREATE User:uuid() SET
username = $username,
displayname = $displayname,
passhash = crypto::argon2::generate($passhash),
joined = $joined;
SELECT * FROM User WHERE username = $username
LET $human = (SELECT id, passhash FROM Human WHERE email = $email)[0];
IF !crypto::argon2::compare($human.passhash, $password) {
RETURN NONE;
};
LET $session_token = rand::string(64);
CREATE SessionToken CONTENT {
id: rand::uuid::v4(),
created: time::now(),
expires: time::now() + 7d,
token: $session_token,
user: type::thing('Human', $human.id),
};
RETURN $session_token;
")
.bind(("username", username.clone()))
.bind(("passhash", password))
.bind(("displayname", username))
.bind(("joined", Utc::now().timestamp()))
.bind(("email", username))
.bind(("password", password))
.await
.unwrap()
.take::<Option<User>>(0)
.take::<Option<String>>(0)
.map_err(|e| BackendError::from(e))
{
Ok(Some(user)) => {
let k = user.id.key().to_string();
println!("Created User: {}", k);
Ok(k)
},
_ => Err(())
Ok(Some(user)) => Ok(user),
_ => Err(BackendError::DbError("Failed to create user".to_string())),
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 696 KiB