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
|
package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
TickLength int `yaml:"tick_length"`
StartingRoom int `yaml:"starting_room"`
StartupValidation ValidationConfig `yaml:"startup_validation"`
GameConstants GameConstants `yaml:"game_constants"`
DefaultColors ColorsConfig `yaml:"default_colors"`
TLS TLSConfig `yaml:"tls"`
Telnet TelnetConfig `yaml:"telnet"`
TelnetTLS TelnetTLSConfig `yaml:"telnet_tls"`
HTTP HTTPConfig `yaml:"http"`
HTTPS HTTPSConfig `yaml:"https"`
AdminHTTP AdminHTTPConfig `yaml:"admin_http"`
AdminHTTPS AdminHTTPSConfig `yaml:"admin_https"`
}
// GameConstants holds tunable game-wide numbers that would otherwise be
// hardcoded in the engine.
type GameConstants struct {
// ShopDefaultRestock is the fallback restock interval (in ticks) for a shop
// item that does not set its own restock_ticks.
ShopDefaultRestock float64 `yaml:"shop_default_restock"`
}
type ColorsConfig map[string]string
func DefaultColors() ColorsConfig {
return ColorsConfig{
"room_name": "74 bold",
"room_number": "F0",
"room_desc": "FF",
"direction": "49",
"exit_direction": "49",
"exit_name": "74",
"protected_mob": "off",
"mob": "off",
"damage_dealt": "B4",
"damage_taken": "A7",
"xp": "B3",
"level_up": "B4 bold",
"item": "6E",
"player_name": "74",
"death": "A7 bold",
"victory": "6C",
"miss": "F5",
"error": "A7",
"say": "FF",
"global": "49",
"dialog": "6E",
"dialog_options": "bold",
"broadcast": "89",
"sequence": "off",
"fire": "B4",
"eat_food": "6C",
"drop_message": "89",
"currency_pickup": "B3",
"visual_tick": "49 dim",
"visual_first_tick": "B4 bold",
"battery": "6C",
"tech_depleted": "A7",
"science_mod": "8B",
"assassin_task": "8B",
"dim": "F5 dim",
"warning": "B3",
"farm_grow": "6C",
"farm_disease": "A7",
"map_at": "B4 bold",
"map_blocked": "A7",
"map_agility": "43",
"safespot_alert": "A7 bold",
}
}
type ValidationConfig struct {
RootRooms []int `yaml:"root_rooms"`
IgnoreUnreachable []int `yaml:"ignore_unreachable"`
}
type TelnetConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
type TLSConfig struct {
CertFile string `yaml:"cert_file"`
KeyFile string `yaml:"key_file"`
}
type TelnetTLSConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
type HTTPConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
type HTTPSConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
type AdminHTTPConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
type AdminHTTPSConfig struct {
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
}
func Default() *Config {
return &Config{
TickLength: 600,
StartingRoom: 1001,
StartupValidation: ValidationConfig{
RootRooms: []int{1},
IgnoreUnreachable: []int{},
},
GameConstants: GameConstants{
ShopDefaultRestock: 1000,
},
DefaultColors: DefaultColors(),
TLS: TLSConfig{
CertFile: "",
KeyFile: "",
},
Telnet: TelnetConfig{
Enabled: true,
Port: 4000,
},
TelnetTLS: TelnetTLSConfig{
Enabled: false,
Port: 4001,
},
HTTP: HTTPConfig{
Enabled: false,
Port: 8080,
},
HTTPS: HTTPSConfig{
Enabled: false,
Port: 8443,
},
AdminHTTP: AdminHTTPConfig{
Enabled: false,
Port: 9091,
},
AdminHTTPS: AdminHTTPSConfig{
Enabled: false,
Port: 9090,
},
}
}
func Load(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
cfg := Default()
if err := yaml.Unmarshal(data, cfg); err != nil {
return nil, err
}
return cfg, nil
}
func SaveDefault(path string) error {
cfg := Default()
data, err := yaml.Marshal(cfg)
if err != nil {
return err
}
return os.WriteFile(path, data, 0644)
}
|