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:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go-ts/pkg/ts3client"
|
||||
@@ -64,6 +65,7 @@ type Model struct {
|
||||
selectedIdx int
|
||||
chatMessages []ChatMessage
|
||||
logMessages []string // Debug logs shown in chat panel
|
||||
logFullscreen bool // Toggle fullscreen log view
|
||||
inputText string
|
||||
inputActive bool
|
||||
|
||||
@@ -226,11 +228,18 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case errorMsg:
|
||||
m.lastError = msg.err
|
||||
return m, nil
|
||||
|
||||
case logMsg:
|
||||
// External log message
|
||||
m.addLog("%s", string(msg))
|
||||
return m, nil
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
type logMsg string
|
||||
|
||||
func (m *Model) updateChannelList(channels []*ts3client.Channel) {
|
||||
// Sort channels by ID for stable ordering
|
||||
sortedChannels := make([]*ts3client.Channel, len(channels))
|
||||
@@ -259,6 +268,11 @@ func (m *Model) updateChannelList(channels []*ts3client.Channel) {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort users by ID for stable ordering
|
||||
sort.Slice(node.Users, func(i, j int) bool {
|
||||
return node.Users[i].ID < node.Users[j].ID
|
||||
})
|
||||
|
||||
m.channels = append(m.channels, node)
|
||||
}
|
||||
}
|
||||
@@ -288,8 +302,17 @@ func (m *Model) handleKeyPress(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m.handleChannelKeys(msg)
|
||||
case FocusInput:
|
||||
return m.handleInputKeys(msg)
|
||||
case FocusChat:
|
||||
return m.handleChatKeys(msg)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *Model) handleChatKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "f":
|
||||
m.logFullscreen = !m.logFullscreen
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -307,7 +330,11 @@ func (m *Model) handleChannelKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
// Join selected channel
|
||||
if m.selectedIdx < len(m.channels) && m.client != nil {
|
||||
ch := m.channels[m.selectedIdx]
|
||||
m.client.JoinChannel(ch.ID)
|
||||
m.addLog("Attempting to join channel: %s (ID=%d)", ch.Name, ch.ID)
|
||||
err := m.client.JoinChannel(ch.ID)
|
||||
if err != nil {
|
||||
m.addLog("Error joining channel: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
@@ -342,6 +369,18 @@ func (m *Model) View() string {
|
||||
return "Loading..."
|
||||
}
|
||||
|
||||
// Fullscreen Log Mode
|
||||
if m.logFullscreen {
|
||||
style := lipgloss.NewStyle().
|
||||
Border(lipgloss.RoundedBorder()).
|
||||
BorderForeground(lipgloss.Color("212")). // Active color
|
||||
Padding(0, 1).
|
||||
Width(m.width - 2).
|
||||
Height(m.height - 2)
|
||||
|
||||
return style.Render(m.renderChat())
|
||||
}
|
||||
|
||||
// Styles
|
||||
headerStyle := lipgloss.NewStyle().
|
||||
Bold(true).
|
||||
@@ -463,12 +502,30 @@ func (m *Model) renderChat() string {
|
||||
if maxLines < 5 {
|
||||
maxLines = 5
|
||||
}
|
||||
|
||||
start := 0
|
||||
if len(m.logMessages) > maxLines {
|
||||
start = len(m.logMessages) - maxLines
|
||||
}
|
||||
|
||||
panelWidth := (m.width / 2) - 4
|
||||
if m.logFullscreen {
|
||||
panelWidth = m.width - 6
|
||||
}
|
||||
if panelWidth < 10 {
|
||||
panelWidth = 10
|
||||
}
|
||||
|
||||
for _, msg := range m.logMessages[start:] {
|
||||
lines = append(lines, lipgloss.NewStyle().Faint(true).Render(msg))
|
||||
// Truncate if too long to prevent wrapping breaking the layout
|
||||
displayMsg := msg
|
||||
if len(displayMsg) > panelWidth {
|
||||
displayMsg = displayMsg[:panelWidth-3] + "..."
|
||||
}
|
||||
// Replace newlines just in case
|
||||
displayMsg = strings.ReplaceAll(displayMsg, "\n", " ")
|
||||
|
||||
lines = append(lines, lipgloss.NewStyle().Faint(true).Render(displayMsg))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user