From 43e312445be18ae91ac4dce9a7a38ed9734c5159 Mon Sep 17 00:00:00 2001 From: Adam Doyle Date: Wed, 9 Oct 2024 02:20:03 -0400 Subject: [PATCH] add new game spam --- Cargo.lock | 3 +++ tools/socket_blaster/Cargo.toml | 3 +++ tools/socket_blaster/src/main.rs | 34 +++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b5910a8..c222a1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2468,6 +2468,9 @@ name = "socket_blaster" version = "0.1.0" dependencies = [ "clap", + "lib", + "serde", + "serde_json", "tungstenite", ] diff --git a/tools/socket_blaster/Cargo.toml b/tools/socket_blaster/Cargo.toml index 20eda6d..652a475 100644 --- a/tools/socket_blaster/Cargo.toml +++ b/tools/socket_blaster/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["cargo"] } tungstenite = "0" +lib = { workspace = true } +serde_json = "1" +serde = { version = "1", features = ["derive"] } diff --git a/tools/socket_blaster/src/main.rs b/tools/socket_blaster/src/main.rs index 3da9c4d..5f12bf7 100644 --- a/tools/socket_blaster/src/main.rs +++ b/tools/socket_blaster/src/main.rs @@ -1,22 +1,54 @@ +use std::collections::HashSet; + use clap::{command, Command}; -use tungstenite::connect; +use lib::*; +use serde_json::to_string; +use tungstenite::{connect, Message}; /// Infinite loop spawning new user connections and then leaving them open fn zombie_horde() { println!("Spamming new zombie user connections"); + loop { let (_, _) = connect("ws://127.0.0.1:3030/websocket").expect("Can't connect"); } } + +/// Infinite loop that creates games +fn spam_games() { + println!("Spamming game creation"); + + let mut packs = HashSet::new(); + for pack in 0..205 { + packs.insert(pack.to_string()); + } + + let (mut socket, _) = connect("ws://127.0.0.1:3030/websocket").expect("Can't connect"); + loop { + socket + .send(Message::Text( + to_string(&NewGameRequest { + name: "ligma".to_string(), + packs: packs.clone(), + }) + .unwrap(), + )) + .unwrap(); + } +} + fn main() { let matches = command!() .subcommand( Command::new("zombies") .about("Infinite loop spawning new user connections and then leaving them open."), ) + .subcommand(Command::new("games").about("Infinite loop that creates games.")) .get_matches(); if matches.subcommand_matches("zombies").is_some() { zombie_horde(); + } else if matches.subcommand_matches("games").is_some() { + spam_games(); } }