This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
/
main.go
90 lines (82 loc) · 2.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"git.fractalqb.de/fractalqb/c4hgol"
"git.fractalqb.de/fractalqb/qblog"
"github.com/fractalqb/change"
"github.com/CmdrVasquess/stated"
"github.com/CmdrVasquess/watched/edeh/edehnet"
)
var (
recv edehnet.Receiver
edstate = stated.NewEDState(&stated.Config{
CmdrFile: stated.CmdrFile{Dir: "."}.Filename,
})
log = qblog.New("netstated")
logCfg = c4hgol.NewLogGroup(log, "",
edehnet.LogCfg,
stated.LogCfg,
)
changes = make(chan stated.ChangeEvent)
)
func printChanges() {
for chg := range changes {
fmt.Printf("%s: %s event changed:\n",
chg.Event.Timestamp(),
chg.Event.Event())
for c := change.Flags(1); c < stated.ChgEND; c = c << 1 {
if chg.Change&c == 0 {
continue
}
switch c {
case stated.ChgGame:
fmt.Printf(" - game : %s beta: %t %s (%s-%s)\n",
edstate.EDVersion,
edstate.Beta,
edstate.Language,
edstate.L10n.Lang,
edstate.L10n.Region,
)
case stated.ChgCommander:
fmt.Print(" - commander: ")
json.NewEncoder(os.Stdout).Encode(edstate.Cmdr)
case stated.ChgSystem:
fmt.Printf(" - system %T: ", edstate.Loc.Location)
json.NewEncoder(os.Stdout).Encode(edstate.Loc.Location)
case stated.ChgLocation:
fmt.Printf(" - location %T: ", edstate.Loc.Location)
json.NewEncoder(os.Stdout).Encode(edstate.Loc.Location)
default:
fmt.Printf(" - chg#%d\n", c)
}
}
}
}
func main() {
fLog := flag.String("log", "", c4hgol.FlagDoc())
fLsLog := flag.Bool("log-list", false, "List configurable loggers")
flag.StringVar(&recv.Listen, "l", "", "TCP listen address")
flag.Parse()
c4hgol.Configure(logCfg, *fLog, true)
if *fLsLog {
wr := flag.CommandLine.Output()
fmt.Fprintln(wr, "Loggers:")
c4hgol.Visit(logCfg, func(_ c4hgol.LogConfig, p string) error {
fmt.Fprintf(wr, " - %s", p)
return nil
})
}
edstate.Notify = []chan<- stated.ChangeEvent{changes}
go printChanges()
log.Infof("StatED receiving edeh-net events on %s…", recv.Listen)
for {
err := recv.Run(edstate)
if err != nil {
log.Errore(err)
break
}
}
}