2019-01-18 11:03:57 +03:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2019-01-18 11:13:37 +03:00
|
|
|
"encoding/json"
|
2023-12-29 18:00:11 +03:00
|
|
|
"mapserver/types"
|
2019-01-18 11:13:37 +03:00
|
|
|
"os"
|
2019-01-23 18:29:14 +03:00
|
|
|
"runtime"
|
2019-01-24 09:52:25 +03:00
|
|
|
"sync"
|
2019-01-18 11:03:57 +03:00
|
|
|
)
|
|
|
|
|
2019-01-21 12:53:58 +03:00
|
|
|
var lock sync.Mutex
|
|
|
|
|
|
|
|
const ConfigFile = "mapserver.json"
|
|
|
|
|
|
|
|
func (cfg *Config) Save() error {
|
|
|
|
return WriteConfig(ConfigFile, cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func WriteConfig(filename string, cfg *Config) error {
|
|
|
|
lock.Lock()
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
f, err := os.Create(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
str, err := json.MarshalIndent(cfg, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
f.Write(str)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-18 11:03:57 +03:00
|
|
|
func ParseConfig(filename string) (*Config, error) {
|
2019-01-18 13:04:37 +03:00
|
|
|
webapi := WebApiConfig{
|
|
|
|
EnableMapblock: false,
|
2019-01-29 20:00:00 +03:00
|
|
|
SecretKey: RandStringRunes(16),
|
2019-01-18 13:04:37 +03:00
|
|
|
}
|
|
|
|
|
2023-12-29 18:00:11 +03:00
|
|
|
layers := []*types.Layer{
|
2023-01-20 20:02:52 +03:00
|
|
|
{
|
2019-01-21 13:13:00 +03:00
|
|
|
Id: 0,
|
2019-02-25 15:01:15 +03:00
|
|
|
Name: "Ground",
|
2019-03-29 21:21:27 +03:00
|
|
|
From: -1,
|
|
|
|
To: 10,
|
2023-01-20 20:02:52 +03:00
|
|
|
}, {
|
2019-02-25 15:01:15 +03:00
|
|
|
Id: 1,
|
|
|
|
Name: "Sky",
|
2019-03-29 21:21:27 +03:00
|
|
|
From: 11,
|
|
|
|
To: 24,
|
2019-02-25 15:01:15 +03:00
|
|
|
},
|
2019-01-21 13:13:00 +03:00
|
|
|
}
|
|
|
|
|
2019-02-12 15:40:33 +03:00
|
|
|
mapobjs := MapObjectConfig{
|
2024-06-06 20:40:36 +03:00
|
|
|
Areas: true,
|
|
|
|
Bones: true,
|
|
|
|
Protector: true,
|
|
|
|
XPProtector: true,
|
|
|
|
PrivProtector: true,
|
|
|
|
TechnicQuarry: true,
|
|
|
|
TechnicSwitch: true,
|
|
|
|
TechnicAnchor: true,
|
|
|
|
TechnicReactor: true,
|
|
|
|
LuaController: true,
|
|
|
|
Digiterms: true,
|
|
|
|
Digilines: true,
|
|
|
|
Travelnet: true,
|
|
|
|
MapserverPlayer: true,
|
|
|
|
MapserverPOI: true,
|
|
|
|
MapserverLabel: true,
|
|
|
|
MapserverTrainline: true,
|
|
|
|
MapserverBorder: true,
|
|
|
|
TileServerLegacy: true,
|
|
|
|
Mission: true,
|
|
|
|
Jumpdrive: true,
|
|
|
|
Smartshop: true,
|
|
|
|
Fancyvend: true,
|
|
|
|
ATM: true,
|
|
|
|
Train: true,
|
|
|
|
TrainSignal: true,
|
|
|
|
Minecart: false,
|
|
|
|
Locator: false,
|
|
|
|
Signs: true,
|
|
|
|
MapserverAirutils: true,
|
|
|
|
UnifiefMoneyAreaForSale: true,
|
|
|
|
Phonograph: true,
|
2019-02-12 15:40:33 +03:00
|
|
|
}
|
|
|
|
|
2019-02-22 21:13:47 +03:00
|
|
|
mapblockaccessor := MapBlockAccessorConfig{
|
2023-10-11 18:42:03 +03:00
|
|
|
Expiretime: "10s",
|
|
|
|
Purgetime: "15s",
|
|
|
|
MaxItems: 50,
|
2019-02-22 21:13:47 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 13:50:40 +03:00
|
|
|
defaultoverlays := []string{
|
|
|
|
"mapserver_poi",
|
|
|
|
"mapserver_label",
|
|
|
|
"mapserver_player",
|
|
|
|
}
|
|
|
|
|
2022-12-16 10:07:47 +03:00
|
|
|
skins := SkinsConfig{
|
|
|
|
EnableSkinsDB: false,
|
|
|
|
SkinsPath: "",
|
|
|
|
}
|
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
cfg := Config{
|
2020-04-14 14:43:07 +03:00
|
|
|
ConfigVersion: 1,
|
|
|
|
Port: 8080,
|
|
|
|
EnableRendering: true,
|
|
|
|
EnablePrometheus: true,
|
|
|
|
EnableSearch: true,
|
|
|
|
EnableInitialRendering: true,
|
|
|
|
EnableTransparency: false,
|
|
|
|
EnableMediaRepository: false,
|
|
|
|
Webdev: false,
|
|
|
|
WebApi: &webapi,
|
|
|
|
Layers: layers,
|
2023-10-11 18:42:03 +03:00
|
|
|
RenderingFetchLimit: 500,
|
2020-04-14 14:43:07 +03:00
|
|
|
RenderingJobs: runtime.NumCPU(),
|
2023-10-11 18:42:03 +03:00
|
|
|
RenderingQueue: 10,
|
2020-04-14 14:43:07 +03:00
|
|
|
IncrementalRenderingTimer: "5s",
|
|
|
|
MapObjects: &mapobjs,
|
|
|
|
MapBlockAccessorCfg: &mapblockaccessor,
|
|
|
|
DefaultOverlays: defaultoverlays,
|
2022-12-16 10:07:47 +03:00
|
|
|
Skins: &skins,
|
2023-09-18 07:47:29 +03:00
|
|
|
WorldPath: "./",
|
|
|
|
DataPath: "./",
|
2023-09-28 08:00:04 +03:00
|
|
|
ColorsTxtPath: "./",
|
2019-01-18 11:13:37 +03:00
|
|
|
}
|
2019-01-18 11:03:57 +03:00
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
info, err := os.Stat(filename)
|
|
|
|
if info != nil && err == nil {
|
2023-01-20 20:04:27 +03:00
|
|
|
data, err := os.ReadFile(filename)
|
2019-01-18 11:13:37 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-01-18 11:03:57 +03:00
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
err = json.Unmarshal(data, &cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 11:03:57 +03:00
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
return &cfg, nil
|
2019-01-18 11:03:57 +03:00
|
|
|
}
|