|
@@ -22,7 +22,9 @@ import (
|
|
|
"bufio"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"syscall"
|
|
@@ -41,34 +43,6 @@ var Height int // Screen height detected
|
|
|
var Width int // Screen width detected
|
|
|
var Inactivity int64 = 120 // Inactivity timeout
|
|
|
|
|
|
-type LIFOBuffer struct {
|
|
|
- data []int
|
|
|
- index int
|
|
|
-}
|
|
|
-
|
|
|
-func (b *LIFOBuffer) Empty() bool {
|
|
|
- return b.index == 0
|
|
|
-}
|
|
|
-
|
|
|
-func (b *LIFOBuffer) Push(value int) {
|
|
|
- if b.index+1 > len(b.data) {
|
|
|
- b.data = append(b.data, value)
|
|
|
- b.index++
|
|
|
- } else {
|
|
|
- b.data[b.index] = value
|
|
|
- b.index++
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (b *LIFOBuffer) Pop() int {
|
|
|
- if b.index == 0 {
|
|
|
- panic("Attempting to Pop from empty LIFOBuffer.")
|
|
|
- }
|
|
|
-
|
|
|
- b.index--
|
|
|
- return b.data[b.index]
|
|
|
-}
|
|
|
-
|
|
|
/*
|
|
|
door32.sys:
|
|
|
|
|
@@ -106,7 +80,7 @@ type Door struct {
|
|
|
Disconnected bool
|
|
|
TimeOut time.Time // Fixed point in time, when time expires
|
|
|
StartTime time.Time
|
|
|
- Pushback LIFOBuffer
|
|
|
+ Pushback FIFOBuffer
|
|
|
}
|
|
|
|
|
|
// Return the amount of time left as time.Duration
|
|
@@ -174,7 +148,8 @@ func (d *Door) detect() {
|
|
|
|
|
|
for {
|
|
|
r := d.getch()
|
|
|
- if r == -1 {
|
|
|
+ if r < 0 {
|
|
|
+ // Timeout or Disconnect
|
|
|
break
|
|
|
}
|
|
|
results += string(byte(r))
|
|
@@ -236,8 +211,14 @@ func (d *Door) detect() {
|
|
|
|
|
|
// Initialize door framework. Parse commandline, read dropfile,
|
|
|
// detect terminal capabilities.
|
|
|
-func (d *Door) Init() {
|
|
|
+func (d *Door) Init(doorname string) {
|
|
|
var dropfile string
|
|
|
+ d.Pushback = NewFIFOBuffer(5)
|
|
|
+
|
|
|
+ // Get path to binary, and chdir to it.
|
|
|
+ binaryPath, _ := os.Executable()
|
|
|
+ binaryPath = filepath.Dir(binaryPath)
|
|
|
+ _ = os.Chdir(binaryPath)
|
|
|
|
|
|
flag.StringVar(&dropfile, "d", "", "Path to dropfile")
|
|
|
flag.Parse()
|
|
@@ -245,13 +226,25 @@ func (d *Door) Init() {
|
|
|
flag.PrintDefaults()
|
|
|
os.Exit(2)
|
|
|
}
|
|
|
- fmt.Printf("Loading: %s\n", dropfile)
|
|
|
+ // fmt.Printf("Loading: %s\n", dropfile)
|
|
|
|
|
|
d.ReadDropfile(dropfile)
|
|
|
|
|
|
- fmt.Printf("BBS %s, User %s / Handle %s / File %d\n", d.Config.BBSID, d.Config.Real_name, d.Config.Handle, d.Config.Comm_handle)
|
|
|
- readerChannel = make(chan byte)
|
|
|
+ // doorname - node #?
|
|
|
+ logfilename := fmt.Sprintf("%s-%d.log", doorname, d.Config.Node)
|
|
|
+ logf, err := os.OpenFile(logfilename, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
|
|
+ if err != nil {
|
|
|
+ log.Panicf("Error creating log file %s: %v", logfilename, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ log.SetOutput(logf)
|
|
|
+ log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
|
|
|
|
+ log.Printf("Loading dropfile %s\n", dropfile)
|
|
|
+ log.Printf("BBS %s, User %s / Handle %s / File %d\n", d.Config.BBSID, d.Config.Real_name, d.Config.Handle, d.Config.Comm_handle)
|
|
|
+
|
|
|
+ // Init Windows Reader Channel
|
|
|
+ readerChannel = make(chan byte)
|
|
|
go Reader(syscall.Handle(d.Config.Comm_handle))
|
|
|
|
|
|
d.detect()
|