From 6d15f303b7378d5a129d6dde00f6a70f509d5427 Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 14 May 2024 09:58:09 +0200 Subject: [PATCH] Fix extra newlines being appended by populateChat() on TLS based servers For some reason, writing to a conn variable on a TLS connection appends newlines by default, so new users will have their chat box populated if the server is using --history/-r with messages that have unnecessary newlines --- cmd/serverFunc.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 75c569b..44857a8 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -132,10 +132,18 @@ func populateChat(conn net.Conn) { } defer file.Close() scanner := bufio.NewScanner(file) - for scanner.Scan() { - conn.Write([]byte(fmt.Sprintln(scanner.Text()))) + // For WHATEVER reason, writing to a TLS-based conn here appends newlines by default, + // so we have to split it off here to avoid ending up with chat logs full of + // unnecessary newlines + if servInsecure == true { + for scanner.Scan() { + conn.Write([]byte(fmt.Sprintln(scanner.Text()))) + } + } else { + for scanner.Scan() { + conn.Write([]byte(fmt.Sprint(scanner.Text()))) + } } - } func getPasswd(conn net.Conn) error {