From 1f83105c8ca68400222d255375f7d89227b5ddc5 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 15 Nov 2024 20:41:34 +0700 Subject: [PATCH] up --- TCPClient.go | 26 +++++++++++--------------- TCPServer.go | 2 +- config.yml | 2 +- flexradio.go | 32 ++++++++++++++++---------------- log.go | 28 ++++++++++++++-------------- 5 files changed, 43 insertions(+), 47 deletions(-) diff --git a/TCPClient.go b/TCPClient.go index 923a9b7..ef52697 100644 --- a/TCPClient.go +++ b/TCPClient.go @@ -132,36 +132,32 @@ func (c *TCPClient) ReadLine() { for { message, err := c.Reader.ReadString('\n') + message, _ = strings.CutSuffix(message, "\n") + message, _ = strings.CutSuffix(message, "\r") if err != nil { Log.Errorf("Error reading message: %s", err) continue } - Log.Debugf("Received Message: %s", message) - - if strings.Contains(message, Cfg.Cluster.LoginPrompt+"\r\n") || strings.Contains(message, Cfg.Cluster.LoginPrompt+" \r\n") { + if strings.Contains(message, Cfg.Cluster.LoginPrompt) { Log.Debug("Found login prompt...sending callsign") c.Write([]byte(c.Login + "\r\n")) - time.Sleep(time.Second * 2) c.SetFilters() - time.Sleep(time.Second * 1) if Cfg.Cluster.Command != "" { c.WriteString(Cfg.Cluster.Command) } Log.Info("Start receiving spots") + } else if strings.Contains(message, "Error reading from server: read tcp") { + Log.Error("Disconnected from Telnet Server, reconnecting") + c.Close() + c.StartClient() + } else { + ProcessTelnetSpot(spotRe, message, c.SpotChanToFlex, c.SpotChanToHTTPServer, c.Countries) } - ProcessTelnetSpot(spotRe, message, c.SpotChanToFlex, c.SpotChanToHTTPServer, c.Countries) - // Send the spot message to TCP server - if len(c.TCPServer.Clients) > 0 { - if count == 0 { - // wait 5 seconds before sending messages to allow the client to connect - time.Sleep(time.Second * 5) - count++ - } - c.MsgChan <- message - } + c.MsgChan <- message + } } diff --git a/TCPServer.go b/TCPServer.go index ca0911e..dd6b2e3 100644 --- a/TCPServer.go +++ b/TCPServer.go @@ -121,7 +121,7 @@ func (s *TCPServer) broadcastMessage(message string) { s.Mutex.Lock() defer s.Mutex.Unlock() for client := range s.Clients { - _, err := client.Write([]byte(message)) + _, err := client.Write([]byte(message + "\r\n")) if err != nil { fmt.Println("Error while sending message to clients:", client.RemoteAddr()) } diff --git a/config.yml b/config.yml index 9055079..f880bc1 100644 --- a/config.yml +++ b/config.yml @@ -1,7 +1,7 @@ general: delete_log_file_at_start: true log_to_file: true - log_level: DEBUG # INFO or DEBUG or WARN + log_level: INFO # INFO or DEBUG or WARN httpserver: true # not in use for now telnetserver: true # not in use for now flexradiospot: true # not in use for now diff --git a/flexradio.go b/flexradio.go index a6f3c0f..4d83598 100644 --- a/flexradio.go +++ b/flexradio.go @@ -158,8 +158,8 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) { UTCTime: spot.Time, LifeTime: Cfg.Flex.SpotLife, Comment: spot.Comment, - Color: "#eaeaea", - BackgroundColor: "#000000", + Color: "#ffeaeaea", + BackgroundColor: "#ff000000", Priority: "5", NewDXCC: spot.NewDXCC, NewBand: spot.NewBand, @@ -171,38 +171,38 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) { // If new DXCC if spot.NewDXCC { - flexSpot.Color = "#3bf908" + flexSpot.Color = "#ff3bf908" flexSpot.Priority = "1" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" flexSpot.Comment = flexSpot.Comment + " [New DXCC]" } else if spot.DX == Cfg.SQLite.Callsign { - flexSpot.Color = "#ff0000" + flexSpot.Color = "#ffff0000" flexSpot.Priority = "1" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" } else if spot.CallsignWorked { - flexSpot.Color = "#000000" - flexSpot.BackgroundColor = "#00c0c0" + flexSpot.Color = "#ff000000" + flexSpot.BackgroundColor = "#ff00c0c0" flexSpot.Priority = "5" flexSpot.Comment = flexSpot.Comment + " [Worked]" } else if spot.NewMode && spot.NewBand { - flexSpot.Color = "#c603fc" + flexSpot.Color = "#ffc603fc" flexSpot.Priority = "1" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" flexSpot.Comment = flexSpot.Comment + " [New Band & Mode]" } else if spot.NewMode && !spot.NewBand { - flexSpot.Color = "#f9a908" + flexSpot.Color = "#fff9a908" flexSpot.Priority = "2" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" flexSpot.Comment = flexSpot.Comment + " [New Mode]" } else if spot.NewBand && !spot.NewMode { - flexSpot.Color = "#f9f508" + flexSpot.Color = "#fff9f508" flexSpot.Priority = "3" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" flexSpot.Comment = flexSpot.Comment + " [New Band]" } else if !spot.NewBand && !spot.NewMode && !spot.NewDXCC && !spot.CallsignWorked { - flexSpot.Color = "#eaeaea" + flexSpot.Color = "#ffeaeaea" flexSpot.Priority = "5" - flexSpot.BackgroundColor = "#000000" + flexSpot.BackgroundColor = "#ff000000" } flexSpot.Comment = strings.ReplaceAll(flexSpot.Comment, " ", "\u00A0") diff --git a/log.go b/log.go index 86f4ff6..17a95ff 100644 --- a/log.go +++ b/log.go @@ -53,20 +53,20 @@ func NewLog() *log.Logger { } // Info ... -func Info(format string, v ...interface{}) { - log.Infof(format, v...) -} +// func Info(format string, v ...interface{}) { +// log.Infof(format, v...) +// } -// Warn ... -func Warn(format string, v ...interface{}) { - log.Warnf(format, v...) -} +// // Warn ... +// func Warn(format string, v ...interface{}) { +// log.Warnf(format, v...) +// } -// Error ... -func Error(format string, v ...interface{}) { - log.Errorf(format, v...) -} +// // Error ... +// func Error(format string, v ...interface{}) { +// log.Errorf(format, v...) +// } -func Debug(format string, v ...interface{}) { - log.Debugf(format, v...) -} +// func Debug(format string, v ...interface{}) { +// log.Debugf(format, v...) +// }