randomize usernames

This commit is contained in:
griffi-gh 2024-04-25 17:48:39 +02:00
parent fb0ff88c10
commit 6a721b0400
3 changed files with 89 additions and 16 deletions

76
Cargo.lock generated
View file

@ -43,7 +43,7 @@ dependencies = [
"getrandom", "getrandom",
"once_cell", "once_cell",
"version_check", "version_check",
"zerocopy", "zerocopy 0.7.32",
] ]
[[package]] [[package]]
@ -245,7 +245,7 @@ dependencies = [
"getrandom", "getrandom",
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"rand", "rand 0.8.5",
"rand_xorshift", "rand_xorshift",
"regex", "regex",
"wasm-bindgen", "wasm-bindgen",
@ -1173,6 +1173,7 @@ dependencies = [
"ndk", "ndk",
"nohash-hasher", "nohash-hasher",
"postcard", "postcard",
"rand 0.9.0-alpha.1",
"raw-window-handle 0.5.2", "raw-window-handle 0.5.2",
"rayon", "rayon",
"serde_json", "serde_json",
@ -1212,7 +1213,7 @@ dependencies = [
"lz4_flex", "lz4_flex",
"nohash-hasher", "nohash-hasher",
"postcard", "postcard",
"rand", "rand 0.8.5",
"rayon", "rayon",
"serde", "serde",
"shipyard", "shipyard",
@ -1233,7 +1234,7 @@ dependencies = [
"num_enum", "num_enum",
"nz", "nz",
"postcard", "postcard",
"rand", "rand 0.8.5",
"rand_xoshiro", "rand_xoshiro",
"serde", "serde",
"serde_with", "serde_with",
@ -1645,8 +1646,19 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [ dependencies = [
"libc", "libc",
"packed_simd_2", "packed_simd_2",
"rand_chacha", "rand_chacha 0.3.1",
"rand_core", "rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.9.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d31e63ea85be51c423e52ba8f2e68a3efd53eed30203ee029dd09947333693e"
dependencies = [
"rand_chacha 0.9.0-alpha.1",
"rand_core 0.9.0-alpha.1",
"zerocopy 0.8.0-alpha.6",
] ]
[[package]] [[package]]
@ -1656,7 +1668,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core", "rand_core 0.6.4",
]
[[package]]
name = "rand_chacha"
version = "0.9.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78674ef918c19451dbd250f8201f8619b494f64c9aa6f3adb28fd8a0f1f6da46"
dependencies = [
"ppv-lite86",
"rand_core 0.9.0-alpha.1",
] ]
[[package]] [[package]]
@ -1668,13 +1690,23 @@ dependencies = [
"getrandom", "getrandom",
] ]
[[package]]
name = "rand_core"
version = "0.9.0-alpha.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc89dffba8377c5ec847d12bb41492bda235dba31a25e8b695cd0fe6589eb8c9"
dependencies = [
"getrandom",
"zerocopy 0.8.0-alpha.6",
]
[[package]] [[package]]
name = "rand_xorshift" name = "rand_xorshift"
version = "0.3.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
dependencies = [ dependencies = [
"rand_core", "rand_core 0.6.4",
] ]
[[package]] [[package]]
@ -1683,7 +1715,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa"
dependencies = [ dependencies = [
"rand_core", "rand_core 0.6.4",
] ]
[[package]] [[package]]
@ -2190,7 +2222,7 @@ version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2417e47ddd3809ad40222777ac754ee881b3a6401e38cbeeeb3ee1ca5f30aa0" checksum = "e2417e47ddd3809ad40222777ac754ee881b3a6401e38cbeeeb3ee1ca5f30aa0"
dependencies = [ dependencies = [
"rand", "rand 0.8.5",
] ]
[[package]] [[package]]
@ -2266,7 +2298,7 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be4d71c1c106a57b0333ac2c28bd4521e0b16a2b98fe84405cdf7f544be46b6" checksum = "3be4d71c1c106a57b0333ac2c28bd4521e0b16a2b98fe84405cdf7f544be46b6"
dependencies = [ dependencies = [
"rand", "rand 0.8.5",
] ]
[[package]] [[package]]
@ -2884,7 +2916,16 @@ version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive 0.7.32",
]
[[package]]
name = "zerocopy"
version = "0.8.0-alpha.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db678a6ee512bd06adf35c35be471cae2f9c82a5aed2b5d15e03628c98bddd57"
dependencies = [
"zerocopy-derive 0.8.0-alpha.6",
] ]
[[package]] [[package]]
@ -2897,3 +2938,14 @@ dependencies = [
"quote", "quote",
"syn 2.0.49", "syn 2.0.49",
] ]
[[package]]
name = "zerocopy-derive"
version = "0.8.0-alpha.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201585ea96d37ee69f2ac769925ca57160cef31acb137c16f38b02b76f4c1e62"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.49",
]

