Просмотр исходного кода

This is the initial door testing / space ace.

Steve Thielemann 4 лет назад
Сommit
a7dc1e607b
10 измененных файлов с 480 добавлено и 0 удалено
  1. 33 0
      CMakeLists.txt
  2. 55 0
      DOOR.SYS
  3. 12 0
      backup.sh
  4. 19 0
      door_2023.sh
  5. 6 0
      grind.sh
  6. 10 0
      main.ans
  7. 286 0
      main.cpp
  8. 19 0
      rlinetd.conf
  9. 36 0
      space.h
  10. 4 0
      try_inet.sh

+ 33 - 0
CMakeLists.txt

@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 3.0)
+project(spaceace
+  VERSION 0.1
+  LANGUAGES CXX C)
+
+###########
+# Debug or Release
+###########
+if (NOT CMAKE_BUILD_TYPE)
+  ## set default to Debug
+  set(CMAKE_BUILD_TYPE Debug)  # override with -DCMAKE_BUILD_TYPE=Release
+  message("==> CMAKE_BUILD_TYPE empty. Changing it to Debug.")
+else()
+  message("==> CMAKE_BUILD_TYPE == ${CMAKE_BUILD_TYPE}.")
+endif()
+
+## https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+## During Debug, use debug version of libstdc++ (asserts on access to invalid iterators, etc!)
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
+
+##############
+# C++ Standard
+##############
+set(CMAKE_CXX_STANDARD   14)
+# set(CMAKE_CXX_STANDARD   17)
+set(CMAKE_CXX_EXTENSIONS ON)
+
+add_subdirectory(door++)
+
+add_executable(space-ace main.cpp)
+target_link_libraries(space-ace door++ pthread)
+

+ 55 - 0
DOOR.SYS

@@ -0,0 +1,55 @@
+COM0:
+38400
+8
+1
+1
+Y
+N
+Y
+Y
+BEAN ZILLA
+BBS Archives
+805-493-8318
+805-493-8328
+
+99
+2630
+01-01-71
+27120
+452
+GR
+25
+N
+
+
+
+43
+
+80
+203
+0
+65535
+01-01-71
+
+
+
+Sysop
+SYSOP
+SYSOP
+N
+N
+N
+N
+N
+N
+N
+
+N
+
+
+N
+0
+0
+N
+0
+0

