# 💥 Crash the Server - Game Architecture & CS Knowledge Base

## 📌 Overview
`Crash the Server` is an interactive password puzzle game designed for the Computer Science Club website. Players must craft a continuously growing "super password" that satisfies all unlocked rules across 5 progressive stages. As new rules are unlocked and satisfied, the Server Overload percentage increases. Reaching 100% overload successfully "crashes the server" and wins the game.

---

## ⚙️ How It Works

### 1. Core Password Evaluation Engine
* **Dynamic Rule Checking:** Whenever user input changes, the engine iterates over all unlocked rules and executes their `check(input: string): boolean` validator function.
* **5-Stage Progressive Escalation:**
  * **Stage 1 (Onboarding & Fundamentals):** Password length, uppercase/digits/symbols, classic developer memes (e.g., `helloworld`, `lgtm`, `shipit`), escape sequences (`\n`, `\t`, `\x41`), and programming language release years (e.g., C 1972, Python 1991, Rust 2010).
  * **Stage 2 (Production Incidents):** Real-world scenarios simulating Linux kernel crashes, memory safety violations (`nullptr`, `malloc`, `free`), CI/CD pipeline/container automation (`docker`, `jenkins`), concurrency deadlocks (`mutex`, `semaphore`), garbage collection memory management (`OOM`, `gc`), and a digit-sum puzzle (digits must total 42).
  * **Stage 3 (Low-Level Systems & Networking):** IPv4 loopback address (`127.0.0.1`), private subnets (`192.168.x.x`, `10.x.x.x`), standard HTTP methods/ports (`80`, `443`), SQL keywords, dangerous Git commands (`git reset --hard`, `git push --force`), and statically typed file extensions.
  * **Stage 4 (Advanced CS Logic & Algorithms):** Palindromes & prime numbers, ticker symbols, boolean/nil keywords, hexadecimal literals, RSA cryptography, Big-O notation (`O(log n)`), and CSS sizing units.
  * **Stage 5 (Ultimate Server Crash):** Matching HTML tag triples, Base64 encoding, real-time clock minutes, UNIX octal permissions (`755`, `644`), standard I/O streams (`stdout`, `stderr`), hex color codes, SemVer versions, and complex string regex distance checks.
* **Server Overload Calculation:**
  $$\text{Server Overload (\%)} = \min\left(100, \left\lfloor \frac{\sum_{\text{passed rules}} \text{weight}_i}{\text{Total Weight}} \times 100 \right\rfloor \right)$$
* **State Persistence:** Automatically saves user progress and entered password to `localStorage` (`crash_the_server_state`), enabling seamless resume or full game reset.

---

## 🧠 CS Knowledge Base & Monthly Puzzle Expansion

This documentation acts as a living Computer Science Knowledge Base. Each password rule corresponds to foundational CS concepts, computer history milestones, and system architecture trivia.

### 📚 Core CS Concepts Reference

#### 🌐 1. Networking & Operating Systems
* **Loopback Address:** `127.0.0.1` (IPv4) / `::1` (IPv6), defined in RFC 1122. Packets sent to this IP are routed internally within the host loopback interface without leaving the network adapter.
* **Private Subnets:** `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16` (defined in RFC 1918). Reserved for local area networks (LANs) and non-routable on the public Internet.
* **UNIX Octal File Permissions:** Compact notation for file permissions where `755` represents `rwxr-xr-x` (User: read/write/execute, Group/Others: read/execute) and `644` represents `rw-r--r--`.
* **Standard Streams:** The three POSIX communication channels opened by default when a command executes: Standard Input (`stdin` / 0), Standard Output (`stdout` / 1), and Standard Error (`stderr` / 2).

#### 🔒 2. Memory Safety & System Reliability
* **Kernel Panic:** An unrecoverable safety measure taken by Unix-like operating system kernels upon detecting a critical error from which system recovery is impossible.
* **Segmentation Fault (Segfault):** A hardware fault raised by the Memory Management Unit (MMU) when a process attempts to access an unauthorized or unmapped memory address (e.g., dereferencing a `nullptr`).
* **Synchronization Primitives & Deadlocks:** Mechanisms like Mutexes and Semaphores prevent race conditions. A Deadlock occurs when threads are blocked forever waiting for resources held by each other.

#### 💻 3. Programming History & Algorithms
* **Language Milestones:**
  * `1957`: Fortran (first high-level language)
  * `1972`: C (Dennis Ritchie at Bell Labs)
  * `1983`: C++ (Bjarne Stroustrup)
  * `1991`: Python (Guido van Rossum)
  * `1995`: Java & JavaScript
  * `2010`: Rust (Memory safety without GC)
* **RSA Cryptography:** Public-key cryptosystem developed in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman based on the computational difficulty of factoring large composite integers.
* **Big-O Time Complexity:** Binary search algorithm achieves logarithmic time complexity $O(\log n)$ on sorted collections.

---

## 📅 Monthly CS Fun Facts & Puzzle Expansion Backlog

> **Maintainer Note:** Use this section as an expandable backlog for monthly puzzle updates. Each month, select 2-3 CS fun facts and convert them into new password validation rules in `CrashTheServer.tsx`!

### 🗓️ July 2026 CS Trivia
* **Fun Fact #1: The First Computer Bug:** On September 9, 1947, Grace Hopper's team discovered a real moth stuck in Relay #70 of Panel F in the Harvard Mark II computer. They taped it into their logbook with the caption "First actual case of bug being found," popularizing the term "debugging".
* **Fun Fact #2: HTTP 418 I'm a Teapot:** Defined on April Fools' Day 1998 in RFC 2324 as part of the Hyper Text Coffee Pot Control Protocol (HTCPCP). Returned by teapots when requested to brew coffee.
* **Puzzle Concept:** Require the password to contain `418` or `teapot`.

### 🗓️ August 2026 CS Trivia
* **Fun Fact #1: Unix Epoch Time:** Standard computer time begins at 00:00:00 UTC on January 1, 1970. The Year 2038 problem (Y2K38) will occur on January 19, 2038, when signed 32-bit Unix timestamps overflow.
* **Fun Fact #2: Fast Inverse Square Root (`0x5f3759df`):** Famous algorithm from Quake III Arena used to compute $\frac{1}{\sqrt{x}}$ at blistering speed using integer bit manipulation of IEEE 754 floating-point representations.
* **Puzzle Concept:** Require the password to contain `1970` or magic constant `0x5f3759df`.

### 🗓️ September 2026 CS Trivia
* **Fun Fact #1: Executable Magic Numbers:** Binary headers start with magic numbers, such as `0x7F 'E' 'L' 'F'` for Linux ELF executables or `0x4D 0x5A` (`MZ`) for Windows PE executables.
* **Fun Fact #2: Sudo Warning:** The first time `sudo` is run, UNIX displays: *"With great power comes great responsibility."*
* **Puzzle Concept:** Require the password to contain `sudo` or magic byte strings.

---

## 🛠️ How to Add New Rules
1. Append a new Rule object to `RULE_POOL` in `CrashTheServer.tsx`:
   ```ts
   {
     id: NEXT_RULE_ID,
     stage: 3, // Target stage (1-5)
     weight: 6, // Overload contribution weight
     title: "Rule description shown to player",
     hint: "Detailed hint for player",
     check: (input: string) => input.includes("your_keyword"),
   }
   ```
2. Document the newly introduced CS fun fact in `crash-the-server.md` under the corresponding month section.
