From 983cd29f5a2c3d9cd1d6a9c4f343adcffe54f88c Mon Sep 17 00:00:00 2001 From: "Jakob L. Kreuze" Date: Tue, 6 Apr 2021 12:23:00 -0400 Subject: Initial import. --- scarymaze/.gitignore | 5 + scarymaze/Cargo.lock | 1127 +++++++++++++++++++++++++++++++++++++++++++++++ scarymaze/Cargo.toml | 30 ++ scarymaze/README.md | 35 ++ scarymaze/src/client.rs | 350 +++++++++++++++ scarymaze/src/server.rs | 247 +++++++++++ 6 files changed, 1794 insertions(+) create mode 100644 scarymaze/.gitignore create mode 100644 scarymaze/Cargo.lock create mode 100644 scarymaze/Cargo.toml create mode 100644 scarymaze/README.md create mode 100644 scarymaze/src/client.rs create mode 100644 scarymaze/src/server.rs (limited to 'scarymaze') diff --git a/scarymaze/.gitignore b/scarymaze/.gitignore new file mode 100644 index 0000000..25d23f6 --- /dev/null +++ b/scarymaze/.gitignore @@ -0,0 +1,5 @@ +target/* +!target/release +target/release/* +!target/release/server +!target/release/client diff --git a/scarymaze/Cargo.lock b/scarymaze/Cargo.lock new file mode 100644 index 0000000..c7d1a54 --- /dev/null +++ b/scarymaze/Cargo.lock @@ -0,0 +1,1127 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "vec-arena", +] + +[[package]] +name = "async-global-executor" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-mutex", + "blocking", + "futures-lite", + "num_cpus", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9315f8f07556761c3e48fec2e6b276004acf426e6dc068b2c2251854d65ee0fd" +dependencies = [ + "concurrent-queue", + "fastrand", + "futures-lite", + "libc", + "log", + "nb-connect", + "once_cell", + "parking", + "polling", + "vec-arena", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-lock" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1996609732bde4a9988bc42125f55f2af5f3c36370e27c778d5191a4a1b63bfb" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-mutex" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-std" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f06685bad74e0570f5213741bea82158279a4103d988e57bfada11ad230341" +dependencies = [ + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "blocking" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + +[[package]] +name = "bumpalo" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" + +[[package]] +name = "cache-padded" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + +[[package]] +name = "cc" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bae8f328835f8f5a6ceb6a7842a7f2d0c03692adb5c889347235d59194731fe3" +dependencies = [ + "autocfg 1.0.1", + "cfg-if 1.0.0", + "lazy_static", + "loom", +] + +[[package]] +name = "ctor" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "event-listener" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" + +[[package]] +name = "fastrand" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" +dependencies = [ + "instant", +] + +[[package]] +name = "fixedbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "futures" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" + +[[package]] +name = "futures-executor" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" + +[[package]] +name = "futures-lite" +version = "1.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" + +[[package]] +name = "futures-task" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" +dependencies = [ + "once_cell", +] + +[[package]] +name = "futures-util" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "generator" +version = "0.6.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fed24fd1e18827652b4d55652899a1e9da8e54d91624dc3437a5bc3a9f9a9c" +dependencies = [ + "cc", + "libc", + "log", + "rustversion", + "winapi", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "gloo-timers" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +dependencies = [ + "autocfg 1.0.1", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "js-sys" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", + "value-bag", +] + +[[package]] +name = "loom" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d44c73b4636e497b4917eb21c33539efa3816741a2d3ff26c6316f1b529481a4" +dependencies = [ + "cfg-if 1.0.0", + "generator", + "scoped-tls", +] + +[[package]] +name = "maze_generator" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9760a510e560932ff42cba79156caa14d6eb639406f5c7de505f6886adb97d" +dependencies = [ + "petgraph", + "rand 0.7.3", + "rand_chacha 0.2.2", +] + +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "nb-connect" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670361df1bc2399ee1ff50406a0d422587dd3bb0da596e1978fe8e05dabddf4f" +dependencies = [ + "libc", + "socket2", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-integer", + "num-iter", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg 1.0.1", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg 1.0.1", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg 1.0.1", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" + +[[package]] +name = "openssl" +version = "0.10.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-sys" +version = "0.9.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +dependencies = [ + "autocfg 1.0.1", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "petgraph" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "polling" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "log", + "wepoll-sys", + "winapi", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rustversion" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" + +[[package]] +name = "scarymaze" +version = "0.1.0" +dependencies = [ + "async-std", + "futures", + "maze_generator", + "openssl", + "petgraph", + "rand 0.8.3", + "sdl2", +] + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "sdl2" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d051a07231e303f5f719da78cb6f7394f6d5b54f733aef5b0b447804a83edd7b" +dependencies = [ + "bitflags", + "lazy_static", + "libc", + "num", + "rand 0.6.5", + "sdl2-sys", +] + +[[package]] +name = "sdl2-sys" +version = "0.32.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34e71125077d297d57e4c1acfe8981b5bdfbf5a20e7b589abfdcb33bf1127f86" +dependencies = [ + "cfg-if 0.1.10", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "value-bag" +version = "1.0.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1" +dependencies = [ + "ctor", +] + +[[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + +[[package]] +name = "vec-arena" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" + +[[package]] +name = "web-sys" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wepoll-sys" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +dependencies = [ + "cc", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/scarymaze/Cargo.toml b/scarymaze/Cargo.toml new file mode 100644 index 0000000..acee02f --- /dev/null +++ b/scarymaze/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "scarymaze" +version = "0.1.0" +authors = ["Jakob L. Kreuze "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +maze_generator = "1.1.1" +petgraph = "0.5.1" +sdl2 = "0.32" +async-std = "1.9.0" +futures = "0.3.4" +rand = "0.8.3" +openssl = "0.10.32" + +[[bin]] +name = "client" +path = "src/client.rs" + +[[bin]] +name = "server" +path = "src/server.rs" + +[profile.release] +opt-level = 'z' # Optimize for size. +lto = true +codegen-units = 1 +panic = 'abort' diff --git a/scarymaze/README.md b/scarymaze/README.md new file mode 100644 index 0000000..9ea4f80 --- /dev/null +++ b/scarymaze/README.md @@ -0,0 +1,35 @@ +# scarymaze + +"I tried to get to level 489, but I was too scared." + +I was hoping that the strings from OpenSSL would make it fairly easy to +determine the behavior of the following function, but that was not the case. No +one had solved the challenge until it was re-released with symbols included. + +```rust +fn my_encrypt(packet: &[u8]) -> Vec { + let mut rng = rand::thread_rng(); + let mut iv = [0 as u8; 16]; + rng.fill_bytes(&mut iv); + + let cipher = Cipher::aes_128_cbc(); + let key = AES_KEY.as_bytes(); + let mut data = encrypt(cipher, key, Some(&iv), packet).unwrap(); + + let mut ciphertext = Vec::from(iv); + ciphertext.append(&mut data); + ciphertext +} +``` + +Once you realized that the network traffic was being encrypted with AES-128-CBC, +you could capture packet traces and decrypt it. The packet format was designed +to be simple enough that be reverse engineered from packet traces and client +interaction alone. + +Then, you were to write your own client which would solve the mazes for you. The +server would give you the flag when you had reached level 489. + +Solving mazes can be done with an +[algorithm](https://en.wikipedia.org/wiki/Depth-first_search) usually introduced +within the first month of a university computer science program. diff --git a/scarymaze/src/client.rs b/scarymaze/src/client.rs new file mode 100644 index 0000000..fc31491 --- /dev/null +++ b/scarymaze/src/client.rs @@ -0,0 +1,350 @@ +#[link(name = "openssl", kind = "static")] +extern crate openssl; + +use maze_generator::ellers_algorithm::EllersGenerator; +use maze_generator::prelude::*; +// use petgraph::graphmap::GraphMap; +// use std::cell::RefCell; +// use std::rc::Rc; + +extern crate sdl2; + +use sdl2::event::Event; +use sdl2::keyboard::Keycode; +use sdl2::pixels::Color; +use sdl2::rect::Point; + +use std::f64::consts::PI; + +const WIDTH: i32 = 800; +const HEIGHT: i32 = 600; + +struct Vec2 { + x: T, + y: T, +} + +impl Vec2 { + fn new(x: T, y: T) -> Vec2 { + Vec2 { x, y } + } +} + +use std::io::prelude::*; +use std::net::TcpStream; +const HOST_NAME: &'static str = "scarymaze.dynamic.ctf.umasscybersec.org:8080"; + +const SERVER_MAP: u8 = 0; +const SERVER_GOTO: u8 = 1; +const SERVER_MESSAGE: u8 = 2; + +enum ClientMessage { + North, + South, + East, + West, + Unknown, +} + +const AES_KEY: &'static str = "STRINGS NOT HERE"; + +use openssl::symm::{decrypt, encrypt, Cipher}; +use rand::RngCore; + +fn my_encrypt(packet: &[u8]) -> Vec { + let mut rng = rand::thread_rng(); + let mut iv = [0 as u8; 16]; + rng.fill_bytes(&mut iv); + + let cipher = Cipher::aes_128_cbc(); + let key = AES_KEY.as_bytes(); + let mut data = encrypt(cipher, key, Some(&iv), packet).unwrap(); + + let mut ciphertext = Vec::from(iv); + ciphertext.append(&mut data); + ciphertext +} + +fn my_decrypt(packet: &[u8]) -> Vec { + let iv = &packet[..16]; + let data = &packet[16..]; + let cipher = Cipher::aes_128_cbc(); + let key = AES_KEY.as_bytes(); + let plaintext = decrypt(cipher, key, Some(iv), data).unwrap(); + plaintext +} + +fn print_map(map: &Vec>, pos: &Vec2) { + let maze_size = 24; + for y in 0..maze_size { + for x in 0..maze_size { + if x == pos.x && y == pos.y { + print!("o"); + } else if map[x as usize][y as usize] != 0 { + if map[x as usize][y as usize] == 2 { + print!("g"); + } else { + print!("x"); + } + } else { + print!(" "); + } + } + println!(); + } +} + +use std::convert::TryInto; +use std::iter; + +fn update_server(stream: &mut TcpStream, message: ClientMessage) { + let mut packet = Vec::new(); + packet.push(match message { + ClientMessage::North => 1, + ClientMessage::East => 2, + ClientMessage::West => 3, + ClientMessage::South => 4, + _ => 5, + }); + + let mut ciphertext = my_encrypt(&packet); + let mut packet = Vec::from((ciphertext.len() as u64).to_be_bytes()); + packet.append(&mut ciphertext); + stream.write(&packet); +} + +fn main() -> Result<(), String> { + let sdl_context = sdl2::init()?; + let video_subsystem = sdl_context.video()?; + let window = video_subsystem + .window("scarymaze", WIDTH as u32, HEIGHT as u32) + .position_centered() + .build() + .map_err(|e| e.to_string())?; + let mut canvas = window + .into_canvas() + .software() + .build() + .map_err(|e| e.to_string())?; + + // Connect to server + let mut buf = [0 as u8; 2048]; + let mut stream = if let Ok(conn) = TcpStream::connect(HOST_NAME) { + conn + } else { + println!("Couldn't connect to server."); + return Err("Couldn't connect to server.".into()); + }; + stream.set_nonblocking(true); + + // Generate maze. + + let maze_size: usize = 24; + let mut map = vec![vec![0; maze_size]; maze_size]; + + let mut generator = EllersGenerator::new(None); + let maze = generator.generate((maze_size / 3) as i32, (maze_size / 3) as i32); + + for x in 0..maze_size { + for y in 0..maze_size { + if x == 0 || x == maze_size - 1 || y == 0 || y == maze_size - 1 { + map[y][x] = 1; + } + } + } + + let mut pos = Vec2::::new(22.5, 12.5); + let mut dir = Vec2::::new(-1.0, 0.0); + let mut plane = Vec2::::new(0.0, 0.66); + + 'mainloop: loop { + // Check for updates from the server. + if let Ok(n) = stream.peek(&mut buf) { + let encrypted_length = u64::from_be_bytes((&buf[..8]).try_into().unwrap()) as usize; + stream.read_exact( + &mut iter::repeat(0) + .take(8 + encrypted_length) + .collect::>(), + ); + let packet = my_decrypt(&buf[8..8 + encrypted_length]); + match packet[0] { + SERVER_MAP => { + for x in 0..maze_size { + for y in 0..maze_size { + map[y][x] = packet[1 + y * maze_size + x]; + } + } + } + SERVER_GOTO => { + let x = i32::from_be_bytes((&packet[1..5]).try_into().unwrap()); + let y = i32::from_be_bytes((&packet[5..]).try_into().unwrap()); + pos = Vec2::::new(x as f64 + 0.5, y as f64 + 0.5); + // print_map(&map, &Vec2::::new(pos.x as i32, pos.y as i32)); + } + SERVER_MESSAGE => { + println!("{:?}", String::from_utf8_lossy(&packet[1..])); + } + _ => { + println!("Received corrupted packet from server :("); + } + } + } + + // Check for events. + for event in sdl_context.event_pump()?.poll_iter() { + match event { + Event::KeyDown { + keycode: Some(Keycode::Escape), + .. + } + | Event::Quit { .. } => break 'mainloop, + Event::KeyDown { + keycode: Some(Keycode::Up), + repeat: false, + .. + } => update_server( + &mut stream, + match (dir.x as i32, dir.y as i32) { + (-1, 0) => ClientMessage::West, + (0, -1) => ClientMessage::South, + (1, 0) => ClientMessage::East, + (0, 1) => ClientMessage::North, + _ => ClientMessage::Unknown, + }, + ), + Event::KeyDown { + keycode: Some(Keycode::Down), + repeat: false, + .. + } => update_server( + &mut stream, + match (dir.x as i32, dir.y as i32) { + (-1, 0) => ClientMessage::East, + (0, -1) => ClientMessage::North, + (1, 0) => ClientMessage::West, + (0, 1) => ClientMessage::South, + _ => ClientMessage::Unknown, + }, + ), + Event::KeyDown { + keycode: Some(Keycode::Left), + repeat: false, + .. + } => { + let old_x = dir.x; + dir.x = dir.x * f64::cos(PI / 2.0) - dir.y * f64::sin(PI / 2.0); + dir.y = old_x * f64::sin(PI / 2.0) + dir.y * f64::cos(PI / 2.0); + let old_plane_x = plane.x; + plane.x = plane.x * f64::cos(PI / 2.0) - plane.y * f64::sin(PI / 2.0); + plane.y = old_plane_x * f64::sin(PI / 2.0) + plane.y * f64::cos(PI / 2.0); + } + Event::KeyDown { + keycode: Some(Keycode::Right), + repeat: false, + .. + } => { + let old_x = dir.x; + dir.x = dir.x * f64::cos(-PI / 2.0) - dir.y * f64::sin(-PI / 2.0); + dir.y = old_x * f64::sin(-PI / 2.0) + dir.y * f64::cos(-PI / 2.0); + let old_plane_x = plane.x; + plane.x = plane.x * f64::cos(-PI / 2.0) - plane.y * f64::sin(-PI / 2.0); + plane.y = old_plane_x * f64::sin(-PI / 2.0) + plane.y * f64::cos(-PI / 2.0); + } + _ => {} + } + } + + canvas.set_draw_color(Color::RGBA(0, 0, 0, 255)); + canvas.clear(); + + for x in 0..WIDTH { + // Calculate ray position and direction. + let scan_dist = ((2 * x) as f64) / (WIDTH as f64) - 1.0; + let ray_dir = + Vec2::::new(dir.x + plane.x * scan_dist, dir.y + plane.y * scan_dist); + + // Which box of the map we're in. + let mut map_pos = Vec2::::new(pos.x as i32, pos.y as i32); + + //length of ray from one x or y-side to next x or y-side + let delta_dist = Vec2::::new((1.0 / ray_dir.x).abs(), (1.0 / ray_dir.y).abs()); + + let mut hit = false; // Was there a wall hit? + let mut goal = false; + let mut side = 0; // Was a north/south or a east/west wall hit? + + // Calculate step and initial sideDist. + let (step_x, mut side_dist_x) = if ray_dir.x < 0.0 { + (-1, (pos.x - map_pos.x as f64) * delta_dist.x) + } else { + (1, ((map_pos.x as f64) + 1.0 - pos.x) * delta_dist.x) + }; + + let (step_y, mut side_dist_y) = if ray_dir.y < 0.0 { + (-1, (pos.y - map_pos.y as f64) * delta_dist.y) + } else { + (1, ((map_pos.y as f64) + 1.0 - pos.y) * delta_dist.y) + }; + + // Perform Digital Differential Analysis. + while !hit { + // Jump to next map square, OR in x-direction, OR in y-direction. + if side_dist_x < side_dist_y { + side_dist_x += delta_dist.x; + map_pos.x += step_x; + side = 0; + } else { + side_dist_y += delta_dist.y; + map_pos.y += step_y; + side = 1; + } + + // Check if ray has hit a wall. + if map[map_pos.x as usize][map_pos.y as usize] > 0 { + hit = true; + if map[map_pos.x as usize][map_pos.y as usize] > 1 { + goal = true; + } + } + } + + // Calculate distance projected on camera direction (Euclidean distance will give fisheye effect!) + let perp_wall_dist = if side == 0 { + ((map_pos.x as f64 - pos.x) + (1.0 - step_x as f64) / 2.0) / ray_dir.x + } else { + ((map_pos.y as f64 - pos.y) + (1.0 - step_y as f64) / 2.0) / ray_dir.y + }; + + // Calculate height of line to draw on screen + let line_height = if perp_wall_dist > 0.0 { + (HEIGHT as f64 / perp_wall_dist) as i32 + } else { + HEIGHT + }; + + // Calculate lowest and highest pixel to fill in current stripe. + let draw_start = -line_height / 2 + HEIGHT / 2; + let draw_end = line_height / 2 + HEIGHT / 2; + + // Draw the pixels of the stripe as a vertical line. + let start = Point::new(x, draw_start); + let end = Point::new(x, draw_end); + if goal { + canvas.set_draw_color(Color::RGBA( + (255 * line_height / HEIGHT) as u8, + (255 * line_height / HEIGHT) as u8, + 0, + 255, + )); + } else { + canvas.set_draw_color(Color::RGBA(0, (255 * line_height / HEIGHT) as u8, 0, 255)); + } + + canvas.draw_line(start, end).unwrap(); + } + + canvas.present(); + } + + Ok(()) +} diff --git a/scarymaze/src/server.rs b/scarymaze/src/server.rs new file mode 100644 index 0000000..59e5621 --- /dev/null +++ b/scarymaze/src/server.rs @@ -0,0 +1,247 @@ +const FLAG: &'static str = "UMASS{pL4YZ_s4d_v1oL1n_s4DlY__g0_3a7_50m37hIN_Pl3453}"; + +use async_std::io; +use async_std::net::{TcpListener, TcpStream}; +use async_std::prelude::*; +use async_std::task; + +enum ClientMessage { + North, + South, + East, + West, + Unknown, +} + +const SERVER_MAP: u8 = 0; +const SERVER_GOTO: u8 = 1; +const SERVER_MESSAGE: u8 = 2; + +const MAZE_SIZE: usize = 24; + +use maze_generator::ellers_algorithm::EllersGenerator; +use maze_generator::prelude::*; + +const AES_KEY: &'static str = "STRINGS NOT HERE"; + +use openssl::symm::{decrypt, encrypt, Cipher}; +use rand::RngCore; + +fn my_encrypt(packet: &[u8]) -> Vec { + let mut rng = rand::thread_rng(); + let mut iv = [0 as u8; 16]; + rng.fill_bytes(&mut iv); + + let cipher = Cipher::aes_128_cbc(); + let key = AES_KEY.as_bytes(); + let mut data = encrypt(cipher, key, Some(&iv), packet).unwrap(); + + let mut ciphertext = Vec::from(iv); + ciphertext.append(&mut data); + ciphertext +} + +fn my_decrypt(packet: &[u8]) -> Vec { + let iv = &packet[..16]; + let data = &packet[16..]; + let cipher = Cipher::aes_128_cbc(); + let key = AES_KEY.as_bytes(); + let plaintext = decrypt(cipher, key, Some(iv), data).unwrap(); + plaintext +} + +fn new_map() -> (Vec>, (i32, i32)) { + let mut generator = EllersGenerator::new(None); + let maze = generator.generate((MAZE_SIZE / 3) as i32, (MAZE_SIZE / 3) as i32); + let mut map = vec![vec![0; MAZE_SIZE]; MAZE_SIZE]; + + for x in 0..MAZE_SIZE { + for y in 0..MAZE_SIZE { + if x == 0 || x == MAZE_SIZE - 1 || y == 0 || y == MAZE_SIZE - 1 { + map[y][x] = 1; + } + } + } + + for x in 0..MAZE_SIZE / 3 { + for y in 0..MAZE_SIZE / 3 { + if let Some(field) = maze.get_field(&Coordinates::new(x as i32, y as i32)) { + if !field.has_passage(&Direction::North) { + map[(y * 3)][(x * 3) + 1] = 1; + } + if !field.has_passage(&Direction::South) { + map[(y * 3) + 2][(x * 3) + 1] = 1; + } + if !field.has_passage(&Direction::East) { + map[(y * 3) + 1][(x * 3) + 2] = 1; + } + if !field.has_passage(&Direction::West) { + map[(y * 3) + 1][(x * 3)] = 1; + } + } + } + } + + map[(maze.goal.y * 3 + 1) as usize][(maze.goal.x * 3 + 1) as usize] = 2; + + (map, (maze.start.x * 3 + 2, maze.start.y * 3 + 2)) +} + +async fn send_map(map: &Vec>, writer: &mut TcpStream) -> std::io::Result { + // Serialize map. + let mut packet = vec![SERVER_MAP]; + let mut buf = [0 as u8; MAZE_SIZE * MAZE_SIZE]; + for y in 0..MAZE_SIZE { + for x in 0..MAZE_SIZE { + buf[y * MAZE_SIZE + x] = map[x][y]; + } + } + packet.append(&mut Vec::from(buf)); + + let mut ciphertext = my_encrypt(&packet); + let mut packet = Vec::from((ciphertext.len() as u64).to_be_bytes()); + packet.append(&mut ciphertext); + writer.write(&packet).await +} + +async fn send_goto(position: (i32, i32), writer: &mut TcpStream) -> std::io::Result { + let mut packet = vec![SERVER_GOTO]; + let mut succ = Vec::from(position.0.to_be_bytes()); + packet.append(&mut succ); + let mut succ = Vec::from(position.1.to_be_bytes()); + packet.append(&mut succ); + + let mut ciphertext = my_encrypt(&packet); + let mut packet = Vec::from((ciphertext.len() as u64).to_be_bytes()); + packet.append(&mut ciphertext); + writer.write(&packet).await +} + +async fn send_message(msg: String, writer: &mut TcpStream) -> std::io::Result { + let mut packet = vec![SERVER_MESSAGE]; + packet.append(&mut Vec::from(msg.as_bytes())); + + let mut ciphertext = my_encrypt(&packet); + let mut packet = Vec::from((ciphertext.len() as u64).to_be_bytes()); + packet.append(&mut ciphertext); + writer.write(&packet).await +} + +fn deserialize_client_message(buf: &[u8]) -> ClientMessage { + ClientMessage::Unknown +} + +use std::convert::TryInto; +use std::iter; + +async fn process(stream: TcpStream) -> io::Result<()> { + println!("Accepted from: {}", stream.peer_addr()?); + + // Two buffers. + let mut recv = [0 as u8; 1024]; + let mut send = [0 as u8; 1024]; + + let mut reader = stream.clone(); + let mut writer = stream; + + let mut map = vec![]; + let mut position = (2, 2); + let mut level: i32 = 1; + + let mut needs_map = true; + + loop { + if needs_map { + let (new_map, new_position) = new_map(); + map = new_map; + position = new_position; + send_map(&map, &mut writer).await?; + send_goto(position, &mut writer).await?; + needs_map = false; + } + + if let Ok(n) = reader.read(&mut recv).await { + let encrypted_length = u64::from_be_bytes((&recv[..8]).try_into().unwrap()) as usize; + let packet = my_decrypt(&recv[8..8 + encrypted_length]); + match packet[0] { + 1 => { + let tile = map[(position.1 + 1) as usize][position.0 as usize]; + if tile == 0 { + position.1 += 1; + } else if tile == 2 { + level += 1; + send_message(format!("Noice, level {}", level), &mut writer).await; + needs_map = true; + if level == 25 { + send_message(format!("Congratulations nerd, you just wasted a weekend on this. Here's your stupid flag: {}. Hope it was worth it.", FLAG), &mut writer).await; + } + } + } + 4 => { + let tile = map[(position.1 - 1) as usize][position.0 as usize]; + if tile == 0 { + position.1 -= 1; + } else if tile == 2 { + level += 1; + send_message(format!("Noice, level {}", level), &mut writer).await; + needs_map = true; + if level == 25 { + send_message(format!("Congratulations nerd, you just wasted a weekend on this. Here's your stupid flag: {}. Hope it was worth it.", FLAG), &mut writer).await; + } + } + } + 3 => { + let tile = map[position.1 as usize][(position.0 - 1) as usize]; + if tile == 0 { + position.0 -= 1; + } else if tile == 2 { + level += 1; + send_message(format!("Noice, level {}", level), &mut writer).await; + needs_map = true; + if level == 25 { + send_message(format!("Congratulations nerd, you just wasted a weekend on this. Here's your stupid flag: {}. Hope it was worth it.", FLAG), &mut writer).await; + } + } + } + 2 => { + let tile = map[position.1 as usize][(position.0 + 1) as usize]; + if tile == 0 { + position.0 += 1; + } else if tile == 2 { + level += 1; + send_message(format!("Noice, level {}", level), &mut writer).await; + needs_map = true; + if level == 25 { + send_message(format!("Congratulations nerd, you just wasted a weekend on this. Here's your stupid flag: {}. Hope it was worth it.", FLAG), &mut writer).await; + } + } + } + _ => { + break; + } + } + + send_goto(position, &mut writer).await?; + } + } + + Ok(()) +} + +fn main() -> io::Result<()> { + task::block_on(async { + // let listener = TcpListener::bind("127.0.0.1:8080").await?; + let listener = TcpListener::bind("0.0.0.0:8080").await?; + println!("Listening on {}", listener.local_addr()?); + + let mut incoming = listener.incoming(); + + while let Some(stream) = incoming.next().await { + let stream = stream?; + task::spawn(async { + process(stream).await.unwrap(); + }); + } + Ok(()) + }) +} -- cgit v1.3