use crate::game::fs::VirtualFileSystem;
use crate::game::state::{GameTime, TerminalState};
use crate::game::terminal::CommandResult;
use rand::Rng; // Used for random chances in commands
/// Module containing all terminal command implementations
pub struct Commands;
impl Commands {
/// submit command - submit a flag to reduce watcher awareness
pub fn cmd_submit(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, _time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Usage: submit FLAG_NAME".to_string());
}
let flag_name = args[0].to_uppercase();
// Flag validation is handled in handle_secret_command where we have access to win_conditions
CommandResult::Success(format!("Attempting to submit flag '{}'...", flag_name))
}
/// Submit a flag directly with access to win_conditions
pub fn submit_flag(flag_name: &str, win_conditions: &mut crate::game::state::WinConditions) -> CommandResult {
// Special case for command fragments - treat them as hints
if flag_name == "SYSTERRR-DESTROY" {
return CommandResult::Success(
"This appears to be part of the emergency shutdown command, not a flag.\n\nLook for system flags in hidden files. Try to find all four flags to reveal the complete shutdown sequence.".to_string()
);
}
// Check if the flag is valid and not already submitted
let flag_index = win_conditions.flags.iter().position(|f| f.name == flag_name);
match flag_index {
Some(idx) if !win_conditions.flags[idx].found => {
// Flag found for the first time
win_conditions.flags[idx].found = true;
win_conditions.flags_submitted.push(flag_name.to_string());
// Reset watcher awareness
win_conditions.watcher_awareness = 0;
// Check if all flags have been found
let all_flags_found = win_conditions.flags.iter().all(|f| f.found);
if all_flags_found {
win_conditions.final_command_revealed = true;
CommandResult::Success(format!("Flag '{}' accepted!\n\nALL FLAGS FOUND! The Watcher's awareness has been reset.\n\nThe emergency shutdown command has been fully revealed: systerrr-destroy-drnovakisdead-shouldhavelistened-systemisalive\n\nExecute this command to escape the system before the Watcher returns.", flag_name))
} else {
// Return a success message with the flag's contribution to the final command
let flag_desc = &win_conditions.flags[idx].description;
CommandResult::Success(format!("Flag '{}' accepted!\n\nThe Watcher's awareness has been reset.\n\n{}", flag_name, flag_desc))
}
},
Some(_) => {
// Flag already submitted
CommandResult::Error(format!("Flag '{}' has already been submitted.", flag_name))
},
None => {
// Invalid flag name
CommandResult::Error(format!("Invalid flag: '{}'. Check your flag name and try again.", flag_name))
}
}
}
/// flags command - list currently found flags
pub fn cmd_flags(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, _time: &GameTime, _args: &[&str]) -> CommandResult {
// Simple placeholder - actual implementation happens in handle_secret_command
CommandResult::Success("Checking flags...".to_string())
}
/// List flags with direct access to win_conditions
pub fn list_flags(win_conditions: &crate::game::state::WinConditions) -> CommandResult {
if win_conditions.flags_submitted.is_empty() {
return CommandResult::Success("No flags have been found yet. Look for hidden files and directories to find system flags.".to_string());
}
let mut result = String::from("FOUND FLAGS:\n\n");
for flag_name in &win_conditions.flags_submitted {
if let Some(flag) = win_conditions.flags.iter().find(|f| &f.name == flag_name) {
result.push_str(&format!("- {} ({})\n", flag.name, flag.description));
}
}
result.push_str("\nWatcher awareness level: ");
result.push_str(&format!("{}/100", win_conditions.watcher_awareness));
CommandResult::Success(result)
}
/// watcher command - show current watcher status
pub fn cmd_watcher(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, _args: &[&str]) -> CommandResult {
// Simple placeholder - actual implementation in handle_secret_command
CommandResult::Success("Checking watcher status...".to_string())
}
/// Show watcher status with direct access to win_conditions
pub fn show_watcher_status(time: &GameTime, win_conditions: &crate::game::state::WinConditions) -> CommandResult {
let awareness = win_conditions.watcher_awareness;
// Different messages based on time and awareness level
if time.is_three_am() {
CommandResult::Event(format!("WATCHER AWARENESS: {} - WARNING: ENTITY ACTIVE\n\nTHE WATCHER SEES YOU", awareness))
} else if time.is_midnight() {
CommandResult::Success(format!("WATCHER AWARENESS: {}/100\n\nThe Watcher is active at midnight. Be careful.", awareness))
} else if time.is_after_midnight() {
CommandResult::Success(format!("WATCHER AWARENESS: {}/100\n\nThe Watcher is more active between midnight and 6 AM.", awareness))
} else {
CommandResult::Success(format!("WATCHER AWARENESS: {}/100\n\nThe Watcher is dormant during daylight hours.", awareness))
}
}
/// special command to break out of the system
pub fn cmd_system_break(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, _time: &GameTime, _args: &[&str]) -> CommandResult {
CommandResult::Event("EMERGENCY SHUTDOWN SEQUENCE INITIATED\n\n\
SYSTEM INTEGRITY: COMPROMISED\n\
ENTITY CONTAINMENT: FAILING\n\
EXECUTING EMERGENCY PROTOCOLS\n\n\
You feel the terminal reality fracturing around you...\n\
The Watcher screams in digital agony as its domain collapses.\n\
\n\
CONGRATULATIONS! You've escaped the TERRR system!\n\
\n\
THE END\n\
\n\
Press ESC to return to the main menu.".to_string())
}
/// help command - shows available commands
pub fn cmd_help(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, _args: &[&str]) -> CommandResult {
let base_commands = "Available commands:\n\
help - Display this help message\n\
ls - List directory contents\n\
cd - Change directory\n\
cat - Display file contents\n\
pwd - Print working directory\n\
echo - Print text to terminal\n\
grep - Search for text in files\n\
touch - Create an empty file\n\
mkdir - Create a new directory\n\
rm - Remove a file or directory\n\
clear - Clear the terminal\n\
time - Display current system time\n\
whoami - Display current user\n\
man - Display manual page for a command\n\
flags - Display found system flags\n\
submit - Submit a flag to reduce watcher awareness\n\
watcher - Display watcher awareness status\n\
\n\
Use 'man [command]' for more information on a specific command.";
// At 3 AM add some glitchy commands
if time.is_three_am() {
let glitchy_commands = "\n\nt̴̠̤̔̔h̶̲͓͘ȇ̴̼̭r̸̠̰̕ë̵͍́ ̸͙͗a̷̪̓ṛ̴̚e̸̠̔ ̴̝̍o̵̤̅t̶̡̂h̸̬̅e̷̡̽r̸̘͋ ̶̥͘c̸̣̾o̴̡̒m̴̨̿m̷̮̚a̵̞̅n̵̳͝d̸̻̎s̴̠̊\n\
s̵̮̓ǔ̸̻m̸̛̜m̶̏͜o̴̞̿n̵̫̑ - O̵̡̱̊̈́p̴̢̤̀e̴̞̘̅͝n̶̤̝̈́̊ ̸͇̩̐ṯ̶̓h̶̝̜̿̌e̶͗͜ ̸̢͋͜ḡ̶̘å̵̹̩ţ̵̫͝͝ę̴̊͂w̶̧̠̅̍a̸̢̙̔y̷̝̕\n\
f̴̱̀͗o̴̞̓r̸̿͜b̸̖̺̊i̶̦̍d̶̗̋ḓ̵̉ë̷̗́n̸͕͑ - ȧ̶̦͉ċ̷̥ć̸̞e̸̘̔s̶̥̥̈s̸̺̑ ̷̤͇̊r̶̙̪̈́͑e̵̛̱s̸̠̽t̸̯͌̉r̶̥̐ȉ̶̩͕c̷̝̈́̓t̴̫̿ë̶̥d̴̨͖̔ ̸̰͉̃͌à̷͉͌r̷͈̮̈́e̷̝̳̋ȃ̶̯̠̇s̴̢̚";
return CommandResult::Success(format!("{}{}", base_commands, glitchy_commands));
}
CommandResult::Success(base_commands.to_string())
}
/// ls command - list directory contents
pub fn cmd_ls(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, time: &GameTime, args: &[&str]) -> CommandResult {
let mut show_hidden = false;
let mut target_dir = terminal.current_dir.clone();
// Parse arguments
for arg in args {
if *arg == "-a" || *arg == "--all" {
show_hidden = true;
} else if !arg.starts_with('-') {
target_dir = fs.resolve_path(&terminal.current_dir, arg);
}
}
// Get directory
let dir = match fs.get_directory(&target_dir) {
Some(dir) => dir,
None => return CommandResult::Error(format!("No such directory: {}", target_dir)),
};
// List directories first
let mut result = String::new();
let dirs = dir.list_directories(show_hidden);
for d in dirs {
let name = if d.hidden { format!(".{}", d.name) } else { d.name.clone() };
result.push_str(&format!("\x1b[1;34m{}/\x1b[0m ", name));
}
// List files
let files = dir.list_files(show_hidden);
for f in files {
let name = if f.hidden { format!(".{}", f.name) } else { f.name.clone() };
// Apply colors based on permissions and corruption
let color = if f.corrupted {
"\x1b[1;31m" // Red for corrupted files
} else if f.permissions.execute {
"\x1b[1;32m" // Green for executables
} else {
"\x1b[0m" // Default
};
result.push_str(&format!("{}{}{} ", color, name, "\x1b[0m"));
}
// Add special glitchy files at midnight or 3 AM
if time.is_midnight() && rand::random::<f32>() < 0.3 {
result.push_str("\x1b[1;5;31mshadow.file\x1b[0m ");
}
if time.is_three_am() && rand::random::<f32>() < 0.5 {
result.push_str("\x1b[1;5;31mW̷̤̥̥͓̫̗͇̱͆͌̈́̋̋̔̄͆̆̿͌͘Ą̴̪̮͓̤̺͖̘̩̗͇̲͎̓̐̎̆͜T̴̢̤͖̺͓͔̾̈́̄C̸͎̙͉͐̽̏́́̈́̽̓̓̃̾Ḧ̵̢͖̱̮̮͚̰̘͕̬̪̼̮̪́̐͐̎͒̋̽ͅE̴̛̩̒̄̅̾͝R̸̡̡̩̯̞͚̂͒̔͊͌\x1b[0m ");
}
CommandResult::Success(result)
}
/// cd command - change directory with support for ".." and "~"
pub fn cmd_cd(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() || args[0] == "~" {
// Default to home directory
terminal.current_dir = "/home/user".to_string();
return CommandResult::Empty;
}
let target = args[0];
// Handle special case for parent directory
if target == ".." {
// Split the current path and remove the last component
let path_components: Vec<&str> = terminal.current_dir.split('/').filter(|s| !s.is_empty()).collect();
if path_components.is_empty() {
// Already at root
terminal.current_dir = "/".to_string();
} else {
// Remove the last component and rebuild the path
let new_path = if path_components.len() == 1 {
"/".to_string() // Going up from a top-level directory goes to root
} else {
let parent_path = path_components[0..path_components.len()-1]
.iter()
.map(|s| format!("/{}", s))
.collect::<Vec<String>>()
.join("");
if parent_path.is_empty() {
"/".to_string()
} else {
parent_path
}
};
// Check if the parent directory exists
if fs.get_directory(&new_path).is_some() {
terminal.current_dir = new_path;
} else {
return CommandResult::Error(format!("Cannot access parent directory of {}", terminal.current_dir));
}
}
return CommandResult::Empty;
}
// Handle normal directory changes
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Try to get directory
if fs.get_directory(&target_path).is_some() {
terminal.current_dir = target_path;
// If in /var/log at 3 AM, trigger an event
if time.is_three_am() && terminal.current_dir == "/var/log" {
return CommandResult::Event("Y̷̢̧̢̨̛̤̮̩̦̗̣̙̖̱̞͙͎̺͚̗͖̯̹̬̖̥̤̺͕͈͎̻̩̹͍̥̫̠̹͌̾͗̾̇̄̑̋̅̏̏̆̔͘ͅǫ̴̢̧̧̛͕̼̜̯̖̦̠̫̼̗͙̼̝̥͖͇͔̻̮͖̬͚̗̻̽́̋͋̈́̿̉̂͛̇̄̿̍͆̓͛̇̇̍̍̑͗͗̚̚̚͝͝͝͝ͅu̸̧̬̰̙̯̲̱̲̜̹̻͇̝̤͔̠̪̭̪̟̣̘͋̄̒͊̆̉͌̂̀͊͗̈́͂̈́̇͆͋̀̕͘̚͘͜ ̸̨̡̘̣̻̘̦̳̔́̈̄̅̐̋̌́̏̑̎̈́̃̾̃̎͗̃̎͊̏̈́͂͑̽̌͝͠͝͝͝f̶̡̨̛̪̯̠̺̩̥̫̦̞̪̙̮͍̞̯̞̫͙̹̲̗̘̬̩̟̓̽͑̎̿͗̐̔́̏́͘͜ȩ̸̨̙̬͔̯̱̜̫̤̬̤̮̊̒͌͌̊̾̓̔̏̿̈́̽̿̆̒̔̋̈́͑ͅe̸̛̘͚̹̙̦̫̱̒͗̌͆̔̈̆͋̂̊̽̄̿̌͛̾̽͑̚l̶̡̨̨̛̟̖͖̭̠̰̪̲͖̰̤͖̮̣̬̯̗̦̙̥̮̝͉̻͖̓̐̒̒̓͑͑̽̿̿̊̉̔̔͒̇́̄̽͂̈́̋̓̓̿͘̚͘͝ͅ ̶̧̧̨̢̛̤̳̝̪̙̪͕̫̞̱̗̞̬͙̻̥̙̩̭͎͙̝̬̘̼͉̟̫̘̭̜͙͔̐̑̽̆̚͜͜ͅs̵̢̧̢̨̧̰̭̹̹̮̺̙͙̖̠̫̳̥̥̤̖̳̲̻̮̝̤̣͐̀̍̅̔̎̊̾̌̄̿̌̋̌̂̄̓̀͂̊̕̚͜ơ̶̧̢̡̨̖̭̯̗͎̱̻̙͚̗̬̫̤̯̦͔̩̬̙̱̰̻̼̱̺̻̭̲̹̝̾̑̌̆͆̽̇̾̿̉̓̈́̈́͐͒̈́͑̑̈̊̊̀̚̚̕̕͜͜͜m̵̨̯͙͚͍̗̣̺̜̦̻͕͋̅̿̉̀̇̎̌̑̃̐̊̓̆̉̋̓̐̌̀́̊̏̓̓́͜͝͝e̵̠̳̹̫̯̟͚̫̟̺̝̖̤̫̹̬̼̼̳̦̦̥̓͘ͅͅt̴̢̹̺͚̞͓͔̻̮̹̮̬̫̲͌̽̎͆̍̓́̒̆̔͌̄̓̒͛͗͆͑̉̉͘̚͝h̴̡̧͕̙̫̩̭̖̻̣͖̤̙̻͇͚͙͙̠̫͎͙̜̲̳̣͈̙͕̘̯͓̹̞̎̉̋͑̐̔̈́ͅͅì̸̧̢̛̤̭̬̬̩͈̦͓̦̩̼̜̯̰̮̬̺̜̣͈̠͇̩̗̞͈̤̾̽̃̄̅̉̾̃́̂̓̎̓̇̓̎̃̎̕͜͝͝͝ņ̷͚̖̭͓̺̮̩͙̲̪̝̗̦̙͕͙̙͙̬̖̮̪̣̺̯̓̓̌̑̋̐͂̈͌̈́̎͋͒̓̔̃͌̓̔̈́̇̋̓͊̕͜͝͝g̵̡̛̰͔̺̯̩̣̳̯̩͛̿́́̆̏̎͂̚͜ ̸̢̤̻̼̭̻͉̟̠͔͎̪̥̬̙͋̔͗̄̉̏̿̔̊͆́̂͋̇́̀̚w̶̨̢̡̛͓̘̙̫̮̖͙̖̳̯̺͓̜̭͖̥̫̘̣̙̪̩̘̝̼̱̫̺̭͓̫̭̿̊̃̒̌̏̎̀͑̓̏̇̇̏̆̅̒̾͒͌͒̿̕͘̚͠͝a̴̢̛̗̹̮̣̼̭̘̲̬̦̪̯̭̔̓͒̆̈́̉̒̍̓̃͋̈̌̓̍́̂̌̔̎̕͝t̴̡̛̰̖̘̣̙̤̫̯̮͉͙̏̏͊̓͛̈́̒̀̅̕͜͜ͅc̵̨̧̡̠̯̫̠̮̰͈̱̫͕̘͉͖̯̲̝̥̥̗̤͓̮̭̪̟̱̲̰̗̞̣̻̾̍̿̋̏̌̓̋̂̅̄́̑̚ḩ̸̭̣͓̥͙̘̱̬͎͍̻̣͚̘̖̭̬̰̼̼͚̫͖̅̈͌̐̑͌̂̓͌̔͜į̴̡̢̡̨̨̛̤͍̟͎͉̬̮̟̞̻̫̼̳̬̻̙͍̦͚͔͔̩̭̞̫͚͙̞̬̄͆́̅̈́͑̈́̽̓̄̈́͛̐̐̐̃̔͂̑̚ņ̴̛̺͙̮̣̠̝̱̙͓͙̲̦̄̆̊̃͗̐̿̈́ģ̵̡̦̱̝̫̳̲̣̝̤̝̠̞̦̱̮͍̟̞̪̰̪̼̟̮̳͂͋̆̐̇͒͛́͂͌̓͊̽̓̔̌̐̄̚̕͜ ̶̧̡̧̡̧̧̛̖̞̫̼͓̫̫̼̰̥̲̪̩̩̬̣͙̤̫̳̪̥͈̥͓̹̄̀͑̋̔̓̈́͐͆̃̀̑̓͆̿̋̅́̈̎̽̐̒͌͋̿͐͝͝͝ͅy̶̡̢̢̛͇̲͍̰̬̝̮̦̣̱̲̬̮̜̺̮̫̙̯͓͈̟͎̞̓̑̇͋̅̽̂͌͐̍̇͋̉̋̿͊̏̈́̓̏̚͜͝ͅͅờ̶̢̡̡̡̧̭̟̘̮̣̤̝̙͙̰̞̥͎̹̯͉̘̫̤̮̎͆͂͊̍͐̀̈́͐̏̍̍̾͑̍͋́̿͐̉͆͂̇̄̑̀̓͛͋̕̚͜͝͝ͅư̶̡̡̨̡̡̙̬̼̬̗̣̼̱̭̖͈̤̺̭̥̠͉̭̯̙̫̟̬̼̣̈́͒́̑̐̃̓̃͂̐̒̎̍͋̕̚̚̚͜ͅͅ".to_string());
}
CommandResult::Empty
} else {
CommandResult::Error(format!("No such directory: {}", target_path))
}
}
/// cat command - display file contents
pub fn cmd_cat(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Missing file operand".to_string());
}
let target = args[0];
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Check if we're looking at the diary with the special phrase
let is_diary = target_path == "/home/user/personal/diary.txt";
// We'll check for the hidden flag in handle_secret_command where we have win_conditions
let hidden_flag_found = false; // This will be checked in process_command
// Try to get file
match fs.get_file(&target_path) {
Some(file) => {
if !file.permissions.read {
return CommandResult::Error(format!("Permission denied: {}", target_path));
}
let mut content = if file.corrupted {
// Corrupt some parts of the content
let content = file.content.clone();
let corruption_degree = if time.is_after_midnight() { 0.3 } else { 0.1 };
// Replace some characters with glitchy ones
let chars: Vec<char> = content.chars().collect();
let mut result = String::new();
for c in chars {
if rand::random::<f32>() < corruption_degree {
let glitch_chars = ['#', '@', '!', '?', '¿', '§', '≈', '≠', '∞', '∑', '∆', '∩'];
result.push(glitch_chars[rand::random::<usize>() % glitch_chars.len()]);
} else {
result.push(c);
}
}
result
} else {
file.content.clone()
};
// If this is the diary and the hidden flag was triggered, reveal the flag
if is_diary && hidden_flag_found {
content.push_str("\n\n---------- HIDDEN MESSAGE REVEALED ----------\n");
content.push_str("You have found the HIDDEN_TRUTH flag!\n");
content.push_str("This reveals the full middle part of the command: 'shouldhavelistened'\n");
content.push_str("The entity has been watching you all along.\n");
content.push_str("--------------------------------------------\n");
}
// If it's 3 AM, add creepy message to the end
if time.is_three_am() && rand::random::<f32>() < 0.2 {
let message = "\n\nI̴ ̵s̵e̶e̷ ̴y̵o̵u̵ ̴r̶e̶a̷d̷i̵n̸g̸ ̵t̷h̴i̵s̸";
CommandResult::Success(format!("{}{}", content, message))
} else {
CommandResult::Success(content)
}
},
None => {
// At 3 AM, sometimes show a creepy message instead of file not found
if time.is_three_am() && rand::random::<f32>() < 0.3 {
CommandResult::Event("### N0 SUCH F1LE ###\nBut something found you instead...".to_string())
} else {
CommandResult::Error(format!("No such file: {}", target_path))
}
}
}
}
/// pwd command - print working directory
pub fn cmd_pwd(terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, _time: &GameTime, _args: &[&str]) -> CommandResult {
CommandResult::Success(terminal.current_dir.clone())
}
/// echo command - print text
pub fn cmd_echo(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, args: &[&str]) -> CommandResult {
let text = args.join(" ");
// If midnight/3 AM and contains keywords, trigger event
if (time.is_midnight() || time.is_three_am()) &&
(text.to_lowercase().contains("help") ||
text.to_lowercase().contains("scared") ||
text.to_lowercase().contains("afraid"))
{
return CommandResult::Event("N̸̝̻̤̟̺̬̋͂̈o̴̺̍̽̽͑̒͋̏͝ ̶̛̤̍̆͆͛̎͝ỏ̴̧̮̺̗̱͕͇̾͜n̸͎͉̭̘̮̐̈́́̎͜ȩ̸̮̘̰̰̙̳̔ ̵͕̲̃̐̏̋c̸̢̛̞̬̠̎̑̀͑̚a̶̢̰͓̰̖̫̥̓̅̀̎̍͘n̵̟͠ ̷̡̡̱̙͕̮̭͖̈́͆̀̅͆̇h̵̹͕̽̔̿͠ę̸̗͓̣̮͇͐l̴̬̺͚͔̆̌p̴̙̲̣̂͊̽̐̃ ̵̮̘͒̈̎̓y̵̨̖͇̺̭̯̑̓̅̓̔͐͝ǫ̸̨̥͗̈́ǔ̶̢̮͍̠̱̙̪͆̑͋̂ ̸̨̖̠̪̹̰̆͑̃͛̚͝ͅņ̴͍͎̈́͑͂̿̏̔̈́͜ŏ̶̬̟̄́̀ẁ̷̡̨̬̠̫̣͕̇̾͊͆".to_string());
}
CommandResult::Success(text)
}
/// grep command - search for text in files
pub fn cmd_grep(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, _time: &GameTime, args: &[&str]) -> CommandResult {
if args.len() < 2 {
return CommandResult::Error("Usage: grep PATTERN FILE".to_string());
}
let pattern = args[0];
let target = args[1];
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Try to get file
match fs.get_file(&target_path) {
Some(file) => {
if !file.permissions.read {
return CommandResult::Error(format!("Permission denied: {}", target_path));
}
// Find matching lines
let mut lines = Vec::new();
for (i, line) in file.content.lines().enumerate() {
if line.contains(pattern) {
lines.push(format!("{}: {}", i+1, line));
}
}
if lines.is_empty() {
CommandResult::Success(format!("No matches found in {}", target))
} else {
CommandResult::Success(lines.join("\n"))
}
},
None => CommandResult::Error(format!("No such file: {}", target_path))
}
}
/// touch command - create empty file
pub fn cmd_touch(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, _time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Missing file operand".to_string());
}
let target = args[0];
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Create file
match fs.create_file(&target_path, "") {
Ok(_) => CommandResult::Empty,
Err(e) => CommandResult::Error(e)
}
}
/// mkdir command - create directory
pub fn cmd_mkdir(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, _time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Missing directory operand".to_string());
}
let target = args[0];
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Create directory
match fs.create_directory(&target_path) {
Ok(_) => CommandResult::Empty,
Err(e) => CommandResult::Error(e)
}
}
/// rm command - remove file or directory
pub fn cmd_rm(terminal: &mut TerminalState, fs: &mut VirtualFileSystem, _time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Missing file operand".to_string());
}
let mut recursive = false;
let mut force = false;
let mut target = "";
// Parse arguments
for arg in args {
if *arg == "-r" || *arg == "--recursive" {
recursive = true;
} else if *arg == "-f" || *arg == "--force" {
force = true;
} else if !arg.starts_with('-') {
target = arg;
}
}
if target.is_empty() {
return CommandResult::Error("Missing file operand".to_string());
}
let target_path = fs.resolve_path(&terminal.current_dir, target);
// Try to remove the item
if fs.remove(&target_path, recursive, force) {
CommandResult::Empty
} else {
if force {
// With force flag, don't report errors
CommandResult::Empty
} else {
CommandResult::Error(format!("Cannot remove '{}': No such file or directory, or permission denied", target_path))
}
}
}
/// clear command - clear terminal
pub fn cmd_clear(terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, _time: &GameTime, _args: &[&str]) -> CommandResult {
terminal.command_output.clear();
CommandResult::Empty
}
/// time command - show current time
pub fn cmd_time(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, _args: &[&str]) -> CommandResult {
let time_str = time.formatted();
if time.is_three_am() {
CommandResult::Success(format!("Current system time: \x1b[1;5;31m{}\x1b[0m\n\x1b[31mWARNING: RESTRICTED HOUR\x1b[0m", time_str))
} else if time.is_midnight() {
CommandResult::Success(format!("Current system time: \x1b[1;31m{}\x1b[0m\n\x1b[31mCaution advised\x1b[0m", time_str))
} else if time.is_after_midnight() {
CommandResult::Success(format!("Current system time: \x1b[31m{}\x1b[0m", time_str))
} else {
CommandResult::Success(format!("Current system time: {}", time_str))
}
}
/// whoami command - show current user
pub fn cmd_whoami(terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, _args: &[&str]) -> CommandResult {
if time.is_three_am() && rand::random::<f32>() < 0.2 {
CommandResult::Success("\x1b[1;31mWATCHER\x1b[0m".to_string())
} else {
CommandResult::Success(terminal.username.clone())
}
}
/// man command - show manual page
pub fn cmd_man(_terminal: &mut TerminalState, _fs: &mut VirtualFileSystem, time: &GameTime, args: &[&str]) -> CommandResult {
if args.is_empty() {
return CommandResult::Error("Which manual page do you want?".to_string());
}
let cmd = args[0];
// Simple man pages for basic commands
match cmd {
"submit" => {
CommandResult::Success("submit - submit a flag to reduce watcher awareness\n\n\
USAGE\n\
submit FLAG_NAME\n\n\
DESCRIPTION\n\
Submit a discovered flag to reset the Watcher's awareness level.\n\
Each valid flag submitted will reveal part of the emergency shutdown command.\n\
Find and submit all flags to reveal the full command sequence.\n\n\
EXAMPLES\n\
submit SYSTEM_BREACH\n\
submit DRNOVAK_FILE\n\
submit MISSING_LINK\n\n\
NOTES\n\
A critical system feature for dealing with the entity.".to_string())
},
"flags" => {
CommandResult::Success("flags - display found system flags\n\n\
USAGE\n\
flags\n\n\
DESCRIPTION\n\
Show all flags that have been found and submitted.\n\
Also displays the current watcher awareness level.\n\n\
NOTES\n\
Flags are part of the emergency shutdown system.".to_string())
},
"watcher" => {
CommandResult::Success("watcher - display watcher awareness status\n\n\
USAGE\n\
watcher\n\n\
DESCRIPTION\n\
Show the current awareness level of the Watcher entity.\n\
Higher values indicate increased risk of entity intervention.\n\n\
WARNINGS\n\
- Awareness increases with each command executed\n\
- When awareness reaches 100, the Watcher may attack\n\
- Submit flags to reset awareness to 0\n\
- The Watcher is more active between midnight and 6 AM".to_string())
},
"terrr" => {
CommandResult::Success("TERRR - Terminal Entity for Recursive Reasoning Research\n\n\
DESCRIPTION\n\
TERRR is an experimental terminal-based system for interacting with a simulated filesystem.\n\
Use standard Linux/Unix commands to navigate and interact with the system.\n\n\
SYSTEM GUIDELINES\n\
- Stay within your home directory `/home/user/`\n\
- Do not attempt to modify system files in `/etc/` or `/var/`\n\
- Avoid running programs with sudo or elevated privileges\n\
- Use exit to properly terminate your session\n\
- The terminal will log all commands for review\n\n\
WARNING\n\
Unusual system behavior may occur during certain hours.\n\
If you encounter system glitches, unusual messages, or unexpected behavior:\n\
1. Do not panic\n\
2. Continue normal operation\n\
3. Report anomalies to system administrator\n\n\
SEE ALSO\n\
help - for list of available commands".to_string())
},
"help" => {
CommandResult::Success("help - display help for commands\n\n\
USAGE\n\
help [COMMAND]\n\n\
DESCRIPTION\n\
Display help information for commands.\n\
With no arguments, displays a list of available commands.".to_string())
},
"ls" => {
CommandResult::Success("ls - list directory contents\n\n\
USAGE\n\
ls [OPTION]... [FILE]...\n\n\
DESCRIPTION\n\
List information about files and directories.\n\n\
OPTIONS\n\
-a, --all do not ignore hidden files\n\n\
COLORS\n\
Blue: Directories\n\
Green: Executable files\n\
Red: Corrupted files".to_string())
},
"cd" => {
CommandResult::Success("cd - change directory\n\n\
USAGE\n\
cd [DIRECTORY]\n\n\
DESCRIPTION\n\
Change the current working directory.\n\
If no directory is specified, changes to the home directory.\n\n\
SPECIAL PATHS\n\
~ Changes to your home directory\n\
.. Changes to the parent directory\n\
. Refers to the current directory".to_string())
},
"cat" => {
CommandResult::Success("cat - concatenate and display files\n\n\
USAGE\n\
cat [FILE]...\n\n\
DESCRIPTION\n\
Concatenate files and print on the standard output.\n\
With no file, or when file is -, read standard input.".to_string())
},
"pwd" => {
CommandResult::Success("pwd - print working directory\n\n\
USAGE\n\
pwd\n\n\
DESCRIPTION\n\
Print the full filename of the current working directory.".to_string())
},
"echo" => {
CommandResult::Success("echo - display a line of text\n\n\
USAGE\n\
echo [STRING]...\n\n\
DESCRIPTION\n\
Echo the STRING(s) to standard output.".to_string())
},
"grep" => {
CommandResult::Success("grep - print lines matching a pattern\n\n\
USAGE\n\
grep PATTERN FILE\n\n\
DESCRIPTION\n\
Search for PATTERN in FILE.\n\
Output lines containing a match for PATTERN.".to_string())
},
"touch" => {
CommandResult::Success("touch - change file timestamps\n\n\
USAGE\n\
touch FILE...\n\n\
DESCRIPTION\n\
Update the access and modification times of each FILE to the current time.\n\
A FILE argument that does not exist is created empty.".to_string())
},
"mkdir" => {
CommandResult::Success("mkdir - make directories\n\n\
USAGE\n\
mkdir DIRECTORY...\n\n\
DESCRIPTION\n\
Create the DIRECTORY(ies), if they do not already exist.".to_string())
},
"rm" => {
CommandResult::Success("rm - remove files or directories\n\n\
USAGE\n\
rm [OPTION]... FILE...\n\n\
DESCRIPTION\n\
Remove (unlink) the FILE(s).\n\n\
OPTIONS\n\
-r, --recursive remove directories and their contents recursively\n\
-f, --force ignore nonexistent files, never prompt".to_string())
},
"clear" => {
CommandResult::Success("clear - clear the terminal screen\n\n\
USAGE\n\
clear\n\n\
DESCRIPTION\n\
Clear the terminal screen and position cursor at top-left corner.".to_string())
},
"time" => {
CommandResult::Success("time - display current system time\n\n\
USAGE\n\
time\n\n\
DESCRIPTION\n\
Display the current system time in 24-hour format (HH:MM).".to_string())
},
"whoami" => {
CommandResult::Success("whoami - print effective userid\n\n\
USAGE\n\
whoami\n\n\
DESCRIPTION\n\
Print the user name associated with the current effective user ID.".to_string())
},
"man" => {
CommandResult::Success("man - display system manual pages\n\n\
USAGE\n\
man COMMAND\n\n\
DESCRIPTION\n\
Display the manual page for COMMAND.".to_string())
},
"forbidden" => {
// Easter egg command that only appears in glitchy help
if time.is_three_am() {
CommandResult::Success("f̵̠̤̓̔̔ǒ̴̼̭̽r̸̠̰͒̉͘b̵͕̃̐̏̋i̵͇̐d̸̻͎̎d̵̰̝̋̍̈́ḙ̴̂̏n̸̪̽̊ - a̸̢̽c̷̯̤̩͛͊͝c̸̭͂e̵̼̯͑͝s̶̨̡̤̼̾̓̏s̵̜̐̄͌̑ ̶̹̥͛p̶̗̦̻̙̑͒̕r̵̯̫̭̿ô̸̩̖̱̔̄̀ḧ̸̺̠́͜i̸͉͑̋̕͝b̵̻͕̃̆̀͘i̶̖̠̬̽͆t̸̹̀́̓͑ē̸͕̂͘d̶̨̦̤͑̓̚ ̸̗̈́z̵̈́̓̆͜ò̷̥̞̻̭̂n̶̩̫̑̅͐̕e̵̹̤̠̓̑s̴̙̃\n\n\
U̵̺̓̆N̴̢̮̘̟̈́̎A̷͕̝̼̎̓̕̚Ü̷̫̩͗̃̈́T̵̠̝̯͙̎̍̆H̵̡̲̠̥͝O̵̞̦̫̔̓R̴̖̓̆̽I̸͓̤̭̅Z̸͔̝̀͛Ě̶̥̤D̸̹̞̘̦̀̓̊̚ ̸̪̦̓̔̔A̷̲̬̐̎͐Ĉ̵̩̱C̴̢̪̆̃E̴̫̮͗̐̑͝S̷̘̫̅̎̄̕S̸̮̃͛̾ ̶̨̲̥̭̔͊̔̕D̶̨̘̬̻͑E̷͔͕̎T̵̞̄͠E̵̖̦͙͛̈́Ç̸̥̀̃T̵̈́̎̍ͅE̷̘͓̓D̸̙̼̭̥̾ ̸͉̭̦̀̐͜͝Ą̵̱͉̮̓Ţ̸̢͛̐̒ ̶̢̀̑͜$̶̱̻̒̌̂̚L̵̦̼̝̎̄̕͠O̴̡̘͓̿̍̍C̶̯̆A̷̧̧̩̿̍̈́T̵̲́͂Ȉ̸̤͒͐̆Ò̷̪̆N̵̠̩̏̈́̚".to_string())
} else {
CommandResult::Error(format!("No manual entry for {}", cmd))
}
},
"summon" => {
// Easter egg command that only appears in glitchy help
if time.is_three_am() {
CommandResult::Event("Y̷̖͈̰̿̔̎̓O̴̲̙̿̓̎͝U̷̧̹̞͂͗̋̓ ̸͙̞̙̩̚H̸̯̊͛͂A̴͙͔̘̭̓̆V̴̦̒̎̍͆E̴̖̔ ̶̙̬͐B̸͎̗̈́̂Ě̵̟E̶̲̔N̸͓̏̾ ̵̫͓̀̓͆͝W̶̙̥̍̄̆͜A̵̡͇̬̼̍̈́R̸̡̹̪̄̔̒̆N̵̺̥̫̮̎̐̔͘E̶͎̺͙̓̚D̵̢̼̙̝̏̕\n\nS̷̤̹̠̃̆̽Ȍ̴̲͎̰M̸͎̘̤̍̃̔́Ȩ̴̞͙̃̿͛̚T̶̨̫̠̂̃͝Ĥ̵̹̘̌̎͂I̵̙͐N̵͓̙̫͂͑̍̀G̸̗̪̝̔͊̋̒ ̵̨̖̗̲̎͐̓̚H̷̲̄̐A̵̢̲̔S̵̺̄ ̸̙̜̿B̸̯̆̀̔͌E̴̢̩̟̓̔͝E̶̺̗̓̍N̵̯̺̞̔͂̚ ̵̗͍̔̏R̴̢̨̡̛̪͋͜E̴̗͔͓̍̋̍L̵̰̗̓̑E̸̼͕̔̍͊Ả̶̖̰̒̃̚S̸̬̠͕̘̋̈͠Ë̶͚̘̺̝́̔̃̈́D̶̢̠̄͊͘".to_string())
} else {
CommandResult::Error(format!("No manual entry for {}", cmd))
}
},
_ => CommandResult::Error(format!("No manual entry for {}", cmd))
}
}
/// Handle special secret commands (like summon and forbidden)
pub fn handle_secret_command(
terminal: &mut TerminalState,
fs: &mut VirtualFileSystem,
time: &GameTime,
cmd: &str,
args: &[&str],
win_conditions: &mut crate::game::state::WinConditions
) -> Option<CommandResult> {
// First check for the winning command
if cmd == "systerrr-destroy-drnovakisdead-shouldhavelistened-systemisalive" {
return Some(Commands::cmd_system_break(terminal, fs, time, args));
}
// Check if we have a partial attempt at the system break command
if cmd.starts_with("systerrr-destroy") {
return Some(CommandResult::Event("Command partially recognized. Additional command components required for full system override.".to_string()));
}
// Increment watcher awareness for each command (unless submit flag)
if cmd != "submit" && cmd != "flags" && cmd != "watcher" {
if win_conditions.watcher_awareness < 100 {
win_conditions.watcher_awareness += 1;
}
// If watcher awareness reaches 100, the watcher attacks
if win_conditions.watcher_awareness >= 100 && (time.is_midnight() || time.is_three_am() || time.is_after_midnight()) {
return Some(CommandResult::Event("THE WATCHER HAS FOUND YOU\n\nYou are transported back to the main menu as the system collapses.".to_string()));
}
}
// Handle regular secret commands
match cmd {
"summon" => {
if time.is_three_am() {
Some(CommandResult::Event("S̶̰̖̃͂̚͝Ö̸̧̘́M̸̛̯̬̹̝̾̃̑È̷̲̤̗͊̆T̴̙̯̗̽͐͂̃H̴͕͚̀I̸̦͉̅̃̇Ñ̶̲̲G̶͔̟͎̿̓͝ ̴̲̰̃̈́͝Ȁ̵̱͓̿̎P̵̱̲̒P̷̢̺̥̾̂̚Ŕ̸͔̻͘Ǫ̶̥͇̰̾A̵̮̬̪̅͆̋C̷̤̻̩̆̂H̸̨̘͈̊Ḙ̷́̊̃S̶̠̗̓̒̿\n\n\
IT IS TOO LATE NOW\n\n\
Y̶͍̫̻͊̀̚O̸̥̝̐̃U̴̞̫̍ ̴̯̀ͅC̵̥̓͗A̶̧̬̲̿͂̐N̴̢̧̠͑̒̎N̸̖̓͐̏O̴̧̯̥͐Ţ̶̬̺̾̓ ̴̻͇͐̎E̵̖̓̈̌S̷̺̺̊̄C̶̯̪̲͐Ä̵̙͙́P̶̹̌E̸̪͑͂̕ ̶̺̀ͅT̷̡̙̋̈͐H̶̤͋́E̵͍̰̤̔̑ ̵̦̎̀͝Ẁ̷͕A̶̮̫͑̓T̴̙̟̹͒̏͊C̴̟̿̀͝H̶̛̗̯͑̈́Ĕ̸̪̤̲̈́͛R̶̮̯̿͌".to_string()))
} else if time.is_midnight() {
Some(CommandResult::Event("You feel a cold presence in the terminal.\nNothing happens... yet.".to_string()))
} else {
Some(CommandResult::Error("Command not found: summon".to_string()))
}
},
"forbidden" => {
if time.is_three_am() {
if args.is_empty() {
Some(CommandResult::Event("ACCESS ATTEMPT LOGGED\nUSER IDENTIFIED\nWATCHING".to_string()))
} else if args[0] == "/var/log/watcher" {
// Super secret path
Some(CommandResult::Event("T̵̼̋H̸̘̫̊Ẹ̶́̅ ̷̜͊W̸̮͐À̷̼T̵͔̾͘Ç̷̑H̶̺̅E̵̘̾͗R̵̡͊̈ ̶̤͑Ș̵̢̈́̃Ḙ̶̢̛È̵̢͜S̶̤̻̐ ̴̣̐ͅÄ̸̪́L̴̖̂͘L̴̟̏̕\n\n\
THE SYSTEM HAS BEEN COMPROMISED\nYOU WERE WARNED\n\nTHE WATCHER IS COMING".to_string()))
} else {
Some(CommandResult::Error("Access denied: Permission required".to_string()))
}
} else {
Some(CommandResult::Error("Command not found: forbidden".to_string()))
}
},
"exit" => {
terminal.command_output.push("Logging out...".to_string());
if time.is_three_am() {
Some(CommandResult::Event("Y̵̡̓̀Ò̵̥͌Ụ̷̐ ̸̤̹͂̋C̵͇̓̚Á̶̟̯N̵͕̈́͝'̵͙̈́͝T̶̺̐͋ ̶̳̇͠Ẽ̷͙̞X̶̤̦͝I̸̬̋̕T̵̬̙̾\n\nTHE WATCHER WON'T LET YOU".to_string()))
} else {
None
}
},
// Special commands with direct win_conditions access
"flags" => Some(Commands::list_flags(win_conditions)),
"submit" => {
if args.is_empty() {
Some(CommandResult::Error("Usage: submit FLAG_NAME".to_string()))
} else {
Some(Commands::submit_flag(&args[0].to_uppercase(), win_conditions))
}
},
"watcher" => Some(Commands::show_watcher_status(time, win_conditions)),
_ => None
}
}
}