aboutsummaryrefslogtreecommitdiff
path: root/joshua.c
blob: 1ccb01dd39785994a338d322a6d21dab361f2fa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 *   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 <http://www.gnu.org/licenses/>.
 *
 *   Contact the author at contact@fwei.tk
 */

#include "chatbot.h"
#include "joshua.h"
#include "strings.h" /* predefined strings */
#include "util.h"

#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void cleanup(int signum)
{
  exit(EXIT_SUCCESS);
}
void random_stuff(void) /* print random junk on the screen for about 3 seconds */
{
  clear();
  /* credit for this text goes to David Brownlee and Chirs Carter */
  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);
  /*
  start_color();
  init_pair(1, COLOR_BLUE, COLOR_BLACK);
  attron(COLOR_PAIR(1));*/
  bool gamesPhase=false;
  char buf[33];
  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, 32);
    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, 32);
  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--");
          exit(EXIT_SUCCESS);
        }
    }
  print_string("\n\nHOW ARE YOU FEELING TODAY?\n\n");
  refresh();
  do_chatbot();
  exit(EXIT_SUCCESS);
}