Fix channel join flooding and enhance TUI features
- Implemented separate PacketID counters for Ping, Pong, and Ack (protocol compliance).
- Encrypted outgoing Pong packets after handshake.
- Fixed 'clientmove' command by omitting empty 'cpw' parameter.
- Added fullscreen log view toggle ('f' key).
- Improved logging with multi-writer and timestamps.
- Updated .gitignore to exclude binaries and logs.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
@@ -23,7 +24,7 @@ func debugLog(format string, args ...any) {
|
||||
func main() {
|
||||
serverAddr := flag.String("server", "127.0.0.1:9987", "TeamSpeak 3 Server Address")
|
||||
nickname := flag.String("nickname", "TUI-User", "Your nickname")
|
||||
debug := flag.Bool("debug", false, "Enable debug logging to tui-debug.log")
|
||||
debug := flag.Bool("debug", true, "Enable debug logging to file (default true)")
|
||||
flag.Parse()
|
||||
|
||||
// Disable log output completely to prevent TUI corruption
|
||||
@@ -32,10 +33,12 @@ func main() {
|
||||
// Enable debug file logging if requested
|
||||
if *debug {
|
||||
var err error
|
||||
debugFile, err = os.Create("tui-debug.log")
|
||||
timestamp := time.Now().Format("20060102-150405")
|
||||
filename := fmt.Sprintf("tui-%s.log", timestamp)
|
||||
debugFile, err = os.Create(filename)
|
||||
if err == nil {
|
||||
defer debugFile.Close()
|
||||
debugLog("TUI Debug started")
|
||||
debugLog("TUI Debug started at %s", timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +48,32 @@ func main() {
|
||||
// Create Bubble Tea program
|
||||
p := tea.NewProgram(m, tea.WithAltScreen())
|
||||
|
||||
// Set up log capture
|
||||
r, w, _ := os.Pipe()
|
||||
if debugFile != nil {
|
||||
log.SetOutput(io.MultiWriter(w, debugFile))
|
||||
} else {
|
||||
log.SetOutput(w)
|
||||
}
|
||||
// Make sure logs have timestamp removed (TUI adds it if needed, or we keep it)
|
||||
log.SetFlags(log.Ltime) // Just time
|
||||
|
||||
go func() {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, err := r.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if n > 0 {
|
||||
lines := string(buf[:n])
|
||||
// Split by newline and send each line
|
||||
// Simple split, might need better buffering for partial lines but OK for debug
|
||||
p.Send(logMsg(lines))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Run
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user