From 49bc77e44aaf18ad28a94bcc3866aa9aed9a5750 Mon Sep 17 00:00:00 2001 From: FantasyPvP <80643031+FantasyPvP@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:50:28 +0100 Subject: [PATCH] added the gigachad detector --- src/system/kernel/authenticator.rs | 36 +++++++++ src/system/kernel/mod.rs | 3 +- src/system/kernel/render.rs | 3 + src/system/kernel/render2.rs | 0 src/user/bin/calc.rs | 17 +++- src/user/bin/gigachad_detector.rs | 51 ++++++++++++ src/user/bin/mod.rs | 1 + src/user/bin/shell.rs | 11 +-- src/user/lib/libgui/libgui_core.rs | 126 ++++++++++++++--------------- 9 files changed, 176 insertions(+), 72 deletions(-) create mode 100644 src/system/kernel/authenticator.rs create mode 100644 src/system/kernel/render2.rs create mode 100644 src/user/bin/gigachad_detector.rs diff --git a/src/system/kernel/authenticator.rs b/src/system/kernel/authenticator.rs new file mode 100644 index 0000000..81cdbc2 --- /dev/null +++ b/src/system/kernel/authenticator.rs @@ -0,0 +1,36 @@ +use lazy_static::lazy_static; +use alloc::sync::Arc; +use spin::Mutex; +use alloc::{vec, vec::Vec, string::String}; + +lazy_static!( + static ref AUTHENTICATOR: Arc>> = Arc::new(Mutex::new(vec![User::new( + String::from("fantasypvp"), + String::from("password") + )])); +); + +pub struct User { + username: String, + pass_hash: u64, +} + +impl User { + fn new(username: String, password: String) -> User { + let pass_hash = User::get_pass_hash(&password); + User { username, pass_hash } + } + + fn get_pass_hash(pass: &String) -> u64 { + pass.bytes().fold(0u64, |b, a| a as u64 + b as u64) + } + pub fn is_authenticated(username: String, password: String) -> Option { + let auth = AUTHENTICATOR.lock(); + let user = auth.iter().find(|x| x.username == username)?; + if User::get_pass_hash(&password) == user.pass_hash { + Some(true) + } else { + Some(false) + } + } +} \ No newline at end of file diff --git a/src/system/kernel/mod.rs b/src/system/kernel/mod.rs index ff0ae35..cad68f9 100644 --- a/src/system/kernel/mod.rs +++ b/src/system/kernel/mod.rs @@ -6,4 +6,5 @@ pub mod memory; pub mod render; pub mod serial; pub mod tasks; -pub mod sysinit; \ No newline at end of file +pub mod sysinit; +pub mod authenticator; \ No newline at end of file diff --git a/src/system/kernel/render.rs b/src/system/kernel/render.rs index 6b928d5..27cbea6 100644 --- a/src/system/kernel/render.rs +++ b/src/system/kernel/render.rs @@ -71,6 +71,9 @@ pub struct Renderer { pub sandbox: bool, } + + + lazy_static! { pub static ref RENDERER: Mutex = Mutex::new(Renderer { col_pos: 0, diff --git a/src/system/kernel/render2.rs b/src/system/kernel/render2.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/user/bin/calc.rs b/src/user/bin/calc.rs index 5790157..2bfef6e 100755 --- a/src/user/bin/calc.rs +++ b/src/user/bin/calc.rs @@ -412,10 +412,24 @@ fn calculate_inner(mut equation: String) -> Result { fn tokenise(equation: &str) -> Result, Error> { let mut tokens = Vec::new(); let mut current_num = "".to_string(); - let current_string: String = "".to_string(); + let mut current_string: String = "".to_string(); + + let mut is_var = false; 'mainloop: for (x, character) in equation.chars().enumerate() { + match character { + 'a'..='z' => { + is_var = true; + current_string.push(character); + } + _ => { + if is_var { + tokens.push(Token::Func(current_string.clone())); + } + is_var = false; + } + } match character { '0'..='9' => current_num.push(character), @@ -478,6 +492,7 @@ enum Token { Operator(Operator), Bracket(char), Null, + Func(String), } diff --git a/src/user/bin/gigachad_detector.rs b/src/user/bin/gigachad_detector.rs new file mode 100644 index 0000000..d216227 --- /dev/null +++ b/src/user/bin/gigachad_detector.rs @@ -0,0 +1,51 @@ +use async_trait::async_trait; +use alloc::{boxed::Box, string::String, vec::Vec}; + +use crate::{ + std::os::OS, + std::io::{Color, write}, + println, + std::application::{ + Application, + Error, + }, +}; + +const GIGACHAD: &'static str = "fantasypvp"; + +pub struct GigachadDetector {} + +#[async_trait] +impl Application for GigachadDetector { + fn new() -> Self { + Self {} + } + + async fn run(&mut self, args: Vec) -> Result<(), Error> { + for arg in args { + self.detect_gigachad_by_username(&arg) + } + Ok(()) + } +} + +impl GigachadDetector { + pub fn detect_gigachad_by_username(&self, username: &str) { + if username == GIGACHAD { + println!("{} is a gigachad B'YES", username); + println!(" + /$$$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$$ + |_____ $$ | $$ / $$ /$$__ $$| $$____/ + /$$/ | $$/ $$/| $$ \\ $$| $$ + /$$/ \\ $$$$/ | $$ | $$| $$$$$$$ + /$$/ >$$ $$ | $$ | $$|_____ $$ + /$$/ /$$/\\ $$| $$/$$ $$ /$$ \\ $$ + /$$$$$$$$| $$ \\ $$| $$$$$$/| $$$$$$/ + |________/|__/ |__/ \\____ $$$ \\______/ + \\__/ + ") + } else { + println!("{} is not a gigachad", username); + } + } +} \ No newline at end of file diff --git a/src/user/bin/mod.rs b/src/user/bin/mod.rs index a99546d..86542ab 100644 --- a/src/user/bin/mod.rs +++ b/src/user/bin/mod.rs @@ -5,3 +5,4 @@ pub mod rickroll; pub mod shell; //pub mod shellrewrite; pub mod tasks; +mod gigachad_detector; diff --git a/src/user/bin/shell.rs b/src/user/bin/shell.rs index 3fa025d..19e87d7 100644 --- a/src/user/bin/shell.rs +++ b/src/user/bin/shell.rs @@ -14,6 +14,7 @@ use crate::{ std::application::{Application, Error}, user::bin::*, }; +use crate::user::bin::gigachad_detector::GigachadDetector; lazy_static! { pub static ref CMD: Mutex = Mutex::new(CommandHandler::new()); @@ -121,13 +122,9 @@ async fn exec() -> Result<(), Error> { "switch" => { crate::std::io::switch_mode(); } - "random" => { - use crate::std::random::Random; - let vec = Vec::from(["is", "is not", "is absolutely"]); - let vec2 = Vec::from(["simp", "gigachad", "genius", "bozo", "Non simp"]); - let sel = *Random::selection(&vec); - let sel2 = *Random::selection(&vec2); - println!("panic attack {} a {}", sel, sel2); + "gigachad?" => { + let mut gigachad_detector = GigachadDetector::new(); + gigachad_detector.run(args).await?; } "filesystem" => { use crate::std::io; diff --git a/src/user/lib/libgui/libgui_core.rs b/src/user/lib/libgui/libgui_core.rs index 4e94a95..cf9b45b 100644 --- a/src/user/lib/libgui/libgui_core.rs +++ b/src/user/lib/libgui/libgui_core.rs @@ -50,7 +50,7 @@ pub struct Container<'a> { dimensions: Pos, // x,y } -impl Container<'a> { +impl<'a> Container<'a> { fn new(position: Pos, dimensions: Pos, outlined: bool) -> Container<'a> { Self { frame: vec![vec![' '; dimensions.x as usize]; dimensions.y as usize], @@ -212,68 +212,68 @@ pub fn gen_outline(dimensions: Pos) -> Vec> { return charmap; } -// testing functions - -pub fn test_elements() { - use super::libgui_elements; - - let mut containers = Vec::::new(); - - /* - - //for _ in 0..10 { - // containers.push(generate_box()); - //} - - containers.push(Container::new((5, 5), (15, 5), true)); - containers.push(Container::new((10, 3), (50, 20), true)); - - let mut bar = IndicatorBar::new((10, 6), 12); - let mut bar2 = IndicatorBar::new((10, 7), 12); - - bar.set_value(43); - bar.abs = 101; - bar2.set_value(14); - bar2.abs = 15; - containers[1].elements.push(Box::new(bar)); - containers[1].elements.push(Box::new(bar2)); - - let tbox = libgui_elements::TextBox::new( - String::from("panic attack simps"), - String::from("i have finally obtained evidence of his simpiness against tari and crystal, however i cannot reveal this evidence for now, however, once the contract is over NO ONE CAN STOP ME MWHAHAHAHAHA"), - Pos::new(25, 10), - Pos::new(10, 9), - true, - ); - - containers[1].elements.push(Box::new(tbox)); - - */ - - containers.push(Container::new(Pos::new(0, 1), Pos::new(80, 24), true)); - - let tbox = libgui_elements::TextBox::new( - String::from("ANNOUNCEMENTS"), - String::from( - "CrystalRPG coming soon! XD -this is gonna be the best game ever", - ), - Pos::new(25, 10), - Pos::new(0, 0), - true, - ); - - containers[0].elements.push(Box::new(&tbox)); - - let mut bar = IndicatorBar::new(Pos::new(7, 7), 12); - bar.set_value(70); - bar.set_text(String::from("ayo")); - - containers[0].elements.push(Box::new(bar)); - render_frame(containers); - - return; -} +// // testing functions +// +// pub fn test_elements() { +// use super::libgui_elements; +// +// let mut containers = Vec::::new(); +// +// /* +// +// //for _ in 0..10 { +// // containers.push(generate_box()); +// //} +// +// containers.push(Container::new((5, 5), (15, 5), true)); +// containers.push(Container::new((10, 3), (50, 20), true)); +// +// let mut bar = IndicatorBar::new((10, 6), 12); +// let mut bar2 = IndicatorBar::new((10, 7), 12); +// +// bar.set_value(43); +// bar.abs = 101; +// bar2.set_value(14); +// bar2.abs = 15; +// containers[1].elements.push(Box::new(bar)); +// containers[1].elements.push(Box::new(bar2)); +// +// let tbox = libgui_elements::TextBox::new( +// String::from("panic attack simps"), +// String::from("i have finally obtained evidence of his simpiness against tari and crystal, however i cannot reveal this evidence for now, however, once the contract is over NO ONE CAN STOP ME MWHAHAHAHAHA"), +// Pos::new(25, 10), +// Pos::new(10, 9), +// true, +// ); +// +// containers[1].elements.push(Box::new(tbox)); +// +// */ +// +// containers.push(Container::new(Pos::new(0, 1), Pos::new(80, 24), true)); +// +// let tbox = libgui_elements::TextBox::new( +// String::from("ANNOUNCEMENTS"), +// String::from( +// "CrystalRPG coming soon! XD +// this is gonna be the best game ever", +// ), +// Pos::new(25, 10), +// Pos::new(0, 0), +// true, +// ); +// +// containers[0].elements.push(Box::new(&tbox)); +// +// let mut bar = IndicatorBar::new(Pos::new(7, 7), 12); +// bar.set_value(70); +// bar.set_text(String::from("ayo")); +// +// containers[0].elements.push(Box::new(bar)); +// render_frame(containers); +// +// return; +// } // function to generate a box in a random location on the screen.