mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-27 19:12:07 +02:00
Store the clients that are connected to a telnet shell in the connected viewers stats
This commit is contained in:
@ -14,6 +14,7 @@ var (
|
||||
// TODO Config should not be exported
|
||||
Cfg *Options
|
||||
currentMessage map[string]*string
|
||||
clientCount map[string]int
|
||||
)
|
||||
|
||||
// Options holds telnet package configuration
|
||||
@ -34,6 +35,7 @@ func Serve(config *Options) {
|
||||
}
|
||||
|
||||
currentMessage = make(map[string]*string)
|
||||
clientCount = make(map[string]int)
|
||||
|
||||
listener, err := net.Listen("tcp", Cfg.ListenAddress)
|
||||
if err != nil {
|
||||
@ -94,15 +96,19 @@ func Serve(config *Options) {
|
||||
}
|
||||
}
|
||||
|
||||
clientCount[streamID]++
|
||||
|
||||
for {
|
||||
n, err := s.Write([]byte(*currentMessage[streamID]))
|
||||
if err != nil {
|
||||
log.Printf("Error while sending TCP data: %s", err)
|
||||
_ = s.Close()
|
||||
clientCount[streamID]--
|
||||
break
|
||||
}
|
||||
if n == 0 {
|
||||
_ = s.Close()
|
||||
clientCount[streamID]--
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Duration(Cfg.Delay) * time.Millisecond)
|
||||
@ -114,6 +120,14 @@ func Serve(config *Options) {
|
||||
log.Println("Telnet server initialized")
|
||||
}
|
||||
|
||||
// GetNumberConnectedSessions returns the numbers of clients that are viewing the stream through a telnet shell
|
||||
func GetNumberConnectedSessions(streamID string) int {
|
||||
if !Cfg.Enabled {
|
||||
return 0
|
||||
}
|
||||
return clientCount[streamID]
|
||||
}
|
||||
|
||||
func asciiChar(pixel byte) string {
|
||||
asciiChars := []string{"@", "#", "$", "%", "?", "*", "+", ";", ":", ",", ".", " "}
|
||||
return asciiChars[(255-pixel)/22]
|
||||
|
Reference in New Issue
Block a user