-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
servermanager_config.go
234 lines (188 loc) · 5.34 KB
/
servermanager_config.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package servermanager
import (
"errors"
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/cj123/sessions"
"github.com/etcd-io/bbolt"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
var config *Configuration
type Configuration struct {
HTTP HTTPConfig `yaml:"http"`
Steam SteamConfig `yaml:"steam"`
Store StoreConfig `yaml:"store"`
LiveMap LiveMapConfig `yaml:"live_map"`
Server ServerExtraConfig `yaml:"server"`
Accounts AccountsConfig `yaml:"accounts"`
Monitoring MonitoringConfig `yaml:"monitoring"`
Championships ChampionshipsConfig `yaml:"championships"`
Lua LuaConfig `yaml:"lua"`
}
type ChampionshipsConfig struct {
RecaptchaConfig struct {
SiteKey string `yaml:"site_key"`
SecretKey string `yaml:"secret_key"`
} `yaml:"recaptcha"`
}
type MonitoringConfig struct {
Enabled bool `yaml:"enabled"`
}
type AccountsConfig struct {
AdminPasswordOverride string `yaml:"admin_password_override"`
}
type LiveMapConfig struct {
IntervalMs int `yaml:"refresh_interval_ms"`
}
func (l *LiveMapConfig) IsEnabled() bool {
return l.IntervalMs > 0
}
type HTTPConfig struct {
Hostname string `yaml:"hostname"`
SessionKey string `yaml:"session_key"`
SessionStoreType string `yaml:"session_store_type"`
SessionStorePath string `yaml:"session_store_path"`
BaseURL string `yaml:"server_manager_base_URL"`
TLS TLSConfig `yaml:"tls"`
}
type TLSConfig struct {
Enabled bool `yaml:"enabled"`
CertPath string `yaml:"cert_path"`
KeyPath string `yaml:"key_path"`
}
type LuaConfig struct {
Enabled bool `yaml:"enabled"`
}
const (
sessionStoreCookie = "cookie"
sessionStoreFilesystem = "filesystem"
)
func (h *HTTPConfig) createSessionStore() (sessions.Store, error) {
switch h.SessionStoreType {
case sessionStoreFilesystem:
if info, err := os.Stat(h.SessionStorePath); os.IsNotExist(err) {
err := os.MkdirAll(h.SessionStorePath, 0755)
if err != nil {
return nil, err
}
} else if err != nil {
return nil, err
} else if !info.IsDir() {
return nil, errors.New("servermanager: session store location must be a directory")
}
fsStore := sessions.NewFilesystemStore(h.SessionStorePath, []byte(h.SessionKey))
fsStore.Options.SameSite = http.SameSiteStrictMode
return fsStore, nil
case sessionStoreCookie:
fallthrough
default:
cookieStore := sessions.NewCookieStore([]byte(h.SessionKey))
cookieStore.Options.SameSite = http.SameSiteStrictMode
return cookieStore, nil
}
}
type SteamConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
InstallPath string `yaml:"install_path"`
ForceUpdate bool `yaml:"force_update"`
ExecutablePath string `yaml:"executable_path"`
}
type StoreConfig struct {
Type string `yaml:"type"`
Path string `yaml:"path"`
SharedPath string `yaml:"shared_data_path"`
ScheduledEventCheckLoop time.Duration `yaml:"scheduled_event_check_loop"`
}
func (s *StoreConfig) BuildStore() (Store, error) {
var rs Store
if s.SharedPath == "" {
s.SharedPath = s.Path
}
switch s.Type {
case "boltdb":
bbdb, err := bbolt.Open(s.Path, 0644, nil)
if err != nil {
return nil, err
}
rs = NewBoltStore(bbdb)
case "json":
rs = NewJSONStore(s.Path, s.SharedPath)
default:
return nil, fmt.Errorf("invalid store type (%s), must be either boltdb/json", s.Type)
}
if err := Migrate(rs); err != nil {
return nil, err
}
return rs, nil
}
type ServerExtraConfig struct {
Plugins []*CommandPlugin `yaml:"plugins"`
AuditLogging bool `yaml:"audit_logging"`
PerformanceMode bool `yaml:"performance_mode"`
DisableWindowsBrowserOpen bool `yaml:"dont_open_browser"`
ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"`
UseCarNameCache bool `yaml:"use_car_name_cache"`
PersistMidSessionResults bool `yaml:"persist_mid_session_results"`
// Deprecated: use Plugins instead
RunOnStart []string `yaml:"run_on_start"`
}
type CommandPlugin struct {
Executable string `yaml:"executable"`
Arguments []string `yaml:"arguments"`
}
func (c *CommandPlugin) String() string {
out := c.Executable
out += strings.Join(c.Arguments, " ")
return out
}
func ReadConfig(location string) (conf *Configuration, err error) {
f, err := os.Open(location)
if err != nil {
return nil, err
}
defer f.Close()
if err := yaml.NewDecoder(f).Decode(&conf); err != nil {
return nil, err
}
config = conf
sessionsStore, err = conf.HTTP.createSessionStore()
if err != nil {
return nil, err
}
if config.Accounts.AdminPasswordOverride != "" {
logrus.Infof("WARNING! Admin Password Override is set. Please only have this set if you are resetting your admin account password!")
}
if config.Steam.ExecutablePath == "" {
config.Steam.ExecutablePath = ServerExecutablePath
}
return conf, err
}
type Theme string
const (
ThemeDefault = "default"
ThemeLight = "light"
ThemeDark = "dark"
)
type ThemeDetails struct {
Theme Theme
Name string
}
var ThemeOptions = []ThemeDetails{
{
Theme: ThemeDefault,
Name: "Use Default",
},
{
Theme: ThemeLight,
Name: "Light",
},
{
Theme: ThemeDark,
Name: "Dark",
},
}