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
This commit is contained in:
raul 2024-05-14 09:58:09 +02:00
parent 872523700b
commit 6d15f303b7
1 changed files with 11 additions and 3 deletions

View File

@ -132,10 +132,18 @@ func populateChat(conn net.Conn) {
} }
defer file.Close() defer file.Close()
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
// 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() { for scanner.Scan() {
conn.Write([]byte(fmt.Sprintln(scanner.Text()))) conn.Write([]byte(fmt.Sprintln(scanner.Text())))
} }
} else {
for scanner.Scan() {
conn.Write([]byte(fmt.Sprint(scanner.Text())))
}
}
} }
func getPasswd(conn net.Conn) error { func getPasswd(conn net.Conn) error {