87 lines
2.0 KiB
Go
87 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/goccy/go-json"
|
|
)
|
|
|
|
type Config struct {
|
|
Server ServerConfig `json:"server"`
|
|
Database DatabaseConfig `json:"database"`
|
|
Web WebConfig `json:"web"`
|
|
Game GameConfig `json:"game"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Port int `json:"port"`
|
|
MaxClients int `json:"max_clients"`
|
|
MaxWorldServers int `json:"max_world_servers"`
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
type WebConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
Address string `json:"address"`
|
|
Port int `json:"port"`
|
|
CertFile string `json:"cert_file"`
|
|
KeyFile string `json:"key_file"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
type GameConfig struct {
|
|
AllowAccountCreation bool `json:"allow_account_creation"`
|
|
ExpansionFlag uint32 `json:"expansion_flag"`
|
|
CitiesFlag uint8 `json:"cities_flag"`
|
|
DefaultSubscriptionLevel uint32 `json:"default_subscription_level"`
|
|
EnabledRaces uint32 `json:"enabled_races"`
|
|
MaxCharactersPerAccount int `json:"max_characters_per_account"`
|
|
}
|
|
|
|
func LoadConfig(filename string) (*Config, error) {
|
|
data, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
// Return default config if file doesn't exist
|
|
return getDefaultConfig(), nil
|
|
}
|
|
|
|
var config Config
|
|
if err := json.Unmarshal(data, &config); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &config, nil
|
|
}
|
|
|
|
func getDefaultConfig() *Config {
|
|
return &Config{
|
|
Server: ServerConfig{
|
|
Port: 5998,
|
|
MaxClients: 1000,
|
|
MaxWorldServers: 10,
|
|
},
|
|
Database: DatabaseConfig{
|
|
Path: "login.db",
|
|
},
|
|
Web: WebConfig{
|
|
Enabled: true,
|
|
Address: "0.0.0.0",
|
|
Port: 8080,
|
|
Username: "admin",
|
|
Password: "password",
|
|
},
|
|
Game: GameConfig{
|
|
AllowAccountCreation: true,
|
|
ExpansionFlag: 0x7CFF,
|
|
CitiesFlag: 0xFF,
|
|
DefaultSubscriptionLevel: 0xFFFFFFFF,
|
|
EnabledRaces: 0xFFFF,
|
|
MaxCharactersPerAccount: 7,
|
|
},
|
|
}
|
|
}
|