+ 12 - 0
backup.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# Recommended RAR parameters
+
+# RAR4="-m5 -dh -ed -mct -ow -t -s -rr10p"
+RAR4="-m5 -dh -mct -ow -t -s -rr10p"
+
+# RAR5="-ma5 -qo+ -md128M -m5 -dh -ed -ow -t -s -rr10p -idp"
+# RAR5="-ma5 -qo+ -md128M -m5 -dh -ow -t -s -rr10p -idp"
+
+rar a $RAR4 -r -ola -x*.rar -x*.log -xbuild/* -xbackup/* -xdbuild/* -agYYYY-MM-DD-NN door++ 
+

+ 19 - 0
door_2023.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+
+trap failwhale SIGINT
+
+failwhale() {
+echo "FAIL WHALE"
+exit
+}
+
+# pipexec -k (kills other processes if one dies)
+# ^ This fixes problem when you hangup on netcat (MEOOOW)
+
+while true
+do
+  pipexec -k -- [ NETCAT /bin/netcat -l 2023 ] [ DOOR build/space-ace -D DOOR.SYS ] "{NETCAT:1>DOOR:0}" "{DOOR:1>NETCAT:0}"
+  echo "Let's do it again!"
+
+done
+

+ 6 - 0
grind.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+valgrind -v --log-file=grind.log build/space-ace -l -u grinder
+
+
+tail grind.log

+ 10 - 0
main.ans

@@ -0,0 +1,10 @@
+[?7hワイイイイロワ アアイイロロアイイロアイイロロアイイロロアイイロアイイロロアイイロロ
+アアロアアロローアイローアロローアロローアイローアロローアロロ
+ーアワワワワ   ーアイロ ーイローーーーワワ ーイローーーーワワ
+ ゚゚゚゚イイーーアアイ  ーーアアイイ ー ー゚゚  ーーアアイイ ー ー゚゚
+ロ    アイ ー  アイ  アイ  アイ  アイ  アイ  アイ
+゚ ローーア゚     ーア  ーーア  ーーア  ーア  ーーア  ーーア
+
+
+Bugz in space, with a deck of cards
+

+ 286 - 0
main.cpp

@@ -0,0 +1,286 @@
+#include "door.h"
+#include "space.h"
+#include <iostream>
+#include <random>
+#include <string>
+
+// The idea is that this would be defined elsewhere (maybe)
+int user_score = 0;
+
+// NOTE:  When run as a door, we always detect CP437 (because that's what Enigma
+// is defaulting to)
+
+void adjust_score(int by) { user_score += by; }
+
+door::Panel make_timeout(int mx, int my) {
+  door::ANSIColor yellowred =
+      door::ANSIColor(door::COLOR::YELLOW, door::COLOR::RED, door::ATTR::BOLD);
+
+  std::string line_text("Sorry, you've been inactive for too long.");
+  int msgWidth = line_text.length() + (2 * 3); // + padding * 2
+  door::Panel timeout((mx - (msgWidth)) / 2, my / 2 + 4, msgWidth);
+  // place.setTitle(std::make_unique<door::Line>(title), 1);
+  timeout.setStyle(door::BorderStyle::DOUBLE);
+  timeout.setColor(yellowred);
+
+  door::Line base(line_text);
+  base.setColor(yellowred);
+  std::string pad1(3, ' ');
+
+  /*
+      std::string pad1(3, '\xb0');
+      if (door::unicode) {
+        std::string unicode;
+        door::cp437toUnicode(pad1.c_str(), unicode);
+        pad1 = unicode;
+      }
+  */
+
+  base.setPadding(pad1, yellowred);
+  // base.setColor(door::ANSIColor(door::COLOR::GREEN, door::COLOR::BLACK));
+  std::unique_ptr<door::Line> stuff = std::make_unique<door::Line>(base);
+
+  timeout.addLine(std::make_unique<door::Line>(base));
+  return timeout;
+}
+
+door::Menu make_main_menu(void) {
+  door::Menu m(5, 5, 25);
+  door::Line mtitle("Space-Ace Main Menu");
+  door::ANSIColor border_color(door::COLOR::CYAN, door::COLOR::BLUE);
+  door::ANSIColor title_color(door::COLOR::CYAN, door::COLOR::BLUE,
+                              door::ATTR::BOLD);
+  m.setColor(border_color);
+  mtitle.setColor(title_color);
+  mtitle.setPadding(" ", title_color);
+
+  m.setTitle(std::make_unique<door::Line>(mtitle), 1);
+
+  // m.setColorizer(true,
+  m.setRender(true, door::Menu::makeRender(
+                        door::ANSIColor(door::COLOR::CYAN, door::ATTR::BOLD),
+                        door::ANSIColor(door::COLOR::BLUE, door::ATTR::BOLD),
+                        door::ANSIColor(door::COLOR::CYAN, door::ATTR::BOLD),
+                        door::ANSIColor(door::COLOR::BLUE, door::ATTR::BOLD)));
+  // m.setColorizer(false,
+  m.setRender(false, door::Menu::makeRender(
+                         door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
+                                         door::ATTR::BOLD),
+                         door::ANSIColor(door::COLOR::WHITE, door::COLOR::BLUE,
+                                         door::ATTR::BOLD),
+                         door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
+                                         door::ATTR::BOLD),
+                         door::ANSIColor(door::COLOR::CYAN, door::COLOR::BLUE,
+                                         door::ATTR::BOLD)));
+
+  m.addSelection('1', "Play Cards");
+  m.addSelection('2', "View Scores");
+  m.addSelection('3', "Drop to DOS");
+  m.addSelection('4', "Chat with BUGZ");
+  m.addSelection('H', "Help");
+  m.addSelection('A', "About this game");
+  m.addSelection('Q', "Quit");
+
+  return m;
+}
+
+door::Panel make_about(void) {
+  door::Panel about(2, 2, 60);
+  about.setStyle(door::BorderStyle::DOUBLE_SINGLE);
+  about.setColor(door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
+                                 door::ATTR::BOLD));
+  about.addLine(std::make_unique<door::Line>("About This Door", 60));
+  /*
+  123456789012345678901234567890123456789012345678901234567890
+  This door was written by Bugz.
+
+  It is written in c++, only supports Linux, and replaces
+  opendoors.
+
+  It's written in c++, and replaces the outdated opendoors
+  library.
+
+   */
+  about.addLine(
+      std::make_unique<door::Line>("This door was written by Bugz.", 60));
+  about.addLine(std::make_unique<door::Line>("", 60));
+  about.addLine(std::make_unique<door::Line>(
+      "It is written in c++, only support Linux, and replaces", 60));
+  about.addLine(std::make_unique<door::Line>("opendoors.", 60));
+  return about;
+}
+
+void display_starfield(int mx, int my, door::Door &door, std::mt19937 &rng) {
+  door << door::reset << door::cls;
+
+  // display starfield
+  const char *stars[2];
+
+  stars[0] = ".";
+  if (door::unicode) {
+    stars[1] = "\u2219"; // "\u00b7";
+
+  } else {
+    stars[1] = "\xf9"; // "\xfa";
+  };
+
+  {
+    // Make uniform random distribution between 1 and MAX screen size X/Y
+    std::uniform_int_distribution<int> uni_x(1, mx);
+    std::uniform_int_distribution<int> uni_y(1, my);
+
+    door::ANSIColor white(door::COLOR::WHITE);
+    door::ANSIColor dark(door::COLOR::BLACK, door::ATTR::BRIGHT);
+
+    for (int x = 0; x < (mx * my / 100); x++) {
+      door::Goto star_at(uni_x(rng), uni_y(rng));
+      door << star_at;
+      if (x % 5 < 2)
+        door << dark;
+      else
+        door << white;
+
+      if (x % 2 == 0)
+        door << stars[0];
+      else
+        door << stars[1];
+    }
+  }
+}
+
+void display_space_ace(int mx, int my, door::Door &door) {
+  // space_ace is 72 chars wide, 6 high
+  int sa_x = (mx - 72) / 2;
+  int sa_y = (my - 6) / 2;
+
+  // output the SpaceAce logo -- centered!
+  for (const auto s : space) {
+    door::Goto sa_at(sa_x, sa_y);
+    door << sa_at;
+    if (door::unicode) {
+      std::string unicode;
+      door::cp437toUnicode(s, unicode);
+      door << unicode; // << door::nl;
+    } else
+      door << s; // << door::nl;
+    sa_y++;
+  }
+  // pause 5 seconds so they can enjoy our awesome logo
+  door.sleep_key(5);
+}
+
+void display_starfield_space_ace(int mx, int my, door::Door &door,
+                                 std::mt19937 &rng) {
+  display_starfield(mx, my, door, rng);
+  display_space_ace(mx, my, door);
+  door << door::reset;
+}
+
+int main(int argc, char *argv[]) {
+  door::Door door("space-ace", argc, argv);
+  // door << door::reset << door::cls << door::nl;
+  door::ANSIColor ac(door::COLOR::YELLOW, door::ATTR::BOLD);
+
+  // https://stackoverflow.com/questions/5008804/generating-random-integer-from-a-range
+
+  std::random_device rd; // only used once to initialise (seed) engine
+  std::mt19937 rng(
+      rd()); // random-number engine used (Mersenne-Twister in this case)
+  // std::uniform_int_distribution<int> uni(min, max); // guaranteed unbiased
+
+  int mx, my; // Max screen width/height
+  if (door.width == 0) {
+    // screen detect failed, use sensible defaults
+    mx = 80;
+    my = 23;
+  } else {
+    mx = door.width;
+    my = door.height;
+  }
+  // We assume here that the width and height are something crazy like 10x15. :P
+
+  display_starfield_space_ace(mx, my, door, rng);
+
+  // for testing inactivity timeout
+  door.inactivity = 10;
+
+  door::Panel timeout = make_timeout(mx, my);
+  door::Menu m = make_main_menu();
+
+  int r = m.choose(door);
+  // need to reset the colors.  (whoops!)
+  door << door::reset;
+
+  if (r == -1) {
+  TIMEOUT:
+    door.log("TIMEOUT");
+    // mx, my
+    door::ANSIColor yellowred = door::ANSIColor(
+        door::COLOR::YELLOW, door::COLOR::RED, door::ATTR::BOLD);
+
+    std::string line_text("Sorry, you've been inactive for too long.");
+    int msgWidth = line_text.length() + (2 * 3); // + padding * 2
+    door::Panel timeout((mx - (msgWidth)) / 2, my / 2 + 4, msgWidth);
+    // place.setTitle(std::make_unique<door::Line>(title), 1);
+    timeout.setStyle(door::BorderStyle::DOUBLE);
+    timeout.setColor(yellowred);
+
+    door::Line base(line_text);
+    base.setColor(yellowred);
+    std::string pad1(3, ' ');
+
+    /*
+        std::string pad1(3, '\xb0');
+        if (door::unicode) {
+          std::string unicode;
+          door::cp437toUnicode(pad1.c_str(), unicode);
+          pad1 = unicode;
+        }
+    */
+
+    base.setPadding(pad1, yellowred);
+    // base.setColor(door::ANSIColor(door::COLOR::GREEN, door::COLOR::BLACK));
+    std::unique_ptr<door::Line> stuff = std::make_unique<door::Line>(base);
+
+    timeout.addLine(std::make_unique<door::Line>(base));
+    door << timeout << door::reset << door::nl << door::nl;
+    return 0;
+  }
+
+  display_starfield(mx, my, door, rng);
+  // WARNING: After starfield, cursor position is random!
+
+  door << door::Goto(1, 9); // door::nl << door::nl; // door::cls;
+  door << "Hello, " << door.username << ", you chose option " << r << "!"
+       << door::nl;
+
+  door << "Press a key...";
+  r = door.sleep_key(door.inactivity);
+  if (r == -1)
+    goto TIMEOUT;
+
+  door << door::nl;
+
+  door::Panel about = make_about();
+  about.set((mx - 60) / 2, (my - 5) / 2);
+
+  door << about;
+
+  door << door::reset << door::nl << "Press another key...";
+  r = door.sleep_key(door.inactivity);
+  if (r == -1)
+    goto TIMEOUT;
+
+  door << door::nl;
+
+  // door << door::reset << door::cls;
+  display_starfield(mx, my, door, rng);
+  door << m << door::reset << door::nl << "This is what the menu looked liked!"
+       << door::nl;
+
+  // Normal DOOR exit goes here...
+  door << door::nl << "Returning you to the BBS, please wait..." << door::nl;
+  sleep(2);
+
+  return 0;
+}

