/* * WarGames - a WOPR emulator written in C * Copyright (C) 2014 Franklin Wei * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Contact the author at contact@fwei.tk */ #include "chatbot.h" #include "joshua.h" #include "strings.h" /* predefined strings */ #include "util.h" #include #include #include #include #include void cleanup(int signum) { exit(EXIT_SUCCESS); } void random_stuff(void) { clear(); print_string("#45 11456 11009 11893 11972 11315\nPRT CON. 3.4.5. SECTRAN 9.4.3. PORT STAT: SD-345\n\n(311) 699-7305\n"); clear(); print_string("\n\n\n\n\n\n\n"); print_string("(311) 767-8739\n(311) 936-2364\n- PRT. STAT. CRT. DEF.\n||||||||||||||==================================================\nFSKDJLSD: SDSDKJ: SBFJSL: DKSJL: SKFJJ: SDKFJLJ:\nSYSPROC FUNCT READY ALT NET READY\nCPU AUTH RY-345-AX3 SYSCOMP STATUS ALL PORTS ACTIVE\n22/34534.90/3209 11CVB-3904-3490\n(311) 935-2364\n"); usleep(100000); clear(); } void be_joshua(int fd) { out_fd = fd; clear(); signal(SIGINT, &cleanup); /* old curses stuff */ /* start_color(); init_pair(1, COLOR_BLUE, COLOR_BLACK); attron(COLOR_PAIR(1));*/ bool gamesPhase = false; char buf[32]; if(connection_data[out_fd].know_termsize == 1) { /* the terminal size could change while the spaces are being printed, so use a while loop */ int n = 0; while(n < connection_data[out_fd].term_width * 2) { print_string(" "); ++n; } } else print_string("\n\n"); do { if(!gamesPhase) print_string("LOGON: "); refresh(); int ret = getnstr(buf, sizeof(buf)); allLower(buf); usleep(SLEEP_TIME * 100); if(strcmp(buf, "help logon") == 0 && !gamesPhase) { print_string("\nHELP NOT AVAILABLE\n\n\n"); } else if(strcmp(buf, "help games") == 0) { print_string("\n'GAMES' REFERS TO MODELS, SIMULATIONS AND GAMES\nWHICH HAVE TACTICAL AND STRATEGIC APPLICATIONS.\n\n\n"); gamesPhase = true; } else if(strcmp(buf, "list games") == 0 && gamesPhase) { print_string("\nFALKEN'S MAZE\nBLACK JACK\nGIN RUMMY\nHEARTS\nBRIDGE\nCHECKERS\nCHESS\nPOKER\nFIGHTER COMBAT\nGUERRILLA ENGAGEMENT\nDESERT WARFARE\nAIR-TO-GROUND ACTIONS\nTHEATERWIDE TACTICAL WARFARE\nTHEATERWIDE BIOTOXIC AND CHEMICAL WARFARE\n\nGLOBAL THERMONUCLEAR WAR\n\n\n"); } else if(ret == ERR || strcmp(buf, "joshua") && !gamesPhase) { print_string("\nIDENTIFICATION NOT RECOGNIZED BY SYSTEM\n--CONNECTION TERMINATED--"); exit(EXIT_SUCCESS); } } while(strcmp(buf, "joshua") || gamesPhase); random_stuff(); usleep(SLEEP_TIME * 100); print_string("GREETINGS, PROFESSOR FALKEN.\n\n"); refresh(); getnstr(buf, sizeof(buf)); allLower(buf); remove_punct(buf); for(int i = 0; i < sizeof(exit_triggers) / sizeof(const char*); ++i) { if(strcmp(buf, exit_triggers[i]) == 0) { print_string("\n\n"); print_string(exit_responses[rand() % sizeof(exit_responses)/sizeof(const char*)]); print_string("\n--CONNECTION TERMINATED--"); return; } } print_string("\n\nHOW ARE YOU FEELING TODAY?\n\n"); refresh(); do_chatbot(); return; }