This commit is contained in:
Gregory Salaun 2024-11-30 21:49:00 +07:00
parent eaa0c62892
commit 71c57cb2a1
7 changed files with 40 additions and 31 deletions

View File

@ -4,7 +4,7 @@ WORKDIR /app
COPY go.mod go.sum ./
COPY clublog.go config.go config.yml database.go flexradio.go HTTPServer.go spot.go main.go TCPClient.go TCPServer.go utils.go log.go ./
COPY config.go config.yml database.go flexradio.go spot.go main.go TCPClient.go TCPServer.go utils.go log.go xml.go ./
COPY templates/* .
RUN go build -o bin main.go

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
build:
go build .

View File

@ -135,7 +135,8 @@ func (c *TCPClient) ReadLine() {
message, _ = strings.CutSuffix(message, "\r")
if err != nil {
Log.Errorf("Error reading message: %s", err)
continue
c.Conn.Close()
c.StartClient()
}
if strings.Contains(message, Cfg.Cluster.LoginPrompt) {

View File

@ -8,11 +8,11 @@ sqlite:
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\Vietnam.SQLite' # SQLite Db oath of Log4OM
callsign: XV9Q # Log4OM Callsign used to check if you get spotted by someone
cluster:
server: dxc.k0xm.net
server: cluster.f4bpo.com # dxc.k0xm.net
port: 7300
login: xv9q
skimmer: true
ft8: true
ft8: false
ft4: false
command: #SET/NOFILTER
login_prompt: "Please enter your call:"

26
main.go
View File

@ -4,9 +4,7 @@ import (
"flag"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
)
func ParseFlags() (string, error) {
@ -65,32 +63,10 @@ func main() {
FlexClient := NewFlexClient(*fRepo, TCPServer, TCPClient.SpotChanToFlex)
// HTTPServer := NewHTTPServer(*cRepo, *fRepo, TCPServer, TCPClient.SpotChanToHTTPServer)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
go FlexClient.StartFlexClient()
go TCPClient.StartClient()
go TCPServer.StartServer()
// Gracely closing all connextions if signal is received
for sig := range sigCh {
log.Infof("received signal: %v, shutting down all connections.", sig)
TCPClient.Close()
TCPServer.Conn.Close()
FlexClient.Conn.Close()
if err := fRepo.db.Close(); err != nil {
log.Error("failed to close the database connection properly")
os.Exit(1)
}
if err := cRepo.db.Close(); err != nil {
log.Error("failed to close Log4OM database connection properly")
os.Exit(1)
}
os.Exit(0)
}
CheckSignal(TCPClient, TCPServer, FlexClient, fRepo, cRepo)
}

View File

@ -96,8 +96,8 @@ func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChanToFlex chan Te
SpotChanToFlex <- spot
if spot.NewDXCC {
Log.Debugf("(** New DXCC **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - Command: %v, FlexSpot: %v",
spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.CommandNumber, spot.FlexSpotNumber)
Log.Debugf("(** New DXCC **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s",
spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC)
}
if !spot.NewDXCC && spot.NewBand && spot.NewMode {

View File

@ -2,7 +2,10 @@ package main
import (
"log"
"os"
"os/signal"
"strconv"
"syscall"
)
func FreqMhztoHz(freq string) string {
@ -26,3 +29,30 @@ func FreqHztoMhz(freq string) string {
return strconv.FormatFloat(frequency, 'f', 6, 64)
}
func CheckSignal(TCPClient *TCPClient, TCPServer *TCPServer, FlexClient *FlexClient, fRepo *FlexDXClusterRepository, cRepo *Log4OMContactsRepository) {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
// Gracely closing all connextions if signal is received
for sig := range sigCh {
Log.Infof("received signal: %v, shutting down all connections.", sig)
TCPClient.Close()
TCPServer.Conn.Close()
FlexClient.Conn.Close()
if err := fRepo.db.Close(); err != nil {
Log.Error("failed to close the database connection properly")
os.Exit(1)
}
if err := cRepo.db.Close(); err != nil {
Log.Error("failed to close Log4OM database connection properly")
os.Exit(1)
}
os.Exit(0)
}
}