+ 19 - 0
rlinetd.conf

@@ -0,0 +1,19 @@
+
+service "door" {
+    enabled yes;
+    port 2023;
+    interface any;
+    # execv(build/space-ace -l -u wired): No such file or directory
+    # exec "build/space-ace -l -u wired";
+
+    exec "build/space-ace -l -u wired";
+    # this runs it (with no parameters) causing help screen to be displayed.
+    # server "build/space-ace";
+    server "build/space-ace";
+    user "stevet";
+    group "stevet";
+    protocol tcp;
+    instances 3;
+}
+
+

+ 36 - 0
space.h

@@ -0,0 +1,36 @@
+#include <array>
+// #include <vector>
+
+// std::vector<const char *>
+// const char * space[] =
+std::array<const char *, 10> space = {
+    "\x1b[0;1;32m\xdc\x1b[42m\xb2\xb2\xb2\xb2\xdb\x1b[40m\xdc "
+    "\x1b[42m\xb1\xb1\xb2\xb2\xdb\xdb\x1b[4C\xb1\xb2\xb2\xdb\x1b["
+    "4C\xb1\xb2\xb2\xdb\xdb\x1b[3C\xb1\xb2\xb2\xdb\xdb\x1b["
+    "11C\xb1\xb2\xb2\xdb\x1b[4C\xb1\xb2\xb2\xdb\xdb\x1b["
+    "3C\xb1\xb2\xb2\xdb\xdb\x1b[40m",
+    "\x1b[42m\xb1\xb1\x1b[4C\xdb\x1b[2C\xb1\xb1\x1b[2C\xdb\xdb\x1b["
+    "2C\xb0\xb1\x1b[2C\xb2\xdb\x1b[2C\xb0\xb1\x1b[3C\xdb\xdb\x1b["
+    "1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[9C\xb0\xb1\x1b[2C\xb2\xdb\x1b["
+    "2C\xb0\xb1\x1b[3C\xdb\xdb\x1b[1C\xb0\xb1\x1b[3C\xdb\xdb\x1b[40m",
+    "\x1b[42m\xb0\xb1\x1b[40m\xdc\xdc\xdc\xdc   "
+    "\x1b[42m\xb0\xb1\x1b[2C\xb2\xdb\x1b[1C "
+    "\xb0\x1b[4C\xb2\xdb\x1b[1C\xb0\xb0\x1b[6C\xb0\xb0\x1b[0;32m\xdc\xdc\x1b["
+    "11C\x1b[42m "
+    "\x1b[1m\xb0\x1b[4C\xb2\xdb\x1b[1C\xb0\xb0\x1b[6C\xb0\xb0\x1b[0;"
+    "32m\xdc\xdc",
+    " \x1b[1m\xdf\xdf\xdf\xdf\x1b[42m\xb2\xb2\x1b[2C\xb0\xb0\xb1\xb1\xb2\x1b["
+    "2C  \xb0\xb0\xb1\xb1\xb2\xb2\x1b[1C \xb0\x1b[6C "
+    "\xb0\x1b[0;32m\xdf\xdf\x1b[11C\x1b[42m  "
+    "\x1b[1m\xb0\xb0\xb1\xb1\xb2\xb2\x1b[1C \xb0\x1b[6C \xb0\x1b[0;32m\xdf\xdf",
+    "\xdb    \x1b[1;42m\xb1\xb2\x1b[2C \xb0\x1b[5C  \x1b[4C\xb1\xb2\x1b[1C  "
+    "\x1b[3C\xb1\xb2\x1b[1C  \x1b[3C\xb1\xb2\x1b[8C  \x1b[4C\xb1\xb2\x1b[1C  "
+    "\x1b[3C\xb1\xb2\x1b[1C  \x1b[3C\xb1\xb2\x1b[40m",
+    "\x1b[0;32m\xdf\x1b[42m \x1b[40m\xdb\x1b[1;42m\xb0\xb0\xb1\x1b[0;32m\xdf "
+    "\x1b[42m  \x1b[7C  \x1b[2C\x1b[1m\xb0\xb1\x1b[3C  \xb0\xb0\xb1\x1b[3C  "
+    "\xb0\xb0\xb1\x1b[10C  \x1b[2C\xb0\xb1\x1b[3C  \xb0\xb0\xb1\x1b[3C  "
+    "\xb0\xb0\xb1\x1b[40m",
+    "",
+    "",
+    "\x1b[37mBugz in space, with a deck of cards",
+    "\x1b[0m"};

+ 4 - 0
try_inet.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+
+rlinetd -d -f rlinetd.conf
+