You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gomud/cmd/echo/telnet.go

45 lines
761 B
Go

package main
import (
"bufio"
"context"
"log"
"net"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
)
type TELNETParser struct {
}
type TELNETServer struct {
l net.Listener
p message.Publisher
c context.Context
}
func NewTELNETServer(c context.Context, l net.Listener, p message.Publisher) *TELNETServer {
ts := TELNETServer{
c: c,
l: l,
p: p,
}
return &ts
}
func (ts *TELNETServer) Handle(conn net.Conn) {
s := bufio.NewScanner(conn)
defer conn.Close()
for s.Scan() {
t := s.Text()
err := ts.p.Publish("telnet.raw", message.NewMessage(watermill.NewUUID(), []byte(t)))
if err != nil {
log.Fatalln("couldn't write to raw_telnet queue")
}
log.Printf("Received user input: %q\n", t)
}
}