Browse Source

Added USER and NICK into harry_timeout_event

username and fullname needed to be moved
out of the using namespace std section,
else we couldn't link them.

test-mangle needed those string defined.

wordplay now looks to see if we have fullname,
and if so, adds additional phrases to the
random options.

BUG:  We're not doing the console terminal correctly.
I need to know the corrent current cursor position --
some of the phrases are getting long.

BUG:  The "Here lies USER, rest in peace", the
delay needs to be longer for this one, it
takes longer to read that.
bugz 4 years ago
parent
commit
c2a7c18ba9
3 changed files with 47 additions and 13 deletions
  1. 7 7
      hharry.cpp
  2. 2 0
      test-mangle.cpp
  3. 38 6
      wordplay.cpp

+ 7 - 7
hharry.cpp

@@ -12,6 +12,13 @@
 #include <sstream>
 #include <string>
 
+/*
+We get the username/fullname from tailing the node logs,
+and reading the user.dat file.
+ */
+std::string username;
+std::string fullname;
+
 using namespace std;
 
 // #include <signal.h> // handle Ctrl-C/SIGINT
@@ -109,13 +116,6 @@ that we'll be executing and mangling?
 
  */
 
-/*
-The code to get the username and fullname is useless on telnet
-connections.
-
- */
-string username;
-string fullname;
 int node;
 
 /*

+ 2 - 0
test-mangle.cpp

@@ -20,6 +20,8 @@
 #define GTEST_COUT std::cerr << "[          ] [ INFO ]"
 
 struct console_details console;
+std::string username = "Pseudonym";
+std::string fullname = "Joe User";
 
 int harry_level(void) { return 4; }
 int randint(int x) { return 1; }

+ 38 - 6
wordplay.cpp

@@ -15,6 +15,8 @@
 #include <vector>
 
 extern struct console_details console;
+extern std::string username;
+extern std::string fullname;
 
 #define BSIZE 512
 
@@ -32,23 +34,52 @@ void harry_idle_event(int fd) {
   if (!level)
     return;
 
+  // If the username is something, we have their info!
+  bool have_userinfo = !username.empty();
+
   // This is no where near finished, BUT!
   // Do not put any ^ codes in these -- the strlen() would be wrong.
-  const char *phrases[] = {"Hahaha",    "Snicker, snicker", "Boo!",
-                           "MeOW",      "I see U",          "Arrooo!",
-                           "Ahh-wooo!", "Aaaooo!"};
+  const char *phrases[] = {
+      "Hahaha",  "Snicker, snicker", "Boo!",           "Arrooo!", "Ahh-wooo!",
+      "Aaaooo!", "Sorry, I forgot!", "Knock-Knock...",
+  };
+  const int total_phrases = sizeof(phrases) / sizeof(char *);
+
+  const char *user_phrases[] = {
+      "Is USER really here?",
+      "What is a NICK?",
+      "Here lies USER, rest in peace.",
+      "Don't be scared, NICK.",
+  };
+  const int total_user_phrases = sizeof(user_phrases) / sizeof(char *);
 
   static LastSeen last_seen_harry_event(2);
 
+  int total_possible =
+      have_userinfo ? total_phrases + total_user_phrases : total_phrases;
+
+  ZF_LOGD("%d total %d console @ %d,%d", have_userinfo, total_possible,
+          console.posx, console.posy);
   do {
-    r = randint((sizeof(phrases) / sizeof(char *)));
+    r = randint(total_possible);
   } while (last_seen_harry_event.seen_before(r));
 
+  std::string selected;
+  if (r > total_phrases) {
+    selected = user_phrases[r - total_phrases];
+    replace(selected, "USER", fullname);
+    replace(selected, "NICK", username);
+  } else
+    selected = phrases[r];
+
   int color = randint(15) + 1;
   // %02d = std::setfill('0') << std::setw(2) << (int)
-
+  /*
   buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color
          << phrases[r] << "^P2^CR^D" << std::setw(2) << strlen(phrases[r]);
+  */
+  buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color << selected
+         << "^P2^CR^D" << std::setw(2) << selected.size();
 
   std::string str = buffer.str();
   ZF_LOGD("harry_event: render(%d, \"%s\")", fd, str.c_str());
@@ -272,7 +303,8 @@ int mangle(int fd, std::string &buffer) {
             "NeXTSTEP", "MINIX",      "Solaris",
             "Plan 9",   "FreeBSD",    "Windows 95",
             "Palm OS",  "Mac OS X",   "Windows XP",
-            "DESQview",
+            "DESQview", "EMACS",
+            // EMACS *should* be an OS!
         };
 
         int r = randint(sizeof(bbs_systems) / sizeof(char *));