Implement Poke functionality, refine talking status and add local log events
This commit is contained in:
@@ -134,26 +134,41 @@ func (c *Client) Connect(address string) error {
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
// Recovery from panics in the main loop
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Printf("PANIC in Client loop: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-c.done:
|
||||
log.Println("Client loop stopped")
|
||||
return
|
||||
case pkt := <-pktChan:
|
||||
if pkt == nil {
|
||||
// Channel closed
|
||||
return
|
||||
}
|
||||
if err := c.handlePacket(pkt); err != nil {
|
||||
log.Printf("Error handling packet: %v", err)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if !c.Connected {
|
||||
return // Don't send pings if not connected yet
|
||||
}
|
||||
// Send KeepAlive Ping (Encrypted, No NewProtocol)
|
||||
if err := c.sendPing(); err != nil {
|
||||
log.Printf("Error sending Ping: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
// Check if we should exit after the inner function
|
||||
select {
|
||||
case <-c.done:
|
||||
log.Println("Client loop stopped")
|
||||
return nil
|
||||
case pkt := <-pktChan:
|
||||
if pkt == nil {
|
||||
// Channel closed
|
||||
return nil
|
||||
}
|
||||
if err := c.handlePacket(pkt); err != nil {
|
||||
log.Printf("Error handling packet: %v", err)
|
||||
}
|
||||
case <-ticker.C:
|
||||
if !c.Connected {
|
||||
continue // Don't send pings if not connected yet
|
||||
}
|
||||
// Send KeepAlive Ping (Encrypted, No NewProtocol)
|
||||
if err := c.sendPing(); err != nil {
|
||||
log.Printf("Error sending Ping: %v", err)
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,8 +226,8 @@ func (c *Client) processCommand(data []byte, pkt *protocol.Packet) error {
|
||||
cmdStr := string(data)
|
||||
|
||||
// Debug: Log packet flags and raw command preview (sanitized)
|
||||
log.Printf("Debug Packet: Compressed=%v, Fragmented=%v, RawLen=%d, Preview=%q",
|
||||
pkt.Header.FlagCompressed(), pkt.Header.FlagFragmented(), len(data),
|
||||
log.Printf("Debug Packet: PID=%d, Compressed=%v, Fragmented=%v, RawLen=%d, Preview=%q",
|
||||
pkt.Header.PacketID, pkt.Header.FlagCompressed(), pkt.Header.FlagFragmented(), len(data),
|
||||
func() string {
|
||||
preview := cmdStr
|
||||
if len(preview) > 100 {
|
||||
@@ -544,6 +544,28 @@ func (c *Client) processCommand(data []byte, pkt *protocol.Packet) error {
|
||||
"message": msg,
|
||||
})
|
||||
|
||||
case "notifyclientpoke":
|
||||
msg := ""
|
||||
invoker := "Unknown"
|
||||
var invokerID uint16
|
||||
if m, ok := args["msg"]; ok {
|
||||
msg = protocol.Unescape(m)
|
||||
}
|
||||
if name, ok := args["invokername"]; ok {
|
||||
invoker = protocol.Unescape(name)
|
||||
}
|
||||
if iid, ok := args["invokerid"]; ok {
|
||||
var id uint64
|
||||
fmt.Sscanf(iid, "%d", &id)
|
||||
invokerID = uint16(id)
|
||||
}
|
||||
log.Printf("[Poke] %s: %s", invoker, msg)
|
||||
c.emitEvent("client_poke", map[string]any{
|
||||
"senderID": invokerID,
|
||||
"senderName": invoker,
|
||||
"message": msg,
|
||||
})
|
||||
|
||||
case "notifyservergrouplist", "notifychannelgrouplist", "notifyclientneededpermissions":
|
||||
// Ignore verbose noisy setup commands
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user