|
@@ -30,8 +30,6 @@ g00r00 Line 7 : User's handle/alias
|
|
|
*/
|
|
|
|
|
|
var Reset string = Color(0)
|
|
|
-var READFD int
|
|
|
-var WRITEFD int
|
|
|
|
|
|
type DropfileConfig struct {
|
|
|
comm_type int
|
|
@@ -51,8 +49,15 @@ type Door struct {
|
|
|
config DropfileConfig
|
|
|
READFD int
|
|
|
WRITEFD int
|
|
|
+ TimeOut time.Time // Fixed point in time, when time expires
|
|
|
}
|
|
|
|
|
|
+// Return the amount of time left as time.Duration
|
|
|
+func (d *Door) TimeLeft() time.Duration {
|
|
|
+ return d.TimeOut.Sub(time.Now())
|
|
|
+}
|
|
|
+
|
|
|
+// Read the BBS door file. We only support door32.sys.
|
|
|
func (d *Door) ReadDropfile(filename string) {
|
|
|
file, err := os.Open(filename)
|
|
|
if err != nil {
|
|
@@ -71,7 +76,6 @@ func (d *Door) ReadDropfile(filename string) {
|
|
|
for scanner.Scan() {
|
|
|
line := scanner.Text()
|
|
|
lines = append(lines, line)
|
|
|
- // fmt.Printf("[%s]\n", line)
|
|
|
}
|
|
|
|
|
|
d.config.comm_type, err = strconv.Atoi(lines[0])
|
|
@@ -87,11 +91,10 @@ func (d *Door) ReadDropfile(filename string) {
|
|
|
d.config.node_number, err = strconv.Atoi(lines[10])
|
|
|
|
|
|
d.READFD = d.config.comm_handle
|
|
|
- //if d.READFD == 0 {
|
|
|
- // d.WRITEFD = 1
|
|
|
- //} else {
|
|
|
d.WRITEFD = d.config.comm_handle
|
|
|
- //}
|
|
|
+
|
|
|
+ // Calculate the time when time expires.
|
|
|
+ d.TimeOut = time.Now().Add(time.Duration(d.config.time_left) * time.Minute)
|
|
|
}
|
|
|
|
|
|
func (d *Door) HasKey() bool {
|
|
@@ -109,12 +112,14 @@ func (d *Door) HasKey() bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-var Unicode bool
|
|
|
-var CP437 bool
|
|
|
-var Full_CP437 bool
|
|
|
-var Height int
|
|
|
-var Width int
|
|
|
+var Unicode bool // Unicode support detected
|
|
|
+var CP437 bool // CP437 support detected
|
|
|
+var Full_CP437 bool // Full CP437 support detected (handles control codes properly)
|
|
|
+var Height int // Screen height detected
|
|
|
+var Width int // Screen width detected
|
|
|
|
|
|
+// Detect client terminal capabilities, Unicode, CP437, Full_CP437,
|
|
|
+// screen Height and Width.
|
|
|
func (d *Door) detect() {
|
|
|
// if d.config.comm_handle == 0 {
|
|
|
// d.Write("\377\375\042\377\373\001") // fix telnet client
|
|
@@ -188,6 +193,8 @@ func (d *Door) detect() {
|
|
|
fmt.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() {
|
|
|
var dropfile string
|
|
|
|
|
@@ -201,10 +208,11 @@ func (d *Door) Init() {
|
|
|
|
|
|
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.READFD)
|
|
|
+ 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)
|
|
|
d.detect()
|
|
|
}
|
|
|
|
|
|
+// Write string to client.
|
|
|
func (d *Door) Write(output string) {
|
|
|
buffer := []byte(output)
|
|
|
n, err := syscall.Write(d.WRITEFD, buffer)
|