Browse Source

Moved directory structure for running as BBS door

  It was found that when I set this up, I set it up wrong.

  To build this:
  * copy just the door lib from doorgo into the main directory with the
directories yt and mdbook.
    door/
    yt/
    mdbook/
    Makefile
    ...
  * Then make and run.
Apollo 2 years ago
parent
commit
2aa7443ba1
20 changed files with 310 additions and 1 deletions
  1. 6 0
      .gitignore
  2. 28 0
      Makefile
  3. 244 0
      door32.c
  4. 3 0
      go_4044
  5. 4 0
      run_4044
  6. 0 0
      yt/XANNORHQ.TXT
  7. 0 0
      yt/YTOPEN.ANS
  8. 0 0
      yt/armagedonred.go
  9. 0 0
      yt/cyberwar.go
  10. 1 1
      yt/go.mod
  11. 0 0
      yt/go.sum
  12. 0 0
      yt/yt.go
  13. 24 0
      yt/yt2000-1.log
  14. 0 0
      yt/ytdata.go
  15. 0 0
      yt/ytname.dat
  16. 0 0
      yt/ytnews.dat
  17. 0 0
      yt/ytopen.ans
  18. 0 0
      yt/ytopen.go
  19. 0 0
      yt/ytrmsg.dat
  20. 0 0
      yt/ytscore.asc

+ 6 - 0
.gitignore

@@ -1,6 +1,12 @@
+
+# Ignore doorgo lib
+door/
+
 # Ignore drop files
 *.sys
 *.SYS
 
 # Ignore executable
 yt2000
+door32
+

+ 28 - 0
Makefile

