From 22aa8fe628258f7bf0992c3074213ce38bfea2f6 Mon Sep 17 00:00:00 2001 From: p7mj Date: Tue, 7 Apr 2026 15:12:44 -0400 Subject: [PATCH] basic server --- CHATTER/requests/1775566784403.txt | 1 - CHATTER/server.py | 60 ++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) delete mode 100644 CHATTER/requests/1775566784403.txt diff --git a/CHATTER/requests/1775566784403.txt b/CHATTER/requests/1775566784403.txt deleted file mode 100644 index c2d8a47..0000000 --- a/CHATTER/requests/1775566784403.txt +++ /dev/null @@ -1 +0,0 @@ -LOGIN:bob:bob_is_i \ No newline at end of file diff --git a/CHATTER/server.py b/CHATTER/server.py index fecdef1..7d733b4 100644 --- a/CHATTER/server.py +++ b/CHATTER/server.py @@ -1,6 +1,58 @@ -# SERVER CLIENT -# PURPOSE: read requests, send data, validate interactions +import time +from pathlib import Path + +# Setup paths +base_path = Path(__file__).parent +req_path = base_path / "requests" +req_path.mkdir(exist_ok=True) + +print("Server online. Monitoring requests...") while True: - # reading requests logic - pass \ No newline at end of file + # 1. Grab everything in the folder + # .iterdir() is efficient for scanning + for file_path in req_path.iterdir(): + + # FAILSAFE 1: Ignore folders or non-txt files (like .DS_Store or .tmp) + if not file_path.is_file() or file_path.suffix != ".txt": + print(f"Skipping non-txt file: {file_path.name}") + continue + + try: + # 2. Try to read the content + with open(file_path, "r") as f: + content = f.read().strip() + + # FAILSAFE 2: Check if the file is empty or missing colons + if not content or ":" not in content: + print(f"Malformed request in {file_path.name}. Deleting.") + file_path.unlink() + continue + + # 3. Parse the data + # Use the '2' limit we discussed to protect passwords with colons + parts = content.split(":", 2) + + # FAILSAFE 3: Check if we have enough parts (Command:User:Pass) + if len(parts) < 3: + print(f"Incomplete data in {file_path.name}. Deleting.") + file_path.unlink() + continue + + command, user, data = parts + print(f"Processing {command} for {user}...") + + # --- YOUR LOGIC GOES HERE --- + # if command == "LOGIN": ... + # if command == "CREATEUSER": ... + + # 4. Clean up: Delete the request after successful processing + file_path.unlink() + + except Exception as e: + # FAILSAFE 4: Catch-all for weird errors (like file being locked) + print(f"Error processing {file_path.name}: {e}") + continue + + # 5. Heartbeat + time.sleep(0.1) \ No newline at end of file