Skip to content

Commit 3524708

Browse files
committed
Move controller sign-on time to ControlClient.SessionStats
(And renamed ControllerStats->SessionStats there.)
1 parent 8dedae8 commit 3524708

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ func main() {
258258
if ctrl, ok := controlClient.State.Controllers[id]; ok {
259259
id += " (" + ctrl.Position + ")"
260260
}
261-
stats := controlClient.ControllerStats
261+
stats := controlClient.SessionStats
262262
SetDiscordStatus(DiscordStatus{
263-
TotalDepartures: stats.Departures + stats.IntraFacility/2,
264-
TotalArrivals: stats.Arrivals + stats.IntraFacility/2,
263+
TotalDepartures: stats.Departures + stats.IntraFacility,
264+
TotalArrivals: stats.Arrivals + stats.IntraFacility,
265265
Position: id,
266266
Start: mgr.ConnectionStartTime(),
267267
}, config, lg)

pkg/aviation/aviation.go

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ type Controller struct {
186186
ERAMFacility bool `json:"eram_facility"` // To weed out N56 and N4P being the same fac
187187
Facility string `json:"facility"` // So we can get the STARS facility from a controller
188188
DefaultAirport string `json:"default_airport"` // only required if CRDA is a thing
189-
SignOnTime time.Time
190189
}
191190

192191
func (c Controller) Id() string {

pkg/panes/stars/lists.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ func (sp *STARSPane) drawSignOnList(ctx *panes.Context, pw [2]float32, style ren
870870

871871
var text strings.Builder
872872
if ctrl := ctx.ControlClient.Controllers[ctx.ControlClient.PrimaryTCP]; ctrl != nil {
873-
text.WriteString(ctx.ControlClient.PrimaryTCP + " " + ctrl.SignOnTime.UTC().Format("1504")) // TODO: initials
873+
signOnTime := ctx.ControlClient.SessionStats.SignOnTime
874+
text.WriteString(ctx.ControlClient.PrimaryTCP + " " + signOnTime.UTC().Format("1504")) // TODO: initials
874875
td.AddText(text.String(), pw, style)
875876
}
876877
}

pkg/server/client.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ type ControlClient struct {
2929

3030
pendingCalls []*util.PendingCall
3131

32-
ControllerStats struct {
32+
SessionStats struct {
3333
Departures int
3434
Arrivals int
3535
IntraFacility int
3636
Overflights int
37+
38+
SignOnTime time.Time
3739
}
3840

3941
// This is all read-only data that we expect other parts of the system
@@ -46,7 +48,7 @@ func (c *ControlClient) RPCClient() *util.RPCClient {
4648
}
4749

4850
func NewControlClient(ss sim.State, local bool, controllerToken string, client *util.RPCClient, lg *log.Logger) *ControlClient {
49-
return &ControlClient{
51+
cc := &ControlClient{
5052
State: ss,
5153
lg: lg,
5254
remoteSim: !local,
@@ -56,13 +58,15 @@ func NewControlClient(ss sim.State, local bool, controllerToken string, client *
5658
},
5759
lastUpdateRequest: time.Now(),
5860
}
61+
cc.SessionStats.SignOnTime = ss.SimTime
62+
return cc
5963
}
6064

6165
func (c *ControlClient) Status() string {
6266
if c == nil || c.SimDescription == "" {
6367
return "[disconnected]"
6468
} else {
65-
stats := c.ControllerStats
69+
stats := c.SessionStats
6670
deparr := fmt.Sprintf(" [ %d departures %d arrivals %d intrafacility %d overflights ]",
6771
stats.Departures, stats.Arrivals, stats.IntraFacility, stats.Overflights)
6872
return c.State.PrimaryTCP + c.SimDescription + deparr
@@ -231,13 +235,13 @@ func (c *ControlClient) updateControllerStats(callsign string, next func(any)) f
231235
return func(result any) {
232236
if ac, ok := c.State.Aircraft[callsign]; ok {
233237
if c.IsIntraFacility(ac) {
234-
c.ControllerStats.IntraFacility++
238+
c.SessionStats.IntraFacility++
235239
} else if c.IsDeparture(ac) {
236-
c.ControllerStats.Departures++
240+
c.SessionStats.Departures++
237241
} else if c.IsArrival(ac) {
238-
c.ControllerStats.Arrivals++
242+
c.SessionStats.Arrivals++
239243
} else if c.IsOverflight(ac) {
240-
c.ControllerStats.Overflights++
244+
c.SessionStats.Overflights++
241245
}
242246
}
243247
if next != nil {

pkg/sim/sim.go

-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ func (s *Sim) signOn(tcp string, instructor bool) error {
224224

225225
s.humanControllers[tcp] = s.eventStream.Subscribe()
226226
s.State.Controllers[tcp] = s.SignOnPositions[tcp]
227-
s.State.Controllers[tcp].SignOnTime = s.State.SimTime
228227
s.State.HumanControllers = append(s.State.HumanControllers, tcp)
229228

230229
if tcp == s.State.PrimaryController {

0 commit comments

Comments
 (0)