mirror of
https://github.com/EQEmu/Server.git
synced 2026-08-30 22:06:46 +00:00
Merge pull request #635 from xackery/eqemu_config_json
Eqemu config json
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
eqemu_config.xml
|
||||
eqemu_config.json
|
||||
@@ -0,0 +1 @@
|
||||
Converts the old eqemu_config.xml to eqemu_config.json
|
||||
@@ -0,0 +1,21 @@
|
||||
@echo off
|
||||
setlocal
|
||||
set name="xmltojson"
|
||||
|
||||
echo Building Linux
|
||||
set GOOS=linux
|
||||
set GOARCH=amd64
|
||||
go build -o %name%-linux-x64 main.go
|
||||
set GOARCH=386
|
||||
go build -o %name%-linux-x86 main.go
|
||||
echo Building Windows
|
||||
set GOOS=windows
|
||||
set GOARCH=amd64
|
||||
go build -o %name%-windows-x64.exe main.go
|
||||
set GOARCH=386
|
||||
go build -o %name%-windows-x86.exe main.go
|
||||
echo Building OSX
|
||||
REM set GOOS=darwin
|
||||
REM set GOARCH=amd64
|
||||
REM go build -o %name%-osx-x64 main.go
|
||||
endlocal
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
export NAME="xmltojson"
|
||||
echo Building Linux
|
||||
GOOS=linux GOARCH=amd64 go build -o $NAME-linux-x64 main.go
|
||||
GOOS=linux GOARCH=386 go build -o $NAME-linux-x86 main.go
|
||||
echo Building Windows
|
||||
GOOS=windows GOARCH=amd64 go build -o $NAME-windows-x64.exe main.go
|
||||
GOOS=windows GOARCH=386 go build -o $NAME-windows-x86.exe main.go
|
||||
#echo Building OSX
|
||||
#GOOS=darwin GOARCH=amd64 go build -o $NAME-osx-x64 main.go
|
||||
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
xj "github.com/basgys/goxml2json"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
var data []byte
|
||||
var sData string
|
||||
buf := &bytes.Buffer{}
|
||||
var buf2 bytes.Buffer
|
||||
|
||||
if data, err = ioutil.ReadFile("eqemu_config.xml"); err != nil {
|
||||
fmt.Println("Failed to open eqemu_config.xml:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//detect malformed xml in eqemuconfig
|
||||
sData = strings.Replace(string(data), "<?xml version=\"1.0\">", "<?xml version=\"1.0\"?>", 1)
|
||||
r := strings.NewReader(sData)
|
||||
dec := xj.NewDecoder(r)
|
||||
root := &xj.Node{}
|
||||
if err = dec.DecodeWithCustomPrefixes(root, "", ""); err != nil {
|
||||
fmt.Println("Failed to decode eqemu_config.xml:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if root.Children["server"] == nil || len(root.Children["server"]) < 1 {
|
||||
fmt.Println("Server element not found")
|
||||
os.Exit(1)
|
||||
}
|
||||
server := root.Children["server"][0]
|
||||
|
||||
//locked: "true" is only way to trigger locked
|
||||
if server.Children["world"] != nil && len(server.Children["world"]) > 0 {
|
||||
world := server.Children["world"][0]
|
||||
|
||||
if world.Children["locked"] != nil && len(world.Children["locked"]) > 0 {
|
||||
fmt.Println("Locked!")
|
||||
world.Children["locked"][0].Data = "true"
|
||||
}
|
||||
}
|
||||
|
||||
elements := []string{
|
||||
"chatserver",
|
||||
"directories",
|
||||
"files",
|
||||
"launcher",
|
||||
"mailserver",
|
||||
"webinterface",
|
||||
"world",
|
||||
"zones",
|
||||
}
|
||||
for _, ele := range elements {
|
||||
if server.Children[ele] != nil && len(server.Children[ele]) > 0 && len(server.Children[ele][0].Children) == 0 {
|
||||
delete(server.Children, ele)
|
||||
}
|
||||
}
|
||||
|
||||
enc := xj.NewEncoder(buf)
|
||||
err = enc.EncodeWithCustomPrefixes(root, "", "")
|
||||
if err != nil {
|
||||
fmt.Println("Failed to encode eqemu_config.xml:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//prettyprint
|
||||
if err = json.Indent(&buf2, buf.Bytes(), "", "\t"); err != nil {
|
||||
fmt.Println("Failed to encode json:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile("eqemu_config.json", buf2.Bytes(), 0744); err != nil {
|
||||
fmt.Println("Failed to write eqemu_config.json:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user