-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
91 lines (77 loc) · 1.9 KB
/
main.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
package main
import (
"flag"
"fmt"
"os"
"path"
"github.com/minetest-go/areasparser"
"github.com/minetest-go/mtdb"
"github.com/minetest-go/mtdb/block"
"github.com/sirupsen/logrus"
)
var Version string
var block_repo block.BlockRepository
var wd string
func main() {
help := flag.Bool("help", false, "show help")
debug := flag.Bool("debug", false, "set the loglevel to debug")
mode := flag.String("mode", "prune_unproteced", "set the working mode [prune_unproteced|export_protected]")
exportAllProtected := flag.Bool("export-all", false, "when mode=export_protected, parse all blocks to also preserve mapcleaner_protect.txt alongside areas")
flag.IntVar(&block.IteratorBatchSize, "batch-size", block.IteratorBatchSize, "iterator batch size")
flag.Parse()
if *help {
flag.Usage()
return
}
if *debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debug("loglevel set to debug")
}
var err error
wd, err = os.Getwd()
if err != nil {
panic(err)
}
if Version == "" {
Version = "DEV"
}
logrus.WithFields(logrus.Fields{
"world": wd,
"version": Version,
}).Info("Starting mapcleaner")
// load main block database
block_repo, err = mtdb.NewBlockDB(wd)
if err != nil {
panic(err)
}
// load areas file
areas_file := path.Join(wd, "areas.dat")
areas, err := areasparser.ParseFile(areas_file)
if err != nil {
logrus.WithFields(logrus.Fields{"filename": areas_file}).Warn("Areas not found")
} else {
for _, area := range areas {
if area == nil {
continue
}
PopulateAreaProtection(area)
}
}
// start main process
switch *mode {
case "prune_unproteced":
err = ProcessRemoveUnprotected()
case "export_protected":
if *exportAllProtected {
err = ProccessExportAllProtected()
} else {
err = ProcessExportProtected(areas)
}
default:
panic(fmt.Sprintf("mode not implemented: '%s'", *mode))
}
if err != nil {
panic(err)
}
logrus.Info("mapcleaner exiting")
}