added the gigachad detector
This commit is contained in:
@@ -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<Mutex<Vec<User>>> = 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<bool> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ pub mod memory;
|
||||
pub mod render;
|
||||
pub mod serial;
|
||||
pub mod tasks;
|
||||
pub mod sysinit;
|
||||
pub mod sysinit;
|
||||
pub mod authenticator;
|
||||
@@ -71,6 +71,9 @@ pub struct Renderer {
|
||||
pub sandbox: bool,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
lazy_static! {
|
||||
pub static ref RENDERER: Mutex<Renderer> = Mutex::new(Renderer {
|
||||
col_pos: 0,
|
||||
|
||||
+16
-1
@@ -412,10 +412,24 @@ fn calculate_inner(mut equation: String) -> Result<f64, Error> {
|
||||
fn tokenise(equation: &str) -> Result<Vec<Token>, 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),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<String>) -> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,4 @@ pub mod rickroll;
|
||||
pub mod shell;
|
||||
//pub mod shellrewrite;
|
||||
pub mod tasks;
|
||||
mod gigachad_detector;
|
||||
|
||||
@@ -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<CommandHandler> = 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;
|
||||
|
||||
@@ -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<Vec<char>> {
|
||||
return charmap;
|
||||
}
|
||||
|
||||
// testing functions
|
||||
|
||||
pub fn test_elements() {
|
||||
use super::libgui_elements;
|
||||
|
||||
let mut containers = Vec::<Container>::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::<Container>::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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user