@@ -0,0 +1,28 @@
+
+all: door32 yt
+
+
+door32: door32.c
+	gcc -o door32 door32.c
+
+testdoor/art.go: space.ans
+	./ansi-to-go.py main space.ans > testdoor/art.go
+
+testdoor/testdoor: testdoor/art.go testdoor/*.go door/*.go
+	cd testdoor; go build
+
+space-construct: game/*.go door/*.go game/sc.go
+	cd game; go build -ldflags="-extldflags=-static" -tags sqlite_omit_load_extension
+
+ansi-to-go/ansi-to-go: ansi-to-go/ansi-to-go.go
+	cd ansi-to-go; go build
+
+lobd/art.go: art/*.ans ansi-to-go/ansi-to-go
+	./ansi-to-go/ansi-to-go art/*.ans > game/art.go
+
+lobd: game/*.go door/*.go
+	cd game; go build -ldflags="-extldflags=-static" -tags sqlite_omit_load_extension
+
+yt: yt/*.go door/*.go
+	cd yt; go build -ldflags="-extldflags=-static" -tags sqlite_omit_load_extension
+

+ 244 - 0
door32.c

@@ -0,0 +1,244 @@
+#include <netdb.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+void doprocessing(int sock);
+char *cmds[10];
+
+void set_raw(int fd) {
+  struct termios tio_raw;
+  tcgetattr(fd, &tio_raw);
+  cfmakeraw(&tio_raw);
+  tcsetattr(fd, TCSANOW, &tio_raw);
+}
+
+int drain(int fd) {
+  struct timeval tv;
+  fd_set set;
+  int ret;
+  char buffer[21];
+  int total = 0;
+
+   printf("draining... \n");
+
+  do {
+    FD_ZERO(&set);
+    FD_SET(fd, &set);
+    tv.tv_sec = 0;
+    // 50,000 works for syncterm
+    tv.tv_usec = 50000;
+
+    ret = select(fd + 1, &set, NULL, NULL, &tv);
+    if (ret == 1) {
+      total += read(fd, buffer, 20);
+    }
+  } while (ret != 0);
+  printf(" [%d]\n", total);
+  return total;
+}
+
+int main(int argc, char *argv[]) {
+  int sockfd, newsockfd, portno, clilen;
+  char buffer[256];
+  struct sockaddr_in serv_addr, cli_addr;
+  int n, pid;
+
+  /* First call to socket() function */
+  sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+  if (sockfd < 0) {
+    perror("ERROR opening socket");
+    exit(1);
+  }
+
+  if (argc != 3) {
+    printf("I need a listening port number, and command/door to call.\n");
+    exit(2);
+  }
+
+  int listen_port = atoi(argv[1]);
+  char *command = strdup(argv[2]);
+  char *cp;
+  int cmd_count;
+  cp = command;
+  cmds[cmd_count] = cp;
+  cmd_count++;
+  while (*cp != 0) {
+    if (*cp == ' ') {
+      *cp = 0;
+      cp++;
+      cmds[cmd_count] = cp;
+      cmd_count++;
+      continue;
+    }
+    cp++;
+  }
+  cmds[cmd_count] = (char *)NULL;
+
+  if (listen_port == 0) {
+    printf("I need a listening port number as a parameter.\n");
+    exit(2);
+  }
+
+  /* Initialize socket structure */
+  bzero((char *)&serv_addr, sizeof(serv_addr));
+  portno = listen_port;
+
+  serv_addr.sin_family = AF_INET;
+  serv_addr.sin_addr.s_addr = INADDR_ANY;
+  serv_addr.sin_port = htons(portno);
+
+  int flag = 1;
+  if (-1 == setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag))) {
+    perror("setsockopt fail");
+  }
+
+  /* Now bind the host address using bind() call.*/
+  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
+    perror("ERROR on binding");
+    exit(1);
+  }
+
+  /* Now start listening for the clients, here
+   * process will go in sleep mode and will wait
+   * for the incoming connection
+   */
+  printf("Listening for connections on %d\n", listen_port);
+
+  listen(sockfd, 5);
+  clilen = sizeof(cli_addr);
+
+  while (1) {
+    newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
+
+    if (newsockfd < 0) {
+      perror("ERROR on accept");
+      exit(1);
+    }
+
+    set_raw(newsockfd);
+
+    /* Create child process */
+    pid = fork();
+
+    if (pid < 0) {
+      perror("ERROR on fork");
+      exit(1);
+    }
+
+    if (pid == 0) {
+      /* This is the client process */
+      close(sockfd);
+      doprocessing(newsockfd);
+      exit(0);
+    } else {
+      close(newsockfd);
+    }
+
+  } /* end of while */
+  free((void *)command);
+}
+
+#define CRNL "\r\n"
+
+void doprocessing(int sock) {
+  int n;
+  char buffer[256];
+  // raw mode
+  // set_raw(sock);
+  /*
+      std::string ayt = std::string((const char *)"\x00\xff\xfd\xf6", 4);
+      std::string ayt_resp = std::string((const char *)"\xff\xfb\x00", 3);
+      std::string ayt2 = std::string((const char *)"\xff\xfb\x00", 3);
+      std::string ayt2_resp = std::string((const char *)"\xff\xfd\x00", 3);
+
+  */
+  // write(sock, "\x00\xff\xfd\xf6", 4);
+  // write(sock, "\xff\xfb\x00", 3);
+
+  /*
+  https://www.rfc-editor.org/rfc/rfc658.html
+  https://www.rfc-editor.org/rfc/rfc652.html
+  https://www.iana.org/assignments/telnet-options/telnet-options.xhtml
+  https://stackoverflow.com/questions/273261/force-telnet-client-into-character-mode
+  https://www.omnisecu.com/tcpip/telnet-modes-of-operation.php
+  https://www.omnisecu.com/tcpip/iac-interpret-as-command-telnet.php
+  https://www.omnisecu.com/tcpip/telnet-negotiation.php
+  https://stackoverflow.com/questions/10413963/telnet-iac-command-answering
+  http://ryobbs.com/doku.php/terminal_iac
+  https://www.omnisecu.com/tcpip/telnet-commands-and-options.php
+  
+   */
+  write(sock, "\xff\xfb\x01", 3);
+  // drain(sock);
+  write(sock, "\xff\xfb\x03", 3);
+  // drain(sock);
+  write(sock, "\xff\xfd\x10", 3);
+  // write(sock, "\xff\xfc\x22", 3);
+
+  // syncterm is slow.  It needs time to drain.  :()
+  
+  drain(sock);
+  // drain(sock);
+  /*
+  struct termios tio_raw;
+  tcgetattr(sock, &tio_raw);
+  cfmakeraw(&tio_raw);
+  tcsetattr(sock, TCSANOW, &tio_raw);
+  */
+
+  // telnet client into character mode
+  // sprintf(buffer, "\377\375\042\377\373\001Welcome socket %d\n\r", sock);
+  sprintf(buffer, "Welcome socket %d" CRNL, sock);
+  write(sock, buffer, strlen(buffer));
+
+  // can I read the buffer until empty, maybe?
+
+  FILE *fp;
+
+  fp = fopen("door32.sys", "w");
+  if (fp == NULL) {
+    return;
+  }
+
+  fprintf(fp, "%d\n", 2);
+  fprintf(fp, "%d\n", sock);
+  fprintf(fp, "38400\n");
+  fprintf(fp, "Fake Door32 BBS\n");
+  fprintf(fp, "1\n");
+  fprintf(fp, "%s\n%s\n", "Bugz Laundry", "Bugz");
+  fprintf(fp, "%d\n", 100);
+  fprintf(fp, "%d\n", 120);
+  fprintf(fp, "1\n1\n");
+  fclose(fp);
+
+  // This resets the termios ??
+  // execl("./testdoor", "testdoor", "-d", "door32.sys", (const char *)NULL);
+  execv(cmds[0], cmds);
+
+  // step1:  write out door32.sys file
+  // exec / replace this with our door
+
+  /*
+  bzero(buffer,256);
+
+  n = read(sock,buffer,255);
+
+  if (n < 0) {
+     perror("ERROR reading from socket");
+     exit(1);
+  }
+
+  printf("Here is the message: %s\n",buffer);
+  n = write(sock,"I got your message",18);
+
+  if (n < 0) {
+     perror("ERROR writing to socket");
+     exit(1);
+  }
+  */
+}

