Переглянути джерело

Initial attempt at doing things better.

Steve Thielemann 4 роки тому
батько
коміт
6c4b2f8919
1 змінених файлів з 28 додано та 6 видалено
  1. 28 6
      mystic.c

+ 28 - 6
mystic.c

@@ -473,20 +473,41 @@ void init_have_seen(int *list, int len) {
 #define MAX_HARRY_EVENT_DUPS 2
 int last_seen_harry_event[MAX_HARRY_EVENT_DUPS];
 
+#ifdef CPP_MADMAN_STL_CODE
+
+const char *random_phrase(const char *words, int len, int last_seen) {
+  // ooh.  a map of char *s to last_seen_events.  :P
+  static map<const char *, array<int>> tracker;
+  map<const char *, array<int>>::iterator it;
+  array<int, last_seen> it = tracker.find(words);
+  if (it == tracker.end()) {
+    // key does not exist.
+    array<int, last_seen> last;
+    for (int i = 0; i < last_seen; i++) {
+      last[i] = -1;
+    };
+
+    tracker.insert(words, last);
+    it = tracker.find(words);
+  };
+}
+#endif
+
 void harry_event(int fd) {
   // Make something happen
   char buffer[100];
   int r;
   // This is no where near finished, BUT!
-  const char *phrases[] = {"Hahaha", "Snicker, snicker", "Boo!", "MeOW",
-                           "I see U", "Arrooo!", "Ahh-wooo!", "Aaaooo!"};
+  const char *phrases[] = {"Hahaha",    "Snicker, snicker", "Boo!",
+                           "MeOW",      "I see U",          "Arrooo!",
+                           "Ahh-wooo!", "Aaaooo!"};
   const char *cp;
 
   // Remember the last phrase used,
   // and don't repeat (the last two)!
 
   do {
-    r = random() % ( (sizeof(phrases) / sizeof(char *)) - 1 );;
+    r = random() % ((sizeof(phrases) / sizeof(char *)) - 1);
   } while (have_seen(last_seen_harry_event, MAX_HARRY_EVENT_DUPS, r));
 
   ZF_LOGD("%d => %d %d", r, last_seen_harry_event[0], last_seen_harry_event[1]);
@@ -506,9 +527,10 @@ void init_harry() {
 }
 
 /*
-NOTE: Logging is single file, don't use in production!
-It won't handle multiple writers.
-*/
+The code to get the username and fullname is useless on telnet
+connections.
+
+ */
 char *username = NULL;
 char *fullname = NULL;