Browse Source

Added configuration to telnet connection

This should update telnet so it's raw and does not echo.
Apollo 7 months ago
parent
commit
d81ad4ea53
2 changed files with 23 additions and 0 deletions
  1. 2 0
      client.go
  2. 21 0
      utils.go

+ 2 - 0
client.go

@@ -28,6 +28,8 @@ func NewClient(server *Server, conn net.Conn) *Client {
 		Prompt:      "Login: ",
 		PromptWLine: true,
 	}
+	c.Write("\xff\xfb\x01\xff\xfb\x03\xff\xfd\x10")
+	Drain(c.conn, 3)
 	go c.reader()
 	return c
 }

+ 21 - 0
utils.go

@@ -1,3 +1,24 @@
 package main
 
+import (
+	"log"
+	"net"
+	"time"
+)
+
 type ID uint64
+
+func Drain(conn net.Conn, drain int) {
+	conn.SetReadDeadline(time.Now().Add(time.Second * time.Duration(drain)))
+	var buff []byte = make([]byte, 32)
+	var n int
+	var err error
+	n, err = conn.Read(buff)
+	if n > 0 {
+		log.Printf("Drained %d bytes [%#v].\n", n, buff[:n])
+	}
+	if err != nil {
+		log.Println("Drain:", err)
+	}
+	conn.SetReadDeadline(time.Time{})
+}