#!/usr/bin/newlisp ;; Creative Commons Attribution (by) License v2.5 ;; Full text - http://creativecommons.org/licenses/by/2.5/ ;; Contact - tyler.mace@versantvoice.com ;; Copyright (c) 2009, Versant Voice, LLC. ;; Context: SQLITE ;; This context provides us with the ability to manipulate ;; all the data in the database. Sorta important, I'd say. (context 'SQLITE) ;; Context: NCURSES ;; This context provides us with the necessary functionality ;; to draw our fancy shell. (context 'NCURSES) (setq library_path "/lib64/libncurses.so.5") (setq function_list '("initscr" "box" "newwin" "endwin" "delwin" "wgetch" "wrefresh" "mvwprintw" "LINES" "COLS" "getmaxx" "getmaxy")) ;; Import any needed ncurses functionality (define (Import_NCurses) (dolist (x NCURSES:function_list) (import library_path x) ) ) ;; Context: COMMUNICATION ;; As our players will likely want to converse with one ;; another, we thought it might be a good idea to include ;; functionality for such. This is where you can find it. (context 'COMMUNICATION) ;; Context: EXPLOIT ;; This context is where we will keep work our exploit ;; creation and implementation. A sort of 'crafting' for ;; our little game here. (context 'EXPLOIT) ;; Context: MISSION ;; This is where we provide functionality and information ;; regarding our mission system. Similar to 'quests' in ;; other games. (context 'MISSION) ;; Context: PLAYER ;; This context is where we're going to keep all ;; player-specific information. (context 'PLAYER) ;; Context: NPC ;; This context will contain information and functionality ;; of our NPCs (law enforcement, other hackers, etc). (context 'NPC) ;; Context: HOST ;; This context is, as you guessed, where we keep our host ;; information and functionality. We want to keep track of ;; host external and internal addresses, owner(s), status, ;; and more. (context 'HOST) ;; Host variables (setq addr "") (setq owner "") (setq status "") (setq services '()) ;; Context: SHELL ;; This context is where the visual magic occurs. It ;; contains the information and functionality of our ;; in-game shell, where players will be spending all of ;; their time. (context 'SHELL) ;; Shell variables (setq shell_rows 0) (setq shell_cols 0) (setq ps1 "secsec> ") (setq quit_command "quit") (setq current_command "") (setq last_command "") ;; Process command lambda ;; Takes a command as an argument and processes it (define (Process_Command command_string) (begin ;; Local variables (setq command_list (parse command_string)) (setq command (first command_list)) (setq command_args (rest command_list)) (setq all_commands (directory MAIN:command_directory)) (setq usable_commands (begin ;; Strip out ".", "..", and scripts named the same as quit command ;; Returns only usable scripts (pop all_commands (find "." all_commands)) (pop all_commands (find ".." all_commands)) (pop all_commands (find SHELL:quit_command all_commands)) all_commands ) ) ;; Debug information ;;(println (append "Command: " command)) ;;(println (append "Argument(s): " (join command_args ", "))) ;;(println (append "Commands available: " (join usable_commands ", "))) ;; Find our command script and run it, if available, else show available commands (if (find command usable_commands) (begin ;; Gather command data from our script (setq script_data (read-file (append MAIN:command_directory command))) ;; Evaluate newly gathered data (setq evaluated_script_data (eval-string script_data)) ) (println (append "Unknown command: " command)) ) ) ) ;; Run shell lambda ;; Run our shell, looping to process commands as they're entered (define (Run_Shell) (begin ;; NCurses (NCURSES:Import_NCurses) (NCURSES:initscr) (setq shell (NCURSES:newwin SHELL:shell_rows SHELL:shell_cols 0 0)) (NCURSES:box shell 0 0) (NCURSES:mvwprintw shell 1 1 SHELL:ps1) (NCURSES:wrefresh shell) (NCURSES:wgetch shell) (NCURSES:delwin shell) (NCURSES:endwin) ;; Process commands so long as player doesn't enter quit command (while (begin (print SHELL:ps1 ) (setq SHELL:current_command (read-line))) (begin ;; Is the player trying to quit? (if (= SHELL:current_command SHELL:quit_command) (begin ;;(NCURSES:delwin shell) ;;(NCURSES:endwin) ;;(println (NCURSES:getmaxx shell)) ;;(println (NCURSES:getmaxy shell)) (MAIN:Exit_Game) ) ) ;; Process current command (SHELL:Process_Command SHELL:current_command) ) ) ) ) ;; Context: MAIN ;; Perhaps the most boring of all contexts, this context ;; contains our exit and splash messages, versioning info, ;; and that's about it. (context 'MAIN) ;; Main variables (setq game_name "SecSec") (setq game_major_version "0") (setq game_minor_version "4") (setq game_full_version (append game_major_version "." game_minor_version)) (setq script_directory "script/") (setq command_directory (append script_directory "command/")) (setq host_directory (append script_directory "host/")) (setq npc_directory (append script_directory "npc/")) (setq player_directory (append script_directory "player/")) ;; Splash Screen lambda ;; Display version and other game information (define (Splash_Screen) (begin (println (append MAIN:game_name " - v" MAIN:game_full_version "\r\n")) ) ) ;; Exit lambda (define (Exit_Game) (begin (println "Exiting...") (exit) ) ) ;; Let's play! (MAIN:Splash_Screen) (SHELL:Run_Shell)