-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
race_quick.go
118 lines (91 loc) · 2.49 KB
/
race_quick.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package servermanager
import (
"net/http"
"time"
"github.com/sirupsen/logrus"
)
type QuickRaceHandler struct {
*BaseHandler
raceManager *RaceManager
}
func NewQuickRaceHandler(baseHandler *BaseHandler, raceManager *RaceManager) *QuickRaceHandler {
return &QuickRaceHandler{
BaseHandler: baseHandler,
raceManager: raceManager,
}
}
func (qrh *QuickRaceHandler) create(w http.ResponseWriter, r *http.Request) {
quickRaceData, err := qrh.raceManager.BuildRaceOpts(r)
if err != nil {
logrus.WithError(err).Errorf("couldn't build quick race")
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
qrh.viewRenderer.MustLoadTemplate(w, r, "quick-race.html", quickRaceData)
}
func (qrh *QuickRaceHandler) submit(w http.ResponseWriter, r *http.Request) {
err := qrh.raceManager.SetupQuickRace(r)
if err == ErrMustSubmitCar {
AddErrorFlash(w, r, "You must choose at least one car!")
http.Redirect(w, r, r.Referer(), http.StatusFound)
return
} else if err != nil {
logrus.WithError(err).Errorf("couldn't apply quick race")
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
AddFlash(w, r, "Quick race successfully started!")
if config.Server.PerformanceMode {
http.Redirect(w, r, "/", http.StatusFound)
} else {
http.Redirect(w, r, "/live-timing", http.StatusFound)
}
}
type QuickRace struct {
OverridePassword bool
ReplacementPassword string
RaceConfig CurrentRaceConfig
EntryList EntryList
}
func (q QuickRace) GetRaceConfig() CurrentRaceConfig {
return q.RaceConfig
}
func (q QuickRace) GetEntryList() EntryList {
return q.EntryList
}
func (q QuickRace) IsLooping() bool {
return false
}
func (q QuickRace) IsPractice() bool {
return false
}
func (q QuickRace) IsChampionship() bool {
return false
}
func (q QuickRace) IsRaceWeekend() bool {
return false
}
func (q QuickRace) IsTimeAttack() bool {
return q.RaceConfig.TimeAttack
}
func (q QuickRace) EventName() string {
return trackSummary(q.RaceConfig.Track, q.RaceConfig.TrackLayout)
}
func (q QuickRace) OverrideServerPassword() bool {
return q.OverridePassword
}
func (q QuickRace) ReplacementServerPassword() string {
return q.ReplacementPassword
}
func (q QuickRace) EventDescription() string {
return ""
}
func (q QuickRace) GetURL() string {
return ""
}
func (q QuickRace) GetForceStopTime() time.Duration {
return 0
}
func (q QuickRace) GetForceStopWithDrivers() bool {
return false
}