Security Update #6

Merged
raul merged 25 commits from testing into main 2024-05-17 08:00:14 +02:00
1 changed files with 23 additions and 5 deletions
Showing only changes of commit a615cb9194 - Show all commits

View File

@ -7,13 +7,15 @@ package cmd
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/jroimartin/gocui"
"github.com/nsf/termbox-go"
"log" "log"
"net" "net"
"os" "os"
"runtime"
"strings" "strings"
"time" "time"
"github.com/jroimartin/gocui"
"github.com/nsf/termbox-go"
) )
type Message struct { type Message struct {
@ -92,13 +94,29 @@ func receiveMessage(conn net.Conn) (s string, err error) {
return finalMessage, nil return finalMessage, nil
} }
func sendName(conn net.Conn) { func scanLine() (line string, err error) {
message, err := bufio.NewReader(os.Stdin).ReadString('\n') switch runtime.GOOS {
case "linux":
message, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return "", err
}
line = message
case "windows":
message, err := bufio.NewReader(os.Stdin).ReadString('\r')
if err != nil {
return "", err
}
line = message
}
return line, nil
}
func sendName(conn net.Conn) {
message, err := scanLine()
if err != nil { if err != nil {
log.Fatalf("Error occurred sending message to server: %v\n", err) log.Fatalf("Error occurred sending message to server: %v\n", err)
} }
Profile.Username = strings.TrimRight(message, "\n") Profile.Username = strings.TrimRight(message, "\n")
if _, err := conn.Write([]byte(message)); err != nil { if _, err := conn.Write([]byte(message)); err != nil {