View file

@ -35,6 +35,7 @@ lz4_flex = { version = "0.11", default-features = false, features = ["std"] }
static_assertions = "1.1" static_assertions = "1.1"
tinyset = "0.4" tinyset = "0.4"
serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data` serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data`
rand = { version = "0.9.0-alpha.0", features = ["alloc", "small_rng"]}
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
android-activity = "^0.5.2" android-activity = "^0.5.2"
@ -49,7 +50,7 @@ raw-evt = [] #required for mouse input, but breaks keyboard on android
generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"] generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"]
safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"] safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"]
parallel = ["shipyard/parallel"] # causes some serious issues! parallel = ["shipyard/parallel"] # causes some serious issues!
nightly = ["hashbrown/nightly", "glam/core-simd", "static_assertions/nightly", "lz4_flex/nightly", "kubi-shared/nightly"] nightly = ["hashbrown/nightly", "glam/core-simd", "static_assertions/nightly", "lz4_flex/nightly", "kubi-shared/nightly", "rand/nightly"]
#part of wip android support #part of wip android support
[package.metadata.android] [package.metadata.android]

View file

@ -5,9 +5,21 @@ use kubi_shared::networking::{
state::ClientJoinState, state::ClientJoinState,
channels::Channel, channels::Channel,
}; };
use crate::player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}; use rand::prelude::*;
use crate::{chat::ChatManager, player::{spawn_local_player_multiplayer, spawn_remote_player_multiplayer}};
use super::{UdpClient, NetworkEvent}; use super::{UdpClient, NetworkEvent};
const USERNAME_BANK: &[&str] = &[
"XxX-FishFucker-69420",
"Sbeve34",
"ShadowBladeX",
"CyberNinja92",
"sputnik1",
"dumbpotato",
"FortNiteNinja",
"MinecraftMiner",
];
#[derive(Unique)] #[derive(Unique)]
pub struct ConnectionRejectionReason { pub struct ConnectionRejectionReason {
pub reason: String, pub reason: String,
@ -23,7 +35,8 @@ pub fn set_client_join_state_to_connected(
pub fn say_hello( pub fn say_hello(
mut client: UniqueViewMut<UdpClient>, mut client: UniqueViewMut<UdpClient>,
) { ) {
let username = "XxX-FishFucker-69420-XxX".into(); let mut rng = thread_rng();
let username = (*USERNAME_BANK.choose(&mut rng).unwrap()).to_owned();
let password = None; let password = None;
log::info!("Authenticating"); log::info!("Authenticating");
client.0.send( client.0.send(
@ -64,7 +77,10 @@ pub fn check_server_hello_response(
// direction: Quat, // direction: Quat,
// health: Health, // health: Health,
// } // }
let client_id = init.user.client_id;
let username = init.user.username.clone();
//Add components to main player //Add components to main player
spawn_local_player_multiplayer(&mut storages, init.user); spawn_local_player_multiplayer(&mut storages, init.user);
@ -78,6 +94,10 @@ pub fn check_server_hello_response(
*join_state = ClientJoinState::Joined; *join_state = ClientJoinState::Joined;
log::info!("Joined the server!"); log::info!("Joined the server!");
// Send chat message
let mut chat = storages.borrow::<UniqueViewMut<ChatManager>>().unwrap();
chat.add_player_join(client_id, username);
} }
pub fn check_server_fuck_off_response( pub fn check_server_fuck_off_response(