+ 3 - 0
go_4044

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+telnet 127.0.0.1 4044

+ 4 - 0
run_4044

@@ -0,0 +1,4 @@
+#!/bin/bash
+
+./door32 4044 "yt/yt2000 -d ../door32.sys"
+

+ 0 - 0
XANNORHQ.TXT → yt/XANNORHQ.TXT


+ 0 - 0
YTOPEN.ANS → yt/YTOPEN.ANS


+ 0 - 0
armagedonred.go → yt/armagedonred.go


+ 0 - 0
cyberwar.go → yt/cyberwar.go


+ 1 - 1
go.mod → yt/go.mod

@@ -2,7 +2,7 @@ module red-green/yt2000
 
 go 1.18
 
-replace red-green/door => ../doorgo/door
+replace red-green/door => ../door
 
 require red-green/door v0.0.0-00010101000000-000000000000
 

+ 0 - 0
go.sum → yt/go.sum


+ 0 - 0
yt.go → yt/yt.go


+ 24 - 0
yt2000-1.log → yt/yt2000-1.log

@@ -210,3 +210,27 @@
 2022/07/27 11:22:55 input_linux.go:13: ~Reader2
 2022/07/27 11:22:55 write_linux.go:59: closeChannel
 2022/07/27 11:22:55 write_linux.go:65: ~Writer
+2022/07/27 11:30:30 door.go:289: Loading dropfile door32.sys
+2022/07/27 11:30:30 door.go:290: BBS Fake Door32 BBS, User Bugz Laundry / Handle Bugz / File 4
+2022/07/27 11:30:30 write_linux.go:14: Writer
+2022/07/27 11:30:30 write_linux.go:59: closeChannel
+2022/07/27 11:30:30 write_linux.go:65: ~Writer
+2022/07/27 11:30:30 input_linux.go:30: Reader ERR: 0x16
+2022/07/27 11:30:30 input_linux.go:13: ~Reader2
+2022/07/27 11:30:30 door.go:211: DETECT: Nothing received.
+2022/07/27 11:30:30 ytopen.go:79: Call after door.Init() so Unicode/CP437 has been set.
+2022/07/27 12:08:08 door.go:289: Loading dropfile ../door32.sys
+2022/07/27 12:08:08 door.go:290: BBS Fake Door32 BBS, User Bugz Laundry / Handle Bugz / File 4
+2022/07/27 12:08:08 write_linux.go:14: Writer
+2022/07/27 12:08:08 door.go:209: DETECT: ^[[1;1R^[[2;3R^[[24;80R
+2022/07/27 12:08:08 door.go:254: Unicode true Screen: 80 X 24
+2022/07/27 12:08:40 door.go:289: Loading dropfile ../door32.sys
+2022/07/27 12:08:40 door.go:290: BBS Fake Door32 BBS, User Bugz Laundry / Handle Bugz / File 4
+2022/07/27 12:08:40 write_linux.go:14: Writer
+2022/07/27 12:08:40 door.go:209: DETECT: ^[[1;1R^[[2;3R^[[41;190R
+2022/07/27 12:08:40 door.go:254: Unicode true Screen: 190 X 41
+2022/07/27 12:09:27 door.go:289: Loading dropfile ../door32.sys
+2022/07/27 12:09:27 door.go:290: BBS Fake Door32 BBS, User Bugz Laundry / Handle Bugz / File 4
+2022/07/27 12:09:27 write_linux.go:14: Writer
+2022/07/27 12:09:27 door.go:209: DETECT: ÿýÿýÿü^[[1;3R^[[2;4R^[[24;80R
+2022/07/27 12:09:27 door.go:254: Unicode false Screen: 80 X 24

+ 0 - 0
ytdata.go → yt/ytdata.go


+ 0 - 0
ytname.dat → yt/ytname.dat


+ 0 - 0
ytnews.dat → yt/ytnews.dat


+ 0 - 0
ytopen.ans → yt/ytopen.ans


+ 0 - 0
ytopen.go → yt/ytopen.go


+ 0 - 0
ytrmsg.dat → yt/ytrmsg.dat


+ 0 - 0
ytscore.asc → yt/ytscore.asc