|
@@ -22,7 +22,9 @@ import (
|
|
|
"bufio"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"syscall"
|
|
@@ -208,10 +210,10 @@ func (d *Door) detect() {
|
|
|
r, err := syscall.Read(d.READFD, buffer)
|
|
|
results = string(buffer[:r])
|
|
|
output := strings.Replace(results, "\x1b", "^[", -1)
|
|
|
- fmt.Println("DETECT:", r, err, output)
|
|
|
+ log.Println("DETECT:", r, err, output)
|
|
|
} else {
|
|
|
// local telnet echos the reply :()
|
|
|
- fmt.Println("DETECT: Nothing received.")
|
|
|
+ log.Println("DETECT: Nothing received.")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -249,7 +251,7 @@ func (d *Door) detect() {
|
|
|
width := results[:pos]
|
|
|
|
|
|
Width, err = strconv.Atoi(width)
|
|
|
- fmt.Printf("Width: %s, %d, %v\n", results, Width, err)
|
|
|
+ log.Printf("Width: %s, %d, %v\n", results, Width, err)
|
|
|
}
|
|
|
} else {
|
|
|
Height = 0
|
|
@@ -257,26 +259,39 @@ func (d *Door) detect() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- fmt.Printf("Unicode %v Screen: %d X %d\n", Unicode, Width, Height)
|
|
|
+ log.Printf("Unicode %v Screen: %d X %d\n", Unicode, Width, Height)
|
|
|
}
|
|
|
|
|
|
// 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()
|
|
|
if len(dropfile) == 0 {
|
|
|
flag.PrintDefaults()
|
|
|
os.Exit(2)
|
|
|
}
|
|
|
- fmt.Printf("Loading: %s\n", dropfile)
|
|
|
|
|
|
d.ReadDropfile(dropfile)
|
|
|
+ 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 {
|
|
|
+ panic(fmt.Sprintf("Error creating log file %s: %v", logfilename, err))
|
|
|
+ }
|
|
|
+
|
|
|
+ log.SetOutput(logf)
|
|
|
+ //= log.New(logf, fmt.Sprintf("%s-%d", doorname, d.Config.Node), log.Ldate|log.Ltime|log.Lshortfile)
|
|
|
+ log.Printf("Loading dropfile %s\n", 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)
|
|
|
+ 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)
|
|
|
d.detect()
|
|
|
if Unicode {
|
|
|
BOXES = BOXES_UNICODE
|
|
@@ -295,12 +310,12 @@ func (d *Door) Write(output string) {
|
|
|
buffer := []byte(output)
|
|
|
n, err := syscall.Write(d.WRITEFD, buffer)
|
|
|
if err != nil {
|
|
|
- fmt.Println("Write error/HANGUP?", n)
|
|
|
+ log.Println("Write error/HANGUP?", n)
|
|
|
d.Disconnected = true
|
|
|
}
|
|
|
// No, this isn't it. The # of bytes in buffer == bytes written.
|
|
|
if n != len(buffer) {
|
|
|
- fmt.Printf("Write fail: %d != %d\n", len(buffer), n)
|
|
|
+ log.Printf("Write fail: %d != %d\n", len(buffer), n)
|
|
|
}
|
|
|
}
|
|
|
|