1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 19:42:20 +00:00
ghostream/stream/telnet/telnet.go
2020-10-17 19:40:37 +02:00

42 lines
865 B
Go

// Package telnet provides some fancy tools, like an ASCII-art stream.
package telnet
import (
"log"
"net"
"gitlab.crans.org/nounous/ghostream/stream"
)
// Options holds telnet package configuration
type Options struct {
Enabled bool
ListenAddress string
}
// Serve Telnet server
func Serve(streams map[string]*stream.Stream, cfg *Options) {
if !cfg.Enabled {
// Telnet is not enabled, ignore
return
}
// Start TCP server
listener, err := net.Listen("tcp", cfg.ListenAddress)
if err != nil {
log.Fatalf("Error while listening to the address %s: %s", cfg.ListenAddress, err)
}
log.Printf("Telnet server listening on %s", cfg.ListenAddress)
// Handle each new client
for {
s, err := listener.Accept()
if err != nil {
log.Printf("Error while accepting TCP socket: %s", s)
continue
}
go handleViewer(s, streams, cfg)
}
}